Check if the user has access to a depot before attempting to download it.

pull/8/head
Scott Ehlert 14 years ago
parent bfe267e194
commit 5d4590e6cf

@ -12,6 +12,9 @@ namespace DepotDownloader
{
[BlobField( FieldKey = CDRFields.eFieldApplicationsRecord, Depth = 1, Complex = true )]
public List<App> Apps { get; set; }
[BlobField( FieldKey = CDRFields.eFieldSubscriptionsRecord, Depth = 1, Complex = true )]
public List<Sub> Subs { get; set; }
}
class App
@ -35,6 +38,15 @@ namespace DepotDownloader
public Dictionary<string, string> UserDefined { get; private set; }
}
class Sub
{
[BlobField( FieldKey = CDRSubRecordFields.eFieldSubId, Depth = 1 )]
public int SubID { get; set; }
[BlobField( FieldKey = CDRSubRecordFields.eFieldAppIdsRecord, Depth = 1 )]
public List<int> AppIDs { get; private set; }
}
class AppVersion
{
[BlobField( FieldKey = CDRAppVersionFields.eFieldVersionId )]
@ -121,6 +133,11 @@ namespace DepotDownloader
return cdrObj.Apps.Find( ( app ) => app.AppID == appID );
}
static Sub GetSubBlob( int subID )
{
return cdrObj.Subs.Find( ( sub ) => sub.SubID == subID );
}
public static string GetDepotName( int depotId )
{
// Match hardcoded names from hldsupdatetool for certain HL1 depots
@ -352,6 +369,16 @@ namespace DepotDownloader
Console.WriteLine( "\t\"{0}\"", game );
}
public static bool SubHasDepot( int subId, int depotId )
{
Sub sub = GetSubBlob( subId );
if ( sub == null )
return false;
return sub.AppIDs.Contains( depotId );
}
static byte[] GetCdr()
{
try

@ -108,6 +108,20 @@ namespace DepotDownloader
return false;
}
static bool AccountHasAccess( int depotId )
{
if ( steam3 == null || steam3.Licenses == null )
return CDRManager.SubHasDepot( 0, depotId );
foreach ( var license in steam3.Licenses )
{
if ( CDRManager.SubHasDepot( ( int )license.PackageID, depotId ) )
return true;
}
return false;
}
public static void Download( int depotId, int depotVersion, int cellId, string username, string password, bool onlyManifest, bool gameServer, bool exclude, string installDir, string[] fileList )
{
if ( !CreateDirectories( depotId, depotVersion, ref installDir ) )
@ -135,6 +149,17 @@ namespace DepotDownloader
credentials = GetCredentials( ( uint )depotId, username, password );
}
if ( !AccountHasAccess( depotId ) )
{
string contentName = CDRManager.GetDepotName( depotId );
Console.WriteLine( "Depot {0} ({1}) is not available from this account.", depotId, contentName );
if ( steam3 != null )
steam3.Disconnect();
return;
}
string manifestFile = Path.Combine( installDir, "manifest.bin" );
string txtManifest = Path.Combine( installDir, "manifest.txt" );

@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using SteamKit2;
using System.Threading;
using System.Collections.ObjectModel;
namespace DepotDownloader
{
@ -18,6 +19,12 @@ namespace DepotDownloader
public byte[] AppTicket { get; set; }
}
public ReadOnlyCollection<SteamApps.LicenseListCallback.License> Licenses
{
get;
private set;
}
SteamClient steamClient;
SteamUser steamUser;
@ -90,7 +97,7 @@ namespace DepotDownloader
if ( diff > STEAM3_TIMEOUT && !bConnected )
break;
if ( credentials.HasSessionToken && credentials.AppTicket != null )
if ( credentials.HasSessionToken && credentials.AppTicket != null && Licenses != null )
break;
if ( callback == null )
@ -162,6 +169,21 @@ namespace DepotDownloader
credentials.SessionToken = msg.SessionToken;
credentials.HasSessionToken = true;
}
if ( callback.IsType<SteamApps.LicenseListCallback>() )
{
var msg = callback as SteamApps.LicenseListCallback;
if ( msg.Result != EResult.OK )
{
Console.WriteLine( "Unable to get license list: {0} ", msg.Result );
steamUser.LogOff();
break;
}
Console.WriteLine( "Got {0} licenses for account!", msg.LicenseList.Count );
Licenses = msg.LicenseList;
}
}
credentialHandle.Set();

Loading…
Cancel
Save