]> Shamusworld >> Repos - virtualjaguar/blobdiff - src/gui/filethread.cpp
Moving towards a better file picker... :-)
[virtualjaguar] / src / gui / filethread.cpp
index 3d53f92b8dd4a02b85a08e7673e224a0d85a6a56..a6ecd3fbd1dcbd3c435e058d3ee6f986286b52ef 100644 (file)
 
 #include "filethread.h"
 
+#include <QtGui>
 #include "crc32.h"
 #include "settings.h"
-#include "types.h"
+//#include "types.h"
 
+#if 0
 struct RomIdentifier
 {
        const uint32 crc32;
        const char name[128];
        const char file[128];
 };
+#endif
 
 RomIdentifier romList[] = {
        { 0x0509C85E, "Raiden (World)", "" },
@@ -106,7 +109,7 @@ for the future...
 Maybe box art, screenshots will go as well...
 */
 
-FileThread::FileThread(QObject * parent/*= 0*/): QThread(parent), listWidget(NULL), abort(false)
+FileThread::FileThread(QObject * parent/*= 0*/): QThread(parent), /*listWidget(NULL),*/ abort(false)
 {
 }
 
@@ -120,32 +123,40 @@ FileThread::~FileThread()
        wait();
 }
 
-FileThread::Go(QListWidget * lw)
+//void FileThread::Go(QListWidget * lw)
+void FileThread::Go(void)
 {
        QMutexLocker locker(&mutex);
-       this->listWidget = lw;
+//     this->listWidget = lw;
        start();
 }
 
+//
+// Here's the thread's actual execution path...
+//
 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 +167,33 @@ 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);
+                               emit FoundAFile(index);
                        }
                }
 
                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;
 }