X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fgui%2Ffilethread.cpp;h=306af9fd4ff3596d46e69935d07e4737eb0bd37e;hb=5c28b6dbf7aa20441c8a51f484f4f64b1966f7e3;hp=dec070ffd4efcfeeb81207a06de89df66d0b2d62;hpb=68e8886a9aaf48fcc130334d8cf4fe35a4534a02;p=virtualjaguar diff --git a/src/gui/filethread.cpp b/src/gui/filethread.cpp index dec070f..306af9f 100644 --- a/src/gui/filethread.cpp +++ b/src/gui/filethread.cpp @@ -1,15 +1,18 @@ // // filethread.cpp - File discovery thread // -// by James L. Hammons +// by James Hammons // (C) 2010 Underground Software // -// JLH = James L. Hammons +// JLH = James Hammons // // Who When What // --- ---------- ------------------------------------------------------------- // JLH 01/28/2010 Created this file // JLH 02/16/2010 Moved RomIdentifier stuff to its own file +// JLH 03/02/2010 Added .ZIP file fishing +// JLH 06/28/2011 Cleanup in the file parsing/fishing code, to make it easier +// to follow the flow of the logic // #include "filethread.h" @@ -18,8 +21,11 @@ #include "crc32.h" #include "file.h" #include "filedb.h" +//#include "memory.h" #include "settings.h" +#define VERBOSE_LOGGING + FileThread::FileThread(QObject * parent/*= 0*/): QThread(parent), abort(false) { } @@ -34,8 +40,9 @@ FileThread::~FileThread() wait(); } -void FileThread::Go(void) +void FileThread::Go(bool allowUnknown/*= false*/) { + allowUnknownSoftware = allowUnknown; QMutexLocker locker(&mutex); start(); } @@ -53,6 +60,7 @@ put that in the list. User picks from a graphical image of the cart. Ideally, the label will go into the archive along with the ROM image, but that's for the future... Maybe box art, screenshots will go as well... +The future is NOW! :-) */ // @@ -61,76 +69,117 @@ Maybe box art, screenshots will go as well... void FileThread::run(void) { QDir romDir(vjs.ROMPath); -// QDir romDir("../virtualjaguar/roms/rarities/"); 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 0) - { //printf("FileThread: About to calc checksum on file with size %u... (buffer=%08X)\n", size, buffer); - uint32 crc = crc32_calcCheckSum(buffer, size); - uint32 index = FindCRCIndexInFileList(crc); - delete[] buffer; - -// Mebbe we should pass a index AND a QImage here??? - if (index != 0xFFFFFFFF && !(romList[index].flags & FF_BIOS)) - { - QImage img; - size = GetFileFromZIP(fileInfo.canonicalFilePath().toAscii(), FT_LABEL, buffer); - - if (size > 0) - { - img.loadFromData(buffer, size); - delete[] buffer; - } -//printf("FileThread: Attempted to load image. Size: %u x %u...\n", img.width(), img.height()); + if (foundUniversalHeader) + crc = crc32_calcCheckSum(buffer + 8192, fileSize - 8192); + else + crc = crc32_calcCheckSum(buffer, fileSize); - emit FoundAFile(index); - } - } - } - else + uint32 index = FindCRCIndexInFileList(crc); + delete[] buffer; + + // Here we filter out files that are *not* in the DB and of unknown type, + // and BIOS files. If desired, this can be overriden with a config option. + if ((index == 0xFFFFFFFF) && (fileType == JST_NONE)) + { + // If we allow unknown software, we pass the (-1) index on, otherwise... + if (!allowUnknownSoftware) + return; // CRC wasn't found, so bail... + } + else if ((index != 0xFFFFFFFF) && romList[index].flags & FF_BIOS) + return; + +//Here's a little problem. When we create the image here and pass it off to FilePicker, +//we can clobber this image before we have a chance to copy it out in the FilePicker function +//because we can be back here before FilePicker can respond. +// So now we create the image on the heap, problem solved. :-) + QImage * img = NULL; + + // See if we can fish out a label. :-) + if (haveZIPFile) + { + uint32 size = GetFileFromZIP(fileInfo.filePath().toAscii(), FT_LABEL, buffer); +//printf("FT: Label size = %u bytes.\n", size); + + if (size > 0) { - QFile file(romDir.filePath(fileInfo.fileName())); - - if (file.open(QIODevice::ReadOnly)) - { - uint8 * buffer = new uint8[fileInfo.size()]; - file.read((char *)buffer, fileInfo.size()); - file.close(); - uint32 crc = crc32_calcCheckSum(buffer, fileInfo.size()); - uint32 index = FindCRCIndexInFileList(crc); - delete[] buffer; - -// Mebbe we should pass a index AND a QImage here??? - if (index != 0xFFFFFFFF && !(romList[index].flags & FF_BIOS)) - emit FoundAFile(index); - } + QImage label; + bool successful = label.loadFromData(buffer, size); + img = new QImage; + *img = label.scaled(365, 168, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); +//printf("FT: Label %s: %ux%u.\n", (successful ? "succeeded" : "did not succeed"), img->width(), img->height()); + delete[] buffer; } +//printf("FileThread: Attempted to load image. Size: %u x %u...\n", img.width(), img.height()); } + +// emit FoundAFile2(index, fileInfo.canonicalFilePath(), img, fileSize); + emit FoundAFile3(index, fileInfo.canonicalFilePath(), img, fileSize, foundUniversalHeader, fileType, crc); } // @@ -139,6 +188,9 @@ printf("FileThread: Aborting!!!\n"); // uint32 FileThread::FindCRCIndexInFileList(uint32 crc) { + // Instead of a simple brute-force search, we should probably do a binary + // partition search instead, since the CRCs are sorted numerically. +#warning "!!! Should do binary partition search here !!!" for(int i=0; romList[i].crc32!=0xFFFFFFFF; i++) { if (romList[i].crc32 == crc) @@ -147,4 +199,3 @@ uint32 FileThread::FindCRCIndexInFileList(uint32 crc) return 0xFFFFFFFF; } -