From e277ca9a44ad5de35356b489b8373c64b8256697 Mon Sep 17 00:00:00 2001 From: Hash Borgir Date: Thu, 1 Jun 2023 23:31:55 -0600 Subject: [PATCH] path clean up, format code --- src/D2Config.php | 326 ++++++++++++++++++++++++----------------------- 1 file changed, 169 insertions(+), 157 deletions(-) diff --git a/src/D2Config.php b/src/D2Config.php index 7b0e7e2..8f38e50 100755 --- a/src/D2Config.php +++ b/src/D2Config.php @@ -1,43 +1,43 @@

-ERROR: INVALID PATH

'; - } else { - // set this mod to active mod in session - $_SESSION['path'] = $path; - $_SESSION['tbl'] = $tbl; + $modname = str_replace(' ', '', $_POST['modname']); + $_SESSION['modname'] = $modname; + $time = time(); + $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); // replace \\ (\' is invalid, so \\ escapes the first backslash) with / + + $modpath = $path; + $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 ( + modname VARCHAR(255), + modpath VARCHAR(255), + savepath VARCHAR(255), + path VARCHAR(255), + tbl VARCHAR(255), + lastused INT, + theme INT + )"; + PDO_Execute($sql); + + $sql = ''; + if (!is_dir($path)) { + echo ' +
+

+ + ERROR: INVALID PATH +

+
+ '; + } else { + // set this mod to active mod in session + $_SESSION['path'] = $path; + $_SESSION['tbl'] = $tbl; $_SESSION['savepath'] = $savePath; - $_SESSION['docpath'] = 'docs/'.$_SESSION['modname']; + $_SESSION['docpath'] = 'docs/' . $_SESSION['modname']; $_SESSION['modpath'] = $modpath; - // 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`,`modpath`,`savepath`,`path`,`tbl`,`lastused`) VALUES(?, ?, ?, ?, ?, ?)"; - PDO_Execute($sql, [$modname, $modpath, $savePath, $path, $tbl, $time]); - } - header("Location: /processFiles.php"); - } - } else { - - /* - ELSE BLOCK FOR LINUX TESTING - */ - - - PDO_Connect("sqlite:../D2Modder.db"); + // 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]); - $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 '

-ERROR: INVALID PATH

'; - } 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"); - } - } + if (empty($res)) { + $sql = "INSERT INTO D2Modder(`modname`,`modpath`,`savepath`,`path`,`tbl`,`lastused`) VALUES(?, ?, ?, ?, ?, ?)"; + PDO_Execute($sql, [$modname, $modpath, $savePath, $path, $tbl, $time]); + } + header("Location: /processFiles.php"); + } + } } ?> - section */ -$css = ''; -require_once "head.php"; -?> - -
+ section */ + $css = ''; + require_once "head.php"; + ?> + + + +
+ +

+ X +
+
+

Select Mod folder

+

Example: D:\Diablo II\MODS\your-mod-name\

+

Input path to D2 Mod Directory.

+
+
+

+
+ +

+

+
+ + +

+
+
+
+
+

After saving path, app will convert txt files to SQL database.

+

This may take a few minutes depending on the size of your txt files.
Please be patient. Once done, app will load.
Each time you set a new mod path, txt files will be processed.
Every mod will be saved to ModName.db.

+
+
+ -
- \ No newline at end of file