Rev 15 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 15 | Rev 16 | ||
---|---|---|---|
Line 19... | Line 19... | ||
19 | 19 | ||
20 | // This script generates SFV files |
20 | // This script generates SFV files |
21 | // If there is already an SFV file existing, only new files get appended to the existing SFV files. |
21 | // If there is already an SFV file existing, only new files get appended to the existing SFV files. |
22 | 22 | ||
23 | function _rec($directory) { |
23 | function _rec($directory) { |
- | 24 | $res = true; |
|
- | 25 | ||
24 | if (!is_dir($directory)) { |
26 | if (!is_dir($directory)) { |
25 | fwrite(STDERR, "Invalid directory path '$directory'\n"); |
27 | fwrite(STDERR, "Invalid directory path '$directory'\n"); |
26 | return false; |
28 | return false; |
27 | } |
29 | } |
28 | 30 | ||
Line 66... | Line 68... | ||
66 | 68 | ||
67 | if (!file_exists($sfv_file)) { |
69 | if (!file_exists($sfv_file)) { |
68 | file_put_contents($sfv_file, "; Generated by ViaThinkSoft\r\n"); // TODO: BOM |
70 | file_put_contents($sfv_file, "; Generated by ViaThinkSoft\r\n"); // TODO: BOM |
69 | } |
71 | } |
70 | 72 | ||
71 | if (!in_array($file, $existing_files)) { |
73 | if (!in_arrayi($file, $existing_files)) { |
72 | $crc32 = strtoupper(crc32_file($fullpath)); |
74 | $hash = crc32_file($fullpath); |
- | 75 | if ($hash === false) { |
|
- | 76 | fwrite(STDERR, "Cannot get hash of '$fullpath'\n"); |
|
- | 77 | $res = false; |
|
- | 78 | } else { |
|
- | 79 | $crc32 = strtoupper($hash); |
|
73 | file_put_contents($sfv_file, "$file $crc32\r\n", FILE_APPEND); |
80 | file_put_contents($sfv_file, "$file $crc32\r\n", FILE_APPEND); |
74 | } |
81 | } |
- | 82 | } |
|
75 | } else { |
83 | } else { |
76 | // For some reason, some files on a NTFS volume are "FIFO" pipe files?! |
84 | // For some reason, some files on a NTFS volume are "FIFO" pipe files?! |
77 | fwrite(STDERR, "Warning: $fullpath is not a regular file!\n"); |
85 | fwrite(STDERR, "Warning: $fullpath is not a regular file!\n"); |
- | 86 | $res = false; |
|
78 | } |
87 | } |
79 | } |
88 | } |
80 | 89 | ||
81 | return true; |
90 | return $res; |
82 | } |
91 | } |
83 | 92 | ||
84 | function sfv_get_files($filename) { |
93 | function sfv_get_files($filename) { |
85 | $out = array(); |
94 | $out = array(); |
86 | $lines = file($filename); |
95 | $lines = file($filename); |
Line 97... | Line 106... | ||
97 | function swapEndianness($hex) { |
106 | function swapEndianness($hex) { |
98 | return implode('', array_reverse(str_split($hex, 2))); |
107 | return implode('', array_reverse(str_split($hex, 2))); |
99 | } |
108 | } |
100 | 109 | ||
101 | function crc32_file($filename, $rawOutput = false) { |
110 | function crc32_file($filename, $rawOutput = false) { |
102 | $out = bin2hex(hash_file ('crc32b', $filename , true)); |
111 | $hash = hash_file('crc32b', $filename, true); |
- | 112 | if ($hash === false) return false; |
|
- | 113 | $out = bin2hex($hash); |
|
103 | if (hash('crc32b', 'TEST') == 'b893eaee') { |
114 | if (hash('crc32b', 'TEST') == 'b893eaee') { |
104 | // hash_file() in PHP 5.2 has the wrong Endianess! |
115 | // hash_file() in PHP 5.2 has the wrong Endianess! |
105 | // https://bugs.php.net/bug.php?id=47467 |
116 | // https://bugs.php.net/bug.php?id=47467 |
106 | $out = swapEndianness($out); |
117 | $out = swapEndianness($out); |
107 | } |
118 | } |
108 | return $out; |
119 | return $out; |
109 | } |
120 | } |
110 | 121 | ||
- | 122 | function in_arrayi($needle, $haystack) { |
|
- | 123 | // Source: https://www.php.net/manual/en/function.in-array.php#89256 |
|
- | 124 | return in_array(strtolower($needle), array_map('strtolower', $haystack)); |
|
- | 125 | } |
|
- | 126 | ||
111 | # --- |
127 | # --- |
112 | 128 | ||
113 | $show_verbose = false; |
129 | $show_verbose = false; |
114 | $do_recursive = false; |
130 | $do_recursive = false; |
115 | $dirs = array(); |
131 | $dirs = array(); |