Subversion Repositories checksum-tools

Compare Revisions

Regard whitespace Rev 3 → Rev 4

/trunk/PHP/md5_generate.php
20,6 → 20,8
// 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");
44,7 → 46,8
if (is_dir($fullpath)) {
_rec($fullpath);
} else {
### echo "$fullpath\n";
global $show_verbose;
if ($show_verbose) echo "$fullpath\n";
$dir = pathinfo($fullpath, PATHINFO_DIRNAME);
 
if (!file_exists($md5_file)) {
79,16 → 82,27
 
# ---
 
if ($argc != 2) {
echo "Syntax: $argv[0] <directory>\n";
$show_verbose = false;
$dir = '';
 
for ($i=1; $i<$argc; $i++) {
if ($argv[$i] == '-v') {
$show_verbose = true;
} else {
$dir = $argv[$i];
}
}
 
if (empty($dir)) {
echo "Syntax: $argv[0] [-v] <directory>\n";
exit(2);
}
 
if (!is_dir($argv[1])) {
if (!is_dir($dir)) {
echo "Directory not found\n";
exit(1);
}
 
_rec($argv[1]);
_rec($dir);
 
echo "Done.\n";
if ($show_verbose) echo "Done.\n";
/trunk/PHP/md5_verify.php
17,6 → 17,8
limitations under the License.
*/
 
// TODO: make use of STDERR and return different exit codes
 
function testmd5($file) {
// TODO: warn if an entry is multiple times (with different checksums) in a single file
if (!file_exists($file)) {
25,8 → 27,18
}
 
$lines = file($file);
$is_first_line = true;
$force_utf8 = false;
foreach ($lines as $line) {
$line = str_replace("\xEF\xBB\xBF",'',$line);
if ($is_first_line) {
$tmp = 0;
$line = str_replace("\xEF\xBB\xBF",'',$line,$tmp);
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);
 
$line = trim($line);
if ($line == '') continue;
$line = str_replace('*', ' ', $line);
41,7 → 53,8
if (strtolower($checksum) != strtolower($checksum2)) {
echo "CHECKSUM FAIL: $origname (expected $checksum, but is $checksum2)\n";
} else {
//echo "OK: $origname\n";
global $show_verbose;
if ($show_verbose) echo "OK: $origname\n";
}
}
// TODO: Also warn about extra files which are not indexed
49,23 → 62,33
}
 
function _rec($directory) {
$directory = rtrim($directory, '/\\');
 
if (!is_dir($directory)) {
exit("Invalid directory path $directory\n");
}
 
if ($dont_add_files = count(glob("$directory/*.md5")) == 0) {
// echo "Directory $directory has no MD5 file. Skipping.\n";
global $show_verbose;
if ($show_verbose) echo "Directory $directory has no MD5 file. Skipping.\n";
} else {
$out = array();
 
// echo "Check $directory\n";
$md5files = glob('*.md5');
global $show_verbose;
if ($show_verbose) echo "Check directory $directory\n";
$md5files = glob($directory.'/*.md5');
foreach ($md5files as $md5file) {
testmd5($md5file);
}
}
 
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 !== '.' && $file !== '..') {
$file = $directory . '/' . $file;
if (is_dir($file)) {
78,16 → 101,27
 
# ---
 
if ($argc != 2) {
echo "Syntax: $argv[0] <directory>\n";
$show_verbose = false;
$dir = '';
 
for ($i=1; $i<$argc; $i++) {
if ($argv[$i] == '-v') {
$show_verbose = true;
} else {
$dir = $argv[$i];
}
}
 
if (empty($dir)) {
echo "Syntax: $argv[0] [-v] <directory>\n";
exit(2);
}
 
if (!is_dir($argv[1])) {
if (!is_dir($dir)) {
echo "Directory not found\n";
exit(1);
}
 
_rec($argv[1]);
_rec($dir);
 
echo "Done.\n";
if ($show_verbose) echo "Done.\n";
/trunk/PHP/sfv_generate.php
20,6 → 20,8
// 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");
44,7 → 46,8
if (is_dir($fullpath)) {
_rec($fullpath);
} else {
### echo "$fullpath\n";
global $show_verbose;
if ($show_verbose) echo "$fullpath\n";
$dir = pathinfo($fullpath, PATHINFO_DIRNAME);
 
if (!file_exists($sfv_file)) {
88,16 → 91,27
 
# ---
 
if ($argc != 2) {
echo "Syntax: $argv[0] <directory>\n";
$show_verbose = false;
$dir = '';
 
for ($i=1; $i<$argc; $i++) {
if ($argv[$i] == '-v') {
$show_verbose = true;
} else {
$dir = $argv[$i];
}
}
 
if (empty($dir)) {
echo "Syntax: $argv[0] [-v] <directory>\n";
exit(2);
}
 
if (!is_dir($argv[1])) {
if (!is_dir($dir)) {
echo "Directory not found\n";
exit(1);
}
 
_rec($argv[1]);
_rec($dir);
 
echo "Done.\n";
if ($show_verbose) echo "Done.\n";
/trunk/PHP/sfv_verify.php
17,6 → 17,8
limitations under the License.
*/
 
// TODO: make use of STDERR and return different exit codes
 
function testsfv($file) {
// TODO: warn if an entry is multiple times (with different checksums) in a single file
if (!file_exists($file)) {
25,8 → 27,18
}
 
$lines = file($file);
$is_first_line = true;
$force_utf8 = false;
foreach ($lines as $line) {
$line = str_replace("\xEF\xBB\xBF",'',$line);
if ($is_first_line) {
$tmp = 0;
$line = str_replace("\xEF\xBB\xBF",'',$line,$tmp);
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);
 
$line = rtrim($line);
if ($line == '') continue;
$checksum = substr($line,-8);
39,7 → 51,8
if (strtolower($checksum) != strtolower($checksum2)) {
echo "CHECKSUM FAIL: $origname (expected $checksum, but is $checksum2)\n";
} else {
//echo "OK: $origname\n";
global $show_verbose;
if ($show_verbose) echo "OK: $origname\n";
}
}
// TODO: Also warn about extra files which are not indexed
61,23 → 74,33
}
 
function _rec($directory) {
$directory = rtrim($directory, '/\\');
 
if (!is_dir($directory)) {
exit("Invalid directory path $directory\n");
}
 
if ($dont_add_files = count(glob("$directory/*.sfv")) == 0) {
// echo "Directory $directory has no SFV file. Skipping.\n";
global $show_verbose;
if ($show_verbose) echo "Directory $directory has no SFV file. Skipping.\n";
} else {
$out = array();
 
// echo "Check $directory\n";
$sfvfiles = glob('*.sfv');
global $show_verbose;
if ($show_verbose) echo "Check directory $directory\n";
$sfvfiles = glob($directory.'/*.sfv');
foreach ($sfvfiles as $sfvfile) {
testsfv($sfvfile);
}
}
 
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 !== '.' && $file !== '..') {
$file = $directory . '/' . $file;
if (is_dir($file)) {
90,16 → 113,27
 
# ---
 
if ($argc != 2) {
echo "Syntax: $argv[0] <directory>\n";
$show_verbose = false;
$dir = '';
 
for ($i=1; $i<$argc; $i++) {
if ($argv[$i] == '-v') {
$show_verbose = true;
} else {
$dir = $argv[$i];
}
}
 
if (empty($dir)) {
echo "Syntax: $argv[0] [-v] <directory>\n";
exit(2);
}
 
if (!is_dir($argv[1])) {
if (!is_dir($dir)) {
echo "Directory not found\n";
exit(1);
}
 
_rec($argv[1]);
_rec($dir);
 
echo "Done.\n";
if ($show_verbose) echo "Done.\n";