Skip to content

Commit

Permalink
Final update logic fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bkacjios committed Dec 25, 2022
1 parent 7e0ab3b commit f03565a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 22 deletions.
1 change: 1 addition & 0 deletions launcher/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local downloader = require("downloader")

function love.load(args, unfilteredArgs)
if love.filesystem.mount("application.love", "") then
_LAUNCHER = true
package.loaded.ssl = nil
package.loaded.https = nil
package.loaded.downloader = nil
Expand Down
2 changes: 1 addition & 1 deletion release.bat
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ copy /b %LOVE_DIR%\love.exe+,, %BUILD_DIR%

echo Customizing love.exe
rcedit-x64 "%BUILD_DIR%\love.exe" --set-icon "%INSTALLER_DIR%\icon.ico"
rcedit-x64 "%BUILD_DIR%\love.exe" --set-version-string "FileDescription" "M'Overlay"
rcedit-x64 "%BUILD_DIR%\love.exe" --set-file-version "%VERSION%"
rcedit-x64 "%BUILD_DIR%\love.exe" --set-version-string "FileDescription" "M'Overlay"
rcedit-x64 "%BUILD_DIR%\love.exe" --set-version-string "InternalName" "%NAME%-%BIT%"
rcedit-x64 "%BUILD_DIR%\love.exe" --set-version-string "OriginalFilename" "%EXE_NAME%"

Expand Down
2 changes: 1 addition & 1 deletion release.iss
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
;#define AppBuild
;#define AppVersion GetVersionComponents("build/x64/m-overlay-x64.exe", AppMajor, AppMinor, AppRevision, AppBuild)
;#define AppVersion Str(AppMajor) + "." + Str(AppMinor) + "." + Str(AppRevision)
#define AppVersion 2.1.0
#define AppVersion "2.1.0"
PrivilegesRequired=lowest
DisableWelcomePage=no
AppName={#AppName}
Expand Down
28 changes: 18 additions & 10 deletions source/modules/gui/panels/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local json = require("serializer.json")
local notification = require("notification")
local music = require("music")
local overlay = require("overlay")
local updater = require("updater")

require("extensions.math")

Expand Down Expand Up @@ -340,15 +341,20 @@ This is also the same directory you use to place all your music for Melee.]])
self.ABOUT = self.MAIN:AddTab("About", "textures/icon.png")
self.ABOUT:SetBackgroundColor(color_purple)

local updater = require("updater")

self.ABOUT.LEFT = self.ABOUT:Add("Panel")
self.ABOUT.LEFT:SetDrawPanel(false)
self.ABOUT.LEFT:Dock(DOCK_LEFT)
self.ABOUT.LEFT:SetWidth(160)

self.ABOUT.LEFT.Paint = function(this, w, h)
updater.draw(w,h)
if _LAUNCHER then
self.ABOUT.LEFT.Paint = function(this, w, h)
updater.draw(w,h)
end
else
local ICON = self.ABOUT.LEFT:Add("Image")
ICON:Dock(DOCK_FILL)
ICON:DockMargin(32, 32, 32, 32)
ICON:SetImage("textures/icon.png")
end

self.ABOUT.RIGHT = self.ABOUT:Add("Panel")
Expand All @@ -365,13 +371,15 @@ This is also the same directory you use to place all your music for Melee.]])
love.system.openURL(("https://github.com/bkacjios/m-overlay/releases/tag/v%s"):format(love.getMOverlayVersion()))
end

local UPDATE = self.ABOUT.RIGHT:Add("ButtonIcon")
UPDATE:SetImage("textures/gui/wrench.png")
UPDATE:SetText("Check for update")
UPDATE:Dock(DOCK_TOP)
if _LAUNCHER then
local UPDATE = self.ABOUT.RIGHT:Add("ButtonIcon")
UPDATE:SetImage("textures/gui/wrench.png")
UPDATE:SetText("Check for update")
UPDATE:Dock(DOCK_TOP)

function UPDATE:OnClick()
updater.check()
function UPDATE:OnClick()
updater.check()
end
end

self.ABOUT.SOCIALS = self.ABOUT.RIGHT:Add("Panel")
Expand Down
26 changes: 16 additions & 10 deletions source/modules/updater.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@ local DOWNLOADED = 0

local STATUS = ""

local function splitVersion(tag)
local function versionNumber(tag)
-- Split into: major, minor, revision, hotfix
if not tag then
return 0, 0, 0, 0, ""
return -1
end
local maj, min, rev, hot = tag:match("v?(%d+)%.(%d+)%.(%d+)(%a?)")
return tonumber(maj), tonumber(min), tonumber(rev), hot
local maj, min, rev, hot = tag:lower():match("v?(%d+)%.(%d+)%.(%d+)(%a?)")
if not maj then
return -1
end
local hotfix = 0
if hot and #hot > 0 then
-- 97 = a
hotfix = string.byte(hot) - 96
end
return (tonumber(maj) * 10000) + (tonumber(min) * 1000) + (tonumber(rev) * 100) + hotfix
end

do
Expand Down Expand Up @@ -54,20 +62,18 @@ do
end

function updater.check()
local version = love.getMOverlayVersion()

if version == "0.0.0" then return end
local version = versionNumber(love.getMOverlayVersion())

local maj, min, rev, hot = splitVersion(version)
if version <= 0 then return end

STATUS = "Checking for update.."

web.get("https://api.github.com/repos/bkacjios/m-overlay/releases/latest", function(event)
if event.success and event.code == 200 then
local response = json.decode(event.response)
if (response.tag_name) then
local rmaj, rmin, rrev, rhot = splitVersion(response.tag_name)
if rmaj > maj or rmin > min or rev > rrev or rhot > hot then
local updateVersion = versionNumber(response.tag_name)
if updateVersion > 0 and updateVersion > version then
log.warn("[UPDATER] Application update available")
for id, asset in pairs(response.assets) do
if asset.name == "application.love" then
Expand Down

0 comments on commit f03565a

Please sign in to comment.