-
Notifications
You must be signed in to change notification settings - Fork 4
/
compatibility-generator.php
191 lines (161 loc) · 6.56 KB
/
compatibility-generator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php
/***
* ares compatibility database seeder
* This script iterates through a set of redump/no-intro datfiles and generates a game database
* and static pages for the ares compatibility list
*
*/
function progressBar($done, $total) {
$perc = floor(($done / $total) * 100);
$left = 100 - $perc;
$write = sprintf("\033[0G\033[2K[%'={$perc}s>%-{$left}s] - $perc%% - $done/$total", "", "");
fwrite(STDERR, $write);
}
// Cleanup old system markdown files
$dir = new DirectoryIterator('compatibility');
foreach ($dir as $fileinfo) {
if (!$fileinfo->isDot() && $fileinfo->getExtension() == 'md') {
unlink($fileinfo->getRealPath());
}
}
$dir = new DirectoryIterator("_data/datfiles/");
foreach ($dir as $fileinfo) {
if (!$fileinfo->isDot() && $fileinfo->getExtension() == 'dat') {
// Step 1: Generate json from DAT files
$xml = simplexml_load_file($fileinfo->getRealPath());
$info = [];
$info['header'] = [];
$info['games'] = [];
$info['header'] = [
'name' => (string)$xml->header->name,
'description' => (string)$xml->header->description,
'version' => (string)$xml->header->version,
'homepage' => (string)$xml->header->homepage,
'url' => (string)$xml->header->url
];
foreach($info['header'] as $key => &$value) {
$value = str_replace(' (BigEndian)', '', $value);
$value = str_replace(' (Decrypted)', '', $value);
}
$total = count($xml->game);
$completed = 0;
$jsonFile = '_data/romsets/'.$info['header']['name'].'.json';
echo "Generating ".$jsonFile."\n";
foreach($xml->game as $game) {
$completed++;
// Attempt to skip bios files and other non-game content
$ignoredStrings = [
'[BIOS]', // Bios/Firmware
'[Prototype', // Neo Geo
'[Homebrew', // Neo Geo
'[Demo', // Neo Geo
'[Bootleg', // Neo Geo
'[Hack', // Neo Geo
'(Demo',
'(Sample',
'(Beta',
'(beta', // Neo Geo
'Beta)',
'(Proto',
'(Program)',
'(Pirate)',
'(bootleg', // Neo Geo
'[hack', // Neo Geo
'(hack', // Neo Geo
'hack)', // Neo Geo
'Hack)', // Neo Geo
'EEZEZY)', // Neo Geo
'(Unl)',
'(Test Program)',
// Exclude emulated re-release roms
'(Sega Channel)',
'(SegaNet)',
'(Sega Ages)',
'(PC Rerelease)',
'(Wii',
'Wii)',
'(Virtual Console',
'Virtual Console)',
'(iQue)',
'Switch Online)',
'Collection)',
'Mini)',
// TOSEC
'[a', // 'alternate' sets
'[b', // known bad dumps
'[f', // fixed (modified)
'[h', // hacks
'[m', // modified
'[cr', // cracked copies
'[t', // Trainer applied and/or translation [tr]
'[u', // Under-dumped
'[o', // Over-dumped
'[v', // infected with virus
'[p', // remove private copies
'[re-release]',
// Atari,
'(Atari Anthology)',
'Atari 7800 Development Card (USA)'
];
foreach($ignoredStrings as $string) {
if (str_contains($game['name'], $string)) { continue 2; }
if (str_contains($game['description'], $string)) continue 2;
if (str_contains($game->description, $string)) continue 2;
}
// HACK: Jekyll falls over when encountering "...", so filter it out
$name = str_replace('...', '', $game['name']);
$info['games'][] = [
'name' => (string)$name,
'description' => (string)$game->description,
];
progressBar($completed, $total);
}
// Sort games by name
usort($info['games'], function($a, $b) {
return strcasecmp($a['name'], $b['name']);
});
// Merge multi-disc games together
foreach($info['games'] as &$game) {
if(preg_match("/\((Disc|Disk|Side|Tape)[^)]+\)/", $game['name'])) {
$nameWithoutDisc = preg_replace("/\((Disc|Disk|Side|Tape)[^)]+\)/","", $game['name']);
$descriptionWithoutDisc = preg_replace("/\((Disc|Disk|Side|Tape)[^)]+\)/","", $game['description']);
foreach($info['games'] as $key => $otherGame) {
// Prevent removing the parent entry
if ($otherGame['name'] == $game['name']) continue;
$otherGame['name'] = preg_replace("/\((Disc|Disk|Side|Tape)[^)]+\)/","", $otherGame['name']);
if ($nameWithoutDisc == $otherGame['name']) {
unset($info['games'][$key]);
}
}
$game['name'] = $nameWithoutDisc;
$game['description'] = $descriptionWithoutDisc;
}
$info['games'] = array_values($info['games']);
}
file_put_contents($jsonFile, json_encode($info, JSON_PRETTY_PRINT));
// Step 2: Generate static compatibility pages for systems/games
$content = "---\n".
"layout: compatibility\n".
"title: \"".$info['header']['name']."\"\n".
"---\n";
file_put_contents('compatibility/'.$info['header']['name'].'.md', $content);
// Step 3: Generate edit pages for systems/games
$content = "---\n".
"layout: compatibility-edit\n".
"title: \"".$info['header']['name']."\"\n".
"---\n";
file_put_contents('compatibility/'.$info['header']['name'].'-edit.md', $content);
$systemPath = 'compatibility/'.$info['header']['name'].'/';
// Cleanup old markdown files
if (file_exists($systemPath)) {
$dir = new DirectoryIterator($systemPath);
foreach ($dir as $fileinfo) {
if (!$fileinfo->isDot() && $fileinfo->getExtension() == 'md') {
unlink($fileinfo->getRealPath());
}
}
}
echo "\n";
}
}
?>