Skip to content

Commit eac9208

Browse files
Wires77ccitro
andauthored
Resume failed update feature (#1226)
* [PATCH 1/2] Resume failed download * [PATCH 2/2] Get proper local directory * [PATCH 1/2] Fix flashing command prompt during update check -use GetScriptPath and GetRuntimePath to assign vas in UpdateCheck.lua -fixes flashing command prompt caused by io.popen -fall back to "." if unable to determine paths * [PATCH 2/2] Define scriptPath and runtimePath as local -preserves original definition, prevents global namespace pollution * Use local script path --------- Co-authored-by: Craig Citro <craig@citro.net>
1 parent cbec0e2 commit eac9208

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

src/UpdateCheck.lua

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ end
7878

7979
ConPrintf("Checking for update...")
8080

81+
-- Use built-in helpers to obtain absolute paths without spawning a shell.
8182
local scriptPath = "."
8283
local runtimePath = "."
8384

@@ -214,7 +215,6 @@ for index, data in ipairs(updateFiles) do
214215
source = source:gsub("{branch}", localBranch)
215216
local fileName = scriptPath.."/Update/"..data.name:gsub("[\\/]","{slash}")
216217
data.updateFileName = fileName
217-
local content
218218
local zipName = source:match("/([^/]+%.zip)$")
219219
if zipName then
220220
if not zipFiles[zipName] then
@@ -238,8 +238,20 @@ for index, data in ipairs(updateFiles) do
238238
ConPrintf("Couldn't extract '%s' from '%s' (zip open failed)", data.name, zipName)
239239
end
240240
else
241-
ConPrintf("Downloading %s... (%d of %d)", data.name, index, #updateFiles)
242-
downloadFile(source, data.name, fileName)
241+
local skipDownload
242+
local file = io.open(fileName, "rb")
243+
if file then
244+
local content = file:read("*all")
245+
if data.sha1 == sha1(content) or data.sha1 == sha1(content:gsub("\n", "\r\n")) then
246+
ConPrintf("Using file from previous update attempt '%s'", fileName)
247+
skipDownload = true
248+
end
249+
file:close()
250+
end
251+
if not skipDownload then
252+
ConPrintf("Downloading %s... (%d of %d)", data.name, index, #updateFiles)
253+
downloadFile(source, data.name, fileName)
254+
end
243255
end
244256
local file = io.open(fileName, "rb")
245257
if not file then

0 commit comments

Comments
 (0)