Skip to content

Resume failed update feature #8469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
26 changes: 21 additions & 5 deletions src/UpdateCheck.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,13 @@ end

ConPrintf("Checking for update...")

local scriptPath = "."
local runtimePath = "."
local scriptPath
local runtimePath
do
local currentDir = io.popen("cd"):read() or io.popen("pwd"):read() or "."
scriptPath = currentDir
runtimePath = currentDir
end

-- Load and process local manifest
local localVer
Expand Down Expand Up @@ -214,7 +219,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 +242,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