fix(update): 优化更新逻辑,添加错误提示并清理冗余代码
移除所有脚本文件的头部注释模板 删除installer.lua中未使用的splitCsv函数 重构静默更新逻辑,改用loadfile替代os.run以正确捕获执行错误 添加更新错误追踪机制,在界面版本指示器处显示失败提示 修复更新成功的判断条件
This commit is contained in:
@@ -128,9 +128,16 @@ local function setLastUpdateVersion(v)
|
||||
end
|
||||
|
||||
local function runSilentGateUpdate()
|
||||
if not fs.exists("update_gate.lua") then
|
||||
return false, "update_gate.lua not found"
|
||||
end
|
||||
local baseEnv = (getfenv and getfenv()) or _ENV or _G
|
||||
local env = setmetatable({ AUTO_UPDATE_SILENT = true }, { __index = baseEnv })
|
||||
return os.run(env, "update_gate.lua", "--silent")
|
||||
local fn, err = loadfile("update_gate.lua", env)
|
||||
if not fn then return false, err end
|
||||
local ok, res = pcall(fn, "--silent")
|
||||
if not ok then return false, tostring(res) end
|
||||
return true, true
|
||||
end
|
||||
|
||||
local function setServerConnected(ok)
|
||||
@@ -174,6 +181,8 @@ local function drawServerStatusIndicator(w)
|
||||
termDev.setTextColor(colors.white)
|
||||
end
|
||||
|
||||
local lastUpdateError = nil
|
||||
|
||||
local function drawVersionIndicator(w)
|
||||
local s = tostring(VERSION or "")
|
||||
if #s == 0 then return end
|
||||
@@ -196,6 +205,13 @@ local function drawVersionIndicator(w)
|
||||
termDev.write(s)
|
||||
termDev.setTextColor(markerColor)
|
||||
termDev.write(markerText)
|
||||
|
||||
if lastUpdateError then
|
||||
termDev.setCursorPos(1, 2)
|
||||
termDev.setTextColor(colors.red)
|
||||
termDev.write(string.sub(tostring(lastUpdateError), 1, w))
|
||||
end
|
||||
|
||||
termDev.setTextColor(colors.white)
|
||||
end
|
||||
|
||||
@@ -1452,16 +1468,18 @@ while true do
|
||||
|
||||
if pendingGateUpdate and isGateIdleForUpdate() then
|
||||
isUpdating = true
|
||||
lastUpdateError = nil
|
||||
drawReadyScreen()
|
||||
os.sleep(0.5)
|
||||
local ok, updated = pcall(runSilentGateUpdate)
|
||||
if ok and updated then
|
||||
if ok and updated == true then
|
||||
if expectedGateVersion then setLastUpdateVersion(expectedGateVersion) end
|
||||
os.reboot()
|
||||
return
|
||||
end
|
||||
isUpdating = false
|
||||
pendingGateUpdate = false
|
||||
lastUpdateError = tostring(updated)
|
||||
failedUpdateVersion = expectedGateVersion
|
||||
end
|
||||
drawReadyScreen()
|
||||
|
||||
+2
-18
@@ -1,11 +1,4 @@
|
||||
--[[
|
||||
Author: HenryDu8133 813367384@qq.com
|
||||
Date: 2026-05-16 23:26:53
|
||||
LastEditors: HenryDu8133 813367384@qq.com
|
||||
LastEditTime: 2026-07-11 00:11:28
|
||||
FilePath: \TicketMachine\installer.lua
|
||||
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
--]]
|
||||
|
||||
local URL_ERROR = "http://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/raw/branch/main/error.dfpwm"
|
||||
local URL_PASS = "http://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/raw/branch/main/pass.dfpwm"
|
||||
local URL_GATE = "http://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/raw/branch/main/gate.lua"
|
||||
@@ -17,16 +10,7 @@ local function trim(s)
|
||||
return (tostring(s or ""):gsub("^%s+", ""):gsub("%s+$", ""))
|
||||
end
|
||||
|
||||
local function splitCsv(s)
|
||||
local out = {}
|
||||
s = trim(s)
|
||||
if #s == 0 then return out end
|
||||
for part in s:gmatch("[^,/%s]+") do
|
||||
local v = trim(part)
|
||||
if #v > 0 then table.insert(out, v) end
|
||||
end
|
||||
return out
|
||||
end
|
||||
|
||||
|
||||
|
||||
local function writeFile(path, content, binary)
|
||||
|
||||
+21
-3
@@ -673,9 +673,16 @@ local function setLastUpdateVersion(v)
|
||||
end
|
||||
|
||||
local function runSilentMachineUpdate()
|
||||
if not fs.exists('update_machine.lua') then
|
||||
return false, "update_machine.lua not found"
|
||||
end
|
||||
local baseEnv = (getfenv and getfenv()) or _ENV or _G
|
||||
local env = setmetatable({ AUTO_UPDATE_SILENT = true }, { __index = baseEnv })
|
||||
return os.run(env, 'update_machine.lua', '--silent')
|
||||
local fn, err = loadfile('update_machine.lua', env)
|
||||
if not fn then return false, err end
|
||||
local ok, res = pcall(fn, '--silent')
|
||||
if not ok then return false, tostring(res) end
|
||||
return true, true
|
||||
end
|
||||
|
||||
local function backgroundSyncTask()
|
||||
@@ -690,17 +697,19 @@ local function backgroundSyncTask()
|
||||
|
||||
if pendingMachineUpdate and state and tostring(state.page or 'home') == 'home' then
|
||||
isUpdating = true
|
||||
lastUpdateError = nil
|
||||
pcall(drawVersionIndicator)
|
||||
sleep(0.5)
|
||||
local ok, updated = pcall(runSilentMachineUpdate)
|
||||
if ok and updated then
|
||||
local expected = CFG.lua_versions and CFG.lua_versions.ticketmachine
|
||||
if ok and updated == true 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
|
||||
lastUpdateError = tostring(updated)
|
||||
failedUpdateVersion = CFG.lua_versions and CFG.lua_versions.ticketmachine
|
||||
pcall(drawVersionIndicator)
|
||||
end
|
||||
@@ -1129,6 +1138,8 @@ local function stationDisplay(code)
|
||||
return code
|
||||
end
|
||||
|
||||
local lastUpdateError = nil
|
||||
|
||||
local function drawVersionIndicator()
|
||||
if w < 1 then return end
|
||||
local markerColor = colors.yellow
|
||||
@@ -1149,6 +1160,13 @@ local function drawVersionIndicator()
|
||||
termDev.write(tostring(VERSION))
|
||||
termDev.setTextColor(markerColor)
|
||||
termDev.write(markerText)
|
||||
|
||||
if lastUpdateError then
|
||||
termDev.setCursorPos(1, 2)
|
||||
termDev.setTextColor(colors.red)
|
||||
termDev.write(string.sub(tostring(lastUpdateError), 1, w))
|
||||
end
|
||||
|
||||
termDev.setTextColor(colors.white)
|
||||
end
|
||||
|
||||
|
||||
+1
-8
@@ -1,11 +1,4 @@
|
||||
--[[
|
||||
Author: HenryDu8133 813367384@qq.com
|
||||
Date: 2026-05-17 13:44:24
|
||||
LastEditors: HenryDu8133 813367384@qq.com
|
||||
LastEditTime: 2026-07-11 00:10:45
|
||||
FilePath: \TicketMachine\update_gate.lua
|
||||
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
--]]
|
||||
|
||||
local URL_GATE = "http://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/raw/branch/main/gate.lua"
|
||||
local args = { ... }
|
||||
local silent = AUTO_UPDATE_SILENT == true or args[1] == "--silent"
|
||||
|
||||
Reference in New Issue
Block a user