feat(自动更新): 添加持久化版本追踪避免重复更新

新增读写本地版本记录文件的工具函数,调整自动更新触发逻辑仅在版本不一致时触发,更新成功后写入版本号;修复更新失败版本号的赋值问题,同时为安装脚本添加标准文件头注释
This commit is contained in:
2026-07-11 00:09:43 +08:00
parent d848f1c438
commit 446a8b0d09
3 changed files with 45 additions and 5 deletions
+17 -2
View File
@@ -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