Skip to content
Snippets Groups Projects
Commit 21fbfb52 authored by DarkGod's avatar DarkGod
Browse files

if somehow a save fails, it is checked and resave until it succeeds

parent 90cdf17d
No related branches found
No related tags found
No related merge requests found
......@@ -604,6 +604,22 @@ function _M:loadEntity(name)
return loadedEntity
end
--- Checks validity of a kind
function _M:checkValidity(type)
local path = fs.getRealPath(self.save_dir..self['nameLoad'..type:lower():capitalize()](self))
if not path or path == "" then
print("[SAVEFILE] checked validity of type", type, " => path not found")
return false
end
fs.mount(path, self.load_dir)
local ok = false
local f = fs.open(self.load_dir.."main", "r")
if f then ok = true f:close() end
fs.umount(path)
print("[SAVEFILE] checked validity of type", type, " => ", ok and "all fine" or "main not found")
return ok
end
--- Checks for existence
function _M:check()
return fs.exists(self.save_dir..self:nameLoadGame())
......
......@@ -130,10 +130,39 @@ function _M:doThread()
local pop = core.serial.popSaveReturn()
if not pop then coroutine.yield()
else
if waiton[pop] and waiton[pop].on_end then
waiton[pop].on_end(waiton[pop].save)
local dontremove = false
local p = waiton[pop]
if p then
local Savefile = require(p.class)
print("[SAVEFILE PIPE] Checking save", p.savename, p.type, p.save.current_save_zip)
local save = Savefile.new(p.savename, config.settings.background_saves)
local okmain = save:checkValidity(p.type)
save:close()
if not okmain then
print("[SAVEFILE PIPE] *RE*new save running in the pipe:", p.savename, p.type, "::", p.id, "::", p.baseobject, "=>", p.object, "("..p.nb_objects..")")
local o = p.object
local save = Savefile.new(p.savename, config.settings.background_saves)
o.__saved_saveversion = p.saveversion
save["save"..p.type:lower():capitalize()](save, o, true)
if p.screenshot then save:saveScreenshot(p.screenshot) end
p.save = save
waiton[save.current_save_zip:gsub("%.tmp$", "")] = p
save:close()
core.serial.threadSave()
print("[SAVEFILE PIPE] Resaving sent", p.savename, p.type, p.save.current_save_zip)
dontremove = true
end
end
if not dontremove then
if p and p.on_end then
p.on_end(p.save)
end
waiton[pop] = nil
end
waiton[pop] = nil
end
end
self.waiton = nil
......
......@@ -2104,6 +2104,9 @@ end
--- Requests the game to save
function _M:saveGame()
world:saveWorld()
do return end
self:registerHighscore()
if self.party then for actor, _ in pairs(self.party.members) do engine.interface.PlayerHotkeys:updateQuickHotkeys(actor) end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment