Subversion Repositories checksum-tools

Compare Revisions

Ignore whitespace Rev 15 → Rev 16

/trunk/PHP/md5_generate.php
21,6 → 21,8
// If there is already an MD5 file existing, only new files get appended to the existing MD5 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($md5_file, "; Generated by ViaThinkSoft\r\n"); // TODO: BOM
}
 
if (!in_array($file, $existing_files)) {
$md5 = strtolower(md5_file($fullpath));
file_put_contents($md5_file, "$md5 *$file\r\n", FILE_APPEND);
if (!in_arrayi($file, $existing_files)) {
$hash = md5_file($fullpath);
if ($hash === false) {
fwrite(STDERR, "Cannot get hash of '$fullpath'\n");
$res = false;
} else {
$md5 = strtolower($hash);
file_put_contents($md5_file, "$md5 *$file\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 md5_get_files($filename) {
99,6 → 108,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;
/trunk/PHP/sfv_generate.php
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));
file_put_contents($sfv_file, "$file $crc32\r\n", FILE_APPEND);
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;