From f4ae364059b06c62166f6dae4431856c130d88c0 Mon Sep 17 00:00:00 2001 From: Wires77 Date: Wed, 27 Mar 2024 00:12:45 -0500 Subject: [PATCH] Add popup to specify new user path if default one fails (#7476) * Adding popup to specify new user path * Extract userPath dependent functions * Add FAQ link, fix a few bugs * Forgot to uncomment devMode lines --- src/Modules/Main.lua | 116 ++++++++++++++++++++++++++++++------------- 1 file changed, 81 insertions(+), 35 deletions(-) diff --git a/src/Modules/Main.lua b/src/Modules/Main.lua index 5c1696023d..39385efabc 100644 --- a/src/Modules/Main.lua +++ b/src/Modules/Main.lua @@ -50,16 +50,44 @@ function main:Init() self.modes["LIST"] = LoadModule("Modules/BuildList") self.modes["BUILD"] = LoadModule("Modules/Build") + self.popups = { } + self.sharedItemList = { } + self.sharedItemSetList = { } + self.gameAccounts = { } + + local ignoreBuild + if arg[1] then + buildSites.DownloadBuild(arg[1], nil, function(isSuccess, data) + if not isSuccess then + self:SetMode("BUILD", false, data) + else + local xmlText = Inflate(common.base64.decode(data:gsub("-","+"):gsub("_","/"))) + self:SetMode("BUILD", false, "Imported Build", xmlText) + self.newModeChangeToTree = true + end + end) + arg[1] = nil -- Protect against downloading again this session. + ignoreBuild = true + end + + if not ignoreBuild then + self:SetMode("BUILD", false, "Unnamed build") + end if launch.devMode or (GetScriptPath() == GetRuntimePath() and not launch.installedMode) then -- If running in dev mode or standalone mode, put user data in the script path self.userPath = GetScriptPath().."/" else - self.userPath = GetUserPath().."/Path of Building/" - MakeDir(self.userPath) + local invalidPath + self.userPath, invalidPath = GetUserPath() + if not self.userPath then + self:OpenPathPopup(invalidPath, ignoreBuild) + else + self.userPath = self.userPath.."/Path of Building/" + end + end + if self.userPath then + self:ChangeUserPath(self.userPath, ignoreBuild) end - self.defaultBuildPath = self.userPath.."Builds/" - self.buildPath = self.defaultBuildPath - MakeDir(self.buildPath) if launch.devMode and IsKeyDown("CTRL") then -- If modLib.parseMod doesn't find a cache entry it generates it. @@ -76,11 +104,8 @@ function main:Init() self.inputEvents = { } - self.popups = { } self.tooltipLines = { } - self.gameAccounts = { } - self.buildSortMode = "NAME" self.connectionProtocol = 0 self.nodePowerTheme = "RED/BLUE" @@ -96,26 +121,6 @@ function main:Init() self.slotOnlyTooltips = true self.POESESSID = "" - local ignoreBuild - if arg[1] then - buildSites.DownloadBuild(arg[1], nil, function(isSuccess, data) - if not isSuccess then - self:SetMode("BUILD", false, data) - else - local xmlText = Inflate(common.base64.decode(data:gsub("-","+"):gsub("_","/"))) - self:SetMode("BUILD", false, "Imported Build", xmlText) - self.newModeChangeToTree = true - end - end) - arg[1] = nil -- Protect against downloading again this session. - ignoreBuild = true - end - - if not ignoreBuild then - self:SetMode("BUILD", false, "Unnamed build") - end - self:LoadSettings(ignoreBuild) - self.tree = { } self:LoadTree(latestTreeVersion) @@ -160,7 +165,7 @@ function main:Init() self.rareDB.loading = nil ConPrintf("Rares loaded") end - + if self.saveNewModCache then local saved = self.defaultItemAffixQuality self.defaultItemAffixQuality = 0.5 @@ -169,9 +174,6 @@ function main:Init() self.defaultItemAffixQuality = saved end - self.sharedItemList = { } - self.sharedItemSetList = { } - self.anchorMain = new("Control", nil, 4, 0, 0, 0) self.anchorMain.y = function() return self.screenH - 4 @@ -235,8 +237,6 @@ please reinstall using one of the installers from the "Releases" section of the GitHub page.]]) end - self:LoadSharedItems() - self.onFrameFuncs = { ["FirstFrame"] = function() self.onFrameFuncs["FirstFrame"] = nil @@ -249,7 +249,7 @@ the "Releases" section of the GitHub page.]]) if not self.saveNewModCache then local itemsCoroutine = coroutine.create(loadItemDBs) - + self.onFrameFuncs["LoadItems"] = function() local res, errMsg = coroutine.resume(itemsCoroutine) if coroutine.status(itemsCoroutine) == "dead" then @@ -717,6 +717,52 @@ function main:SaveSettings() end end +function main:OpenPathPopup(invalidPath, ignoreBuild) + local controls = { } + local defaultLabelPlacementX = 8 + + controls.label = new("LabelControl", { "TOPLEFT", nil, "TOPLEFT" }, defaultLabelPlacementX, 20, 206, 16, function() + return "^7User settings path contains unicode characters and cannot be loaded.".. + "\nCurrent Path: "..invalidPath:gsub("?", "^1?^7").."/Path of Building/".. + "\nSpecify a new location for your Settings.xml:" + end) + controls.explainButton = new("ButtonControl", { "LEFT", controls.label, "RIGHT" }, 4, 0, 20, 20, "?", function() + OpenURL("https://github.com/PathOfBuildingCommunity/PathOfBuilding/wiki/Why-do-I-have-to-change-my-Settings-path%3F") + end) + controls.userPath = new("EditControl", { "TOPLEFT", controls.label, "TOPLEFT" }, 0, 60, 206, 20, invalidPath, nil, nil, nil, function(buf) + invalidPath = sanitiseText(buf) + if not invalidPath:match("?") then + controls.save.enabled = true + else + controls.save.enabled = false + end + end) + controls.save = new("ButtonControl", { "TOPLEFT", controls.userPath, "TOPLEFT" }, 0, 26, 206, 20, "Save", function() + local res, msg = MakeDir(controls.userPath.buf) + if not res and msg ~= "No error" then + self:OpenMessagePopup("Error", "Couldn't create '"..controls.userPath.buf.."' : "..msg) + else + self:ChangeUserPath(controls.userPath.buf, ignoreBuild) + self:ClosePopup() + end + end) + controls.save.enabled = false + controls.cancel = new("ButtonControl", nil, 0, 0, 0, 0, "Cancel", function() + -- Do nothing, require user to enter a location + end) + self:OpenPopup(600, 150, "Change Settings Path", controls, "save", nil, "cancel") +end + +function main:ChangeUserPath(newUserPath, ignoreBuild) + self.userPath = newUserPath + MakeDir(self.userPath) + self.defaultBuildPath = self.userPath.."Builds/" + self.buildPath = self.defaultBuildPath + MakeDir(self.buildPath) + self:LoadSettings(ignoreBuild) + self:LoadSharedItems() +end + function main:OpenOptionsPopup() local controls = { }