mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 23:16:03 +01:00
Comparing "2.7.4" to "2.10.1" would compare each number, i.e. 2 = 2, 7 < 10, 4 > 1 Instead compare the major (2 v 2), then minor.patch (7.4 v 10.1). where doka to do my math
20 lines
699 B
Lua
20 lines
699 B
Lua
function lib.checkDependency(resource, minimumVersion, printMessage)
|
|
local currentVersion = GetResourceMetadata(resource, 'version', 0):match('%d%.%d+%.%d+')
|
|
|
|
if currentVersion ~= minimumVersion then
|
|
local cMajor, cMinor = string.strsplit('.', currentVersion, 2)
|
|
local mMajor, mMinor = string.strsplit('.', minimumVersion, 2)
|
|
|
|
local msg = ("^1%s requires version '%s' of '%s' (current version: %s)^0"):format(GetInvokingResource() or GetCurrentResourceName(), minimumVersion, resource, currentVersion)
|
|
if tonumber(cMajor) < tonumber(mMajor) or tonumber(cMinor) < tonumber(mMinor) then
|
|
if printMessage then
|
|
return print(msg)
|
|
end
|
|
|
|
return false, msg
|
|
end
|
|
end
|
|
|
|
return true
|
|
end
|