]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/filethread.cpp
Moving towards a better file picker... :-)
[virtualjaguar] / src / gui / filethread.cpp
1 //
2 // filethread.cpp - File discovery thread
3 //
4 // by James L. Hammons
5 // (C) 2010 Underground Software
6 //
7 // JLH = James L. Hammons <jlhamm@acm.org>
8 //
9 // Who  When        What
10 // ---  ----------  -------------------------------------------------------------
11 // JLH  01/28/2010  Created this file
12 //
13
14 #include "filethread.h"
15
16 #include <QtGui>
17 #include "crc32.h"
18 #include "settings.h"
19 //#include "types.h"
20
21 #if 0
22 struct RomIdentifier
23 {
24         const uint32 crc32;
25         const char name[128];
26         const char file[128];
27 };
28 #endif
29
30 RomIdentifier romList[] = {
31         { 0x0509C85E, "Raiden (World)", "" },
32         { 0x08F15576, "Iron Soldier (World) (v1.04)", "" },
33         { 0x0957A072, "Kasumi Ninja (World)", "" },
34         { 0x0AC83D77, "NBA Jam T.E. (World)", "" },
35         { 0x0EC5369D, "Evolution - Dino Dudes (World)", "" },
36         { 0x0F6A1C2C, "Ultra Vortek (World)", "" },
37         { 0x14915F20, "White Men Can't Jump (World)", "" },
38         { 0x1660F070, "Power Drive Rally (World)", "" },
39         { 0x1E451446, "Trevor McFur in the Crescent Galaxy (World)", "" },
40         { 0x27594C6A, "Defender 2000 (World)", "" },
41         { 0x2E17D5DA, "Bubsy in Fractured Furry Tales (World)", "" },
42         { 0x348E6449, "Double Dragon V - The Shadow Falls (World)", "" },
43         { 0x3615AF6A, "Fever Pitch Soccer (World) (En,Fr,De,Es,It)", "" },
44         { 0x38A130ED, "Troy Aikman NFL Football (World)", "" },
45         { 0x3C044941, "Skyhammer (World)", "" },
46         { 0x42A13EC5, "Soccer Kid (World)", "" },
47         { 0x47EBC158, "Theme Park (World)", "" },
48         { 0x4899628F, "Hover Strike (World)", "" },
49         { 0x53DF6440, "Space War 2000 (World)", "" },
50         { 0x55A0669C, "[BIOS] Atari Jaguar Developer CD (World)", "" },
51         { 0x58272540, "Syndicate (World)", "" },
52         { 0x5A101212, "Sensible Soccer - International Edition (World)", "" },
53         { 0x5B6BB205, "Ruiner Pinball (World)", "" },
54         { 0x5CFF14AB, "Pinball Fantasies (World)", "" },
55         { 0x5E2CDBC0, "Doom (World)", "" },
56         { 0x61C7EEC0, "Zero 5 (World)", "" },
57         { 0x67F9AB3A, "Battle Sphere Gold (World)", "" },
58         { 0x687068D5, "[BIOS] Atari Jaguar CD (World)", "" },
59         { 0x6B2B95AD, "Tempest 2000 (World)", "" },
60         { 0x6EB774EB, "Worms (World)", "" },
61         { 0x6F8B2547, "Super Burnout (World)", "" },
62         { 0x817A2273, "Pitfall - The Mayan Adventure (World)", "" },
63         { 0x8975F48B, "Zool 2 (World)", "" },
64         { 0x8D15DBC6, "[BIOS] Atari Jaguar Stubulator '94 (World)", "" },
65         { 0x8FEA5AB0, "Dragon - The Bruce Lee Story (World)", "" },
66         { 0x97EB4651, "I-War (World)", "" },
67         { 0xA27823D8, "Ultra Vortek (World) (v0.94) (Beta)", "" },
68         { 0xA56D0798, "Protector - Special Edition (World)", "" },
69         { 0xA9F8A00E, "Rayman (World)", "" },
70         { 0xB14C4753, "Fight for Life (World)", "" },
71         { 0xBCB1A4BF, "Brutal Sports Football (World)", "" },
72         { 0xBDA405C6, "Cannon Fodder (World)", "" },
73         { 0xBDE67498, "Cybermorph (World) (Rev 1)", "" },
74         { 0xC5562581, "Zoop! (World)", "" },
75         { 0xC654681B, "Total Carnage (World)", "" },
76         { 0xC6C7BA62, "Fight for Life (World) (Alt)", "" },
77         { 0xC9608717, "Val d'Isere Skiing and Snowboarding (World)", "" },
78         { 0xCBFD822A, "Air Cars (World)", "" },
79         { 0xCD5BF827, "Attack of the Mutant Penguins (World)", "" },
80         { 0xD6C19E34, "Iron Soldier 2 (World)", "" },
81         { 0xDA9C4162, "Missile Command 3D (World)", "" },
82         { 0xDC187F82, "Alien vs Predator (World)", "" },
83         { 0xDE55DCC7, "Flashback - The Quest for Identity (World) (En,Fr)", "" },
84         { 0xE28756DE, "Atari Karts (World)", "" },
85         { 0xE60277BB, "[BIOS] Atari Jaguar Stubulator '93 (World)", "" },
86         { 0xE91BD644, "Wolfenstein 3D (World)", "" },
87         { 0xEC22F572, "SuperCross 3D (World)", "" },
88         { 0xECF854E7, "Cybermorph (World) (Rev 2)", "" },
89         { 0xEEE8D61D, "Club Drive (World)", "" },
90         { 0xF0360DB3, "Hyper Force (World)", "" },
91         { 0xFA7775AE, "Checkered Flag (World)", "" },
92         { 0xFAE31DD0, "Flip Out! (World)", "" },
93         { 0xFB731AAA, "[BIOS] Atari Jaguar (World)", "" },
94         { 0xFFFFFFFF, "***END***", "" }
95 };
96
97 /*
98 Our strategy here is like so:
99 Look at the files in the directory pointed to by ROMPath.
100 For each file in the directory, take the CRC32 of it and compare it to the CRC
101 in the romList[]. If there's a match, put it in a list and note it's index value
102 in romList for future reference.
103
104 When constructing the list, use the index to pull up an image of the cart and
105 put that in the list. User picks from a graphical image of the cart.
106
107 Ideally, the label will go into the archive along with the ROM image, but that's
108 for the future...
109 Maybe box art, screenshots will go as well...
110 */
111
112 FileThread::FileThread(QObject * parent/*= 0*/): QThread(parent), /*listWidget(NULL),*/ abort(false)
113 {
114 }
115
116 FileThread::~FileThread()
117 {
118         mutex.lock();
119         abort = true;
120         condition.wakeOne();
121         mutex.unlock();
122
123         wait();
124 }
125
126 //void FileThread::Go(QListWidget * lw)
127 void FileThread::Go(void)
128 {
129         QMutexLocker locker(&mutex);
130 //      this->listWidget = lw;
131         start();
132 }
133
134 //
135 // Here's the thread's actual execution path...
136 //
137 void FileThread::run(void)
138 {
139         QDir romDir(vjs.ROMPath);
140         QFileInfoList list = romDir.entryInfoList();
141
142 /*
143 Another thing we'll probably have to do here is check for compressed files and
144 decompress/fish around in them to find what we need. :-P
145 */
146
147         for(int i=0; i<list.size(); i++)
148         {
149                 if (abort)
150 #if 1
151 {
152 printf("FileThread: Aborting!!!\n");
153 #endif
154                         return;
155 #if 1
156 }
157 #endif
158
159                 QFileInfo fileInfo = list.at(i);
160                 QFile file(romDir.filePath(fileInfo.fileName()));
161                 uint8 * buffer = new uint8[fileInfo.size()];
162
163                 if (file.open(QIODevice::ReadOnly))
164                 {
165                         file.read((char *)buffer, fileInfo.size());
166                         uint32 crc = crc32_calcCheckSum(buffer, fileInfo.size());
167                         file.close();
168 //printf("FilePickerWindow: File crc == %08X...\n", crc);
169
170                         uint32 index = FindCRCIndexInFileList(crc);
171
172                         if (index != 0xFFFFFFFF)
173                         {
174 //printf("FileThread: Found match [%s]...\n", romList[index].name);
175 //                              new QListWidgetItem(QIcon(":/res/generic.png"), romList[index].name, listWidget);
176 //                              emit FoundAFile(romList[index].crc32);
177                                 emit FoundAFile(index);
178                         }
179                 }
180
181                 delete[] buffer;
182         }
183 }
184
185 //
186 // Find a CRC in the ROM list (simple brute force algorithm).
187 // If it's there, return the index, otherwise return $FFFFFFFF
188 //
189 uint32 FileThread::FindCRCIndexInFileList(uint32 crc)
190 {
191         for(int i=0; romList[i].crc32!=0xFFFFFFFF; i++)
192         {
193                 if (romList[i].crc32 == crc)
194                         return i;
195         }
196
197         return 0xFFFFFFFF;
198 }
199