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
2 changes: 1 addition & 1 deletion runtime/lua/xml.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function xml.LoadXMLFile(fileName)
local fileText = fileHnd:read("*a")
fileHnd:close()
if not fileText then
return nil, fileName.." file returns nil. OneDrive?"
return nil, fileName.." file returns nil"
elseif fileText == "" then
return nil, fileName.." file is empty"
end
Expand Down
9 changes: 8 additions & 1 deletion src/HeadlessWrapper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function PCall(func, ...)
return nil, unpack(ret)
else
return ret[2]
end
end
end
function ConPrintf(fmt, ...)
-- Optional
Expand All @@ -157,6 +157,13 @@ function SetProfiling(isEnabled) end
function Restart() end
function Exit() end

---@return string? provider
---@return string? version
---@return number? status
function GetCloudProvider(fullPath)
return nil, nil, nil
end

local l_require = require
function require(name)
-- Hack to stop it looking for lcurl, which we don't really need
Expand Down
8 changes: 4 additions & 4 deletions src/Modules/Build.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2157,11 +2157,11 @@ end
function buildMode:LoadDB(xmlText, fileName)
-- Parse the XML
local dbXML, errMsg = common.xml.ParseXML(xmlText)
if not dbXML then
launch:ShowErrMsg("^1Error loading '%s': %s", fileName, errMsg)
if errMsg and errMsg:match(".*file returns nil") then
main:OpenCloudErrorPopup(fileName)
return true
elseif #dbXML == 0 then
main:OpenMessagePopup("Error", "Build file is empty, or error parsing xml.\n\n"..fileName)
elseif errMsg then
launch:ShowErrMsg("^1"..errMsg)
return true
elseif dbXML[1].elem ~= "PathOfBuilding2" then
launch:ShowErrMsg("^1Error parsing '%s': 'PathOfBuilding2' root element missing", fileName)
Expand Down
4 changes: 4 additions & 0 deletions src/Modules/BuildList.lua
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ function listMode:BuildList()
if fileHnd then
local fileText = fileHnd:read("*a")
fileHnd:close()
if not fileText then
main:OpenCloudErrorPopup(build.fullFileName)
return
end
fileText = fileText:match("(<Build.->)")
if fileText then
local xml = common.xml.ParseXML(fileText.."</Build>")
Expand Down
55 changes: 51 additions & 4 deletions src/Modules/Main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ function main:Init()
self.POESESSID = ""
--self.showPublicBuilds = true
self.showFlavourText = true
self.errorReadingSettings = false

if self.userPath then
self:ChangeUserPath(self.userPath, ignoreBuild)
Expand Down Expand Up @@ -506,9 +507,16 @@ function main:CallMode(func, ...)
end

function main:LoadSettings(ignoreBuild)
if self.errorReadingSettings then
return true
end
local setXML, errMsg = common.xml.LoadXMLFile(self.userPath.."Settings.xml")
if errMsg and not errMsg:match(".*No such file or directory") then
ConPrintf("Error: '%s'", errMsg)
if errMsg and errMsg:match(".*file returns nil") then
self.errorReadingSettings = true
self:OpenCloudErrorPopup(self.userPath.."Settings.xml")
return true
elseif errMsg and not errMsg:match(".*No such file or directory") then
self.errorReadingSettings = true
launch:ShowErrMsg("^1"..errMsg)
return true
end
Expand Down Expand Up @@ -649,9 +657,16 @@ function main:LoadSettings(ignoreBuild)
end

function main:LoadSharedItems()
if self.errorReadingSettings then
return true
end
local setXML, errMsg = common.xml.LoadXMLFile(self.userPath.."Settings.xml")
if errMsg and not errMsg:match(".*No such file or directory") then
ConPrintf("Error: '%s'", errMsg)
if errMsg and errMsg:match(".*file returns nil") then
self.errorReadingSettings = true
self:OpenCloudErrorPopup(self.userPath.."Settings.xml")
return true
elseif errMsg and not errMsg:match(".*No such file or directory") then
self.errorReadingSettings = true
launch:ShowErrMsg("^1"..errMsg)
return true
end
Expand Down Expand Up @@ -697,6 +712,9 @@ function main:LoadSharedItems()
end

function main:SaveSettings()
if self.errorReadingSettings then
return
end
local setXML = { elem = "PathOfBuilding2" }
local mode = { elem = "Mode", attrib = { mode = self.mode } }
for _, val in ipairs({ self:CallMode("GetArgs") }) do
Expand Down Expand Up @@ -1546,6 +1564,35 @@ function main:OpenNewFolderPopup(path, onClose)
main:OpenPopup(370, 100, "New Folder", controls, "create", "edit", "cancel")
end

-- Show an error popup if a file cannot be read due to cloud provider unavailability.
-- Help button opens a URL to PoB's GitHub wiki.
function main:OpenCloudErrorPopup(fileName)
local provider, _, status = GetCloudProvider(fileName)
ConPrintf('^1Error: file offline "%s" provider: "%s" status: "%s"', fileName or "?", provider, status)
fileName = fileName and "\n\n^8'"..fileName.."'" or ""
local version = "^8v"..launch.versionNumber..(launch.versionBranch and " "..launch.versionBranch or "")..(launch.devMode and " (dev)" or "")
local title = " ^1Error "
provider = provider or "your cloud provider"
local statusText = tostring(status) or "nil"
local msg = "\n^7Cannot read file.\n\nMake sure "..provider.." is running then restart "..APP_NAME.." and try again."..
fileName.."\nstatus: "..statusText.."\n\n"..version
local url = "https://github.com/PathOfBuildingCommunity/PathOfBuilding/wiki/CloudError"
local controls = { }
local numMsgLines = 0
for line in string.gmatch(msg .. "\n", "([^\n]*)\n") do
t_insert(controls, new("LabelControl", nil, {0, 20 + numMsgLines * 16, 0, 16}, line))
numMsgLines = numMsgLines + 1
end
controls.help = new("ButtonControl", nil, {-55, 40 + numMsgLines * 16, 80, 20}, "Help (web)", function()
OpenURL(url)
end)
controls.help.tooltipText = url
controls.close = new("ButtonControl", nil, {55, 40 + numMsgLines * 16, 80, 20}, "Ok", function()
main:ClosePopup()
end)
return self:OpenPopup(m_max(DrawStringWidth(16, "VAR", msg) + 30, 190), 70 + numMsgLines * 16, title, controls, "close")
end

function main:SetWindowTitleSubtext(subtext)
if not subtext or not self.showTitlebarName then
SetWindowTitle(APP_NAME)
Expand Down