Subversion Repositories checksum-tools

Compare Revisions

Regard whitespace Rev 4 → Rev 5

/trunk/PHP/md5_generate.php
35,17 → 35,23
$existing_files = array();
}
 
foreach (scandir($directory) as $file) {
$sd = @scandir($directory);
if ($sd === false) {
echo "Error: Cannot scan directory $directory\n";
return;
}
 
foreach ($sd as $file) {
if ($file === '.') continue;
if ($file === '..') continue;
if (strtolower($file) === 'thumbs.db') continue;
if (substr($file, -4) === '.md5') continue;
if (substr($file, -4) === '.sfv') continue;
if (strtolower(substr($file, -4)) === '.md5') continue;
if (strtolower(substr($file, -4)) === '.sfv') continue;
 
$fullpath = $directory . '/' . $file;
if (is_dir($fullpath)) {
_rec($fullpath);
} else {
} else if (is_file($fullpath)) {
global $show_verbose;
if ($show_verbose) echo "$fullpath\n";
$dir = pathinfo($fullpath, PATHINFO_DIRNAME);
58,6 → 64,9
$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?!
echo "Warning: $fullpath is not a regular file!\n";
}
}
}
/trunk/PHP/md5_verify.php
18,7 → 18,24
*/
 
// TODO: make use of STDERR and return different exit codes
// TODO: On Windows file systems, accept file names case insensitively
 
function utf8_normalize($str) {
// This helps to handle decomposite Unicode endpoints (E.g. German Umlauts have different representations)
// Requires php-intl
if (!class_exists('Normalizer')) return $str;
return Normalizer::normalize($str);
}
 
function convertToUTF8($str) {
$enc = mb_detect_encoding($str);
if ($enc && $enc != 'UTF-8') {
return iconv($enc, 'UTF-8', $str);
} else {
return $str;
}
}
 
function testmd5($file) {
// TODO: warn if an entry is multiple times (with different checksums) in a single file
if (!file_exists($file)) {
36,9 → 53,10
if ($tmp > 0) $force_utf8 = true;
$is_first_line = false;
}
$is_ansi = strstr(utf8_decode($line),'?') !== false; // Attention: This assumes that '?' is not part of the line!
if (!$force_utf8 && $is_ansi) $line = utf8_encode($line);
if (!$force_utf8) $line = convertToUTF8($line);
 
if (substr(trim($line),0,1) == ';') continue;
 
$line = trim($line);
if ($line == '') continue;
$line = str_replace('*', ' ', $line);
49,6 → 67,7
if (!file_exists($origname)) {
echo "WARNING: File vanished : $origname\n";
} else {
if (is_file($origname)) {
$checksum2 = md5_file($origname);
if (strtolower($checksum) != strtolower($checksum2)) {
echo "CHECKSUM FAIL: $origname (expected $checksum, but is $checksum2)\n";
56,11 → 75,39
global $show_verbose;
if ($show_verbose) echo "OK: $origname\n";
}
} else {
// For some reason, some files on a NTFS volume are "FIFO" pipe files?!
echo "Warning: $origname is not a regular file!\n";
}
// TODO: Also warn about extra files which are not indexed
}
 
$origname = utf8_normalize(basename($origname));
$files_checked[] = dirname($file) . '/' . $origname;
}
 
// Now check if files have vanished!
$directory = dirname($file);
$sd = @scandir($directory);
if ($sd === false) {
echo "Error: Cannot scan directory $directory\n";
} else {
foreach ($sd as $file) {
if ($file === '.') continue;
if ($file === '..') continue;
if (strtolower($file) === 'thumbs.db') continue;
if (strtolower(substr($file, -4)) === '.md5') continue;
if (strtolower(substr($file, -4)) === '.sfv') continue;
$fullpath = $directory . '/' . $file;
if (!is_dir($fullpath)) {
$fullpath = utf8_normalize($fullpath);
if (!in_array($fullpath,$files_checked)) {
echo "Warning: File not in SFV checksum file: $fullpath\n";
}
}
}
}
}
 
function _rec($directory) {
$directory = rtrim($directory, '/\\');
 
/trunk/PHP/sfv_generate.php
35,17 → 35,23
$existing_files = array();
}
 
foreach (scandir($directory) as $file) {
$sd = @scandir($directory);
if ($sd === false) {
echo "Error: Cannot scan directory $directory\n";
return;
}
 
foreach ($sd as $file) {
if ($file === '.') continue;
if ($file === '..') continue;
if (strtolower($file) === 'thumbs.db') continue;
if (substr($file, -4) === '.md5') continue;
if (substr($file, -4) === '.sfv') continue;
if (strtolower(substr($file, -4)) === '.md5') continue;
if (strtolower(substr($file, -4)) === '.sfv') continue;
 
$fullpath = $directory . '/' . $file;
if (is_dir($fullpath)) {
_rec($fullpath);
} else {
} else if (is_file($fullpath)) {
global $show_verbose;
if ($show_verbose) echo "$fullpath\n";
$dir = pathinfo($fullpath, PATHINFO_DIRNAME);
58,6 → 64,9
$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?!
echo "Warning: $fullpath is not a regular file!\n";
}
}
}
/trunk/PHP/sfv_verify.php
18,7 → 18,24
*/
 
// TODO: make use of STDERR and return different exit codes
// TODO: On Windows file systems, accept file names case insensitively
 
function utf8_normalize($str) {
// This helps to handle decomposite Unicode endpoints (E.g. German Umlauts have different representations)
// Requires php-intl
if (!class_exists('Normalizer')) return $str;
return Normalizer::normalize($str);
}
 
function convertToUTF8($str) {
$enc = mb_detect_encoding($str);
if ($enc && $enc != 'UTF-8') {
return iconv($enc, 'UTF-8', $str);
} else {
return $str;
}
}
 
function testsfv($file) {
// TODO: warn if an entry is multiple times (with different checksums) in a single file
if (!file_exists($file)) {
26,6 → 43,8
return;
}
 
$files_checked = array();
 
$lines = file($file);
$is_first_line = true;
$force_utf8 = false;
36,17 → 55,19
if ($tmp > 0) $force_utf8 = true;
$is_first_line = false;
}
$is_ansi = strstr(utf8_decode($line),'?') !== false; // Attention: This assumes that '?' is not part of the line!
if (!$force_utf8 && $is_ansi) $line = utf8_encode($line);
if (!$force_utf8) $line = convertToUTF8($line);
 
if (substr(trim($line),0,1) == ';') continue;
 
$line = rtrim($line);
if ($line == '') continue;
$checksum = substr($line,-8);
$origname = rtrim(substr($line,0,strlen($line)-8));
$origname = dirname($file) . '/' . trim($origname);
$origname = dirname($file) . '/' . rtrim($origname);
if (!file_exists($origname)) {
echo "WARNING: File vanished : $origname\n";
} else {
if (is_file($origname)) {
$checksum2 = crc32_file($origname);
if (strtolower($checksum) != strtolower($checksum2)) {
echo "CHECKSUM FAIL: $origname (expected $checksum, but is $checksum2)\n";
54,11 → 75,39
global $show_verbose;
if ($show_verbose) echo "OK: $origname\n";
}
} else {
// For some reason, some files on a NTFS volume are "FIFO" pipe files?!
echo "Warning: $origname is not a regular file!\n";
}
// TODO: Also warn about extra files which are not indexed
}
 
$origname = utf8_normalize(basename($origname));
$files_checked[] = dirname($file) . '/' . $origname;
}
 
// Now check if files have vanished!
$directory = dirname($file);
$sd = @scandir($directory);
if ($sd === false) {
echo "Error: Cannot scan directory $directory\n";
} else {
foreach ($sd as $file) {
if ($file === '.') continue;
if ($file === '..') continue;
if (strtolower($file) === 'thumbs.db') continue;
if (strtolower(substr($file, -4)) === '.md5') continue;
if (strtolower(substr($file, -4)) === '.sfv') continue;
$fullpath = $directory . '/' . $file;
if (!is_dir($fullpath)) {
$fullpath = utf8_normalize($fullpath);
if (!in_array($fullpath,$files_checked)) {
echo "Warning: File not in SFV checksum file: $fullpath\n";
}
}
}
}
}
 
function swapEndianness($hex) {
return implode('', array_reverse(str_split($hex, 2)));
}