Skip to content
Snippets Groups Projects
Commit a44d20ac authored by dg's avatar dg
Browse files

Fix bug when saving profile data would error out while saving the game

git-svn-id: http://svn.net-core.org/repos/t-engine4@3046 51575b47-30f0-44d4-a5cc-537603b46e54
parent 38eacd1e
No related branches found
No related tags found
No related merge requests found
......@@ -134,6 +134,9 @@ end
--- Loads profile generic profile from disk
-- Generic profile is always read from the "online" profile
function _M:loadGenericProfile()
-- Delay when we are currently saving
if savefile_pipe and savefile_pipe.saving then savefile_pipe:pushGeneric("loadGenericProfile", function() self:loadGenericProfile() end) return end
local pop = self:mountProfile(true)
local d = "/current-profile/generic/"
for i, file in ipairs(fs.list(d)) do
......@@ -207,6 +210,9 @@ end
function _M:loadModuleProfile(short_name)
if short_name == "boot" then return end
-- Delay when we are currently saving
if savefile_pipe and savefile_pipe.saving then savefile_pipe:pushGeneric("loadModuleProfile", function() self:loadModuleProfile(short_name) end) return end
local function load(online)
local pop = self:mountProfile(online, short_name)
local d = "/current-profile/modules/"..short_name.."/"
......@@ -241,6 +247,9 @@ end
--- Saves a profile data
function _M:saveGenericProfile(name, data, nosync)
-- Delay when we are currently saving
if savefile_pipe and savefile_pipe.saving then savefile_pipe:pushGeneric("saveGenericProfile", function() self:saveGenericProfile(name, data, nosync) end) return end
data = serialize(data)
-- Check for readability
......@@ -263,6 +272,9 @@ end
function _M:saveModuleProfile(name, data, module, nosync)
if module == "boot" then return end
-- Delay when we are currently saving
if savefile_pipe and savefile_pipe.saving then savefile_pipe:pushGeneric("saveModuleProfile", function() self:saveModuleProfile(name, data, module, nosync) end) return end
data = serialize(data)
module = module or self.mod_name
......
......@@ -37,6 +37,7 @@ function _M:init(class, max_before_wait)
self.saveclass = class or "engine.Savefile"
self.pipe = {}
self.on_done = {}
self.max_before_wait = max_before_wait or 4
self.co = nil
self.current_nb = 0
......@@ -73,6 +74,11 @@ function _M:push(savename, type, object, class)
end
end
--- Push a generic action to be done once saves complete
function _M:pushGeneric(name, fct)
self.on_done[#self.on_done+1] = {name=name, fct=fct}
end
--- Actually do the saves
-- This should run in a coroutine.<br/>
-- Do not call this, this is automatic!
......@@ -99,6 +105,14 @@ function _M:doThread()
-- collectgarbage("restart")
self.saving = false
if game:getPlayer() then game:getPlayer().changed = true end
-- Run the generic stuff
while #self.on_done > 0 do
local p = self.on_done[1]
print("[SAVEFILE PIPE] on end", p.name)
p.fct()
table.remove(self.on_done, 1)
end
end
--- Force to wait for the saves
......
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