@@ -164,105 +164,112 @@ public static async Task LoadGames()
164164 // skip steam tools
165165 if ( gameId == "228980" ) continue ;
166166
167- // read game manifest
168- var appManifestData = KVSerializer . Create ( KVSerializationFormat . KeyValues1Text )
169- . Deserialize ( File . OpenRead ( Path . Combine ( steamAppsDir , $ "appmanifest_{ gameId } .acf") ) ) ;
170-
171- // get metadata
172- var gameData = JsonDocument . Parse ( await httpClient . GetStringAsync ( $ "https://store.steampowered.com/api/appdetails?appids={ gameId } &l=english", _ ) ) . RootElement . GetProperty ( gameId ) ;
173- // get playtime data
174- //var playTimeData = XDocument.Parse(await httpClient.GetStringAsync($"https://steamcommunity.com/profiles/{GetSteam64ID()}/?tab=all&xml=1", _));
175-
176- //string playTime = playTimeData.Descendants("game")
177- // .Where(game => (string)game.Element("appID") == gameId)
178- // .Select(game =>
179- // {
180- // var hoursStr = (string)game.Element("hoursOnRecord");
181- // return double.TryParse(hoursStr, NumberStyles.Float, CultureInfo.InvariantCulture, out var h)
182- // ? $"{(int)h}h {(int)((h - (int)h) * 60)}min"
183- // : null;
184- // })
185- // .FirstOrDefault() ?? "0m";
186-
187- // get review data
188- var reviewData = JsonDocument . Parse ( await httpClient . GetStringAsync ( $ "https://store.steampowered.com/appreviews/{ gameId } ?json=1", _ ) ) . RootElement . GetProperty ( "query_summary" ) ;
189- int totalPositive = reviewData . GetProperty ( "total_positive" ) . GetInt32 ( ) ;
190- int totalNegative = reviewData . GetProperty ( "total_negative" ) . GetInt32 ( ) ;
191-
192- // get age rating
193- string rating = null ;
194- string descriptors = null ;
195-
196- var data = gameData . GetProperty ( "data" ) ;
197-
198- if ( data . TryGetProperty ( "ratings" , out var ratings ) && ratings . ValueKind == JsonValueKind . Object && ratings . TryGetProperty ( ratingKey . ToLowerInvariant ( ) , out var ratingData ) )
167+ try
199168 {
200- if ( ratingData . TryGetProperty ( "rating" , out var ratingElement ) && ratingElement . ValueKind == JsonValueKind . String )
169+ // read game manifest
170+ var appManifestData = KVSerializer . Create ( KVSerializationFormat . KeyValues1Text )
171+ . Deserialize ( File . OpenRead ( Path . Combine ( steamAppsDir , $ "appmanifest_{ gameId } .acf") ) ) ;
172+
173+ // get metadata
174+ var gameData = JsonDocument . Parse ( await httpClient . GetStringAsync ( $ "https://store.steampowered.com/api/appdetails?appids={ gameId } &l=english", _ ) ) . RootElement . GetProperty ( gameId ) ;
175+ // get playtime data
176+ //var playTimeData = XDocument.Parse(await httpClient.GetStringAsync($"https://steamcommunity.com/profiles/{GetSteam64ID()}/?tab=all&xml=1", _));
177+
178+ //string playTime = playTimeData.Descendants("game")
179+ // .Where(game => (string)game.Element("appID") == gameId)
180+ // .Select(game =>
181+ // {
182+ // var hoursStr = (string)game.Element("hoursOnRecord");
183+ // return double.TryParse(hoursStr, NumberStyles.Float, CultureInfo.InvariantCulture, out var h)
184+ // ? $"{(int)h}h {(int)((h - (int)h) * 60)}min"
185+ // : null;
186+ // })
187+ // .FirstOrDefault() ?? "0m";
188+
189+ //// get review data
190+ //var reviewData = JsonDocument.Parse(await httpClient.GetStringAsync($"https://store.steampowered.com/appreviews/{gameId}?json=1", _)).RootElement.GetProperty("query_summary");
191+ //int totalPositive = reviewData.GetProperty("total_positive").GetInt32();
192+ //int totalNegative = reviewData.GetProperty("total_negative").GetInt32();
193+
194+ // get age rating
195+ string rating = null ;
196+ string descriptors = null ;
197+
198+ var data = gameData . GetProperty ( "data" ) ;
199+
200+ if ( data . TryGetProperty ( "ratings" , out var ratings ) && ratings . ValueKind == JsonValueKind . Object && ratings . TryGetProperty ( ratingKey . ToLowerInvariant ( ) , out var ratingData ) )
201201 {
202- rating = ratingElement . GetString ( ) ;
202+ if ( ratingData . TryGetProperty ( "rating" , out var ratingElement ) && ratingElement . ValueKind == JsonValueKind . String )
203+ {
204+ rating = ratingElement . GetString ( ) ;
205+ }
206+
207+ if ( ratingData . TryGetProperty ( "descriptors" , out var descElement ) && descElement . ValueKind == JsonValueKind . String )
208+ {
209+ descriptors = descElement . GetString ( ) ?
210+ . Replace ( "\r \n " , ", " )
211+ . Replace ( "\n " , ", " )
212+ . Replace ( "\r " , ", " ) ;
213+ }
203214 }
204215
205- if ( ratingData . TryGetProperty ( "descriptors" , out var descElement ) && descElement . ValueKind == JsonValueKind . String )
206- {
207- descriptors = descElement . GetString ( ) ?
208- . Replace ( "\r \n " , ", " )
209- . Replace ( "\n " , ", " )
210- . Replace ( "\r " , ", " ) ;
211- }
212- }
213-
214- DateTimeOffset releaseDate = DateTimeOffset . Parse (
215- gameData . GetProperty ( "data" )
216- . GetProperty ( "release_date" )
217- . GetProperty ( "date" )
218- . GetString ( ) !
219- ) ;
216+ DateTimeOffset releaseDate = DateTimeOffset . Parse (
217+ gameData . GetProperty ( "data" )
218+ . GetProperty ( "release_date" )
219+ . GetProperty ( "date" )
220+ . GetString ( ) !
221+ ) ;
220222
221- long ? sizeBytes = long . TryParse ( appManifestData [ "SizeOnDisk" ] ? . ToString ( ) , out var result ) ? result : null ;
223+ long ? sizeBytes = long . TryParse ( appManifestData [ "SizeOnDisk" ] ? . ToString ( ) , out var result ) ? result : null ;
222224
223- GamesPage . Instance . DispatcherQueue . TryEnqueue ( ( ) =>
224- {
225- GamesPage . Instance . Games . Items . Add ( new Views . Settings . Games . HeaderCarouselItem
225+ GamesPage . Instance . DispatcherQueue . TryEnqueue ( ( ) =>
226226 {
227- Launcher = "Steam" ,
228- ImageUrl = $ "https://cdn.steamstatic.com/steam/apps/{ gameId } /library_600x900.jpg",
229- BackgroundImageUrl = $ "https://cdn.steamstatic.com/steam/apps/{ gameId } /library_hero.jpg",
230- Title = appManifestData [ "name" ] ? . ToString ( ) ,
231- Developers = string . Join ( ", " , gameData . GetProperty ( "data" ) . GetProperty ( "developers" )
232- . EnumerateArray ( ) . Select ( d => d . GetString ( ) ) . Where ( s => ! string . IsNullOrWhiteSpace ( s ) ) ) ,
233- Genres = [ .. gameData . GetProperty ( "data" ) . GetProperty ( "genres" )
227+ GamesPage . Instance . Games . Items . Add ( new Views . Settings . Games . HeaderCarouselItem
228+ {
229+ Launcher = "Steam" ,
230+ ImageUrl = $ "https://cdn.steamstatic.com/steam/apps/{ gameId } /library_600x900.jpg",
231+ BackgroundImageUrl = $ "https://cdn.steamstatic.com/steam/apps/{ gameId } /library_hero.jpg",
232+ Title = appManifestData [ "name" ] ? . ToString ( ) ,
233+ Developers = string . Join ( ", " , gameData . GetProperty ( "data" ) . GetProperty ( "developers" )
234+ . EnumerateArray ( ) . Select ( d => d . GetString ( ) ) . Where ( s => ! string . IsNullOrWhiteSpace ( s ) ) ) ,
235+ Genres = [ .. gameData . GetProperty ( "data" ) . GetProperty ( "genres" )
234236 . EnumerateArray ( )
235237 . Select ( g => g . GetProperty ( "description" ) . GetString ( ) )
236238 . Where ( s => ! string . IsNullOrWhiteSpace ( s ) ) ] ,
237- Features = [ .. gameData . GetProperty ( "data" ) . GetProperty ( "categories" )
239+ Features = [ .. gameData . GetProperty ( "data" ) . GetProperty ( "categories" )
238240 . EnumerateArray ( )
239241 . Select ( c => c . GetProperty ( "description" ) . GetString ( ) )
240242 . Where ( s => ! string . IsNullOrWhiteSpace ( s ) ) ] ,
241- Rating = totalPositive + totalNegative > 0
242- ? Math . Round ( 5.0 * totalPositive / ( totalPositive + totalNegative ) , 1 )
243- : 0.0 ,
244- //PlayTime = playTime,
245- PlayTime = "0m" ,
246- AgeRatingUrl = ! string . IsNullOrEmpty ( rating ) ? $ "{ ratingBaseUrl } { rating . ToLowerInvariant ( ) } .png" : null ,
247- AgeRatingTitle = ! string . IsNullOrEmpty ( rating ) ? ( ratingTitles . TryGetValue ( rating . ToLowerInvariant ( ) , out var title ) ? title : rating ) : null ,
248- AgeRatingDescription = ! string . IsNullOrEmpty ( descriptors ) ? descriptors : null ,
249- Description = gameData . GetProperty ( "data" ) . GetProperty ( "short_description" ) . GetString ( ) ,
250- Screenshots = gameData . GetProperty ( "data" ) . TryGetProperty ( "screenshots" , out var screenshots )
251- ? [ .. screenshots . EnumerateArray ( )
243+ // Rating = totalPositive + totalNegative > 0
244+ // ? Math.Round(5.0 * totalPositive / (totalPositive + totalNegative), 1)
245+ // : 0.0,
246+ //PlayTime = playTime,
247+ PlayTime = "0m" ,
248+ AgeRatingUrl = ! string . IsNullOrEmpty ( rating ) ? $ "{ ratingBaseUrl } { rating . ToLowerInvariant ( ) } .png" : null ,
249+ AgeRatingTitle = ! string . IsNullOrEmpty ( rating ) ? ( ratingTitles . TryGetValue ( rating . ToLowerInvariant ( ) , out var title ) ? title : rating ) : null ,
250+ AgeRatingDescription = ! string . IsNullOrEmpty ( descriptors ) ? descriptors : null ,
251+ Description = gameData . GetProperty ( "data" ) . GetProperty ( "short_description" ) . GetString ( ) ,
252+ Screenshots = gameData . GetProperty ( "data" ) . TryGetProperty ( "screenshots" , out var screenshots )
253+ ? [ .. screenshots . EnumerateArray ( )
252254 . Select ( s => s . GetProperty ( "path_thumbnail" ) . GetString ( ) )
253255 . Where ( s => ! string . IsNullOrWhiteSpace ( s ) ) ]
254- : [ ] ,
255- InstallLocation = Path . Combine ( steamAppsDir , "common" , appManifestData [ "installdir" ] ? . ToString ( ) ) ,
256- ReleaseDate = releaseDate . ToString ( "d" ) ,
257- Size = sizeBytes >= 1024 * 1024 * 1024
258- ? $ "{ sizeBytes . Value / ( 1024d * 1024d * 1024d ) : F1} GB"
259- : $ "{ sizeBytes . Value / ( 1024d * 1024d ) : F2} MB",
260- Version = appManifestData [ "buildid" ] ? . ToString ( ) ,
261- GameID = gameId ,
262- Width = 240 ,
263- Height = 320 ,
256+ : [ ] ,
257+ InstallLocation = Path . Combine ( steamAppsDir , "common" , appManifestData [ "installdir" ] ? . ToString ( ) ) ,
258+ ReleaseDate = releaseDate . ToString ( "d" ) ,
259+ Size = sizeBytes >= 1024 * 1024 * 1024
260+ ? $ "{ sizeBytes . Value / ( 1024d * 1024d * 1024d ) : F1} GB"
261+ : $ "{ sizeBytes . Value / ( 1024d * 1024d ) : F2} MB",
262+ Version = appManifestData [ "buildid" ] ? . ToString ( ) ,
263+ GameID = gameId ,
264+ Width = 240 ,
265+ Height = 320 ,
266+ } ) ;
264267 } ) ;
265- } ) ;
268+ }
269+ catch ( Exception ex )
270+ {
271+ Debug . WriteLine ( ex ) ;
272+ }
266273 }
267274 } ) ;
268275 }
0 commit comments