mirror of
https://github.com/SabreTools/wizzardRedux.git
synced 2026-02-04 05:36:18 +00:00
Make it read from file line by line
Larger files (e.g. CSDB and EAB) can overload the server because of how much data it has to hold and process. Reading the files line by line makes that drop to more than half of what it was.
This commit is contained in:
@@ -224,10 +224,19 @@ function import_dat ($filename)
|
||||
$xmlr = new XmlReader;
|
||||
|
||||
// If the file doesn't start with the right thing, convert it
|
||||
$file = file($importroot.$filename);
|
||||
if (strpos($file[0], "<") !== 0)
|
||||
$handle = fopen($importroot.$filename, "r");
|
||||
if ($handle === false)
|
||||
{
|
||||
$xmlr->XML(rv2xml($file));
|
||||
echo "The file was not valid!<p/>\n";
|
||||
return;
|
||||
}
|
||||
|
||||
$file = fgets($handle);
|
||||
fclose($handle);
|
||||
if (strpos($file, "<") !== 0)
|
||||
{
|
||||
$xmlr->XML(rv2xml($importroot.$filename));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -237,7 +246,7 @@ function import_dat ($filename)
|
||||
if (!$result)
|
||||
{
|
||||
echo "The file was not valid!<p/>\n";
|
||||
die();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ function get_data($url)
|
||||
}
|
||||
|
||||
// Convert an old-style DAT to XML
|
||||
function rv2xml ($file)
|
||||
function rv2xml ($filename)
|
||||
{
|
||||
//ob_end_clean();
|
||||
ini_set('max_execution_time', 0); // Set the execution time to infinite. This is a bad idea in production.
|
||||
@@ -51,6 +51,15 @@ function rv2xml ($file)
|
||||
$itemPattern = @"/^(.*?) (.*)/";
|
||||
$endPattern = @"/^\)\s*$/";
|
||||
|
||||
// Get the file open for reading
|
||||
$file = fopen($filename, "r");
|
||||
|
||||
// If there's an error, return null
|
||||
if ($file === false)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Create the XMLWriter
|
||||
$xmlw = new XMLWriter;
|
||||
$xmlw->openMemory();
|
||||
@@ -60,9 +69,9 @@ function rv2xml ($file)
|
||||
$xmlw->startElement("datafile");
|
||||
|
||||
$block = false; $header = false;
|
||||
for ($k = 0; $k < sizeof($file); $k++)
|
||||
while (($line = fgets($file)) !== false)
|
||||
{
|
||||
$line = trim($file[$k]);
|
||||
$line = trim($line);
|
||||
|
||||
// If the line is the header or a game
|
||||
if (preg_match($headerPattern, $line, $matches) !== 0)
|
||||
@@ -179,6 +188,7 @@ function rv2xml ($file)
|
||||
}
|
||||
$xmlw->endElement();
|
||||
$xmlw->endDocument();
|
||||
fclose($file);
|
||||
|
||||
return $xmlw->outputMemory();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user