DepotDownloader: Switched to PICS. Started anonymous download support.

pull/8/head
Ryan Kistner 13 years ago
parent 2532f88768
commit eb64860ae8

@ -194,19 +194,21 @@ namespace DepotDownloader
if ( steam3 == null || steam3.Licenses == null ) if ( steam3 == null || steam3.Licenses == null )
return CDRManager.SubHasDepot( 0, depotId ); return CDRManager.SubHasDepot( 0, depotId );
steam3.RequestPackageInfo( steam3.Licenses.Select( x => x.PackageID ) );
foreach ( var license in steam3.Licenses ) foreach ( var license in steam3.Licenses )
{ {
steam3.RequestPackageInfo(license.PackageID);
SteamApps.PackageInfoCallback.Package package; SteamApps.PICSProductInfoCallback.PICSProductInfo package;
if (steam3.PackageInfo.TryGetValue((uint)license.PackageID, out package) && package.Status == SteamApps.PackageInfoCallback.Package.PackageStatus.OK) if ( steam3.PackageInfo.TryGetValue( (uint)license.PackageID, out package ) || package == null )
{ {
KeyValue root = package.Data[license.PackageID.ToString()]; KeyValue root = package.KeyValues[license.PackageID.ToString()];
KeyValue subset = (appId == true ? root["appids"] : root["depotids"]); KeyValue subset = (appId == true ? root["appids"] : root["depotids"]);
foreach (var child in subset.Children) foreach ( var child in subset.Children )
{ {
if (child.AsInteger() == depotId) if ( child.AsInteger() == depotId )
return true; return true;
} }
} }
@ -250,25 +252,41 @@ namespace DepotDownloader
return true; return true;
} }
static KeyValue GetSteam3AppSection(int appId, EAppInfoSection section) internal static KeyValue GetSteam3AppSection( int appId, EAppInfoSection section )
{ {
if (steam3 == null || steam3.AppInfo == null) if (steam3 == null || steam3.AppInfo == null)
{ {
return null; return null;
} }
SteamApps.AppInfoCallback.App app; SteamApps.PICSProductInfoCallback.PICSProductInfo app;
if (!steam3.AppInfo.TryGetValue((uint)appId, out app)) if ( !steam3.AppInfo.TryGetValue( (uint)appId, out app ) || app == null )
{ {
return null; return null;
} }
KeyValue section_kv; KeyValue appinfo = app.KeyValues;
if (!app.Sections.TryGetValue(section, out section_kv)) string section_key;
switch (section)
{ {
return null; case EAppInfoSection.Common:
section_key = "common";
break;
case EAppInfoSection.Extended:
section_key = "extended";
break;
case EAppInfoSection.Config:
section_key = "config";
break;
case EAppInfoSection.Depots:
section_key = "depots";
break;
default:
throw new NotImplementedException();
} }
KeyValue section_kv = appinfo.Children.Where(c => c.Name == section_key).FirstOrDefault();
return section_kv; return section_kv;
} }
@ -303,8 +321,8 @@ namespace DepotDownloader
return 0; return 0;
} }
SteamApps.AppInfoCallback.App app; SteamApps.PICSProductInfoCallback.PICSProductInfo app;
if (!steam3.AppInfo.TryGetValue((uint)appId, out app)) if (!steam3.AppInfo.TryGetValue((uint)appId, out app) || app == null)
{ {
return 0; return 0;
} }

@ -32,6 +32,7 @@ namespace DepotDownloader
bool bApp = false; bool bApp = false;
bool bListDepots = HasParameter(args, "-listdepots"); bool bListDepots = HasParameter(args, "-listdepots");
bool bDumpManifest = HasParameter( args, "-manifest" ); bool bDumpManifest = HasParameter( args, "-manifest" );
bool bSignonSteam3 = HasParameter( args, "-username" ) || HasParameter( args, "-anonymous" );
int appId = -1; int appId = -1;
int depotId = -1; int depotId = -1;
@ -62,7 +63,7 @@ namespace DepotDownloader
if (cellId == -1) if (cellId == -1)
{ {
cellId = 0; cellId = 0;
if (GetStringParameter(args, "-username") == null) if (!bSignonSteam3)
{ {
Console.WriteLine( Console.WriteLine(
"Warning: Using default CellID of 0! This may lead to slow downloads. " + "Warning: Using default CellID of 0! This may lead to slow downloads. " +
@ -157,7 +158,7 @@ namespace DepotDownloader
Console.WriteLine(); Console.WriteLine();
} }
if (username != null) if (bSignonSteam3)
{ {
ContentDownloader.InitializeSteam3(username, password); ContentDownloader.InitializeSteam3(username, password);
} }

@ -4,6 +4,7 @@ using System.Collections.ObjectModel;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using SteamKit2; using SteamKit2;
using System.Diagnostics;
namespace DepotDownloader namespace DepotDownloader
{ {
@ -12,12 +13,13 @@ namespace DepotDownloader
{ {
public class Credentials public class Credentials
{ {
public bool LoggedOn { get; set; }
public ulong SessionToken { get; set; } public ulong SessionToken { get; set; }
public Steam2Ticket Steam2Ticket { get; set; } public Steam2Ticket Steam2Ticket { get; set; }
public bool IsValid public bool IsValid
{ {
get { return SessionToken > 0 && Steam2Ticket != null; } get { return LoggedOn; }// && SessionToken > 0 && Steam2Ticket != null; }
} }
} }
@ -29,8 +31,8 @@ namespace DepotDownloader
public Dictionary<uint, byte[]> AppTickets { get; private set; } public Dictionary<uint, byte[]> AppTickets { get; private set; }
public Dictionary<uint, byte[]> DepotKeys { get; private set; } public Dictionary<uint, byte[]> DepotKeys { get; private set; }
public Dictionary<uint, SteamApps.AppInfoCallback.App> AppInfo { get; private set; } public Dictionary<uint, SteamApps.PICSProductInfoCallback.PICSProductInfo> AppInfo { get; private set; }
public Dictionary<uint, SteamApps.PackageInfoCallback.Package> PackageInfo { get; private set; } public Dictionary<uint, SteamApps.PICSProductInfoCallback.PICSProductInfo> PackageInfo { get; private set; }
public Dictionary<uint, bool> AppInfoOverridesCDR { get; private set; } public Dictionary<uint, bool> AppInfoOverridesCDR { get; private set; }
public SteamClient steamClient; public SteamClient steamClient;
@ -50,8 +52,6 @@ namespace DepotDownloader
// output // output
Credentials credentials; Credentials credentials;
JobCallback<SteamApps.PackageInfoCallback> packageInfoCallback;
static readonly TimeSpan STEAM3_TIMEOUT = TimeSpan.FromSeconds( 30 ); static readonly TimeSpan STEAM3_TIMEOUT = TimeSpan.FromSeconds( 30 );
@ -65,8 +65,8 @@ namespace DepotDownloader
this.AppTickets = new Dictionary<uint, byte[]>(); this.AppTickets = new Dictionary<uint, byte[]>();
this.DepotKeys = new Dictionary<uint, byte[]>(); this.DepotKeys = new Dictionary<uint, byte[]>();
this.AppInfo = new Dictionary<uint, SteamApps.AppInfoCallback.App>(); this.AppInfo = new Dictionary<uint, SteamApps.PICSProductInfoCallback.PICSProductInfo>();
this.PackageInfo = new Dictionary<uint, SteamApps.PackageInfoCallback.Package>(); this.PackageInfo = new Dictionary<uint, SteamApps.PICSProductInfoCallback.PICSProductInfo>();
this.AppInfoOverridesCDR = new Dictionary<uint, bool>(); this.AppInfoOverridesCDR = new Dictionary<uint, bool>();
this.steamClient = new SteamClient(); this.steamClient = new SteamClient();
@ -112,28 +112,34 @@ namespace DepotDownloader
if (AppInfo.ContainsKey(appId) || bAborted) if (AppInfo.ContainsKey(appId) || bAborted)
return; return;
Action<SteamApps.AppInfoCallback, JobID> cbMethod = (appInfo, jobId) => Action<SteamApps.PICSProductInfoCallback, JobID> cbMethod = (appInfo, jobId) =>
{ {
foreach (var app in appInfo.Apps) Debug.Assert( appInfo.ResponsePending == false );
foreach (var app_value in appInfo.Apps)
{ {
Console.WriteLine("Got AppInfo for {0}: {1}", app.AppID, app.Status); var app = app_value.Value;
AppInfo.Add(app.AppID, app);
if (app.Status == SteamApps.AppInfoCallback.App.AppInfoStatus.Unknown) Console.WriteLine("Got AppInfo for {0}", app.ID);
continue; AppInfo.Add(app.ID, app);
KeyValue depots; KeyValue depots = ContentDownloader.GetSteam3AppSection((int)app.ID, EAppInfoSection.Depots);
if (app.Sections.TryGetValue(EAppInfoSection.Depots, out depots)) if (depots != null)
{ {
if (depots["OverridesCDDB"].AsBoolean(false)) if (depots["OverridesCDDB"].AsBoolean(false))
{ {
AppInfoOverridesCDR[app.AppID] = true; AppInfoOverridesCDR[app.ID] = true;
} }
} }
} }
foreach (var app in appInfo.UnknownApps)
{
AppInfo.Add(app, null);
}
}; };
using (JobCallback<SteamApps.AppInfoCallback> appInfoCallback = new JobCallback<SteamApps.AppInfoCallback>(cbMethod, callbacks, steamApps.GetAppInfo(appId))) using (JobCallback<SteamApps.PICSProductInfoCallback> appInfoCallback = new JobCallback<SteamApps.PICSProductInfoCallback>(cbMethod, callbacks, steamApps.PICSGetProductInfo(appId, null, false)))
{ {
do do
{ {
@ -143,30 +149,37 @@ namespace DepotDownloader
} }
} }
public void RequestPackageInfo(uint packageId) public void RequestPackageInfo(IEnumerable<uint> packageIds)
{ {
if (PackageInfo.ContainsKey(packageId)) List<uint> packages = packageIds.ToList();
packages.RemoveAll(pid => PackageInfo.ContainsKey(pid));
if (packages.Count == 0 || bAborted)
return; return;
if (packageInfoCallback != null) Action<SteamApps.PICSProductInfoCallback, JobID> cbMethod = (packageInfo, jobId) =>
{ {
do Debug.Assert( packageInfo.ResponsePending == false );
foreach (var package_value in packageInfo.Packages)
{ {
WaitForCallbacks(); var package = package_value.Value;
PackageInfo.Add(package.ID, package);
} }
while (!packageInfoCallback.Completed && !bAborted);
if (PackageInfo.ContainsKey(packageId)) foreach (var package in packageInfo.UnknownPackages)
return; {
} PackageInfo.Add(package, null);
}
};
using (var singlePackageInfoCallback = new JobCallback<SteamApps.PackageInfoCallback>(PackageInfoCallback, callbacks, steamApps.GetPackageInfo(packageId))) using (JobCallback<SteamApps.PICSProductInfoCallback> packageInfoCallback = new JobCallback<SteamApps.PICSProductInfoCallback>(cbMethod, callbacks, steamApps.PICSGetProductInfo(new List<uint>(), packages)))
{ {
do do
{ {
WaitForCallbacks(); WaitForCallbacks();
} }
while (!singlePackageInfoCallback.Completed && !bAborted); while (!packageInfoCallback.Completed && !bAborted);
} }
} }
@ -269,9 +282,16 @@ namespace DepotDownloader
{ {
Console.WriteLine(" Done!"); Console.WriteLine(" Done!");
bConnected = true; bConnected = true;
steamUser.LogOn(logonDetails); if ( logonDetails.Username == null )
{
Console.Write("Logging '{0}' into Steam3...", logonDetails.Username); Console.Write( "Logging anonymously into Steam3..." );
steamUser.LogOnAnonymous();
}
else
{
Console.Write( "Logging '{0}' into Steam3...", logonDetails.Username );
steamUser.LogOn( logonDetails );
}
} }
private void LogOnCallback(SteamUser.LoggedOnCallback loggedOn) private void LogOnCallback(SteamUser.LoggedOnCallback loggedOn)
@ -305,12 +325,17 @@ namespace DepotDownloader
Console.WriteLine(" Done!"); Console.WriteLine(" Done!");
Console.WriteLine("Got Steam2 Ticket!"); credentials.LoggedOn = true;
credentials.Steam2Ticket = loggedOn.Steam2Ticket;
if (loggedOn.Steam2Ticket != null)
{
Console.WriteLine("Got Steam2 Ticket!");
credentials.Steam2Ticket = loggedOn.Steam2Ticket;
}
if (ContentDownloader.Config.CellID == 0) if (ContentDownloader.Config.CellID == 0)
{ {
Console.WriteLine("Using Steam3 suggest CellID: " + loggedOn.CellID); Console.WriteLine("Using Steam3 suggested CellID: " + loggedOn.CellID);
ContentDownloader.Config.CellID = (int)loggedOn.CellID; ContentDownloader.Config.CellID = (int)loggedOn.CellID;
} }
} }
@ -340,16 +365,6 @@ namespace DepotDownloader
}); });
Console.WriteLine("Licenses: {0}", string.Join(", ", licenseQuery)); Console.WriteLine("Licenses: {0}", string.Join(", ", licenseQuery));
packageInfoCallback = new JobCallback<SteamApps.PackageInfoCallback>(PackageInfoCallback, callbacks, steamApps.GetPackageInfo(licenseQuery));
}
private void PackageInfoCallback(SteamApps.PackageInfoCallback packageInfo, JobID jobid)
{
foreach (var package in packageInfo.Packages)
{
PackageInfo[package.PackageID] = package;
}
} }
private void UpdateMachineAuthCallback(SteamUser.UpdateMachineAuthCallback machineAuth, JobID jobId) private void UpdateMachineAuthCallback(SteamUser.UpdateMachineAuthCallback machineAuth, JobID jobId)

Loading…
Cancel
Save