mirror of
https://github.com/asherao/dcs-scratchpad.git
synced 2025-10-29 16:56:22 +00:00
fix content migration
... by changing the order in which local functions are defined Refs #6
This commit is contained in:
parent
810f2a8949
commit
059263eea3
@ -132,62 +132,6 @@ function scratchpad_load()
|
|||||||
local pagesCount = 0
|
local pagesCount = 0
|
||||||
local pages = {}
|
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)
|
local function loadPage(page)
|
||||||
scratchpad.log("loading page " .. page.path)
|
scratchpad.log("loading page " .. page.path)
|
||||||
file, err = io.open(page.path, "r")
|
file, err = io.open(page.path, "r")
|
||||||
@ -257,6 +201,62 @@ function scratchpad_load()
|
|||||||
currentPage = pages[pagesCount].path
|
currentPage = pages[pagesCount].path
|
||||||
end
|
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()
|
function scratchpad.saveConfiguration()
|
||||||
U.saveInFile(scratchpad.config, "config", lfs.writedir() .. "Config/ScratchpadConfig.lua")
|
U.saveInFile(scratchpad.config, "config", lfs.writedir() .. "Config/ScratchpadConfig.lua")
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user