]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/filepicker.cpp
e8a44d1bad7ea9d88d32fb99bd71fa06170afdff
[virtualjaguar] / src / gui / filepicker.cpp
1 //
2 // filepicker.cpp - A ROM chooser
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/22/2010  Created this file
12 //
13
14 #include "filepicker.h"
15
16 #include "crc32.h"
17 #include "filelistmodel.h"
18 #include "filethread.h"
19 #include "settings.h"
20 #include "types.h"
21
22 struct RomIdentifier
23 {
24         const uint32 crc32;
25         const char name[128];
26         const char file[128];
27 };
28
29 RomIdentifier romList2[] = {
30         { 0x0509C85E, "Raiden (World)", "" },
31         { 0x08F15576, "Iron Soldier (World) (v1.04)", "" },
32         { 0x0957A072, "Kasumi Ninja (World)", "" },
33         { 0x0AC83D77, "NBA Jam T.E. (World)", "" },
34         { 0x0EC5369D, "Evolution - Dino Dudes (World)", "" },
35         { 0x0F6A1C2C, "Ultra Vortek (World)", "" },
36         { 0x14915F20, "White Men Can't Jump (World)", "" },
37         { 0x1660F070, "Power Drive Rally (World)", "" },
38         { 0x1E451446, "Trevor McFur in the Crescent Galaxy (World)", "" },
39         { 0x27594C6A, "Defender 2000 (World)", "" },
40         { 0x2E17D5DA, "Bubsy in Fractured Furry Tales (World)", "" },
41         { 0x348E6449, "Double Dragon V - The Shadow Falls (World)", "" },
42         { 0x3615AF6A, "Fever Pitch Soccer (World) (En,Fr,De,Es,It)", "" },
43         { 0x38A130ED, "Troy Aikman NFL Football (World)", "" },
44         { 0x3C044941, "Skyhammer (World)", "" },
45         { 0x42A13EC5, "Soccer Kid (World)", "" },
46         { 0x47EBC158, "Theme Park (World)", "" },
47         { 0x4899628F, "Hover Strike (World)", "" },
48         { 0x53DF6440, "Space War 2000 (World)", "" },
49         { 0x55A0669C, "[BIOS] Atari Jaguar Developer CD (World)", "" },
50         { 0x58272540, "Syndicate (World)", "" },
51         { 0x5A101212, "Sensible Soccer - International Edition (World)", "" },
52         { 0x5B6BB205, "Ruiner Pinball (World)", "" },
53         { 0x5CFF14AB, "Pinball Fantasies (World)", "" },
54         { 0x5E2CDBC0, "Doom (World)", "" },
55         { 0x61C7EEC0, "Zero 5 (World)", "" },
56         { 0x67F9AB3A, "Battle Sphere Gold (World)", "" },
57         { 0x687068D5, "[BIOS] Atari Jaguar CD (World)", "" },
58         { 0x6B2B95AD, "Tempest 2000 (World)", "" },
59         { 0x6EB774EB, "Worms (World)", "" },
60         { 0x6F8B2547, "Super Burnout (World)", "" },
61         { 0x817A2273, "Pitfall - The Mayan Adventure (World)", "" },
62         { 0x8975F48B, "Zool 2 (World)", "" },
63         { 0x8D15DBC6, "[BIOS] Atari Jaguar Stubulator '94 (World)", "" },
64         { 0x8FEA5AB0, "Dragon - The Bruce Lee Story (World)", "" },
65         { 0x97EB4651, "I-War (World)", "" },
66         { 0xA27823D8, "Ultra Vortek (World) (v0.94) (Beta)", "" },
67         { 0xA56D0798, "Protector - Special Edition (World)", "" },
68         { 0xA9F8A00E, "Rayman (World)", "" },
69         { 0xB14C4753, "Fight for Life (World)", "" },
70         { 0xBCB1A4BF, "Brutal Sports Football (World)", "" },
71         { 0xBDA405C6, "Cannon Fodder (World)", "" },
72         { 0xBDE67498, "Cybermorph (World) (Rev 1)", "" },
73         { 0xC5562581, "Zoop! (World)", "" },
74         { 0xC654681B, "Total Carnage (World)", "" },
75         { 0xC6C7BA62, "Fight for Life (World) (Alt)", "" },
76         { 0xC9608717, "Val d'Isere Skiing and Snowboarding (World)", "" },
77         { 0xCBFD822A, "Air Cars (World)", "" },
78         { 0xCD5BF827, "Attack of the Mutant Penguins (World)", "" },
79         { 0xD6C19E34, "Iron Soldier 2 (World)", "" },
80         { 0xDA9C4162, "Missile Command 3D (World)", "" },
81         { 0xDC187F82, "Alien vs Predator (World)", "" },
82         { 0xDE55DCC7, "Flashback - The Quest for Identity (World) (En,Fr)", "" },
83         { 0xE28756DE, "Atari Karts (World)", "" },
84         { 0xE60277BB, "[BIOS] Atari Jaguar Stubulator '93 (World)", "" },
85         { 0xE91BD644, "Wolfenstein 3D (World)", "" },
86         { 0xEC22F572, "SuperCross 3D (World)", "" },
87         { 0xECF854E7, "Cybermorph (World) (Rev 2)", "" },
88         { 0xEEE8D61D, "Club Drive (World)", "" },
89         { 0xF0360DB3, "Hyper Force (World)", "" },
90         { 0xFA7775AE, "Checkered Flag (World)", "" },
91         { 0xFAE31DD0, "Flip Out! (World)", "" },
92         { 0xFB731AAA, "[BIOS] Atari Jaguar (World)", "" },
93         { 0xFFFFFFFF, "***END***", "" }
94 };
95
96 /*
97 Our strategy here is like so:
98 Look at the files in the directory pointed to by ROMPath.
99 For each file in the directory, take the CRC32 of it and compare it to the CRC
100 in the romList[]. If there's a match, put it in a list and note it's index value
101 in romList for future reference.
102
103 When constructing the list, use the index to pull up an image of the cart and
104 put that in the list. User picks from a graphical image of the cart.
105
106 Ideally, the label will go into the archive along with the ROM image, but that's
107 for the future...
108 Maybe box art, screenshots will go as well...
109 */
110
111 //FilePickerWindow::FilePickerWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Dialog)//could use Window as well...
112 FilePickerWindow::FilePickerWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Window)
113 {
114         setWindowTitle("Insert Cartridge...");
115
116 #if 1
117         fileList2 = new QListWidget(this);
118 //      addWidget(fileList);
119
120         QVBoxLayout * layout = new QVBoxLayout();
121 //      layout->setSizeConstraint(QLayout::SetFixedSize);
122         setLayout(layout);
123
124         layout->addWidget(fileList2);
125
126 //      PopulateList();
127         fileThread = new FileThread(this);
128
129         /*bool b =*/ connect(fileThread, SIGNAL(FoundAFile(unsigned long)), this, SLOT(AddFileToList(unsigned long)));
130 //printf("FilePickerWindow: Connection to FileThread %s...\n", (b ? "succeeded" : "failed"));
131
132         fileThread->Go(fileList2);
133 #else
134 QStringList numbers;
135 numbers << "One" << "Two" << "Three" << "Four" << "Five";
136
137 QAbstractItemModel * model = new StringListModel(numbers);
138 QListView * view = new QListView;
139 view->setModel(model);
140
141 #endif
142 }
143
144 // Need a slot here to pickup stuff from the thread...
145
146 void FilePickerWindow::AddFileToList(unsigned long index)
147 {
148         printf("--> Found CRC: %08X...\n", (uint32)index);
149 }
150
151
152 /*
153 void FilePickerWindow::PopulateList(void)
154 {
155         QDir romDir(vjs.ROMPath);
156         QFileInfoList list = romDir.entryInfoList();
157
158         for(int i=0; i<list.size(); i++)
159         {
160                 QFileInfo fileInfo = list.at(i);
161 //         std::cout << qPrintable(QString("%1 %2").arg(fileInfo.size(), 10)
162 //                                                 .arg(fileInfo.fileName()));
163 //         std::cout << std::endl;
164                 QFile file(romDir.filePath(fileInfo.fileName()));
165                 uint8 * buffer = new uint8[fileInfo.size()];
166
167                 if (file.open(QIODevice::ReadOnly))
168                 {
169                         file.read((char *)buffer, fileInfo.size());
170                         uint32 crc = crc32_calcCheckSum(buffer, fileInfo.size());
171                         file.close();
172 //printf("FilePickerWindow: File crc == %08X...\n", crc);
173
174                         for(int j=0; romList2[j].crc32 != 0xFFFFFFFF; j++)
175                         {
176                                 if (romList2[j].crc32 == crc)
177                                 {
178 printf("FilePickerWindow: Found match [%s]...\n", romList2[j].name);
179                                         new QListWidgetItem(QIcon(":/res/generic.png"), romList2[j].name, fileList);
180                                         break;
181                                 }
182                         }
183                 }
184
185                 delete[] buffer;
186         }
187 }
188 */