From eb64860ae89f216760110485d1d0f97de7f54b18 Mon Sep 17 00:00:00 2001 From: Ryan Kistner Date: Thu, 13 Dec 2012 01:16:49 -0700 Subject: [PATCH] DepotDownloader: Switched to PICS. Started anonymous download support. --- DepotDownloader/ContentDownloader.cs | 48 +++++++++---- DepotDownloader/Program.cs | 5 +- DepotDownloader/Steam3Session.cs | 103 +++++++++++++++------------ 3 files changed, 95 insertions(+), 61 deletions(-) diff --git a/DepotDownloader/ContentDownloader.cs b/DepotDownloader/ContentDownloader.cs index 866b7751..95c0a7d4 100644 --- a/DepotDownloader/ContentDownloader.cs +++ b/DepotDownloader/ContentDownloader.cs @@ -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; } diff --git a/DepotDownloader/Program.cs b/DepotDownloader/Program.cs index 05d991af..17550a9b 100644 --- a/DepotDownloader/Program.cs +++ b/DepotDownloader/Program.cs @@ -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); } diff --git a/DepotDownloader/Steam3Session.cs b/DepotDownloader/Steam3Session.cs index 4eb61b21..d12e7c63 100644 --- a/DepotDownloader/Steam3Session.cs +++ b/DepotDownloader/Steam3Session.cs @@ -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 AppTickets { get; private set; } public Dictionary DepotKeys { get; private set; } - public Dictionary AppInfo { get; private set; } - public Dictionary PackageInfo { get; private set; } + public Dictionary AppInfo { get; private set; } + public Dictionary PackageInfo { get; private set; } public Dictionary AppInfoOverridesCDR { get; private set; } public SteamClient steamClient; @@ -50,8 +52,6 @@ namespace DepotDownloader // output Credentials credentials; - JobCallback packageInfoCallback; - static readonly TimeSpan STEAM3_TIMEOUT = TimeSpan.FromSeconds( 30 ); @@ -65,8 +65,8 @@ namespace DepotDownloader this.AppTickets = new Dictionary(); this.DepotKeys = new Dictionary(); - this.AppInfo = new Dictionary(); - this.PackageInfo = new Dictionary(); + this.AppInfo = new Dictionary(); + this.PackageInfo = new Dictionary(); this.AppInfoOverridesCDR = new Dictionary(); this.steamClient = new SteamClient(); @@ -112,28 +112,34 @@ namespace DepotDownloader if (AppInfo.ContainsKey(appId) || bAborted) return; - Action cbMethod = (appInfo, jobId) => + Action 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 appInfoCallback = new JobCallback(cbMethod, callbacks, steamApps.GetAppInfo(appId))) + using (JobCallback appInfoCallback = new JobCallback(cbMethod, callbacks, steamApps.PICSGetProductInfo(appId, null, false))) { do { @@ -143,30 +149,37 @@ namespace DepotDownloader } } - public void RequestPackageInfo(uint packageId) + public void RequestPackageInfo(IEnumerable packageIds) { - if (PackageInfo.ContainsKey(packageId)) + List packages = packageIds.ToList(); + packages.RemoveAll(pid => PackageInfo.ContainsKey(pid)); + + if (packages.Count == 0 || bAborted) return; - if (packageInfoCallback != null) + Action 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(PackageInfoCallback, callbacks, steamApps.GetPackageInfo(packageId))) + using (JobCallback packageInfoCallback = new JobCallback(cbMethod, callbacks, steamApps.PICSGetProductInfo(new List(), 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(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)