Skip to content

Commit 776d985

Browse files
authored
Add file offline error popup (cloud error) (#9188)
1 parent 8836b1d commit 776d985

File tree

5 files changed

+70
-11
lines changed

5 files changed

+70
-11
lines changed

runtime/lua/xml.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function xml.LoadXMLFile(fileName)
102102
local fileText = fileHnd:read("*a")
103103
fileHnd:close()
104104
if not fileText then
105-
return nil, fileName.." file returns nil. OneDrive?"
105+
return nil, fileName.." file returns nil"
106106
elseif fileText == "" then
107107
return nil, fileName.." file is empty"
108108
end

src/HeadlessWrapper.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ function PCall(func, ...)
146146
return nil, unpack(ret)
147147
else
148148
return ret[2]
149-
end
149+
end
150150
end
151151
function ConPrintf(fmt, ...)
152152
-- Optional
@@ -162,6 +162,14 @@ function Restart() end
162162
function Exit() end
163163
function TakeScreenshot() end
164164

165+
---@return string? provider
166+
---@return string? version
167+
---@return number? status
168+
function GetCloudProvider(fullPath)
169+
return nil, nil, nil
170+
end
171+
172+
165173
local l_require = require
166174
function require(name)
167175
-- Hack to stop it looking for lcurl, which we don't really need

src/Modules/Build.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,7 +1814,7 @@ do
18141814
if int and (int > 14 or int > self.calcsTab.mainOutput.Int) then
18151815
t_insert(req, s_format("%s%d ^x7F7F7FInt", main:StatColor(int, intBase, self.calcsTab.mainOutput.Int), int))
18161816
end
1817-
end
1817+
end
18181818
if req[1] then
18191819
local fontSizeBig = main.showFlavourText and 18 or 16
18201820
tooltip:AddLine(fontSizeBig, "^x7F7F7FRequires "..table.concat(req, "^x7F7F7F, "), "FONTIN SC")
@@ -1827,11 +1827,11 @@ end
18271827
function buildMode:LoadDB(xmlText, fileName)
18281828
-- Parse the XML
18291829
local dbXML, errMsg = common.xml.ParseXML(xmlText)
1830-
if not dbXML then
1831-
launch:ShowErrMsg("^1Error loading '%s': %s", fileName, errMsg)
1830+
if errMsg and errMsg:match(".*file returns nil") then
1831+
main:OpenCloudErrorPopup(fileName)
18321832
return true
1833-
elseif #dbXML == 0 then
1834-
main:OpenMessagePopup("Error", "Build file is empty, or error parsing xml.\n\n"..fileName)
1833+
elseif errMsg then
1834+
launch:ShowErrMsg("^1"..errMsg)
18351835
return true
18361836
elseif dbXML[1].elem ~= "PathOfBuilding" then
18371837
launch:ShowErrMsg("^1Error parsing '%s': 'PathOfBuilding' root element missing", fileName)

src/Modules/BuildList.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ function listMode:BuildList()
216216
if fileHnd then
217217
local fileText = fileHnd:read("*a")
218218
fileHnd:close()
219+
if not fileText then
220+
main:OpenCloudErrorPopup(build.fullFileName)
221+
return
222+
end
219223
fileText = fileText:match("(<Build.->)")
220224
if fileText then
221225
local xml = common.xml.ParseXML(fileText.."</Build>")

src/Modules/Main.lua

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ function main:Init()
112112
self.POESESSID = ""
113113
self.showPublicBuilds = true
114114
self.showFlavourText = true
115+
self.errorReadingSettings = false
115116

116117
if not SetDPIScaleOverridePercent then SetDPIScaleOverridePercent = function(scale) end end
117118

@@ -515,9 +516,16 @@ function main:CallMode(func, ...)
515516
end
516517

517518
function main:LoadSettings(ignoreBuild)
519+
if self.errorReadingSettings then
520+
return true
521+
end
518522
local setXML, errMsg = common.xml.LoadXMLFile(self.userPath.."Settings.xml")
519-
if errMsg and not errMsg:match(".*No such file or directory") then
520-
ConPrintf("Error: '%s'", errMsg)
523+
if errMsg and errMsg:match(".*file returns nil") then
524+
self.errorReadingSettings = true
525+
self:OpenCloudErrorPopup(self.userPath.."Settings.xml")
526+
return true
527+
elseif errMsg and not errMsg:match(".*No such file or directory") then
528+
self.errorReadingSettings = true
521529
launch:ShowErrMsg("^1"..errMsg)
522530
return true
523531
end
@@ -655,9 +663,16 @@ function main:LoadSettings(ignoreBuild)
655663
end
656664

657665
function main:LoadSharedItems()
666+
if self.errorReadingSettings then
667+
return true
668+
end
658669
local setXML, errMsg = common.xml.LoadXMLFile(self.userPath.."Settings.xml")
659-
if errMsg and not errMsg:match(".*No such file or directory") then
660-
ConPrintf("Error: '%s'", errMsg)
670+
if errMsg and errMsg:match(".*file returns nil") then
671+
self.errorReadingSettings = true
672+
self:OpenCloudErrorPopup(self.userPath.."Settings.xml")
673+
return true
674+
elseif errMsg and not errMsg:match(".*No such file or directory") then
675+
self.errorReadingSettings = true
661676
launch:ShowErrMsg("^1"..errMsg)
662677
return true
663678
end
@@ -703,6 +718,9 @@ function main:LoadSharedItems()
703718
end
704719

705720
function main:SaveSettings()
721+
if self.errorReadingSettings then
722+
return
723+
end
706724
local setXML = { elem = "PathOfBuilding" }
707725
local mode = { elem = "Mode", attrib = { mode = self.mode } }
708726
for _, val in ipairs({ self:CallMode("GetArgs") }) do
@@ -1553,6 +1571,35 @@ function main:OpenNewFolderPopup(path, onClose)
15531571
main:OpenPopup(370, 100, "New Folder", controls, "create", "edit", "cancel")
15541572
end
15551573

1574+
-- Show an error popup if a file cannot be read due to cloud provider unavailability.
1575+
-- Help button opens a URL to PoB's GitHub wiki.
1576+
function main:OpenCloudErrorPopup(fileName)
1577+
local provider, _, status = GetCloudProvider(fileName)
1578+
ConPrintf('Error: file offline "%s" provider: "%s" status: "%s"',
1579+
fileName or "?", provider, status)
1580+
fileName = fileName and "\n\n^8'"..fileName.."'" or ""
1581+
local pobVersion = "^8v"..launch.versionNumber..(launch.versionBranch == "dev" and " (Dev)" or launch.versionBranch == "beta" and " (Beta)" or "")
1582+
local title = " Error "
1583+
provider = provider or "your cloud provider"
1584+
local msg = "\nCannot read file.\n\nMake sure "..provider.." is running then restart "..APP_NAME.." and try again."..
1585+
fileName.."\n\n"..pobVersion
1586+
local url = "https://github.com/PathOfBuildingCommunity/PathOfBuilding/wiki/CloudError"
1587+
local controls = { }
1588+
local numMsgLines = 0
1589+
for line in string.gmatch(msg .. "\n", "([^\n]*)\n") do
1590+
t_insert(controls, new("LabelControl", nil, {0, 20 + numMsgLines * 16, 0, 16}, line))
1591+
numMsgLines = numMsgLines + 1
1592+
end
1593+
controls.help = new("ButtonControl", nil, {-55, 40 + numMsgLines * 16, 80, 20}, "Help (web)", function()
1594+
OpenURL(url)
1595+
end)
1596+
controls.help.tooltipText = url
1597+
controls.close = new("ButtonControl", nil, {55, 40 + numMsgLines * 16, 80, 20}, "Ok", function()
1598+
main:ClosePopup()
1599+
end)
1600+
return self:OpenPopup(m_max(DrawStringWidth(16, "VAR", msg) + 30, 190), 70 + numMsgLines * 16, title, controls, "close")
1601+
end
1602+
15561603
function main:SetWindowTitleSubtext(subtext)
15571604
if not subtext or not self.showTitlebarName then
15581605
SetWindowTitle(APP_NAME)

0 commit comments

Comments
 (0)