diff --git a/src/VERSION.lua b/src/VERSION.lua index 6d24405..7d04e2d 100644 --- a/src/VERSION.lua +++ b/src/VERSION.lua @@ -1,6 +1,7 @@ --!strict -- LOCAL local VERSION = {} +local hasFetchedLatestVersion = false @@ -11,28 +12,31 @@ VERSION.latestVersion = nil :: string? -- FUNCTIONS +local function isNewerVersion(latest: string, current: string): boolean + local latestParts = string.split(string.match(latest, "(%d+%.%d+%.%d+)") or "", ".") + local currentParts = string.split(string.match(current, "(%d+%.%d+%.%d+)") or "", ".") + for index = 1, 3 do + local latestPart, currentPart = tonumber(latestParts[index]) or 0, tonumber(currentParts[index]) or 0 + if latestPart ~= currentPart then + return latestPart > currentPart + end + end + return false +end + function VERSION.getLatestVersion(): string? - local DEVELOPMENT_PLACE_ID = 117501901079852 - local latestVersion = VERSION.latestVersion - if latestVersion then - return latestVersion + if hasFetchedLatestVersion then + return VERSION.latestVersion end - local placeName = "" - while true do - local success, hdDevelopmentDetails = pcall(function() - return game:GetService("MarketplaceService"):GetProductInfoAsync(DEVELOPMENT_PLACE_ID) - end) - if success and hdDevelopmentDetails then - placeName = hdDevelopmentDetails.Name - break - end - task.wait(1) + hasFetchedLatestVersion = true + local success, result = pcall(function() + return game:GetService("MarketplaceService"):GetProductInfoAsync(92368439343389) + end) + if success and result then + local versionNumbers = string.match(result.Name, "v(%d+%.%d+%.%d+)") + VERSION.latestVersion = if versionNumbers then "v"..versionNumbers else nil end - -- Roblox translates the place name for different languages so only the digits can be trusted - local versionNumbers = string.match(placeName, "(%d+%.%d+%.%d+)") - latestVersion = if versionNumbers then "v"..versionNumbers else nil - VERSION.latestVersion = latestVersion - return latestVersion + return VERSION.latestVersion end function VERSION.getAppVersion() @@ -41,8 +45,7 @@ end function VERSION.isUpToDate() local latestVersion = VERSION.getLatestVersion() - local appVersion = VERSION.getAppVersion() - return latestVersion ~= nil and latestVersion == appVersion + return latestVersion == nil or not isNewerVersion(latestVersion, VERSION.getAppVersion()) end