This is a bulk cleanup of all of the functions that have since been
surpassed by their desktop counterparts. A lot of effort went into these
original features but the effort that was expended to make the desktop
better far exceeded this. I thank the efforts of everyone who helped to
make the web version a reality in the first place since it provided the
strong base that SabreTools has become. This will still be maintained
purely as a way of checking files online as will be required when the
WoD DATs are properly recreated.
This commit is contained in:
Matt Nadareski
2016-07-28 11:02:20 -07:00
parent f5222fad76
commit d3acae2ed7
26 changed files with 5 additions and 4487 deletions

View File

@@ -1,124 +0,0 @@
<?php
/* ------------------------------------------------------------------------------------
Clean duplicates and orphaned checksums from the database
Original code by Matt Nadareski (darksabre76)
------------------------------------------------------------------------------------ */
//http://stackoverflow.com/questions/18932/how-can-i-remove-duplicate-rows
// Delete dupes from games
$query = "DELETE games
FROM games LEFT OUTER JOIN (
SELECT MIN(id) as id, system, name, parent, source
FROM games
GROUP BY system, name, parent, source
) as KeepRows ON
games.id = KeepRows.id
WHERE KeepRows.id IS NULL";
$result = mysqli_query($link, $query);
if (gettype($result) == "boolean" && $result)
{
echo "Deleting game dupes succeeded!<br/>\n";
}
else
{
echo "Deleting game dupes failed!<br/>\n".mysqli_error($link);
}
// Delete dupes from files
$query = "DELETE files
FROM files LEFT OUTER JOIN (
SELECT MIN(id) as id, setid, name, type, lastupdated
FROM files
GROUP BY setid, name, type, lastupdated
) as KeepRows ON
files.id = KeepRows.id
WHERE KeepRows.id IS NULL";
if (gettype($result) == "boolean" && $result)
{
echo "Deleting file dupes succeeded!<br/>\n";
}
else
{
echo "Deleting file dupes failed!<br/>\n".mysqli_error($link);
}
// Delete orphaned files
$query = "DELETE FROM files
WHERE NOT EXISTS (
SELECT *
FROM games
WHERE files.setid = games.id)";
$result = mysqli_query($link, $query);
if (gettype($result) == "boolean" && $result)
{
echo "Deleting file orphans succeeded!<br/>\n";
}
else
{
echo "Deleting file orphans failed!<br/>\n".mysqli_error($link);
}
// Delete orphaned checksums
$query = "DELETE FROM checksums
WHERE NOT EXISTS (
SELECT *
FROM files
WHERE checksums.file = files.id)";
$result = mysqli_query($link, $query);
if (gettype($result) == "boolean" && $result)
{
echo "Deleting checksum orphans succeeded!<br/>\n";
}
else
{
echo "Deleting checksum orphans failed!<br/>\n".mysqli_error($link);
}
// Fix the names of games that have spacing issues
$query = "SELECT * FROM games
WHERE name LIKE ' %'
ORDER BY name ASC";
$result = mysqli_query($link, $query);
while ($line = mysqli_fetch_assoc($result))
{
$query = "UPDATE games
SET name='".trim($line["name"])."'
WHERE id=".$line["id"];
$result2 = mysqli_query($link, $query);
if (gettype($result2) == "boolean" && $result2)
{
echo "Trimming game names succeeded!<br/>\n";
}
else
{
echo "Trimming game names failed!<br/>\n".mysqli_error($link);
}
}
// Fix the names of files that have spacing issues
$query = "SELECT * FROM files
WHERE name LIKE ' %'
ORDER BY name ASC";
$result = mysqli_query($link, $query);
while ($line = mysqli_fetch_assoc($result))
{
$query = "UPDATE files
SET name='".trim($line["name"])."'
WHERE id=".$line["id"];
$result2 = mysqli_query($link, $query);
if (gettype($result2) == "boolean" && $result2)
{
echo "Trimming file names succeeded!<br/>\n";
}
else
{
echo "Trimming file names failed!<br/>\n".mysqli_error($link);
}
}
?>

View File

@@ -1,144 +0,0 @@
<?php
/* ------------------------------------------------------------------------------------
Deheader files in a folder
Original code by Matt Nadareski (darksabre76)
Requires:
dir Directory to deheader files from
type Type of the roms to be deheadered
------------------------------------------------------------------------------------ */
// Type mapped to header size (in decimal bytes)
$types = array(
"a7800" => 128,
"fds" => 16,
"lynx" => 64,
"nes" => 16,
"snes" => 512,
);
$dir = (isset($_GET["dir"]) ? urldecode($_GET["dir"]) : "");
$type = (isset($_GET["type"]) ? $_GET["type"] : "");
echo "<h2>Remove File Headers</h2>";
// If the directory isn't set or it's not a directory, prompt the user to enter a directory and set which type it is
if (trim($dir) == "" || !is_dir($dir))
{
echo <<<EOL
<form type="get">
<input type="hidden" name="page" value="deheader">
<b>Enter a directory name: </b> <input type="text" name="dir"><p/>
<b>Select rom type: </b><br/>
EOL;
foreach ($types as $typename => $val)
{
echo "\t<input type=\"radio\" name=\"type\" value=\"".$typename."\">".$typename."<br/>\n";
}
echo <<<EOL
<br/>
<input type="submit" value="Submit"><br/>
</form><p/>
EOL;
}
// If a directory is given but the type isn't defined or it's incorrect, give the options for file type
elseif (trim($type) == "" || !$types[$type] === "")
{
echo <<<EOL
<form type="get">
<input type="hidden" name="page" value="deheader">
<input type="hidden" name="dir" value="$dir">
<b>Select rom type: </b><br/>
EOL;
foreach ($types as $typename => $val)
{
echo "\t<input type=\"radio\" name=\"type\" value=\"".$typename."\">".$typename."<br/>\n";
}
echo <<<EOL
<br/>
<input type="submit" value="Submit"><br/>
</form><p/>
EOL;
}
// Otherwise, process the folder
else
{
$dir = $dir."/";
$roms = scandir($dir);
echo "<table>\n<tr><th>Name</th><th>Has Header</th></tr>\n";
foreach ($roms as $rom)
{
if ($rom == "." || $rom == ".." || is_dir($dir.$rom))
{
continue;
}
$hs = $types[$type];
$handle = fopen($dir.$rom, "r");
$header = fread($handle, $hs);
$header = bin2hex($header);
$header = strtoupper($header);
switch ($type)
{
case "a7800":
$a7800a = preg_match("/^.415441524937383030/", $header);
$a7800b = preg_match("/^.{64}41435455414C20434152542044415441205354415254532048455245/", $header);
$has_header = ($a7800a == 1 || $a7800b == 1);
break;
case "fds":
$fdsa = preg_match("/^4644531A010000000000000000000000/", $header);
$fdsb = preg_match("/^4644531A020000000000000000000000/", $header);
$fdsc = preg_match("/^4644531A030000000000000000000000/", $header);
$fdsd = preg_match("/^4644531A040000000000000000000000/", $header);
$has_header = ($fdsa == 1 || $fdsb == 1 || $fdsc == 1 || $fdsd == 1);
break;
case "lynx":
$lynxa = preg_match("/^4C594E58/", $header);
$lynxb = preg_match("/^425339/", $header);
$has_header = ($lynxa == 1 || $lynxb == 1);
break;
case "nes":
$nes = preg_match("/^4E45531A/", $header);
$has_header = ($nes == 1);
break;
case "snes":
$fig = preg_match("/^.{16}0000000000000000/", $header);
$smc = preg_match("/^.{16}AABB040000000000/", $header);
$ufo = preg_match("/^.{16}535550455255464F/", $header);
$has_header = ($fig == 1 || $smc == 1 || $ufo == 1);
break;
default:
$has_header = false;
break;
}
echo "<tr><td>".$rom."</td><td style='text-align: center'>".($has_header ? "true" : "false")."</td></tr>\n";
if ($has_header)
{
$data = fread($handle, filesize($dir.$rom) - 512);
$outhandle = fopen($dir.$rom.".new", "w");
fwrite($outhandle, $data);
fclose($outhandle);
}
fclose($handle);
}
echo "</table>\n";
}
?>

View File

@@ -1,874 +0,0 @@
<?php
/* ------------------------------------------------------------------------------------
Add, edit, and remove data from the database manually.
Original code by Matt Nadareski (darksabre76)
TODO: Add search functionality
------------------------------------------------------------------------------------ */
// All possible $_GET variables that we can use (propogate this to other files?)
$getvars = array(
"system", // systems.id
"source", // sources.id
"game", // games.id
"file", // files.id
"offset", // offset for pagination
"remove", // enable deletion mode, see $rmopts for more details
);
// All possible $_POST variables that we can use
$postvars = array(
"system", // systems.id (-1 for new)
"manufacturer", // systems.manufacturer
"systemname", // systems.system
"source", // sources.id (-1 for new)
"sourcename", // sources.name
"url", // sources.url
"game", // games.id (-1 for new)
"gamename", // games.name
"file", // files.id (-1 for new)
"filename", // files.name
"type", // files.type
"size", // checksums.size
"crc", // checksums.crc
"md5", // checksums.md5
"sha1", // checksums.sha1
);
// All possible values for $_GET["remove"]
$rmopts = array(
"system", // set all former games with system to have system 0, requires system
"source", // set all former games with source to have source 0, requires source
"game", // delete all files and checksums associated, requires game
"file", // delete all checksums associated, requires file
);
//Get the values for all parameters
foreach ($getvars as $var)
{
$$var = (isset($_GET[$var]) && $_GET[$var] != "-1" ? trim($_GET[$var]) : "");
}
//Get thve values for all POST vars ($_GET overrides)
foreach ($postvars as $var)
{
if (!isset($$var) || $$var == "")
{
$$var = (isset($_POST[$var]) ? $_POST[$var] : "");
}
}
// Set the special check values
$source_set = $source != "";
$system_set = $system != "";
// Handle the remove cases. They have to be mutually exclusive
if (in_array($remove, $rmopts))
{
// If a system is being removed (can't remove default)
if ($remove == "system" && $system != "" && $system != "0")
{
$query = "DELETE FROM system where id=".$system;
$result = mysqli_query($link, $query);
if (gettype($result) == "boolean" && $result)
{
echo "System deleted successfully! Altering all related files.<br/>";
$query = "UPDATE games SET system=0 WHERE system=".$system;
$result = mysqli_query($link, $query);
if (gettype($result) == "boolean" && $result)
{
echo "Files altered successfully! No further action required.<br/>";
}
else
{
echo "Something has gone wrong, please manually alter all files with system '".$system."' to have value 0<br/>";
}
}
else
{
echo "System could not be deleted. Try again later.<br/>";
}
}
// If a source is being removed (can't remove default)
elseif ($remove == "source" && $source != "" && $source != "0")
{
$query = "DELETE FROM source where id=".$system;
$result = mysqli_query($link, $query);
if (gettype($result) == "boolean" && $result)
{
echo "Source deleted successfully! Altering all related files.<br/>";
$query = "UPDATE games SET source=0 WHERE source=".$source;
$result = mysqli_query($link, $query);
if (gettype($result) == "boolean" && $result)
{
echo "Files altered successfully! No further action required.<br/>";
}
else
{
echo "Something has gone wrong, please manually alter all files with source '".$source."' to have value 0<br/>";
}
}
else
{
echo "System could not be deleted. Try again later.<br/>";
}
}
// If a game is being removed
elseif ($remove == "game" && $game != "")
{
$query = "DELETE FROM games
JOIN files
ON games.id=files.setid
JOIN checksums
ON files.id=checksums.file
WHERE games.id=".$game;
$result = mysqli_query($link, $query);
if (gettype($result) == "boolean" && $result)
{
echo "Game and dependent files deleted successfully!<br/>";
}
else
{
echo "Could not delete game or dependent files. Please try again<br/>";;
}
}
// If a file is being removed
elseif ($remove == "file" && $file != "")
{
$query = "DELETE FROM files
JOIN checksums
ON files.id=checksums.file
WHERE files.id=".$file;
$result = mysqli_query($link, $query);
if (gettype($result) == "boolean" && $result)
{
echo "File deleted successfully!<br/>";
}
else
{
echo "Could not delete file. Please try again<br/>";;
}
}
}
// Handle the POST cases. They do not have to be mutually exclusive
else
{
// If a system is being edited or added via POST
if ($system != "" && $manufacturer != "" && $systemname != "")
{
// If the system is new and being added
if ($system == "-1")
{
// Always check if this exact combination is already there. This might have been in error
$query = "SELECT * FROM systems WHERE manufacturer='".$manufacturer." AND system='".$systemname."'";
$result = mysqli_query($link, $query);
// If we find this system, tell the user and don't move forward
if (gettype($result) != "boolean" && mysqli_num_rows($result) > 0)
{
echo "This system has been found. No further action is required<br/>";
}
// If the system is not found, add it
else
{
$query = "INSERT INTO systems (manufacturer, system) VALUES ('".$manufacturer."', '".$systemname."')";
$result = mysqli_query($link, $query);
if (gettype($result) == "boolean" && $result)
{
echo "The system '".$manufacturer." - ".$systemname."' has been added successfully!<br/>";
}
else
{
echo "The system '".$manufacturer." - ".$systemname."' could not be added, try again later<br/>";
}
}
}
// If the system is being edited
else
{
// Check if the system exists first
$query = "SELECT * FROM systems WHERE id=".$system;
$result = mysqli_query($link, $query);
// If we don't find the system, don't add it. This might have been in error
if (gettype($result) == "boolean" && !$result)
{
echo "The system with id '".$system."' could not be found, try again later<br/>";
}
// If we find the system, update with the new information, if not a duplicate of another
else
{
$query = "SELECT * FROM systems WHERE manufacturer='".$manufacturer." AND system='".$systemname."'";
$result = mysqli_query($link, $query);
// If the system is found or unchanged, don't readd it
if (gettype($result) != "boolean" && mysqli_num_rows($result) > 0)
{
echo "This system has been found. No further action is required<br/>";
}
// If the system really has changed or is not a duplicate, add it
else
{
$query = "UPDATE systems SET manufacturer='".$manufacturer."', system='".$systemname."' WHERE id=".$system;
$result = mysqli_query($link, $query);
if (gettype($result) == "boolean" && $result)
{
echo "The system '".$manufacturer." - ".$systemname."' has been updated successfully!<br/>";
}
else
{
echo "The system '".$manufacturer." - ".$systemname."' could not be updated, try again later<br/>";
}
}
}
}
}
// If a source is being edited or added via POST
if ($source != "" && $sourcename != "" && $url != "")
{
// If the source is new and being added
if ($source == "-1")
{
// Always check if this exact combination is already there. This might have been in error
$query = "SELECT * FROM sources WHERE name='".$sourcename."'";
$result = mysqli_query($link, $query);
// If we find this source, tell the user and don't move forward
if (gettype($result) != "boolean" && mysqli_num_rows($result) > 0)
{
echo "This source has been found. No further action is required<br/>";
}
// If the source is not found, add it
else
{
$query = "INSERT INTO sources (name, url) VALUES ('".$sourcename."', '".$url."')";
$result = mysqli_query($link, $query);
if (gettype($result) == "boolean" && $result)
{
echo "The source '".$sourcename."' has been added successfully!<br/>";
}
else
{
echo "The source '".$sourcename."' could not be added, try again later<br/>";
}
}
}
// If the source is being edited
else
{
// Check if the source exists first
$query = "SELECT * FROM sources WHERE id=".$system;
$result = mysqli_query($link, $query);
// If we don't find the source, don't add it. This might have been in error
if (gettype($result) == "boolean" && !$result)
{
echo "The source with id '".$source."' could not be found, try again later<br/>";
}
// If we find the source, update with the new information, if not a duplicate of another
else
{
$query = "SELECT * FROM sources WHERE name='".$sourcename."'";
$result = mysqli_query($link, $query);
// If the source is found or unchanged, don't readd it
if (gettype($result) != "boolean" && mysqli_num_rows($result) > 0)
{
echo "This source has been found. No further action is required<br/>";
}
// If the source really has changed or is not a duplicate, add it
else
{
$query = "UPDATE sources SET name='".$sourcename."', url='".$url."' WHERE id=".$source;
$result = mysqli_query($link, $query);
if (gettype($result) == "boolean" && $result)
{
echo "The source '".$sourcename."' has been updated successfully!<br/>";
}
else
{
echo "The source '".$sourcename."' could not be updated, try again later<br/>";
}
}
}
}
}
// If a game is being edited or added via POST
if ($game != "" && $gamename != "" && $system != "" && $source != "")
{
// If the game is new and being added
if ($game == "-1")
{
// Always check if this exact combination is already there. This might have been in error
$query = "SELECT * FROM games WHERE name='".$gamename."' AND system=".$system." AND source=".$source;
$result = mysqli_query($link, $query);
// If we find this game, tell the user and don't move forward
if (gettype($result) != "boolean" && mysqli_num_rows($result) > 0)
{
echo "This game has been found. No further action is required<br/>";
}
// If the game is not found, add it
else
{
$query = "INSERT INTO games (name, system, source) VALUES ('".$gamename."', ".$system.", ".$source.")";
$result = mysqli_query($link, $query);
if (gettype($result) == "boolean" && $result)
{
echo "The game '".$gamename."' has been added successfully!<br/>";
}
else
{
echo "The game '".$gamename."' could not be added, try again later<br/>";
}
}
}
// If the game is being edited
else
{
// Check if the game exists first
$query = "SELECT * FROM games WHERE id=".$game;
$result = mysqli_query($link, $query);
// If we don't find the game, don't add it. This might have been in error
if (gettype($result) == "boolean" && !$result)
{
echo "The game with id '".$game."' could not be found, try again later<br/>";
}
// If we find the game, update with the new information, if not a duplicate of another
else
{
$query = "SELECT * FROM games WHERE name='".$gamename."' AND system=".$system." AND source=".$source;
$result = mysqli_query($link, $query);
// If the game is found elsewhere or unchanged, don't readd it
if (gettype($result) != "boolean" && mysqli_num_rows($result) > 0)
{
echo "This source has been found. No further action is required<br/>";
}
// If the game really has changed or is not a duplicate, add it
else
{
$query = "UPDATE game SET name='".$gamename."', system=".$system.", source=".$source." WHERE id=".$game;
$result = mysqli_query($link, $query);
if (gettype($result) == "boolean" && $result)
{
echo "The game '".$gamename."' has been updated successfully!<br/>";
}
else
{
echo "The game '".$gamename."' could not be updated, try again later<br/>";
}
}
}
}
}
// If a file is being edited or added via POST
if ($file != "" && $filename != "" && $game != "" && $type != "" &&
(($type == "rom" && $size != "" && ($crc != "" || $md5 != "" || $sha1 != "")) ||
($type == "disk" && ($md5 != "" || $sha1 != ""))))
{
// If the file is new and being added
if ($file == "-1")
{
// Always check if this exact combination is already there. This might have been in error
$query = "SELECT * FROM files
JOIN checksums ON files.id=checksums.file
WHERE files.name='".$filename.
"' AND files.setid=".$game.
" AND files.type='".$type.
"' AND checksums.size=".$size.
"' AND checksums.crc='".$crc.
"' AND checksums.md5='".$md5.
"' AND checksums.sha1='".$sha1;
$result = mysqli_query($link, $query);
// If we find this file, tell the user and don't move forward
if (gettype($result) != "boolean" && mysqli_num_rows($result) > 0)
{
echo "This file has been found. No further action is required<br/>";
}
// If the file is not found, add it
else
{
$query = "INSERT INTO files (name, game, type)
VALUES ('".$filename."', ".$game.", ".$type.")";
$result = mysqli_query($link, $query);
if (gettype($result) == "boolean" && $result)
{
echo "The file '".$filename."' has been added successfully! Adding checksums.<br/>";
$file = mysqli_insert_id($link);
$query = "INSERT INTO checksums (game, size, crc, md5, sha1)
VALUES (".$game.", ".$size.", '".$crc."', '".$md5."', '".$sha1."')";
$result = mysqli_query($link, $query);
if (gettype($result) == "boolean" && $result)
{
echo "The checksums have been added!<br/>";
}
else
{
echo "The checksums could not be added, please try again later<br/>";
}
}
else
{
echo "The file '".$filename."' could not be added, try again later<br/>";
}
}
}
// If the file is being edited
else
{
// Check if the file exists first
$query = "SELECT * FROM files WHERE id=".$file;
$result = mysqli_query($link, $query);
// If we don't find the file, don't add it. This might have been in error
if (gettype($result) == "boolean" && !$result)
{
echo "The game with id '".$file."' could not be found, try again later<br/>";
}
// If we find the file, update with the new information, if not a duplicate of another
else
{
$query = "SELECT * FROM files
JOIN checksums ON files.id=checksums.file
WHERE files.name='".$filename.
"' AND files.setid=".$game.
" AND files.type='".$type.
"' AND checksums.size=".$size.
"' AND checksums.crc='".$crc.
"' AND checksums.md5='".$md5.
"' AND checksums.sha1='".$sha1;
$result = mysqli_query($link, $query);
// If the file is found elsewhere or unchanged, don't readd it
if (gettype($result) != "boolean" && mysqli_num_rows($result) > 0)
{
echo "This file has been found. No further action is required<br/>";
}
// If the source really has changed or is not a duplicate, add it
else
{
$query = "UPDATE file
JOIN checksums ON files.id=checksums.file
SET files.name='".$filename.
"' AND files.setid=".$game.
" AND files.type='".$type.
"' AND checksums.size=".$size.
"' AND checksums.crc='".$crc.
"' AND checksums.md5='".$md5.
"' AND checksums.sha1='".$sha1;
$result = mysqli_query($link, $query);
if (gettype($result) == "boolean" && $result)
{
echo "The file '".$filename."' has been updated successfully!<br/>";
}
else
{
echo "The file '".$filename."' could not be updated, try again later<br/>";
}
}
}
}
}
}
// Assuming there are no relevent params (or processing POST is done), show the basic page
if ($system == "" && $source == "" && $game == "" && $file == "")
{
show_default($link);
}
// First and foremost, capture file edit mode. It's exclusive above all others.
elseif ($file != "")
{
// Retrieve the file info
$query = "SELECT files.id AS file,
files.name AS name,
files.type AS type,
checksums.size AS size,
checksums.crc AS crc,
checksums.md5 AS md5,
checksums.sha1 AS sha1
FROM files
JOIN checksums
ON files.id=checksums.file
WHERE files.id=".$file;
$result = mysqli_query($link, $query);
$rom = mysqli_fetch_assoc($result);
// Now output the editable information
echo "<form action='index.php?page=edit' method='post'>
<input type='hidden' name='file' value='".$file."' />
<table>
<tr>
<th>Name</th>
<td><input type='text' name='filename' value='".$rom["name"]."' /></td>
</tr>
<tr>
<th>Type</th>
<td><select name='type' id='type'>
<option value='rom'".($rom["type"] == "rom" ? " selected='selected'" : "").">rom</option>
<option value='disk'".($rom["type"] == "disk" ? " selected='selected'" : "").">disk</option>
</td>
</tr>
<tr>
<th>Size</th>
<td><input type='text' name='size' value='".$rom["size"]."' /></td>
</tr>
<tr>
<th>CRC</th>
<td><input type='text' name='crc' value='".$rom["crc"]."' /></td>
</tr>
<tr>
<th>MD5</th>
<td><input type='text' name='md5' value='".$rom["md5"]."' /></td>
</tr>
<tr>
<th>SHA-1</th>
<td><input type='text' name='sha1' value='".$rom["sha1"]."' /></td>
</tr>
</table>
<input type='submit'>
</form><br/>";
}
// Then capture game edit mode, it also takes precidence over the others.
elseif ($game != "")
{
// Retrieve the system listing
$query = "SELECT id, manufacturer, system FROM systems
ORDER BY manufacturer ASC,
system ASC";
$result = mysqli_query($link, $query);
$systems = array();
while ($row = mysqli_fetch_assoc($result))
{
array_push($systems, $row);
}
// Retrieve the sources listing
$query = "SELECT id, name FROM sources
ORDER BY name ASC";
$result = mysqli_query($link, $query);
$sources = array();
while ($row = mysqli_fetch_assoc($result))
{
array_push($sources, $row);
}
// Get the total count in the case that it needs limiting
$query = "SELECT COUNT(*) as count
FROM systems
JOIN games
ON systems.id=games.system
JOIN sources
ON games.source=sources.id
JOIN files
ON games.id=files.setid
JOIN checksums
ON files.id=checksums.file
WHERE games.id=".$game;
$count = mysqli_query($link, $query);
$count = mysqli_fetch_assoc($count);
$count = $count["count"];
settype($count, "integer");
// Retrieve the game info
$query = "SELECT systems.manufacturer AS manufacturer,
systems.system AS system,
systems.id AS systemid,
sources.name AS source,
sources.id AS sourceid,
games.name AS game,
files.id AS file,
files.name AS name,
files.type AS type,
checksums.size AS size,
checksums.crc AS crc,
checksums.md5 AS md5,
checksums.sha1 AS sha1
FROM systems
JOIN games
ON systems.id=games.system
JOIN sources
ON games.source=sources.id
JOIN files
ON games.id=files.setid
JOIN checksums
ON files.id=checksums.file
WHERE games.id=".$game.
" LIMIT 50 OFFSET ".($offset == "" ? "0" : ($offset*5)."0");
$result = mysqli_query($link, $query);
if (gettype($result) == "boolean" || mysqli_num_rows($result) == 0)
{
echo "No game info could be retrieved! There might be an error.<br/>";
exit;
}
$roms = mysqli_fetch_all($result);
$game_info = $roms[0];
echo "<form action='index.php?page=edit' method='post'>
<input type='hidden' name='game' value='".$game."'/>
<h2>Edit the Game Information Below</h2>
<table>
<tr>
<th width='100px'>System</th>
<td><select name='system' id='system'>\n";
foreach ($systems as $system)
{
echo "\t\t<option value='".$system["id"]."'".
($system["id"] == $game_info[2] ? " selected='selected'" : "").
">".$system["manufacturer"]." - ".$system["system"]."</option>\n";
}
echo "\t</select></td>
</tr>
<tr>
<th>Source</th>
<td><select name='source' id='source'>\n";
foreach ($sources as $source)
{
echo "\t\t<option value='".$source["id"]."'".
($source["id"] == $game_info[4] ? " selected='selected'" : "").
">".$source["name"]."</option>\n";
}
echo "\t</select></td>
</tr>
<tr>
<th>Name</th>
<td><input type='text' name='gamename' value='".$game_info[5]."'/></td>
</tr>
</table><br/>
<table>
<tr>
<th></th><th>Name</th><th>Type</th><th>Size</th><th>CRC</th><th>MD5</th><th>SHA-1</th>
</tr>";
foreach ($roms as $rom)
{
echo "<tr>
<td><input type='radio' name='file' value='".$rom[6]."'/></td>";
for ($i = 7; $i < 13; $i++)
{
echo "<td>".$rom[$i]."</td>";
}
echo "</tr>\n";
}
echo "</table>".
"<input type='submit'>\n</form><br/>";
echo "<br/>";
if ($offset != "" && $offset > 0)
{
echo "<a href='?page=edit&system=".$system."&source=".$source."&game=".$game."&offset=".($offset-1)."'>Last 50</a> ";
}
if ($count > (mysqli_num_rows($result) + ($offset == "" ? 0 : $offset*50)))
{
echo "<a href='?page=edit&system=".$system."&source=".$source."&game=".$game."&offset=".($offset+1)."'>Next 50</a>";
}
echo "<br/>";
echo "<a href='?page=edit".
($source_set ? "&source='".$source : "").
($system_set ? "&system='".$system : "").
"'>Back to previous page</a><br/>\n";
}
else
{
// Retrieve source info only so it's not duplicated
if ($source_set)
{
$query = "SELECT name, url FROM sources WHERE id='".$source."'";
$source_result = mysqli_query($link, $query);
$source_info = mysqli_fetch_assoc($source_result);
}
// Retrieve system info only so it's not duplicated
if ($system_set)
{
$query = "SELECT manufacturer, system FROM systems WHERE id='".$system."'";
$system_result = mysqli_query($link, $query);
$system_info = mysqli_fetch_assoc($system_result);
}
// Get the total count in the case that it needs limiting
$query = "SELECT COUNT(*) as count
FROM systems
JOIN games
ON systems.id=games.system
JOIN sources
ON games.source=sources.id
WHERE ".
($source_set ? "sources.id=".$source : "").
($source_set && $system_set ? " AND " : "").
($system_set ? "systems.id=".$system : "");
$count = mysqli_query($link, $query);
$count = mysqli_fetch_assoc($count);
$count = $count["count"];
settype($count, "integer");
// Then get all games assocated
$query = "SELECT games.name AS name,
games.id AS id,
systems.manufacturer AS manufacturer,
systems.system AS system,
sources.name AS source
FROM systems
JOIN games
ON systems.id=games.system
JOIN sources
ON games.source=sources.id
WHERE ".
($source_set ? "sources.id=".$source : "").
($source_set && $system_set ? " AND " : "").
($system_set ? "systems.id=".$system : "").
" ORDER BY games.name ASC
LIMIT 50 OFFSET ".($offset == "" ? "0" : ($offset*5)."0");
$games_result = mysqli_query($link, $query);
echo "<form action='index.php?page=edit".
($source_set ? "&source=".$source : "").
($system_set ? "&system=".$system : "").
"' method='post'>\n";
if ($source_set)
{
echo "<input type='hidden' name='source' value='".$source."' />\n".
"<b>Source:</b> <input type='text' name='sourcename' value='".$source_info["name"]."' />\n".
"<b>URL(s):</b> <input type='text' name='url' value='".$source_info["url"]."' /><br/>\n";
}
if ($system_set)
{
echo "<input type='hidden' name='system' value='".$system."' />\n".
"<b>Manufacturer:</b> <input type='text' name='manufacturer' value='".$system_info["manufacturer"]."' />\n".
"<b>Name:</b> <input type='text' name='system' value='".$system_info["system"]."' /><br/>\n";
}
echo "<input type='submit'>\n</form><br/>\n";
echo "<h2>Games With This ".
($source_set ? "Source" : "").
($source_set && $system_set ? " And " : "").
($system_set ? "System" : "")."</h2>\n";
if (gettype($games_result) != "boolean")
{
while ($game = mysqli_fetch_assoc($games_result))
{
echo "<a href='?page=edit&game=".$game["id"]."'>".$game["name"];
if ($source_set && !$system_set)
{
echo " (".$game["manufacturer"]." - ".$game["system"].")";
}
if (!$source_set && $system_set)
{
echo " (".$game["source"].")";
}
echo "</a><br/>\n";
}
echo "<br/>";
if ($offset != "" && $offset > 0)
{
echo "<a href='?page=edit&system=".$system."&source=".$source."&offset=".($offset-1)."'>Last 50</a> ";
}
if ($count > (mysqli_num_rows($games_result) + ($offset == "" ? 0 : $offset*50)))
{
echo "<a href='?page=edit&system=".$system."&source=".$source."&offset=".($offset+1)."'>Next 50</a>";
}
echo "<br/>";
}
else
{
echo "No games could be found!";
}
echo "<br/>";
}
// Requires the mysqli link
function show_default($link)
{
// Retrieve the system listing
$query = "SELECT id, manufacturer, system FROM systems
ORDER BY manufacturer ASC,
system ASC";
$result = mysqli_query($link, $query);
$systems = array();
while ($row = mysqli_fetch_assoc($result))
{
array_push($systems, $row);
}
// Retrieve the sources listing
$query = "SELECT id, name FROM sources
ORDER BY name ASC";
$result = mysqli_query($link, $query);
$sources = array();
while ($row = mysqli_fetch_assoc($result))
{
array_push($sources, $row);
}
// Output the input selection form
echo <<<END
<form action='index.php' method='get'>
<input type='hidden' name='page' value='edit' />
<h2>Select a System or Source</h2>
<select name='system' id='system'>
<option value='' selected='selected'>Choose a System</option>
END;
foreach ($systems as $system)
{
echo "<option value='".$system["id"]."'>".$system["manufacturer"]." - ".$system["system"]."</option>\n";
}
echo "</select>
<select name='source' id='source'>
<option value='' selected='selected'>Choose a Source</option>";
foreach ($sources as $source)
{
echo "<option value='".$source["id"]."'>".$source["name"]."</option>\n";
}
echo "</select><p/>
<input type='submit'>
</form>
<h2>Or Add a New One</h2>
<form action='index.php?page=edit&source=-1&system=-1' method='post'>
<h3>Source Add</h3>
<b>Name:</b> <input type='text' name='sourcename' value='".$source_info["name"]."' />
<b>URL(s):</b> <input type='text' name='url' value='".$source_info["url"]."' /><br/>
<h3>System Add</h3>
<b>Manufacturer:</b> <input type='text' name='manufacturer' value='".$system_info["manufacturer"]."' />
<b>Name:</b> <input type='text' name='systemname' value='".$system_info["system"]."' /><br/><br/>
<input type='submit'>\n</form><p/>\n";
}
?>

View File

@@ -1,564 +0,0 @@
<?php
/* ------------------------------------------------------------------------------------
Import an existing DAT into the system
Original code by Matt Nadareski (darksabre76)
Requires:
filename File name in one of a few formats, see $datpattern
size Sort the list by size of the DAT file (handy for multiple imports)
TODO: Auto-generate DATs affected by import (merged and custom)?
TODO: Figure out if some systems need to have their data removed before importing again
e.g. TOSEC, Redump, TruRip
TODO: RomCenter format? http://www.logiqx.com/DatFAQs/RomCenter.php
Seems based on INI format; see PHP reference http://php.net/manual/en/function.parse-ini-file.php
------------------------------------------------------------------------------------ */
echo "<h2>Import From Datfile</h2>";
ini_set('max_execution_time', 0); // Set the execution time to infinite. This is a bad idea in production.
// Verify GET variables
$auto = isset($_GET["auto"]) && $_GET["auto"] == "1";
$size = isset($_GET["size"]) && $_GET["size"] == "1";
// Set import path
$importroot = "../temp/import/";
if (!isset($_GET["filename"]))
{
// List all files, auto-generate links to proper pages
echo "<p><a href='?page=import&auto=1".($size ? "&size=1" : "")."'>Automatically add all DATs</a><br/>\n".
"<a href='?page=import'>Sort list by name</a><br/>\n".
"<a href='?page=import&size=1'>Sort list by size</a></p>\n";
$files = scandir($importroot);
if (sizeof($files) != 0)
{
if ($size)
{
usort($files, function ($a, $b)
{
global $importroot;
$size_a = filesize($importroot.$a);
$size_b = filesize($importroot.$b);
return $size_a - $size_b;
});
}
foreach ($files as $file)
{
if (preg_match("/^.*\.dat$/", $file) || preg_match("/^.*\.xml$/", $file))
{
// If we want to import everything in the folder...
if ($auto)
{
import_dat($file);
sleep(1);
echo "<script type='text/javascript'>window.location='?page=import&auto=1".
($size ? "&size=1" : "").
"'</script>";
}
else
{
echo "<a href=\"?page=import&filename=".$file.
($size ? "&size=1" : "").
"\">".htmlspecialchars($file)."</a> (".filesize($importroot.$file)." bytes)<br/>\n";
}
}
}
}
}
else
{
import_dat($_GET["filename"]);
sleep(1);
echo "<script type='text/javascript'>window.location='?page=import".($size ? "&size=1" : "")."'</script>";
}
function import_dat ($filename)
{
global $link, $normalize_chars, $search_pattern, $importroot,
$mapping_mame, $mapping_nointro, $mapping_redump, $mapping_tosec, $mapping_trurip;
$_defaultPattern = @"/^(.+?) - (.+?) \((.*) (.*)\)\.dat$/";
$_mamePattern = @"/^(.*)\.xml$/";
$_noIntroPattern = @"/^(.*?) \((\d{8}-\d{6})_CM\)\.dat$/";
$_noIntroNumberedPattern = @"/(.*? - .*?) \(\d.*?_CM\).dat/";
$_noIntroSpecialPattern = @"/(.*? - .*?) \((\d{8})\)\.dat/";
$_redumpPattern = @"/^(.*?) \((\d{8} \d{2}-\d{2}-\d{2})\)\.dat$/";
$_redumpBiosPattern = @"/^(.*?) \(\d+\) \((\d{4}-\d{2}-\d{2})\)\.dat$/";
$_tosecPattern = @"/^(.*?) - .* \(TOSEC-v(\d{4}-\d{2}-\d{2})_CM\)\.dat$/";
$_tosecSpecialPatternA = @"/^(.*? - .*?) - .* \(TOSEC-v(\d{4}-\d{2}-\d{2})_CM\)\.dat$/";
$_tosecSpecialPatternB = @"/^(.*? - .*? - .*?) - .* \(TOSEC-v(\d{4}-\d{2}-\d{2})_CM\)\.dat$/";
$_truripPattern = @"/^(.*) - .* \(trurip_XML\)\.dat$/";
// Regex Mapped Name Patterns
$_remappedPattern = @"/^(.*) - (.*)$/";
// Regex Date Patterns
$_defaultDatePattern = @"/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/";
$_noIntroDatePattern = @"/(\d{4})(\d{2})(\d{2})-(\d{2})(\d{2})(\d{2})/";
$_noIntroSpecialDatePattern = @"/(\d{4})(\d{2})(\d{2})/";
$_redumpDatePattern = @"/(\d{4})(\d{2})(\d{2}) (\d{2})-(\d{2})-(\d{2})/";
$_tosecDatePattern = @"/(\d{4})-(\d{2})-(\d{2})/";
// Check the file is valid
if (!file_exists($importroot.$filename))
{
echo "<b>The file you supply must be in ".$importroot."</b><br/>";
echo "<a href='?page=import".($size ? "&size=1" : "")."'>Go back to import page</a>";
return;
}
// Then determine the type of the DAT
$type = "";
if (preg_match($_mamePattern, $filename, $fileinfo))
{
$type = "mame";
}
elseif (preg_match($_noIntroPattern, $filename, $fileinfo))
{
$type = "nointro";
}
// For numbered DATs only
elseif (preg_match($_noIntroNumberedPattern, $filename, $fileinfo))
{
$type = "nointro";
}
// For N-Gage and Gizmondo only
elseif (preg_match($_noIntroSpecialPattern, $filename, $fileinfo))
{
$type = "nointro";
}
elseif (preg_match($_redumpPattern, $filename, $fileinfo))
{
$type = "redump";
}
// For special BIOSes only
elseif (preg_match($_redumpBiosPattern, $filename, $fileinfo))
{
$type = "redump";
}
elseif (preg_match($_tosecPattern, $filename, $fileinfo))
{
$type = "tosec";
}
elseif (preg_match($_truripPattern, $filename, $fileinfo))
{
$type = "trurip";
}
elseif (preg_match($_defaultPattern, $filename, $fileinfo))
{
$type = "custom";
}
else
{
echo "<b>DAT type could not be determined from file name!</b><br/>\n";
echo "<a href='?page=import".($size ? "&size=1" : "")."'>Go back to import page</a>";
return;
}
echo "<p>The file ".$filename." has a proper pattern!</p>\n";
// Next, get information from the database on the current machine
switch ($type)
{
case "mame":
preg_match($_remappedPattern, $mapping_mame[$fileinfo[1]], $name);
$manufacturer = $name[1];
$system = $name[2];
$source = "MAME";
$datestring = filemtime($importroot.$filename);
$date = date("Y-m-d G:i:s", $datestring);
break;
case "nointro":
preg_match($_remappedPattern, $mapping_nointro[$fileinfo[1]], $name);
$manufacturer = $name[1];
$system = $name[2];
$source = "no-Intro";
if (fileinfo.Count < 2)
{
$date = date("Y-m-d H:i:s", filemtime($importroot.$filename));
}
elseif (preg_match($_noIntroDatePattern, $fileinfo[2]))
{
$datestring = $fileinfo[2];
preg_match($_noIntroDatePattern, $datestring, $date);
$date = $date[1]."-".$date[2]."-".$date[3]." ".$date[4].":".$date[5].":".$date[6];
}
else
{
$datestring = $fileinfo[2];
preg_match($_noIntroSpecialDatePattern, $datestring, $date);
$date = $date[1]."-".$date[2]."-".$date[3]." 00:00:00";
}
break;
case "redump":
if (!isset($mapping_redump[$fileinfo[1]]))
{
// Handle special case mappings found only in Redump
preg_match($_redumpBiosPattern, $filename, $fileinfo);
if (!isset($mapping_redump[$fileinfo[1]]))
{
echo "The filename ".$fileinfo[1]." could not be mapped! Please check the mappings and try again";
return false;
}
}
preg_match($_remappedPattern, $mapping_redump[$fileinfo[1]], $name);
$manufacturer = $name[1];
$system = $name[2];
$source = "Redump";
$datestring = $fileinfo[2];
preg_match($_redumpDatePattern, $datestring, $date);
$date = $date[1]."-".$date[2]."-".$date[3]." ".$date[4].":".$date[5].":".$date[6];
break;
case "tosec":
// If it's a special case, try to see if it's one of the odd TOSEC's
if (!isset($mapping_tosec[$fileinfo[1]]))
{
preg_match($_tosecSpecialPatternA, $filename, $fileinfo);
if (!isset($mapping_tosec[$fileinfo[1]]))
{
preg_match($_tosecSpecialPatternB, $filename, $fileinfo);
if (!isset($mapping_tosec[$fileinfo[1]]))
{
echo "The filename ".$fileinfo[1]." could not be mapped! Please check the mappings and try again";
return false;
}
}
}
preg_match($_remappedPattern, $mapping_tosec[$fileinfo[1]], $name);
$manufacturer = $name[1];
$system = $name[2];
$source = "TOSEC";
$datestring = $fileinfo[2];
preg_match($_tosecDatePattern, $datestring, $date);
$date = $date[1]."-".$date[2]."-".$date[3]." 00:00:00";
break;
case "trurip":
preg_match($_remappedPattern, $mapping_trurip[$fileinfo[1]], $name);
$manufacturer = $name[1];
$system = $name[2];
$source = "trurip";
$datestring = filemtime($importroot.$filename);
$date = date("Y-m-d G:i:s", $datestring);
break;
case "custom":
default:
$manufacturer = $fileinfo[1];
$system = $fileinfo[2];
$source = $fileinfo[3];
$datestring = $fileinfo[4];
preg_match($_defaultDatePattern, $datestring, $date);
$date = $date[1]."-".$date[2]."-".$date[3]." ".$date[4].":".$date[5].":".$date[6];
break;
}
$query = "SELECT id
FROM systems
WHERE manufacturer='$manufacturer'
AND system='$system'";
$result = mysqli_query($link, $query);
if (!gettype($result) == "boolean" || mysqli_num_rows($result) == 0)
{
echo('Error: No suitable system found! Please add the system and then try again<br/>');
return;
}
$sysid = mysqli_fetch_assoc($result);
$sysid = $sysid["id"];
$query = "SELECT id
FROM sources
WHERE name='".$source."'";
$result = mysqli_query($link, $query);
if (!gettype($result) == "boolean" || mysqli_num_rows($result) == 0)
{
echo('Error: No suitable source found! Please add the source and then try again<br/>');
return;
}
$srcid = mysqli_fetch_assoc($result);
$srcid = $srcid["id"];
// Try to open the file as XML
$superdat = false;
$xmlr = new XmlReader;
// If the file doesn't start with the right thing, convert it
$handle = fopen($importroot.$filename, "r");
if ($handle === false)
{
echo "The file was not valid!<p/>\n";
return;
}
$file = fgets($handle);
fclose($handle);
if (strpos($file, "<") !== 0)
{
$xmlr->XML(rv2xml($importroot.$filename));
}
else
{
$result = $xmlr->open($importroot.$filename);
// If it can't be opened, then it doesn't exist
if (!$result)
{
echo "The file was not valid!<p/>\n";
return;
}
}
// Read until we find the main body
while ($xmlr->name !== "datafile" && $xmlr->name !== "softwarelist")
{
$xmlr->read();
}
// Now find the header inside of that
while ($xmlr->name !== "header")
{
$xmlr->read();
}
// Check for SuperDAT mode by finding the name
while ($xmlr->name !== "name")
{
$xmlr->read();
}
if (strpos($xmlr->readString(), " - SuperDAT") !== false)
{
$superdat = true;
}
// Now seek to the end of the header
while (!($xmlr->name === "header" && $xmlr->nodeType === XMLReader::END_ELEMENT))
{
$xmlr->read();
}
// Now loop over the main body
echo "<h3>Roms Added:</h3>
<table border='1'>
<tr><th>Machine</th><th>Rom</th><th>Size</th><th>CRC32</th><th>MD5</th><th>SHA1</th></tr>\n";
while ($xmlr->read())
{
//var_dump($xmlr->name, $xmlr->nodeType, $xmlr->depth, $xmlr->readString(), "<br/>\n");
// For each game, find all of the roms inside of it
if ($xmlr->nodeType === XMLReader::ELEMENT && ($xmlr->name == "machine" || $xmlr->name == "game" || $xmlr->name == "software"))
{
$gameid = 0;
$tempname = "";
if ($xmlr->name == "software")
{
while ($xmlr->name != "description")
{
$xmlr->read();
}
$tempname = $xmlr->readString();
}
else
{
$tempname = $xmlr->getAttribute("name");
}
// If we're in SuperDAT mode, strip the folder out
if ($superdat)
{
preg_match("/.*?\\(.*)/", $tempname, $tempname);
$tempname = $tempname[1];
}
$gameid = add_game($sysid, $tempname, $srcid);
// For each of the roms in the machine
$delim = $xmlr->name;
while ($xmlr->read() && $xmlr->name != $delim)
{
// If we find a rom or disk, add it
if ($xmlr->nodeType === XMLReader::ELEMENT && ($xmlr->name == "rom" || $xmlr->name == "disk"))
{
// If there's no name, skip it because it can't be added
$name = "";
if ($xmlr->getAttribute("name") === null)
{
continue;
}
// Take care of hex-sized files
$size = -1;
if ($xmlr->getAttribute("size") !== null && strpos($xmlr->getAttribute("size"), "0x") !== false)
{
$size = hexdec($xmlr->getAttribute("size"));
}
elseif ($xmlr->getAttribute("size") !== null)
{
$size = (real)$xmlr->getAttribute("size");
}
add_rom($tempname,
$xmlr->name,
$gameid,
$xmlr->getAttribute("name"),
$date,
$size,
($xmlr->getAttribute("crc") !== null ? trim($xmlr->getAttribute("crc")) : ""),
($xmlr->getAttribute("md5") !== null ? trim($xmlr->getAttribute("md5")) : ""),
($xmlr->getAttribute("sha1") !== null ? trim($xmlr->getAttribute("sha1")) : "")
);
}
}
}
}
$xmlr->close();
echo "</table><p/>\n";
// Add the imported file to the zip and delete
$extfilename = $importroot.$filename;
$zip = new ZipArchive();
$zip->open("../temp/imported".($type != "" ? "-".$type : "").".zip", ZIPARCHIVE::CREATE);
$zip->addFile($extfilename, $filename);
$zip->close();
unlink($extfilename);
}
function add_game ($sysid, $machinename, $srcid)
{
global $link, $normalize_chars, $search_pattern;
// WoD gets rid of anything past the first "(" or "[" as the name, we will do the same
preg_match("/(([[(].*[\)\]] )?([^([]+))/", $machinename, $machinename);
$machinename = $machinename[1];
// Run the name through the filters to make sure that it's correct
$machinename = strtr($machinename, $normalize_chars);
$machinename = ru2lat($machinename);
$machinename = preg_replace($search_pattern["EXT"], $search_pattern["REP"], $machinename);
$machinename = trim($machinename);
// This is an issue, apparently
if ($machinename == "")
{
echo "</table><br/>\n";
die("Machinename is blank!");
}
$query = "SELECT id
FROM games
WHERE system=".$sysid."
AND name='".addslashes($machinename)."'
AND source=".$srcid;
$result = mysqli_query($link, $query);
if (gettype($result) == "boolean" || mysqli_num_rows($result) == 0)
{
$query = "INSERT INTO games (system, name, source)
VALUES (".$sysid.", '".addslashes($machinename)."', ".$srcid.")";
$result = mysqli_query($link, $query);
$gameid = mysqli_insert_id($link);
}
else
{
$gameid = mysqli_fetch_assoc($result);
$gameid = $gameid["id"];
}
return $gameid;
}
function add_rom ($machinename, $romtype, $gameid, $name, $date, $size, $crc, $md5, $sha1)
{
global $link, $normalize_chars, $search_pattern;
// Run the name through the filters to make sure that it's correct
$name = strtr($name, $normalize_chars);
$name = ru2lat($name);
$name = str_replace($search_pattern["EXT"], $search_pattern["REP"], $name);
// WOD origninally stripped out any subdirs from the imported files, we do the same
$name = explode("\\", $name);
$name = $name[sizeof($name) - 1];
if ($romtype != "rom" && $romtype != "disk")
{
$romtype = "rom";
}
// Check for the existance of the rom in the given system and game
// If it doesn't exist, create the rom with the information provided
$query = "SELECT files.id
FROM files
JOIN checksums
ON files.id=checksums.file
WHERE files.name='".addslashes($name)."' ".
"AND files.type='".$romtype."' ".
"AND files.setid=".$gameid." ".
($size != "" ? " AND checksums.size=".$size : "").
($crc != "" ? " AND checksums.crc='".$crc."'" : "").
($md5 != "" ? " AND checksums.md5='".$md5."'" : "").
($sha1 != "" ? " AND checksums.sha1='".$sha1."'" : "");
$result = mysqli_query($link, $query);
if (gettype($result) == "boolean" || mysqli_num_rows($result) == 0)
{
$query = "INSERT INTO files (setid, name, type, lastupdated)
VALUES (".$gameid.",
'".addslashes($name)."',
'".$romtype."',
'".$date."')";
$result = mysqli_query($link, $query);
if (gettype($result) == "boolean" && $result)
{
$romid = mysqli_insert_id($link);
$query = "INSERT INTO checksums (file".
($size != "" ? ", size" : "").
($crc != "" ? ", crc" : "").
($md5!= "" ? ", md5" : "").
($sha1 != "" ? ", sha1" : "").
")
VALUES (".$romid.
($size != "" ? ", ".$size : "").
($crc != "" ? ", '".strtolower($crc)."'" : "").
($md5 != "" ? ", '".strtolower($md5)."'" : "").
($sha1 != "" ? ", '".strtolower($sha1)."'" : "").
")";
$result = mysqli_query($link, $query);
if (gettype($result)=="boolean" && $result)
{
echo "<tr><td>".$machinename."</td><td>".$name."</td><td>".$size."</td><td>".$crc."</td><td>".$md5."</td><td>".$sha1."</td></tr>\n";
ob_flush(); flush();
echo "<script>window.scrollTo(0,document.body.scrollHeight)</script>";
}
else
{
echo("MYSQL Error! ".mysqli_error($link)."<br/>");
return;
}
}
else
{
echo("MYSQL Error! ".mysqli_error($link)."<br/>");
return;
}
}
}
?>

View File

@@ -25,7 +25,6 @@
<?php
include_once("../css/style.php");
include_once("../includes/remapping.php");
include_once("../includes/functions.php");
// Connect to the database so it doesn't have to be done in every page
@@ -46,14 +45,8 @@ else
echo "<p>
Administrative Functions Homepage
<ol>
<li><a href='?page=edit'>Add/Edit/Remove a system/source/game/file</a></li>
<li><a href='parenting/index.php'>Add/Edit/Remove a parent</a></li>
<li><a href='?page=import'>Bulk add from DAT</a></li>
<li><a href='../?page=generate&auto=1'>Create all available DATs</a></li>
<li><a href='?page=onlinecheck'>Check for new files online</a></li>
<li><a href='?page=deheader'>Deheader files in a local (server) folder</a></li>
<li><a href='?page=scene'>Import or generate scene release information</a></li>
<li><a href='?page=clean'>Clean the database of dupes and orphans (CAUTION! CANNOT BE UNDONE!)</a></li>
</ol>";
}

View File

@@ -1,5 +0,0 @@
<?php
include_once("parenting/index.php");
?>

View File

@@ -1,24 +0,0 @@
<?php
#TODO: Move the connection away from here, use whatever the main system uses globally
$link = mysqli_connect('localhost', 'root', '', 'wod');
if (!$link)
{
die('Error: Database link could not be established: ' . mysqli_error($link));
}
if (!isset($_GET['new']))
die ("Fatal Error: There is no point to continue unless you specify the name for the new parent to add!");
$new_parent_name = $_GET['new'];
$sql = "INSERT INTO parent (name) VALUES ('".$new_parent_name."')";
if (mysqli_query($link, $sql)) {
echo "New parent added!";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($link);
}
mysqli_close($link);
?>

View File

@@ -1,115 +0,0 @@
<?php
/**
* Manual Parenting Tool for wizzardRedux
* @author emuLOAD
* @version 0.1
* @copyright Copyright (c) 2016
*/
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>TITLE</title>
<meta name="description" content="The Wizard of DATz Parenting Tool">
<meta name="author" content="emuLOAD">
<link rel="stylesheet" href="css/styles.css?v=1.0">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script type="text/javascript">
//This is where the jQuery magic happens ^_^
$(function(){
$.ajaxSetup ({
// Disable caching of AJAX responses */
cache: false
});
$("#tbl_parents_db").load("list_parents.php", function(responseTxt, statusTxt, xhr){
//if(statusTxt == "success")
//alert("External content loaded successfully!");
if(statusTxt == "error")
alert("Error: " + xhr.status + ": " + xhr.statusText);
});
$("#parent_filter").keyup(function(){
$("#tbl_parents_db").load("list_parents.php?name=" + encodeURIComponent($("#parent_filter").val()), function(responseTxt, statusTxt, xhr){
//if(statusTxt == "success")
//alert("External content loaded successfully!");
if(statusTxt == "error")
alert("Error: " + xhr.status + ": " + xhr.statusText);
});
$("#set_name_filter").val($("#parent_filter").val());
$("#tbl_sets_db").load("list_sets.php?name=" + encodeURIComponent($("#set_name_filter").val()), function(responseTxt, statusTxt, xhr){
//if(statusTxt == "success")
//alert("External content loaded successfully!");
if(statusTxt == "error")
alert("Error: " + xhr.status + ": " + xhr.statusText);
});
});
$("#set_name_filter").keyup(function(){
$("#tbl_sets_db").load("list_sets.php?name=" + encodeURIComponent($("#set_name_filter").val()), function(responseTxt, statusTxt, xhr){
//if(statusTxt == "success")
//alert("External content loaded successfully!");
if(statusTxt == "error")
alert("Error: " + xhr.status + ": " + xhr.statusText);
});
});
});
</script>
</head>
<body>
<div id="left_panel" style="float: left; overflow: hiddden; width: 50%">
<div id="left_top_panel">
<!-- Here we display site navigation links, and form tools for selecting targets -->
<span>
<!-- Filtering tool for the below table data -->
Filter by Family: <input type="text" id="family_filter"><br>
Filter by Title: <input type="text" id="parent_filter"><br>
</span>
<hr>
</div>
<span id="tbl_parents_db">
<!-- tabular representation of the contents of the "parents" table -->
</span>
</div>
<div id="right_panel" style="overflow:hidden; width: 50%;">
<!-- Based on the "game" selected from the games menu, show its children, and allow adding more clones -->
<div id="right_top_panel">
<!-- Here we display site navigation links, and form tools for selecting targets -->
<span>
<!-- Filtering tool for the below table data -->
Filter by System: <input type="text" id="system_filter"><br>
Filter by Title: <input type="text" id="set_name_filter"><br>
</span>
<hr>
<span id="tbl_sets_db">
<!-- tabular representation of the contents of the "parents" table -->
</span>
</div>
</div>
</body>
</html>

View File

@@ -1,98 +0,0 @@
<script type="text/javascript">
//This is where the jQuery magic happens ^_^
$(function(){
$("#new_parent_add").click(function(){
$("#service").load("add_parent_db.php?new=" + encodeURIComponent($("#new_parent_title").val()), function(responseTxt, statusTxt, xhr){
location.reload(true);
if(srviatusTxt == "success")
//alert("External content loaded successfully!");
if(statusTxt == "error")
alert("Error: " + xhr.status + ": " + xhr.statusText);
});
});
});
</script>
<?php
#TODO: Move the connection away from here, use whatever the main system uses globally
$link = mysqli_connect('localhost', 'root', '', 'wod');
if (!$link)
{
die('Error: Database link could not be established: ' . mysqli_error($link));
}
echo "
<table>
<thead>
<tr>
<th>id</th>
<th>Game Family</th>
<th>Game Title</th>
</tr>
</thead>
<tbody>";
if (!isset($_GET['name']) OR $_GET['name'] == "")
{
$filter = "1";
} else {
#only list parents as per the filtered name
$filter = "name LIKE \"%".$_GET['name']."%\"";
}
//Get all existing "parent" table entries
$sql = "SELECT id, name FROM parent WHERE $filter;";
$res = mysqli_query($link, $sql) OR die(mysqli_error($link));
if(!$res)
{
}
else
{
//We have data!
$found=false;
while ($row = mysqli_fetch_assoc($res))
{
$found = true;
echo "
<tr>
<td>".$row['id']."</td>
<td>unsupported</td>
<td>".$row['name']."</td>
</tr>";
}
echo "
</tbody>
</table>
</span>";
echo "<BR>";
if (!$found)
{
//No result found, want to add a new parent?
echo "<p>Parent not found. Add new?</p>";
echo "
Game Family: <input type=\"text\" id=\"new_parent_family\"><br>
Game Title: <input type=\"text\" id=\"new_parent_title\" value=\"".(isset($_GET['name']) ? $_GET['name'] : "")."\"><br>
<button id=\"new_parent_add\">Add new parent</button>
";
}
}
mysqli_close($link);
?>
<div id="service">
</div>

View File

@@ -1,131 +0,0 @@
<script type="text/javascript">
//This is where the jQuery magic happens ^_^
$(function(){
$('a.clones').click(function() {
var id = $(this).attr('id');
var set_id = id.replace('set_', '');
var parent_id = $("#spid_" + id.replace('set_', '')).val();
//alert(id.replace('set_', ''));
//alert($("#spid_" + id.replace('set_', '')).val());
$("#service").load("set_parent.php?set_id=" + set_id + "&dad_id=" + parent_id, function(responseTxt, statusTxt, xhr){
if(srviatusTxt == "success")
//alert("External content loaded successfully!");
if(statusTxt == "error")
alert("Error: " + xhr.status + ": " + xhr.statusText);
});
return false;
});
});
</script>
<?php
#TODO: Move the connection away from here, use whatever the main system uses globally
$link = mysqli_connect('localhost', 'root', '', 'wod');
if (!$link)
{
die('Error: Database link could not be established: ' . mysqli_error($link));
}
echo "
<table>
<thead>
<tr>
<th>Action</th>
<th>id</th>
<th>Parent</th>
<th>Set Title</th>
</tr>
</thead>
<tbody>";
if (!isset($_GET['name']) OR $_GET['name'] == "")
{
$filter = "1";
} else {
#only list parents as per the filtered name
$filter = "name LIKE \"%".$_GET['name']."%\"";
}
//Get all existing "parent" table entries
$sql = "SELECT id, name, parent FROM games WHERE $filter;";
$res = mysqli_query($link, $sql) OR die(mysqli_error($link));
if(!$res)
{
}
else
{
//We have data!
$found=false;
while ($row = mysqli_fetch_assoc($res))
{
$found = true;
$daddy = getMyParent($row['parent'],$link);
if($daddy == "none") {
$daddy = "<input type=\"text\" id=\"spid_".$row['id']."\" style=\"border-style:solid; border-color:#000000; width: 4em; border-width: 1px; background-color:white;}\">";
}
echo "
<tr>
<td><a href=\"#\" class=\"clones\" id=\"set_".$row['id']."\"><<< Add</a></td>
<td>".$row['id']."</td>
<td>".$daddy."</td>
<td>".$row['name']."</td>
</tr>";
}
echo "
</tbody>
</table>
</span>";
echo "<BR>";
if (!$found)
{
//No result found, want to add a new parent?
echo "<p>No sets found</p>";
}
}
function getMyParent($parentID, $link) {
#TODO: Move the connection away from here, use whatever the main system uses globally
$sql = "SELECT name FROM parent WHERE id=$parentID;";
$res = mysqli_query($link, $sql) OR die(mysqli_error($link));
if(!$res)
{
}
else
{
$row = mysqli_fetch_assoc($res);
if (!$row['name'] || $row['name']=="")
$name = "none";
else
$name = $row['name'];
return $name;
}
}
mysqli_close($link);
?>
<div id="service">
</div>

View File

@@ -1,3 +0,0 @@
<?php
?>

View File

@@ -1,25 +0,0 @@
<?php
#TODO: Move the connection away from here, use whatever the main system uses globally
$link = mysqli_connect('localhost', 'root', '', 'wod');
if (!$link)
{
die('Error: Database link could not be established: ' . mysqli_error($link));
}
if (!isset($_GET['set_id']) || !isset($_GET['dad_id']))
die ("Fatal Error: You must specify both the set's and the parent's IDs!");
$set_id = $_GET['set_id'];
$dad_id = $_GET['dad_id'];
$sql = "UPDATE games SET parent=".$dad_id." WHERE id=".$set_id."";
if (mysqli_query($link, $sql)) {
echo "Record updated!";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($link);
}
mysqli_close($link);
?>

View File

@@ -1,43 +0,0 @@
<?php
/* ------------------------------------------------------------------------------------
Reset the database in case of data error
Original code by Matt Nadareski (darksabre76)
------------------------------------------------------------------------------------ */
$allreset = true;
// Reset checksums table
$query = "DELETE FROM checksums";
$allreset = $allreset && mysqli_query($link, $query);
$query = "ALTER TABLE checksums AUTO_INCREMENT = 1";
$allreset = $allreset && mysqli_query($link, $query);
// Reset files table
$query = "DELETE FROM files";
$allreset = $allreset && mysqli_query($link, $query);
$query = "ALTER TABLE files AUTO_INCREMENT = 1";
$allreset = $allreset && mysqli_query($link, $query);
// Reset games table
$query = "DELETE FROM games";
$allreset = $allreset && mysqli_query($link, $query);
$query = "ALTER TABLE games AUTO_INCREMENT = 1";
$allreset = $allreset && mysqli_query($link, $query);
// Reset parent table
$query = "DELETE FROM parent";
$allreset = $allreset && mysqli_query($link, $query);
$query = "ALTER TABLE parent AUTO_INCREMENT = 1";
$allreset = $allreset && mysqli_query($link, $query);
if ($allreset)
{
echo "Resetting database succeeded!<br/>\n";
}
else
{
echo "Resetting database failed!<br/>\n".mysqli_error($link);
}
?>

View File

@@ -1,17 +0,0 @@
<?xml version="1.0"?>
<detector>
<name>Atari 7800</name>
<author>Roman Scherzer</author>
<version>1.0</version>
<rule start_offset="80" end_offset="EOF" operation="none">
<data offset="1" value="415441524937383030" result="true"/>
</rule>
<rule start_offset="80" end_offset="EOF" operation="none">
<data offset="64" value="41435455414C20434152542044415441205354415254532048455245" result="true"/>
</rule>
</detector>

View File

@@ -1,25 +0,0 @@
<?xml version="1.0"?>
<detector>
<name>fds</name>
<author>Yori Yoshizuki</author>
<version>1.0</version>
<rule start_offset="10">
<data offset="0" value="4644531A010000000000000000000000"/>
</rule>
<rule start_offset="10">
<data offset="0" value="4644531A020000000000000000000000"/>
</rule>
<rule start_offset="10">
<data offset="0" value="4644531A030000000000000000000000"/>
</rule>
<rule start_offset="10">
<data offset="0" value="4644531A040000000000000000000000"/>
</rule>
</detector>

View File

@@ -1,17 +0,0 @@
<?xml version="1.0"?>
<detector>
<name>Atari Lynx</name>
<author>Roman Scherzer</author>
<version>1.0</version>
<rule start_offset="40" end_offset="EOF" operation="none">
<data offset="0" value="4C594E58" result="true"/>
</rule>
<rule start_offset="40" end_offset="EOF" operation="none">
<data offset="6" value="425339" result="true"/>
</rule>
</detector>

View File

@@ -1,87 +0,0 @@
<?xml version="1.0"?>
<detector>
<name>MEGAMERGED</name>
<author>Roman Scherzer, Yori Yoshizuki, CUE, Matt Nadareski (darksabre76)</author>
<version>1.0</version>
<!-- a7800.xml -->
<rule start_offset="80" end_offset="EOF" operation="none">
<data offset="1" value="415441524937383030" result="true"/>
</rule>
<rule start_offset="80" end_offset="EOF" operation="none">
<data offset="64" value="41435455414C20434152542044415441205354415254532048455245" result="true"/>
</rule>
<!-- fds.xml -->
<rule start_offset="10">
<data offset="0" value="4644531A010000000000000000000000"/>
</rule>
<rule start_offset="10">
<data offset="0" value="4644531A020000000000000000000000"/>
</rule>
<rule start_offset="10">
<data offset="0" value="4644531A030000000000000000000000"/>
</rule>
<rule start_offset="10">
<data offset="0" value="4644531A040000000000000000000000"/>
</rule>
<!-- lynx.xml -->
<rule start_offset="40" end_offset="EOF" operation="none">
<data offset="0" value="4C594E58" result="true"/>
</rule>
<rule start_offset="40" end_offset="EOF" operation="none">
<data offset="6" value="425339" result="true"/>
</rule>
<!-- n64.xml -->
<!-- V64 format -->
<rule start_offset="0" end_offset="EOF" operation="none">
<data offset="0" value="80371240" result="true"/>
</rule>
<!-- Z64 format -->
<rule start_offset="0" end_offset="EOF" operation="byteswap">
<data offset="0" value="37804012" result="true"/>
</rule>
<!-- N64 format? -->
<rule start_offset="0" end_offset="EOF" operation="wordswap">
<data offset="0" value="40123780" result="true"/>
</rule>
<!-- nes.xml -->
<rule start_offset="10" end_offset="EOF" operation="none">
<data offset="0" value="4E45531A" result="true"/>
</rule>
<!-- snes.xml -->
<!-- fig header -->
<rule start_offset="200">
<data offset="16" value="0000000000000000"/>
</rule>
<!-- smc header -->
<rule start_offset="200">
<data offset="16" value="AABB040000000000"/>
</rule>
<!-- ufo header -->
<rule start_offset="200">
<data offset="16" value="535550455255464F"/>
</rule>
</detector>

View File

@@ -1,24 +0,0 @@
<?xml version="1.0"?>
<detector>
<name>Nintendo 64 - ABCD</name>
<author>CUE</author>
<version>1.1</version>
<!-- V64 format -->
<rule start_offset="0" end_offset="EOF" operation="none">
<data offset="0" value="80371240" result="true"/>
</rule>
<!-- Z64 format -->
<rule start_offset="0" end_offset="EOF" operation="byteswap">
<data offset="0" value="37804012" result="true"/>
</rule>
<!-- N64 format? -->
<rule start_offset="0" end_offset="EOF" operation="wordswap">
<data offset="0" value="40123780" result="true"/>
</rule>
</detector>

View File

@@ -1,13 +0,0 @@
<?xml version="1.0"?>
<detector>
<name>Nintendo Famicon/NES</name>
<author>Roman Scherzer</author>
<version>1.1</version>
<rule start_offset="10" end_offset="EOF" operation="none">
<data offset="0" value="4E45531A" result="true"/>
</rule>
</detector>

View File

@@ -1,24 +0,0 @@
<?xml version="1.0"?>
<detector>
<name>Nintendo Super Famicom/SNES</name>
<author>Matt Nadareski (darksabre76)</author>
<version>1.0</version>
<!-- fig header -->
<rule start_offset="200">
<data offset="16" value="0000000000000000"/>
</rule>
<!-- smc header -->
<rule start_offset="200">
<data offset="16" value="AABB040000000000"/>
</rule>
<!-- ufo header -->
<rule start_offset="200">
<data offset="16" value="535550455255464F"/>
</rule>
</detector>

View File

@@ -40,157 +40,4 @@ function get_data($url)
return $content;
}
// Convert an old-style DAT to XML
function rv2xml ($filename)
{
//ob_end_clean();
ini_set('max_execution_time', 0); // Set the execution time to infinite. This is a bad idea in production.
// Set the complex regex patterns
$headerPattern = @"/(.*?) \($/m";
$itemPattern = @"/^(.*?) (.*)/";
$endPattern = @"/^\)\s*$/";
// Get the file open for reading
$file = fopen($filename, "r");
// If there's an error, return null
if ($file === false)
{
return null;
}
// Create the XMLWriter
$xmlw = new XMLWriter;
$xmlw->openMemory();
$xmlw->setIndent(true);
$xmlw->setIndentString("\t");
$xmlw->startDocument();
$xmlw->startElement("datafile");
$block = false; $header = false;
while (($line = fgets($file)) !== false)
{
$line = trim($line);
// If the line is the header or a game
if (preg_match($headerPattern, $line, $matches) !== 0)
{
if ($matches[1] == "clrmamepro" || $matches[1] == "romvault")
{
$xmlw->startElement("header");
$header = true;
}
else
{
$xmlw->startElement($matches[1]);
}
$block = true;
}
// If the line is a rom or disk and we're in a block
elseif ((strpos(trim($line), "rom (") === 0 || strpos(trim($line), "disk (") === 0) && $block)
{
$line = explode(" ", $line);
$xmlw->startElement($line[0]);
// Loop over all attributes and add them if possible
$quote = false; $attrib = ""; $val = "";
for ($i = 2; $i < sizeof($line); $i++)
{
// Get the number of quotes
preg_match_all(@"/\"/", $line[$i], $quotes);
$quotes = sizeof($quotes[0]);
// Even number of quotes, not in a quote, not in attribute
if ($quotes % 2 == 0 && !$quote && $attrib == "")
{
$attrib = str_replace("\"", "", $line[$i]);
}
// Even number of quotes, not in a quote, in attribute
elseif ($quotes % 2 == 0 && !$quote && $attrib != "")
{
$xmlw->writeAttribute($attrib, str_replace("\"", "", $line[$i]));
$attrib = "";
}
// Even number of quotes, in a quote, not in attribute
elseif ($quotes % 2 == 0 && $quote && $attrib == "")
{
// Attributes can't have quoted names
}
// Even number of quotes, in a quote, in attribute
elseif ($quotes % 2 == 0 && $quote && $attrib != "")
{
$val .= " ".$line[$i];
}
// Odd number of quotes, not in a quote, not in attribute
elseif ($quotes % 2 == 1 && !$quote && $attrib == "")
{
// Attributes can't have quoted names
}
// Odd number of quotes, not in a quote, in attribute
elseif ($quotes % 2 == 1 && !$quote && $attrib != "")
{
$val = str_replace("\"", "", $line[$i]);
$quote = true;
}
// Odd number of quotes, in a quote, not in attribute
elseif ($quotes % 2 == 1 && $quote && $attrib == "")
{
$quote = false;
}
// Odd number of quotes, in a quote, in attribute
elseif ($quotes % 2 == 1 && $quote && $attrib != "")
{
$val .= " ".str_replace("\"", "", $line[$i]);
$xmlw->writeAttribute($attrib, $val);
$quote = false;
$attrib = "";
$val = "";
}
}
$xmlw->endElement();
}
// If the line is anything but a rom or disk and we're in a block
elseif (preg_match($itemPattern, $line, $matches) !== 0 && $block)
{
$matches[2] = str_replace("\"", "", $matches[2]);
if ($matches[1] == "name" && !$header)
{
$xmlw->writeAttribute($matches[1], $matches[2]);
$xmlw->writeElement("description", $matches[2]);
}
else
{
$xmlw->writeElement($matches[1], $matches[2]);
}
}
// If we find an end bracket that's not associated with anything else, the block is done
elseif (preg_match($endPattern, $line) !== 0 && $block)
{
$block = false;
$xmlw->endElement();
$header = false;
}
// Somehow didn't match anything
else
{
//echo "<pre>".$line."</pre><br/>\n";
}
}
$xmlw->endElement();
$xmlw->endDocument();
fclose($file);
return $xmlw->outputMemory();
}
?>

View File

@@ -1,956 +0,0 @@
<?php
/*------------------------------------------------------------------------------------
Map all known external sets to "Manufacturer - System" combos
Original code by Matt Nadareski (darksabre76), @tractivo
-----------------------------------------------------------------------------------*/
// MAME softlist mapping
$mapping_mame = array (
"32x" => "Sega - 32X",
"3do_m2" => "Panasonic - 3DO M2",
"a2600" => "Atari - 2600",
"a2600_cass" => "Atari - 2600",
"a5200" => "Atari - 5200",
"a7800" => "Atari - 7800",
"a800" => "Atari - 8bit",
"a800_flop" => "Atari - 8bit",
"abc1600" => "Luxor - ABC 1600",
"abc800" => "Luxor - ABC 800",
"abc800_hdd" => "Luxor - ABC 800",
"abc806" => "Luxor - ABC 806",
"abc80_cass" => "Luxor - ABC 80",
"abc80_flop" => "Luxor - ABC 80",
"adam_cart" => "Coleco - ColecoVision, ColecoVision ADAM",
"adam_cass" => "Coleco - ColecoVision, ColecoVision ADAM",
"adam_flop" => "Coleco - ColecoVision, ColecoVision ADAM",
"advantage" => "NorthStar - Advantage",
"advision" => "Entex - Adventure Vision",
"aim65_cart" => "Rockwell - AIM 65",
"aleste" => "Patisonic - Aleste 520EX",
"alice32" => "Matra Hachette - Alice 32 &amp; 90",
"alice90" => "Matra Hachette - Alice 32 &amp; 90",
"alphatro_flop" => "Triumph-Adler - Alphatronic PC",
"altos5" => "Altos Computer Systems - Series 5",
"amiga_a1000" => "Commodore - Amiga",
"amiga_a3000" => "Commodore - Amiga",
"amiga_apps" => "Commodore - Amiga",
"amiga_flop" => "Commodore - Amiga",
"amiga_hardware" => "Commodore - Amiga",
"amiga_workbench" => "Commodore - Amiga",
"amigaaga_flop" => "Commodore - Amiga",
"amigaecs_flop" => "Commodore - Amiga",
"amigaocs_flop" => "Commodore - Amiga",
"ampro" => "Ampro - Little Board",
"apc" => "NEC - Advanced Personal Computer",
"apfimag_cass" => "APF - M-1000",
"apfm1000" => "APF - M-1000",
"apogee" => "Radio-86RK - Apogej BK-01",
"apollo_ctape" => "Hewlett-Packard - Apollo",
"apple1" => "Apple - I",
"apple2" => "Apple - II",
"apple2gs" => "Apple - II",
"apple3" => "Apple - III",
"aquarius" => "Mattel - Aquarius",
"arcadia" => "Emerson - Arcadia 2001",
"archimedes" => "Acorn - Archimedes",
"astrocde" => "Bally Professional - Arcade, Astrocade",
"atom" => "Acorn - Atom",
"atom_cass" => "Acorn - Atom",
"atom_flop" => "Acorn - Atom",
"atom_rom" => "Acorn - Atom",
"attache" => "Otrona - Attache",
"b2m" => "BNPO - Bashkiria-2M",
"bbc_32016_flop" => "Acorn - BBC, Electron",
"bbc_65c102_flop" => "Acorn - BBC, Electron",
"bbc_68000_flop" => "Acorn - BBC, Electron",
"bbc_80186_flop" => "Acorn - BBC, Electron",
"bbc_arm_flop" => "Acorn - BBC, Electron",
"bbc_flop_32016" => "Acorn - BBC, Electron",
"bbc_flop_6502" => "Acorn - BBC, Electron",
"bbc_flop_65c102" => "Acorn - BBC, Electron",
"bbc_flop_68000" => "Acorn - BBC, Electron",
"bbc_flop_80186" => "Acorn - BBC, Electron",
"bbc_flop_arm" => "Acorn - BBC, Electron",
"bbc_flop_torch" => "Acorn - BBC, Electron",
"bbc_flop_z80" => "Acorn - BBC, Electron",
"bbc_torch_flop" => "Acorn - BBC, Electron",
"bbc_z80_flop" => "Acorn - BBC, Electron",
"bbca_cass" => "Acorn - BBC, Electron",
"bbcb_cass" => "Acorn - BBC, Electron",
"bbcb_cass_de" => "Acorn - BBC, Electron",
"bbcb_de_cass" => "Acorn - BBC, Electron",
"bbcb_flop" => "Acorn - BBC, Electron",
"bbcb_flop_orig" => "Acorn - BBC, Electron",
"bbcb_flop_us" => "Acorn - BBC, Electron",
"bbcb_orig_flop" => "Acorn - BBC, Electron",
"bbcb_us_flop" => "Acorn - BBC, Electron",
"bbcbc" => "BBC - Bridge Companion",
"bbcm_cart" => "Acorn - BBC, Electron",
"bbcm_cass" => "Acorn - BBC, Electron",
"bbcm_flop" => "Acorn - BBC, Electron",
"bbcmc_flop" => "Acorn - BBC, Electron",
"bk0010" => "Elektronika - BK-0010",
"bml3_flop" => "Hitachi - Basic Master Level 3",
"bw12" => "Bondwell - 12",
"bw14" => "Bondwell - 14",
"bw2" => "Bondwell - 2",
"bx256hp_flop" => "Commodore - BX256-80HP, CBM 730",
"c128_cart" => "Commodore - 128",
"c128_flop" => "Commodore - 128",
"c128_rom" => "Commodore - 128",
"c64_cart" => "Commodore - 64",
"c64_cass" => "Commodore - 64",
"c64_flop" => "Commodore - 64",
"c65_flop" => "Commodore - 65",
"casloopy" => "Casio - Loopy",
"cbm2_cart" => "Commodore - CBM-II",
"cbm2_flop" => "Commodore - CBM-II",
"cbm8096_flop" => "Commodore - 8096",
"cbm8296_flop" => "Commodore - 8296",
"cc40_cart" => "Texas Instruments - CC-40",
"cd32" => "Commodore - Amiga",
"cdi" => "Philips - CD-i",
"cdtv" => "Commodore - Amiga",
"cgenie_cart" => "EACA - EG2000 Colour Genie",
"cgenie_cass" => "EACA - EG2000 Colour Genie",
"channelf" => "Fairchild - Channel F",
"coco_cart" => "Tandy Radio Shack - TRS-80 Color Computer",
"coco_flop" => "Tandy Radio Shack - TRS-80 Color Computer",
"coleco" => "Coleco - ColecoVision, ColecoVision ADAM",
"compclr2_flop" => "ISC - Compucolor II",
"compis" => "Telenova - Compis",
"comx35_flop" => "COMX - COMX-35",
"copera" => "Sega - PICO",
"cpc_cass" => "Amstrad - CPC",
"cpc_flop" => "Amstrad - CPC",
"crvision" => "VTech - CreatiVision",
"cx3000tc" => "Palson - CX 3000 Tele Computer",
"dai_cass" => "DAI - Personal Computer",
"database" => "Voltmace - Database",
"dim68k" => "Dimension - 68000",
"dmv" => "NCR - Decision Mate V",
"dps1" => "Ithaca InterSystems - DPS-1",
"ec1841" => "MPO BT - EC 1841",
"einstein" => "Tatung - Einstein TC-01",
"electron_cart" => "Acorn - BBC, Electron",
"electron_cass" => "Acorn - BBC, Electron",
"ep64_cart" => "Enterprise - 64, 128",
"ep64_cass" => "Enterprise - 64, 128",
"ep64_flop" => "Enterprise - 64, 128",
"epson_cpm" => "Epson - CPM",
"exl100" => "Exelvision - Exeltel, EXL100",
"famicom_cass" => "Nintendo - Famicom BASIC",
"famicom_flop" => "Nintendo - Famicom Disk System",
"fidel_scc" => "Fidelity - SCC",
"fm77av" => "Fujitsu - FM-77AV",
"fm7_cass" => "Fujitsu - FM-7",
"fm7_disk" => "Fujitsu - FM-7",
"fmtowns_cd" => "Fujitsu - FM Towns",
"g7400" => "Philips - Videopac+, Odyssey2",
"galaxy" => "Galaksija - Galaksija, Galaksija Plus",
"gamate" => "Bit Corp - Gamate",
"gameboy" => "Nintendo - Game Boy",
"gamecom" => "Tiger Electronics - Game.com",
"gamegear" => "Sega - Game Gear",
"gameking" => "TimeTop - GameKing",
"gameking3" => "TimeTop - GameKing",
"gamepock" => "Epoch - Game Pocket Computer",
"gba" => "Nintendo - Game Boy Advance",
"gbcolor" => "Nintendo - Game Boy Color",
"genius" => "VTech - Genius",
"gimix" => "Gimix - 6809",
"gjmovie" => "VTech - Genius",
"gl2000" => "VTech - Genius",
"gl6000sl" => "VTech - Genius",
"glcolor" => "VTech - Genius",
"gmaster" => "Hartung - Game Master",
"gp32" => "GamePark - GP32",
"guab" => "JPM - Give us a Break",
"gx4000" => "Amstrad - GX4000",
"h21" => "TRQ - Video Computer H-21",
"horizon" => "NorthStar - Horizon",
"hp9835a_rom" => "Hewlett-Packard - 9835",
"hp9845a_rom" => "Hewlett-Packard - 9845",
"hp9845b_rom" => "Hewlett-Packard - 9845",
"ht68k" => "Hawthorne Technologies - HT68K",
"i7000_card" => "Itautec - I-7000",
"ibm5140" => "IBM - PC Compatibles",
"ibm5150" => "IBM - PC Compatibles",
"ibm5150_cass" => "IBM - PC Compatibles",
"ibm5160_flop" => "IBM - PC Compatibles",
"ibm5170" => "IBM - PC Compatibles",
"ibm5170_cdrom" => "IBM - PC Compatibles",
"ibmpcjr_cart" => "IBM - PC Jr",
"ibmpcjr_flop" => "IBM - PC Jr",
"interact" => "Interact - Family Computer",
"intv" => "Mattel - Intellivision",
"intvecs" => "Mattel - Intellivision",
"iq128" => "VTech - Genius",
"iq151_cart" => "ZPA Novy Bor - IQ-151",
"iq151_flop" => "ZPA Novy Bor - IQ-151",
"jaguar" => "Atari - Jaguar",
"juicebox" => "Mattel - Juice Box",
"jupace_cass" => "Jupiter Cantab - Jupiter Ace",
"k28m2" => "Tiger Electronics - K28",
"kayproii" => "Kaypro - II",
"kc_cart" => "Robotron - KC85",
"kc_cass" => "Robotron - KC85",
"kc_flop" => "Robotron - KC85",
"korvet_flop" => "Moscow State University - Korvet",
"lantutor" => "Texas Instruments - Language Tutor",
"leapster" => "LeapFrog - Leapster Learning Game System",
"lisa" => "Apple - Lisa",
"lisa2" => "Apple - Lisa 2",
"lviv" => "Lviv - PC-01",
"lynx" => "Atari - Lynx",
"m20" => "Olivetti - M20",
"m5_cart" => "Sord - M5",
"m5_cass" => "Sord - M5",
"m5_flop" => "Sord - M5",
"mac_flop" => "Apple - Macintosh",
"mac_hdd" => "Apple - Macintosh",
"mbc200" => "Sanyo - MBC-200, MBC-1200",
"mbc55x" => "Sanyo - MBC-550, MBC-555",
"mc10" => "Tandy Radio Shack - TRS-80 MC-10",
"mc1000_cass" => "CCE - MC-1000",
"mc1502_flop" => "Elektronika - MC 1502",
"md2_flop" => "Morrow - Micro Decision MD-2",
"megacd" => "Sega - Mega-CD, Sega CD",
"megacdj" => "Sega - Mega-CD, Sega CD",
"megadriv" => "Sega - Mega Drive, Genesis",
"megaduck" => "Creatronic - Mega Duck, Cougar Boy",
"megapc" => "Amstrad - Mega PC",
"megatech" => "Sega - Megatech",
"microvision" => "Milton Bradley - MicroVision",
"mikro80" => "Radio-86RK - Mikro-80",
"mikrosha_cart" => "Radio-86RK - Mikrosha",
"mikrosha_cass" => "Radio-86RK - Mikrosha",
"misterx" => "Yeno - MisterX",
"mm1_flop" => "Nokia - MikroMikko 1",
"mo5_cart" => "Thomson - 8bit",
"mpu1000" => "Acetronic - MPU-1000",
"mpz80" => "Morrow - MPZ80",
"msx1_cart" => "Microsoft - MSX, MSX 2",
"msx1_cass" => "Microsoft - MSX, MSX 2",
"msx1_flop" => "Microsoft - MSX, MSX 2",
"msx2_cart" => "Microsoft - MSX, MSX 2",
"msx2_cass" => "Microsoft - MSX, MSX 2",
"msx2_flop" => "Microsoft - MSX, MSX 2",
"msx2p_flop" => "Microsoft - MSX, MSX 2",
"msxr_flop" => "Microsoft - MSX, MSX 2",
"mtx_cass" => "Memotech - MTX512",
"myvision" => "Nichibutsu - My Vision",
"mz2000_cass" => "Sharp - MZ-2000",
"mz2000_flop" => "Sharp - MZ-2000",
"mz2500" => "Sharp - MZ-2500",
"mz700_cass" => "Sharp - MZ-700",
"mz800_cass" => "Sharp - MZ-800, MZ-1500",
"n64" => "Nintendo - Nintendo 64",
"n64dd" => "Nintendo - Nintendo 64DD",
"nascom_flop" => "Nascom - I, II",
"nascom_socket" => "Nascom - I, II",
"neocd" => "SNK - Neo Geo CD",
"neogeo" => "SNK - Neo Geo",
"nes" => "Nintendo - Nintendo Entertainment System",
"nes_ade" => "Nintendo - Nintendo Entertainment System",
"nes_datach" => "Nintendo - Nintendo Entertainment System",
"nes_kstudio" => "Nintendo - Nintendo Entertainment System",
"nes_ntbrom" => "Nintendo - Nintendo Entertainment System",
"next" => "NeXT - NeXT",
"ngp" => "SNK - Neo Geo Pocket",
"ngpc" => "SNK - Neo Geo Pocket Color",
"nimbus" => "RM - Nimbus PC",
"odyssey2" => "Philips - Videopac+, Odyssey2",
"ondra" => "Tesla - Ondra, Ondra ViLi",
"orao" => "PEL Varazdin - Orao",
"orion_cart" => "Orion - Orion 128, OrionPro",
"orion_cass" => "Orion - Orion 128, OrionPro",
"orion_flop" => "Orion - Orion 128, OrionPro",
"orionpro_flop" => "Orion - Orion 128, OrionPro",
"osborne1" => "OCC - Osborne 1, 2, 3, 4",
"osborne2" => "OCC - Osborne 1, 2, 3, 4",
"p500_flop" => "Commodore - P500",
"partner_cass" => "Radio-86RK - Partner-01.01",
"partner_flop" => "Radio-86RK - Partner-01.01",
"pasogo" => "Koei - PasoGo",
"pb2000c" => "Casio - PB-2000C",
"pc1000" => "VTech - PreComputer 1000",
"pc1512" => "Amstrad - PC1512",
"pc1640" => "Amstrad - PC1640",
"pc8201" => "NEC - PC-8201",
"pc8801_cass" => "NEC - PC-8801",
"pc8801_flop" => "NEC - PC-8801",
"pc88va" => "NEC - PC-88VA",
"pc98" => "NEC - PC-9801",
"pce" => "NEC - PC Engine, TurboGrafx 16",
"pcecd" => "NEC - PC Engine CD, TurboGrafx 16 CD",
"pcw" => "Amstrad - PCW",
"pcw16" => "Amstrad - PCW",
"pecom_cass" => "Elektronska Industrija Nis - PECOM 32, 64",
"pegasus_cart" => "Technosys - Aamber Pegasus",
"pencil2" => "Hanimex - Pencil II",
"pentagon_cass" => "Pentagon - 1024SL",
"pet_cass" => "Commodore - PET",
"pet_flop" => "Commodore - PET",
"pet_hdd" => "Commodore - PET",
"pet_rom" => "Commodore - PET",
"pico" => "Sega - PICO",
"pippin" => "Bandai - Pippin",
"pippin_flop" => "Bandai - Pippin",
"plus4_cart" => "Commodore - Plus-4",
"plus4_cass" => "Commodore - Plus-4",
"plus4_flop" => "Commodore - Plus-4",
"pmd85_cass" => "Tesla - PMD 85",
"pockchalv1" => "Benesse - Pocket Challenge V",
"pockchalv2" => "Benesse - Pocket Challenge V",
"pokemini" => "Nintendo - Pokemon Mini",
"pro128_cart" => "Olivetti - Prodest PC 128",
"pro128s_flop" => "Olivetti - Prodest PC 128",
"prof180" => "Conitec - PROF-180",
"prof80" => "Conitec - PROF-80",
"psion1" => "Psion - Organiser I",
"psion2" => "Psion - Organiser II",
"psx" => "Sony - PlayStation",
"pt68k2" => "Peripheral Technology - PT68K",
"pv1000" => "Casio - PV-1000",
"pv2000" => "Casio - PV-2000",
"px4_cart" => "Epson - PX-4",
"pyl601" => "SASDF - Pyldin-601",
"ql_cart" => "Sinclair - QL",
"ql_cass" => "Sinclair - QL",
"ql_flop" => "Sinclair - QL",
"qx10_flop" => "Epson - QX-10",
"r9751" => "ROLM - CBX 9751",
"radio86_cart" => "Radio-86RK - Radio-86RK",
"radio86_cass" => "Radio-86RK - Radio-86RK",
"rainbow" => "DEC - Rainbow 100",
"rwtrntcs" => "Rowtron - Television Computer System",
"rx78" => "Gundam - RX-78",
"sage2" => "Sage - Sage II",
"samcoupe_cass" => "MGT - Sam Coupe",
"samcoupe_flop" => "MGT - Sam Coupe",
"sat_cart" => "Sega - Saturn",
"saturn" => "Sega - Saturn",
"sawatte" => "Sega - PICO",
"sc3000_cart" => "Sega - SG-1000, SC-3000, SF-7000, Othello Multivision",
"sc3000_cass" => "Sega - SG-1000, SC-3000, SF-7000, Othello Multivision",
"scv" => "Epoch - Super Cassette Vision",
"segacd" => "Sega - Mega-CD, Sega CD",
"sf7000" => "Sega - SG-1000, SC-3000, SF-7000, Othello Multivision",
"sg1000" => "Sega - SG-1000, SC-3000, SF-7000, Othello Multivision",
"sgx" => "NEC - Super Grafx",
"smc777" => "Sony - SMC777",
"sms" => "Sega - Master System, Mark III",
"snes" => "Nintendo - Super Nintendo Entertainment System",
"snes_bspack" => "Nintendo - Super Nintendo Entertainment System",
"snes_strom" => "Nintendo - Super Nintendo Entertainment System",
"snes_vkun" => "Nintendo - Super Nintendo Entertainment System",
"snotec" => "Bandai - Super Note Club",
"snread" => "Texas Instruments - Speak &amp; Read",
"snspell" => "Texas Instruments - Speak &amp; Spell",
"socrates" => "VTech - Socrates",
"softbox" => "SSE - SoftBox",
"sol20_cass" => "PTC - Sol Terminal Computer SOL-20",
"sorcerer_cart" => "Exidy - Sorcerer",
"sorcerer_cass" => "Exidy - Sorcerer",
"sorcerer_flop" => "Exidy - Sorcerer",
"spc1000_cass" => "Samsung - SPC-1000",
"special_cass" => "Specialist - Specialist",
"special_flop" => "Specialist - Specialist",
"specpls3_flop" => "Sinclair - ZX Spectrum",
"spectrum_cart" => "Sinclair - ZX Spectrum",
"spectrum_cass" => "Sinclair - ZX Spectrum",
"st_cart" => "Atari - ST",
"st_flop" => "Atari - ST",
"studio2" => "RCA - Studio II",
"stv" => "Sega - Titan Video",
"super6" => "ADC - Super Six",
"superpet_flop" => "Commodore - SuperPET, MMF 9000",
"supracan" => "Funtech - Super Acan",
"sv8000" => "Bandai - Super Vision 8000",
"svi318_cart" => "Spectravideo - SVI-318, SVI-328",
"svi318_cass" => "Spectravideo - SVI-318, SVI-328",
"svi318_flop" => "Spectravideo - SVI-318, SVI-328",
"svision" => "Watara - Supervision",
"svmu" => "Sega - Visual Memory System",
"tandy200" => "Tandy Radio Shack - TRS-80 Model 200",
"tandy2k" => "Tandy Radio Shack - 2000",
"tandy6k" => "Tandy Radio Shack - 6000",
"tdv2324" => "Tandberg - TDV 2324",
"tek4052_cart" => "Tektronix - 4052",
"tg16" => "NEC - PC Engine, TurboGrafx 16",
"ti74_cart" => "Texas Instruments - TI-74",
"ti99_cart" => "Texas Instruments - TI-99 4A",
"tiki100" => "Tiki Data - Kontiki-100, Tiki-100",
"timex_dock" => "Timex - TS-2068",
"tntell" => "Texas Instruments - Touch &amp; Tell",
"to770_cart" => "Thomson - 8bit",
"to7_cart" => "Thomson - 8bit",
"trs80m2" => "Tandy Radio Shack - TRS-80 Model II",
"trsm100" => "Tandy Radio Shack - TRS-80 Model 100",
"tutor" => "Tomy - Tutor, Pyuuta",
"tvc_cart" => "Videoton - TV-Computer",
"tvc_cass" => "Videoton - TV-Computer",
"tvc_flop" => "Videoton - TV-Computer",
"unichamp" => "Unisonic - Champion 2711",
"ut88" => "Radio-86RK - YuT-88",
"uzebox" => "Uzebox - Uzebox",
"v1050_flop" => "Visual Technology - Visual 1050",
"v1050_hdd" => "Visual Technology - Visual 1050",
"vboy" => "Nintendo - Virtual Boy",
"vc4000" => "Interton - VC 4000",
"vector06_cart" => "Temirazov &amp; Sokolov - Vector-06C",
"vectrex" => "GCE - Vectrex",
"vg5k" => "Philips - VG 5000",
"vic10" => "Commodore - VIC-10",
"vic1001_cart" => "Commodore - VIC-20",
"vic1001_cass" => "Commodore - VIC-20",
"vic1001_flop" => "Commodore - VIC-20",
"victor9k_flop" => "Sirius - Victor 9000",
"vidbrain" => "VideoBrain - Family Computer",
"vii" => "Chintendo - Vii",
"vip" => "RCA - Vip",
"visicom" => "Toshiba - Visicom",
"vixen" => "OCC - Osborne 1, 2, 3, 4",
"vreader" => "VTech - V.Reader, Storio",
"vsmile_cart" => "VTech - V.Smile, V.Disc",
"vsmile_cd" => "VTech - V.Smile, V.Disc",
"vz_cass" => "Dick Smith Electronics - VZ-200, VZ-300",
"wangpc" => "Wang - PC",
"wicat" => "Millennium Systems - Wicat",
"wmbullet" => "WaveMate - Bullet",
"wscolor" => "Bandai - WonderSwan Color",
"wswan" => "Bandai - WonderSwan",
"x07_card" => "Canon - X-07",
"x07_cass" => "Canon - X-07",
"x1_cass" => "Sharp - X1",
"x1_flop" => "Sharp - X1",
"x68k_flop" => "Sharp - X68000",
"xegs" => "Atari - 8bit",
"xerox820" => "Xerox - 820",
"xerox820ii" => "Xerox - 820 II",
);
// No-Intro DAT name base mapping
$mapping_nointro = array (
"Atari - 5200" => "Atari - 5200",
"Atari - 7800" => "Atari - 7800",
"Atari - Jaguar" => "Atari - Jaguar",
"Atari - Lynx" => "Atari - Lynx",
"Atari - ST" => "Atari - ST",
"Bandai - WonderSwan" => "Bandai - WonderSwan",
"Bandai - WonderSwan Color" => "Bandai - WonderSwan Color",
"Casio - Loopy" => "Casio - Loopy",
"Casio - PV-1000" => "Casio - PV-1000",
"Coleco - ColecoVision" => "Coleco - ColecoVision, ColecoVision ADAM",
"Commodore - 64" => "Commodore - 64",
"Commodore - 64 (PP)" => "Commodore - 64",
"Commodore - 64 (Tapes)" => "Commodore - 64",
"Commodore - Amiga" => "Commodore - Amiga",
"Commodore - Plus-4" => "Commodore - Plus-4",
"Commodore - VIC-20" => "Commodore - VIC-20",
"Emerson - Arcadia 2001" => "Emerson - Arcadia 2001",
"Entex - Adventure Vision" => "Entex - Adventure Vision",
"Epoch - Super Cassette Vision" => "Epoch - Super Cassette Vision",
"Fairchild - Channel F" => "Fairchild - Channel F",
"Funtech - Super Acan" => "Funtech - Super Acan",
"GamePark - GP32" => "GamePark - GP32",
"GCE - Vectrex" => "GCE - Vectrex",
"Hartung - Game Master" => "Hartung - Game Master",
"LeapFrog - Leapster Learning Game System" => "LeapFrog - Leapster Learning Game System",
"Magnavox - Odyssey2" => "Philips - Videopac+, Odyssey2",
"Microsoft - MSX" => "Microsoft - MSX, MSX 2",
"Microsoft - MSX 2" => "Microsoft - MSX, MSX 2",
"Microsoft - XBOX 360 (DLC)" => "Microsoft - Xbox 360",
"Microsoft - XBOX 360 (Games on Demand)" => "Microsoft - Xbox 360",
"Microsoft - XBOX 360 (Title Updates)" => "Microsoft - Xbox 360",
"NEC - PC Engine - TurboGrafx 16" => "NEC - PC Engine, TurboGrafx 16",
"NEC - Super Grafx" => "NEC - Super Grafx",
"Nintendo - Famicom Disk System" => "Nintendo - Famicom Disk System",
"Nintendo - Game Boy" => "Nintendo - Game Boy",
"Nintendo - Game Boy Advance" => "Nintendo - Game Boy Advance",
"Nintendo - Game Boy Advance (e-Cards)" => "Nintendo - Game Boy Advance",
"Nintendo - Game Boy Color" => "Nintendo - Game Boy Color",
"Nintendo - New Nintendo 3DS" => "Nintendo - Nintendo 3DS",
"Nintendo - New Nintendo 3DS (DLC)" => "Nintendo - Nintendo 3DS",
"Nintendo - Nintendo 3DS" => "Nintendo - Nintendo 3DS",
"Nintendo - Nintendo 3DS (DLC)" => "Nintendo - Nintendo 3DS",
"Nintendo - Nintendo 64" => "Nintendo - Nintendo 64",
"Nintendo - Nintendo 64DD" => "Nintendo - Nintendo 64DD",
"Nintendo - Nintendo DS" => "Nintendo - Nintendo DS",
"Nintendo - Nintendo DS Decrypted" => "Nintendo - Nintendo DS",
"Nintendo - Nintendo DS Encrypted" => "Nintendo - Nintendo DS",
"Nintendo - Nintendo DS (Download Play) (BETA)" => "Nintendo - Nintendo DS",
"Nintendo - Nintendo DSi" => "Nintendo - Nintendo DSi",
"Nintendo - Nintendo DSi Decrypted" => "Nintendo - Nintendo DSi",
"Nintendo - Nintendo DSi Encrypted" => "Nintendo - Nintendo DSi",
"Nintendo - Nintendo DSi (DLC)" => "Nintendo - Nintendo DSi",
"Nintendo - Nintendo Entertainment System" => "Nintendo - Nintendo Entertainment System",
"Nintendo - Nintendo Wii (DLC)" => "Nintendo - Nintendo Wii",
"Nintendo - Pokemon Mini" => "Nintendo - Pokemon Mini",
"Nintendo - Satellaview" => "Nintendo - Super Nintendo Entertainment System",
"Nintendo - Sufami Turbo" => "Nintendo - Super Nintendo Entertainment System",
"Nintendo - Super Nintendo Entertainment System" => "Nintendo - Super Nintendo Entertainment System",
"Nintendo - Virtual Boy" => "Nintendo - Virtual Boy",
"Nokia - N-Gage" => "Nokia - N-Gage",
"Philips - Videopac+" => "Philips - Videopac+, Odyssey2",
"RCA - Studio II" => "RCA - Studio II",
"Sega - 32X" => "Sega - 32X",
"Sega - Game Gear" => "Sega - Game Gear",
"Sega - Master System - Mark III" => "Sega - Master System, Mark III",
"Sega - Mega Drive - Genesis" => "Sega - Mega Drive, Genesis",
"Sega - PICO" => "Sega - PICO",
"Sega - SG-1000" => "Sega - SG-1000, SC-3000, SF-7000, Othello Multivision",
"Sinclair - ZX Spectrum +3" => "Sinclair - ZX Spectrum",
"Sony - PlayStation 3 (DLC)" => "Sony - PlayStation 3",
"Sony - PlayStation 3 (Downloadable)" => "Sony - PlayStation 3",
"Sony - PlayStation 3 (PSN)" => "Sony - PlayStation 3",
"Sony - PlayStation Portable" => "Sony - PlayStation Portable",
"Sony - PlayStation Portable (DLC)" => "Sony - PlayStation Portable",
"Sony - PlayStation Portable (PSN)" => "Sony - PlayStation Portable",
"Sony - PlayStation Portable (PSX2PSP)" => "Sony - PlayStation Portable",
"Sony - PlayStation Portable (UMD Music)" => "Sony - PlayStation Portable",
"Sony - PlayStation Portable (UMD Video)" => "Sony - PlayStation Portable",
"SNK - Neo Geo Pocket" => "SNK - Neo Geo Pocket",
"SNK - Neo Geo Pocket Color" => "SNK - Neo Geo Pocket Color",
"Tiger - Game.com" => "Tiger Electronics - Game.com",
"Tiger - Gizmondo" => "Tiger Telematics - Gizmondo",
"VTech - CreatiVision" => "VTech - CreatiVision",
"VTech - V.Smile" => "VTech - V.Smile, V.Disc",
"Watara - Supervision" => "Watara - Supervision",
);
// Redump DAT name base mapping
$mapping_redump = array (
"Apple - Macintosh" => "Apple - Macintosh",
"Arcade - Namco - Sega - Nintendo - Triforce" => "Namco - Triforce",
"Arcade - Sega - Chihiro" => "Sega - Chihiro",
"Arcade - Sega - Lindbergh" => "Sega - Lindbergh",
"Arcade - Sega - Naomi" => "Sega - Naomi, Naomi 2, Atomiswave",
"Bandai - Apple - Pippin" => "Bandai - Pippin",
"Bandai - Playdia" => "Bandai - Playdia",
"Commodore - Amiga CD" => "Commodore - Amiga",
"Commodore - Amiga CD32" => "Commodore - Amiga",
"Commodore - Amiga CDTV" => "Commodore - Amiga",
"Fujitsu - FM-Towns" => "Fujitsu - FM Towns",
"IBM - PC compatible" => "IBM - PC Compatibles",
"Mattel - HyperScan" => "Mattel - HyperScan",
"Microsoft - Xbox - BIOS Images" => "Microsoft - Xbox",
"Microsoft - Xbox" => "Microsoft - Xbox",
"Microsoft - Xbox 360" => "Microsoft - Xbox 360",
"Microsoft - Xbox One" => "Microsoft - Xbox One",
"NEC - PC Engine CD - TurboGrafx-CD" => "NEC - PC Engine CD, TurboGrafx 16 CD",
"NEC - PC-88 series" => "NEC - PC-8801",
"NEC - PC-98 series" => "NEC - PC-9801",
"NEC - PC-FX - PC-FXGA" => "NEC - PC FX, PC FXGA",
"Nintendo - GameCube - BIOS Images" => "Nintendo - GameCube",
"Nintendo - GameCube" => "Nintendo - GameCube",
"Nintendo - Wii" => "Nintendo - Nintendo Wii",
"Nintendo - Wii U" => "Nintendo - Nintendo Wii U",
"Palm" => "Hewlett-Packard - Palm",
"Panasonic - 3DO Interactive Multiplayer" => "Panasonic - 3DO Interactive Multiplayer",
"Philips - CD-i" => "Philips - CD-i",
"Sega - Dreamcast" => "Sega - Dreamcast",
"Sega - Mega-CD - Sega CD" => "Sega - Mega-CD, Sega CD",
"Sega - Saturn" => "Sega - Saturn",
"SNK - Neo Geo CD" => "SNK - Neo Geo CD",
"Sony - PlayStation - BIOS Images" => "Sony - PlayStation",
"Sony - PlayStation" => "Sony - PlayStation",
"Sony - PlayStation 2 - BIOS Images" => "Sony - PlayStation 2",
"Sony - PlayStation 2" => "Sony - PlayStation 2",
"Sony - PlayStation 3" => "Sony - PlayStation 3",
"Sony - PlayStation 4" => "Sony - PlayStation 4",
"Sony - PlayStation Portable" => "Sony - PlayStation Portable",
"VTech - V.Flash" => "VTech - V.Flash Home Edutainment System",
);
// TOSEC DAT name base mapping
$mapping_tosec = array (
"3DO 3DO Interactive Multiplayer" => "Panasonic - 3DO Interactive Multiplayer",
"APF Imagination Machine" => "APF - M-1000",
"Acorn Archimedes" => "Acorn - Archimedes",
"Acorn BBC" => "Acorn - BBC, Electron",
"Acorn BBC Micro" => "Acorn - BBC, Electron",
"Acorn Electron" => "Acorn - BBC, Electron",
"Altos Computer Systems ACS-186, 586 &amp; 986" => "Altos Computer Systems - ACS-186, 586, 986",
"Altos Computer Systems ACS-8000" => "Altos Computer Systems - ACS-8000",
"Altos Computer Systems Series 5" => "Altos Computer Systems - Series 5",
"American Laser Games CD-ROM System" => "American Laser Games - CD-ROM System",
"Amstrad CPC" => "Amstrad - CPC",
"Amstrad GX4000" => "Amstrad - GX4000",
"Amstrad PCW" => "Amstrad - PCW",
"Apple 1" => "Apple - I",
"Apple I" => "Apple - I",
"Apple II" => "Apple - II",
"Apple IIGS" => "Apple - II",
"Apple III" => "Apple - III",
"Apple Lisa" => "Apple - Lisa",
"Apple Macintosh" => "Apple - Macintosh",
"Applied Technology MicroBee" => "Applied Technology - MicroBee",
"Atari 2600 &amp; VCS" => "Atari - 2600",
"Atari 5200" => "Atari - 5200",
"Atari 7800" => "Atari - 7800",
"Atari 8bit" => "Atari - 8bit",
"Atari Jaguar CD" => "Atari - Jaguar CD",
"Atari Jaguar" => "Atari - Jaguar",
"Atari Lynx" => "Atari - Lynx",
"Atari ST" => "Atari - ST",
"Bally Midway Astrocade" => "Bally Professional - Arcade, Astrocade",
"Bally Professional Arcade &amp; Astrocade" => "Bally Professional - Arcade, Astrocade",
"Bandai Pippin @World &amp; Pippin Atmark" => "Bandai - Pippin",
"Bandai Pippin Atmark" => "Bandai - Pippin",
"Bandai Playdia" => "Bandai - Playdia",
"Bandai WonderSwan Color" => "Bandai - WonderSwan Color",
"Bandai WonderSwan" => "Bandai - WonderSwan",
"Bondwell 12" => "Bondwell - 12",
"Bondwell 2" => "Bondwell - 2",
"Bondwell Model 2" => "Bondwell - 2",
"CBS ColecoVision ADAM" => "Coleco - ColecoVision, ColecoVision ADAM",
"CBS ColecoVision" => "Coleco - ColecoVision, ColecoVision ADAM",
"Cambridge University EDSAC" => "University of Cambridge - EDSAC",
"Camputers Lynx" => "Camputers - Lynx",
"Capcom CP System III" => "Capcom - CPS III",
"Casio CFX-9850" => "Casio - CFX-9850",
"Casio Loopy" => "Casio - Loopy",
"Casio PB-1000" => "Casio - PB-1000",
"Casio PV-2000" => "Casio - PV-2000",
"Coleco ColecoVision ADAM" => "Coleco - ColecoVision, ColecoVision ADAM",
"Coleco ColecoVision" => "Coleco - ColecoVision, ColecoVision ADAM",
"Commodore Amiga CD32" => "Commodore - Amiga",
"Commodore Amiga CDTV" => "Commodore - Amiga",
"Commodore Amiga" => "Commodore - Amiga",
"Commodore C128" => "Commodore - 128",
"Commodore C16, C116 &amp; Plus-4" => "Commodore - Plus-4",
"Commodore C64" => "Commodore - 64",
"Commodore C64DTV" => "Commodore - 64 DTV",
"Commodore C65" => "Commodore - 65",
"Commodore MAX Machine &amp; VIC10" => "Commodore - VIC-10",
"Commodore PET" => "Commodore - PET",
"Commodore VIC10" => "Commodore - VIC-10",
"Commodore VIC20" => "Commodore - VIC-20",
"Creatronic Mega Duck &amp; Cougar Boy" => "Creatronic - Mega Duck, Cougar Boy",
"Cybiko Cybiko" => "Cybiko - Cybiko",
"Cybiko Xtreme" => "Cybiko - Xtreme",
"DEC PDP-1" => "DEC - PDP-1",
"DEC PDP-10" => "DEC - PDP-10",
"DEC PDP-11" => "DEC - PDP-11",
"DEC PDP-12" => "DEC - PDP-12",
"DEC PDP-15" => "DEC - PDP-15",
"DEC PDP-7" => "DEC - PDP-7",
"DEC PDP-8" => "DEC - PDP-8",
"DEC PDP-9" => "DEC - PDP-9",
"Dragon 32 &amp; 64" => "Dragon Data - Dragon",
"Dragon Data Dragon" => "Dragon Data - Dragon",
"EACA Colour Genie EG-2000" => "EACA - EG2000 Colour Genie",
"EACA EG2000 Colour Genie" => "EACA - EG2000 Colour Genie",
"ETL Mark 2" => "ETL - Mark II",
"ETL Mark 4" => "ETL - Mark IV",
"ETL Mark 4a" => "ETL - Mark IV A",
"ETL Mark II" => "ETL - Mark II",
"ETL Mark IV A" => "ETL - Mark IV A",
"ETL Mark IV" => "ETL - Mark IV",
"Elektronika BK-0010-0011M" => "Elektronika - BK-0010",
"Elektronika BK-0011-411" => "Elektronika - BK-0011",
"Elektronska Industrija Nis PECOM 32 &amp; 64" => "Elektronska Industrija Nis - PECOM 32, 64",
"Emerson Arcadia 2001" => "Emerson - Arcadia 2001",
"Enterprise 64 &amp; 128" => "Enterprise - 64, 128",
"Entex Adventure Vision" => "Entex - Adventure Vision",
"Epoch Super Cassette Vision" => "Epoch - Super Cassette Vision",
"Epson PX-8, HC-88 &amp; Geneva" => "Epson - PX-8, HC-88, Geneva",
"Exelvision EXL100" => "Exelvision - Exeltel, EXL100",
"Exelvision Exeltel" => "Exelvision - Exeltel, EXL100",
"Exidy Sorcerer" => "Exidy - Sorcerer",
"FM Towns Marty" => "Fujitsu - FM Towns",
"Fairchild Channel F" => "Fairchild - Channel F",
"Fairchild Saba" => "Fairchild - Channel F",
"Fairchild VES &amp; Channel F" => "Fairchild - Channel F",
"Front Fareast Magic Drive" => "Front Fareast - Magic Drive",
"Fuji C" => "Fuji Photo Film - FUJIC",
"Fuji Photo Film FUJIC" => "Fuji Photo Film - FUJIC",
"Fujitsu FM Towns" => "Fujitsu - FM Towns",
"Fujitsu FM-7" => "Fujitsu - FM-7",
"Funtech - Super Acan" => "Funtech - Super Acan",
"Funtech Super Acan" => "Funtech - Super Acan",
"GCE Vectrex" => "GCE - Vectrex",
"Galaksija Galaksija Plus" => "Galaksija - Galaksija, Galaksija Plus",
"Galaksija Galaksija" => "Galaksija - Galaksija, Galaksija Plus",
"Game Park GP32" => "GamePark - GP32",
"Hewlett-Packard HP48" => "Hewlett-Packard - HP48",
"Hewlett-Packard HP49" => "Hewlett-Packard - HP49",
"HomeLab BraiLab" => "HomeLab - BraiLab",
"HomeLab HomeLab" => "HomeLab - HomeLab",
"IBM PC Compatible" => "IBM - PC Compatibles",
"IBM PC Compatibles" => "IBM - PC Compatibles",
"IBM PCjr" => "IBM - PC Jr",
"Incredible Technologies Eagle" => "Incredible Technologies - Eagle",
"Infocom Z-Machine" => "Infocom - Z-Machine",
"Interact Family Computer" => "Interact - Family Computer",
"Jupiter Cantab Jupiter Ace" => "Jupiter Cantab - Jupiter Ace",
"Kaypro II" => "Kaypro - II",
"Keio University K-1" => "University of Keio - K-1",
"Konami Bemani System 573 Analog" => "Konami - System 573",
"Konami Bemani System 573 Digital" => "Konami - System 573",
"Konami System 573" => "Konami - System 573",
"Luxor ABC 80" => "Luxor - ABC 80",
"Luxor ABC 800" => "Luxor - ABC 800",
"Luxor Video Entertainment System" => "Luxor - Video Entertainment System",
"MGT Sam Coupe" => "MGT - Sam Coupe",
"MITS Altair 8800" => "MITS - Altair 8800",
"MSX MSX" => "Microsoft - MSX, MSX 2",
"MSX MSX2" => "Microsoft - MSX, MSX 2",
"MSX MSX2+" => "Microsoft - MSX, MSX 2",
"MSX Turbo-R" => "Microsoft - MSX, MSX 2",
"MSX TurboR" => "Microsoft - MSX, MSX 2",
"Magnavox Odyssey2" => "Philips - Videopac+, Odyssey2",
"Matra Hachette Alice 32" => "Matra Hachette - Alice 32 &amp; 90",
"Matsushita National JR 200" => "Matsushita National - JR 200",
"Mattel Aquarius" => "Mattel - Aquarius",
"Mattel HyperScan" => "Mattel - HyperScan",
"Mattel Intellivision" => "Mattel - Intellivision",
"Memorex Video Information System" => "Memorex - Video Information System",
"Memotech MTX" => "Memotech - MTX512",
"Memotech MTX512" => "Memotech - MTX512",
"MicroBee" => "Applied Technology - MicroBee",
"Microkey Primo" => "Microkey - Primo",
"Miles Gordon Technology Sam Coupe" => "MGT - Sam Coupe",
"NCR Decision Mate V" => "NCR - Decision Mate V",
"NCR Decision V" => "NCR - Decision Mate V",
"NEC PC-6001" => "NEC - PC-6001",
"NEC PC-8001" => "NEC - PC-8001",
"NEC PC-8201" => "NEC - PC-8201",
"NEC PC-8801" => "NEC - PC-8801",
"NEC PC-88VA" => "NEC - PC-88VA",
"NEC PC-9801" => "NEC - PC-9801",
"NEC PC-9821" => "NEC - PC-9801",
"NEC PC-Engine &amp; TurboGrafx-16" => "NEC - PC Engine, TurboGrafx 16",
"NEC PC-Engine CD &amp; TurboGrafx-16 CD" => "NEC - PC Engine CD, TurboGrafx 16 CD",
"NEC PC-FX" => "NEC - PC FX, PC FXGA",
"NEC PC-FXGA" => "NEC - PC FX, PC FXGA",
"NEC PC6001" => "NEC - PC-6001",
"NEC SuperGrafx" => "NEC - Super Grafx",
"Nascom I &amp; II" => "Nascom - I, II",
"Nintendo 64" => "Nintendo - Nintendo 64",
"Nintendo 64DD" => "Nintendo - Nintendo 64DD",
"Nintendo Famicom &amp; Entertainment System" => "Nintendo - Nintendo Entertainment System",
"Nintendo Famicom Disk System" => "Nintendo - Famicom Disk System",
"Nintendo Game Boy Advance" => "Nintendo - Game Boy Advance",
"Nintendo Game Boy Color" => "Nintendo - Game Boy Color",
"Nintendo Game Boy" => "Nintendo - Game Boy",
"Nintendo GameCube" => "Nintendo - GameCube",
"Nintendo N64" => "Nintendo - Nintendo 64",
"Nintendo Pokemon Mini" => "Nintendo - Pokemon Mini",
"Nintendo Super Famicom &amp; Super Entertainment System" => "Nintendo - Super Nintendo Entertainment System",
"Nintendo Super Famicom" => "Nintendo - Super Nintendo Entertainment System",
"Nintendo Virtual Boy" => "Nintendo - Virtual Boy",
"OCC Osborne 1 &amp; Osborne Executive" => "OCC - Osborne 1, 2, 3, 4",
"OpenPandora Pandora" => "OpenPandora - Pandora",
"Osborne OSBORNE 1 &amp; Executive" => "OCC - Osborne 1, 2, 3, 4",
"Othello Multivision" => "Sega - SG-1000, SC-3000, SF-7000, Othello Multivision",
"PEL Varazdin Orao" => "PEL Varazdin - Orao",
"PTC Sol Terminal Computer SOL-20" => "PTC - Sol Terminal Computer SOL-20",
"Philips CD-i" => "Philips - CD-i",
"Philips G7000" => "Philips - Videopac+, Odyssey2",
"Philips P2000" => "Philips - P2000",
"Philips P2000T" => "Philips - P2000",
"Philips VG 5000" => "Philips - VG 5000",
"Philips Videopac G7000" => "Philips - Videopac+, Odyssey2",
"Philips Videopac+" => "Philips - Videopac+, Odyssey2",
"Pioneer LaserActive" => "Pioneer - LaserActive",
"RCA Chip-8" => "RCA - Chip-8",
"RCA Studio II" => "RCA - Studio II",
"RCA Superchip" => "RCA - Superchip",
"REAL 3DO Interactive Multiplayer" => "Panasonic - 3DO Interactive Multiplayer",
"RM Nimbus PC" => "RM - Nimbus PC",
"RM Nimbus PC-186" => "RM - Nimbus PC",
"Radica Arcade Legends &amp; Play TV Legends" => "Radica - Arcade Legends, Play TV Legends",
"Radio-86RK Apogej BK-01" => "Radio-86RK - Apogej BK-01",
"Radio-86RK Mikro-80" => "Radio-86RK - Mikro-80",
"Radio-86RK Mikrosha" => "Radio-86RK - Mikrosha",
"Radio-86RK Partner-01.01" => "Radio-86RK - Partner-01.01",
"Radio-86RK Radio-86RK" => "Radio-86RK - Radio-86RK",
"Radio-86RK YuT-88" => "Radio-86RK - YuT-88",
"Robotron HC900, KC85 2, KC85 3 &amp; KC85 4" => "Robotron - KC85",
"Robotron KC Compact" => "Robotron - KC Compact",
"Robotron KC85 2-4" => "Robotron - KC85",
"Robotron Z1013" => "Robotron - Z1013",
"Robotron Z9001 &amp; KC85 1" => "Robotron - KC85",
"Robotron Z9001" => "Robotron - KC85",
"SABA Videoplay" => "Fairchild - Channel F",
"SNK Hyper Neo-Geo 64" => "SNK - Hyper Neo Geo 64",
"SNK Neo-Geo CD" => "SNK - Neo Geo CD",
"SNK Neo-Geo Pocket Color" => "SNK - Neo Geo Pocket Color",
"SNK Neo-Geo Pocket" => "SNK - Neo Geo Pocket",
"Sega 32X" => "Sega - 32X",
"Sega Computer 3000" => "Sega - SG-1000, SC-3000, SF-7000, Othello Multivision",
"Sega Dreamcast" => "Sega - Dreamcast",
"Sega Game 1000" => "Sega - SG-1000, SC-3000, SF-7000, Othello Multivision",
"Sega Game Gear" => "Sega - Game Gear",
"Sega Mark III &amp; Master System" => "Sega - Master System, Mark III",
"Sega Master System &amp; Mark III" => "Sega - Master System, Mark III",
"Sega Mega Drive &amp; Genesis" => "Sega - Mega Drive, Genesis",
"Sega Mega-CD &amp; Sega CD" => "Sega - Mega-CD, Sega CD",
"Sega Mega-CD and Sega CD" => "Sega - Mega-CD, Sega CD",
"Sega NAOMI 2" => "Sega - Naomi, Naomi 2, Atomiswave",
"Sega NAOMI" => "Sega - Naomi, Naomi 2, Atomiswave",
"Sega NAOMI GD-ROM" => "Sega - Naomi, Naomi 2, Atomiswave",
"Sega Pico" => "Sega - PICO",
"Sega Saturn" => "Sega - Saturn",
"Sega Super Control Station" => "Sega - SG-1000, SC-3000, SF-7000, Othello Multivision",
"Sega Visual Memory System" => "Sega - Visual Memory System",
"Sega Visual Memory Unit" => "Sega - Visual Memory System",
"Sega WonderMega" => "Sega - Mega-CD, Sega CD",
"Sharp MZ-700" => "Sharp - MZ-700",
"Sharp MZ-800 &amp; MZ-1500" => "Sharp - MZ-800, MZ-1500",
"Sharp X1 Turbo" => "Sharp - X1",
"Sharp X1" => "Sharp - X1",
"Sharp X68000" => "Sharp - X68000",
"Sinclair QL" => "Sinclair - QL",
"Sinclair ZX Spectrum" => "Sinclair - ZX Spectrum",
"Sinclair ZX-81" => "Sinclair - ZX81",
"Sinclair ZX81" => "Sinclair - ZX81",
"Sony PlayStation 2" => "Sony - PlayStation 2",
"Sony PlayStation" => "Sony - PlayStation",
"Sony PocketStation" => "Sony - PocketStation",
"Sord M5" => "Sord - M5",
"Spectravideo SVI 318 &amp; SVI 328" => "Spectravideo - SVI-318, SVI-328",
"Spectravideo SVI 318-328" => "Spectravideo - SVI-318, SVI-328",
"Spectravideo SVI-318 &amp; SVI-328" => "Spectravideo - SVI-318, SVI-328",
"TESLA PMD-85" => "Tesla - PMD 85",
"Tandy MC-10" => "Tandy Radio Shack - TRS-80 MC-10",
"Tandy Radio Shack - CoCo" => "Tandy Radio Shack - TRS-80 Color Computer",
"Tandy Radio Shack - TRS-80 - Model 1" => "Tandy Radio Shack - TRS-80 Model I",
"Tandy Radio Shack - TRS-80 - Model 3" => "Tandy Radio Shack - TRS-80 Model III",
"Tandy Radio Shack - TRS-80 - Model 4" => "Tandy Radio Shack - TRS-80 Model IV",
"Tandy Radio Shack - TRS-80 Color Computer" => "Tandy Radio Shack - TRS-80 Color Computer",
"Tandy Radio Shack - TRS-80 MC-10" => "Tandy Radio Shack - TRS-80 MC-10",
"Tandy Radio Shack - TRS-80 Model 4" => "Tandy Radio Shack - TRS-80 Model IV",
"Tandy Radio Shack - TRS-80 Model I" => "Tandy Radio Shack - TRS-80 Model I",
"Tandy Radio Shack - TRS-80 Model III" => "Tandy Radio Shack - TRS-80 Model III",
"Tandy Radio Shack TRS-80 Color Computer" => "Tandy Radio Shack - TRS-80 Color Computer",
"Tandy Radio Shack TRS-80 MC-10" => "Tandy Radio Shack - TRS-80 MC-10",
"Tandy Radio Shack TRS-80 Model 100" => "Tandy Radio Shack - TRS-80 Model 100",
"Tandy Radio Shack TRS-80 Model 4" => "Tandy Radio Shack - TRS-80 Model IV",
"Tandy Radio Shack TRS-80 Model I" => "Tandy Radio Shack - TRS-80 Model I",
"Tandy Radio Shack TRS-80 Model III" => "Tandy Radio Shack - TRS-80 Model III",
"Tangerine MICROTAN 65" => "Tangerine - Microtan 65",
"Tangerine Microtan 65" => "Tangerine - Microtan 65",
"Tangerine ORIC 1-Atmos-Telestrat" => "Tangerine - Oric-1, Oric Atmos",
"Tangerine Oric-1 &amp; Atmos" => "Tangerine - Oric-1, Oric Atmos",
"Tangerine Oric-1 &amp; Oric Atmos" => "Tangerine - Oric-1, Oric Atmos",
"Tatung Einstein TC-01" => "Tatung - Einstein TC-01",
"Technosys Aamber Pegasus" => "Technosys - Aamber Pegasus",
"Tesla PMD 85" => "Tesla - PMD 85",
"Texas Instruments CC-40" => "Texas Instruments - CC-40",
"Texas Instruments TI-73" => "Texas Instruments - TI-73",
"Texas Instruments TI-80" => "Texas Instruments - TI-80",
"Texas Instruments TI-81" => "Texas Instruments - TI-81",
"Texas Instruments TI-82" => "Texas Instruments - TI-82",
"Texas Instruments TI-83" => "Texas Instruments - TI-83",
"Texas Instruments TI-85" => "Texas Instruments - TI-85",
"Texas Instruments TI-86" => "Texas Instruments - TI-86",
"Texas Instruments TI-89" => "Texas Instruments - TI-89",
"Texas Instruments TI-92" => "Texas Instruments - TI-92",
"Texas Instruments TI-99 4A" => "Texas Instruments - TI-99 4A",
"Texas Instruments TI-99-4A+" => "Texas Instruments - TI-99 4A",
"Texas Instruments TI73" => "Texas Instruments - TI-73",
"Texas Instruments TI80" => "Texas Instruments - TI-80",
"Thomson MO5" => "Thomson - 8bit",
"Thomson MO6" => "Thomson - 8bit",
"Thomson TO7" => "Thomson - 8bit",
"Thomson TO8" => "Thomson - 8bit",
"Thomson TO9+" => "Thomson - 8bit",
"Tiger Game.com" => "Tiger Electronics - Game.com",
"Tiki Data Kontiki-100 &amp; Tiki-100" => "Tiki Data - Kontiki-100, Tiki-100",
"Tomy KISS-Site" => "Tomy - Kiss-site",
"Tomy Tutor &amp; Pyuuta" => "Tomy - Tutor, Pyuuta",
"Tsukuda Original Othello Multivision" => "Sega - SG-1000, SC-3000, SF-7000, Othello Multivision",
"Tsukuda Othello Multivision" => "Sega - SG-1000, SC-3000, SF-7000, Othello Multivision",
"University of Cambridge EDSAC" => "University of Cambridge - EDSAC",
"University of Tokyo PC-1" => "University of Tokyo - PC-1",
"VM Labs Nuon" => "VM Labs - Nuon",
"VTech Creativision" => "VTech - CreatiVision",
"VTech Laser 200" => "VTech - Laser",
"VTech Laser 2001 &amp; CreatiVision" => "VTech - CreatiVision",
"VTech Laser 310" => "VTech - Laser",
"VTech V.Flash Home Edutainment System" => "VTech - V.Flash Home Edutainment System",
"Videoton TV Computer 64" => "Videoton - TV-Computer",
"Videoton TV-Computer" => "Videoton - TV-Computer",
"Visual Technology Visual 1050" => "Visual Technology - Visual 1050",
"Wang VS" => "Wang - VS",
"Watara Supervision" => "Watara - Supervision",
"ZAPiT Games Game Wave Family Entertainment System" => "ZAPiT Games - Game Wave Family Entertainment System",
);
// TruRip DAT name base mapping
$mapping_trurip = array (
"Acorn Archimedes" => "Acorn - Archimedes",
"Acorn Archimedes CD" => "Acorn - Archimedes",
"Acorn BBC Microcomputer System" => "Acorn - BBC, Electron",
"American Laser Games American Laser Games (Arcade)" => "American Laser Games - CD-ROM System",
"Amstrad GX4000" => "Amstrad - GX4000",
"Andamiro Pump It Up (Arcade)" => "Andamiro - Pump It Up",
"Apple Macintosh CD" => "Apple - Macintosh",
"Atari 5200" => "Atari - 5200",
"Atari 7800" => "Atari - 7800",
"Atari Jaguar CD" => "Atari - Jaguar CD",
"Atari Lynx" => "Atari - Lynx",
"Bandai Pippin @World &amp; Atmark" => "Bandai - Pippin",
"Bandai Playdia" => "Bandai - Playdia",
"Bandai WonderSwan Color (SwanCrystal)" => "Bandai - WonderSwan Color",
"Bandai WonderSwan" => "Bandai - WonderSwan",
"Capcom CP SYSTEM III" => "Capcom - CPS III",
"Capcom CP SYSTEM III (CPS3)" => "Capcom - CPS III",
"Commodore Amiga CD" => "Commodore - Amiga",
"Commodore Amiga CD32" => "Commodore - Amiga",
"Commodore Amiga CDTV" => "Commodore - Amiga",
"Fairchild Channel F (Video Entertainment System)" => "Fairchild - Channel F",
"Fujitsu FM Towns (Marty)" => "Fujitsu - FM Towns",
"IBM Compatible IBM PC compatible" => "IBM - PC Compatibles",
"IBM PC Compatible IBM PC compatible" => "IBM - PC Compatibles",
"Incredible Technologies IT Eagle" => "Incredible Technologies - Eagle",
"Incredible Technologies IT PC" => "Incredible Technologies - PC",
"Konami Bemani FireBeat" => "Konami - Bemani FireBeat",
"Konami Bemani Twinkle" => "Konami - Bemani Twinkle",
"Konami M2" => "Panasonic - 3DO M2",
"Konami System 573" => "Konami - System 573",
"Mattel HyperScan" => "Mattel - HyperScan",
"Memorex VIS interactive Video Information" => "Memorex - Video Information System",
"MSX MSX CD" => "Microsoft - MSX, MSX 2",
"Namco - Sega - Nintendo Triforce" => "Namco - Triforce",
"Namco System 2x6" => "Namco - System 246, System 256",
"NCR Decision Mate V" => "NCR - Decision Mate V",
"NEC PC Engine CD &amp; TurboGrafx CD" => "NEC - PC Engine CD, TurboGrafx 16 CD",
"NEC PC-FX" => "NEC - PC FX, PC FXGA",
"NEC PC-FXGA" => "NEC - PC FX, PC FXGA",
"Panasonic 3DO Interactive Multiplayer" => "Panasonic - 3DO Interactive Multiplayer",
"Philips CD-i &amp; VCD" => "Philips - CD-i",
"Philips Videopac + G7400" => "Philips - Videopac+, Odyssey2",
"Sega Chihiro" => "Sega - Chihiro",
"Sega Dreamcast" => "Sega - Dreamcast",
"Sega Lindbergh" => "Sega - Lindbergh",
"Sega Mega-CD &amp; Sega CD" => "Sega - Mega-CD, Sega CD",
"Sega Mega-CD &amp; Sega CD - Games" => "Sega - 32X CD",
"Sega NAOMI 2" => "Sega - Naomi, Naomi 2, Atomiswave",
"Sega NAOMI" => "Sega - Naomi, Naomi 2, Atomiswave",
"Sega RingWide" => "Sega - RingWide",
"Sega Saturn" => "Sega - Saturn",
"Sharp X1" => "Sharp - X1",
"SNK Neo-Geo CD" => "SNK - Neo Geo CD",
"Sony PlayStation &amp; PSone" => "Sony - PlayStation",
"Sord CGL M 5 (M 5, Game M 5)" => "Sord - M5",
"Spectravideo SV-318 &amp; SV-328" => "Spectravideo - SVI-318, SVI-328",
"Tesla PMD-85" => "Tesla - PMD 85",
"Tiger Game.com" => "Tiger Electronics - Game.com",
"Tomy Grandstand Tutor (Tutor, Pyuuta)" => "Tomy - Tutor, Pyuuta",
"Tomy Kiss-site" => "Tomy - Kiss-site",
"Tsukuda Original Othello Multivision" => "Sega - SG-1000, SC-3000, SF-7000, Othello Multivision",
"Videoton TV-Computer" => "Videoton - TV-Computer",
"VM Labs Nuon" => "VM Labs - Nuon",
"VTech V.Flash Home Edutainment System" => "VTech - V.Flash Home Edutainment System",
"Wang VS" => "Wang - VS",
"Watara SuperVision (Quickshot, Hartung SV-100, HiperVision, Tiger Boy)" => "Watara - Supervision",
"ZAPiT Games Game Wave Family Entertainment System" => "ZAPiT Games - Game Wave Family Entertainment System",
);
?>

View File

@@ -14,7 +14,6 @@ ob_start();
<?php
include_once("css/style.php");
include_once("includes/remapping.php");
include_once("includes/functions.php");
// Connect to the database so it doesn't have to be done in every page
@@ -35,14 +34,6 @@ else
echo "<p>
Welcome to the WoD Revival homepage!
<ul>
<li><a href='?page=view'>Viewing system, source, and game data</a></li>
<li><a href='?page=generate'>Creating and downloading DATs</a><ul>
<li>Merged dats based on multiple sources</li>
<li>Custom dats based on a single source</li>
</ul></li>
</ul>
</p>
<p><a href='admin/'>Access administrative functions (admin/admin)</a></p>";
}

View File

@@ -1,723 +0,0 @@
<?php
/* ------------------------------------------------------------------------------------
Create a DAT from the database
Original code by Matt Nadareski (darksabre76), emuLOAD
TODO: emuload - For CMP, a virtual parent can be created as an empty set and then
each set that has it as a parent sets it as cloneof
------------------------------------------------------------------------------------ */
// All possible $_GET variables that we can use (propogate this to other files?)
$getvars = array(
"mega", // override to create complete merged DAT
"auto", // auto-create all available DATs
);
$postvars = array(
"generate", // If a DAT should be generated (only on submit)
"system", // systems.id
"source", // sources.id
"all", // All sources selected
"old", // Set this to 1 for the old style output
);
// Map systems to headers for datfile creation
$headers = array(
"25" => "a7800.xml",
"228" => "fds.xml",
"31" => "lynx.xml",
"0" => "mega.xml", // Merged version of all other headers
"234" => "n64.xml",
"238" => "nes.xml",
"241" => "snes.xml", // Self-created to deal with various headers
);
ini_set('max_execution_time', 0); // Set the execution time to infinite. This is a bad idea in production.
ini_set("memory_limit", "-1"); // Set the maximum memory to infinite. This is a bad idea in production.
//Get the values for all parameters
foreach ($getvars as $var)
{
$$var = (isset($_GET[$var]) ? trim($_GET[$var]) : "");
}
//Get the values for all parameters
foreach ($postvars as $var)
{
$$var = (isset($_POST[$var]) ? trim($_POST[$var]) : "");
}
// Specifically deal with MEGA being set
if ($mega == "1")
{
$system = "";
$source = "";
}
// If not generating or creating MEGAMERGED, show the list of all available DATs
if ($generate != "1" && $mega != "1" && $auto != "1")
{
echo <<<EOL
<h2>Export to Datfile</h2>
<table>
<tr><th>System</th><th>Source</th></tr>
<tr><td>
<form name="systemselect" action="?page=generate" method="post">
<select name="system" onChange="window.document.forms['systemselect'].submit();">\n
EOL;
$query = "SELECT DISTINCT systems.id, systems.manufacturer, systems.system
FROM systems
JOIN games
ON systems.id=games.system
ORDER BY systems.manufacturer, systems.system";
$result = mysqli_query($link, $query);
// Either generate options for custom and system-merged DATs OR generate them in auto mode
while($sys = mysqli_fetch_assoc($result))
{
// If nothing is set, use the default option
if ($system == "" && $source == "")
{
$system = $sys["id"];
}
echo "<option value='".$sys["id"]."'".($system == $sys["id"] ? " selected='selected'" : "").">".$sys["manufacturer"]." - ".$sys["system"]."</option>\n";
}
echo <<<EOL
</select></form></td>
<td>
<form name="sourceselect" action="?page=generate" method="post">
<select name="source" onChange="window.document.forms['sourceselect'].submit();">\n
EOL;
// Generate options for source-merged DATs
$query = "SELECT DISTINCT sources.id, sources.name
FROM sources
JOIN games
ON sources.id=games.source
ORDER BY sources.name";
$result = mysqli_query($link, $query);
while($src = mysqli_fetch_assoc($result))
{
// If the source is not one of the import-only ones
if ((int) $src["id"] > 14)
{
echo "<option value='".$src["id"]."'".($source == $src["id"] ? " selected='selected'" : "").">".$src["name"]."</option>\n";
}
}
echo "</select><br/>
</form></tr></table>";
// If the system is set, it takes precidence in DAT creation
if ($system != "")
{
echo <<<EOL
<form name="dat" action="?page=generate" method="post">
<input type="hidden" name="generate" value="1">
<input type="hidden" name="system" value="$system">
<h3>Sources:</h3>
<input type="radio" name="all" value="1" checked>All sources <b> OR </b> <input type="radio" name="all" value="0">Select a source below:<p/>\n
EOL;
$query = "SELECT DISTINCT sources.id, sources.name
FROM systems
JOIN games
ON systems.id=games.system
JOIN sources
ON games.source=sources.id
WHERE systems.id=".$system.
" ORDER BY sources.name";
$result = mysqli_query($link, $query);
while($src = mysqli_fetch_assoc($result))
{
echo "<input type=\"checkbox\" name=\"".$src["id"]."\" value=\"1\">".$src["name"]."<br/>";
}
}
// If the source is set, show all values for the source
else if ($source != "")
{
echo <<<EOL
<form name="dat" action="?page=generate" method="post">
<input type="hidden" name="generate" value="1">
<input type="hidden" name="source" value="$source">
<h3>Systems:</h3>
<input type="radio" name="all" value="1" checked>All systems <b> OR </b> <input type="radio" name="all" value="0">Select a system below:<p/>\n
EOL;
$query = "SELECT DISTINCT systems.id, systems.manufacturer, systems.system
FROM sources
JOIN games
ON sources.id=games.source
JOIN systems
ON games.system=systems.id
WHERE sources.id=".$source.
" ORDER BY systems.manufacturer, systems.system";
$result = mysqli_query($link, $query);
while($sys = mysqli_fetch_assoc($result))
{
echo "<input type=\"checkbox\" name=\"".$sys["id"]."\" value=\"1\">".$sys["manufacturer"]." - ".$sys["system"]."<br/>";
}
}
echo "<br/><h3>Datfile format:</h3>
<input type='radio' name='old' value='0' checked>XML Format<br/>
<input type='radio' name='old' value='1'>Old Format<p/>
<input type='submit' value='Submit'>
</form><p/>
<a href='?page=generate&mega=1'>Create DAT of all available files</a><br/>";
}
// If auto is set, create all DATs and zip for distribution
elseif ($auto == "1")
{
echo "<h2>Generate All DATs</h2>";
$query = "SELECT DISTINCT systems.id, systems.manufacturer, systems.system
FROM systems
JOIN games
ON systems.id=games.system
ORDER BY systems.manufacturer, systems.system";
$result = mysqli_query($link, $query);
// Generate system-merged and custom DATs
while($sys = mysqli_fetch_assoc($result))
{
echo "Beginning generate ".$sys["manufacturer"]." - ".$sys["system"]." (merged)<br/>\n";
generate_dat($sys["id"], "");
sleep(2);
$squery = "SELECT DISTINCT sources.id, sources.name
FROM systems
JOIN games
ON systems.id=games.system
JOIN sources
ON games.source=sources.id
WHERE systems.id=".$sys["id"]."
ORDER BY sources.name";
$sresult = mysqli_query($link, $squery);
while($src = mysqli_fetch_assoc($sresult))
{
// If the source is not one of the import-only ones
if ((int) $src["id"] > 14)
{
echo "Beginning generate ".$sys["manufacturer"]." - ".$sys["system"]." (".$src["name"].")<br/>\n";
generate_dat($sys["id"], $src["id"]);
sleep(2);
}
}
// Free up some memory if possible
unset($sresult);
}
// Free up some memory if possible
unset($result);
// Generate source-merged DATs
$query = "SELECT DISTINCT sources.id, sources.name
FROM sources
JOIN games
ON sources.id=games.source
ORDER BY sources.name";
$result = mysqli_query($link, $query);
while($src = mysqli_fetch_assoc($result))
{
echo "Beginning generate ALL (".$src["name"].")<br/>\n";
generate_dat("", $src["id"]);
sleep(2);
}
// Free up some memory if possible
unset($result);
// Create the MEGAMERGED as part of the generation process
echo "Beginning generate ALL (merged)<br/>\n";
generate_dat("", "");
//echo "Creating new zipfile...<br/>\n";
$zip = new ZipArchive();
$zip->open("temp/dats-".date("Ymd").".zip", ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
// Seems unnecessary, but helps make sure the zipfile is populated correctly
$zip->addEmptyDir("merged-system");
$zip->addEmptyDir("merged-source");
$zip->addEmptyDir("custom");
//echo "Zipfile created successfully!<br/>\n";
foreach (scandir("temp/output") as $item)
{
if (strpos($item, ".xml") !== FALSE || strpos($item, ".dat") !== FALSE)
{
//echo "Adding ".$item."<br/>\n";
$zip->addFile("temp/output/".$item,
(strpos($item, "ALL (merged") !== FALSE ? $item :
(strpos($item, "merged") !== FALSE ? "merged-system/".$item :
(strpos($item, "ALL") !== FALSE ? "merged-source/".$item : "custom/".$item))));
}
}
$zip->close();
// http://php.net/manual/en/function.unlink.php#109971
array_map("unlink", glob("temp/output/*.*"));
}
// If we are generating an individual DAT
elseif ($generate == "1" || $mega == "1")
{
$systems = array();
$sources = array();
// If we have a source, treat all POST vars as systems
if ($system == "" && $source != "")
{
$sources = $source;
if ($all == "1")
{
$systems = "";
}
else
{
foreach ($_POST as $key => $value)
{
if (!in_array($key, $postvars) && $value == "1")
{
$systems[] = $key;
}
}
$systems = implode(", ", $systems);
}
}
// If we have a system, treat all POST vars as sources
elseif ($system != "" && $source == "")
{
$systems = $system;
if ($all == "1")
{
$sources = "";
}
else
{
foreach ($_POST as $key => $value)
{
if (!in_array($key, $postvars) && $value == "1")
{
$sources[] = $key;
}
}
$sources = implode(", ", $sources);
}
}
// If we have neither, then it's MEGA
else
{
$systems = "";
$sources = "";
}
// If the source is not one of the import-only ones
if (!($sources != "" && sizeof(explode(", ", $sources)) == 1 && (int) $sources <= 14))
{
generate_dat($systems, $sources, true);
}
exit();
}
/*
If just the source is set, create a DAT that has each game suffixed by system and merged
If just the system is set, create a DAT that has each game suffixed by source and merged (merged)
If both system and source are set, create a DAT that has each rom unsuffixed and unmerged (custom)
*/
function generate_dat ($systems, $sources, $lone = false)
{
global $link, $headers;
// Get the systems and sources names for the given inputs
$querysy = "SELECT manufacturer, system FROM systems WHERE id IN (".$systems.")";
$resultsy = mysqli_query($link, $querysy);
$syslist = "";
// If the result has data, populate the srclist
if (gettype($resultsy) != "boolean" && mysqli_num_rows($resultsy) > 0)
{
$syslist = array();
while ($sys = mysqli_fetch_assoc($resultsy))
{
$syslist[] = $sys["manufacturer"]." - ".$sys["system"];
}
$syslist = implode("; ", (sizeof($syslist) > 3 ? array($syslist[0], $syslist[1], "etc.") : $syslist));
}
// Free up some memory if possible
unset($resultsy);
$queryso = "SELECT name FROM sources WHERE id IN (".$sources.")";
$resultso = mysqli_query($link, $queryso);
$srclist = "";
// If the result has data, populate the srclist
if (gettype($resultso) != "boolean" && mysqli_num_rows($resultso) > 0)
{
$srclist = array();
while ($src = mysqli_fetch_assoc($resultso))
{
$srclist[] = $src["name"];
}
$srclist = implode("; ", (sizeof($srclist) > 3 ? array($srclist[0], $srclist[1], "etc.") : $srclist));
}
// Free up some memory if possible
unset($resultso);
// Retrieve the roms in a preprocessed order
$roms = process_roms($systems, $sources);
$version = date("YmdHis");
// Create a name for the file based on the retrieved information
$datname = ($syslist != "" ? $syslist : "ALL")." (".($srclist != "" ? $srclist : "merged")." ".$version.")";
// Create and open an output file for writing (currently uses current time, change to "last updated time"
if ($lone)
{
ob_end_clean();
//First thing first, push the http headers
header('content-type: application/x-gzip');
header('Content-Disposition: attachment; filename="'.$datname.($old == "1" ? ".dat" : ".xml").'.gz"');
}
else
{
echo "Opening file for writing: temp/output/".$datname.($old == "1" ? ".dat" : ".xml")."<br/>\n";
$handle = fopen("temp/output/".$datname.($old == "1" ? ".dat" : ".xml"), "w");
}
// Temporarilly set $system if we're in MEGAMERGED mode to get the right header skip XML
if ($systems == "" && $sources == "")
{
$systems = "0";
}
$header_old = "clrmamepro (
name \"".htmlspecialchars($datname)."\"
description \"".htmlspecialchars($datname)."\"
version \"".$version."\"
".($system != "" && array_key_exists($systems, $headers) ? " header \"".$headers[$systems]."\"" : "")."
comment \"\"
author \"The Wizard of DATz\"
)\n";
$header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE datafile PUBLIC \"-//Logiqx//DTD ROM Management Datafile//EN\" \"http://www.logiqx.com/Dats/datafile.dtd\">
<datafile>
<header>
<name>".htmlspecialchars($datname)."</name>
<description>".htmlspecialchars($datname)."</description>
<category>The Wizard of DATz</category>
<version>".$version."</version>
<date>".$version."</date>
<author>The Wizard of DATz</author>
<clrmamepro".($systems != "" && array_key_exists($systems, $headers) ? " header=\"".$headers[$systems]."\"" : "")."/>
</header>\n";
$footer = "\n</datafile>";
// Unset $system again if we're in MEGAMERGED mode
if ($system == "0" && $source == "")
{
$system = "";
}
if (!$lone)
{
echo "Writing data to file<br/>\n";
}
$lastgame = "";
if ($old == "1")
{
// Write the header out
if ($lone)
{
echo gzencode($header_old, 9);
}
else
{
fwrite($handle, $header_old);
}
// Write out each of the machines and roms
foreach ($roms as $rom)
{
$state = "";
if ($lastgame != "" && $lastgame != $rom["game"])
{
$state = $state.")\n";
}
if ($lastgame != $rom["game"])
{
$state = $state."game (\n".
"\tname \"".$rom["game"]."\"\n".
"\tdescription \"".$rom["game"]."\"\n";
}
$state = $state."\t".$rom["type"]." ( name \"".$rom["name"]."\"".
($rom["size"] != "0" ? " size ".$rom["size"] : "").
($rom["crc"] != "" ? " crc ".$rom["crc"] : "").
($rom["md5"] != "" ? " md5 ".$rom["md5"] : "").
($rom["sha1"] != "" ? " sha1 ".$rom["sha1"] : "").
" )\n";
$lastgame = $rom["game"];
if ($lone)
{
echo gzencode($state, 9);
}
else
{
fwrite($handle, $state);
}
}
if ($lone)
{
echo gzencode(")", 9);
}
else
{
fwrite($handle, ")");
}
}
else
{
// Write the header out
if ($lone)
{
echo gzencode($header, 9);
}
else
{
fwrite($handle, $header);
}
// Write out each of the machines and roms
foreach ($roms as $rom)
{
// Preprocess each game and rom name for safety
$rom["game"] = htmlspecialchars(utf8_encode($rom["game"]));
$rom["name"] = htmlspecialchars(utf8_encode($rom["name"]));
$state = "";
if ($lastgame != "" && $lastgame != $rom["game"])
{
$state = $state."\t</machine>\n";
}
if ($lastgame != $rom["game"])
{
$state = $state."\t<machine name=\"".$rom["game"]."\">\n".
"\t\t<description>".$rom["game"]."</description>\n";
}
$state = $state."\t\t<".$rom["type"]." name=\"".$rom["name"]."\"".
($rom["size"] != "" ? " size=\"".$rom["size"]."\"" : "").
($rom["crc"] != "" ? " crc=\"".$rom["crc"]."\"" : "").
($rom["md5"] != "" ? " md5=\"".$rom["md5"]."\"" : "").
($rom["sha1"] != "" ? " sha1=\"".$rom["sha1"]."\"" : "").
" />\n";
$lastgame = $rom["game"];
if ($lone)
{
echo gzencode($state, 9);
}
else
{
fwrite($handle, $state);
}
}
if ($lone)
{
echo gzencode("\t</machine>", 9);
echo gzencode($footer, 9);
}
else
{
fwrite($handle, "\t</machine>");
fwrite($handle, $footer);
}
}
if (!$lone)
{
fclose($handle);
echo "File written!<br/>\n";
}
}
// Change duplicate names and remove duplicates (merged only)
function process_roms($systems, $sources)
{
global $link;
// Check if we're in a merged mode
$sysmerged = $systems == "" || sizeof(explode(", ", $systems)) > 1;
$srcmerged = $sources == "" || sizeof(explode(", ", $sources)) > 1;
$merged = $sysmerged || $srcmerged;
// Since the source and/or system are valid, retrive all files
$query = "SELECT DISTINCT systems.manufacturer AS manufacturer, systems.system AS system, systems.id AS systemid,
sources.name AS source, sources.url AS url, sources.id AS sourceid,
games.name AS game, files.name AS name, files.type AS type, checksums.size AS size, checksums.crc AS crc,
checksums.md5 AS md5, checksums.sha1 AS sha1
FROM systems
JOIN games
ON systems.id=games.system
JOIN sources
ON games.source=sources.id
JOIN files
ON games.id=files.setid
JOIN checksums
ON files.id=checksums.file".
(!$sysmerged || !$srcmerged ? "\nWHERE" : "").
(!$srcmerged ? " sources.id IN (".$sources.")" : "").
(!$srcmerged && !$sysmerged ? " AND" : "").
(!$sysmerged ? " systems.id IN (".$systems.")" : "")."
ORDER BY ".
($merged ? "checksums.size, checksums.crc, checksums.md5, checksums.sha1"
: "systems.id, sources.id, games.name, files.name");
$result = mysqli_query($link, $query);
// If there are no games for this set of parameters, tell the user
if (gettype($result) == "boolean" || mysqli_num_rows($result) == 0)
{
echo "No games could be found with those inputs. Please check and try again.<br/>";
echo "<a href='?page=generate'>Go Back</a>";
exit;
}
// Retrieve the array from the sql result
$roms = mysqli_fetch_all($result, MYSQLI_ASSOC);
// If we're in merged mode, take care of merging before renaming
if ($merged)
{
// First, dedupe the set
$lastgood = 0;
for ($i = 0; $i < sizeof($roms); $i++)
{
$rom = $roms[$i];
$last = $roms[$lastgood];
// Check if the rom is a duplicate
$dupe = false;
if ($rom["type"] == "rom" && $last["type"] == "rom")
{
$dupe = (($rom["size"] != -1 && $rom["size"] == $last["size"]) && (
($rom["crc"] != "" && $last["crc"] != "" && $rom["crc"] == $last["crc"]) ||
($rom["md5"] != "" && $last["md5"] != "" && $rom["md5"] == $last["md5"]) ||
($rom["sha1"] != "" && $last["sha1"] != "" && $rom["sha1"] == $last["sha1"])
)
);
}
else if ($rom["type"] == "disk" && $lasttype == "disk")
{
$dupe = (($rom["md5"] != "" && $last["md5"] != "" && $rom["md5"] == $last["md5"]) ||
($rom["sha1"] != "" && $last["sha1"] != "" && $rom["sha1"] == $last["sha1"])
);
}
// If it's a duplicate, unset it so it's not in the output, but add the info to the previous item
if ($dupe)
{
$last["crc"] = ($last["crc"] == "" && $rom["crc"] != "" ? $rom["crc"] : $last["crc"]);
$last["md5"] = ($last["md5"] == "" && $rom["md5"] != "" ? $rom["md5"] : $last["md5"]);
$last["sha1"] = ($last["sha1"] == "" && $rom["sha1"] != "" ? $rom["sha1"] : $last["sha1"]);
$roms[$lastgood] = $last;
unset($roms[$i]);
}
// Otherwise, set the last unset rom
else
{
$lastgood = $i;
}
}
// Then we put it in the right order
usort($roms, function ($a, $b)
{
if ($a["systemid"] == $b["systemid"])
{
if ($a["sourceid"] == $b["sourceid"])
{
if ($a["game"] == $b["game"])
{
return strcmp($a["name"], $b["name"]);
}
return strcmp($a["game"], $b["game"]);
}
return (int) $a["sourceid"] - (int) $b["sourceid"];
}
return (int) $a["systemid"] - (int) $b["systemid"];
});
}
// Rename the games and roms if necessary
$lastname = ""; $lastgame = "";
foreach ($roms as &$rom)
{
// If we're in merged mode, rename the game associated
if ($merged)
{
$rom["game"] = $rom["game"].
($sysmerged ? " [".$rom["manufacturer"]." - ".$rom["system"]."]" : "").
($srcmerged ? " [".$rom["source"]."]" : "");
}
// Now relable any roms that have the same name inside of the same game
$samename = false; $samegame = false;
if ($rom["name"] != "")
{
$samename = ($lastname == $rom["name"]);
}
if ($rom["game"] != "")
{
$samegame = ($lastgame == $rom["game"]);
}
$lastname = $rom["name"];
$lastgame = $rom["game"];
// If the name and set are the same, rename it with whatever is different
if ($samename && $samegame)
{
$rom["name"] = preg_replace("/^(.*)(\..*)/", "$1 (".
($rom["crc"] != "" ? $rom["crc"] :
($rom["md5"] != "" ? $rom["md5"] :
($rom["sha1"] != "" ? $rom["sha1"] : "Alt"))).
")$2", $rom["name"]);
}
}
// Return the sorted list of roms
return $roms;
}
?>

View File

@@ -1,279 +0,0 @@
<?php
/* ------------------------------------------------------------------------------------
View systems, sources, games, and parents from one convenient location.
Original code by Matt Nadareski (darksabre76)
TODO: Add search functionality
------------------------------------------------------------------------------------ */
// All possible $_GET variables that we can use (propogate this to other files?)
$getvars = array(
"system", // systems.id
"source", // sources.id
"game", // games.id
"offset", // offset for pagination
);
//Get the values for all parameters
foreach ($getvars as $var)
{
$$var = (isset($_GET[$var]) && $_GET[$var] != "-1" ? trim($_GET[$var]) : "");
}
// Assuming there are no relevent params show the basic page
if ($system == "" && $source == "" && $game == "")
{
show_default($link);
}
// Then capture game view mode, it also takes precidence over the others.
elseif ($game != "")
{
// Get the total count in the case that it needs limiting
$query = "SELECT COUNT(*) as count
FROM systems
JOIN games
ON systems.id=games.system
JOIN sources
ON games.source=sources.id
JOIN files
ON games.id=files.setid
JOIN checksums
ON files.id=checksums.file
WHERE games.id=".$game;
$count = mysqli_query($link, $query);
$count = mysqli_fetch_assoc($count);
$count = $count["count"];
settype($count, "integer");
// Retrieve the game info
$query = "SELECT systems.manufacturer AS manufacturer,
systems.system AS system,
systems.id AS systemid,
sources.name AS source,
sources.id AS sourceid,
games.name AS game,
files.id AS file,
files.name AS name,
files.type AS type,
checksums.size AS size,
checksums.crc AS crc,
checksums.md5 AS md5,
checksums.sha1 AS sha1
FROM systems
JOIN games
ON systems.id=games.system
JOIN sources
ON games.source=sources.id
JOIN files
ON games.id=files.setid
JOIN checksums
ON files.id=checksums.file
WHERE games.id=".$game.
" LIMIT 50 OFFSET ".($offset == "" ? "0" : ($offset*5)."0");
$result = mysqli_query($link, $query);
if (gettype($result) == "boolean" || mysqli_num_rows($result) == 0)
{
echo "No game info could be retrieved! There might be an error.<br/>";
exit;
}
$roms = mysqli_fetch_all($result);
$game_info = $roms[0];
echo "<h2>View the Game Information Below</h2>
<table>
<tr>
<th width='100px'>System</th>
<td>".$game_info[0]." - ".$game_info[1]."</td>
</tr>
<tr>
<th>Source</th>
<td>".$game_info[3]."</td>
</tr>
<tr>
<th>Name</th>
<td>".$game_info[5]."</td>
</tr>
</table><br/>
<table>
<tr>
<th>Name</th><th>Type</th><th>Size</th><th>CRC</th><th>MD5</th><th>SHA-1</th>
</tr>";
foreach ($roms as $rom)
{
echo "<tr>\n";
for ($i = 7; $i < 13; $i++)
{
echo "\t<td>".$rom[$i]."</td>\n";
}
echo "</tr>\n";
}
echo "</table><br/>";
echo "<br/>";
if ($offset != "" && $offset > 0)
{
echo "<a href='?page=view&system=".$system."&source=".$source."&game=".$game."&offset=".($offset-1)."'>Last 50</a> ";
}
if ($count > (mysqli_num_rows($result) + ($offset == "" ? 0 : $offset*50)))
{
echo "<a href='?page=view&system=".$system."&source=".$source."&game=".$game."&offset=".($offset+1)."'>Next 50</a>";
}
echo "<br/>";
echo "<a href='?page=view".
($source != "" ? "&source='".$source : "").
($system != "" ? "&system='".$system : "").
"'>Back to previous page</a><br/>\n";
}
else
{
// Retrieve source info only so it's not duplicated
if ($source != "")
{
$query = "SELECT name, url FROM sources WHERE id='".$source."'";
$source_result = mysqli_query($link, $query);
$source_info = mysqli_fetch_assoc($source_result);
}
// Retrieve system info only so it's not duplicated
if ($system != "")
{
$query = "SELECT manufacturer, system FROM systems WHERE id='".$system."'";
$system_result = mysqli_query($link, $query);
$system_info = mysqli_fetch_assoc($system_result);
}
// Get the total count in the case that it needs limiting
$query = "SELECT COUNT(*) as count
FROM systems
JOIN games
ON systems.id=games.system
JOIN sources
ON games.source=sources.id
WHERE ".
($source != "" ? "sources.id=".$source : "").
($source != "" && $system != "" ? " AND " : "").
($system != "" ? "systems.id=".$system : "");
$count = mysqli_query($link, $query);
$count = mysqli_fetch_assoc($count);
$count = $count["count"];
settype($count, "integer");
// Then get all games assocated
$query = "SELECT games.name AS name,
games.id AS id,
systems.manufacturer AS manufacturer,
systems.system AS system,
sources.name AS source
FROM systems
JOIN games
ON systems.id=games.system
JOIN sources
ON games.source=sources.id
WHERE ".
($source != "" ? "sources.id=".$source : "").
($source != "" && $system != "" ? " AND " : "").
($system != "" ? "systems.id=".$system : "").
" ORDER BY games.name ASC
LIMIT 50 OFFSET ".($offset == "" ? "0" : ($offset*5)."0");
$games_result = mysqli_query($link, $query);
echo "<h2>Games With This ".
($source != "" ? "Source" : "").
($source != "" && $system != "" ? " And " : "").
($system != "" ? "System" : "")."</h2>\n";
if (gettype($games_result) != "boolean")
{
while ($game = mysqli_fetch_assoc($games_result))
{
echo "<a href='?page=view&game=".$game["id"]."'>".$game["name"];
if ($source != "" && !$system != "")
{
echo " (".$game["manufacturer"]." - ".$game["system"].")";
}
if (!$source != "" && $system != "")
{
echo " (".$game["source"].")";
}
echo "</a><br/>\n";
}
echo "<br/>";
if ($offset != "" && $offset > 0)
{
echo "<a href='?page=view&system=".$system."&source=".$source."&offset=".($offset-1)."'>Last 50</a> ";
}
if ($count > (mysqli_num_rows($games_result) + ($offset == "" ? 0 : $offset*50)))
{
echo "<a href='?page=view&system=".$system."&source=".$source."&offset=".($offset+1)."'>Next 50</a>";
}
echo "<br/>";
}
else
{
echo "No games could be found!";
}
echo "<br/>";
}
// Requires the mysqli link
function show_default($link)
{
// Retrieve the system listing
$query = "SELECT id, manufacturer, system FROM systems
ORDER BY manufacturer ASC,
system ASC";
$result = mysqli_query($link, $query);
$systems = mysqli_fetch_all($result, MYSQLI_ASSOC);
// Retrieve the sources listing
$query = "SELECT id, name FROM sources
ORDER BY name ASC";
$result = mysqli_query($link, $query);
$sources = mysqli_fetch_all($result, MYSQLI_ASSOC);
// Output the input selection form
echo <<<END
<form action='index.php' method='get'>
<input type='hidden' name='page' value='view' />
<h2>Select a System or Source</h2>
<select name='system' id='system'>
<option value='' selected='selected'>Choose a System</option>
END;
foreach ($systems as $system)
{
echo "<option value='".$system["id"]."'>".$system["manufacturer"]." - ".$system["system"]."</option>\n";
}
echo "</select>
<select name='source' id='source'>
<option value='' selected='selected'>Choose a Source</option>";
foreach ($sources as $source)
{
echo "<option value='".$source["id"]."'>".$source["name"]."</option>\n";
}
echo "</select><br/>
<input type='submit'>
</form><br/><br/>\n";
// Retieve the last 30 games to be updated, based on lastupdated time
$query = "SELECT games.name as name, files.lastupdated as lu, systems.manufacturer as manufacturer, systems.system as system
FROM files
JOIN games ON files.setid=games.id
JOIN systems ON games.system=systems.id
ORDER BY files.lastupdated DESC
LIMIT 30";
$result = mysqli_query($link, $query);
echo "<table style='border: 1'>
<tr><th>Game</th><th>System</th><th>Last Updated</th></tr>\n";
while ($row = mysqli_fetch_assoc($result))
{
echo "<tr><td>".$row["name"]."</td><td>".$row["manufacturer"]." - ".$row["system"]."</td><td>".$row["lu"]."</td></tr>\n";
}
echo "</table><br/><br/>\n";
}
?>

View File

@@ -6,6 +6,7 @@ print "<pre>";
print "load <a href=?page=onlinecheck&source=".$_GET["source"]."&type=full>full</a>\n";
print "load <a href=?page=onlinecheck&source=".$_GET["source"]."&type=updates>updates</a>\n";
/*
if ($_GET["type"] == "updates")
{
$full_query = implode('', file("../sites/".$source."_full.txt"));
@@ -23,7 +24,8 @@ if ($_GET["type"] == "updates")
$old = 0;
print "load :".$fullURL."\n";
$query = get_data($fullURL);
$query = get_data("http://www.cpc-power.com".$fullURL);
$query = explode('<img src="images/download.gif" />&nbsp; &nbsp;<a href="', $query);
$query[0] = null;
@@ -49,6 +51,7 @@ if ($_GET["type"] == "updates")
sleep(1);
}
*/
if ($_GET["type"] == "updates")
{
@@ -114,8 +117,6 @@ if ($u_query)
$name = explode(';return false;">', $row);
$name = explode('<', $name[1]);
$name = $name[0];
print "found ".$crc." # ".$name." # ".$url."\n";
if (!$r_query[$crc])
{
@@ -125,6 +126,7 @@ if ($u_query)
}
else
{
print "found ".$crc." # ".$name." # ".$url."\n";
$found[] = array($url, $name, $crc);
$r_query[$crc] = true;
$new++;