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 '../_pdo.php';
include "../config.php";
// the form posts to it self, and then forwards to processFiles
if (!empty($_POST)) {
$modname = str_replace(' ', '', $_POST['modname']);
@ -54,20 +56,18 @@ if (!empty($_POST)) {
$savePath = '';
// write the D2Modder.db file and replace \ with \\
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$path = rtrim($_POST['path'], "\\");
$path = str_replace("\\", "\\\\", $path);
$path = rtrim($_POST['path'], '\\');
$path = str_replace('\\', '/', $path); // replace \\ (\' is invalid, so \\ escapes the first backslash) with /
$modpath = $path;
$savePath = $path . '\\\\save\\\\';
$tbl = $path.'\\\\data\\\\local\\\\lng\\\\eng\\\\';
$path .= '\\\\data\\\\global\\\\excel\\\\';
$savePath = $path . '/save/';
$tbl = $path . '/data/local/lng/eng/';
$path .= '/data/global/excel/';
PDO_Connect("sqlite:../D2Modder.db");
$sql = "CREATE TABLE IF NOT EXISTS D2Modder (
$sql = "
CREATE TABLE IF NOT EXISTS D2Modder (
modname VARCHAR(255),
modpath VARCHAR(255),
savepath VARCHAR(255),
@ -79,10 +79,15 @@ if (!empty($_POST)) {
PDO_Execute($sql);
$sql = '';
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>';
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;
@ -101,46 +106,6 @@ ERROR: INVALID PATH</h1></center>';
}
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 = '';
require_once "head.php";
?>
<body style="background: white;">
<div class="center container container-top">
<style>
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>
<a class="btn btn-outline-danger" style="color:red; font-size: 18px;float:right;" href="/">X</a>
<hr style="margin: 60px;">
h1 {
display: inline;
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">
<h2>Select Mod folder</h2>
<p style="font-family: lato">Example: D:\Diablo II\MODS\your-mod-name\</p>
<p style="font-family: lato">Input path to D2 Mod Directory.</p>
<div style="margin-top: 20px;" class="ctrl-config">
<form enctype="multipart/form-data" style="font-family: Lato; font-size: 14pt;" action="" method="post">
<p>Example: D:\Diablo II\MODS\your-mod-name\</p>
<p>Input path to D2 Mod Directory.</p>
<div class="ctrl-config">
<form enctype="multipart/form-data" action="" method="post">
<p>
<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>
<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">
</p>
</form>
</div>
</div>
<div id="loading" class="offset-2 col-8 alert alert-primary">
<p style="font-family: Lato;">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.
<br> Every mod will be saved to ModName.db.
</p>
<div id="loading" class="offset-2 col-8 alert">
<p>After saving path, app will convert txt files to SQL database.</p>
<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>
</div>
</div>
</body>
</html>