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 )
return CDRManager.SubHasDepot( 0, depotId );
steam3.RequestPackageInfo( steam3.Licenses.Select( x => x.PackageID ) );
foreach ( var license in steam3.Licenses )
{
steam3.RequestPackageInfo(license.PackageID);
SteamApps.PackageInfoCallback.Package package;
if (steam3.PackageInfo.TryGetValue((uint)license.PackageID, out package) && package.Status == SteamApps.PackageInfoCallback.Package.PackageStatus.OK)
SteamApps.PICSProductInfoCallback.PICSProductInfo package;
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"]);
foreach (var child in subset.Children)
foreach ( var child in subset.Children )
{
if (child.AsInteger() == depotId)
if ( child.AsInteger() == depotId )
return true;
}
}
@ -250,25 +252,41 @@ namespace DepotDownloader
return true;
}
static KeyValue GetSteam3AppSection(int appId, EAppInfoSection section)
internal static KeyValue GetSteam3AppSection( int appId, EAppInfoSection section )
{
if (steam3 == null || steam3.AppInfo == null)
{
return null;
}
SteamApps.AppInfoCallback.App app;
if (!steam3.AppInfo.TryGetValue((uint)appId, out app))
SteamApps.PICSProductInfoCallback.PICSProductInfo app;
if ( !steam3.AppInfo.TryGetValue( (uint)appId, out app ) || app == null )
{
return null;
}
KeyValue section_kv;
if (!app.Sections.TryGetValue(section, out section_kv))
KeyValue appinfo = app.KeyValues;
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;
}
@ -303,8 +321,8 @@ namespace DepotDownloader
return 0;
}
SteamApps.AppInfoCallback.App app;
if (!steam3.AppInfo.TryGetValue((uint)appId, out app))
SteamApps.PICSProductInfoCallback.PICSProductInfo app;
if (!steam3.AppInfo.TryGetValue((uint)appId, out app) || app == null)
{
return 0;
}

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

@ -4,6 +4,7 @@ using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using SteamKit2;
using System.Diagnostics;
namespace DepotDownloader
{
@ -12,12 +13,13 @@ namespace DepotDownloader
{
public class Credentials
{
public bool LoggedOn { get; set; }
public ulong SessionToken { get; set; }
public Steam2Ticket Steam2Ticket { get; set; }
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[]> DepotKeys { get; private set; }
public Dictionary<uint, SteamApps.AppInfoCallback.App> AppInfo { get; private set; }
public Dictionary<uint, SteamApps.PackageInfoCallback.Package> PackageInfo { get; private set; }
public Dictionary<uint, SteamApps.PICSProductInfoCallback.PICSProductInfo> AppInfo { get; private set; }
public Dictionary<uint, SteamApps.PICSProductInfoCallback.PICSProductInfo> PackageInfo { get; private set; }
public Dictionary<uint, bool> AppInfoOverridesCDR { get; private set; }
public SteamClient steamClient;
@ -50,8 +52,6 @@ namespace DepotDownloader
// output
Credentials credentials;
JobCallback<SteamApps.PackageInfoCallback> packageInfoCallback;
static readonly TimeSpan STEAM3_TIMEOUT = TimeSpan.FromSeconds( 30 );
@ -65,8 +65,8 @@ namespace DepotDownloader
this.AppTickets = new Dictionary<uint, byte[]>();
this.DepotKeys = new Dictionary<uint, byte[]>();
this.AppInfo = new Dictionary<uint, SteamApps.AppInfoCallback.App>();
this.PackageInfo = new Dictionary<uint, SteamApps.PackageInfoCallback.Package>();
this.AppInfo = new Dictionary<uint, SteamApps.PICSProductInfoCallback.PICSProductInfo>();
this.PackageInfo = new Dictionary<uint, SteamApps.PICSProductInfoCallback.PICSProductInfo>();
this.AppInfoOverridesCDR = new Dictionary<uint, bool>();
this.steamClient = new SteamClient();
@ -112,28 +112,34 @@ namespace DepotDownloader
if (AppInfo.ContainsKey(appId) || bAborted)
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);
AppInfo.Add(app.AppID, app);
var app = app_value.Value;
if (app.Status == SteamApps.AppInfoCallback.App.AppInfoStatus.Unknown)
continue;
Console.WriteLine("Got AppInfo for {0}", app.ID);
AppInfo.Add(app.ID, app);
KeyValue depots;
if (app.Sections.TryGetValue(EAppInfoSection.Depots, out depots))
KeyValue depots = ContentDownloader.GetSteam3AppSection((int)app.ID, EAppInfoSection.Depots);
if (depots != null)
{
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
{
@ -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;
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))
return;
}
foreach (var package in packageInfo.UnknownPackages)
{
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
{
WaitForCallbacks();
}
while (!singlePackageInfoCallback.Completed && !bAborted);
while (!packageInfoCallback.Completed && !bAborted);
}
}
@ -269,9 +282,16 @@ namespace DepotDownloader
{
Console.WriteLine(" Done!");
bConnected = true;
steamUser.LogOn(logonDetails);
Console.Write("Logging '{0}' into Steam3...", logonDetails.Username);
if ( logonDetails.Username == null )
{
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)
@ -305,12 +325,17 @@ namespace DepotDownloader
Console.WriteLine(" Done!");
Console.WriteLine("Got Steam2 Ticket!");
credentials.Steam2Ticket = loggedOn.Steam2Ticket;
credentials.LoggedOn = true;
if (loggedOn.Steam2Ticket != null)
{
Console.WriteLine("Got Steam2 Ticket!");
credentials.Steam2Ticket = loggedOn.Steam2Ticket;
}
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;
}
}
@ -340,16 +365,6 @@ namespace DepotDownloader
});
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)

Loading…
Cancel
Save