-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanager.php
87 lines (69 loc) · 1.78 KB
/
manager.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
define('CRLF', "\r\n");
define('DS', '/');
$exclude = [
'.DS_Store',
'thumbs.db',
'Thumbs.db'
];
function err($m) {
echo $m.PHP_EOL;
die(0);
}
function main($argc, $argv) {
if ($argc < 2) return;
switch ($argv[1]) {
case 'genhash':
if ($argc < 3) return;
$hashes = [];
hashDir($argv[3], $argv[3], $hashes, 'size');
$output = filteredIniCreate($hashes, 'size');
file_put_contents($argv[2], $output);
break;
default:
err('ERROR');
}
}
function hashDir($dir, $base, &$map, $type) {
if (!is_dir($dir)) err('No such directory '.$dir);
$files = scandir($dir);
for ($i = 2, $s = sizeof($files); $i < $s; $i++) {
if (is_dir($dir.DS.$files[$i])) {
hashDir($dir.DS.$files[$i], $base, $map, $type);
} else {
if ($type == 'adler') {
$hash = hash('adler32', file_get_contents($dir.DS.$files[$i]));
} else if ($type == 'size') {
$hash = filesize($dir.DS.$files[$i]);
} else {
$hash = md5_file($dir.DS.$files[$i]);
}
$map[str_replace($base, '', $dir).DS.$files[$i]] = $hash;
}
}
}
function hasIn($haystack, $needle) {
if (!is_array($needle)) $needle = [$needle];
foreach ($needle as $query) {
if (strstr($haystack, $query) !== false) return true;
}
return false;
}
function filteredIniCreate($hashes, $mode) {
global $exclude;
$output = '[info]'.CRLF;
$output .= '"game"="UminekoPS3fication*"'.CRLF;
$output .= '"hash"="'.$mode.'"'.CRLF;
$output .= '"ver"="20190109-ru"'.CRLF;
$output .= '"apiver"="2.2.0"'.CRLF;
$output .= '"date"="ignore"'.CRLF;
$output .= '[data]'.CRLF;
foreach ($hashes as $file => $hash) {
if (!hasIn($file, $exclude) && !strstr($file, 'game.hash')) {
if ($file[0] == '/') $file = substr($file, 1);
$output .= '"'.$file.'"="'.$hash.'"'.CRLF;
}
}
return $output;
}
main($argc, $argv);