Skip to content

Commit

Permalink
Removing a filter for prerelease games that was preventing active bet…
Browse files Browse the repository at this point in the history
…as from being displayed in select-apps. Removed some excluded app ids from the ExcludedAppId enum which are already being filtered out.
  • Loading branch information
tpill90 committed Dec 13, 2024
1 parent 724b89f commit 3cda9bf
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 44 deletions.
50 changes: 21 additions & 29 deletions SteamPrefill/Handlers/AppInfoHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class AppInfoHandler
private readonly Steam3Session _steam3Session;
private readonly LicenseManager _licenseManager;

private List<CPlayer_GetOwnedGames_Response.Game> _ownedGames;
private List<CPlayer_GetOwnedGames_Response.Game> _recentlyPlayed;

/// <summary>
/// A dictionary of all app metadata currently retrieved from Steam
Expand All @@ -26,21 +26,18 @@ public AppInfoHandler(IAnsiConsole ansiConsole, Steam3Session steam3Session, Lic
#region Loading Metadata

/// <summary>
/// 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.
/// </summary>
public async Task RetrieveAppMetadataAsync(List<uint> appIds, bool loadDlcApps = true, bool getRecentlyPlayedMetadata = false)
public async Task RetrieveAppMetadataAsync(List<uint> 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())
Expand Down Expand Up @@ -166,14 +163,13 @@ public virtual async Task<AppInfo> GetAppInfoAsync(uint appId)
}

/// <summary>
/// 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.
/// </summary>
private async Task<List<CPlayer_GetOwnedGames_Response.Game>> GetUsersOwnedGamesAsync()
public async Task<List<CPlayer_GetOwnedGames_Response.Game>> GetRecentlyPlayedGamesAsync()
{
if (_ownedGames != null)
if (_recentlyPlayed != null)
{
return _ownedGames;
return _recentlyPlayed;
}

var request = new CPlayer_GetOwnedGames_Request
Expand All @@ -190,15 +186,10 @@ public virtual async Task<AppInfo> 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<List<CPlayer_GetOwnedGames_Response.Game>> 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?
/// <summary>
Expand All @@ -213,17 +204,18 @@ public async Task<List<AppInfo>> GetAvailableGamesByIdAsync(List<uint> appIds)
appInfos.Add(await GetAppInfoAsync(appId));
}

// Filtering down some exclusions


// Filtering out some apps exclusions
var excludedAppIds = Enum.GetValues(typeof(ExcludedAppId)).Cast<uint>().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;
}
Expand Down
8 changes: 1 addition & 7 deletions SteamPrefill/Models/Enums/ExcludedAppId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
public enum ExcludedAppId
{
CodenameGordon = 92,

/// <summary>
/// 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
/// </summary>
SpaceWar = 480,
PCGamerOnline = 92500,
RisingStormBetaDedicatedServer = 238690,
MinervaMetastasis = 235780,
GamepadControllerTemplate = 1456390
SpaceWar = 480
}
}
4 changes: 2 additions & 2 deletions SteamPrefill/Models/Enums/ExcludedDepots.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 3 additions & 6 deletions SteamPrefill/SteamManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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())
Expand Down Expand Up @@ -445,7 +442,7 @@ public async Task<List<AppInfo>> 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;
Expand Down

0 comments on commit 3cda9bf

Please sign in to comment.