Skip to content

Commit c86bb98

Browse files
QuickStick123Wires77
authored andcommitted
handle corrupted saves and re export on datSource creation (#88)
1 parent ac666b5 commit c86bb98

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/Export/Classes/GGPKSourceListControl.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function GGPKSourceListClass:EditDATSource(datSource, newSource)
4343
controls.save.enabled = (controls.dat.buf:match("%S") or controls.ggpk.buf:match("%S")) and controls.label.buf:match("%S") and buf:match("%S")
4444
end)
4545
controls.save = new("ButtonControl", {"TOP",controls.spec,"TOP"}, {-45, 22, 80, 20}, "Save", function()
46-
local reload = datSource.label == main.datSource.label
46+
local reload = datSource.label == (main.datSource and main.datSource.label)
4747
datSource.label = controls.label.buf
4848
datSource.ggpkPath = controls.ggpk.buf or ""
4949
datSource.datFilePath = controls.dat.buf or ""

src/Export/Main.lua

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,13 @@ end
334334

335335
function main:LoadDatSource(value)
336336
self.leagueLabel = nil
337+
local reExportState = self.reExportGGPKData
338+
self.reExportGGPKData = true
339+
self.datSource = value
337340
local out = io.open(self.datSource.spec..(self.datSource.spec:match("%.lua$") and "" or ".lua"), "w")
338341
out:write('return ')
339342
writeLuaTable(out, self.datSpecs, 1)
340343
out:close()
341-
self.datSource = value
342344
self.datSpecs = LoadModule(self.datSource.spec)
343345
self:InitGGPK()
344346
if USE_DAT64 then
@@ -349,6 +351,7 @@ function main:LoadDatSource(value)
349351
if self.datFileByName["leaguenames"] then
350352
self.leagueLabel = self.datFileByName["leaguenames"]:ReadValueText({ type = "String" }, self.datFileByName["leaguenames"].rows[2] + 8)
351353
end
354+
self.reExportGGPKData = reExportState
352355
end
353356

354357
function main:OpenPathPopup()
@@ -520,7 +523,7 @@ function main:LoadSettings()
520523
end
521524
for _, node in ipairs(setXML[1]) do
522525
if type(node) == "table" then
523-
if node.elem == "DatSource" then
526+
if node.elem == "DatSource" and (node.attrib.ggpkPath or node.attrib.path) and node.attrib.datFilePath then
524527
self.datSource = self.datSource or { }
525528
self.datSource.ggpkPath = node.attrib.ggpkPath or node.attrib.path
526529
self.datSource.datFilePath = node.attrib.datFilePath
@@ -530,18 +533,19 @@ function main:LoadSettings()
530533
if node.elem == "DatSources" then
531534
self.datSources = self.datSources or { }
532535
for _, child in ipairs(node) do
533-
t_insert(self.datSources, { ggpkPath = child.attrib.ggpkPath, datFilePath = child.attrib.datFilePath, label = child.attrib.label, spec = child.attrib.spec })
536+
if (child.attrib.ggpkPath or child.attrib.path) and child.attrib.datFilePath then
537+
t_insert(self.datSources, { ggpkPath = child.attrib.ggpkPath, datFilePath = child.attrib.datFilePath, label = child.attrib.label, spec = child.attrib.spec })
538+
end
534539
end
535540
end
536541
end
537542
end
538-
if type(self.datSources) ~= "table" then
539-
self.datSources = { }
540-
end
541-
if not next(self.datSources) then
543+
if self.datSources and not next(self.datSources) and self.datSource then
542544
t_insert(self.datSources, self.datSource)
543545
end
544-
self.datSource = self.datSource or self.datSources[1]
546+
if not self.datSoruce and self.datSources then
547+
self.datSource = self.datSources[1]
548+
end
545549
end
546550

547551
function main:SaveSettings()

0 commit comments

Comments
 (0)