From 5aef075408df7dec4581e9b5a03a3fad0c298f0e Mon Sep 17 00:00:00 2001 From: Wires77 Date: Tue, 26 Mar 2024 12:00:04 -0500 Subject: [PATCH 1/4] Adding popup to specify new user path --- src/Modules/Main.lua | 65 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 12 deletions(-) diff --git a/src/Modules/Main.lua b/src/Modules/Main.lua index 5c1696023d..b34644f26c 100644 --- a/src/Modules/Main.lua +++ b/src/Modules/Main.lua @@ -50,16 +50,23 @@ function main:Init() self.modes["LIST"] = LoadModule("Modules/BuildList") self.modes["BUILD"] = LoadModule("Modules/Build") - 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().."/" + self.popups = { } + --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 + local invalidPath + self.userPath, invalidPath = GetUserPath() + if not self.userPath then + self:OpenPathPopup(invalidPath) else - self.userPath = GetUserPath().."/Path of Building/" + self.userPath = self.userPath.."/Path of Building/" MakeDir(self.userPath) + --end + self.defaultBuildPath = self.userPath.."Builds/" + self.buildPath = self.defaultBuildPath + MakeDir(self.buildPath) 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,7 +83,6 @@ function main:Init() self.inputEvents = { } - self.popups = { } self.tooltipLines = { } self.gameAccounts = { } @@ -114,7 +120,9 @@ function main:Init() if not ignoreBuild then self:SetMode("BUILD", false, "Unnamed build") end - self:LoadSettings(ignoreBuild) + if self.userPath then + self:LoadSettings(ignoreBuild) + end self.tree = { } self:LoadTree(latestTreeVersion) @@ -160,7 +168,7 @@ function main:Init() self.rareDB.loading = nil ConPrintf("Rares loaded") end - + if self.saveNewModCache then local saved = self.defaultItemAffixQuality self.defaultItemAffixQuality = 0.5 @@ -235,7 +243,9 @@ please reinstall using one of the installers from the "Releases" section of the GitHub page.]]) end - self:LoadSharedItems() + if self.userPath then + self:LoadSharedItems() + end self.onFrameFuncs = { ["FirstFrame"] = function() @@ -249,7 +259,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 +727,37 @@ function main:SaveSettings() end end +function main:OpenPathPopup(invalidPath) + 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.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 then + main:OpenMessagePopup("Error", "Couldn't create '"..controls.userPath.buf.."' : "..msg) + end + self.userPath = controls.userPath.buf + 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:OpenOptionsPopup() local controls = { } From 3dff49c1efa4727ab5ab392d0c209756381e7e2c Mon Sep 17 00:00:00 2001 From: Wires77 Date: Tue, 26 Mar 2024 19:41:32 -0500 Subject: [PATCH 2/4] Extract userPath dependent functions --- src/Modules/Main.lua | 98 ++++++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 48 deletions(-) diff --git a/src/Modules/Main.lua b/src/Modules/Main.lua index b34644f26c..992b17e2a8 100644 --- a/src/Modules/Main.lua +++ b/src/Modules/Main.lua @@ -51,21 +51,42 @@ function main:Init() self.modes["BUILD"] = LoadModule("Modules/Build") self.popups = { } - --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 - local invalidPath - self.userPath, invalidPath = GetUserPath() - if not self.userPath then - self:OpenPathPopup(invalidPath) + 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 = self.userPath.."/Path of Building/" - MakeDir(self.userPath) - --end - self.defaultBuildPath = self.userPath.."Builds/" - self.buildPath = self.defaultBuildPath - MakeDir(self.buildPath) + local invalidPath + self.userPath, invalidPath = GetUserPath() + if not self.userPath then + self:OpenPathPopup(invalidPath) + else + self.userPath = self.userPath.."/Path of Building/" + end + end + if self.userPath then + self:ChangeUserPath(self.userPath, ignoreBuild) end if launch.devMode and IsKeyDown("CTRL") then @@ -85,8 +106,6 @@ function main:Init() self.inputEvents = { } self.tooltipLines = { } - self.gameAccounts = { } - self.buildSortMode = "NAME" self.connectionProtocol = 0 self.nodePowerTheme = "RED/BLUE" @@ -102,28 +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 - if self.userPath then - self:LoadSettings(ignoreBuild) - end - self.tree = { } self:LoadTree(latestTreeVersion) @@ -177,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 @@ -243,10 +237,6 @@ please reinstall using one of the installers from the "Releases" section of the GitHub page.]]) end - if self.userPath then - self:LoadSharedItems() - end - self.onFrameFuncs = { ["FirstFrame"] = function() self.onFrameFuncs["FirstFrame"] = nil @@ -746,10 +736,12 @@ function main:OpenPathPopup(invalidPath) 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 then - main:OpenMessagePopup("Error", "Couldn't create '"..controls.userPath.buf.."' : "..msg) + if not res and msg ~= "No error" then + self:OpenMessagePopup("Error", "Couldn't create '"..controls.userPath.buf.."' : "..msg) + else + self:ChangeUserPath(controls.userPath.buf) + self:ClosePopup() end - self.userPath = controls.userPath.buf end) controls.save.enabled = false controls.cancel = new("ButtonControl", nil, 0, 0, 0, 0, "Cancel", function() @@ -758,6 +750,16 @@ function main:OpenPathPopup(invalidPath) 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 = { } From 0f22b5ff9f2ab91487af7adc03ea0fc7850df219 Mon Sep 17 00:00:00 2001 From: Wires77 Date: Tue, 26 Mar 2024 20:27:02 -0500 Subject: [PATCH 3/4] Add FAQ link, fix a few bugs --- src/Modules/Main.lua | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Modules/Main.lua b/src/Modules/Main.lua index 992b17e2a8..211e8467e5 100644 --- a/src/Modules/Main.lua +++ b/src/Modules/Main.lua @@ -73,18 +73,18 @@ function main:Init() 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 + --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 local invalidPath self.userPath, invalidPath = GetUserPath() if not self.userPath then - self:OpenPathPopup(invalidPath) + self:OpenPathPopup(invalidPath, ignoreBuild) else self.userPath = self.userPath.."/Path of Building/" end - end + --end if self.userPath then self:ChangeUserPath(self.userPath, ignoreBuild) end @@ -717,7 +717,7 @@ function main:SaveSettings() end end -function main:OpenPathPopup(invalidPath) +function main:OpenPathPopup(invalidPath, ignoreBuild) local controls = { } local defaultLabelPlacementX = 8 @@ -726,6 +726,9 @@ function main:OpenPathPopup(invalidPath) "\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 @@ -739,7 +742,7 @@ function main:OpenPathPopup(invalidPath) if not res and msg ~= "No error" then self:OpenMessagePopup("Error", "Couldn't create '"..controls.userPath.buf.."' : "..msg) else - self:ChangeUserPath(controls.userPath.buf) + self:ChangeUserPath(controls.userPath.buf, ignoreBuild) self:ClosePopup() end end) From b8abea732a01f659df591479144dd67dc6203402 Mon Sep 17 00:00:00 2001 From: Wires77 Date: Tue, 26 Mar 2024 20:28:48 -0500 Subject: [PATCH 4/4] Forgot to uncomment devMode lines --- src/Modules/Main.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Modules/Main.lua b/src/Modules/Main.lua index 211e8467e5..39385efabc 100644 --- a/src/Modules/Main.lua +++ b/src/Modules/Main.lua @@ -73,10 +73,10 @@ function main:Init() 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 + 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 local invalidPath self.userPath, invalidPath = GetUserPath() if not self.userPath then @@ -84,7 +84,7 @@ function main:Init() else self.userPath = self.userPath.."/Path of Building/" end - --end + end if self.userPath then self:ChangeUserPath(self.userPath, ignoreBuild) end