Skip to content

Commit

Permalink
fix content migration
Browse files Browse the repository at this point in the history
... by changing the order in which local functions are defined
Refs #6
  • Loading branch information
rkusa committed Aug 23, 2019
1 parent 810f2a8 commit 059263e
Showing 1 changed file with 56 additions and 56 deletions.
112 changes: 56 additions & 56 deletions Scripts/Hooks/scratchpad-hook.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 059263e

Please sign in to comment.