/trunk/PHP/md5_generate.php |
---|
2,7 → 2,7 |
<?php |
/* |
Copyright 2020-2021 Daniel Marschall, ViaThinkSoft |
Copyright 2020-2022 Daniel Marschall, ViaThinkSoft |
Licensed under the Apache License, Version 2.0 (the "License"); |
you may not use this file except in compliance with the License. |
20,11 → 20,10 |
// This script generates MD5 files |
// If there is already an MD5 file existing, only new files get appended to the existing MD5 files. |
// TODO: make use of STDERR and return different exit codes |
function _rec($directory) { |
if (!is_dir($directory)) { |
die("Invalid directory path $directory\n"); |
fwrite(STDERR, "Invalid directory path '$directory'\n"); |
return false; |
} |
if ((basename($directory) == '.') || (basename($directory) == '..')) { |
44,13 → 43,14 |
$sd = @scandir($directory); |
if ($sd === false) { |
echo "Error: Cannot scan directory $directory\n"; |
return; |
fwrite(STDERR, "Error: Cannot scan directory $directory\n"); |
return false; |
} |
foreach ($sd as $file) { |
if ($file === '.') continue; |
if ($file === '..') continue; |
if (substr($file,0,1) === '.') continue; |
if (strtolower($file) === 'thumbs.db') continue; |
if (strtolower(substr($file, -4)) === '.md5') continue; |
if (strtolower(substr($file, -4)) === '.sfv') continue; |
74,9 → 74,11 |
} |
} else { |
// For some reason, some files on a NTFS volume are "FIFO" pipe files?! |
echo "Warning: $fullpath is not a regular file!\n"; |
fwrite(STDERR, "Warning: $fullpath is not a regular file!\n"); |
} |
} |
return true; |
} |
function md5_get_files($filename) { |
101,7 → 103,7 |
$show_verbose = false; |
$do_recursive = false; |
$dir = ''; |
$dirs = array(); |
for ($i=1; $i<$argc; $i++) { |
if ($argv[$i] == '-v') { |
109,20 → 111,19 |
} else if ($argv[$i] == '-r') { |
$do_recursive = true; |
} else { |
$dir = $argv[$i]; |
$dirs[] = $argv[$i]; |
} |
} |
if (empty($dir)) { |
echo "Syntax: $argv[0] [-v] [-r] <directory>\n"; |
if (count($dirs) == 0) { |
echo "Syntax: $argv[0] [-v] [-r] <directory> [<directory> [...]]\n"; |
exit(2); |
} |
if (!is_dir($dir)) { |
echo "Directory not found\n"; |
exit(1); |
$res = 0; |
foreach ($dirs as $dir) { |
if (!_rec($dir)) $res = 1; |
} |
if ($show_verbose) echo "Done.\n"; |
exit($res); |
_rec($dir); |
if ($show_verbose) echo "Done.\n"; |
/trunk/PHP/md5_verify.php |
---|
2,7 → 2,7 |
<?php |
/* |
Copyright 2020 Daniel Marschall, ViaThinkSoft |
Copyright 2020-2022 Daniel Marschall, ViaThinkSoft |
Licensed under the Apache License, Version 2.0 (the "License"); |
you may not use this file except in compliance with the License. |
17,7 → 17,6 |
limitations under the License. |
*/ |
// TODO: make use of STDERR and return different exit codes |
// TODO: On Windows file systems, accept file names case insensitively |
function utf8_normalize($str) { |
39,7 → 38,7 |
function testmd5($file) { |
// TODO: warn if an entry is multiple times (with different checksums) in a single file |
if (!file_exists($file)) { |
echo "ERROR: File $file does not exist.\n"; |
fwrite(STDERR, "ERROR: File $file does not exist.\n"); |
return; |
} |
67,12 → 66,12 |
$origname = dirname($file) . '/' . trim($origname); |
$checksum = trim($checksum); |
if (!file_exists($origname)) { |
echo "WARNING: File vanished : $origname\n"; |
fwrite(STDERR, "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"; |
fwrite(STDERR, "CHECKSUM FAIL: $origname (expected $checksum, but is $checksum2)\n"); |
} else { |
global $show_verbose; |
if ($show_verbose) echo "OK: $origname\n"; |
79,7 → 78,7 |
} |
} else { |
// For some reason, some files on a NTFS volume are "FIFO" pipe files?! |
echo "Warning: $origname is not a regular file!\n"; |
fwrite(STDERR, "Warning: $origname is not a regular file!\n"); |
} |
} |
91,11 → 90,12 |
$directory = dirname($file); |
$sd = @scandir($directory); |
if ($sd === false) { |
echo "Error: Cannot scan directory $directory\n"; |
fwrite(STDERR, "Error: Cannot scan directory $directory\n"); |
} else { |
foreach ($sd as $file) { |
if ($file === '.') continue; |
if ($file === '..') continue; |
if (substr($file,0,1) === '.') continue; |
if (strtolower($file) === 'thumbs.db') continue; |
if (strtolower(substr($file, -4)) === '.md5') continue; |
if (strtolower(substr($file, -4)) === '.sfv') continue; |
103,7 → 103,7 |
if (!is_dir($fullpath)) { |
$fullpath = utf8_normalize($fullpath); |
if (!in_array($fullpath,$files_checked)) { |
echo "Warning: File not in SFV checksum file: $fullpath\n"; |
fwrite(STDERR, "Warning: File not in SFV checksum file: $fullpath\n"); |
} |
} |
} |
114,7 → 114,8 |
$directory = rtrim($directory, '/\\'); |
if (!is_dir($directory)) { |
exit("Invalid directory path $directory\n"); |
fwrite(STDERR, "Invalid directory path $directory\n"); |
return false; |
} |
if ($dont_add_files = count(glob("$directory/*.md5")) == 0) { |
133,8 → 134,8 |
$sd = @scandir($directory); |
if ($sd === false) { |
echo "Error: Cannot scan directory $directory\n"; |
return; |
fwrite(STDERR, "Error: Cannot scan directory $directory\n"); |
return false; |
} |
foreach ($sd as $file) { |
145,6 → 146,8 |
} |
} |
} |
return true; |
} |
151,26 → 154,25 |
# --- |
$show_verbose = false; |
$dir = ''; |
$dirs = array(); |
for ($i=1; $i<$argc; $i++) { |
if ($argv[$i] == '-v') { |
$show_verbose = true; |
} else { |
$dir = $argv[$i]; |
$dirs[] = $argv[$i]; |
} |
} |
if (empty($dir)) { |
echo "Syntax: $argv[0] [-v] <directory>\n"; |
if (count($dirs) == 0) { |
echo "Syntax: $argv[0] [-v] <directory> [<directory> [...]]\n"; |
exit(2); |
} |
if (!is_dir($dir)) { |
echo "Directory not found\n"; |
exit(1); |
$res = 0; |
foreach ($dirs as $dir) { |
if (!_rec($dir)) $res = 1; |
} |
if ($show_verbose) echo "Done.\n"; |
exit($res); |
_rec($dir); |
if ($show_verbose) echo "Done.\n"; |
/trunk/PHP/sfv_generate.php |
---|
2,7 → 2,7 |
<?php |
/* |
Copyright 2020-2021 Daniel Marschall, ViaThinkSoft |
Copyright 2020-2022 Daniel Marschall, ViaThinkSoft |
Licensed under the Apache License, Version 2.0 (the "License"); |
you may not use this file except in compliance with the License. |
20,11 → 20,10 |
// This script generates SFV files |
// If there is already an SFV file existing, only new files get appended to the existing SFV files. |
// TODO: make use of STDERR and return different exit codes |
function _rec($directory) { |
if (!is_dir($directory)) { |
die("Invalid directory path $directory\n"); |
fwrite(STDERR, "Invalid directory path '$directory'\n"); |
return false; |
} |
if ((basename($directory) == '.') || (basename($directory) == '..')) { |
44,13 → 43,14 |
$sd = @scandir($directory); |
if ($sd === false) { |
echo "Error: Cannot scan directory $directory\n"; |
return; |
fwrite(STDERR, "Error: Cannot scan directory $directory\n"); |
return false; |
} |
foreach ($sd as $file) { |
if ($file === '.') continue; |
if ($file === '..') continue; |
if (substr($file,0,1) === '.') continue; |
if (strtolower($file) === 'thumbs.db') continue; |
if (strtolower(substr($file, -4)) === '.md5') continue; |
if (strtolower(substr($file, -4)) === '.sfv') continue; |
74,9 → 74,11 |
} |
} else { |
// For some reason, some files on a NTFS volume are "FIFO" pipe files?! |
echo "Warning: $fullpath is not a regular file!\n"; |
fwrite(STDERR, "Warning: $fullpath is not a regular file!\n"); |
} |
} |
return true; |
} |
function sfv_get_files($filename) { |
110,7 → 112,7 |
$show_verbose = false; |
$do_recursive = false; |
$dir = ''; |
$dirs = array(); |
for ($i=1; $i<$argc; $i++) { |
if ($argv[$i] == '-v') { |
118,20 → 120,18 |
} else if ($argv[$i] == '-r') { |
$do_recursive = true; |
} else { |
$dir = $argv[$i]; |
$dirs[] = $argv[$i]; |
} |
} |
if (empty($dir)) { |
echo "Syntax: $argv[0] [-v] [-r] <directory>\n"; |
if (count($dirs) == 0) { |
echo "Syntax: $argv[0] [-v] [-r] <directory> [<directory> [...]]\n"; |
exit(2); |
} |
if (!is_dir($dir)) { |
echo "Directory not found\n"; |
exit(1); |
$res = 0; |
foreach ($dirs as $dir) { |
if (!_rec($dir)) $res = 1; |
} |
_rec($dir); |
if ($show_verbose) echo "Done.\n"; |
exit($res); |
/trunk/PHP/sfv_verify.php |
---|
2,7 → 2,7 |
<?php |
/* |
Copyright 2020 Daniel Marschall, ViaThinkSoft |
Copyright 2020-2022 Daniel Marschall, ViaThinkSoft |
Licensed under the Apache License, Version 2.0 (the "License"); |
you may not use this file except in compliance with the License. |
17,7 → 17,6 |
limitations under the License. |
*/ |
// TODO: make use of STDERR and return different exit codes |
// TODO: On Windows file systems, accept file names case insensitively |
function utf8_normalize($str) { |
39,7 → 38,7 |
function testsfv($file) { |
// TODO: warn if an entry is multiple times (with different checksums) in a single file |
if (!file_exists($file)) { |
echo "ERROR: File $file does not exist.\n"; |
fwrite(STDERR, "ERROR: File $file does not exist.\n"); |
return; |
} |
65,12 → 64,12 |
$origname = rtrim(substr($line,0,strlen($line)-8)); |
$origname = dirname($file) . '/' . rtrim($origname); |
if (!file_exists($origname)) { |
echo "WARNING: File vanished : $origname\n"; |
fwrite(STDERR, "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"; |
fwrite(STDERR, "CHECKSUM FAIL: $origname (expected $checksum, but is $checksum2)\n"); |
} else { |
global $show_verbose; |
if ($show_verbose) echo "OK: $origname\n"; |
77,7 → 76,7 |
} |
} else { |
// For some reason, some files on a NTFS volume are "FIFO" pipe files?! |
echo "Warning: $origname is not a regular file!\n"; |
fwrite(STDERR, "Warning: $origname is not a regular file!\n"); |
} |
} |
89,11 → 88,12 |
$directory = dirname($file); |
$sd = @scandir($directory); |
if ($sd === false) { |
echo "Error: Cannot scan directory $directory\n"; |
fwrite(STDERR, "Error: Cannot scan directory $directory\n"); |
} else { |
foreach ($sd as $file) { |
if ($file === '.') continue; |
if ($file === '..') continue; |
if (substr($file,0,1) === '.') continue; |
if (strtolower($file) === 'thumbs.db') continue; |
if (strtolower(substr($file, -4)) === '.md5') continue; |
if (strtolower(substr($file, -4)) === '.sfv') continue; |
101,7 → 101,7 |
if (!is_dir($fullpath)) { |
$fullpath = utf8_normalize($fullpath); |
if (!in_array($fullpath,$files_checked)) { |
echo "Warning: File not in SFV checksum file: $fullpath\n"; |
fwrite(STDERR, "Warning: File not in SFV checksum file: $fullpath\n"); |
} |
} |
} |
126,7 → 126,8 |
$directory = rtrim($directory, '/\\'); |
if (!is_dir($directory)) { |
exit("Invalid directory path $directory\n"); |
fwrite(STDERR, "Invalid directory path $directory\n"); |
return false; |
} |
if ($dont_add_files = count(glob("$directory/*.sfv")) == 0) { |
145,8 → 146,8 |
$sd = @scandir($directory); |
if ($sd === false) { |
echo "Error: Cannot scan directory $directory\n"; |
return; |
fwrite(STDERR, "Error: Cannot scan directory $directory\n"); |
return false; |
} |
foreach ($sd as $file) { |
157,6 → 158,8 |
} |
} |
} |
return true; |
} |
163,26 → 166,25 |
# --- |
$show_verbose = false; |
$dir = ''; |
$dirs = array(); |
for ($i=1; $i<$argc; $i++) { |
if ($argv[$i] == '-v') { |
$show_verbose = true; |
} else { |
$dir = $argv[$i]; |
$dirs[] = $argv[$i]; |
} |
} |
if (empty($dir)) { |
echo "Syntax: $argv[0] [-v] <directory>\n"; |
if (count($dirs) == 0) { |
echo "Syntax: $argv[0] [-v] <directory> [<directory> [...]]\n"; |
exit(2); |
} |
if (!is_dir($dir)) { |
echo "Directory not found\n"; |
exit(1); |
$res = 0; |
foreach ($dirs as $dir) { |
if (!_rec($dir)) $res = 1; |
} |
if ($show_verbose) echo "Done.\n"; |
exit($res); |
_rec($dir); |
if ($show_verbose) echo "Done.\n"; |