@@ -9,9 +9,39 @@ local SteamUtilities = require("./Utilities")
99local  VDFParser  =  require ("./VDFParser" )
1010local  SteamApp  =  require ("../Classes" ).SteamApp 
1111
12+ local  function  VDFHandler (filePath :  string , errorMessage :  string , logging :  boolean ? ): any 
13+ 	if  logging  ==  nil  then 
14+ 		logging  =  true 
15+ 	end 
16+ 
17+ 	local  timeStart 
18+ 	if  logging  then 
19+ 		timeStart  =  os.clock ()
20+ 		Logging .write ("data" , "Parsing VDF file : "  ..  filePath )
21+ 	end 
22+ 
23+ 	local  result , parsedData  =  pcall (VDFParser .parseFile , filePath )
24+ 	if  not  result  then 
25+ 		error (errorMessage )
26+ 	else 
27+ 		if  logging  then 
28+ 			Logging .write ("speed" , timeStart )
29+ 		end 
30+ 		return  parsedData 
31+ 	end 
32+ end 
33+ 
34+ local  function  getMostRecentUserID (userData :  loginusers_vdf ): number 
35+ 	for  id , data  in  pairs (userData .users ) do 
36+ 		if  data .MostRecent  ==  1  then 
37+ 			return  id 
38+ 		end 
39+ 	end 
40+ 	error ("No most recent user found in loginusers.vdf. What ?!" )
41+ end 
42+ 
1243-- --------------------------- Definitions ----------------------------- 
1344
14- -- Steam files 
1545-- Note : Most of the entries are unused and simply for informative purposes. 
1646
1747type  loginusers_vdf  =  {
@@ -137,19 +167,14 @@ type compat_vdf = {
137167
138168local  Configuration  =  {}
139169
140- Configuration .Private  =  {}
141- Configuration .Public  =  {}
142- 
143- -- Public 
144- 
145- function  Configuration .Public .getSteamConfiguration ()
170+ function  Configuration .getSteamConfiguration ()
146171	--[[ 
147172		Chapter 1 : We recover the Steam user config so we can get the last active user. 
148173		And also the SteamID3 to access their settings folder. 
149174	]] 
150175	local  userConfiguration :  loginusers_vdf  = 
151- 		Configuration . Private . VDFHandler (process .env .HOME  ..  "/.local/share/Steam/config/loginusers.vdf" , "Failed to parse loginusers.vdf file." )
152- 	local  activeUserSteamID3  =  SteamUtilities .convertToSteamID3 (Configuration . Private . getMostRecentUserID (userConfiguration ))
176+ 		VDFHandler (process .env .HOME  ..  "/.local/share/Steam/config/loginusers.vdf" , "Failed to parse loginusers.vdf file." )
177+ 	local  activeUserSteamID3  =  SteamUtilities .convertToSteamID3 (getMostRecentUserID (userConfiguration ))
153178	Logging .write ("info" , "Active user SteamID3 : "  ..  activeUserSteamID3 )
154179	Logging .separator ()
155180
@@ -158,7 +183,7 @@ function Configuration.Public.getSteamConfiguration()
158183
159184		Note : Error handling should be added for the scenario where the configuration can't be loaded. 
160185	]] 
161- 	local  localconfig_vdf :  localconfig_vdf  =  Configuration . Private . VDFHandler (
186+ 	local  localconfig_vdf :  localconfig_vdf  =  VDFHandler (
162187		process .env .HOME  ..  "/.local/share/Steam/userdata/"  ..  activeUserSteamID3  ..  "/config/localconfig.vdf" ,
163188		"Failed to parse active user localconfig.vdf file with SteamID3: "  ..  activeUserSteamID3 
164189	)
@@ -171,7 +196,7 @@ function Configuration.Public.getSteamConfiguration()
171196		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. 
172197		Logically, a game completely absent from this list is a native Linux game. 
173198	]] 
174- 	local  compat_vdf :  compat_vdf  =  Configuration . Private . VDFHandler (
199+ 	local  compat_vdf :  compat_vdf  =  VDFHandler (
175200		process .env .HOME  ..  "/.local/share/Steam/userdata/"  ..  activeUserSteamID3  ..  "/config/compat.vdf" ,
176201		"Failed to parse compat.vdf file." 
177202	)
@@ -183,7 +208,7 @@ function Configuration.Public.getSteamConfiguration()
183208		We can't use just libraryfolders.vdf to get the game IDs, as Steam seems to not always update it immediately. 
184209	]] 
185210	local  libraries :  libraryfolders_vdf  = 
186- 		Configuration . Private . VDFHandler (process .env .HOME  ..  "/.local/share/Steam/config/libraryfolders.vdf" , "Failed to parse libraryfolders.vdf file." )
211+ 		VDFHandler (process .env .HOME  ..  "/.local/share/Steam/config/libraryfolders.vdf" , "Failed to parse libraryfolders.vdf file." )
187212	Logging .write ("info" , "Steam libraries loaded." )
188213	Logging .separator ()
189214
@@ -200,7 +225,7 @@ function Configuration.Public.getSteamConfiguration()
200225
201226			Async .asyncForEach (appManifestFilenames , function (_ , appManifestFilename )
202227				local  appManifestPath :  string  =  library .path  ..  "/steamapps/"  ..  appManifestFilename 
203- 				local  appManifest :  appmanifest_vdf  =  Configuration . Private . VDFHandler (appManifestPath , "Failed to parse "  ..  appManifestPath  ..  "." , false )
228+ 				local  appManifest :  appmanifest_vdf  =  VDFHandler (appManifestPath , "Failed to parse "  ..  appManifestPath  ..  "." , false )
204229
205230				Logging .write ("info" , 'Found "'  ..  appManifest .AppState .name  ..  '" ('  ..  appManifest .AppState .appid  ..  ")" )
206231
@@ -247,39 +272,4 @@ function Configuration.Public.getSteamConfiguration()
247272	return  steamApps 
248273end 
249274
250- -- Private 
251- 
252- function  Configuration .Private .VDFHandler (filePath :  string , errorMessage :  string , logging :  boolean ? ): any 
253- 	if  logging  ==  nil  then 
254- 		logging  =  true 
255- 	end 
256- 
257- 	local  timeStart 
258- 	if  logging  then 
259- 		timeStart  =  os.clock ()
260- 		Logging .write ("data" , "Parsing VDF file : "  ..  filePath )
261- 	end 
262- 
263- 	local  result , parsedData  =  pcall (VDFParser .parseFile , filePath )
264- 	if  not  result  then 
265- 		error (errorMessage )
266- 	else 
267- 		if  logging  then 
268- 			Logging .write ("speed" , timeStart )
269- 		end 
270- 		return  parsedData 
271- 	end 
272- end 
273- 
274- -- loginuser.vdf 
275- 
276- function  Configuration .Private .getMostRecentUserID (userData :  loginusers_vdf ): number 
277- 	for  id , data  in  pairs (userData .users ) do 
278- 		if  data .MostRecent  ==  1  then 
279- 			return  id 
280- 		end 
281- 	end 
282- 	error ("No most recent user found in loginusers.vdf. What ?!" )
283- end 
284- 
285- return  Configuration .Public 
275+ return  Configuration 
0 commit comments