path clean up, format code

This commit is contained in:
Hash Borgir 2023-06-01 23:31:55 -06:00
parent c63393c225
commit e277ca9a44

View File

@ -46,6 +46,8 @@ require_once './D2Functions.php';
require_once './D2Database.php'; require_once './D2Database.php';
require_once '../_pdo.php'; require_once '../_pdo.php';
include "../config.php"; include "../config.php";
// the form posts to it self, and then forwards to processFiles
if (!empty($_POST)) { if (!empty($_POST)) {
$modname = str_replace(' ', '', $_POST['modname']); $modname = str_replace(' ', '', $_POST['modname']);
@ -54,20 +56,18 @@ if (!empty($_POST)) {
$savePath = ''; $savePath = '';
// write the D2Modder.db file and replace \ with \\ // write the D2Modder.db file and replace \ with \\
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$path = rtrim($_POST['path'], "\\"); $path = rtrim($_POST['path'], '\\');
$path = str_replace("\\", "\\\\", $path); $path = str_replace('\\', '/', $path); // replace \\ (\' is invalid, so \\ escapes the first backslash) with /
$modpath = $path; $modpath = $path;
$savePath = $path . '\\\\save\\\\'; $savePath = $path . '/save/';
$tbl = $path.'\\\\data\\\\local\\\\lng\\\\eng\\\\'; $tbl = $path . '/data/local/lng/eng/';
$path .= '/data/global/excel/';
$path .= '\\\\data\\\\global\\\\excel\\\\';
PDO_Connect("sqlite:../D2Modder.db"); PDO_Connect("sqlite:../D2Modder.db");
$sql = "CREATE TABLE IF NOT EXISTS D2Modder (
$sql = "
CREATE TABLE IF NOT EXISTS D2Modder (
modname VARCHAR(255), modname VARCHAR(255),
modpath VARCHAR(255), modpath VARCHAR(255),
savepath VARCHAR(255), savepath VARCHAR(255),
@ -79,10 +79,15 @@ if (!empty($_POST)) {
PDO_Execute($sql); PDO_Execute($sql);
$sql = ''; $sql = '';
if (!is_dir($path)) { if (!is_dir($path)) {
echo '<center><h1 style="font-family:Lato; color:#880000;"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> echo '
ERROR: INVALID PATH</h1></center>'; <center>
<h1 style="font-family:Lato; color:#880000;">
<i class="fa fa-exclamation-triangle" aria-hidden="true"></i>
ERROR: INVALID PATH
</h1>
</center>
';
} else { } else {
// set this mod to active mod in session // set this mod to active mod in session
$_SESSION['path'] = $path; $_SESSION['path'] = $path;
@ -101,46 +106,6 @@ ERROR: INVALID PATH</h1></center>';
} }
header("Location: /processFiles.php"); header("Location: /processFiles.php");
} }
} else {
/*
ELSE BLOCK FOR LINUX TESTING
*/
PDO_Connect("sqlite:../D2Modder.db");
$sql = "CREATE TABLE IF NOT EXISTS D2Modder (
modname VARCHAR(255),
path VARCHAR(255),
tbl VARCHAR(255),
lastused INT,
theme INT
)";
PDO_Execute($sql);
$sql = '';
$path = $_POST['path'];
$path = rtrim($_POST['path'], "/");
$path = $path . DIRECTORY_SEPARATOR;
if (!is_dir($path)) {
echo '<center><h1 style="font-family:Lato; color:#880000;"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i>
ERROR: INVALID PATH</h1></center>';
} else {
// set this mod to active mod in session
$_SESSION['path'] = $path;
$_SESSION['tbl'] = $path;
// Don't yell at me, security is the least of my considerations atm
// check modname in db
$sql = "SELECT * FROM D2Modder WHERE modname=?";
$res = PDO_FetchAll($sql, [$modname]);
if (empty($res)) {
$sql = "INSERT INTO D2Modder (`modname`,`path`,`tbl`,`lastused`) VALUES(?, ?, ?, ?)";
PDO_Execute($sql, [$modname, $path, $tbl, $time]);
}
header("Location: /processFiles.php");
}
} }
} }
?> ?>
@ -151,38 +116,85 @@ ERROR: INVALID PATH</h1></center>';
$css = ''; $css = '';
require_once "head.php"; require_once "head.php";
?> ?>
<body style="background: white;"> <style>
<div class="center container container-top"> body {
background: white;
}
<img src="/img/Diablo2.png" style="float:left"><h1 syle="display:inline; font-weight: 900"><?php echo $title . " " . $version; ?><span style="font-family: Lato !important; font-size: 14px;"> <?php echo " By: " . $author ?></span></h1> h1 {
<a class="btn btn-outline-danger" style="color:red; font-size: 18px;float:right;" href="/">X</a> display: inline;
<hr style="margin: 60px;"> font-weight: 900;
}
.btn-outline-danger {
color: red;
font-size: 18px;
float: right;
}
hr {
margin: 60px;
}
p {
font-family: Lato;
}
.ctrl-config {
margin-top: 20px;
}
form {
font-family: Lato;
font-size: 14pt;
}
input#path {
width: 220px;
}
input#path[name="path"] {
width: 420px;
}
.btn-config {
/* Add any necessary styles */
}
#loading p {
font-family: Lato;
}
</style>
<body>
<div class="center container container-top">
<img src="/img/Diablo2.png" style="float:left">
<h1><?php echo $title . " " . $version; ?><span style="font-family: Lato !important; font-size: 14px;"> <?php echo " By: " . $author ?></span></h1>
<a class="btn btn-outline-danger" href="/">X</a>
<hr>
<div class="offset-2 col-8"> <div class="offset-2 col-8">
<h2>Select Mod folder</h2> <h2>Select Mod folder</h2>
<p style="font-family: lato">Example: D:\Diablo II\MODS\your-mod-name\</p> <p>Example: D:\Diablo II\MODS\your-mod-name\</p>
<p style="font-family: lato">Input path to D2 Mod Directory.</p> <p>Input path to D2 Mod Directory.</p>
<div class="ctrl-config">
<div style="margin-top: 20px;" class="ctrl-config"> <form enctype="multipart/form-data" action="" method="post">
<form enctype="multipart/form-data" style="font-family: Lato; font-size: 14pt;" action="" method="post">
<p> <p>
<label for="path">Enter Mod Name</label><br> <label for="path">Enter Mod Name</label><br>
<input id="path" style="width: 220px;" required="required" name="modname" type="text"> <input id="path" required="required" name="modname" type="text">
</p> </p>
<p> <p>
<label for="path">Enter PATH </label><br> <label for="path">Enter PATH </label><br>
<input id="path" style="width: 420px;" required="required" name="path" type="text"> <input id="path" required="required" name="path" type="text">
<input type="submit" value="Save" name="submit" class="btn-config"> <input type="submit" value="Save" name="submit" class="btn-config">
</p> </p>
</form> </form>
</div> </div>
</div> </div>
<div id="loading" class="offset-2 col-8 alert alert-primary"> <div id="loading" class="offset-2 col-8 alert">
<p style="font-family: Lato;">After saving path, app will convert txt files to SQL database.</p> <p>After saving path, app will convert txt files to SQL database.</p>
<p style="font-family: Lato;">This may take a few minutes depending on the size of your txt files. <br>Please be patient. Once done, app will load. <br>Each time you set a new mod path, txt files will be processed. <p>This may take a few minutes depending on the size of your txt files.<br>Please be patient. Once done, app will load.<br>Each time you set a new mod path, txt files will be processed.<br>Every mod will be saved to ModName.db.</p>
<br> Every mod will be saved to ModName.db.
</p>
</div> </div>
</div> </div>
</body> </body>
</html> </html>