diff --git a/CreamInstaller/CreamInstaller.csproj b/CreamInstaller/CreamInstaller.csproj index b92928d..71b5d20 100644 --- a/CreamInstaller/CreamInstaller.csproj +++ b/CreamInstaller/CreamInstaller.csproj @@ -5,7 +5,7 @@ True Resources\ini.ico true - 3.4.2.2 + 3.4.3.0 Resources\ini.ico LICENSE 2021, pointfeev (https://github.com/pointfeev) diff --git a/CreamInstaller/Forms/SelectForm.cs b/CreamInstaller/Forms/SelectForm.cs index 03c1eae..74fa8b9 100644 --- a/CreamInstaller/Forms/SelectForm.cs +++ b/CreamInstaller/Forms/SelectForm.cs @@ -126,29 +126,32 @@ internal partial class SelectForm : CustomForm } if (Directory.Exists(SteamLibrary.InstallPath) && ProgramsToScan.Any(c => c.platform == "Steam")) { - List> steamGames = await SteamLibrary.GetGames(); - foreach (Tuple program in steamGames) + List<(string appId, string name, string branch, int buildId, string gameDirectory)> steamGames = await SteamLibrary.GetGames(); + int totalGames = steamGames.Count; + int gamesChecked = 0; + foreach ((string appId, string name, string branch, int buildId, string gameDirectory) in steamGames) { - string appId = program.Item1; - string name = program.Item2; - string branch = program.Item3; - int buildId = program.Item4; - string directory = program.Item5; if (Program.Canceled) return; Thread.Sleep(0); - if (Program.IsGameBlocked(name, directory) || !ProgramsToScan.Any(c => c.id == appId)) continue; + if (Program.IsGameBlocked(name, gameDirectory) || !ProgramsToScan.Any(c => c.id == appId)) + { + gamesChecked++; + continue; + } AddToRemainingGames(name); Task task = Task.Run(async () => { if (Program.Canceled) return; Thread.Sleep(0); - List dllDirectories = await SteamLibrary.GetDllDirectoriesFromGameDirectory(directory); + List dllDirectories = await SteamLibrary.GetDllDirectoriesFromGameDirectory(gameDirectory); if (dllDirectories is null) { + gamesChecked++; RemoveFromRemainingGames(name); return; } AppData appData = await SteamStore.QueryStoreAPI(appId); + gamesChecked++; VProperty appInfo = await SteamCMD.GetAppInfo(appId, branch, buildId); if (appData is null && appInfo is null) { @@ -171,7 +174,8 @@ internal partial class SelectForm : CustomForm Task task = Task.Run(async () => { if (Program.Canceled) return; - Thread.Sleep(0); + do Thread.Sleep(10); while (!Program.Canceled && gamesChecked < totalGames); // give games steam store api limit priority + if (Program.Canceled) return; string dlcName = null; string dlcIcon = null; AppData dlcAppData = await SteamStore.QueryStoreAPI(dlcAppId, true); @@ -218,7 +222,7 @@ internal partial class SelectForm : CustomForm selection.Enabled = allCheckBox.Checked || selection.SelectedDlc.Any() || selection.ExtraDlc.Any(); selection.Id = appId; selection.Name = appData?.name ?? name; - selection.RootDirectory = directory; + selection.RootDirectory = gameDirectory; selection.DllDirectories = dllDirectories; selection.IsSteam = true; selection.ProductUrl = "https://store.steampowered.com/app/" + appId; @@ -413,9 +417,9 @@ internal partial class SelectForm : CustomForm if (Directory.Exists(ParadoxLauncher.InstallPath)) gameChoices.Add(("Paradox", "ParadoxLauncher", "Paradox Launcher", ProgramsToScan is not null && ProgramsToScan.Any(p => p.id == "ParadoxLauncher"))); if (Directory.Exists(SteamLibrary.InstallPath)) - foreach (Tuple program in await SteamLibrary.GetGames()) - if (!Program.IsGameBlocked(program.Item2, program.Item5)) - gameChoices.Add(("Steam", program.Item1, program.Item2, ProgramsToScan is not null && ProgramsToScan.Any(p => p.id == program.Item1))); + foreach ((string appId, string name, string branch, int buildId, string gameDirectory) in await SteamLibrary.GetGames()) + if (!Program.IsGameBlocked(name, gameDirectory)) + gameChoices.Add(("Steam", appId, name, ProgramsToScan is not null && ProgramsToScan.Any(p => p.id == appId))); if (Directory.Exists(EpicLibrary.EpicManifestsPath)) foreach (Manifest manifest in await EpicLibrary.GetGames()) if (!Program.IsGameBlocked(manifest.DisplayName, manifest.InstallLocation)) diff --git a/CreamInstaller/Steam/SteamLibrary.cs b/CreamInstaller/Steam/SteamLibrary.cs index bdb6c53..01e577b 100644 --- a/CreamInstaller/Steam/SteamLibrary.cs +++ b/CreamInstaller/Steam/SteamLibrary.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; @@ -25,18 +24,18 @@ internal static class SteamLibrary } } - internal static async Task>> GetGames() => await Task.Run(async () => + internal static async Task> GetGames() => await Task.Run(async () => { - List> games = new(); + List<(string appId, string name, string branch, int buildId, string gameDirectory)> games = new(); List gameLibraryDirectories = await GetLibraryDirectories(); foreach (string libraryDirectory in gameLibraryDirectories) { if (Program.Canceled) return games; Thread.Sleep(0); - List> directoryGames = await GetGamesFromLibraryDirectory(libraryDirectory); + List<(string appId, string name, string branch, int buildId, string gameDirectory)> directoryGames = await GetGamesFromLibraryDirectory(libraryDirectory); if (directoryGames is not null) - foreach (Tuple game in directoryGames) - if (!games.Any(_game => _game.Item1 == game.Item1)) + foreach ((string appId, string name, string branch, int buildId, string gameDirectory) game in directoryGames) + if (!games.Any(_game => _game.appId == game.appId)) games.Add(game); } return games; @@ -68,9 +67,9 @@ internal static class SteamLibrary return !dllDirectories.Any() ? null : dllDirectories; }); - internal static async Task>> GetGamesFromLibraryDirectory(string libraryDirectory) => await Task.Run(() => + internal static async Task> GetGamesFromLibraryDirectory(string libraryDirectory) => await Task.Run(() => { - List> games = new(); + List<(string appId, string name, string branch, int buildId, string gameDirectory)> games = new(); if (Program.Canceled || !Directory.Exists(libraryDirectory)) return null; string[] files = Directory.GetFiles(libraryDirectory, "*.acf"); foreach (string file in files) @@ -93,7 +92,7 @@ internal static class SteamLibrary string gameDirectory = libraryDirectory + @"\common\" + installdir; if (!int.TryParse(appId, out int appIdInt)) continue; if (!int.TryParse(buildId, out int buildIdInt)) continue; - games.Add(new(appId, name, branch, buildIdInt, gameDirectory)); + games.Add((appId, name, branch, buildIdInt, gameDirectory)); } } return !games.Any() ? null : games; diff --git a/CreamInstaller/Steam/SteamStore.cs b/CreamInstaller/Steam/SteamStore.cs index 9b06e4b..8976266 100644 --- a/CreamInstaller/Steam/SteamStore.cs +++ b/CreamInstaller/Steam/SteamStore.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.IO; +using System.Threading; using System.Threading.Tasks; using CreamInstaller.Utility; @@ -33,7 +34,7 @@ internal static class SteamStore string response = await HttpClientManager.EnsureGet($"https://store.steampowered.com/api/appdetails?appids={appId}"); if (response is not null) { - IDictionary apps = (dynamic)JsonConvert.DeserializeObject(response); + IDictionary apps = JsonConvert.DeserializeObject(response) as dynamic; foreach (KeyValuePair app in apps) { try @@ -72,6 +73,11 @@ internal static class SteamStore File.Delete(cacheFile); } } + if (!isDlc) + { + Thread.Sleep(1000); + return await QueryStoreAPI(appId); + } return null; } }