Skip to content
Merged
Show file tree
Hide file tree
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
Binary file removed src/Data/TimelessJewelData/GloriousVanity.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
44 changes: 33 additions & 11 deletions src/Modules/Data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ LoadModule("Data/Global")

local m_min = math.min
local m_max = math.max
local t_concat = table.concat

local skillTypes = {
"act_str",
Expand Down Expand Up @@ -479,46 +480,67 @@ end
-- Load legion jewel data

local function loadJewelFile(jewelTypeName)
jewelTypeName = "Data/TimelessJewelData/" .. jewelTypeName
jewelTypeName = "/Data/TimelessJewelData/" .. jewelTypeName
local jewelData

local fileHandle = NewFileSearch(main.userPath .. jewelTypeName .. ".bin")
local scriptPath = GetScriptPath()

local fileHandle = NewFileSearch(scriptPath .. jewelTypeName .. ".bin")
local uncompressedFileAttr = { }
if fileHandle then
uncompressedFileAttr.fileName = fileHandle:GetFileName()
uncompressedFileAttr.modified = fileHandle:GetFileModifiedTime()
end
fileHandle = NewFileSearch(main.userPath .. jewelTypeName .. ".zip")

fileHandle = NewFileSearch(scriptPath .. jewelTypeName .. ".zip")
local compressedFileAttr = { }
if fileHandle then
compressedFileAttr.fileName = fileHandle:GetFileName()
compressedFileAttr.modified = fileHandle:GetFileModifiedTime()
end

if uncompressedFileAttr.modified and uncompressedFileAttr.modified > compressedFileAttr.modified then
fileHandle = NewFileSearch(scriptPath .. jewelTypeName .. ".zip.part*")
local splitFile = { }
if fileHandle then
compressedFileAttr.modified = fileHandle:GetFileModifiedTime()
end
while fileHandle do
local fileName = fileHandle:GetFileName()
local file = io.open(scriptPath .. "/Data/TimelessJewelData/" .. fileName, "rb")
local part = tonumber(fileName:match("%.part(%d)")) or 0
splitFile[part + 1] = file:read("*a")
file:close()
if not fileHandle:NextFile() then
break
end
end
splitFile = t_concat(splitFile, "")

if uncompressedFileAttr.modified and uncompressedFileAttr.modified > (compressedFileAttr.modified or 0) then
ConPrintf("Uncompressed jewel data is up-to-date, loading " .. uncompressedFileAttr.fileName)
local uncompressedFile = io.open(jewelTypeName .. ".bin", "rb")
local uncompressedFile = io.open(scriptPath .. jewelTypeName .. ".bin", "rb")
if uncompressedFile then
jewelData = uncompressedFile:read("*all")
jewelData = uncompressedFile:read("*a")
uncompressedFile.close()
end
if jewelData then
return jewelData
end
end

ConPrintf("Failed to load " .. main.userPath .. jewelTypeName .. ".bin, or data is out of date, falling back to compressed file")
local compressedFile = io.open(jewelTypeName .. ".zip", "rb")
ConPrintf("Failed to load " .. scriptPath .. jewelTypeName .. ".bin, or data is out of date, falling back to compressed file")
local compressedFile = io.open(scriptPath .. jewelTypeName .. ".zip", "rb")
if compressedFile then
-- load the binary jewel data file
jewelData = Inflate(compressedFile:read("*all"))
jewelData = Inflate(compressedFile:read("*a"))
compressedFile:close()
elseif splitFile ~= "" then
jewelData = Inflate(splitFile)
end

if jewelData == nil then
ConPrintf("Failed to load either file: " .. jewelTypeName .. ".zip, " .. jewelTypeName .. ".bin")
else
local uncompressedFile = io.open(jewelTypeName .. ".bin", "wb+")
local uncompressedFile = io.open(scriptPath .. jewelTypeName .. ".bin", "wb+")
uncompressedFile:write(jewelData)
uncompressedFile:close()
end
Expand Down
60 changes: 41 additions & 19 deletions src/UpdateCheck.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,35 @@ local function downloadFileText(source, file)
end
end
local function downloadFile(source, file, outName)
local text = downloadFileText(source, file)
if text then
local outFile = io.open(outName, "wb")
outFile:write(text)
outFile:close()
else
return true
for i = 1, 5 do
if i > 1 then
ConPrintf("Retrying... (%d of 5)", i)
end
local easy = curl.easy()
local escapedUrl = source..easy:escape(file)
easy:setopt_url(escapedUrl)
easy:setopt(curl.OPT_ACCEPT_ENCODING, "")
if connectionProtocol then
easy:setopt(curl.OPT_IPRESOLVE, connectionProtocol)
end
if proxyURL then
easy:setopt(curl.OPT_PROXY, proxyURL)
end
local file = io.open(outName, "wb+")
easy:setopt_writefunction(file)
local _, error = easy:perform()
easy:close()
file:close()
if not error then
return true
end
ConPrintf("Download failed (%s)", error:msg())
if globalRetryLimit == 0 or i == 5 then
return nil, error:msg()
end
globalRetryLimit = globalRetryLimit - 1
end
return true
end

ConPrintf("Checking for update...")
Expand Down Expand Up @@ -154,7 +175,7 @@ for name, data in pairs(remoteFiles) do
else
local content = file:read("*a")
file:close()
if data.sha1 ~= sha1(content) and data.sha1 ~= sha1(content:gsub("\n","\r\n")) then
if data.sha1 ~= sha1(content) and data.sha1 ~= sha1(content:gsub("\n", "\r\n")) then
ConPrintf("Warning: Integrity check on '%s' failed, it will be replaced", data.name)
table.insert(updateFiles, data)
end
Expand Down Expand Up @@ -206,7 +227,9 @@ for index, data in ipairs(updateFiles) do
if zip then
local zippedFile = zip:OpenFile(data.name)
if zippedFile then
content = zippedFile:Read("*a")
local file = io.open(fileName, "wb+")
file:write(zippedFile:Read("*a"))
file:close()
zippedFile:Close()
else
ConPrintf("Couldn't extract '%s' from '%s' (extract failed)", data.name, zipName)
Expand All @@ -216,19 +239,18 @@ for index, data in ipairs(updateFiles) do
end
else
ConPrintf("Downloading %s... (%d of %d)", data.name, index, #updateFiles)
content = downloadFileText(source, data.name)
downloadFile(source, data.name, fileName)
end
if content then
if data.sha1 ~= sha1(content) and data.sha1 ~= sha1(content:gsub("\n","\r\n")) then
ConPrintf("Hash mismatch on '%s'", data.name)
local file = io.open(fileName, "rb")
if not file then
failedFile = true
else
local content = file:read("*all")
if data.sha1 ~= sha1(content) and data.sha1 ~= sha1(content:gsub("\n", "\r\n")) then
ConPrintf("Hash mismatch on '%s'", fileName)
failedFile = true
else
local file = io.open(fileName, "w+b")
file:write(content)
file:close()
end
else
failedFile = true
file:close()
end
end
for name, zip in pairs(zipFiles) do
Expand Down