-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.lua
executable file
·130 lines (114 loc) · 4.43 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
--- for macos we need to append the source directory to use our .so file in
-- the exported version
if love.system.getOS() == 'OS X' and love.filesystem.isFused() then
package.cpath = package.cpath .. ';' .. love.filesystem.getSourceBaseDirectory() .. '/?.so'
end
-- for debugging, use love 12 so that https is automatically available in the correct location
-- by tying the inner loop to runInternal it can be overwritten later on
local loveRun = love.run
function love.run()
love.runInternal = loveRun()
return function()
if love.runInternal then
local shouldQuit, restartArg = love.runInternal()
if shouldQuit then
return shouldQuit, restartArg
end
end
end
end
if os.getenv("LOCAL_LUA_DEBUGGER_VSCODE") == "1" then
require("lldebugger").start()
end
--require("updater.tests.tests")
local logger = require("updater.logger")
local love_errorhandler = love.errorhandler
GAME_UPDATER_STATES = { idle = 0, checkingForUpdates = 1, downloading = 2}
GAME_UPDATER = require("updater.gameUpdater")
local loadingIndicator = require("loadingIndicator")
local bigFont = love.graphics.newFont(24)
local updateString = ""
local stuck = false
function love.load(args)
loadingIndicator:setDrawPosition(love.graphics:getDimensions())
loadingIndicator:setFont(bigFont)
GAME_UPDATER:registerCallback(function(version)
-- if we downloaded something we want to use it
GAME_UPDATER.activeVersion = version
-- clear for later use by the actual game
GAME_UPDATER.onDownloadedCallbacks = {}
end)
GAME_UPDATER:init()
GAME_UPDATER:getAvailableVersions(GAME_UPDATER.activeReleaseStream)
end
function love.update(dt)
GAME_UPDATER:update()
if GAME_UPDATER.state ~= GAME_UPDATER_STATES.idle then
if GAME_UPDATER.state == GAME_UPDATER_STATES.checkingForUpdates then
updateString = "Checking for updates..."
else
updateString = "Downloading new version..."
end
elseif love.restart and love.restart.restartSource == "updater" then
updateString = "Something went wrong while trying to start game file " .. (love.restart.startUpFile or "")
stuck = true
love.restart = nil
loadingIndicator.draw = function () end
else
if not stuck then
if GAME_UPDATER:updateAvailable(GAME_UPDATER.activeReleaseStream) then
-- auto update
logger:log("New update available")
table.sort(GAME_UPDATER.activeReleaseStream.availableVersions, function(a,b) return a.version > b.version end)
GAME_UPDATER:downloadVersion(GAME_UPDATER.activeReleaseStream.availableVersions[1])
else
logger:log("No updates available")
if GAME_UPDATER.activeVersion then
local v = GAME_UPDATER.activeVersion
-- if the active version is an embedded version, we got to copy it to the save directory first
-- otherwise it won't be mountable
if love.filesystem.getRealDirectory(v.path) ~= love.filesystem.getSaveDirectory() then
love.filesystem.createDirectory(GAME_UPDATER.path .. v.releaseStream.name .. "/" .. tostring(v.version))
local file = love.filesystem.read(v.path)
love.filesystem.write(v.path, file)
end
GAME_UPDATER:launch(GAME_UPDATER.activeVersion)
else
if GAME_UPDATER.activeReleaseStream.name == GAME_UPDATER.defaultReleaseStream.name then
updateString = "No version available.\nPlease check your internet connection and try again."
stuck = true
loadingIndicator.draw = function () end
pcall(logger.write, logger)
else
GAME_UPDATER.activeReleaseStream = GAME_UPDATER.defaultReleaseStream
local latest = GAME_UPDATER.getLatestInstalledVersion(GAME_UPDATER.defaultReleaseStream)
if latest then
GAME_UPDATER.activeVersion = latest
end
end
end
end
end
end
end
local width, height = love.graphics.getDimensions()
function love.draw()
love.graphics.printf(updateString, bigFont, 0, height / 2 - 12, width, "center")
loadingIndicator:draw()
end
function love.errorhandler(msg)
--if lldebugger then
-- error(msg, 2)
--else
logger:log(msg)
pcall(logger.write, logger)
return love_errorhandler(msg)
--end
end
function love.threaderror(thread, errorstr)
logger:log("Thread error!\n"..errorstr)
-- thread:getError() will return the same error string now.
end
function love.quit(args)
pcall(logger.write, logger)
end