Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added version checker #117

Merged
merged 3 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ server_scripts {
'server/chemicals.lua',
'server/lisenceshop.lua',
'server/moneywash.lua',
'server/versioncheck.lua'
}

client_scripts {
Expand Down
45 changes: 45 additions & 0 deletions server/versioncheck.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
local function versionCheck(repository)
local resource = GetInvokingResource() or GetCurrentResourceName()

local currentVersion = GetResourceMetadata(resource, 'version', 0)

if currentVersion then
currentVersion = currentVersion:match('%d+%.%d+%.%d+')
end

if not currentVersion then return print(("^1Unable to determine current resource version for '%s' ^0"):format(resource)) end

SetTimeout(1000, function()
PerformHttpRequest(('https://api.github.com/repos/%s/releases/latest'):format(repository), function(status, response)
if status ~= 200 then return end

response = json.decode(response)

if response.prerelease then return end

local latestVersion = response.tag_name:match('%d+%.%d+%.%d+')
if not latestVersion or latestVersion == currentVersion then return end

local cv = { string.strsplit('.', currentVersion) }
local lv = { string.strsplit('.', latestVersion) }

for i = 1, #cv do
local current, minimum = tonumber(cv[i]), tonumber(lv[i])
if current ~= minimum then
if current < minimum then

print("^0.-----------------------------------------------.")
print("^0| Project Sloth |")
print("^0'-----------------------------------------------'")
print(('^6Your %s is outdated (your version: %s)\r\nMake sure to update: %s^0'):format(resource, currentVersion, response.html_url))
print('^2'..response.body:gsub("\r\n\r\n\r", "^0"))


else break end
end
end
end, 'GET')
end)
end

versionCheck('Project-Sloth/ps-drugprocessing')