Subversion Repositories checksum-tools

Compare Revisions

Regard whitespace Rev 15 → Rev 14

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