From 12e9ccbc8a8542bfd6e7df3e53ac30bfb29d4cc4 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Sun, 31 Oct 2021 08:32:27 +1100 Subject: [PATCH] feat(lua): update http link and version checking --- lua/wrapper.lua | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lua/wrapper.lua b/lua/wrapper.lua index f203856..5388689 100644 --- a/lua/wrapper.lua +++ b/lua/wrapper.lua @@ -5,13 +5,24 @@ CreateThread(function() local resource = GetCurrentResourceName() local url = GetResourceMetadata(resource, 'url', 0) local version = GetResourceMetadata(resource, 'version', 0) - local link = ('%s/releases/download/v%s/oxmysql-v%s.zip'):format(url, version, version) - PerformHttpRequest(('%s/main/fxmanifest.lua'):format(url:gsub('github.com', 'raw.githubusercontent.com')), function(error, response) + PerformHttpRequest(('%s/main/lua/fxmanifest.lua'):format(url:gsub('github.com', 'raw.githubusercontent.com')), function(error, response) if error == 200 then local latest = response:match('%d%.%d+%.%d+') if version ~= latest then - print(('^3Your version of oxmysql is outdated (%s) - please update to the latest version (%s)!\n ^3- %s^0'):format(version, latest, link)) + local curMajor, curMinor = string.strsplit('.', version) + local newMajor, newMinor = string.strsplit('.', response:match('%d%.%d+%.%d+')) + local link = ('%s/releases/download/v%s/oxmysql-v%s.zip'):format(url, latest, latest) + + if tonumber(curMajor) < tonumber(newMajor) then + latest = 'A major update' + elseif tonumber(curMinor) < tonumber(newMinor) then + latest = 'An update' + else + latest = 'A patch' + end + + print(('^3%s is available for oxmysql - please update to the latest release (current version: %s)\n ^3- %s^0'):format(latest, version, link)) end end end, 'GET')