Bugfixing. Adding sanity checks

This commit is contained in:
color.diff=auto
2021-03-27 02:53:26 -06:00
parent b85fbf02b3
commit 9bc941faea
8 changed files with 187 additions and 68 deletions

View File

@@ -1,26 +1,49 @@
<?php
include "includes.php";
// Second step after D2Config. If we made it here, d2im.db should
// have been created. Config writes active mod to session.
session_start();
include "./_pdo.php";
// check to see if config db exists or if for some reason it doesn't exist
if (file_exists("d2im.db")) {
if(file_exists(DB_FILE)) unlink(DB_FILE);
if (file_exists($_SESSION['modname'] . ".db")) {
unlink($_SESSION['modname'] . ".db"); // delete old mod db file
}
// Set CONSTANTS (if d2im.db exists, D2Config set the session mod correctly)
define('FILTER_PROPERTIES_FILE', 'filterProperties.txt');
define('DB_FILE', $_SESSION['modname'] . ".db");
define('TXT_PATH', $_SESSION['path']);
// require D2IM src
require_once "./src/D2Functions.php";
require_once "./src/D2Database.php";
require_once './src/D2Files.php';
require_once './src/D2TxtParser.php';
// Create D2IM objects
$files = new D2Files();
$parser = new D2TxtParser();
$db = new D2Database();
// Parse all files
foreach ($files->files as $k => $v) {
$data[$v] = $parser->parseFile($v);
}
// Write all parse data to mod db
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
// an error on header() but linux does not.
} else {
// if config db does not exist, go to configure page
header("Location: /src/D2Config.php");
}
die();
// put in html redirect as backup, because
// for some odd reason windows gives
// an error on header() but linux does not.
?>
<!doctype html>
<html lang="en">