sqlite3.exe import cubemain working

This commit is contained in:
Hash Borgir 2021-03-27 07:06:10 -06:00
parent d64ae02201
commit ce01b0e602
4 changed files with 20 additions and 15 deletions

BIN
bin/sqlite3.exe Normal file

Binary file not shown.

View File

@ -5,7 +5,16 @@
session_start(); session_start();
include "./_pdo.php"; include "./_pdo.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 // check to see if config db exists or if for some reason it doesn't exist
if (file_exists("d2im.db")) { if (file_exists("d2im.db")) {
if (file_exists($_SESSION['modname'] . ".db")) { if (file_exists($_SESSION['modname'] . ".db")) {
@ -27,6 +36,8 @@ if (file_exists("d2im.db")) {
$parser = new D2TxtParser(); $parser = new D2TxtParser();
$db = new D2Database(); $db = new D2Database();
$data = null;
// Parse all files // Parse all files
foreach ($files->files as $k => $v) { foreach ($files->files as $k => $v) {
$data[$v] = $parser->parseFile($v); $data[$v] = $parser->parseFile($v);
@ -37,6 +48,8 @@ if (file_exists("d2im.db")) {
$db->fillsTables($k, $v); $db->fillsTables($k, $v);
} }
unset($data);
processCubeMain('cubemain.txt');
// put in html redirect as backup, because // put in html redirect as backup, because
// for some odd reason windows gives // for some odd reason windows gives
// an error on header() but linux does not. // an error on header() but linux does not.

View File

@ -1,5 +1,4 @@
<?php <?php
session_start();
/* /*
GPLv2 (C) <2021> <HashCasper> GPLv2 (C) <2021> <HashCasper>
@ -25,11 +24,12 @@ class D2Files {
public function __construct() { public function __construct() {
$filesToIgnore = [ $filesToIgnore = [
"AiParms.txt" "aiparms.txt",
"cubemain.txt"
]; ];
$glob = glob($_SESSION['path'].'*.txt'); $glob = glob($_SESSION['path'].'*.txt');
foreach ($glob as $g){ foreach ($glob as $g){
$files[] = basename($g); $files[] = strtolower(basename($g));
} }
$this->files = array_diff($files, $filesToIgnore); $this->files = array_diff($files, $filesToIgnore);
return $this->files; return $this->files;

View File

@ -32,9 +32,6 @@ class D2TxtParser {
} }
public function parseFile($file) { public function parseFile($file) {
if ($file == "CubeMain.txt") {
$this->processCubeMain($file);
}
return $this->parseData($file); return $this->parseData($file);
} }
@ -52,19 +49,14 @@ class D2TxtParser {
$file = $this->path . $file; $file = $this->path . $file;
$rows = array_map(function ($v) { $rows = array_map(function ($v) {
return str_getcsv($v, "\t"); return str_getcsv($v, "\t");
} }, file($file));
, file($file));
$header = array_shift($rows); $header = array_shift($rows);
$data = null; $data = null;
foreach ($rows as $row) { foreach ($rows as $row) {
$data[] = @array_combine($header, $row); $data[] = @array_combine($header, $row);
} }
unset($rows);
return $data; return $data;
} }
public function processCubeMain($file){
$path = dirname(getcwd()).DIRECTORY_SEPARATOR."bin".DIRECTORY_SEPARATOR;
exec($path."sqlite3.exe ".$path.DB_FILE." '.separator \"t\"' '.import ".TXT_PATH."$file cubemain'");
}
} }
?> ?>