]> Shamusworld >> Repos - virtualjaguar/blobdiff - src/gui/filethread.cpp
More ROM picker refinements...
[virtualjaguar] / src / gui / filethread.cpp
index 3d53f92b8dd4a02b85a08e7673e224a0d85a6a56..8bb2b87b70f4edda23d8acd3369b9ebc136ee784 100644 (file)
 
 #include "filethread.h"
 
+#include <QtGui>
 #include "crc32.h"
 #include "settings.h"
-#include "types.h"
+//#include "types.h"
 
 struct RomIdentifier
 {
@@ -120,7 +121,7 @@ FileThread::~FileThread()
        wait();
 }
 
-FileThread::Go(QListWidget * lw)
+void FileThread::Go(QListWidget * lw)
 {
        QMutexLocker locker(&mutex);
        this->listWidget = lw;
@@ -129,23 +130,27 @@ FileThread::Go(QListWidget * lw)
 
 void FileThread::run(void)
 {
-//     mutex.lock();
-//     if (abort)
-//             return;
-//     mutex.unlock();
-
        QDir romDir(vjs.ROMPath);
        QFileInfoList list = romDir.entryInfoList();
 
+/*
+Another thing we'll probably have to do here is check for compressed files and
+decompress/fish around in them to find what we need. :-P
+*/
+
        for(int i=0; i<list.size(); i++)
        {
                if (abort)
+#if 1
+{
+printf("FileThread: Aborting!!!\n");
+#endif
                        return;
+#if 1
+}
+#endif
 
                QFileInfo fileInfo = list.at(i);
-//         std::cout << qPrintable(QString("%1 %2").arg(fileInfo.size(), 10)
-//                                                 .arg(fileInfo.fileName()));
-//         std::cout << std::endl;
                QFile file(romDir.filePath(fileInfo.fileName()));
                uint8 * buffer = new uint8[fileInfo.size()];
 
@@ -156,19 +161,32 @@ void FileThread::run(void)
                        file.close();
 //printf("FilePickerWindow: File crc == %08X...\n", crc);
 
-                       for(int j=0; romList[j].crc32 != 0xFFFFFFFF; j++)
+                       uint32 index = FindCRCIndexInFileList(crc);
+
+                       if (index != 0xFFFFFFFF)
                        {
-                               if (romList[j].crc32 == crc)
-                               {
-printf("FilePickerWindow: Found match [%s]...\n", romList[j].name);
-                                       new QListWidgetItem(QIcon(":/res/generic.png"), romList[j].name, listWidget);
-                                       break;
-                               }
+printf("FileThread: Found match [%s]...\n", romList[index].name);
+                               new QListWidgetItem(QIcon(":/res/generic.png"), romList[index].name, listWidget);
+                               emit FoundAFile(romList[index].crc32);
                        }
                }
 
                delete[] buffer;
        }
+}
+
+//
+// Find a CRC in the ROM list (simple brute force algorithm).
+// If it's there, return the index, otherwise return $FFFFFFFF
+//
+uint32 FileThread::FindCRCIndexInFileList(uint32 crc)
+{
+       for(int i=0; romList[i].crc32!=0xFFFFFFFF; i++)
+       {
+               if (romList[i].crc32 == crc)
+                       return i;
+       }
 
+       return 0xFFFFFFFF;
 }