diff --git a/Themes/_fallback/Scripts/01 IniFile.lua b/Themes/_fallback/Scripts/01 IniFile.lua index c01743dd4d..e99c918e46 100644 --- a/Themes/_fallback/Scripts/01 IniFile.lua +++ b/Themes/_fallback/Scripts/01 IniFile.lua @@ -42,7 +42,7 @@ local RageFile = IniFile = { 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. -- do a few quick checks to see which one it is. @@ -80,7 +80,7 @@ IniFile = --ignore comments. if not str:find("^%s*#") then -- is this a section? - local _, _, sec = str:find( "%[(.+)%]" ) + local sec = str:match( "%[(.+)%]" ) -- if so, set focus there; otherwise, try to -- read a key/value pair (ignore blank lines) @@ -91,7 +91,7 @@ IniFile = --Warn( "Switching section to " .. sec ) else 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 diff --git a/Themes/_fallback/Scripts/02 ThemePrefs.lua b/Themes/_fallback/Scripts/02 ThemePrefs.lua index dec746da7f..3efbfe94bd 100644 --- a/Themes/_fallback/Scripts/02 ThemePrefs.lua +++ b/Themes/_fallback/Scripts/02 ThemePrefs.lua @@ -79,6 +79,7 @@ ThemePrefs = -- Only read from disk once, when _fallback calls this; we just -- need the base set once to add prefs onto. Init = function( prefs, bLoadFromDisk ) + -- If we don't have IniFile, we can't read/write from/to disk 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 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" ) PrefsTable[section][k] = tbl.Default end @@ -116,16 +117,17 @@ ThemePrefs = Save = function() -- Trace( "ThemePrefs.Save" ) - if not IniFile then return false end - if not NeedsSaved then return end - NeedsSaved = false - IniFile.WriteFile( ThemePrefsPath, PrefsTable ) + if IniFile and ThemePrefs.NeedsSaved then + IniFile.WriteFile( ThemePrefsPath, PrefsTable ) + ThemePrefs.NeedsSaved = false + return + end end, -- for when you absolutely have to save, no matter what NeedsSaved says. ForceSave = function() if not IniFile then return false end - NeedsSaved = false + ThemePrefs.NeedsSaved = false IniFile.WriteFile( ThemePrefsPath, PrefsTable ) end, @@ -140,7 +142,11 @@ ThemePrefs = Set = function( name, value ) --Trace( ("ThemePrefs.Set(%s, %s)"):format(name, tostring(value)) ) 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) ) end, }; diff --git a/Themes/_fallback/Scripts/02 ThemePrefsRows.lua b/Themes/_fallback/Scripts/02 ThemePrefsRows.lua index 21ad8973c2..d6e00381bb 100644 --- a/Themes/_fallback/Scripts/02 ThemePrefsRows.lua +++ b/Themes/_fallback/Scripts/02 ThemePrefsRows.lua @@ -57,8 +57,11 @@ local function DefaultSave( pref, choices, values ) return function(self, list, pn) for i=1, #choices do - if list[i] then ThemePrefs.Set( pref, values[i] ) break end - MESSAGEMAN:Broadcast( msg, params ) + if list[i] then + ThemePrefs.Set( pref, values[i] ) + MESSAGEMAN:Broadcast( msg, params ) + break + end end end end diff --git a/Themes/default/BGAnimations/ScreenOptionsService in.lua b/Themes/default/BGAnimations/ScreenOptionsService in.lua new file mode 100644 index 0000000000..c5355f0dde --- /dev/null +++ b/Themes/default/BGAnimations/ScreenOptionsService in.lua @@ -0,0 +1,5 @@ +return Def.Actor{ + StartTransitioningCommand=function(self) + ThemePrefs.Save() + end +} \ No newline at end of file diff --git a/Themes/default/BGAnimations/ScreenTitleMenu decorations.lua b/Themes/default/BGAnimations/ScreenTitleMenu decorations.lua index f2288395f7..e942af2272 100644 --- a/Themes/default/BGAnimations/ScreenTitleMenu decorations.lua +++ b/Themes/default/BGAnimations/ScreenTitleMenu decorations.lua @@ -2,17 +2,6 @@ InitUserPrefs(); 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("Logo","Logo"); t[#t+1] = StandardDecorationFromFileOptional("VersionInfo","VersionInfo");