Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ To add BIOs for the systems that require it, simply<br />
add the BIOs to a ZIP file and rename it to *console name*.zip.<br />
For example, the gba bios would be kept as /bios/gba.zip <br />

## Search function and folders

Now uses folders (nes, sms, snes, gen, gg, vb, gb, gbc, gba, n64, nds, psx) to organize roms into consoles.<br>
Folders in the 'img', roms' and 'saves' directories need to be named the same. eg. img/nes, roms/nes, saves/nes <br>
New search function for quickly finding a game in your library.<br>

<!----------------------------------------------------------------------------->

[Badge License]: https://img.shields.io/badge/license-GPL-blue
Expand Down
44 changes: 44 additions & 0 deletions getgames.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

// get query and dir parameters from url
$query = $_REQUEST["query"];
$dir = $_REQUEST["dir"];

// scan directory into files array
$files = array_diff(scandir("./roms/$dir"), array('..', '.'));

// if base dir scan all folders for games into array
if ($dir == ""){
foreach ($files as $folder){
$romfiles = array_diff(scandir("./roms/$folder"), array('..', '.'));
foreach ($romfiles as $file){
$games[$file] = $folder;
}
}
} else {
foreach ($files as $file){
$games[$file] = $dir;
}
}

// search games array for query
if ($query !== "") {
foreach($games as $name => $console) {
if (stristr($name, $query)) {
$matches[$name] = $console;
}
}
}

// Output matches with links
foreach ($matches as $name => $console){
$fileurl = 'play.php?game=/' . urlencode($console) . '/' . urlencode($name);
$output = "<a href='$fileurl' class='link'>";
if ($dir == ""){
$output = $output ."<b>".strtoupper($console)."</b><p>";
}
$output = $output . "<li>$name</li></a>";
echo($output);
}

?>
85 changes: 59 additions & 26 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,39 +1,72 @@
<!DOCTYPE html>
<html>

<head>
<title>EmulatorJS Library - Arcade</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>

<body onload="showGames('')">
<!-- Navbar -->
<nav>
<ul>
<li><a href="#">Arcade</a></li>
<li><a href="upload.php">Upload</a></li>
</ul>
</nav>
<?php include 'navbar.php'; ?>

<br />
<!-- Game Arcade -->
<!-- Game Arcade -->
<div class="arcadelist">
<?php
$files = scandir("./roms/");
foreach($files as $file) {
if(!in_array($file, array('.', '..'))) {
$file_url = 'play.php?game=' . urlencode($file);
if (file_exists("./img/$file.png")) {
echo("<a href='".$file_url."'><img class='linkimg' src='img/".$file.".png '/></a>");
} else {
echo("<a href='$file_url' class='link'><p>$file</p></a>");
}

}
}
?>

<script>
function showAll(){
var games = "<?php
$current_dir = $_SERVER['REQUEST_URI'];
$files = array_diff(scandir("./roms$current_dir"), array('..', '.'));
foreach ($files as $file) {
// if base dir show consoles, else show games
if ($current_dir=='/') {
if (file_exists("./img/$file.png")){
echo("<a href='$file'><img class='linkimg' src='img/$file.png'/></a>");
} else {
echo("<a href='$file' class='link'><li>$file</li></a>");
}
} else {
$file_url = 'play.php?game=' . urlencode($current_dir) . '/' . urlencode($file);
echo("<a href='$file_url' class='link'><li>$file</li></a>");
}

}
?>"
return games
}

function showGames(str){
if (str.length == 0){
document.getElementById("gameResults").innerHTML = showAll();
return;
} else {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200){
document.getElementById("gameResults").innerHTML = this.responseText;
}
};
var dir = "<?php echo(substr($_SERVER['REQUEST_URI'],1)); ?>";
xmlhttp.open("GET", "getgames.php?query=" + str + "&dir=" + dir, true);
xmlhttp.send();
}
}
</script>

<br>
<form action="">
<input type="text" id="name" name="name" onkeyup="showGames(this.value)">
</form>
<style media="screen">
ul.b {
display: grid;
grid-template-columns: auto auto auto;
grid-auto-flow: row;
list-style: none;
}
</style>

<ul id="gameResults" class="b"></ul>
</div>
</body>
</html>
</html>
14 changes: 14 additions & 0 deletions navbar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<nav>
<ul>
<li><a href=".." class='link'>home</a></li>
<li><a href='upload.php' class='link'>upload</a></li>
<?php
foreach (array_diff(scandir("./roms"), array('..','.')) as $folder) {
echo("<li><a href='$folder' class='link'>$folder</a></li>");

if(!is_dir("saves/$console")) mkdir("saves/$console");
if(!is_dir("img/$console")) mkdir("img/$console");
}
?>
</ul>
</nav>
17 changes: 10 additions & 7 deletions play.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<?php

$settings = parse_ini_file("./settings.ini");
Expand Down Expand Up @@ -55,9 +56,6 @@
?>
<title><?php echo($name); ?></title>
<style>
body {
background-color: #333;
}

nav {
background-color: #5f5f5f;
Expand Down Expand Up @@ -93,8 +91,13 @@

<nav>
<ul>
<li><a href="index.php">Arcade</a></li>
<li><a href="upload.php">Upload</a></li>
<li><a href=".." class='link'>home</a></li>
<li><a href='upload.php' class='link'>upload</a></li>
<?php
foreach (array_diff(scandir("./roms"), array('..','.')) as $folder) {
echo("<li><a href='$folder' class='link'>$folder</a></li>");
}
?>
<li style="width:10%;"></li>
<li><p>Playing: <?php echo($name); ?></p></li>
</ul>
Expand All @@ -119,7 +122,7 @@
EJS_core = '$console';
$bios
EJS_gameUrl = './roms/".$_GET['game']."';
EJS_pathtodata = 'https://cdn.emulatorjs.org/stable/data/';");
EJS_pathtodata = './data/';");
?>

EJS_onSaveState = function(data) {
Expand Down Expand Up @@ -162,6 +165,6 @@
xhr.send();
};
</script>
<script src='https://cdn.emulatorjs.org/stable/data/loader.js'></script>
<script src='./data/loader.js'></script>
</body>
</html>
26 changes: 17 additions & 9 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ body {

nav {
background-color: #5f5f5f;
border-radius: 5px;
border-radius: 1px;
}

nav ul {
Expand All @@ -20,7 +20,6 @@ nav ul {

nav a {
display: block;
padding: 1rem;
text-decoration: none;
color: #c5c5c5;
border-radius: 5px;
Expand All @@ -36,9 +35,10 @@ nav a:hover {
border-width: 5px;
border-style: solid;
border-color:#CCCCCC;
background-color: #111;
width: 160px;
height: 120px;
margin: 20px 20px;
margin: 10px 10px;
}

.linkimg:hover {
Expand All @@ -52,22 +52,30 @@ nav a:hover {

a.link {
display: inline-block;
padding: 10px 20px;
border-radius: 20px;
background-color: #747474;
padding: 1rem;
border-radius: 5px;
color: #d3d3d3;
text-decoration: none;
margin: 5px;
}

a.link:hover {
background-color: #7e7e7e;
}

.arcadelist {
border-radius: 10px;
border-radius: 5px;
background-color: #5c5c5c;
width: 75%;
height: 100%;
margin: auto auto;
}
}

.arcadelist a.link {
display: inline-block;
padding: 10px 10px;
border-radius: 5px;
background-color: #747474;
color: #d3d3d3;
text-decoration: none;
margin: 5px;
}
57 changes: 47 additions & 10 deletions upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@
<body>

<!-- Navbar -->
<nav>
<ul>
<li><a href="index.php">Arcade</a></li>
<li><a href="#">Upload</a></li>
</ul>
</nav>
<?php include 'navbar.php'; ?>

<br />
<!-- Game Arcade -->
Expand All @@ -30,7 +25,8 @@
// Nintendo
$snes = ["smc", "sfc", "fig", "swc", "bs", "st"];
$gba = ["gba"];
$gb = ["gb", "gbc", "dmg"];
$gb = ["gb", "dmg"];
$gbc = ["gbc"];
$nes = ["fds", "nes", "unif", "unf"];
$vb = ["vb", "vboy"];
$nds = ["nds"];
Expand All @@ -39,6 +35,8 @@
$sms = ["sms"];
$smd = ["smd", "md"];
$gg = ["gg"];
// Playstation
$psx = ["chd", "pbp"];

//Upload functionality
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
Expand All @@ -51,9 +49,48 @@
if(!is_dir("roms")) {
mkdir("roms");
}
//Move File
move_uploaded_file($tmp_name, "roms/$name");
print("<p>File successfully uploaded. Scraping failed due to no key error.</p>");

// find console to mkdir and move to correct folder
switch (true){
case in_array($ext, $snes):
$console = 'snes';
break;
case in_array($ext, $gba):
$console = 'gba';
break;
case in_array($ext, $gb):
$console = 'gb';
break;
case in_array($ext, $nes):
$console = 'nes';
break;
case in_array($ext, $vb):
$console = 'vb';
break;
case in_array($ext, $nds):
$console = 'nds';
break;
case in_array($ext, $n64):
$console = 'n64';
break;
case in_array($ext, $sms):
$console = 'sms';
break;
case in_array($ext, $smd):
$console = 'gen';
break;
case in_array($ext, $gg):
$console = 'gg';
break;
case in_array($ext, $psx):
$console = 'psx';
break;
}

// make dir and Move File
if(!is_dir("roms/$console")) mkdir("roms/$console");
move_uploaded_file($tmp_name, "roms/$console/$name");
print("<p><font style='text-transform:uppercase;'>[$console]</font> $name successfully uploaded.</p>");
}
}
}
Expand Down