diff --git a/frontend/luasettings.lua b/frontend/luasettings.lua new file mode 100644 index 000000000..7ec90e5d1 --- /dev/null +++ b/frontend/luasettings.lua @@ -0,0 +1,52 @@ +local dump = require("dump") + +local LuaSettings = {} + +function LuaSettings:open(file_path) + local new = {file=file_path} + local ok, stored + + ok, stored = pcall(dofile, new.file) + if ok and stored then + new.data = stored + else + new.data = {} + end + + return setmetatable(new, {__index = LuaSettings}) +end + +function LuaSettings:readSetting(key) + return self.data[key] +end + +function LuaSettings:saveSetting(key, value) + self.data[key] = value +end + +function LuaSettings:delSetting(key) + self.data[key] = nil +end + +function LuaSettings:flush() + local f_out = io.open(self.file, "w") + if f_out ~= nil then + os.setlocale('C', 'numeric') + f_out:write("-- we can read Lua syntax here!\nreturn ") + f_out:write(dump(self.data)) + f_out:write("\n") + f_out:close() + end +end + +function LuaSettings:close() + self:flush() +end + +function LuaSettings:purge() + if self.file then + os.remove(self.file) + end +end + +return LuaSettings diff --git a/reader.lua b/reader.lua index 291a05912..ffe5adb82 100755 --- a/reader.lua +++ b/reader.lua @@ -25,12 +25,12 @@ if ffi.os == "Windows" then ffi.C._putenv("PATH=libs;common;") end -local DocSettings = require("docsettings") local _ = require("gettext") -- read settings and check for language override -- has to be done before requiring other files because -- they might call gettext on load -G_reader_settings = DocSettings:open(".reader") +G_reader_settings = require("luasettings"):open( + DataStorage:getDataDir().."/settings.reader.lua") local lang_locale = G_reader_settings:readSetting("language") if lang_locale then _.changeLang(lang_locale)