2021-03-23 08:13:54 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
GPLv2 (C) <2021> <HashCasper>
|
|
|
|
|
2021-03-23 11:55:47 +00:00
|
|
|
This file is part of D2IM.
|
2021-03-23 08:13:54 +00:00
|
|
|
|
2021-03-23 11:55:47 +00:00
|
|
|
D2IM is free software: you can redistribute it and/or modify
|
2021-03-23 08:13:54 +00:00
|
|
|
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.
|
|
|
|
|
2021-03-23 11:55:47 +00:00
|
|
|
D2IM is distributed in the hope that it will be useful,
|
2021-03-23 08:13:54 +00:00
|
|
|
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
|
2021-03-23 11:55:47 +00:00
|
|
|
along with D2IM. If not, see <http://www.gnu.org/licenses/>.
|
2021-03-23 08:13:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
This is a generic D2 Txt Parser
|
|
|
|
*/
|
|
|
|
|
|
|
|
class D2TxtParser {
|
|
|
|
|
|
|
|
public $path = TXT_PATH;
|
2021-03-23 18:35:28 +00:00
|
|
|
|
2021-03-24 10:26:51 +00:00
|
|
|
public $db;
|
|
|
|
|
2021-03-23 08:13:54 +00:00
|
|
|
public function __construct() {
|
|
|
|
}
|
2021-03-23 18:35:28 +00:00
|
|
|
|
|
|
|
public function parseFile($file) {
|
2021-03-27 09:40:43 +00:00
|
|
|
if ($file == "CubeMain.txt") {
|
|
|
|
$this->processCubeMain($file);
|
|
|
|
}
|
2021-03-23 18:35:28 +00:00
|
|
|
return $this->parseData($file);
|
|
|
|
}
|
|
|
|
|
|
|
|
function filterProps($file) {
|
|
|
|
$data = $this->parseData($file);
|
|
|
|
$propsToFilter = file(FILTER_PROPERTIES_FILE, FILE_IGNORE_NEW_LINES);
|
|
|
|
foreach ($data as $d) {
|
|
|
|
$allProps[] = $d['code'];
|
|
|
|
}
|
|
|
|
$filteredProps = array_diff($allProps, $propsToFilter);
|
2021-03-24 10:26:51 +00:00
|
|
|
return $filteredProps;
|
2021-03-23 18:35:28 +00:00
|
|
|
}
|
|
|
|
|
2021-03-24 10:26:51 +00:00
|
|
|
public function parseData($file) {
|
2021-03-23 08:13:54 +00:00
|
|
|
$file = $this->path . $file;
|
|
|
|
$rows = array_map(function ($v) {
|
|
|
|
return str_getcsv($v, "\t");
|
|
|
|
}
|
|
|
|
, file($file));
|
|
|
|
$header = array_shift($rows);
|
2021-03-26 19:09:05 +00:00
|
|
|
$data = null;
|
2021-03-23 08:13:54 +00:00
|
|
|
foreach ($rows as $row) {
|
|
|
|
$data[] = @array_combine($header, $row);
|
2021-03-24 15:37:21 +00:00
|
|
|
}
|
2021-03-23 08:13:54 +00:00
|
|
|
return $data;
|
|
|
|
}
|
2021-03-27 09:40:43 +00:00
|
|
|
|
|
|
|
public function processCubeMain($file){
|
2021-03-27 09:51:38 +00:00
|
|
|
$path = dirname(getcwd()).DIRECTORY_SEPARATOR."bin".DIRECTORY_SEPARATOR;
|
|
|
|
exec($path."sqlite3.exe ".$path.DB_FILE." '.separator \"t\"' '.import ".TXT_PATH."$file cubemain'");
|
2021-03-27 09:40:43 +00:00
|
|
|
}
|
2021-03-23 08:13:54 +00:00
|
|
|
}
|
|
|
|
?>
|