DB Dump Working

This commit is contained in:
color.diff=auto 2021-03-24 04:26:51 -06:00
parent 50252def84
commit 7a6d2ace00
12 changed files with 17280 additions and 35 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
db

89
_pdo.php Normal file
View File

@ -0,0 +1,89 @@
<?php
// PDO helper functions.
// Copyright (c) 2012-2014 The PHP Desktop authors. All rights reserved.
// License: New BSD License.
// Website: http://code.google.com/p/phpdesktop/
function PDO_Connect($dsn, $user="", $password="")
{
global $PDO;
$PDO = new PDO($dsn, $user, $password);
$PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
}
function PDO_FetchOne($query, $params=null)
{
global $PDO;
if (isset($params)) {
$stmt = $PDO->prepare($query);
$stmt->execute($params);
} else {
$stmt = $PDO->query($query);
}
$row = $stmt->fetch(PDO::FETCH_NUM);
if ($row) {
return $row[0];
} else {
return false;
}
}
function PDO_FetchRow($query, $params=null)
{
global $PDO;
if (isset($params)) {
$stmt = $PDO->prepare($query);
$stmt->execute($params);
} else {
$stmt = $PDO->query($query);
}
return $stmt->fetch(PDO::FETCH_ASSOC);
}
function PDO_FetchAll($query, $params=null)
{
global $PDO;
if (isset($params)) {
$stmt = $PDO->prepare($query);
$stmt->execute($params);
} else {
$stmt = $PDO->query($query);
}
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
function PDO_FetchAssoc($query, $params=null)
{
global $PDO;
if (isset($params)) {
$stmt = $PDO->prepare($query);
$stmt->execute($params);
} else {
$stmt = $PDO->query($query);
}
$rows = $stmt->fetchAll(PDO::FETCH_NUM);
$assoc = array();
foreach ($rows as $row) {
$assoc[$row[0]] = $row[1];
}
return $assoc;
}
function PDO_Execute($query, $params=null)
{
global $PDO;
if (isset($params)) {
$stmt = $PDO->prepare($query);
$stmt->execute($params);
return $stmt;
} else {
return $PDO->query($query);
}
}
function PDO_LastInsertId()
{
global $PDO;
return $PDO->lastInsertId();
}
function PDO_ErrorInfo()
{
global $PDO;
return $PDO->errorInfo();
}
?>

View File

@ -20,10 +20,15 @@
along with D2UM. If not, see <http://www.gnu.org/licenses/>.
*/
ini_set('display_errors', 1);
ini_set('display_errors', 0);
error_reporting(0);
ini_set('log_errors', 1);
define('FILTER_PROPERTIES_FILE', 'filterProperties.txt');
define('DB_FILE', 'db');
include "./_pdo.php";
$filename = 'd2im.conf';
@ -40,6 +45,9 @@ if (file_exists($filename)) {
// Misc functions
require_once "./src/D2Functions.php";
// D2 Database
require_once "./src/D2Database.php";
// D2 Files Loader
require_once './src/D2Files.php';
@ -52,15 +60,19 @@ if (file_exists($filename)) {
$parser = new D2TxtParser();
$armor = $parser->parseFile($files->getFile('Armor'));
$weapon = $parser->parseFile($files->getFile('Weapons'));
$gems = $parser->parseFile($files->getFile('Gems'));
$itypes = $parser->parseFile($files->getFile('ItemTypes'));
$misc = $parser->parseFile($files->getFile('Misc'));
$prop = $parser->parseFile($files->getFile('Properties'));
$uni = $parser->parseFile($files->getFile('UniqueItems'));
$sets = $parser->parseFile($files->getFile('Sets'));
$setitems = $parser->parseFile($files->getFile('SetItems'));
$sets = $parser->parseFile($files->getFile('Sets'));
$uni = $parser->parseFile($files->getFile('UniqueItems'));
$weapon = $parser->parseFile($files->getFile('Weapons'));
$u = $files->getFile("UniqueItems");
$s = $files->getFile("SetItems");
// If there's data, process it and save
if (!empty($_POST)) {
require_once './src/D2SaveFile.php';
@ -80,19 +92,15 @@ if (file_exists($filename)) {
}
// if ladder or carry1 is 0, set empty field.
if (!$post['ladder']){
$post['ladder'] = '';
}
if (!$post['carry1']){
$post['carry1'] = '';
}
if ($_POST['formtype'] == "uniqueitems") {
$saver->save($u);
// if ladder or carry1 is 0, set empty field.
if (!$post['ladder']) {
$post['ladder'] = '';
}
if (!$post['carry1']) {
$post['carry1'] = '';
}
$saver->save($u, $post);
$saver->saveTblEnries("UniqueItems.tbl.txt");
}
if ($_POST['formtype'] == "setitems") {
@ -100,7 +108,7 @@ if (file_exists($filename)) {
$saver->save($s);
$saver->save($s, $post);
$saver->saveTblEnries("SetItems.tbl.txt");
}
}

74
src/D2Database.php Normal file
View File

@ -0,0 +1,74 @@
<?php
/*
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/>.
*/
class D2Database {
public function __construct() {
PDO_Connect("sqlite:" . DB_FILE);
}
public function createTables($file, $data) {
$tableName = basename($file);
$tableName = strtolower(substr($tableName, 0, -4));
$sql = "CREATE TABLE IF NOT EXISTS `$tableName` (";
foreach ($data[0] as $k => $v) {
if (is_numeric($v)) {
$dataType = "INT";
} else {
$dataType = "VARCHAR(255)";
}
$sql .= "`$k` $dataType NOT NULL,";
}
$sql = rtrim($sql, ",");
$sql .= ")";
$res = PDO_Execute($sql);
}
public function fillsTables($file, $data) {
$tableName = basename($file);
$tableName = strtolower(substr($tableName, 0, -4));
foreach ($data as $d) {
$sql = "INSERT INTO `$tableName` (";
if (!empty($d)) {
foreach ($d as $k => $v) {
$sql .= "`$k`" . ",";
}
}
$sql = rtrim($sql, ",");
$sql .= ") ";
$sql .= "VALUES (";
if (!empty($d)) {
foreach ($d as $k => $v) {
$sql .= '"' . $v . '"' . ",";
}
}
$sql = rtrim($sql, ",");
$sql .= ");";
var_dump($sql);
PDO_Execute($sql);
}
}
}

View File

@ -1,6 +1,6 @@
<?php
function dd($var) {
function ddump($var) {
echo "<pre>";
var_dump($var);
echo "</pre>";

41
src/D2Gems.php Normal file
View File

@ -0,0 +1,41 @@
<?php
/*
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/>.
*/
?>
<h2>Gem Maker</h2>
<div class="container">
<div class="form-group row">
<div class="col-2" style="background: #ccd;">
<select class="m-select custom-select" name="code[]" id="" required="required">
<option value="">Misc</option>
<?php
foreach ($misc as $a)
if ($a['spawnable']) {
echo '<option value="' . $a['code'] . '">' . $a['name'] . '</option>';
} else {
echo '<option disabled value="' . $a['code'] . '">' . $a['name'] . '</option>';
}
?>
</select>
</div>
</div>
</div>

View File

@ -26,11 +26,8 @@ class D2SaveFile {
public function save($file, $data) {
$fp = fopen($this->path.DIRECTORY_SEPARATOR.$file, 'a+');
$this->saveBackup($file);
fputcsv($fp, $data, "\t");
}

View File

@ -26,10 +26,10 @@ class D2TxtParser {
public $path = TXT_PATH;
// Files specific to Unique Items
public $db;
public function __construct() {
$this->db = new D2Database();
}
public function parseFile($file) {
@ -59,8 +59,11 @@ class D2TxtParser {
foreach ($rows as $row) {
$data[] = @array_combine($header, $row);
}
$this->db->createTables($file, $data);
$this->db->fillsTables($file, $data);
return $data;
}
}
?>

View File

@ -38,6 +38,9 @@
<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 class="tab-content" id="TabContent">
@ -47,4 +50,7 @@
<div class="tab-pane fade" id="Set" role="tabpanel" aria-labelledby="Set-tab">
<?php require_once 'D2SM.php'; ?>
</div>
<div class="tab-pane fade" id="Gem" role="tabpanel" aria-labelledby="Gem-tab">
<?php require_once 'D2Gems.php'; ?>
</div>
</div>

View File

@ -421,3 +421,10 @@ Set24.4 Set24 9ts Harpoon 7 30 51 5 5000 2 dmg% 190 240 stack 75 75 rep
Set25.1 Set25 rin Ring 1 45 45 5 5000 2 hp 35 50 mana 25 25 mag% 200 200 regen -20 -20 regen -15 -15 extra-fire 100 100 0
Set25.2 Set25 rin Ring 1 45 45 5 5000 2 hp 35 50 mana 25 25 mag% 200 200 regen -20 -20 regen -15 -15 extra-ltng 100 100 0
Set25.3 Set25 amu Amulet 1 45 45 5 5000 2 hp 50 75 mana 40 40 mag% 200 200 regen -20 -20 regen -15 -15 extra-cold 100 100 0
"Set 1item" "set 1" ghm "Great Helm" 1 2 3 inv flippy 12 213 2 0 on setitems
"Set 1item" "set 1" ghm "Great Helm" 1 2 3 inv flippy 12 213 2 0 on setitems
"Set 1item" "set 1" ghm "Great Helm" 1 2 3 inv flippy 12 213 2 0 on setitems
"Set 1item" "set 1" ghm "Great Helm" 1 2 3 inv flippy 12 213 2 0 on setitems
"Set 1item" "set 1" ghm "Great Helm" 1 2 3 inv flippy 12 213 2 0 on setitems
"Set 1item" "set 1" ghm "Great Helm" 1 2 3 inv flippy 12 213 2 0 on setitems
"Set 1item" "set 1" ghm "Great Helm" 1 2 3 inv flippy 12 213 2 0 on setitems

17019
vendor/rb-sqlite.php vendored Normal file

File diff suppressed because it is too large Load Diff