From 68a7d4eaa501a7fe5479588c04da60f7f1a511ff Mon Sep 17 00:00:00 2001 From: xomf Date: Sat, 17 Aug 2024 23:24:30 -0400 Subject: [PATCH] trying new update system mayb --- keypadOS.lua | 20 +++++++++++++------- src/ui.lua | 12 ++++++++++-- src/updater.lua | 7 +++---- x.py | 5 ++++- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/keypadOS.lua b/keypadOS.lua index a0404f9..5090159 100644 --- a/keypadOS.lua +++ b/keypadOS.lua @@ -7,7 +7,7 @@ local require = function(path) return __DEFAULT_IMPORT(path) end end - +local KEYPADOS_UPDATE_HASH = "PJIEvsAncSvhKOqsLGVlxvzJ" rawset(__BUNDLER_FILES, "updater.lua", function () local utils = require("utils.lua") local LAST_USED = os.time() @@ -26,10 +26,9 @@ rawset(__BUNDLER_FILES, "updater.lua", function () if string.find(update_code_text, "^local __BUNDLER_FILES = {}") then -- Make backup fs.copy("startup.lua", "backup.lua") - local startup_file = fs.open("startup.lua", "r") - local startup_contents = startup_file.readAll() - startup_file.close() - if update_code_text ~= startup_contents then + local pattern = 'local KEYPADOS_UPDATE_HASH%s*=%s*"(.-)"' + local foundUpdateHash = inputString:match(pattern) + if KEYPADOS_UPDATE_HASH ~= foundUpdateHash then local file = fs.open("startup.lua", "w") file.write(update_code_text) file.close() @@ -160,13 +159,20 @@ rawset(__BUNDLER_FILES, "ui.lua", function () ui.enterButton = ui.main:addButton() :setText(">>>>") :setBackground(colors.blue) - :setPosition(6,3) + :setPosition(6,2) :setSize(1.5,3.2) :onClick(function() unlockDoor(ui) end) local btnX = 1 - local btnY = 3 + local btnY = 2 + ui.main:addButton() + :setPosition(1, 5) + :setText("0") + :setSize(6,1) + :onClick(function() + addToPin(ui, 0) + end) for i = 1, 9 do ui.main:addButton() :setPosition(btnX, btnY) diff --git a/src/ui.lua b/src/ui.lua index a3e4c00..d409c86 100644 --- a/src/ui.lua +++ b/src/ui.lua @@ -83,14 +83,22 @@ function mod.InitUi() ui.enterButton = ui.main:addButton() :setText(">>>>") :setBackground(colors.blue) - :setPosition(6,3) + :setPosition(6,2) :setSize(1.5,3.2) :onClick(function() unlockDoor(ui) end) local btnX = 1 - local btnY = 3 + local btnY = 2 + + ui.main:addButton() + :setPosition(1, 5) + :setText("0") + :setSize(6,1) + :onClick(function() + addToPin(ui, 0) + end) for i = 1, 9 do ui.main:addButton() diff --git a/src/updater.lua b/src/updater.lua index 2a5d644..092f4d9 100644 --- a/src/updater.lua +++ b/src/updater.lua @@ -19,11 +19,10 @@ local function checkForUpdate() -- Make backup fs.copy("startup.lua", "backup.lua") - local startup_file = fs.open("startup.lua", "r") - local startup_contents = startup_file.readAll() - startup_file.close() + local pattern = 'local KEYPADOS_UPDATE_HASH%s*=%s*"(.-)"' + local foundUpdateHash = inputString:match(pattern) - if update_code_text ~= startup_contents then + if KEYPADOS_UPDATE_HASH ~= foundUpdateHash then local file = fs.open("startup.lua", "w") file.write(update_code_text) file.close() diff --git a/x.py b/x.py index 4096655..14978e6 100755 --- a/x.py +++ b/x.py @@ -1,5 +1,7 @@ #!/usr/bin/python - +import string +import random +UPDATE_ID= ''.join(random.choices(string.ascii_letters, k=24)) OUTPUT="keypadOS.lua"; FILES= [ "updater.lua", @@ -31,6 +33,7 @@ def main(): buf += " return __DEFAULT_IMPORT(path)\n"; buf += " end\n"; buf += "end\n"; + buf += f'local KEYPADOS_UPDATE_HASH = "{UPDATE_ID}"'; for file in FILES: print(f"=== FILE: {file}");