Skip to content
Merged
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
116 changes: 81 additions & 35 deletions src/Modules/Main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 = { }

Expand Down