Skip to content

Commit 58de1e5

Browse files
committed
feat: Finalize App Platform detection
1 parent 38cb5db commit 58de1e5

File tree

6 files changed

+81
-21
lines changed

6 files changed

+81
-21
lines changed

src/Classes/SteamApp.luau

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ local SteamApp = {}
1010

1111
SteamApp.Interface = {}
1212

13-
function SteamApp.Interface.new(appID: number, name: string, library: string, location: string, platform: ("windows" | "linux")?, launchArguments: string?): SteamApp
13+
function SteamApp.Interface.new(
14+
appID: number,
15+
name: string,
16+
library: string,
17+
location: string,
18+
platform: ("windows" | "linux")?,
19+
launchArguments: string?
20+
): SteamApp
1421
-- Is the app configured to use STweaks ?
1522
local tweaksEnabled = false
1623
if launchArguments and launchArguments:find(Metadata.executable) then

src/Steam/Configuration.luau

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ type appmanifest_vdf = {
124124
},
125125
}
126126

127+
type compat_vdf = {
128+
platform_overrides: {
129+
[number]: {
130+
dest: "windows" | "linux",
131+
src: "windows" | "linux",
132+
},
133+
},
134+
}
135+
127136
-- STweaker
128137

129138
-- TODO
@@ -161,6 +170,18 @@ function Configuration.Public.getSteamConfiguration(): string?
161170
Logging.write("info", "User game configurations loaded.")
162171
Logging.separator()
163172

173+
--[[
174+
Chapter 2.5 : We recover compat.vdf to know if a game has ever used its Windows version.
175+
We can't use it directly to get the platform details, as games that have previously used Proton will still be set to "windows" here.
176+
Logically, a game completely absent from this list is a native Linux game.
177+
]]
178+
local compat_vdf: compat_vdf = Configuration.Private.VDFHandler(
179+
process.env.HOME .. "/.local/share/Steam/userdata/" .. activeUserSteamID3 .. "/config/compat.vdf",
180+
"Failed to parse compat.vdf file."
181+
)
182+
Logging.write("info", "Compatibility data loaded.")
183+
Logging.separator()
184+
164185
--[[
165186
Chapter 3 : We recover the Steam library config to get the list of games.
166187
We can't use just libraryfolders.vdf to get the game IDs, as Steam seems to not always update it immediately.
@@ -170,14 +191,13 @@ function Configuration.Public.getSteamConfiguration(): string?
170191
Logging.write("info", "Steam libraries loaded.")
171192
Logging.separator()
172193

173-
--print(userGameConfigurations, libraries)
174-
175194
local steamApps = {}
195+
local steamAppCount = 0
176196

177197
Async.asyncForEach(libraries.libraryfolders, function(_, library)
178198
-- We check if the folder exists
179199
if not fs.metadata(library.path).exists then
180-
Logging.write("warning", "Steam library " .. library.path .. " doesn't exist. Skipping...")
200+
Logging.write("warn", "Steam library " .. library.path .. " doesn't exist. Skipping...")
181201
else
182202
Logging.write("data", "Checking library " .. library.path)
183203
local appManifestFilenames = Filesystem.getFilenamePatternInDirectory(library.path .. "/steamapps", "appmanifest_")
@@ -188,22 +208,39 @@ function Configuration.Public.getSteamConfiguration(): string?
188208

189209
Logging.write("info", "Found " .. appManifest.AppState.appid .. " : " .. appManifest.AppState.name)
190210

211+
local location = library.path .. "/steamapps/common/" .. appManifest.AppState.installdir
212+
213+
-- Does the game have launch options set ?
191214
local configuration = userGameConfigurations[appManifest.AppState.appid]
192215
local launchOptions
193216
if configuration then
194217
launchOptions = configuration.LaunchOptions
195218
end
196219

197-
local steamApp = SteamApp.new(
198-
appManifest.AppState.appid,
199-
appManifest.AppState.name,
200-
library.path,
201-
library.path .. "/steamapps/common/" .. appManifest.AppState.installdir,
202-
appManifest.AppState.MountedConfig.platform_override_source,
203-
launchOptions
204-
)
220+
-- Do we know the game's platform
221+
local osPlatform: ("windows" | "linux")? = appManifest.AppState.MountedConfig.platform_override_source
222+
if not osPlatform then
223+
local compat = compat_vdf.platform_overrides[appManifest.AppState.appid]
224+
-- The app being absent from the compat.vdf list means it can only be a native Linux game
225+
if not compat then
226+
osPlatform = "linux"
227+
else
228+
-- Gah ! We still don't have the platform... time to check manually.
229+
Logging.write(
230+
"warn",
231+
"Platform not found for " .. appManifest.AppState.appid .. " : " .. appManifest.AppState.name .. ". Using manual check..."
232+
)
233+
if not Filesystem.directoryContainsLinuxData(location) then
234+
osPlatform = "windows"
235+
else
236+
osPlatform = "linux"
237+
end
238+
end
239+
end
205240

206-
table.insert(steamApps, steamApp)
241+
local steamApp = SteamApp.new(appManifest.AppState.appid, appManifest.AppState.name, library.path, location, osPlatform, launchOptions)
242+
steamApps[steamApp.appID] = steamApp
243+
steamAppCount += 1
207244
end)
208245
end
209246
end)
@@ -212,6 +249,8 @@ function Configuration.Public.getSteamConfiguration(): string?
212249

213250
print(steamApps)
214251

252+
Logging.write("info", "Loaded " .. steamAppCount .. " Steam apps.")
253+
215254
return
216255
end
217256

src/Utilities/Filesystem.luau

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,21 @@ function Filesystem.getFilenamePatternInDirectory(directory: string, pattern: st
8989
return result
9090
end
9191

92+
function Filesystem.directoryContainsLinuxData(path: string): boolean
93+
local files = fs.readDir(path)
94+
for _, file in ipairs(files) do
95+
if file:find(".sh") or not file:find(".") and not fs.isDir(path) then
96+
file = path .. "/" .. file
97+
98+
Logging.write("data", "Checking file " .. file)
99+
local contents = fs.readFile(file)
100+
101+
if contents:find("Linux") or contents:find("shell") then
102+
return true
103+
end
104+
end
105+
end
106+
return false
107+
end
108+
92109
return Filesystem

src/Utilities/Logging.luau

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
type LogColor = "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "grey" | "orange" | "reset"
2-
type LogType = "info" | "warning" | "error" | "debug" | "download" | "data" | "speed" | "special"
2+
type LogType = "info" | "warn" | "error" | "debug" | "data" | "speed" | "special"
33

44
--[=[
55
@class Utilities.Logging
@@ -27,18 +27,15 @@ function Logging.Public.write(type: LogType, message: string | number)
2727
info = function(text)
2828
print(time .. " - [" .. color("blue", "Info") .. "] : " .. text)
2929
end,
30-
warning = function(text)
31-
print(time .. " - [" .. color("yellow", "Warning") .. "] : " .. color("yellow", text))
30+
warn = function(text)
31+
print(time .. " - [" .. color("yellow", "Warn") .. "] : " .. color("yellow", text))
3232
end,
3333
error = function(text)
3434
print(time .. " - " .. color("red", "[Error] : " .. text))
3535
end,
3636
debug = function(text)
3737
print(time .. " - [" .. color("grey", "Debug") .. "] : " .. color("grey", text))
3838
end,
39-
download = function(text)
40-
print(time .. " - [" .. color("green", "Download") .. "] : " .. text)
41-
end,
4239
data = function(text)
4340
print(time .. " - [" .. color("magenta", "Data") .. "] : " .. text)
4441
end,

src/init.luau

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function Application.start()
2727

2828
-- Development version detection
2929
if metadata.version:find("dev") then
30-
Logging.write("warning", "This is a development version of " .. metadata.name .. " !")
30+
Logging.write("warn", "This is a development version of " .. metadata.name .. " !")
3131
Logging.separator()
3232
-- Put the arguments inside the cache folder for testing purposes
3333
fs.writeFile(metadata.folders.cache .. "/arguments.txt", table.concat(process.args, "\n"))

stylua.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
column_width = 175
1+
column_width = 160
22
line_endings = "Unix"
33
indent_type = "Tabs"
44
indent_width = 4

0 commit comments

Comments
 (0)