mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-11-19 18:28:33 +00:00
fix(version): compare semver numbers
Values were being compared as whole strings.
This commit is contained in:
1 parent
8defbaf78f
commit
f5c5597277
2 files changed
+19
-8
No files matched your search
@@ -1,14 +1,20 @@
|
||||
function lib.checkDependency(resource, minimumVersion, printMessage)
|
||||
local currentVersion = GetResourceMetadata(resource, 'version', 0):match('%d%.%d+%.%d+')
|
||||
|
||||
if currentVersion < minimumVersion then
|
||||
if currentVersion ~= minimumVersion then
|
||||
local cv = { string.strsplit('.', currentVersion) }
|
||||
local mv = { string.strsplit('.', minimumVersion) }
|
||||
local msg = ("^1%s requires version '%s' of '%s' (current version: %s)^0"):format(GetInvokingResource() or GetCurrentResourceName(), minimumVersion, resource, currentVersion)
|
||||
|
||||
if printMessage then
|
||||
return print(msg)
|
||||
end
|
||||
for i = 1, #cv do
|
||||
if tonumber(cv[i]) < tonumber(mv[i]) then
|
||||
if printMessage then
|
||||
return print(msg)
|
||||
end
|
||||
|
||||
return false, msg
|
||||
return false, msg
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
|
||||
Reference in new issue
Block a user