feat(自动更新): 添加持久化版本追踪避免重复更新
新增读写本地版本记录文件的工具函数,调整自动更新触发逻辑仅在版本不一致时触发,更新成功后写入版本号;修复更新失败版本号的赋值问题,同时为安装脚本添加标准文件头注释
This commit is contained in:
+20
-3
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user