]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/filethread.cpp
11c11ad6958810ffc2648ef902b64dd4f6c93e0e
[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         const uint32 flags;
28 };
29 #endif
30
31 // Should have another flag for whether or not it requires DSP, BIOS,
32 // whether it's a .rom, it's a BIOS, etc...
33
34 RomIdentifier romList[] = {
35         { 0x0509C85E, "Raiden (World)", "raiden.jpg", 0 },
36         { 0x08F15576, "Iron Soldier (World) (v1.04)", "iron-soldier.jpg", 0 },
37         { 0x0957A072, "Kasumi Ninja (World)", "kasumi-ninja.jpg", 0 },
38         { 0x0AC83D77, "NBA Jam T.E. (World)", "nba-jam.jpg", 0 },
39         { 0x0EC5369D, "Evolution - Dino Dudes (World)", "dino-dudes.jpg", 0 },
40         { 0x0F6A1C2C, "Ultra Vortek (World)", "ultra-vortek.jpg", 0 },
41         { 0x14915F20, "White Men Can't Jump (World)", "white-men-can't-jump.jpg", 0 },
42         { 0x1660F070, "Power Drive Rally (World)", "power-drive-rally.jpg", 0 },
43         { 0x1E451446, "Trevor McFur in the Crescent Galaxy (World)", "trevor-mcfur.jpg", 0 },
44         { 0x27594C6A, "Defender 2000 (World)", "defender-2000.jpg", 0 },
45         { 0x2E17D5DA, "Bubsy in Fractured Furry Tales (World)", "bubsy.jpg", 0 },
46         { 0x348E6449, "Double Dragon V - The Shadow Falls (World)", "double-dragon.jpg", 0 },
47         { 0x3615AF6A, "Fever Pitch Soccer (World) (En,Fr,De,Es,It)", "fever-pitch-soccer.jpg", 0 },
48         { 0x38A130ED, "Troy Aikman NFL Football (World)", "troy-aikman-football.jpg", 0 },
49         { 0x3C044941, "Skyhammer (World)", "skyhammer.jpg", 0 },
50         { 0x42A13EC5, "Soccer Kid (World)", "soccer-kid.jpg", 0 },
51         { 0x47EBC158, "Theme Park (World)", "theme-park.jpg", 0 },
52         { 0x4899628F, "Hover Strike (World)", "hover-strike.jpg", 0 },
53         { 0x53DF6440, "Space War 2000 (World)", "", 0 },
54         { 0x55A0669C, "[BIOS] Atari Jaguar Developer CD (World)", "", 0 },
55         { 0x58272540, "Syndicate (World)", "syndicate.jpg", 0 },
56         { 0x5A101212, "Sensible Soccer - International Edition (World)", "sensible-soccer.jpg", 0 },
57         { 0x5B6BB205, "Ruiner Pinball (World)", "ruiner-pinball.jpg", 0 },
58         { 0x5CFF14AB, "Pinball Fantasies (World)", "pinball-fantasies.jpg", 0 },
59         { 0x5E2CDBC0, "Doom (World)", "doom.jpg", 0 },
60         { 0x61C7EEC0, "Zero 5 (World)", "zero-5.jpg", 0 },
61         { 0x67F9AB3A, "Battle Sphere Gold (World)", "", 0 },
62         { 0x687068D5, "[BIOS] Atari Jaguar CD (World)", "", 0 },
63         { 0x6B2B95AD, "Tempest 2000 (World)", "tempest-2000.jpg", 0 },
64         { 0x6EB774EB, "Worms (World)", "worms.jpg", 0 },
65         { 0x6F8B2547, "Super Burnout (World)", "super-burnout.jpg", 0 },
66         { 0x817A2273, "Pitfall - The Mayan Adventure (World)", "pitfall.jpg", 0 },
67         { 0x8975F48B, "Zool 2 (World)", "zool-2.jpg", 0 },
68         { 0x8D15DBC6, "[BIOS] Atari Jaguar Stubulator '94 (World)", "", 0 },
69         { 0x8FEA5AB0, "Dragon - The Bruce Lee Story (World)", "dragon.jpg", 0 },
70         { 0x97EB4651, "I-War (World)", "i-war.jpg", 0 },
71         { 0xA27823D8, "Ultra Vortek (World) (v0.94) (Beta)", "", 0 },
72         { 0xA56D0798, "Protector - Special Edition (World)", "protector-se.jpg", 0 },
73         { 0xA9F8A00E, "Rayman (World)", "rayman.jpg", 0 },
74         { 0xB14C4753, "Fight for Life (World)", "fight-for-life.jpg", 0 },
75         { 0xBCB1A4BF, "Brutal Sports Football (World)", "brutal-sports-football.jpg", 0 },
76         { 0xBDA405C6, "Cannon Fodder (World)", "cannon-fodder.jpg", 0 },
77         { 0xBDE67498, "Cybermorph (World) (Rev 1)", "cybermorph-2mb.jpg", 0 },
78         { 0xC5562581, "Zoop! (World)", "zoop.jpg", 0 },
79         { 0xC654681B, "Total Carnage (World)", "total-carnage.jpg", 0 },
80         { 0xC6C7BA62, "Fight for Life (World) (Alt) [BOGUS DUMP]", "", 0 },
81         { 0xC9608717, "Val d'Isere Skiing and Snowboarding (World)", "val-d'isere-skiing.jpg", 0 },
82         { 0xCBFD822A, "Air Cars (World)", "air-cars.jpg", 0 },
83         { 0xCD5BF827, "Attack of the Mutant Penguins (World)", "attack-of-the-mutant-pengiuns.jpg", 0 },
84         { 0xD6C19E34, "Iron Soldier 2 (World)", "iron-soldier-2.jpg", 0 },
85         { 0xDA9C4162, "Missile Command 3D (World)", "missile-command-3d.jpg", 0 },
86         { 0xDC187F82, "Alien vs Predator (World)", "alien-vs-predator.jpg", 0 },
87         { 0xDE55DCC7, "Flashback - The Quest for Identity (World) (En,Fr)", "flashback.jpg", 0 },
88         { 0xE28756DE, "Atari Karts (World)", "atari-karts.jpg", 0 },
89         { 0xE60277BB, "[BIOS] Atari Jaguar Stubulator '93 (World)", "", 0 },
90         { 0xE91BD644, "Wolfenstein 3D (World)", "wolfenstein-3d.jpg", 0 },
91         { 0xEC22F572, "SuperCross 3D (World)", "supercross-3d.jpg", 0 },
92         { 0xECF854E7, "Cybermorph (World) (Rev 2)", "cybermorph.jpg", 0 },
93         { 0xEEE8D61D, "Club Drive (World)", "club-drive.jpg", 0 },
94         { 0xF0360DB3, "Hyper Force (World)", "hyper-force.jpg", 0 },
95         { 0xFA7775AE, "Checkered Flag (World)", "checkered-flag.jpg", 0 },
96         { 0xFAE31DD0, "Flip Out! (World)", "flip-out.jpg", 0 },
97         { 0xFB731AAA, "[BIOS] Atari Jaguar (World)", "", 0 },
98         { 0xFFFFFFFF, "***END***", "", 0 }
99 };
100 /*
101 breakout-2000.jpg
102 memory-track.jpg
103 protector.jpg
104 towers-2.jpg
105 */
106
107 /*
108 Our strategy here is like so:
109 Look at the files in the directory pointed to by ROMPath.
110 For each file in the directory, take the CRC32 of it and compare it to the CRC
111 in the romList[]. If there's a match, put it in a list and note it's index value
112 in romList for future reference.
113
114 When constructing the list, use the index to pull up an image of the cart and
115 put that in the list. User picks from a graphical image of the cart.
116
117 Ideally, the label will go into the archive along with the ROM image, but that's
118 for the future...
119 Maybe box art, screenshots will go as well...
120 */
121
122 FileThread::FileThread(QObject * parent/*= 0*/): QThread(parent), /*listWidget(NULL),*/ abort(false)
123 {
124 }
125
126 FileThread::~FileThread()
127 {
128         mutex.lock();
129         abort = true;
130         condition.wakeOne();
131         mutex.unlock();
132
133         wait();
134 }
135
136 //void FileThread::Go(QListWidget * lw)
137 void FileThread::Go(void)
138 {
139         QMutexLocker locker(&mutex);
140 //      this->listWidget = lw;
141         start();
142 }
143
144 //
145 // Here's the thread's actual execution path...
146 //
147 void FileThread::run(void)
148 {
149         QDir romDir(vjs.ROMPath);
150         QFileInfoList list = romDir.entryInfoList();
151
152 /*
153 Another thing we'll probably have to do here is check for compressed files and
154 decompress/fish around in them to find what we need. :-P
155 */
156
157         for(int i=0; i<list.size(); i++)
158         {
159                 if (abort)
160 #if 1
161 {
162 printf("FileThread: Aborting!!!\n");
163 #endif
164                         return;
165 #if 1
166 }
167 #endif
168
169                 QFileInfo fileInfo = list.at(i);
170                 QFile file(romDir.filePath(fileInfo.fileName()));
171                 uint8 * buffer = new uint8[fileInfo.size()];
172
173                 if (file.open(QIODevice::ReadOnly))
174                 {
175                         file.read((char *)buffer, fileInfo.size());
176                         uint32 crc = crc32_calcCheckSum(buffer, fileInfo.size());
177                         file.close();
178 //printf("FilePickerWindow: File crc == %08X...\n", crc);
179
180                         uint32 index = FindCRCIndexInFileList(crc);
181
182                         if (index != 0xFFFFFFFF)
183                         {
184 //printf("FileThread: Found match [%s]...\n", romList[index].name);
185 //                              new QListWidgetItem(QIcon(":/res/generic.png"), romList[index].name, listWidget);
186 //                              emit FoundAFile(romList[index].crc32);
187                                 emit FoundAFile(index);
188                         }
189                 }
190
191                 delete[] buffer;
192         }
193 }
194
195 //
196 // Find a CRC in the ROM list (simple brute force algorithm).
197 // If it's there, return the index, otherwise return $FFFFFFFF
198 //
199 uint32 FileThread::FindCRCIndexInFileList(uint32 crc)
200 {
201         for(int i=0; romList[i].crc32!=0xFFFFFFFF; i++)
202         {
203                 if (romList[i].crc32 == crc)
204                         return i;
205         }
206
207         return 0xFFFFFFFF;
208 }
209