public partial class MainPage : Page { private readonly string _apiKey = ""; SettingsManager settingsManager = new SettingsManager(); AppSettings settings; public string SteamPath; public ObservableCollection Apps { get; set; } public MainPage() { InitializeComponent(); settings = settingsManager.LoadSettings(); SteamPath = settings.steampath; Apps = new ObservableCollection(); DataContext = this; } private void SettingsBtn_Click(object sender, RoutedEventArgs e) { FrameApp.FrameMain.Navigate(new SettingsPage()); } private async void TestBtn_Click(object sender, RoutedEventArgs e) { if (!SteamPath.Contains("Steam") || SteamPath == "" || SteamPath == String.Empty || SteamPath == null) { MessageBox.Show("Incorrect path to the Steam folder!"); FrameApp.FrameMain.Navigate(new SettingsPage()); } else { Debug.WriteLine($"### Getting the list of games started ###"); await GetAllApps(); Debug.WriteLine($"### End of getting the list of games ###"); } } private async void SearchTBX_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { string searchTerm = SearchTBX.Text; await SearchGamesAsync(searchTerm); } } public async Task GetAppDetails(int appId) { using (var httpClient = new HttpClient()) { try { var response = await httpClient.GetStringAsync($"https://store.steampowered.com/api/appdetails/?appids={appId}"); var appDetails = JsonConvert.DeserializeObject>(response); if (appDetails.ContainsKey(appId.ToString()) && appDetails[appId.ToString()].Success) { return appDetails[appId.ToString()]; } else { Debug.WriteLine($"Error when receiving data for a game with AppID {appId};\n {appDetails.Count}\n{response.ToString()}"); return new AppDetails { Success = false, Data = null }; } } catch (Exception ex) { Debug.WriteLine($"Error receiving data: {ex.Message}"); return new AppDetails { Success = false, Data = null }; } } } public async Task SearchGamesAsync(string searchTerm) { using (var httpClient = new HttpClient()) { try { var response = await httpClient.GetStringAsync($"http://api.steampowered.com/ISteamApps/GetAppList/v2/"); var steamApiResponse = JsonConvert.DeserializeObject(response); var apps = steamApiResponse.AppList.Apps; var filteredGames = apps.Where(app => app.AppId.ToString().ToLower().Contains(searchTerm.ToLower())).ToList(); var tasks = filteredGames.Select(app => ProcessGameAsync(app)).ToList(); await Task.WhenAll(tasks); GamesDG.ItemsSource = filteredGames; } catch (Exception ex) { Debug.WriteLine($"Error receiving data: {ex.Message}"); } } } private async Task ProcessGameAsync(App app) { var appDetails = await GetAppDetails(app.AppId); if (appDetails.Success) { app.header_image = appDetails.Data?.header_image; MessageBox.Show($"Added an image for\nGame: {app.Name} ({app.AppId});\n Image: {app.header_image}"); } } } public class SteamApiResponse { public AppList AppList { get; set; } } public class AppList { public List Apps { get; set; } } public class AppDetails { public bool Success { get; set; } public App Data { get; set; } } public class App { public int AppId { get; set; } public string Name { get; set; } public string header_image { get; set; } }