Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/UpdateCheck.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ end

ConPrintf("Checking for update...")

-- Use built-in helpers to obtain absolute paths without spawning a shell.
local scriptPath = "."
local runtimePath = "."

Expand Down Expand Up @@ -214,7 +215,6 @@ for index, data in ipairs(updateFiles) do
source = source:gsub("{branch}", localBranch)
local fileName = scriptPath.."/Update/"..data.name:gsub("[\\/]","{slash}")
data.updateFileName = fileName
local content
local zipName = source:match("/([^/]+%.zip)$")
if zipName then
if not zipFiles[zipName] then
Expand All @@ -238,8 +238,20 @@ for index, data in ipairs(updateFiles) do
ConPrintf("Couldn't extract '%s' from '%s' (zip open failed)", data.name, zipName)
end
else
ConPrintf("Downloading %s... (%d of %d)", data.name, index, #updateFiles)
downloadFile(source, data.name, fileName)
local skipDownload
local file = io.open(fileName, "rb")
if file then
local content = file:read("*all")
if data.sha1 == sha1(content) or data.sha1 == sha1(content:gsub("\n", "\r\n")) then
ConPrintf("Using file from previous update attempt '%s'", fileName)
skipDownload = true
end
file:close()
end
if not skipDownload then
ConPrintf("Downloading %s... (%d of %d)", data.name, index, #updateFiles)
downloadFile(source, data.name, fileName)
end
end
local file = io.open(fileName, "rb")
if not file then
Expand Down