diff --git a/SteamPrefill/Handlers/AppInfoHandler.cs b/SteamPrefill/Handlers/AppInfoHandler.cs index a8325c99..a0d5f847 100644 --- a/SteamPrefill/Handlers/AppInfoHandler.cs +++ b/SteamPrefill/Handlers/AppInfoHandler.cs @@ -9,7 +9,7 @@ public class AppInfoHandler private readonly Steam3Session _steam3Session; private readonly LicenseManager _licenseManager; - private List _ownedGames; + private List _recentlyPlayed; /// /// A dictionary of all app metadata currently retrieved from Steam @@ -26,21 +26,18 @@ public AppInfoHandler(IAnsiConsole ansiConsole, Steam3Session steam3Session, Lic #region Loading Metadata /// - /// Gets the latest app metadata from steam, for the specified apps, as well as their related DLC apps + /// Gets the latest app metadata from steam, for the specified apps, as well as their related DLC apps. /// - public async Task RetrieveAppMetadataAsync(List appIds, bool loadDlcApps = true, bool getRecentlyPlayedMetadata = false) + public async Task RetrieveAppMetadataAsync(List appIds, bool getRecentlyPlayedMetadata = false) { await _ansiConsole.StatusSpinner().StartAsync("Retrieving latest App metadata...", async _ => { await BulkLoadAppInfoAsync(appIds); + // Once we have loaded all the apps we'll know what DLC is owned, so we can then load DLC metadata + await FetchDlcAppInfoAsync(); - if (loadDlcApps) - { - // Once we have loaded all the apps, we can also load information for related DLC - await FetchDlcAppInfoAsync(); - } - - // Populating play time if needed, otherwise we'll skip it to slightly speed things up + // Populating play time if needed in the case of select-apps or using prefill's --recent flag. + // Otherwise we'll skip it to slightly speed things up if (getRecentlyPlayedMetadata) { foreach (var app in await GetRecentlyPlayedGamesAsync()) @@ -166,14 +163,13 @@ public virtual async Task GetAppInfoAsync(uint appId) } /// - /// Gets a list of all games owned by the current user. - /// This differs from the list of owned AppIds, as this exclusively contains "games", excluding things like DLC/Tools/etc + /// Gets a list of games owned by the user, and filters them down to just the ones that have recent playtime in the last 2 weeks. /// - private async Task> GetUsersOwnedGamesAsync() + public async Task> GetRecentlyPlayedGamesAsync() { - if (_ownedGames != null) + if (_recentlyPlayed != null) { - return _ownedGames; + return _recentlyPlayed; } var request = new CPlayer_GetOwnedGames_Request @@ -190,15 +186,10 @@ public virtual async Task GetAppInfoAsync(uint appId) throw new Exception("Unexpected error while requesting owned games!"); } - _ownedGames = response.Body.games; - return _ownedGames; + _recentlyPlayed = response.Body.games.Where(e => e.playtime_2weeks > 0).ToList(); + return _recentlyPlayed; } - public async Task> GetRecentlyPlayedGamesAsync() - { - var userOwnedGames = await GetUsersOwnedGamesAsync(); - return userOwnedGames.Where(e => e.playtime_2weeks > 0).ToList(); - } //TODO is this necessary because --all includes things that shouldn't be downloaded? /// @@ -213,17 +204,18 @@ public async Task> GetAvailableGamesByIdAsync(List appIds) appInfos.Add(await GetAppInfoAsync(appId)); } - // Filtering down some exclusions + + + // Filtering out some apps exclusions var excludedAppIds = Enum.GetValues(typeof(ExcludedAppId)).Cast().ToList(); var filteredGames = appInfos.Where(e => (e.Type == AppType.Game || e.Type == AppType.Beta) - && (e.ReleaseState != ReleaseState.Unavailable && e.ReleaseState != ReleaseState.Prerelease) + && (e.ReleaseState == ReleaseState.Released || e.ReleaseState == ReleaseState.Prerelease) && e.SupportsWindows && _steam3Session.LicenseManager.AccountHasAppAccess(e.AppId)) - .Where(e => !excludedAppIds.Contains(e.AppId)) - .Where(e => !e.Categories.Contains(Category.Mods) && !e.Categories.Contains(Category.ModsHL2)) - .Where(e => !e.Name.Contains("AMD Driver Updater")) - .OrderBy(e => e.Name, StringComparer.OrdinalIgnoreCase) - .ToList(); + .Where(e => !excludedAppIds.Contains(e.AppId)) + .Where(e => !e.Categories.Contains(Category.Mods) && !e.Categories.Contains(Category.ModsHL2)) + .OrderBy(e => e.Name, StringComparer.OrdinalIgnoreCase) + .ToList(); return filteredGames; } diff --git a/SteamPrefill/Models/Enums/ExcludedAppId.cs b/SteamPrefill/Models/Enums/ExcludedAppId.cs index 3798f788..42a5793a 100644 --- a/SteamPrefill/Models/Enums/ExcludedAppId.cs +++ b/SteamPrefill/Models/Enums/ExcludedAppId.cs @@ -3,17 +3,11 @@ [UsedImplicitly(ImplicitUseTargetFlags.Members)] public enum ExcludedAppId { - CodenameGordon = 92, - /// /// SpaceWar is a non-playable game, that is required for Steamworks multiplayer functionality to work /// /// https://www.rockpapershotgun.com/spacewar-why-a-hidden-ancient-game-keeps-showing-in-steams-most-played-games /// - SpaceWar = 480, - PCGamerOnline = 92500, - RisingStormBetaDedicatedServer = 238690, - MinervaMetastasis = 235780, - GamepadControllerTemplate = 1456390 + SpaceWar = 480 } } diff --git a/SteamPrefill/Models/Enums/ExcludedDepots.cs b/SteamPrefill/Models/Enums/ExcludedDepots.cs index 3e50cffd..4bb1ec5e 100644 --- a/SteamPrefill/Models/Enums/ExcludedDepots.cs +++ b/SteamPrefill/Models/Enums/ExcludedDepots.cs @@ -20,8 +20,8 @@ public static class ExcludedDepots 731, 732, 734, - - // Excluding VC Redist since they add unnecessary noise to a app's depot list + + // Excluding VC Redist since they add unnecessary noise to an app's depot list 228981, 228982, 228983, diff --git a/SteamPrefill/SteamManager.cs b/SteamPrefill/SteamManager.cs index 5f76eed4..26de9104 100644 --- a/SteamPrefill/SteamManager.cs +++ b/SteamPrefill/SteamManager.cs @@ -92,12 +92,11 @@ public async Task DownloadMultipleAppsAsync(bool downloadAllOwnedGames, bool pre _ansiConsole.WriteLine(); var availableGames = await _appInfoHandler.GetAvailableGamesByIdAsync(distinctAppIds); - //TODO switch this to iterating over the list of apps instead foreach (var app in availableGames) { try { - await DownloadSingleAppAsync(app.AppId); + await DownloadSingleAppAsync(app); } catch (Exception e) when (e is LancacheNotFoundException || e is InfiniteLoopException) { @@ -120,10 +119,8 @@ public async Task DownloadMultipleAppsAsync(bool downloadAllOwnedGames, bool pre _prefillSummaryResult.RenderSummaryTable(_ansiConsole); } - private async Task DownloadSingleAppAsync(uint appId) + private async Task DownloadSingleAppAsync(AppInfo appInfo) { - AppInfo appInfo = await _appInfoHandler.GetAppInfoAsync(appId); - // Filter depots based on specified language/OS/cpu architecture/etc var filteredDepots = await _depotHandler.FilterDepotsToDownloadAsync(_downloadArgs, appInfo.Depots); if (filteredDepots.Empty()) @@ -445,7 +442,7 @@ public async Task> GetAllAvailableAppsAsync() var ownedGameIds = _steam3.LicenseManager.AllOwnedAppIds; // Loading app metadata from steam, skipping related DLC apps - await _appInfoHandler.RetrieveAppMetadataAsync(ownedGameIds, loadDlcApps: false, getRecentlyPlayedMetadata: true); + await _appInfoHandler.RetrieveAppMetadataAsync(ownedGameIds, getRecentlyPlayedMetadata: true); var availableGames = await _appInfoHandler.GetAvailableGamesByIdAsync(ownedGameIds); return availableGames;