2 // filethread.cpp - File discovery thread
5 // (C) 2010 Underground Software
7 // JLH = James L. Hammons <jlhamm@acm.org>
10 // --- ---------- -------------------------------------------------------------
11 // JLH 01/28/2010 Created this file
12 // JLH 02/16/2010 Moved RomIdentifier stuff to its own file
15 #include "filethread.h"
23 FileThread::FileThread(QObject * parent/*= 0*/): QThread(parent), abort(false)
27 FileThread::~FileThread()
37 void FileThread::Go(void)
39 QMutexLocker locker(&mutex);
44 Our strategy here is like so:
45 Look at the files in the directory pointed to by ROMPath.
46 For each file in the directory, take the CRC32 of it and compare it to the CRC
47 in the romList[]. If there's a match, put it in a list and note it's index value
48 in romList for future reference.
50 When constructing the list, use the index to pull up an image of the cart and
51 put that in the list. User picks from a graphical image of the cart.
53 Ideally, the label will go into the archive along with the ROM image, but that's
55 Maybe box art, screenshots will go as well...
59 // Here's the thread's actual execution path...
61 void FileThread::run(void)
63 QDir romDir(vjs.ROMPath);
64 // QDir romDir("../virtualjaguar/roms/rarities/");
65 QFileInfoList list = romDir.entryInfoList();
68 Another thing we'll probably have to do here is check for compressed files and
69 decompress/fish around in them to find what we need. :-P
72 for(int i=0; i<list.size(); i++)
77 printf("FileThread: Aborting!!!\n");
84 QFileInfo fileInfo = list.at(i);
86 if (fileInfo.suffix().compare("zip", Qt::CaseInsensitive) == 0)
88 uint8 * buffer = NULL;
89 uint32 size = GetFileFromZIP(fileInfo.canonicalFilePath().toAscii(), FT_SOFTWARE, buffer);
93 //printf("FileThread: About to calc checksum on file with size %u... (buffer=%08X)\n", size, buffer);
94 uint32 crc = crc32_calcCheckSum(buffer, size);
95 uint32 index = FindCRCIndexInFileList(crc);
98 // Mebbe we should pass a index AND a QImage here???
99 if (index != 0xFFFFFFFF && !(romList[index].flags & FF_BIOS))
102 size = GetFileFromZIP(fileInfo.canonicalFilePath().toAscii(), FT_LABEL, buffer);
106 img.loadFromData(buffer, size);
109 //printf("FileThread: Attempted to load image. Size: %u x %u...\n", img.width(), img.height());
111 emit FoundAFile(index);
117 QFile file(romDir.filePath(fileInfo.fileName()));
119 if (file.open(QIODevice::ReadOnly))
121 uint8 * buffer = new uint8[fileInfo.size()];
122 file.read((char *)buffer, fileInfo.size());
124 uint32 crc = crc32_calcCheckSum(buffer, fileInfo.size());
125 uint32 index = FindCRCIndexInFileList(crc);
128 // Mebbe we should pass a index AND a QImage here???
129 if (index != 0xFFFFFFFF && !(romList[index].flags & FF_BIOS))
130 emit FoundAFile(index);
137 // Find a CRC in the ROM list (simple brute force algorithm).
138 // If it's there, return the index, otherwise return $FFFFFFFF
140 uint32 FileThread::FindCRCIndexInFileList(uint32 crc)
142 for(int i=0; romList[i].crc32!=0xFFFFFFFF; i++)
144 if (romList[i].crc32 == crc)