X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fgui%2Ffilethread.cpp;h=112e848afccac791b8237dd73c590f975e1b4ebc;hb=481bb094f715443e52695fc46307785e61556c0d;hp=8bb2b87b70f4edda23d8acd3369b9ebc136ee784;hpb=09adab3161f986d5cc8dbeffe15cb6545afa138f;p=virtualjaguar diff --git a/src/gui/filethread.cpp b/src/gui/filethread.cpp index 8bb2b87..112e848 100644 --- a/src/gui/filethread.cpp +++ b/src/gui/filethread.cpp @@ -9,105 +9,19 @@ // 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 // #include "filethread.h" #include #include "crc32.h" +#include "file.h" +#include "filedb.h" #include "settings.h" -//#include "types.h" -struct RomIdentifier -{ - const uint32 crc32; - const char name[128]; - const char file[128]; -}; - -RomIdentifier romList[] = { - { 0x0509C85E, "Raiden (World)", "" }, - { 0x08F15576, "Iron Soldier (World) (v1.04)", "" }, - { 0x0957A072, "Kasumi Ninja (World)", "" }, - { 0x0AC83D77, "NBA Jam T.E. (World)", "" }, - { 0x0EC5369D, "Evolution - Dino Dudes (World)", "" }, - { 0x0F6A1C2C, "Ultra Vortek (World)", "" }, - { 0x14915F20, "White Men Can't Jump (World)", "" }, - { 0x1660F070, "Power Drive Rally (World)", "" }, - { 0x1E451446, "Trevor McFur in the Crescent Galaxy (World)", "" }, - { 0x27594C6A, "Defender 2000 (World)", "" }, - { 0x2E17D5DA, "Bubsy in Fractured Furry Tales (World)", "" }, - { 0x348E6449, "Double Dragon V - The Shadow Falls (World)", "" }, - { 0x3615AF6A, "Fever Pitch Soccer (World) (En,Fr,De,Es,It)", "" }, - { 0x38A130ED, "Troy Aikman NFL Football (World)", "" }, - { 0x3C044941, "Skyhammer (World)", "" }, - { 0x42A13EC5, "Soccer Kid (World)", "" }, - { 0x47EBC158, "Theme Park (World)", "" }, - { 0x4899628F, "Hover Strike (World)", "" }, - { 0x53DF6440, "Space War 2000 (World)", "" }, - { 0x55A0669C, "[BIOS] Atari Jaguar Developer CD (World)", "" }, - { 0x58272540, "Syndicate (World)", "" }, - { 0x5A101212, "Sensible Soccer - International Edition (World)", "" }, - { 0x5B6BB205, "Ruiner Pinball (World)", "" }, - { 0x5CFF14AB, "Pinball Fantasies (World)", "" }, - { 0x5E2CDBC0, "Doom (World)", "" }, - { 0x61C7EEC0, "Zero 5 (World)", "" }, - { 0x67F9AB3A, "Battle Sphere Gold (World)", "" }, - { 0x687068D5, "[BIOS] Atari Jaguar CD (World)", "" }, - { 0x6B2B95AD, "Tempest 2000 (World)", "" }, - { 0x6EB774EB, "Worms (World)", "" }, - { 0x6F8B2547, "Super Burnout (World)", "" }, - { 0x817A2273, "Pitfall - The Mayan Adventure (World)", "" }, - { 0x8975F48B, "Zool 2 (World)", "" }, - { 0x8D15DBC6, "[BIOS] Atari Jaguar Stubulator '94 (World)", "" }, - { 0x8FEA5AB0, "Dragon - The Bruce Lee Story (World)", "" }, - { 0x97EB4651, "I-War (World)", "" }, - { 0xA27823D8, "Ultra Vortek (World) (v0.94) (Beta)", "" }, - { 0xA56D0798, "Protector - Special Edition (World)", "" }, - { 0xA9F8A00E, "Rayman (World)", "" }, - { 0xB14C4753, "Fight for Life (World)", "" }, - { 0xBCB1A4BF, "Brutal Sports Football (World)", "" }, - { 0xBDA405C6, "Cannon Fodder (World)", "" }, - { 0xBDE67498, "Cybermorph (World) (Rev 1)", "" }, - { 0xC5562581, "Zoop! (World)", "" }, - { 0xC654681B, "Total Carnage (World)", "" }, - { 0xC6C7BA62, "Fight for Life (World) (Alt)", "" }, - { 0xC9608717, "Val d'Isere Skiing and Snowboarding (World)", "" }, - { 0xCBFD822A, "Air Cars (World)", "" }, - { 0xCD5BF827, "Attack of the Mutant Penguins (World)", "" }, - { 0xD6C19E34, "Iron Soldier 2 (World)", "" }, - { 0xDA9C4162, "Missile Command 3D (World)", "" }, - { 0xDC187F82, "Alien vs Predator (World)", "" }, - { 0xDE55DCC7, "Flashback - The Quest for Identity (World) (En,Fr)", "" }, - { 0xE28756DE, "Atari Karts (World)", "" }, - { 0xE60277BB, "[BIOS] Atari Jaguar Stubulator '93 (World)", "" }, - { 0xE91BD644, "Wolfenstein 3D (World)", "" }, - { 0xEC22F572, "SuperCross 3D (World)", "" }, - { 0xECF854E7, "Cybermorph (World) (Rev 2)", "" }, - { 0xEEE8D61D, "Club Drive (World)", "" }, - { 0xF0360DB3, "Hyper Force (World)", "" }, - { 0xFA7775AE, "Checkered Flag (World)", "" }, - { 0xFAE31DD0, "Flip Out! (World)", "" }, - { 0xFB731AAA, "[BIOS] Atari Jaguar (World)", "" }, - { 0xFFFFFFFF, "***END***", "" } -}; - -/* -Our strategy here is like so: -Look at the files in the directory pointed to by ROMPath. -For each file in the directory, take the CRC32 of it and compare it to the CRC -in the romList[]. If there's a match, put it in a list and note it's index value -in romList for future reference. - -When constructing the list, use the index to pull up an image of the cart and -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... -*/ - -FileThread::FileThread(QObject * parent/*= 0*/): QThread(parent), listWidget(NULL), abort(false) +FileThread::FileThread(QObject * parent/*= 0*/): QThread(parent), abort(false) { } @@ -121,16 +35,34 @@ FileThread::~FileThread() wait(); } -void FileThread::Go(QListWidget * lw) +void FileThread::Go(void) { QMutexLocker locker(&mutex); - this->listWidget = lw; start(); } +/* +Our strategy here is like so: +Look at the files in the directory pointed to by ROMPath. +For each file in the directory, take the CRC32 of it and compare it to the CRC +in the romList[]. If there's a match, put it in a list and note it's index value +in romList for future reference. + +When constructing the list, use the index to pull up an image of the cart and +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... +*/ + +// +// Here's the thread's actual execution path... +// void FileThread::run(void) { QDir romDir(vjs.ROMPath); +// QDir romDir("../virtualjaguar/roms/rarities/"); QFileInfoList list = romDir.entryInfoList(); /* @@ -151,27 +83,91 @@ printf("FileThread: Aborting!!!\n"); #endif QFileInfo fileInfo = list.at(i); - QFile file(romDir.filePath(fileInfo.fileName())); - uint8 * buffer = new uint8[fileInfo.size()]; - if (file.open(QIODevice::ReadOnly)) + // ZIP files are special: They contain more than just the software now... ;-) + // So now we fish around inside them to pull out the stuff we want. + // Probably also need more stringent error checking as well... :-O + if (fileInfo.suffix().compare("zip", Qt::CaseInsensitive) == 0) { - file.read((char *)buffer, fileInfo.size()); - uint32 crc = crc32_calcCheckSum(buffer, fileInfo.size()); - file.close(); -//printf("FilePickerWindow: File crc == %08X...\n", crc); - - uint32 index = FindCRCIndexInFileList(crc); + uint8 * buffer = NULL; + uint32 size = GetFileFromZIP(fileInfo.canonicalFilePath().toAscii(), FT_SOFTWARE, buffer); - if (index != 0xFFFFFFFF) + if (size > 0) { -printf("FileThread: Found match [%s]...\n", romList[index].name); - new QListWidgetItem(QIcon(":/res/generic.png"), romList[index].name, listWidget); - emit FoundAFile(romList[index].crc32); + uint32_t fileSize = size; +//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); +// These two are NOT interchangeable! +//Hm, confusing. It looks like in file.cpp it uses operater new() to create the buffer... +// delete[] buffer; + free(buffer); + +// Mebbe we should pass a index AND a QImage here??? +/* +Let's think about this... What *do* we need to send out? +we need the filename for sure. image file if it exists. +do we need the index? I think we're only using it to pull the label from the subdir... +we might need it if we want to pull ROM flags from the fileDB... +*/ + if (index != 0xFFFFFFFF && !(romList[index].flags & FF_BIOS)) + { +//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 we need to fix this so that this does not happen. :-/ +//And now it is. :-) +/* +So I guess we can create an image on the heap and pass *that* to FilePicker. But then, would +it be worthwhile to just pass the pointer into the FileListModel instead of a copy of an object? +Maybe. We'd do like so: +QImage * imageCopy = new QImage(); +*/ + QImage * img = NULL; + size = GetFileFromZIP(fileInfo.canonicalFilePath().toAscii(), FT_LABEL, buffer); +//printf("FT: Label size = %u bytes.\n", size); + + if (size > 0) + { +//#warning "!!!" +//Not sure if this will work properly... Seems to. + QImage label; + bool success = label.loadFromData(buffer, size); + img = new QImage(); +// *img = label.scaled(373, 172, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + *img = label.scaled(365, 168, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); +//printf("FT: Label %s: %ux%u.\n", (success ? "succeeded" : "did not succeed"), img->width(), img->height()); +// These two are NOT interchangeable! +//Hm, confusing. It looks like in file.cpp it uses operater new() to create the buffer... +// delete[] buffer; + free(buffer); + } +//printf("FileThread: Attempted to load image. Size: %u x %u...\n", img.width(), img.height()); + +// emit FoundAFile(index); + emit FoundAFile2(index, fileInfo.canonicalFilePath(), img, fileSize); + } } } + else + { + QFile file(romDir.filePath(fileInfo.fileName())); - delete[] buffer; + 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); + emit FoundAFile2(index, fileInfo.canonicalFilePath(), 0, fileInfo.size()); + } + } } }