feat(自动更新): 添加持久化版本追踪避免重复更新
新增读写本地版本记录文件的工具函数,调整自动更新触发逻辑仅在版本不一致时触发,更新成功后写入版本号;修复更新失败版本号的赋值问题,同时为安装脚本添加标准文件头注释
This commit is contained in:
@@ -113,6 +113,20 @@ local function isGateIdleForUpdate()
|
|||||||
return nowMs() >= gateBusyUntilTs
|
return nowMs() >= gateBusyUntilTs
|
||||||
end
|
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 function runSilentGateUpdate()
|
||||||
local baseEnv = (getfenv and getfenv()) or _ENV or _G
|
local baseEnv = (getfenv and getfenv()) or _ENV or _G
|
||||||
local env = setmetatable({ AUTO_UPDATE_SILENT = true }, { __index = baseEnv })
|
local env = setmetatable({ AUTO_UPDATE_SILENT = true }, { __index = baseEnv })
|
||||||
@@ -1430,8 +1444,8 @@ while true do
|
|||||||
pcall(function()
|
pcall(function()
|
||||||
refreshRemoteLuaVersion(guessBaseFromStatusURL(serverURL))
|
refreshRemoteLuaVersion(guessBaseFromStatusURL(serverURL))
|
||||||
end)
|
end)
|
||||||
if remoteForceUpdate and versionMismatch == true then
|
if remoteForceUpdate then
|
||||||
if expectedGateVersion ~= failedUpdateVersion then
|
if expectedGateVersion and expectedGateVersion ~= getLastUpdateVersion() and expectedGateVersion ~= failedUpdateVersion then
|
||||||
pendingGateUpdate = true
|
pendingGateUpdate = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -1442,6 +1456,7 @@ while true do
|
|||||||
os.sleep(0.5)
|
os.sleep(0.5)
|
||||||
local ok, updated = pcall(runSilentGateUpdate)
|
local ok, updated = pcall(runSilentGateUpdate)
|
||||||
if ok and updated then
|
if ok and updated then
|
||||||
|
if expectedGateVersion then setLastUpdateVersion(expectedGateVersion) end
|
||||||
os.reboot()
|
os.reboot()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -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_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"
|
local URL_UPDATE_MACHINE = "http://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/raw/branch/main/update_machine.lua"
|
||||||
|
|||||||
+20
-3
@@ -658,6 +658,20 @@ local function clickSound() end
|
|||||||
-- ###########################
|
-- ###########################
|
||||||
-- Background Tasks
|
-- 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 function runSilentMachineUpdate()
|
||||||
local baseEnv = (getfenv and getfenv()) or _ENV or _G
|
local baseEnv = (getfenv and getfenv()) or _ENV or _G
|
||||||
local env = setmetatable({ AUTO_UPDATE_SILENT = true }, { __index = baseEnv })
|
local env = setmetatable({ AUTO_UPDATE_SILENT = true }, { __index = baseEnv })
|
||||||
@@ -667,8 +681,9 @@ end
|
|||||||
local function backgroundSyncTask()
|
local function backgroundSyncTask()
|
||||||
pcall(refreshConfigOnce)
|
pcall(refreshConfigOnce)
|
||||||
while true do
|
while true do
|
||||||
if type(CFG) == 'table' and type(CFG.force_update) == 'boolean' and CFG.force_update == true and versionMismatch == true then
|
if type(CFG) == 'table' and type(CFG.force_update) == 'boolean' and CFG.force_update == true then
|
||||||
if expectedMachineVersion ~= failedUpdateVersion then
|
local expected = CFG.lua_versions and CFG.lua_versions.ticketmachine
|
||||||
|
if expected and expected ~= getLastUpdateVersion() and expected ~= failedUpdateVersion then
|
||||||
pendingMachineUpdate = true
|
pendingMachineUpdate = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -679,12 +694,14 @@ local function backgroundSyncTask()
|
|||||||
sleep(0.5)
|
sleep(0.5)
|
||||||
local ok, updated = pcall(runSilentMachineUpdate)
|
local ok, updated = pcall(runSilentMachineUpdate)
|
||||||
if ok and updated then
|
if ok and updated then
|
||||||
|
local expected = CFG.lua_versions and CFG.lua_versions.ticketmachine
|
||||||
|
if expected then setLastUpdateVersion(expected) end
|
||||||
os.reboot()
|
os.reboot()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
isUpdating = false
|
isUpdating = false
|
||||||
pendingMachineUpdate = false
|
pendingMachineUpdate = false
|
||||||
failedUpdateVersion = expectedMachineVersion
|
failedUpdateVersion = CFG.lua_versions and CFG.lua_versions.ticketmachine
|
||||||
pcall(drawVersionIndicator)
|
pcall(drawVersionIndicator)
|
||||||
end
|
end
|
||||||
sleep(UPDATE_CHECK_INTERVAL)
|
sleep(UPDATE_CHECK_INTERVAL)
|
||||||
|
|||||||
Reference in New Issue
Block a user