:3333333 extra config stuff

This commit is contained in:
Gvidas Juknevičius 2024-08-18 14:37:59 +03:00
parent 2eb20cb6c5
commit 348e764adf
Signed by: MCorange
GPG Key ID: 12B1346D720B7FBB
6 changed files with 80 additions and 3092 deletions

3033
basalt.lua

File diff suppressed because one or more lines are too long

View File

@ -7,26 +7,22 @@ local require = function(path)
return __DEFAULT_IMPORT(path) return __DEFAULT_IMPORT(path)
end end
end end
rawset(__BUNDLER_FILES, "updater.lua", function () rawset(__BUNDLER_FILES, "updater.lua", function ()
local utils = require("utils.lua") local utils = require("utils.lua")
local config = require("config.lua")
local LAST_USED = os.time() local LAST_USED = os.time()
local mod = {} local mod = {}
local function checkForUpdate() local function checkForUpdate()
local current_time = os.time() local current_time = os.time()
local difference = math.abs(current_time - LAST_USED) local difference = math.abs(current_time - LAST_USED)
print("Checking for update... difference: " .. tostring(difference))
--its been considerable time since the keypad was interacted with
--therefore it's time to force an update down the users throat (microsoft moment)
if difference > .5 then if difference > .5 then
local update_code_request = http.get("https://git.mcorangehq.xyz/xomf/keypadOS/raw/branch/main/keypadOS.lua") print("INFO: Updating! (diff: " .. tostring(difference) .. ")")
local update_code_request = http.get(config.release_url)
if update_code_request then if update_code_request then
local update_code_text = update_code_request.readAll() local update_code_text = update_code_request.readAll()
if update_code_text then if update_code_text then
if string.find(update_code_text, "^local __BUNDLER_FILES = {}") then if string.find(update_code_text, "^local __BUNDLER_FILES = {}") then
--make backup
fs.copy("startup.lua","backup.lua") fs.copy("startup.lua","backup.lua")
--install update
local file = fs.open("startup.lua", "w") local file = fs.open("startup.lua", "w")
file.write(update_code_text) file.write(update_code_text)
file.close() file.close()
@ -50,7 +46,7 @@ rawset(__BUNDLER_FILES, "updater.lua", function ()
utils.MonPrint("Basalt found!") utils.MonPrint("Basalt found!")
else else
utils.MonPrint("Downloading basalt...") utils.MonPrint("Downloading basalt...")
local basalt_code = http.get("https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/versions/latest.lua").readAll() local basalt_code = http.get(config.release_url).readAll()
utils.MonPrint("Installing basalt...") utils.MonPrint("Installing basalt...")
local file = fs.open("basalt.lua", "w") local file = fs.open("basalt.lua", "w")
if not file then if not file then
@ -65,35 +61,36 @@ rawset(__BUNDLER_FILES, "updater.lua", function ()
end end
end end
return mod return mod
end)
end) -- FILE END: updater.lua --
rawset(__BUNDLER_FILES, "config.lua", function () rawset(__BUNDLER_FILES, "config.lua", function ()
return { local config = {
correctPin = "42169" correctPin = "42169",
release_url = "https://git.mcorangehq.xyz/xomf/keypadOS/raw/branch/main/keypadOS.lua",
basalt_url = "https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/versions/latest.lua",
config_path = "keypadOS.config.lua"
} }
local DEFAULT_CONFIG = "return {\n" ..
end) -- FILE END: config.lua -- " group=\"default\",\n" ..
"}\n"
function config.ReadConfig()
if not fs.exists(config.config_path) then
local f = fs.open(config.config_path, "w")
f.write(DEFAULT_CONFIG)
f.close();
end
local cfg = require(config.config_path)
return cfg
end
return config
end)
rawset(__BUNDLER_FILES, "ui.lua", function () rawset(__BUNDLER_FILES, "ui.lua", function ()
local utils = require("utils.lua") local utils = require("utils.lua")
local basalt = require("basalt") local basalt = require("basalt")
local config = require("config.lua") local config = require("config.lua")
local updater = require("updater.lua") local updater = require("updater.lua")
--- @type Monitor
local monitor = utils.Cast(peripheral.find("monitor")) local monitor = utils.Cast(peripheral.find("monitor"))
--- @type drive
local drive = utils.Cast(peripheral.find("drive")) local drive = utils.Cast(peripheral.find("drive"))
local mod = {} local mod = {}
--- @class Ui
--- @field pin string
--- @field main any
--- @field pinLabel any
--- @field enterButton any
--- @field resetEverything function
--- @field unlockDoor function
--- @field addToPin function
--- @param ui Ui
local function resetEverything(ui) local function resetEverything(ui)
sleep(2) sleep(2)
ui.pin = "" ui.pin = ""
@ -101,7 +98,6 @@ rawset(__BUNDLER_FILES, "ui.lua", function ()
redstone.setOutput("front", false) redstone.setOutput("front", false)
ui.enterButton:setBackground(colors.blue) ui.enterButton:setBackground(colors.blue)
end end
--- @param ui Ui
local function unlockDoor(ui) local function unlockDoor(ui)
if drive.isDiskPresent() then if drive.isDiskPresent() then
if drive.getDiskLabel() == config.correctPin then if drive.getDiskLabel() == config.correctPin then
@ -129,7 +125,6 @@ rawset(__BUNDLER_FILES, "ui.lua", function ()
resetEverything(ui) resetEverything(ui)
end) end)
end end
--- @param ui Ui
local function addToPin(ui, i) local function addToPin(ui, i)
if #ui.pin >= 5 then if #ui.pin >= 5 then
return return
@ -180,23 +175,15 @@ rawset(__BUNDLER_FILES, "ui.lua", function ()
fs.delete("startup.lua") fs.delete("startup.lua")
fs.copy("backup.lua", "startup.lua") fs.copy("backup.lua", "startup.lua")
os.exit() os.exit()
-- os.reboot()
end end
end end
return mod return mod
end)
end) -- FILE END: ui.lua --
rawset(__BUNDLER_FILES, "utils.lua", function () rawset(__BUNDLER_FILES, "utils.lua", function ()
local utils = {} local utils = {}
-- Type coersion for lsp
---@generic T
---@param object any
---@return T
function utils.Cast(object) function utils.Cast(object)
return object return object
end end
--- @type Monitor
local MONITOR = utils.Cast(peripheral.find("monitor")) local MONITOR = utils.Cast(peripheral.find("monitor"))
local MONITOR_Y = 1 local MONITOR_Y = 1
function utils.MonPrint(text) function utils.MonPrint(text)
@ -209,12 +196,8 @@ rawset(__BUNDLER_FILES, "utils.lua", function ()
MONITOR.setTextScale(scale) MONITOR.setTextScale(scale)
end end
return utils; return utils;
end)
end) -- FILE END: utils.lua --
rawset(__BUNDLER_FILES, "main.lua", function () rawset(__BUNDLER_FILES, "main.lua", function ()
-- keycardOS "bootloader", has no access to basalt
-- intended for checking for updates, and automatically updating basalt if it is missing
local utils = require("utils.lua") local utils = require("utils.lua")
local updater = require("updater.lua") local updater = require("updater.lua")
local main = {} local main = {}
@ -227,7 +210,5 @@ rawset(__BUNDLER_FILES, "main.lua", function ()
require("ui.lua").InitUi() require("ui.lua").InitUi()
end end
return main return main
end)
end) -- FILE END: main.lua --
require("main.lua").Main() require("main.lua").Main()

View File

@ -1,3 +1,27 @@
return { local config = {
correctPin = "42169" correctPin = "42169",
release_url = "https://git.mcorangehq.xyz/xomf/keypadOS/raw/branch/main/keypadOS.lua",
basalt_url = "https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/versions/latest.lua",
config_path = "keypadOS.config.lua"
} }
local DEFAULT_CONFIG = "return {\n" ..
" group=\"default\",\n" ..
"}\n"
--- @class Config
--- @field group string
--- Read current configs, create if doesnt exist
---@return Config
function config.ReadConfig()
if not fs.exists(config.config_path) then
local f = fs.open(config.config_path, "w")
f.write(DEFAULT_CONFIG)
f.close();
end
local cfg = require(config.config_path)
return cfg
end
return config

View File

@ -2,8 +2,6 @@
-- intended for checking for updates, and automatically updating basalt if it is missing -- intended for checking for updates, and automatically updating basalt if it is missing
local utils = require("utils.lua") local utils = require("utils.lua")
local updater = require("updater.lua") local updater = require("updater.lua")
local main = {} local main = {}

View File

@ -1,5 +1,5 @@
local utils = require("utils.lua") local utils = require("utils.lua")
local config = require("config.lua")
local LAST_USED = os.time() local LAST_USED = os.time()
local mod = {} local mod = {}
@ -7,11 +7,12 @@ local mod = {}
local function checkForUpdate() local function checkForUpdate()
local current_time = os.time() local current_time = os.time()
local difference = math.abs(current_time - LAST_USED) local difference = math.abs(current_time - LAST_USED)
print("Checking for update... difference: " .. tostring(difference)) -- print("INFO: Checking for update... difference: " .. tostring(difference))
--its been considerable time since the keypad was interacted with --its been considerable time since the keypad was interacted with
--therefore it's time to force an update down the users throat (microsoft moment) --therefore it's time to force an update down the users throat (microsoft moment)
if difference > .5 then if difference > .5 then
local update_code_request = http.get("https://git.mcorangehq.xyz/xomf/keypadOS/raw/branch/main/keypadOS.lua") print("INFO: Updating! (diff: " .. tostring(difference) .. ")")
local update_code_request = http.get(config.release_url)
if update_code_request then if update_code_request then
local update_code_text = update_code_request.readAll() local update_code_text = update_code_request.readAll()
if update_code_text then if update_code_text then
@ -45,7 +46,7 @@ function mod.GetBasalt()
utils.MonPrint("Basalt found!") utils.MonPrint("Basalt found!")
else else
utils.MonPrint("Downloading basalt...") utils.MonPrint("Downloading basalt...")
local basalt_code = http.get("https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/versions/latest.lua").readAll() local basalt_code = http.get(config.release_url).readAll()
utils.MonPrint("Installing basalt...") utils.MonPrint("Installing basalt...")
local file = fs.open("basalt.lua", "w") local file = fs.open("basalt.lua", "w")

25
x.py
View File

@ -9,16 +9,30 @@ FILES= [
"main.lua", "main.lua",
] ]
MINIMISE=True
def read_file(p: str) -> str: def read_file(p: str) -> str:
buf = ""; buf = "";
with open("src/"+p, "r", encoding="utf-8") as f: with open("src/"+p, "r", encoding="utf-8") as f:
buf += f"\nrawset(__BUNDLER_FILES, \"{p}\", function ()\n"; buf += f"rawset(__BUNDLER_FILES, \"{p}\", function ()\n";
for line in f.readlines(): for line in f.readlines():
if str.strip(line) != "":
buf += " " + line; buf += " " + line;
buf += f"\nend) -- FILE END: {p} --\n"; buf += "\nend)";
if not MINIMISE:
buf += f"-- FILE END: {p} --\n";
else:
buf += "\n";
return buf; return buf;
def minimise(buf: str) -> str:
newbuf = "";
for line in buf.splitlines():
if line.strip().startswith("--"):
continue;
if line.strip() == "":
continue
newbuf += line + "\n";
return newbuf;
def main(): def main():
buf = "" buf = ""
@ -36,7 +50,10 @@ def main():
print(f"=== FILE: {file}"); print(f"=== FILE: {file}");
buf += read_file(file); buf += read_file(file);
buf += "\nrequire(\"main.lua\").Main()\n"; buf += "require(\"main.lua\").Main()\n";
if MINIMISE:
buf = minimise(buf);
with open(OUTPUT, "w", encoding="utf-8") as f: with open(OUTPUT, "w", encoding="utf-8") as f:
f.write(buf); f.write(buf);