multiple mod selection and config/db working

This commit is contained in:
color.diff=auto 2021-03-26 12:31:13 -06:00
parent d46cfc04e1
commit d5817446ff
12 changed files with 163 additions and 80 deletions

View File

@ -1 +0,0 @@
a:2:{s:4:"path";s:25:"/home/stoned/code/d2/txt/";s:7:"modname";s:7:"Ironman";}

View File

@ -1,13 +1,12 @@
<?php
define('FILTER_PROPERTIES_FILE', 'filterProperties.txt');
$config = unserialize(file_get_contents("d2im.conf"));
define('DB_FILE', $config['modname'].".db");
define('TXT_PATH', $config['path']);
session_start();
include "./_pdo.php";
define('FILTER_PROPERTIES_FILE', 'filterProperties.txt');
define('DB_FILE', $_SESSION['modname'].".db");
define('TXT_PATH', $_SESSION['path']);
require_once "./src/D2Functions.php";
require_once "./src/D2Database.php";
require_once './src/D2Files.php';

View File

@ -26,10 +26,10 @@ ini_set('log_errors', 1);
include "includes.php";
if (file_exists("d2im.conf") && (file_exists($config['modname'].".db"))){
if (file_exists("d2im.db") && (file_exists($_SESSION['modname'].".db"))){
if (is_dir($config['path'])) {
define('TXT_PATH', $config['path']);
if (is_dir($_SESSION['path'])) {
define('TXT_PATH', $_SESSION['path']);
} else {
header('Location: /src/D2Config.php');
}

View File

@ -1,18 +1,21 @@
<?php
include "includes.php";
$files = new D2Files();
if (file_exists("d2im.db")) {
$parser = new D2TxtParser();
$db = new D2Database();
unlink(DB_FILE);
foreach($files->files as $k => $v){
$data[$v] = $parser->parseFile($v);
}
foreach ($data as $k => $v) {
$db->createTables($k, $v);
$db->fillsTables($k, $v);
$files = new D2Files();
$parser = new D2TxtParser();
$db = new D2Database();
foreach ($files->files as $k => $v) {
$data[$v] = $parser->parseFile($v);
}
foreach ($data as $k => $v) {
$db->createTables($k, $v);
$db->fillsTables($k, $v);
}
}
// put in html redirect as backup, because
// for some odd reason windows gives

View File

@ -1,4 +1,6 @@
<?php
session_start();
/*
*
GPLv2 (C) <2021> <HashCasper>
@ -20,61 +22,88 @@
*/
require_once './D2Functions.php';
require_once './D2Database.php';
require_once '../_pdo.php';
if (!empty($_POST)) {
$modname = str_replace(' ', '', $_POST['modname']);
$_SESSION['modname'] = $modname;
// write the d2im.conf file and replace \ with \\
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$path = rtrim($_POST['path'], "\\");
$path = str_replace("\\", "\\\\", $path);
$path = str_replace("\\", "\\\\", $path);
$path .= '\\\\data\\\\global\\\\excel\\\\';
$conf['path'] = $path;
$conf['modname'] = $modname;
file_put_contents("../d2im.conf", serialize($path));
$conf[$modname]['path'] = $path;
$conf[$modname]['modname'] = $modname;
file_put_contents("../d2im.db", serialize($conf));
} else {
$conf['path'] = $_POST['path'].DIRECTORY_SEPARATOR;
$conf['modname'] = $modname;
file_put_contents("../d2im.conf", serialize($conf));
PDO_Connect("sqlite:../d2im.db");
$sql = "CREATE TABLE IF NOT EXISTS d2im (
modname VARCHAR(255),
path VARCHAR(255)
)";
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 {
$_SESSION['path'] = $path;
// Don't yell at me, security is the least of my considerations atm
// check modname in db
$sql = "SELECT * FROM d2im WHERE modname='$modname'";
$res = PDO_FetchAll($sql);
if (empty($res)) {
$sql = "INSERT INTO d2im(modname,path) VALUES(\"$modname\",\"$path\")";
PDO_Execute($sql);
}
header("Location: /processFiles.php");
}
}
header("Location: /processFiles.php");
}
?>
<!doctype html>
<html lang="en">
<?php
/* Require the <head> section */
require_once "head.php";
?>
<?php
/* Require the <head> section */
require_once "head.php";
?>
<body style="background: white;">
<div class="center container container-top">
<h1><img src="/img/Diablo2.png" style="float:left">D2 Item Maker, v3. By HashCasper</h1>
<a class="btn btn-outline-danger" style="color:red; font-size: 18px;float:right;" href="/">X</a>
<hr style="margin: 60px;">
<div class="offset-2 col-8">
<h2>Select Mod folder</h2>
<p style="font-family: lato">Example: D:\Diablo II\MODS\you-mod-name\</p>
<p style="font-family: lato">Input path to D2 Mod Directory.</p>
<h2>Select Mod folder</h2>
<p style="font-family: lato">Example: D:\Diablo II\MODS\you-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>
<label for="path">Enter Mod Name</label><br>
<input id="path" style="width: 220px;" 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 type="submit" value="Save" name="submit" class="btn-config">
</p>
</form>
</div>
<div style="margin-top: 20px;" class="ctrl-config">
<form enctype="multipart/form-data" style="font-family: Lato; font-size: 14pt;" action="" method="post">
<p>
<label for="path">Enter Mod Name</label><br>
<input id="path" style="width: 220px;" 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 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>

View File

@ -22,7 +22,7 @@
class D2Database {
public function __construct() {
PDO_Connect("sqlite:" . DB_FILE);
PDO_Connect("sqlite:" . DB_FILE);
}
public function createTables($file, $data) {

View File

@ -1,7 +1,8 @@
<div class="container">
<div class=" row" style="background: none;">
<div class="offset-9 col-3" style="background: none;">
<a style="font-weight: bold;" class="btn btn-info" href="/src/D2Config.php">Reconfigure Mod Path</a>
<div class="col" style="background: none;">
<a style="font-weight: bold;" class="btn btn-info" href="/src/D2Config.php">Setup New Mod</a>
<a style="font-weight: bold;" class="btn btn-warning" href="/switchMods.php">Switch Mods</a>
</div>
</div>
</div>

View File

@ -1,5 +1,4 @@
<?php
/*
D2UniqueMaker
GPLv2 (C) <2021> <HashCasper>
@ -27,23 +26,30 @@
require_once "head.php";
?>
<body>
<div class="container container-top">
<div>
<img src="img/Diablo2.png" style="float:right"><h2 syle="font-weight: 900">D2 Item Maker, v3. By HashCasper</h2><br><br>
<ul class="nav nav-tabs" id="Tabs" role="tablist">
<li class="nav-item" role="presentation">
<a class="nav-link active" id="Unique-tab" data-toggle="tab" href="#Unique" role="tab" aria-controls="Unique" aria-selected="true">UniqueItems.txt</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="Set-tab" data-toggle="tab" href="#Set" role="tab" aria-controls="Set" aria-selected="false">SetItems.txt</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="Gem-tab" data-toggle="tab" href="#Gem" role="tab" aria-controls="Set" aria-selected="false">Gems.txt</a>
</li>
</ul>
<body>
<div class="container container-top">
<div class="row">
<div class="col">
<img src="img/Diablo2.png" style="float:right"><h2 syle="font-weight: 900">D2 Item Maker, v3. By HashCasper</h2><br><br>
<ul class="nav nav-tabs" id="Tabs" role="tablist">
<li class="nav-item" role="presentation">
<a class="nav-link active" id="Unique-tab" data-toggle="tab" href="#Unique" role="tab" aria-controls="Unique" aria-selected="true">UniqueItems.txt</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="Set-tab" data-toggle="tab" href="#Set" role="tab" aria-controls="Set" aria-selected="false">SetItems.txt</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="Gem-tab" data-toggle="tab" href="#Gem" role="tab" aria-controls="Set" aria-selected="false">Gems.txt</a>
</li>
</ul>
</div>
</div>
<div class="tab-content" id="TabContent">
<div style="font-family: Lato !important; text-align:right; color: tomato">
<p style="font-family: Lato !important;">Active Mod: <?php echo $_SESSION['modname']?>
<br><?php echo $_SESSION['path']?></p>
</div>
<div class="tab-pane fade show active" id="Unique" role="tabpanel" aria-labelledby="Unique-tab">
<?php require_once 'D2UM.php'; ?>
</div>
@ -53,4 +59,4 @@
<div class="tab-pane fade" id="Gem" role="tabpanel" aria-labelledby="Gem-tab">
<?php require_once 'D2Gems.php'; ?>
</div>
</div>
</div>

View File

@ -1,4 +1,5 @@
<?php
session_start();
require_once 'header.php'; // loads head.php inside. Further loads D2UM/SM
require_once 'footer.php';

View File

@ -1,5 +1,5 @@
<div class="form-group row options" style="background: none;">
<div class="offset-10 col-3" style="background: none;">
<div class="offset-10 col-2" style="background: none;">
<button style="" name="submit" type="submit" class="btn btn-success">Save Item</button>
<button name="submit" type="reset" class="btn btn-danger">Clear</button>
</div>

49
switchMods.php Normal file
View File

@ -0,0 +1,49 @@
<?php
include "includes.php";
PDO_Connect("sqlite:" . "d2im.db");
$sql = "SELECT * FROM d2im";
$mods = PDO_FetchAll($sql);
if (!empty($_POST)) {
$sql = "SELECT * FROM d2im WHERE `modname`='{$_POST['modname']}'";
$mod = PDO_FetchRow($sql);
$_SESSION['modname'] = $mod[modname];
$_SESSION['path'] = $mod['path'];
header("Location: /");
}
?>
<!doctype html>
<html lang="en">
<?php
/* Require the <head> section */
require_once "src/head.php";
?>
<body style="background: white;">
<div class="center container container-top">
<h1><img src="/img/Diablo2.png" style="float:left">D2 Item Maker, v3. By HashCasper</h1>
<a class="btn btn-outline-danger" style="color:red; font-size: 18px;float:right;" href="/">X</a>
<hr style="margin: 60px;">
<div class="offset-2 col-8">
<h2>Select Mod</h2>
<div style="margin-top: 20px;" class="ctrl-config">
<form class="" enctype="multipart/form-data" style="font-family: Lato; font-size: 14pt;text-align:center;" action="" method="post">
<p>
<select id="mods" name="modname" required="required" class="custom-select"> <?php foreach ($mods as $mod) { ?>
<option value="<?php echo $mod['modname'] ?>"><?php echo $mod['modname'] ?>: <?php echo $mod['path'] ?></option>
<?php } ?>
</select>
</p>
<p>
<input type="submit" value="Select" name="submit" class="btn-config">
</p>
<p>
<a style="font-weight: bold;" class="btn btn-danger" href="/">Cancel</a>
</p>
</form>
</div>
</div>
</div>
</body>
</html>

View File

@ -1,4 +0,0 @@
.separator " "
.import txt/Armor.txt armor
select * from armors;
.output armor.db