22using System . Collections . Generic ;
33using System . Diagnostics . CodeAnalysis ;
44using System . IO . Abstractions ;
5- using System . Linq ;
65using Microsoft . Extensions . DependencyInjection ;
76using Microsoft . Extensions . Logging ;
87using PG . StarWarsGame . Infrastructure . Games ;
@@ -62,7 +61,7 @@ public bool TryDetect(GameType gameType, ICollection<GamePlatform> platforms, ou
6261 }
6362 catch ( Exception e )
6463 {
65- Logger ? . LogWarning ( e , "Unable to find any games, due to error in detection." ) ;
64+ Logger ? . LogDebug ( e , "Unable to find any games, due to error in detection." ) ;
6665 result = GameDetectionResult . NotInstalled ( gameType ) ;
6766 return false ;
6867 }
@@ -77,7 +76,7 @@ public GameDetectionResult Detect(GameType gameType, params ICollection<GamePlat
7776
7877 if ( ! locationData . IsInstalled )
7978 {
80- Logger ? . LogInformation ( $ "Unable to find an installed game of type { gameType } .") ;
79+ Logger ? . LogTrace ( $ "Unable to find an installed game of type { gameType } .") ;
8180 return GameDetectionResult . NotInstalled ( gameType ) ;
8281 }
8382
@@ -92,20 +91,20 @@ public GameDetectionResult Detect(GameType gameType, params ICollection<GamePlat
9291 // the detector returned a false result.
9392 if ( ! GameExeExists ( location , gameType ) || ! DataAndMegaFilesXmlExists ( location ) )
9493 {
95- Logger ? . LogDebug ( $ "Unable to find the game's executable or megafiles.xml at the given location: { location . FullName } ") ;
94+ Logger ? . LogTrace ( $ "Unable to find the game's executable or megafiles.xml at the given location: { location . FullName } ") ;
9695 return GameDetectionResult . NotInstalled ( gameType ) ;
9796 }
9897
9998 if ( ! MatchesOptionsPlatform ( platforms , actualPlatform ) )
10099 {
101100 var wrongGameFound = GameDetectionResult . NotInstalled ( gameType ) ;
102- Logger ? . LogInformation ( $ "Game detected at location: { wrongGameFound . GameLocation ? . FullName } " +
101+ Logger ? . LogTrace ( $ "Game detected at location: { wrongGameFound . GameLocation ? . FullName } " +
103102 $ "but Platform { actualPlatform } was not requested.") ;
104103 return wrongGameFound ;
105104 }
106105
107106 var detectedResult = GameDetectionResult . FromInstalled ( new GameIdentity ( gameType , actualPlatform ) , location ) ;
108- Logger ? . LogInformation ( $ "Game detected: { detectedResult . GameIdentity } at location: { location . FullName } ") ;
107+ Logger ? . LogDebug ( $ "Game detected: { detectedResult . GameIdentity } at location: ' { location . FullName } ' ") ;
109108 return detectedResult ;
110109 }
111110
@@ -167,7 +166,7 @@ private bool HandleInitialization(GameType gameType, ref GameLocationData locati
167166 if ( ! locationData . InitializationRequired )
168167 return true ;
169168
170- Logger ? . LogDebug ( $ "It appears that the game '{ locationData . ToString ( ) } ' exists but it is not initialized. Game type '{ gameType } '.") ;
169+ Logger ? . LogDebug ( $ "It appears that the game '{ locationData } ' exists but it is not initialized. Game type '{ gameType } '.") ;
171170 if ( ! _tryHandleInitialization )
172171 return false ;
173172
@@ -189,17 +188,21 @@ private bool RequestInitialization(GameType gameType)
189188 return request . Handled ;
190189 }
191190
192- private static IList < GamePlatform > NormalizePlatforms ( ICollection < GamePlatform > platforms )
191+ private static HashSet < GamePlatform > NormalizePlatforms ( ICollection < GamePlatform > platforms )
193192 {
194193 if ( platforms . Count == 0 || platforms . Contains ( GamePlatform . Undefined ) )
195194 return [ GamePlatform . Undefined ] ;
196- return platforms . Distinct ( ) . ToList ( ) ;
195+ return [ .. platforms ] ;
197196 }
198197
199198 /// <summary>
200199 /// Represents location and initialization state of a game.
201200 /// </summary>
202- public readonly struct GameLocationData
201+ /// <remarks>
202+ /// Initializes a new instance of the <see cref="GameLocationData"/> struct of the specified game location.
203+ /// </remarks>
204+ /// <param name="location">The detected game location or <see langword="null"/> if no game was detected.</param>
205+ public readonly struct GameLocationData ( IDirectoryInfo ? location )
203206 {
204207 /// <summary>
205208 /// Gets a <see cref="GameLocationData"/> representing a not installed location.
@@ -211,19 +214,10 @@ public readonly struct GameLocationData
211214 /// </summary>
212215 public static readonly GameLocationData RequiresInitialization = new ( ) { InitializationRequired = true } ;
213216
214- /// <summary>
215- /// Initializes a new instance of the <see cref="GameLocationData"/> struct of the specified game location.
216- /// </summary>
217- /// <param name="location">The detected game location or <see langword="null"/> if no game was detected.</param>
218- public GameLocationData ( IDirectoryInfo ? location )
219- {
220- Location = location ;
221- }
222-
223217 /// <summary>
224218 /// Nullable location entry.
225219 /// </summary>
226- public IDirectoryInfo ? Location { get ; }
220+ public IDirectoryInfo ? Location { get ; } = location ;
227221
228222 /// <summary>
229223 /// Indicates whether an initialization is required.
0 commit comments