From 446a8b0d09bebb6c224baaecbe05602cb7e3b75e Mon Sep 17 00:00:00 2001 From: HenryDu8133 <813367384@qq.com> Date: Sat, 11 Jul 2026 00:09:43 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E8=87=AA=E5=8A=A8=E6=9B=B4=E6=96=B0):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8C=81=E4=B9=85=E5=8C=96=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E8=BF=BD=E8=B8=AA=E9=81=BF=E5=85=8D=E9=87=8D=E5=A4=8D=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增读写本地版本记录文件的工具函数,调整自动更新触发逻辑仅在版本不一致时触发,更新成功后写入版本号;修复更新失败版本号的赋值问题,同时为安装脚本添加标准文件头注释 --- gate.lua | 19 +++++++++++++++++-- install_ticketmachine.lua | 8 ++++++++ ticketmachine.lua | 23 ++++++++++++++++++++--- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/gate.lua b/gate.lua index fd1b5a6..90d84d2 100644 --- a/gate.lua +++ b/gate.lua @@ -113,6 +113,20 @@ local function isGateIdleForUpdate() return nowMs() >= gateBusyUntilTs end +local function getLastUpdateVersion() + if not fs.exists(".last_update_version") then return nil end + local f = fs.open(".last_update_version", "r") + if not f then return nil end + local v = f.readAll() + f.close() + return v +end + +local function setLastUpdateVersion(v) + local f = fs.open(".last_update_version", "w") + if f then f.write(tostring(v)); f.close() end +end + local function runSilentGateUpdate() local baseEnv = (getfenv and getfenv()) or _ENV or _G local env = setmetatable({ AUTO_UPDATE_SILENT = true }, { __index = baseEnv }) @@ -1430,8 +1444,8 @@ while true do pcall(function() refreshRemoteLuaVersion(guessBaseFromStatusURL(serverURL)) end) - if remoteForceUpdate and versionMismatch == true then - if expectedGateVersion ~= failedUpdateVersion then + if remoteForceUpdate then + if expectedGateVersion and expectedGateVersion ~= getLastUpdateVersion() and expectedGateVersion ~= failedUpdateVersion then pendingGateUpdate = true end end @@ -1442,6 +1456,7 @@ while true do os.sleep(0.5) local ok, updated = pcall(runSilentGateUpdate) if ok and updated then + if expectedGateVersion then setLastUpdateVersion(expectedGateVersion) end os.reboot() return end diff --git a/install_ticketmachine.lua b/install_ticketmachine.lua index c3478d1..513e30a 100644 --- a/install_ticketmachine.lua +++ b/install_ticketmachine.lua @@ -1,3 +1,11 @@ +--[[ +Author: HenryDu8133 813367384@qq.com +Date: 2026-06-28 12:58:42 +LastEditors: HenryDu8133 813367384@qq.com +LastEditTime: 2026-07-11 00:02:33 +FilePath: \TicketMachine\install_ticketmachine.lua +Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE +--]] local URL_MACHINE_HTTP = "http://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/raw/branch/main/ticketmachine.lua" local URL_UPDATE_MACHINE = "http://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/raw/branch/main/update_machine.lua" diff --git a/ticketmachine.lua b/ticketmachine.lua index 5e0033a..b9d8759 100644 --- a/ticketmachine.lua +++ b/ticketmachine.lua @@ -658,6 +658,20 @@ local function clickSound() end -- ########################### -- Background Tasks -- ########################### +local function getLastUpdateVersion() + if not fs.exists(".last_update_version") then return nil end + local f = fs.open(".last_update_version", "r") + if not f then return nil end + local v = f.readAll() + f.close() + return v +end + +local function setLastUpdateVersion(v) + local f = fs.open(".last_update_version", "w") + if f then f.write(tostring(v)); f.close() end +end + local function runSilentMachineUpdate() local baseEnv = (getfenv and getfenv()) or _ENV or _G local env = setmetatable({ AUTO_UPDATE_SILENT = true }, { __index = baseEnv }) @@ -667,8 +681,9 @@ end local function backgroundSyncTask() pcall(refreshConfigOnce) while true do - if type(CFG) == 'table' and type(CFG.force_update) == 'boolean' and CFG.force_update == true and versionMismatch == true then - if expectedMachineVersion ~= failedUpdateVersion then + if type(CFG) == 'table' and type(CFG.force_update) == 'boolean' and CFG.force_update == true then + local expected = CFG.lua_versions and CFG.lua_versions.ticketmachine + if expected and expected ~= getLastUpdateVersion() and expected ~= failedUpdateVersion then pendingMachineUpdate = true end end @@ -679,12 +694,14 @@ local function backgroundSyncTask() sleep(0.5) local ok, updated = pcall(runSilentMachineUpdate) if ok and updated then + local expected = CFG.lua_versions and CFG.lua_versions.ticketmachine + if expected then setLastUpdateVersion(expected) end os.reboot() return end isUpdating = false pendingMachineUpdate = false - failedUpdateVersion = expectedMachineVersion + failedUpdateVersion = CFG.lua_versions and CFG.lua_versions.ticketmachine pcall(drawVersionIndicator) end sleep(UPDATE_CHECK_INTERVAL)