Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 24 additions & 21 deletions src/VERSION.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
--!strict
-- LOCAL
local VERSION = {}
local hasFetchedLatestVersion = false



Expand All @@ -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()
Expand All @@ -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


Expand Down
Loading