-
Notifications
You must be signed in to change notification settings - Fork 0
/
repair.php
56 lines (49 loc) · 1.91 KB
/
repair.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
require_once "vendor/autoload.php";
use Aternos\Creabit\Creabit;
use Aternos\Creabit\Enums\DimensionType;
use Aternos\Creabit\Enums\SettingsType;
use Aternos\Creabit\Enums\GeneratorType;
if (!isset($argc)) {
echo "argc and argv disabled. check php.ini\n";
return;
}
$no = ["N", "n"];
function setup(string $filename): Creabit {
if (!file_exists($filename)) {
echo "input file does not exist\n";
exit;
}
$filePtr = fopen($filename, "r");
$fileContent = fread($filePtr, filesize($filename));
fclose($filePtr);
return new Creabit($fileContent);
}
switch ($argc) {
case 1:
echo "too few params given. choose:\n1 argument:\n\t1: path of input file -> output is current dir\n2 arguments:\n\t1: path of input file\n\t2: path of output file\n";
return;
case 2:
$levelRepairer = setup($argv[1]);
$writtenBytes = file_put_contents("new_level.dat", $levelRepairer->repair());
break;
case 3:
$levelRepairer = setup($argv[1]);
$fileName = $argv[2];
if (!file_exists(dirname($argv[2]))) mkdir(dirname($argv[2]), recursive: true);
if (file_exists($argv[2]) === true) {
$answer = readline("output file does already exist.\ndo you want to overwrite it?(Y/n)\n");
if (in_array($answer, $no)) {
while (file_exists($fileName)) {
$numeric = substr($fileName, strlen($argv[2]));
if (!empty($numeric)) $fileName = $argv[2] . strval(intval($numeric) + 1);
else $fileName = $fileName . "1";
}
}
}
$writtenBytes = file_put_contents($fileName, $levelRepairer->repair());
break;
default:
echo "too many params given. choose:\n1 argument:\n\t1: path of input file -> output is current dir\n2 arguments:\n\t1: path of input file\n\t2: path of output file\n";
return;
}