- Minor refactoring
- Steam games now wait on store api queries, so no DLC will ever be missed from the steam store now
- Steam DLC store queries will now only be performed after ALL Steam games have completed their respective store queries, to make sure the steam store api limit isn't hit before all games have queried successfully
This commit is contained in:
pointfeev 2022-05-02 14:12:50 -04:00
parent 2169a6a0ac
commit dd4be5b91f
4 changed files with 35 additions and 26 deletions

View file

@ -5,7 +5,7 @@
<UseWindowsForms>True</UseWindowsForms>
<ApplicationIcon>Resources\ini.ico</ApplicationIcon>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<Version>3.4.2.2</Version>
<Version>3.4.3.0</Version>
<PackageIcon>Resources\ini.ico</PackageIcon>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Copyright>2021, pointfeev (https://github.com/pointfeev)</Copyright>

View file

@ -126,29 +126,32 @@ internal partial class SelectForm : CustomForm
}
if (Directory.Exists(SteamLibrary.InstallPath) && ProgramsToScan.Any(c => c.platform == "Steam"))
{
List<Tuple<string, string, string, int, string>> steamGames = await SteamLibrary.GetGames();
foreach (Tuple<string, string, string, int, string> 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<string> dllDirectories = await SteamLibrary.GetDllDirectoriesFromGameDirectory(directory);
List<string> 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<string, string, string, int, string> 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))

View file

@ -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<List<Tuple<string, string, string, int, string>>> GetGames() => await Task.Run(async () =>
internal static async Task<List<(string appId, string name, string branch, int buildId, string gameDirectory)>> GetGames() => await Task.Run(async () =>
{
List<Tuple<string, string, string, int, string>> games = new();
List<(string appId, string name, string branch, int buildId, string gameDirectory)> games = new();
List<string> gameLibraryDirectories = await GetLibraryDirectories();
foreach (string libraryDirectory in gameLibraryDirectories)
{
if (Program.Canceled) return games;
Thread.Sleep(0);
List<Tuple<string, string, string, int, string>> 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<string, string, string, int, string> 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<List<Tuple<string, string, string, int, string>>> GetGamesFromLibraryDirectory(string libraryDirectory) => await Task.Run(() =>
internal static async Task<List<(string appId, string name, string branch, int buildId, string gameDirectory)>> GetGamesFromLibraryDirectory(string libraryDirectory) => await Task.Run(() =>
{
List<Tuple<string, string, string, int, string>> 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;

View file

@ -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<string, JToken> apps = (dynamic)JsonConvert.DeserializeObject(response);
IDictionary<string, JToken> apps = JsonConvert.DeserializeObject(response) as dynamic;
foreach (KeyValuePair<string, JToken> 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;
}
}