Skip to content

Commit

Permalink
Merge pull request #1009 from xPaw/pics
Browse files Browse the repository at this point in the history
Remove PICSGetProductInfo overloads that takes uint
  • Loading branch information
yaakov-h authored Aug 1, 2021
2 parents 9fc531f + 9a6e7f4 commit 5050024
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 35 deletions.
32 changes: 23 additions & 9 deletions Samples/9.AsyncJobs/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,13 @@ static async void OnLoggedOn( SteamUser.LoggedOnCallback callback )
return;
}

// in this sample, we'll simply do a few async requests to acquire information about appid 440 (Team Fortress 2)
// in this sample, we'll simply do a few async requests to acquire information about Counter-Strike: Global Offensive

// first, we'll request a depot decryption key for TF2's client/server shared depot (441)
var depotJob = steamApps.GetDepotDecryptionKey( depotid: 441, appid: 440 );
uint appid = 730;
uint depotid = 731;

// first, we'll request a depot decryption key for CSGO's common files depot (731)
var depotJob = steamApps.GetDepotDecryptionKey( depotid, appid );

// at this point, this request is now in-flight to the steam server, so we'll use te async/await pattern to wait for a response
// the await pattern allows this code to resume once the Steam servers have replied to the request.
Expand All @@ -144,8 +147,20 @@ static async void OnLoggedOn( SteamUser.LoggedOnCallback callback )
Console.WriteLine( "Unable to request depot key!" );
}

// now request some product info for TF2
var productJob = steamApps.PICSGetProductInfo( 440, package: null );
// now request the access token
var accessTokenJob = steamApps.PICSGetAccessTokens( appid, package: null );
var accessTokenResult = await accessTokenJob;
ulong accessToken = 0;

// Get the access token, if the app is owned it may be a long value, or 0 if it is public.
// If the request was denied, the appid will be listed in AppTokensDenied.
accessTokenResult.AppTokens.TryGetValue( appid, out accessToken );

// create a request product info request struct
var request = new SteamApps.PICSRequest( appid, accessToken );

// now request some product info
var productJob = steamApps.PICSGetProductInfo( app: request, package: null, metaDataOnly: false );

// note that with some requests, Steam can return multiple results, so these jobs don't return the callback object directly, but rather
// a result set that could contain multiple callback objects if Steam gives us multiple results
Expand All @@ -168,7 +183,7 @@ static async void OnLoggedOn( SteamUser.LoggedOnCallback callback )
// AsyncJobFailedException or TaskCanceledException will be thrown

// the result set might not have our data, so we need to test to see if we have results for our request
SteamApps.PICSProductInfoCallback productInfo = resultSet.Results.FirstOrDefault( prodCallback => prodCallback.Apps.ContainsKey( 440 ) );
SteamApps.PICSProductInfoCallback productInfo = resultSet.Results.FirstOrDefault( prodCallback => prodCallback.Apps.ContainsKey( appid ) );

if ( productInfo != null )
{
Expand All @@ -184,7 +199,7 @@ static async void OnLoggedOn( SteamUser.LoggedOnCallback callback )
// the request partially completed, but then we timed out. essentially the same as the previous case, but Steam didn't explicitly fail.

// we still need to check our result set to see if we have our data
SteamApps.PICSProductInfoCallback productInfo = resultSet.Results.FirstOrDefault( prodCallback => prodCallback.Apps.ContainsKey( 440 ) );
SteamApps.PICSProductInfoCallback productInfo = resultSet.Results.FirstOrDefault( prodCallback => prodCallback.Apps.ContainsKey( appid ) );

if ( productInfo != null )
{
Expand All @@ -198,7 +213,7 @@ static async void OnLoggedOn( SteamUser.LoggedOnCallback callback )

// lastly, if you're unable to use the async/await pattern (older VS/compiler, etc) you can still directly access the TPL Task associated
// with the async job by calling `ToTask()`
var depotTask = steamApps.GetDepotDecryptionKey( depotid: 441, appid: 440 ).ToTask();
var depotTask = steamApps.GetDepotDecryptionKey( depotid, appid ).ToTask();

// set up a continuation for when this task completes
var ignored = depotTask.ContinueWith( task =>
Expand All @@ -212,7 +227,6 @@ static async void OnLoggedOn( SteamUser.LoggedOnCallback callback )

}, TaskContinuationOptions.OnlyOnRanToCompletion );
}


static void OnLoggedOff( SteamUser.LoggedOffCallback callback )
{
Expand Down
32 changes: 6 additions & 26 deletions SteamKit2/SteamKit2/Steam/Handlers/SteamApps/SteamApps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,10 @@ namespace SteamKit2
/// </summary>
public sealed partial class SteamApps : ClientMsgHandler
{

// Ambiguous reference in cref attribute: 'SteamApps.PICSGetProductInfo'. Assuming 'SteamKit2.SteamApps.PICSGetProductInfo(uint?, uint?, bool, bool)',
// but could have also matched other overloads including 'SteamKit2.SteamApps.PICSGetProductInfo(System.Collections.Generic.IEnumerable<SteamKit2.SteamApps.PICSRequest>, System.Collections.Generic.IEnumerable<SteamKit2.SteamApps.PICSRequest>, bool)'.
#pragma warning disable 0419

/// <summary>
/// Represents a PICS request used for <see cref="SteamApps.PICSGetProductInfo"/>
/// Represents a PICS request used for <see cref="o:SteamApps.PICSGetProductInfo"/>
/// </summary>
public struct PICSRequest
#pragma warning restore 0419
{
/// <summary>
/// Gets or sets the ID of the app or package being requested
Expand Down Expand Up @@ -181,35 +175,21 @@ public AsyncJob<PICSChangesCallback> PICSGetChangesSince( uint lastChangeNumber
/// Results are returned in a <see cref="PICSProductInfoCallback"/> callback.
/// The returned <see cref="AsyncJob{T}"/> can also be awaited to retrieve the callback result.
/// </summary>
/// <param name="app">App id requested.</param>
/// <param name="package">Package id requested.</param>
/// <param name="app"><see cref="PICSRequest"/> request for an app.</param>
/// <param name="package"><see cref="PICSRequest"/> request for a package.</param>
/// <param name="metaDataOnly">Whether to send only meta data.</param>
/// <returns>The Job ID of the request. This can be used to find the appropriate <see cref="PICSProductInfoCallback"/>.</returns>
public AsyncJobMultiple<PICSProductInfoCallback> PICSGetProductInfo(uint? app, uint? package, bool metaDataOnly = false)
public AsyncJobMultiple<PICSProductInfoCallback> PICSGetProductInfo( PICSRequest? app, PICSRequest? package, bool metaDataOnly = false )
{
List<uint> apps = new List<uint>();
List<uint> packages = new List<uint>();
var apps = new List<PICSRequest>();
var packages = new List<PICSRequest>();

if ( app.HasValue ) apps.Add( app.Value );
if ( package.HasValue ) packages.Add( package.Value );

return PICSGetProductInfo( apps, packages, metaDataOnly );
}

/// <summary>
/// Request product information for a list of apps or packages
/// Results are returned in a <see cref="PICSProductInfoCallback"/> callback.
/// The returned <see cref="AsyncJob{T}"/> can also be awaited to retrieve the callback result.
/// </summary>
/// <param name="apps">List of app ids requested.</param>
/// <param name="packages">List of package ids requested.</param>
/// <param name="metaDataOnly">Whether to send only meta data.</param>
/// <returns>The Job ID of the request. This can be used to find the appropriate <see cref="PICSProductInfoCallback"/>.</returns>
public AsyncJobMultiple<PICSProductInfoCallback> PICSGetProductInfo( IEnumerable<uint> apps, IEnumerable<uint> packages, bool metaDataOnly = false )
{
return PICSGetProductInfo( apps.Select( app => new PICSRequest( app ) ), packages.Select( package => new PICSRequest( package ) ), metaDataOnly );
}

/// <summary>
/// Request product information for a list of apps or packages
/// Results are returned in a <see cref="PICSProductInfoCallback"/> callback.
Expand Down

0 comments on commit 5050024

Please sign in to comment.