2025-03-18 18:46:09 +11:00
--[[
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 >
2025-03-29 21:44:03 +11:00
Copyright © 2025 Linden < https : // github.com / thelindat >
2025-03-18 18:46:09 +11:00
] ]
2022-04-19 01:09:22 +10:00
function lib . checkDependency ( resource , minimumVersion , printMessage )
2023-06-13 00:36:17 +10:00
local currentVersion = GetResourceMetadata ( resource , ' version ' , 0 )
currentVersion = currentVersion and currentVersion : match ( ' %d+%.%d+%.%d+ ' ) or ' unknown '
2022-02-28 02:40:25 +00:00
2022-08-22 20:53:55 +10:00
if currentVersion ~= minimumVersion then
2022-09-29 17:14:11 +10:00
local cv = { string.strsplit ( ' . ' , currentVersion ) }
local mv = { string.strsplit ( ' . ' , minimumVersion ) }
2022-08-23 19:29:45 +10:00
local msg = ( " ^1%s requires version '%s' of '%s' (current version: %s)^0 " ) : format ( GetInvokingResource ( ) or GetCurrentResourceName ( ) , minimumVersion , resource , currentVersion )
2022-09-29 17:14:11 +10:00
for i = 1 , # cv do
local current , minimum = tonumber ( cv [ i ] ) , tonumber ( mv [ i ] )
if current ~= minimum then
2023-06-13 00:36:17 +10:00
if not current or current < minimum then
2022-09-29 17:14:11 +10:00
if printMessage then
return print ( msg )
end
return false , msg
else break end
end
2022-08-22 20:53:55 +10:00
end
2022-02-28 02:40:25 +00:00
end
return true
end