mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 15:06:02 +01:00
Rather than throwing potentially fatal and confusing errors we should just report the current version as 'unknown'.
27 lines
966 B
Lua
27 lines
966 B
Lua
function lib.checkDependency(resource, minimumVersion, printMessage)
|
|
local currentVersion = GetResourceMetadata(resource, 'version', 0)
|
|
currentVersion = currentVersion and currentVersion:match('%d+%.%d+%.%d+') or 'unknown'
|
|
|
|
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)
|
|
|
|
for i = 1, #cv do
|
|
local current, minimum = tonumber(cv[i]), tonumber(mv[i])
|
|
|
|
if current ~= minimum then
|
|
if not current or current < minimum then
|
|
if printMessage then
|
|
return print(msg)
|
|
end
|
|
|
|
return false, msg
|
|
else break end
|
|
end
|
|
end
|
|
end
|
|
|
|
return true
|
|
end
|