Commit f28bac86 authored by Danny SMc's avatar Danny SMc

Fixed settings saving and added basic settings layout

parent d250488f
ewogIFBhc3N3b3JkID0gImFkNGZhYTI1NjM2N2NhM2U3OWRmYjQwMDBkMjFkN2UyODM0MDBiYmYyOGNmMzI4YTcwNTFkYmJmYTQ1OGI3ZDgiLAogIFVzZXJuYW1lID0gImRhbm55c21jOTUiLAp9
\ No newline at end of file
ewogIFBsdWdpbnMgPSB7CiAgICBQYXRoID0gIkRBX1BsdWdpbnMiLAogICAgRW5hYmxlZCA9IHRydWUsCiAgfSwKICBBY2NvdW50ID0ge30sCiAgQ29uZmlnID0gewogICAgUGF0aCA9ICIuRGlzY292ZXJDb25maWciLAogICAgQmxvY2sgPSB0cnVlLAogIH0sCn0=
\ No newline at end of file
......@@ -68,7 +68,8 @@ function program.account.login()
local f = fs.open(Internal.Config.Path, "w")
Internal.Account.Username = username
Internal.Account.Password = Discover.Crypto:Sha256(password)
f.write(Discover.Crypto:Base64("encode", textutils.serialize(Internal.Account)))
local config = { ["Account"]=Internal.Account; ["Config"]=Internal.Config; ["Plugins"]=Internal.Plugins; }
f.write(Discover.Crypto:Base64("encode", textutils.serialize(config)))
f.close();
end
base.gui.alert("You have been logged in!")
......
......@@ -21,7 +21,7 @@ Internal = {
};
Config = {
Path = ".DiscoverConfig";
Block = false;
Block = true;
};
Plugins = {
Enabled = true;
......
......@@ -80,8 +80,8 @@ Internal.Icons = {
};
["settings"] = {
{"8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: "};
{"8:8: ","f:8:S","f:8:e","f:8:t","f:8:t","f:8:i","f:8:n","f:8:g","f:8:s","8:8: ","8:8: ","8:8::","8:8:x","8:8: "};
{"8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8::","8:8:x","8:8: "};
{"8:8: ","f:8:S","f:8:e","f:8:t","f:8:t","f:8:i","f:8:n","f:8:g","f:8:s","8:8: ","8:8: ","0:8::","0:8:x","8:8: "};
{"8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","0:8::","0:8:x","0:8: "};
{"8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: "};
};
["snippetStore"] = {
......
......@@ -32,58 +32,70 @@ function program.core.init()
--log("Checking for update, please wait ...")
--local ok, url = base.app.update("HASH", "VERSION");
-- Check for app config
log("Searching for config ...")
if fs.exists(Internal.Config.Path) then
local f = fs.open(Internal.Config.Path, "r")
local d = f.readAll()
f.close()
local config = textutils.unserialize(Discover.Crypto:Base64("decode", d))
Internal.Account = config.Account;
Internal.Config = config.Config;
Internal.Plugins = config.Plugins;
end
-- Install Plugins
log("Checking for plugins, please wait ...")
if fs.exists(Internal.Plugins.Path) then
local list = fs.list(Internal.Plugins.Path)
local function install(filepath)
local ok, err = pcall(function()
if fs.exists(filepath) then
local basen, func = nil;
local f = fs.open(filepath, "r")
local count = 0;
for line in f.readLine do
count = count + 1
count = count + 1
if line:sub(1,8) == "-- @base" then
basen = tostring(line:sub(10))
elseif line:sub(1,8) == "-- @func" then
func = tostring(line:sub(10))
end
if basen and func then
program[basen] = {};
require(filepath);
Plugin[basen][func]();
break
end
if count > 25 then
break
if Internal.Plugins.Enabled then
log("Checking for plugins, please wait ...")
if fs.exists(Internal.Plugins.Path) then
local list = fs.list(Internal.Plugins.Path)
local function install(filepath)
local ok, err = pcall(function()
if fs.exists(filepath) then
local basen, func = nil;
local f = fs.open(filepath, "r")
local count = 0;
for line in f.readLine do
count = count + 1
count = count + 1
if line:sub(1,8) == "-- @base" then
basen = tostring(line:sub(10))
elseif line:sub(1,8) == "-- @func" then
func = tostring(line:sub(10))
end
if basen and func then
program[basen] = {};
require(filepath);
Plugin[basen][func]();
break
end
if count > 25 then
break
end
end
f.close();
end
f.close();
end)
if ok then
return "Success";
else
print(err)
sleep(1000)
return "Fail";
end
end)
if ok then
return "Success";
else
print(err)
sleep(1000)
return "Fail";
end
end
for k,v in ipairs(list) do
log("Installing plugins: " .. tostring(k) .. "/" .. tostring(#list) .. " :: " .. tostring(tostring(install(fs.combine(Internal.Plugins.Path, v)))))
drawLoad();
for k,v in ipairs(list) do
log("Installing plugins: " .. tostring(k) .. "/" .. tostring(#list) .. " :: " .. tostring(tostring(install(fs.combine(Internal.Plugins.Path, v)))))
drawLoad();
end
end
end
-- Check for app config
log("Searching for config ...")
if fs.exists(Internal.Config.Path) then
local f = fs.open(Internal.Config.Path, "r")
local d = f.readAll()
f.close()
Internal.Account = textutils.unserialize(Discover.Crypto:Base64("decode", d))
-- Check for termination blocking
log("Checking for blocking method ...")
if Internal.Config.Block then
os.oldPullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
end
-- Check for username / password
......
......@@ -26,7 +26,7 @@ Internal = {
};
Config = {
Path = ".DiscoverConfig";
Block = false;
Block = true;
};
Plugins = {
Enabled = true;
......@@ -283,8 +283,8 @@ Internal.Icons = {
};
["settings"] = {
{"8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: "};
{"8:8: ","f:8:S","f:8:e","f:8:t","f:8:t","f:8:i","f:8:n","f:8:g","f:8:s","8:8: ","8:8: ","8:8::","8:8:x","8:8: "};
{"8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8::","8:8:x","8:8: "};
{"8:8: ","f:8:S","f:8:e","f:8:t","f:8:t","f:8:i","f:8:n","f:8:g","f:8:s","8:8: ","8:8: ","0:8::","0:8:x","8:8: "};
{"8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","0:8::","0:8:x","0:8: "};
{"8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: ","8:8: "};
};
["snippetStore"] = {
......@@ -390,58 +390,70 @@ function program.core.init()
--log("Checking for update, please wait ...")
--local ok, url = base.app.update("HASH", "VERSION");
-- Check for app config
log("Searching for config ...")
if fs.exists(Internal.Config.Path) then
local f = fs.open(Internal.Config.Path, "r")
local d = f.readAll()
f.close()
local config = textutils.unserialize(Discover.Crypto:Base64("decode", d))
Internal.Account = config.Account;
Internal.Config = config.Config;
Internal.Plugins = config.Plugins;
end
-- Install Plugins
log("Checking for plugins, please wait ...")
if fs.exists(Internal.Plugins.Path) then
local list = fs.list(Internal.Plugins.Path)
local function install(filepath)
local ok, err = pcall(function()
if fs.exists(filepath) then
local basen, func = nil;
local f = fs.open(filepath, "r")
local count = 0;
for line in f.readLine do
count = count + 1
count = count + 1
if line:sub(1,8) == "-- @base" then
basen = tostring(line:sub(10))
elseif line:sub(1,8) == "-- @func" then
func = tostring(line:sub(10))
end
if basen and func then
program[basen] = {};
require(filepath);
Plugin[basen][func]();
break
end
if count > 25 then
break
if Internal.Plugins.Enabled then
log("Checking for plugins, please wait ...")
if fs.exists(Internal.Plugins.Path) then
local list = fs.list(Internal.Plugins.Path)
local function install(filepath)
local ok, err = pcall(function()
if fs.exists(filepath) then
local basen, func = nil;
local f = fs.open(filepath, "r")
local count = 0;
for line in f.readLine do
count = count + 1
count = count + 1
if line:sub(1,8) == "-- @base" then
basen = tostring(line:sub(10))
elseif line:sub(1,8) == "-- @func" then
func = tostring(line:sub(10))
end
if basen and func then
program[basen] = {};
require(filepath);
Plugin[basen][func]();
break
end
if count > 25 then
break
end
end
f.close();
end
f.close();
end)
if ok then
return "Success";
else
print(err)
sleep(1000)
return "Fail";
end
end)
if ok then
return "Success";
else
print(err)
sleep(1000)
return "Fail";
end
end
for k,v in ipairs(list) do
log("Installing plugins: " .. tostring(k) .. "/" .. tostring(#list) .. " :: " .. tostring(tostring(install(fs.combine(Internal.Plugins.Path, v)))))
drawLoad();
for k,v in ipairs(list) do
log("Installing plugins: " .. tostring(k) .. "/" .. tostring(#list) .. " :: " .. tostring(tostring(install(fs.combine(Internal.Plugins.Path, v)))))
drawLoad();
end
end
end
-- Check for app config
log("Searching for config ...")
if fs.exists(Internal.Config.Path) then
local f = fs.open(Internal.Config.Path, "r")
local d = f.readAll()
f.close()
Internal.Account = textutils.unserialize(Discover.Crypto:Base64("decode", d))
-- Check for termination blocking
log("Checking for blocking method ...")
if Internal.Config.Block then
os.oldPullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
end
-- Check for username / password
......@@ -1814,6 +1826,37 @@ function program.main.settings()
base.screen.colour("white")
program.draw.menubar("Settings: Menu")
base.draw.box(1, 51, 19, 1, " ", "grey", "grey")
base.draw.textr("Exit ", 19, false, "red", "grey")
base.draw.textl(" Setting Names | Value / Enabled | Edit |", 3, false, "lightGrey", "white")
-- Prevent Termination
base.draw.texta("Block Termination", 2, 6, false, "lightBlue", "white")
base.draw.texta("Enabled", 24, 6, false, "green", "white")
base.draw.texta(" Edit ", 45, 6, false, "red", "white")
-- Config File
base.draw.texta("Config File Path", 2, 7, false, "lightBlue", "white")
base.draw.texta(tostring(Internal.Config.Path):sub(1, 20), 24, 7, false, "green", "white")
base.draw.texta(" Edit ", 45, 7, false, "red", "white")
-- Plugins Enabled
base.draw.texta("Plugins Enabled", 2, 8, false, "lightBlue", "white")
base.draw.texta(tostring(Internal.Plugins.Enabled):sub(1, 20), 24, 8, false, "green", "white")
base.draw.texta(" Edit ", 45, 8, false, "red", "white")
-- Plugins Folder
base.draw.texta("Plugins Folder Path", 2, 9, false, "lightBlue", "white")
base.draw.texta(tostring(Internal.Plugins.Path):sub(1, 20), 24, 9, false, "green", "white")
base.draw.texta(" Edit ", 45, 9, false, "red", "white")
local function saveConfig()
local f = fs.open(Internal.Config.Path, "w")
local config = { ["Account"]=Internal.Account; ["Config"]=Internal.Config; ["Plugins"]=Internal.Plugins; }
f.write(Discover.Crypto:Base64("encode", textutils.serialize(config)))
f.close();
end
while true do
local args = { os.pullEvent() }
if args[1] == "timer" then
......@@ -1821,6 +1864,20 @@ function program.main.settings()
elseif args[1] == "mouse_click" then
if args[4] >= 1 and args[4] <= 2 then
program.draw.menu.handler("Settings: Menu", args[3], args[4])
elseif (args[3] >= 47 and args[3] <= 50) and args[4] == 19 then
base.thread.remove("Settings");
if not base.thread.find("Home") then
base.thread.create("Home", program.main.home)
end
base.thread.switch("Home")
elseif (args[3] >= 45 and args[3] <= 50) and args[4] == 6 then
local new = base.gui.confirm("Enable / Disable Termination Blocking?")
Internal.Config.Block = new;
print(textutils.serialize(Internal.Config)); sleep(10000)
saveConfig();
base.gui.alert("Changed!")
sleep(0.5)
program.main.settings();
end
end
end
......@@ -4869,7 +4926,8 @@ function program.account.login()
local f = fs.open(Internal.Config.Path, "w")
Internal.Account.Username = username
Internal.Account.Password = Discover.Crypto:Sha256(password)
f.write(Discover.Crypto:Base64("encode", textutils.serialize(Internal.Account)))
local config = { ["Account"]=Internal.Account; ["Config"]=Internal.Config; ["Plugins"]=Internal.Plugins; }
f.write(Discover.Crypto:Base64("encode", textutils.serialize(config)))
f.close();
end
base.gui.alert("You have been logged in!")
......
......@@ -7,6 +7,37 @@ function program.main.settings()
base.screen.colour("white")
program.draw.menubar("Settings: Menu")
base.draw.box(1, 51, 19, 1, " ", "grey", "grey")
base.draw.textr("Exit ", 19, false, "red", "grey")
base.draw.textl(" Setting Names | Value / Enabled | Edit |", 3, false, "lightGrey", "white")
-- Prevent Termination
base.draw.texta("Block Termination", 2, 6, false, "lightBlue", "white")
base.draw.texta("Enabled", 24, 6, false, "green", "white")
base.draw.texta(" Edit ", 45, 6, false, "red", "white")
-- Config File
base.draw.texta("Config File Path", 2, 7, false, "lightBlue", "white")
base.draw.texta(tostring(Internal.Config.Path):sub(1, 20), 24, 7, false, "green", "white")
base.draw.texta(" Edit ", 45, 7, false, "red", "white")
-- Plugins Enabled
base.draw.texta("Plugins Enabled", 2, 8, false, "lightBlue", "white")
base.draw.texta(tostring(Internal.Plugins.Enabled):sub(1, 20), 24, 8, false, "green", "white")
base.draw.texta(" Edit ", 45, 8, false, "red", "white")
-- Plugins Folder
base.draw.texta("Plugins Folder Path", 2, 9, false, "lightBlue", "white")
base.draw.texta(tostring(Internal.Plugins.Path):sub(1, 20), 24, 9, false, "green", "white")
base.draw.texta(" Edit ", 45, 9, false, "red", "white")
local function saveConfig()
local f = fs.open(Internal.Config.Path, "w")
local config = { ["Account"]=Internal.Account; ["Config"]=Internal.Config; ["Plugins"]=Internal.Plugins; }
f.write(Discover.Crypto:Base64("encode", textutils.serialize(config)))
f.close();
end
while true do
local args = { os.pullEvent() }
if args[1] == "timer" then
......@@ -14,6 +45,20 @@ function program.main.settings()
elseif args[1] == "mouse_click" then
if args[4] >= 1 and args[4] <= 2 then
program.draw.menu.handler("Settings: Menu", args[3], args[4])
elseif (args[3] >= 47 and args[3] <= 50) and args[4] == 19 then
base.thread.remove("Settings");
if not base.thread.find("Home") then
base.thread.create("Home", program.main.home)
end
base.thread.switch("Home")
elseif (args[3] >= 45 and args[3] <= 50) and args[4] == 6 then
local new = base.gui.confirm("Enable / Disable Termination Blocking?")
Internal.Config.Block = new;
print(textutils.serialize(Internal.Config)); sleep(10000)
saveConfig();
base.gui.alert("Changed!")
sleep(0.5)
program.main.settings();
end
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment