fork/m-overlay

git clone https://git.julia.blue/fork/m-overlay

BkacjiosFinal update logic fixesf03565a

v2.1.4
2.1 KiB84 linesraw
1local downloader = require("downloader")
2
3function love.load(args, unfilteredArgs)
4	if love.filesystem.mount("application.love", "") then
5		_LAUNCHER = true
6		package.loaded.ssl = nil
7		package.loaded.https = nil
8		package.loaded.downloader = nil
9		package.loaded.main = nil
10		package.loaded.conf = nil
11		love.conf = nil
12		love.init()
13		love.load(args, unfilteredArgs)
14	else
15		love.install()
16	end
17end
18
19local STATUS = ""
20
21local DOWNLOAD_SIZE = 0
22local DOWNLOADED = 0
23
24function love.install()
25	downloader.download(
26		"https://github.com/bkacjios/m-overlay/releases/latest/download/application.love",
27		"application.love",
28
29		function(event)
30			if event.size then
31				DOWNLOAD_SIZE = event.size
32			elseif event.chunk then
33				DOWNLOADED = DOWNLOADED + event.chunk
34				STATUS = string.format("Downloading: %d%%", DOWNLOADED/DOWNLOAD_SIZE*100)
35			elseif event.code and event.code == 200 then
36				print("[UPDATER] Downloaded latest application.love")
37				love.event.quit("restart")
38			elseif event.error then
39				print(string.format("[UPDATER] Update error: %s", event.error))
40			end
41		end)
42end
43
44function love.update(dt)
45	downloader.update()
46end
47
48do
49	local icon = love.graphics.newImage("textures/icon.png")
50	local angleStart = math.pi * -0.5
51	local angleEnd = math.pi * 2
52	local font = love.graphics.newFont(12)
53
54	function love.draw()
55		local sw, sh = love.graphics.getPixelDimensions()
56
57		local w  = icon:getWidth()
58		local h = icon:getHeight()
59
60		local cx, cy = sw/2, sh/2-(sh/16)
61
62		love.graphics.setColor(1, 1, 1, 1)
63		love.graphics.draw(icon, cx, cy, 0, 0.5, 0.5, w/2, h/2)
64
65		local downloadAng = angleStart + (angleEnd * (DOWNLOADED/DOWNLOAD_SIZE))
66
67		love.graphics.setColor(34/255, 177/255, 76/255, 1)
68		love.graphics.setLineWidth(8)
69		love.graphics.arc("line", "open", cx, cy, sw/3, angleStart, downloadAng)
70
71		local width	= font:getWidth(STATUS)
72		local sy = sh-8-font:getHeight()
73
74		love.graphics.setFont(font)
75		love.graphics.setColor(0, 0, 0, 1)
76		love.graphics.print(STATUS, cx+1, sy+1, 0, 1, 1, width/2)
77		love.graphics.setColor(1, 1, 1, 1)
78		love.graphics.print(STATUS, cx, sy, 0, 1, 1, width/2)
79	end
80end
81
82function love.quit()
83	downloader.close()
84end