21,6 → 21,8 |
// If there is already an SFV file existing, only new files get appended to the existing SFV files. |
|
function _rec($directory) { |
$res = true; |
|
if (!is_dir($directory)) { |
fwrite(STDERR, "Invalid directory path '$directory'\n"); |
return false; |
68,17 → 70,24 |
file_put_contents($sfv_file, "; Generated by ViaThinkSoft\r\n"); // TODO: BOM |
} |
|
if (!in_array($file, $existing_files)) { |
$crc32 = strtoupper(crc32_file($fullpath)); |
if (!in_arrayi($file, $existing_files)) { |
$hash = crc32_file($fullpath); |
if ($hash === false) { |
fwrite(STDERR, "Cannot get hash of '$fullpath'\n"); |
$res = false; |
} else { |
$crc32 = strtoupper($hash); |
file_put_contents($sfv_file, "$file $crc32\r\n", FILE_APPEND); |
} |
} |
} else { |
// For some reason, some files on a NTFS volume are "FIFO" pipe files?! |
fwrite(STDERR, "Warning: $fullpath is not a regular file!\n"); |
$res = false; |
} |
} |
|
return true; |
return $res; |
} |
|
function sfv_get_files($filename) { |
99,7 → 108,9 |
} |
|
function crc32_file($filename, $rawOutput = false) { |
$out = bin2hex(hash_file ('crc32b', $filename , true)); |
$hash = hash_file('crc32b', $filename, true); |
if ($hash === false) return false; |
$out = bin2hex($hash); |
if (hash('crc32b', 'TEST') == 'b893eaee') { |
// hash_file() in PHP 5.2 has the wrong Endianess! |
// https://bugs.php.net/bug.php?id=47467 |
108,6 → 119,11 |
return $out; |
} |
|
function in_arrayi($needle, $haystack) { |
// Source: https://www.php.net/manual/en/function.in-array.php#89256 |
return in_array(strtolower($needle), array_map('strtolower', $haystack)); |
} |
|
# --- |
|
$show_verbose = false; |