-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.lua
131 lines (105 loc) · 4.04 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
131
-- Startup time
local totalStartupTimeVar = os.clock()
-- Internal Modules
local logSystem = require("modules.general.logSystem")
local fsUtils = require("modules.general.fsUtils")
local systemUtils = require("modules.general.systemUtils")
local steamUtils = require("modules.steam.steamUtils")
local programMetadata = require("modules.extra.programMetadata")
local gameLauncher = require("modules.gameLauncher")
if programMetadata.version:find("dev") then
logSystem.log("warning", "DEVELOPMENT VERSION")
end
--[[
Chapter 0 : Preparing the environment
We need to create the config folder if it doesn't exist.
]]
-- Create the config folder if it doesn't exist
fsUtils.createOrUseDirectory(programMetadata.folders.config)
-- And the games folder inside of it
fsUtils.createOrUseDirectory(programMetadata.folders.gamesConfig)
-- Create the cache folder if it doesn't exist
fsUtils.createOrUseDirectory(programMetadata.folders.cache)
-- Put the arguments inside the cache folder for testing purposes
local cacheFile = io.open(programMetadata.folders.cache.."/lastArguments.txt", "w")
if not cacheFile then
logSystem.log("error", "Unable to open cache file.")
else
cacheFile:write(table.concat(arg, "\n"))
cacheFile:close()
end
--[[
Chapter 1 : Game management
What's the Steam config ? Is this being started through Steam or alone ? What to do ?!
]]
-- We retrieve games registered in Steam.
local steamGames = require("modules.steam.steamConfigProvider")
collectgarbage("collect")
-- We check if we're starting a Steam game or not through the arguments.
local gameStartStatus = steamUtils.isSteamArgs(arg)
if gameStartStatus == "steamGame" then
local game = steamGames[arg[3]:gsub("AppId=", "")]
-- We notify the user that SimpleSteamTinker is running.
logSystem.log("info", "Starting "..game.name.."...")
systemUtils.sendNotification(programMetadata.name.." is starting...", "Detected "..game.name, "information")
-- For every argument that is a path, we put \ next to the spaces
for i, v in ipairs(arg) do
if fsUtils.exists(v) then
arg[i] = v:gsub(" ", "\\ ")
end
end
-- We prepare the command
local command = table.concat(arg, " ")
logSystem.log("info", "Applying settings for "..game.name.."...")
command = gameLauncher.prepareGameLaunch(game, command)
if os.execute(command) then
os.exit(0)
else
systemUtils.sendNotification(programMetadata.name.." crashed !", "Something bad happened while running "..game.name..".", "error")
os.exit(1)
end
elseif gameStartStatus == "SteamTinkerLaunch" or (arg[3] and steamGames[arg[3]:gsub("AppId=", "")].status == "SteamTinkerLaunch") then
-- We notify the user that SteamTinkerLaunch is running.
logSystem.log("error", "Can't use "..programMetadata.name.." ! SteamTinkerLaunch detected.")
systemUtils.sendNotification("Can't use "..programMetadata.name.." !", "SteamTinkerLaunch detected.", "warning")
-- For every argument that is a path, we put \ next to the spaces
for i, v in ipairs(arg) do
if fsUtils.exists(v) then
arg[i] = v:gsub(" ", "\\ ")
end
end
-- We prepare the command
local command = table.concat(arg, " ")
os.execute(command)
os.exit(0)
end
logSystem.log("info", "No game to be launched detected. Launching interface...")
--[[
Chapter 2 : The main window
No games started. Time to cook some Libadwaita goodness then.
]]
-- External Modules
local lgi = require("lgi")
local Adw = lgi.Adw
-- Application
local app = Adw.Application({
application_id = programMetadata.developer.."."..programMetadata.name,
})
-- Sort Steam games alphabetically
local newSteamGamesTable = {}
for _, v in pairs(steamGames) do
table.insert(newSteamGamesTable, v)
end
table.sort(newSteamGamesTable, function(a, b) return a.name < b.name end)
steamGames = newSteamGamesTable
-- Time to start the application
local timeStart = os.clock()
function app:on_startup()
require("modules.ui.mainWindow")(app, steamGames)
end
function app:on_activate()
logSystem.log("speed", timeStart)
logSystem.log("info", "Startup time : "..os.clock()-totalStartupTimeVar.." seconds.")
self.active_window:present()
end
return app:run(arg)