-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.lua
More file actions
95 lines (78 loc) · 3.04 KB
/
Copy pathupdate.lua
File metadata and controls
95 lines (78 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
local GITHUB_REPO = 'RedAlex/character-manager'
local GITHUB_RELEASE_API = 'https://api.github.com/repos/' .. GITHUB_REPO .. '/releases/latest'
local GITHUB_RELEASES_URL = 'https://github.com/' .. GITHUB_REPO .. '/releases'
local function getCurrentVersion()
local resourceName = GetCurrentResourceName()
local version = GetResourceMetadata(resourceName, 'version', 0)
if not version then
version = GetResourceMetadata(resourceName, 'version')
end
return version or '0.0.0'
end
local function normalizeVersion(version)
if not version then
return '0.0.0'
end
local normalized = tostring(version):gsub('^[vV]', ''):match('([%d%.]+)')
return normalized or '0.0.0'
end
local function compareVersions(v1, v2)
local parts1 = {}
local parts2 = {}
for part in normalizeVersion(v1):gmatch('[^.]+') do
table.insert(parts1, tonumber(part) or 0)
end
for part in normalizeVersion(v2):gmatch('[^.]+') do
table.insert(parts2, tonumber(part) or 0)
end
local maxParts = math.max(#parts1, #parts2)
for i = 1, maxParts do
local p1 = parts1[i] or 0
local p2 = parts2[i] or 0
if p1 > p2 then
return 1
end
if p1 < p2 then
return -1
end
end
return 0
end
local function checkForUpdates()
if Config.EnableUpdateCheck == false then
return
end
PerformHttpRequest(GITHUB_RELEASE_API, function(errorCode, resultData)
if errorCode == 200 then
local success, response = pcall(json.decode, resultData)
if not success or not response then
print('^3[character-manager] Update check failed: invalid GitHub response^7')
return
end
local latestVersion = normalizeVersion(response.tag_name or response.name)
local currentVersion = normalizeVersion(getCurrentVersion())
local releaseUrl = response.html_url or GITHUB_RELEASES_URL
if compareVersions(latestVersion, currentVersion) > 0 then
print('^2========================================^7')
print('^3[character-manager] Update available!^7')
print('^1Current version: ^7' .. currentVersion)
print('^2Latest version: ^7' .. latestVersion)
print('^4Download: ^7' .. releaseUrl)
print('^2========================================^7')
else
print('^2[character-manager] Up to date (current: v' .. currentVersion .. ', latest: v' .. latestVersion .. ')^7')
end
elseif errorCode == 404 then
print('^3[character-manager] Update check skipped: no GitHub release found yet^7')
else
print('^3[character-manager] Update check failed (HTTP ' .. tostring(errorCode) .. ')^7')
end
end, 'GET', '', {
['User-Agent'] = 'character-manager-update-checker',
['Accept'] = 'application/vnd.github+json'
})
end
CreateThread(function()
Wait(2000)
checkForUpdates()
end)