Merge pull request #553 from dguzek/Fix-ThemePrefs

Fix theme prefs
This commit is contained in:
Kyzentun
2015-04-17 00:43:41 -06:00
5 changed files with 26 additions and 23 deletions
+3 -3
View File
@@ -42,7 +42,7 @@ local RageFile =
IniFile = IniFile =
{ {
StrToKeyVal = function( str ) StrToKeyVal = function( str )
local _, _, key, value = str:find( "(.+)=(.*)" ) local key, value = str:match( "(.+)=(.*)" )
-- key is always a string, but value may be num, bool, or nil. -- key is always a string, but value may be num, bool, or nil.
-- do a few quick checks to see which one it is. -- do a few quick checks to see which one it is.
@@ -80,7 +80,7 @@ IniFile =
--ignore comments. --ignore comments.
if not str:find("^%s*#") then if not str:find("^%s*#") then
-- is this a section? -- is this a section?
local _, _, sec = str:find( "%[(.+)%]" ) local sec = str:match( "%[(.+)%]" )
-- if so, set focus there; otherwise, try to -- if so, set focus there; otherwise, try to
-- read a key/value pair (ignore blank lines) -- read a key/value pair (ignore blank lines)
@@ -91,7 +91,7 @@ IniFile =
--Warn( "Switching section to " .. sec ) --Warn( "Switching section to " .. sec )
else else
local k, v = IniFile.StrToKeyVal( str ) local k, v = IniFile.StrToKeyVal( str )
if k and v then current[k] = v end if k and v ~= nil then current[k] = v end
end end
end end
end end
+13 -7
View File
@@ -79,6 +79,7 @@ ThemePrefs =
-- Only read from disk once, when _fallback calls this; we just -- Only read from disk once, when _fallback calls this; we just
-- need the base set once to add prefs onto. -- need the base set once to add prefs onto.
Init = function( prefs, bLoadFromDisk ) Init = function( prefs, bLoadFromDisk )
-- If we don't have IniFile, we can't read/write from/to disk -- If we don't have IniFile, we can't read/write from/to disk
if not IniFile then Warn( GetString("IniFileMissing") ) end if not IniFile then Warn( GetString("IniFileMissing") ) end
@@ -99,7 +100,7 @@ ThemePrefs =
-- if the key doesn't exist, add it with our default value -- if the key doesn't exist, add it with our default value
for k, tbl in pairs(prefs) do for k, tbl in pairs(prefs) do
if not PrefsTable[section][k] then if PrefsTable[section][k] == nil then
Trace( k .. " doesn't exist, creating" ) Trace( k .. " doesn't exist, creating" )
PrefsTable[section][k] = tbl.Default PrefsTable[section][k] = tbl.Default
end end
@@ -116,16 +117,17 @@ ThemePrefs =
Save = function() Save = function()
-- Trace( "ThemePrefs.Save" ) -- Trace( "ThemePrefs.Save" )
if not IniFile then return false end if IniFile and ThemePrefs.NeedsSaved then
if not NeedsSaved then return end IniFile.WriteFile( ThemePrefsPath, PrefsTable )
NeedsSaved = false ThemePrefs.NeedsSaved = false
IniFile.WriteFile( ThemePrefsPath, PrefsTable ) return
end
end, end,
-- for when you absolutely have to save, no matter what NeedsSaved says. -- for when you absolutely have to save, no matter what NeedsSaved says.
ForceSave = function() ForceSave = function()
if not IniFile then return false end if not IniFile then return false end
NeedsSaved = false ThemePrefs.NeedsSaved = false
IniFile.WriteFile( ThemePrefsPath, PrefsTable ) IniFile.WriteFile( ThemePrefsPath, PrefsTable )
end, end,
@@ -140,7 +142,11 @@ ThemePrefs =
Set = function( name, value ) Set = function( name, value )
--Trace( ("ThemePrefs.Set(%s, %s)"):format(name, tostring(value)) ) --Trace( ("ThemePrefs.Set(%s, %s)"):format(name, tostring(value)) )
local tbl = ResolveTable(name) local tbl = ResolveTable(name)
if tbl then tbl[name] = value; NeedsSaved = true; return end if tbl then
ThemePrefs.NeedsSaved = true
tbl[name] = value
return
end
Warn( "Set: "..GetString("UnknownPreference"):format(name) ) Warn( "Set: "..GetString("UnknownPreference"):format(name) )
end, end,
}; };
@@ -57,8 +57,11 @@ local function DefaultSave( pref, choices, values )
return function(self, list, pn) return function(self, list, pn)
for i=1, #choices do for i=1, #choices do
if list[i] then ThemePrefs.Set( pref, values[i] ) break end if list[i] then
MESSAGEMAN:Broadcast( msg, params ) ThemePrefs.Set( pref, values[i] )
MESSAGEMAN:Broadcast( msg, params )
break
end
end end
end end
end end
@@ -0,0 +1,5 @@
return Def.Actor{
StartTransitioningCommand=function(self)
ThemePrefs.Save()
end
}
@@ -2,17 +2,6 @@ InitUserPrefs();
local t = Def.ActorFrame {} local t = Def.ActorFrame {}
t[#t+1] = Def.ActorFrame {
OnCommand=function(self)
if not FILEMAN:DoesFileExist("Save/ThemePrefs.ini") then
Trace("ThemePrefs doesn't exist; creating file")
ThemePrefs.ForceSave()
end
ThemePrefs.Save()
end;
};
t[#t+1] = StandardDecorationFromFileOptional("Footer","Footer"); t[#t+1] = StandardDecorationFromFileOptional("Footer","Footer");
t[#t+1] = StandardDecorationFromFileOptional("Logo","Logo"); t[#t+1] = StandardDecorationFromFileOptional("Logo","Logo");
t[#t+1] = StandardDecorationFromFileOptional("VersionInfo","VersionInfo"); t[#t+1] = StandardDecorationFromFileOptional("VersionInfo","VersionInfo");