Subversion Repositories checksum-tools

Compare Revisions

Regard whitespace Rev 16 → Rev 15

/trunk/PHP/md5_generate.php
21,8 → 21,6
// 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;
70,24 → 68,17
file_put_contents($md5_file, "; Generated by ViaThinkSoft\r\n"); // TODO: BOM
}
 
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);
if (!in_array($file, $existing_files)) {
$md5 = strtolower(md5_file($fullpath));
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 $res;
return true;
}
 
function md5_get_files($filename) {
108,11 → 99,6
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,8 → 21,6
// 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;
70,24 → 68,17
file_put_contents($sfv_file, "; Generated by ViaThinkSoft\r\n"); // TODO: BOM
}
 
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);
if (!in_array($file, $existing_files)) {
$crc32 = strtoupper(crc32_file($fullpath));
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 $res;
return true;
}
 
function sfv_get_files($filename) {
108,9 → 99,7
}
 
function crc32_file($filename, $rawOutput = false) {
$hash = hash_file('crc32b', $filename, true);
if ($hash === false) return false;
$out = bin2hex($hash);
$out = bin2hex(hash_file ('crc32b', $filename , true));
if (hash('crc32b', 'TEST') == 'b893eaee') {
// hash_file() in PHP 5.2 has the wrong Endianess!
// https://bugs.php.net/bug.php?id=47467
119,11 → 108,6
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;