|
1 |
| -[[ ---------- Usage ---------- |
| 1 | +[[---------- Usage ---------- |
2 | 2 |
|
3 | 3 | 1. Create a DownloadManager:
|
4 | 4 |
|
@@ -67,11 +67,11 @@ void Sleep(unsigned long);
|
67 | 67 | sleep = ffi.os == "Windows" and (( ms = 100 ) -> ffi.C.Sleep ms) or (( ms = 100 ) -> ffi.C.usleep ms*1000)
|
68 | 68 |
|
69 | 69 | class DownloadManager
|
70 |
| - @version = 0x000103 |
71 |
| - @version_string = "0.1.3" |
| 70 | + @version = 0x000104 |
| 71 | + @version_string = "0.1.4" |
72 | 72 |
|
73 | 73 | DM = nil
|
74 |
| - DMVersion = 0x000101 |
| 74 | + DMVersion = 0x000102 |
75 | 75 | pathExt = "/automation/include/#{@__name}/#{(ffi.os != 'Windows') and 'lib' or ''}#{@__name}.#{(OSX: 'dylib', Windows: 'dll')[ffi.os] or 'so'}"
|
76 | 76 | defaultLibraryPaths = aegisub and {aegisub.decode_path("?user"..pathExt), aegisub.decode_path("?data"..pathExt)} or {@__name}
|
77 | 77 | msgs = {
|
@@ -137,6 +137,10 @@ class DownloadManager
|
137 | 137 | -- lfs.mkdir returns nil on success and error alike
|
138 | 138 | return nil, err if err
|
139 | 139 |
|
| 140 | + -- make sure sha1 is lowercase for comparison. |
| 141 | + if sha1 |
| 142 | + sha1 = sha1\lower! |
| 143 | + |
140 | 144 | DM.addDownload @manager, url, outfile, sha1
|
141 | 145 | @downloadCount += 1
|
142 | 146 | @downloads[@downloadCount] = id:@downloadCount, :url, :outfile, :sha1
|
@@ -182,17 +186,17 @@ class DownloadManager
|
182 | 186 | -- just make them instance methods than trying to juggle the DM init.
|
183 | 187 | -- Also make them fat arrow functions for calling consistency.
|
184 | 188 | checkFileSHA1: ( filename, expected ) =>
|
185 |
| - switch DM.checkFileSHA1 filename, expected |
186 |
| - when -1 |
187 |
| - return nil |
188 |
| - when 0 |
189 |
| - return true |
190 |
| - when 1 |
191 |
| - return false |
| 189 | + result = DM.getFileSHA1 filename |
| 190 | + if nil == result |
| 191 | + return nil, "Could not open file #{filename}." |
| 192 | + if result == expected\lower! |
| 193 | + return true |
| 194 | + else |
| 195 | + return false, "Hash mismatch. Got #{result}, expected #{expected}." |
192 | 196 |
|
193 | 197 | checkStringSHA1: ( string, expected ) =>
|
194 |
| - switch DM.checkStringSHA1 filename, expected |
195 |
| - when 0 |
196 |
| - return true |
197 |
| - when 1 |
198 |
| - return false |
| 198 | + result = DM.getStringSHA1 string |
| 199 | + if result == expected\lower! |
| 200 | + return true |
| 201 | + else |
| 202 | + return false, "Hash mismatch. Got #{result}, expected #{expected}." |
0 commit comments