Config DB renamed/refactored to D2Modder.db

This commit is contained in:
color.diff=auto 2021-03-28 03:22:23 -06:00
parent 867a0409e1
commit a174bc4992
5 changed files with 72 additions and 44 deletions

47
config.php Normal file
View File

@ -0,0 +1,47 @@
<?php
/*
Copyright (C) 2021 Hash Borgir
This file is part of D2Modder
Redistribution and use in source and binary forms, with
or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* This software must not be used for commercial purposes
* without my consent. Any sales or commercial use are prohibited
* without my express knowledge and consent.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY!
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
$title = '<span style="color: #880000">D2</span>Modder';
$author = "HashCasper";
$version = '<span style="color: #aaa">4.0';
define('APP_DB', "D2Modder.db");

View File

@ -48,8 +48,10 @@ ini_set('log_errors', 1);
include "./_pdo.php";
include "./config.php";
if (!isset($_SESSION['modname'])
|| (!file_exists("d2im.db"))
|| (!file_exists(APP_DB))
|| (!file_exists($_SESSION['modname'] . ".db")))
{
// first load, no active mod, go to switchmods to select mod

View File

@ -41,38 +41,37 @@
*/
// Second step after D2Config. If we made it here, d2im.db should
// Second step after D2Config. If we made it here, D2Modder.db should
// have been created. Config writes active mod to session.
session_start();
include "./_pdo.php";
include "./config.php";
function processCubeMain(){
$bin = getcwd().DIRECTORY_SEPARATOR."bin".DIRECTORY_SEPARATOR."sqlite3.exe ";
$dbfile = getcwd().DIRECTORY_SEPARATOR.DB_FILE;
$cubemain = TXT_PATH."cubemain.txt";
// D:\Documents\D2IM\www\bin\sqlite3.exe D:\Documents\D2IM\www\ZyEl4.5.db ".separator \"\t"\" ".import \"D:\\Diablo II\\MODS\\D2SE_Zy-El mod v4.5 HiRes\\data\\global\\excel\\cubemain.txt\" cubemain"
exec("$bin $dbfile \".separator \\\"\\t\\\"\" \".import \\\"$cubemain\\\" cubemain\"");
}
// check to see if config db exists or if for some reason it doesn't exist
if (file_exists("d2im.db")) {
if (file_exists(APP_DB)) {
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)
// Set CONSTANTS (if D2Modder.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 src
require_once "./src/D2Functions.php";
require_once "./src/D2Database.php";
require_once './src/D2Files.php';
require_once './src/D2TxtParser.php';
// Create D2IM objects
// Create objects
$files = new D2Files();
$parser = new D2TxtParser();
$db = new D2Database();

View File

@ -42,43 +42,23 @@
*/
session_start();
/*
*
GPLv2 (C) <2021> <HashCasper>
This file is part of D2IM.
D2IM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
D2IM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with D2IM. If not, see <http://www.gnu.org/licenses/>.
*/
require_once './D2Functions.php';
require_once './D2Database.php';
require_once '../_pdo.php';
include "../config.php";
if (!empty($_POST)) {
$modname = str_replace(' ', '', $_POST['modname']);
$_SESSION['modname'] = $modname;
// write the d2im.conf file and replace \ with \\
// 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 .= '\\\\data\\\\global\\\\excel\\\\';
PDO_Connect("sqlite:../d2im.db");
$sql = "CREATE TABLE IF NOT EXISTS d2im (
PDO_Connect("sqlite:../D2Modder.db");
$sql = "CREATE TABLE IF NOT EXISTS D2Modder (
modname VARCHAR(255),
path VARCHAR(255)
)";
@ -94,18 +74,18 @@ ERROR: INVALID PATH</h1></center>';
$_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'";
$sql = "SELECT * FROM D2Modder WHERE modname='$modname'";
$res = PDO_FetchAll($sql);
if (empty($res)) {
$sql = "INSERT INTO d2im(modname,path) VALUES(\"$modname\",\"$path\")";
$sql = "INSERT INTO D2Modder(modname,path) VALUES(\"$modname\",\"$path\")";
PDO_Execute($sql);
}
header("Location: /processFiles.php");
}
} else {
PDO_Connect("sqlite:../d2im.db");
PDO_Connect("sqlite:../D2Modder.db");
$sql = "CREATE TABLE IF NOT EXISTS d2im (
$sql = "CREATE TABLE IF NOT EXISTS D2Modder (
modname VARCHAR(255),
path VARCHAR(255)
)";
@ -124,10 +104,10 @@ ERROR: INVALID PATH</h1></center>';
$_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'";
$sql = "SELECT * FROM D2Modder WHERE modname='$modname'";
$res = PDO_FetchAll($sql);
if (empty($res)) {
$sql = "INSERT INTO d2im(modname,path) VALUES(\"$modname\",\"$path\")";
$sql = "INSERT INTO D2Modder(modname,path) VALUES(\"$modname\",\"$path\")";
PDO_Execute($sql);
}
header("Location: /processFiles.php");

View File

@ -42,20 +42,20 @@
*/
session_start();
include "./_pdo.php";
include "./config.php";
// if config db exists, connect to it and grab list of mods
if (file_exists("d2im.db")) {
PDO_Connect("sqlite:d2im.db");
if (file_exists(APP_DB)) {
PDO_Connect("sqlite:".APP_DB);
$sql = "SELECT * FROM d2im";
$sql = "SELECT * FROM D2Modder";
$mods = PDO_FetchAll($sql);
if (!empty($_POST)) {
$sql = "SELECT * FROM d2im WHERE `modname`='{$_POST['modname']}'";
$sql = "SELECT * FROM D2Modder WHERE `modname`='{$_POST['modname']}'";
$mod = PDO_FetchRow($sql);
if (isset($_POST['deletemod'])) {
$sql = "DELETE FROM d2im WHERE modname='{$_POST['modname']}'";
$sql = "DELETE FROM D2Modder WHERE modname='{$_POST['modname']}'";
PDO_Execute($sql);
unlink($_POST['modname'] . ".db");
header("Refresh:0");