Compare commits
28 Commits
bacd5ac1aa
...
keypad
| Author | SHA1 | Date | |
|---|---|---|---|
|
9e633867da
|
|||
|
79c5654247
|
|||
|
6b864b43be
|
|||
|
5fa92ae0c4
|
|||
|
4ccc4b07da
|
|||
|
b0c5b756b1
|
|||
|
a3ca65a458
|
|||
|
d07a35f360
|
|||
|
b88ca058fa
|
|||
|
df5e544347
|
|||
|
7c78db3620
|
|||
|
7ed9f76f15
|
|||
|
2a8932a19f
|
|||
|
28ceac8643
|
|||
| 68422b9343 | |||
| dcc0a3e687 | |||
| 9b48f2adcb | |||
| 9d8398565b | |||
| 7292f271fb | |||
| 0e6fa358a7 | |||
| 20495931d0 | |||
| 1e170263fd | |||
| 7ce154ed44 | |||
|
4c2197919a
|
|||
|
5eb4a9edb7
|
|||
|
87fb39b9bd
|
|||
|
a2546cb9ba
|
|||
|
348e764adf
|
3033
basalt.lua
3033
basalt.lua
File diff suppressed because one or more lines are too long
131
keypadOS.lua
131
keypadOS.lua
@@ -3,65 +3,23 @@ local __DEFAULT_IMPORT = require
|
|||||||
local require = function(path)
|
local require = function(path)
|
||||||
if __BUNDLER_FILES[path] then
|
if __BUNDLER_FILES[path] then
|
||||||
return __BUNDLER_FILES[path]()
|
return __BUNDLER_FILES[path]()
|
||||||
|
elseif __BUNDLER_FILES[path .. ".lua"] then
|
||||||
|
return __BUNDLER_FILES[path .. ".lua"]()
|
||||||
else
|
else
|
||||||
return __DEFAULT_IMPORT(path)
|
return __DEFAULT_IMPORT(path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local KEYPADOS_UPDATE_HASH = "sxJGuLGHFrttJcPZAxUKxhPw"
|
local __UPDATE_HASH = "5e1c10aba96c3f9ded6aecb030f2774577c005af"
|
||||||
rawset(__BUNDLER_FILES, "updater.lua", function ()
|
rawset(__BUNDLER_FILES, "updater.lua", function ()
|
||||||
local utils = require("utils.lua")
|
local utils = require("utils.lua")
|
||||||
local LAST_USED = os.time()
|
local config = require("config.lua")
|
||||||
local mod = {}
|
local mod = {}
|
||||||
local function checkForUpdate()
|
|
||||||
local current_time = os.time()
|
|
||||||
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 > 10 then
|
|
||||||
local update_code_request = http.get("https://git.mcorangehq.xyz/xomf/keypadOS/raw/branch/main/keypadOS.lua?x=" .. tostring(math.random(11111111, 99999999))) -- I HATE CACHE REEEEEEEEEEEEEEEEE
|
|
||||||
if update_code_request then
|
|
||||||
local update_code_text = update_code_request.readAll()
|
|
||||||
if update_code_text then
|
|
||||||
if string.find(update_code_text, "^local __BUNDLER_FILES = {}") then
|
|
||||||
-- Make backup
|
|
||||||
if fs.exists("backup.lua") then
|
|
||||||
fs.delete("backup.lua")
|
|
||||||
end
|
|
||||||
fs.copy("startup.lua", "backup.lua")
|
|
||||||
if not string.find(update_code_text, KEYPADOS_UPDATE_HASH) then
|
|
||||||
local file = fs.open("startup.lua", "w")
|
|
||||||
file.write(update_code_text)
|
|
||||||
file.close()
|
|
||||||
os.reboot()
|
|
||||||
else
|
|
||||||
print("Nothing changed, not updating.")
|
|
||||||
LAST_USED = os.time()
|
|
||||||
return
|
|
||||||
end
|
|
||||||
else
|
|
||||||
print("Bad file download (core)")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
print("Bad mem read (core)")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
print("Bad download (core)")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
function mod.UpdateChecker()
|
|
||||||
while true do
|
|
||||||
checkForUpdate()
|
|
||||||
sleep(1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
function mod.GetBasalt()
|
function mod.GetBasalt()
|
||||||
if fs.exists("basalt.lua") then
|
if fs.exists("basalt.lua") then
|
||||||
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.basalt_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
|
||||||
@@ -76,35 +34,37 @@ 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 = "42069"
|
correctPin = "42069",
|
||||||
|
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",
|
||||||
|
ntfy_url = "https://ntfy.sh/keypadOS_alerts",
|
||||||
|
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 = ""
|
||||||
@@ -112,7 +72,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
|
||||||
@@ -120,8 +79,8 @@ rawset(__BUNDLER_FILES, "ui.lua", function ()
|
|||||||
drive:ejectDisk()
|
drive:ejectDisk()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
basalt.debug("test")
|
|
||||||
if ui.pin == config.correctPin then
|
if ui.pin == config.correctPin then
|
||||||
|
blibs.notifier.notify("5", "Unlocked door :3 love u");
|
||||||
ui.enterButton:setBackground(colors.green)
|
ui.enterButton:setBackground(colors.green)
|
||||||
ui.pinLabel:setText("Welcome")
|
ui.pinLabel:setText("Welcome")
|
||||||
redstone.setOutput("front", true)
|
redstone.setOutput("front", true)
|
||||||
@@ -140,7 +99,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
|
||||||
@@ -189,11 +147,11 @@ rawset(__BUNDLER_FILES, "ui.lua", function ()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
local status, err = pcall(function ()
|
local status, err = pcall(function ()
|
||||||
parallel.waitForAll(basalt.autoUpdate, updater.UpdateChecker)
|
parallel.waitForAll(basalt.autoUpdate)
|
||||||
end)
|
end)
|
||||||
if not status and err ~= "Terminated" then
|
if not status and err ~= "Terminated" then
|
||||||
print("Error detected: " .. err)
|
log.error("Error detected: " .. err)
|
||||||
http.post("https://ntfy.sh/keypadOS_alerts", err, {Priority = "urgent"}) --exposed ntfy url no spam me pls
|
blibs.notifier.notify("5", err); --exposed ntfy url no spam me pls
|
||||||
sleep(5)
|
sleep(5)
|
||||||
utils.MonReset(0.5)
|
utils.MonReset(0.5)
|
||||||
fs.delete("basalt.lua")
|
fs.delete("basalt.lua")
|
||||||
@@ -203,19 +161,12 @@ rawset(__BUNDLER_FILES, "ui.lua", function ()
|
|||||||
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)
|
||||||
@@ -228,25 +179,21 @@ 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 mod = {}
|
||||||
KEYPADOS_VERSION = "4.0"
|
KEYPADOS_VERSION = "4.0"
|
||||||
function main.Main()
|
function mod.main(blibs)
|
||||||
|
_G.log = blibs.log;
|
||||||
|
_G.blibs = blibs;
|
||||||
utils.MonReset(0.5)
|
utils.MonReset(0.5)
|
||||||
updater.GetBasalt()
|
updater.GetBasalt()
|
||||||
utils.MonPrint("keypadOS v" .. KEYPADOS_VERSION)
|
utils.MonPrint("keypadOS v" .. KEYPADOS_VERSION)
|
||||||
utils.MonReset(1)
|
utils.MonReset(1)
|
||||||
require("ui.lua").InitUi()
|
require("ui.lua").InitUi()
|
||||||
end
|
end
|
||||||
return main
|
return mod;
|
||||||
|
end)
|
||||||
end) -- FILE END: main.lua --
|
return require("main.lua")
|
||||||
|
|
||||||
require("main.lua").Main()
|
|
||||||
|
|||||||
@@ -1,3 +1,28 @@
|
|||||||
return {
|
local config = {
|
||||||
correctPin = "42069"
|
correctPin = "42069",
|
||||||
|
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",
|
||||||
|
ntfy_url = "https://ntfy.sh/keypadOS_alerts",
|
||||||
|
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 :3
|
||||||
|
---@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
|
||||||
|
|||||||
36
src/main.lua
36
src/main.lua
@@ -1,15 +1,37 @@
|
|||||||
-- 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 mod = {}
|
||||||
local main = {}
|
|
||||||
|
|
||||||
|
|
||||||
KEYPADOS_VERSION = "4.0"
|
KEYPADOS_VERSION = "4.0"
|
||||||
|
|
||||||
function main.Main()
|
--- @class BootloaderLibs
|
||||||
|
--- @field log Logger
|
||||||
|
--- @field updater Updater
|
||||||
|
--- @field notifier Notifier
|
||||||
|
--- @field json JsonParser
|
||||||
|
|
||||||
|
|
||||||
|
--- @class Logger
|
||||||
|
--- @field error fun(...)
|
||||||
|
--- @field warn fun(...)
|
||||||
|
--- @field info fun(...)
|
||||||
|
--- @field debug fun(...)
|
||||||
|
|
||||||
|
--- @class Updater
|
||||||
|
--- @field addEntry fun(path: string, branch: string, url: string)
|
||||||
|
|
||||||
|
--- @class JsonParser
|
||||||
|
--- @field decode fun(s: string): table
|
||||||
|
--- @field encode fun(s: table): string
|
||||||
|
|
||||||
|
--- @class Notifier
|
||||||
|
--- @field notify fun(priority: "1"|"2"|"3"|"4"|"5", body: string)
|
||||||
|
|
||||||
|
---@param blibs BootloaderLibs
|
||||||
|
function mod.main(blibs)
|
||||||
|
_G.log = blibs.log;
|
||||||
|
_G.blibs = blibs;
|
||||||
utils.MonReset(0.5)
|
utils.MonReset(0.5)
|
||||||
updater.GetBasalt()
|
updater.GetBasalt()
|
||||||
utils.MonPrint("keypadOS v" .. KEYPADOS_VERSION)
|
utils.MonPrint("keypadOS v" .. KEYPADOS_VERSION)
|
||||||
@@ -18,5 +40,5 @@ function main.Main()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
return main
|
return mod;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ 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
|
--- @type Monitor
|
||||||
local monitor = utils.Cast(peripheral.find("monitor"))
|
local monitor = utils.Cast(peripheral.find("monitor"))
|
||||||
--- @type drive
|
--- @type drive
|
||||||
@@ -36,8 +37,8 @@ local function unlockDoor(ui)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
basalt.debug("test")
|
|
||||||
if ui.pin == config.correctPin then
|
if ui.pin == config.correctPin then
|
||||||
|
blibs.notifier.notify("5", "Unlocked door :3 love u");
|
||||||
ui.enterButton:setBackground(colors.green)
|
ui.enterButton:setBackground(colors.green)
|
||||||
ui.pinLabel:setText("Welcome")
|
ui.pinLabel:setText("Welcome")
|
||||||
redstone.setOutput("front", true)
|
redstone.setOutput("front", true)
|
||||||
@@ -117,12 +118,12 @@ function mod.InitUi()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local status, err = pcall(function ()
|
local status, err = pcall(function ()
|
||||||
parallel.waitForAll(basalt.autoUpdate, updater.UpdateChecker)
|
parallel.waitForAll(basalt.autoUpdate)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if not status and err ~= "Terminated" then
|
if not status and err ~= "Terminated" then
|
||||||
print("Error detected: " .. err)
|
log.error("Error detected: " .. err)
|
||||||
http.post("https://ntfy.sh/keypadOS_alerts", err, {Priority = "urgent"}) --exposed ntfy url no spam me pls
|
blibs.notifier.notify("5", err); --exposed ntfy url no spam me pls
|
||||||
sleep(5)
|
sleep(5)
|
||||||
utils.MonReset(0.5)
|
utils.MonReset(0.5)
|
||||||
fs.delete("basalt.lua")
|
fs.delete("basalt.lua")
|
||||||
|
|||||||
@@ -1,62 +1,15 @@
|
|||||||
local utils = require("utils.lua")
|
local utils = require("utils.lua")
|
||||||
|
local config = require("config.lua")
|
||||||
local LAST_USED = os.time()
|
|
||||||
|
|
||||||
local mod = {}
|
local mod = {}
|
||||||
|
|
||||||
local function checkForUpdate()
|
|
||||||
local current_time = os.time()
|
|
||||||
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 > 10 then
|
|
||||||
local update_code_request = http.get("https://git.mcorangehq.xyz/xomf/keypadOS/raw/branch/main/keypadOS.lua?x=" .. tostring(math.random(11111111, 99999999))) -- I HATE CACHE REEEEEEEEEEEEEEEEE
|
|
||||||
if update_code_request then
|
|
||||||
local update_code_text = update_code_request.readAll()
|
|
||||||
if update_code_text then
|
|
||||||
if string.find(update_code_text, "^local __BUNDLER_FILES = {}") then
|
|
||||||
-- Make backup
|
|
||||||
if fs.exists("backup.lua") then
|
|
||||||
fs.delete("backup.lua")
|
|
||||||
end
|
|
||||||
fs.copy("startup.lua", "backup.lua")
|
|
||||||
|
|
||||||
if not string.find(update_code_text, KEYPADOS_UPDATE_HASH) then
|
|
||||||
local file = fs.open("startup.lua", "w")
|
|
||||||
file.write(update_code_text)
|
|
||||||
file.close()
|
|
||||||
os.reboot()
|
|
||||||
else
|
|
||||||
print("Nothing changed, not updating.")
|
|
||||||
LAST_USED = os.time()
|
|
||||||
return
|
|
||||||
end
|
|
||||||
else
|
|
||||||
print("Bad file download (core)")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
print("Bad mem read (core)")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
print("Bad download (core)")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function mod.UpdateChecker()
|
|
||||||
while true do
|
|
||||||
checkForUpdate()
|
|
||||||
sleep(1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function mod.GetBasalt()
|
function mod.GetBasalt()
|
||||||
if fs.exists("basalt.lua") then
|
if fs.exists("basalt.lua") then
|
||||||
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.basalt_url).readAll()
|
||||||
utils.MonPrint("Installing basalt...")
|
utils.MonPrint("Installing basalt...")
|
||||||
|
|
||||||
local file = fs.open("basalt.lua", "w")
|
local file = fs.open("basalt.lua", "w")
|
||||||
|
|||||||
68
x.py
68
x.py
@@ -1,7 +1,5 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
import string
|
import hashlib
|
||||||
import random
|
|
||||||
UPDATE_ID= ''.join(random.choices(string.ascii_letters, k=24))
|
|
||||||
OUTPUT="keypadOS.lua";
|
OUTPUT="keypadOS.lua";
|
||||||
FILES= [
|
FILES= [
|
||||||
"updater.lua",
|
"updater.lua",
|
||||||
@@ -11,37 +9,67 @@ 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 += "\nend)";
|
||||||
buf += f"\nend) -- FILE END: {p} --\n";
|
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 get_hash(buf: str) -> str:
|
||||||
|
hasher = hashlib.sha1();
|
||||||
|
|
||||||
|
hasher.update(bytes(buf, "utf-8"));
|
||||||
|
return hasher.hexdigest();
|
||||||
|
|
||||||
|
REQ_HEADER = """
|
||||||
|
local __BUNDLER_FILES = {}
|
||||||
|
local __DEFAULT_IMPORT = require
|
||||||
|
local require = function(path)
|
||||||
|
if __BUNDLER_FILES[path] then
|
||||||
|
return __BUNDLER_FILES[path]()
|
||||||
|
elseif __BUNDLER_FILES[path .. ".lua"] then
|
||||||
|
return __BUNDLER_FILES[path .. ".lua"]()
|
||||||
|
else
|
||||||
|
return __DEFAULT_IMPORT(path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local __UPDATE_HASH = __BUNDLER_REPLACE_HASH__
|
||||||
|
"""
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
buf = ""
|
buf = ""
|
||||||
buf += "local __BUNDLER_FILES = {}\n";
|
buf += REQ_HEADER;
|
||||||
buf += "local __DEFAULT_IMPORT = require\n";
|
|
||||||
buf += "local require = function(path)\n";
|
|
||||||
buf += " if __BUNDLER_FILES[path] then\n";
|
|
||||||
buf += " return __BUNDLER_FILES[path]()\n";
|
|
||||||
buf += " else\n";
|
|
||||||
buf += " return __DEFAULT_IMPORT(path)\n";
|
|
||||||
buf += " end\n";
|
|
||||||
buf += "end\n";
|
|
||||||
buf += f'local KEYPADOS_UPDATE_HASH = "{UPDATE_ID}"';
|
|
||||||
|
|
||||||
for file in FILES:
|
for file in FILES:
|
||||||
print(f"=== FILE: {file}");
|
print(f"=== FILE: {file}");
|
||||||
buf += read_file(file);
|
buf += read_file(file);
|
||||||
print(f"=== UPDATE HASH: {UPDATE_ID}")
|
|
||||||
|
buf += "return require(\"main.lua\")";
|
||||||
|
|
||||||
buf += "\nrequire(\"main.lua\").Main()\n";
|
if MINIMISE:
|
||||||
|
buf = minimise(buf);
|
||||||
|
update_hash = get_hash(buf);
|
||||||
|
buf = buf.replace("__BUNDLER_REPLACE_HASH__", f"\"{update_hash}\"");
|
||||||
|
|
||||||
|
print(f"=== UPDATE HASH: {update_hash}")
|
||||||
with open(OUTPUT, "w", encoding="utf-8") as f:
|
with open(OUTPUT, "w", encoding="utf-8") as f:
|
||||||
f.write(buf);
|
f.write(buf);
|
||||||
print("DONE");
|
print("DONE");
|
||||||
|
|||||||
Reference in New Issue
Block a user