Subversion Repositories checksum-tools

Compare Revisions

Regard whitespace Rev 4 → Rev 3

/trunk/PHP/md5_generate.php
20,8 → 20,6
// 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");
46,8 → 44,7
if (is_dir($fullpath)) {
_rec($fullpath);
} else {
global $show_verbose;
if ($show_verbose) echo "$fullpath\n";
### echo "$fullpath\n";
$dir = pathinfo($fullpath, PATHINFO_DIRNAME);
 
if (!file_exists($md5_file)) {
82,27 → 79,16
 
# ---
 
$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";
if ($argc != 2) {
echo "Syntax: $argv[0] <directory>\n";
exit(2);
}
 
if (!is_dir($dir)) {
if (!is_dir($argv[1])) {
echo "Directory not found\n";
exit(1);
}
 
_rec($dir);
_rec($argv[1]);
 
if ($show_verbose) echo "Done.\n";
echo "Done.\n";
/trunk/PHP/md5_verify.php
17,8 → 17,6
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)) {
27,18 → 25,8
}
 
$lines = file($file);
$is_first_line = true;
$force_utf8 = false;
foreach ($lines as $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 = str_replace("\xEF\xBB\xBF",'',$line);
$line = trim($line);
if ($line == '') continue;
$line = str_replace('*', ' ', $line);
53,8 → 41,7
if (strtolower($checksum) != strtolower($checksum2)) {
echo "CHECKSUM FAIL: $origname (expected $checksum, but is $checksum2)\n";
} else {
global $show_verbose;
if ($show_verbose) echo "OK: $origname\n";
//echo "OK: $origname\n";
}
}
// TODO: Also warn about extra files which are not indexed
62,33 → 49,23
}
 
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) {
global $show_verbose;
if ($show_verbose) echo "Directory $directory has no MD5 file. Skipping.\n";
// echo "Directory $directory has no MD5 file. Skipping.\n";
} else {
$out = array();
 
global $show_verbose;
if ($show_verbose) echo "Check directory $directory\n";
$md5files = glob($directory.'/*.md5');
// echo "Check $directory\n";
$md5files = glob('*.md5');
foreach ($md5files as $md5file) {
testmd5($md5file);
}
}
 
$sd = @scandir($directory);
if ($sd === false) {
echo "Error: Cannot scan directory $directory\n";
return;
}
 
foreach ($sd as $file) {
foreach (scandir($directory) as $file) {
if ($file !== '.' && $file !== '..') {
$file = $directory . '/' . $file;
if (is_dir($file)) {
101,27 → 78,16
 
# ---
 
$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";
if ($argc != 2) {
echo "Syntax: $argv[0] <directory>\n";
exit(2);
}
 
if (!is_dir($dir)) {
if (!is_dir($argv[1])) {
echo "Directory not found\n";
exit(1);
}
 
_rec($dir);
_rec($argv[1]);
 
if ($show_verbose) echo "Done.\n";
echo "Done.\n";
/trunk/PHP/sfv_generate.php
20,8 → 20,6
// 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");
46,8 → 44,7
if (is_dir($fullpath)) {
_rec($fullpath);
} else {
global $show_verbose;
if ($show_verbose) echo "$fullpath\n";
### echo "$fullpath\n";
$dir = pathinfo($fullpath, PATHINFO_DIRNAME);
 
if (!file_exists($sfv_file)) {
91,27 → 88,16
 
# ---
 
$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";
if ($argc != 2) {
echo "Syntax: $argv[0] <directory>\n";
exit(2);
}
 
if (!is_dir($dir)) {
if (!is_dir($argv[1])) {
echo "Directory not found\n";
exit(1);
}
 
_rec($dir);
_rec($argv[1]);
 
if ($show_verbose) echo "Done.\n";
echo "Done.\n";
/trunk/PHP/sfv_verify.php
17,8 → 17,6
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)) {
27,18 → 25,8
}
 
$lines = file($file);
$is_first_line = true;
$force_utf8 = false;
foreach ($lines as $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 = str_replace("\xEF\xBB\xBF",'',$line);
$line = rtrim($line);
if ($line == '') continue;
$checksum = substr($line,-8);
51,8 → 39,7
if (strtolower($checksum) != strtolower($checksum2)) {
echo "CHECKSUM FAIL: $origname (expected $checksum, but is $checksum2)\n";
} else {
global $show_verbose;
if ($show_verbose) echo "OK: $origname\n";
//echo "OK: $origname\n";
}
}
// TODO: Also warn about extra files which are not indexed
74,33 → 61,23
}
 
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) {
global $show_verbose;
if ($show_verbose) echo "Directory $directory has no SFV file. Skipping.\n";
// echo "Directory $directory has no SFV file. Skipping.\n";
} else {
$out = array();
 
global $show_verbose;
if ($show_verbose) echo "Check directory $directory\n";
$sfvfiles = glob($directory.'/*.sfv');
// echo "Check $directory\n";
$sfvfiles = glob('*.sfv');
foreach ($sfvfiles as $sfvfile) {
testsfv($sfvfile);
}
}
 
$sd = @scandir($directory);
if ($sd === false) {
echo "Error: Cannot scan directory $directory\n";
return;
}
 
foreach ($sd as $file) {
foreach (scandir($directory) as $file) {
if ($file !== '.' && $file !== '..') {
$file = $directory . '/' . $file;
if (is_dir($file)) {
113,27 → 90,16
 
# ---
 
$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";
if ($argc != 2) {
echo "Syntax: $argv[0] <directory>\n";
exit(2);
}
 
if (!is_dir($dir)) {
if (!is_dir($argv[1])) {
echo "Directory not found\n";
exit(1);
}
 
_rec($dir);
_rec($argv[1]);
 
if ($show_verbose) echo "Done.\n";
echo "Done.\n";