From 059263eea3a22d1d80eb06894b3aa30285d85d89 Mon Sep 17 00:00:00 2001 From: Markus Ast Date: Fri, 23 Aug 2019 17:51:18 +0200 Subject: [PATCH] fix content migration ... by changing the order in which local functions are defined Refs #6 --- Scripts/Hooks/scratchpad-hook.lua | 112 +++++++++++++++--------------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/Scripts/Hooks/scratchpad-hook.lua b/Scripts/Hooks/scratchpad-hook.lua index f86834d..69b30b1 100644 --- a/Scripts/Hooks/scratchpad-hook.lua +++ b/Scripts/Hooks/scratchpad-hook.lua @@ -132,62 +132,6 @@ function scratchpad_load() local pagesCount = 0 local pages = {} - function scratchpad.loadConfiguration() - scratchpad.log("Loading config file...") - local tbl = Tools.safeDoFile(lfs.writedir() .. "Config/ScratchpadConfig.lua", false) - if (tbl and tbl.config) then - scratchpad.log("Configuration exists...") - scratchpad.config = tbl.config - - -- config migration - - -- add default fontSize config - if scratchpad.config.fontSize == nil then - scratchpad.config.fontSize = 14 - scratchpad.saveConfiguration() - end - - -- move content into text file - if scratchpad.config.content ~= nil then - savePage(dirPath .. [[0000.txt]], scratchpad.config.content, false) - scratchpad.config.content = nil - scratchpad.saveConfiguration() - end - else - scratchpad.log("Configuration not found, creating defaults...") - scratchpad.config = { - hotkey = "Ctrl+Shift+x", - windowPosition = {x = 200, y = 200}, - windowSize = {w = 350, h = 150}, - fontSize = 14 - } - scratchpad.saveConfiguration() - end - - -- scan scratchpad dir for pages - for name in lfs.dir(dirPath) do - local path = dirPath .. name - scratchpad.log(path) - if lfs.attributes(path, "mode") == "file" then - if name:sub(-4) ~= ".txt" then - scratchpad.log("Ignoring file " .. name .. ", because of it doesn't seem to be a text file (.txt)") - elseif lfs.attributes(path, "size") > 1024 * 1024 then - scratchpad.log("Ignoring file " .. name .. ", because of its file size of more than 1MB") - else - scratchpad.log("found page " .. path) - table.insert( - pages, - { - name = name:sub(1, -5), - path = path - } - ) - pagesCount = pagesCount + 1 - end - end - end - end - local function loadPage(page) scratchpad.log("loading page " .. page.path) file, err = io.open(page.path, "r") @@ -257,6 +201,62 @@ function scratchpad_load() currentPage = pages[pagesCount].path end + function scratchpad.loadConfiguration() + scratchpad.log("Loading config file...") + local tbl = Tools.safeDoFile(lfs.writedir() .. "Config/ScratchpadConfig.lua", false) + if (tbl and tbl.config) then + scratchpad.log("Configuration exists...") + scratchpad.config = tbl.config + + -- config migration + + -- add default fontSize config + if scratchpad.config.fontSize == nil then + scratchpad.config.fontSize = 14 + scratchpad.saveConfiguration() + end + + -- move content into text file + if scratchpad.config.content ~= nil then + savePage(dirPath .. [[0000.txt]], scratchpad.config.content, false) + scratchpad.config.content = nil + scratchpad.saveConfiguration() + end + else + scratchpad.log("Configuration not found, creating defaults...") + scratchpad.config = { + hotkey = "Ctrl+Shift+x", + windowPosition = {x = 200, y = 200}, + windowSize = {w = 350, h = 150}, + fontSize = 14 + } + scratchpad.saveConfiguration() + end + + -- scan scratchpad dir for pages + for name in lfs.dir(dirPath) do + local path = dirPath .. name + scratchpad.log(path) + if lfs.attributes(path, "mode") == "file" then + if name:sub(-4) ~= ".txt" then + scratchpad.log("Ignoring file " .. name .. ", because of it doesn't seem to be a text file (.txt)") + elseif lfs.attributes(path, "size") > 1024 * 1024 then + scratchpad.log("Ignoring file " .. name .. ", because of its file size of more than 1MB") + else + scratchpad.log("found page " .. path) + table.insert( + pages, + { + name = name:sub(1, -5), + path = path + } + ) + pagesCount = pagesCount + 1 + end + end + end + end + function scratchpad.saveConfiguration() U.saveInFile(scratchpad.config, "config", lfs.writedir() .. "Config/ScratchpadConfig.lua") end