Files
ox_lib/resource/version/shared.lua
Linden fb2225e373 chore: add copyright notices to each file
Some people accidentally, mistakenly, and without any malicious intent forget to attribute code from this resource to its source. This change will hopefully assist people, so that they do not make that mistake again.
2025-03-18 18:46:09 +11:00

35 lines
1.2 KiB
Lua

--[[
https://github.com/overextended/ox_lib
This file is licensed under LGPL-3.0 or higher <https://www.gnu.org/licenses/lgpl-3.0.en.html>
Copyright (c) 2025 Linden <https://github.com/thelindat/fivem>
]]
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