From cc9e57636135481176a425db34228f547e4e004b Mon Sep 17 00:00:00 2001 From: Ryan Kistner Date: Sat, 11 Oct 2014 04:45:10 -0600 Subject: [PATCH] Upgraded Steam3Session to latest SteamKit. Added error handling to CollectCDNClientsForDepot --- DepotDownloader/ContentDownloader.cs | 31 +++++++++++++-- DepotDownloader/Program.cs | 2 + DepotDownloader/Steam3Session.cs | 56 +++++++++++++++++----------- 3 files changed, 64 insertions(+), 25 deletions(-) diff --git a/DepotDownloader/ContentDownloader.cs b/DepotDownloader/ContentDownloader.cs index 1b0051a0..32f5ffb7 100644 --- a/DepotDownloader/ContentDownloader.cs +++ b/DepotDownloader/ContentDownloader.cs @@ -439,12 +439,32 @@ namespace DepotDownloader private static ConcurrentQueue CollectCDNClientsForDepot(DepotDownloadInfo depot) { var cdnClients = new ConcurrentQueue(); - CDNClient initialClient = new CDNClient(steam3.steamClient, steam3.AppTickets[depot.id]); - var cdnServers = initialClient.FetchServerList(cellId: (uint)Config.CellID); + CDNClient initialClient = new CDNClient( steam3.steamClient, steam3.AppTickets[depot.id] ); + List cdnServers = null; + int tries = 5; + + while ( tries-- > 0 ) + { + try + { + cdnServers = initialClient.FetchServerList( cellId: (uint)Config.CellID ); + if (cdnServers != null) break; + } + catch (WebException) + { + Console.WriteLine("\nFailed to retrieve content server list. Remaining tries: {0}", tries); + } + } + + if ( cdnServers == null ) + { + Console.WriteLine( "\nUnable to query any content servers for depot {0} - {1}", depot.id, depot.contentName ); + return cdnClients; + } // Grab up to the first eight server in the allegedly best-to-worst order from Steam var limit = cdnServers.Take( Config.MaxServers ); - int tries = 0; + tries = 0; foreach( var s in limit ) { CDNClient c; @@ -754,13 +774,16 @@ namespace DepotDownloader try { chunkData = client.DownloadDepotChunk(depot.id, data); - cdnClients.Enqueue(client); break; } catch { Console.WriteLine("Encountered error downloading chunk {0}", chunkID); } + finally + { + cdnClients.Enqueue(client); + } } if (chunkData == null) diff --git a/DepotDownloader/Program.cs b/DepotDownloader/Program.cs index 326f0754..a0d740af 100644 --- a/DepotDownloader/Program.cs +++ b/DepotDownloader/Program.cs @@ -94,6 +94,8 @@ namespace DepotDownloader ContentDownloader.Config.MaxDownloads = GetParameter(args, "-max-downloads", 4); string branch = GetParameter(args, "-branch") ?? GetParameter(args, "-beta") ?? "Public"; + ContentDownloader.Config.MaxServers = Math.Max(ContentDownloader.Config.MaxServers, ContentDownloader.Config.MaxDownloads); + if (username != null && password == null) { Console.Write("Enter account password for \"{0}\": ", username); diff --git a/DepotDownloader/Steam3Session.cs b/DepotDownloader/Steam3Session.cs index 84f633d6..d9577e67 100644 --- a/DepotDownloader/Steam3Session.cs +++ b/DepotDownloader/Steam3Session.cs @@ -86,7 +86,7 @@ namespace DepotDownloader this.callbacks.Register(new Callback(LogOnCallback)); this.callbacks.Register(new Callback(SessionTokenCallback)); this.callbacks.Register(new Callback(LicenseListCallback)); - this.callbacks.Register(new JobCallback(UpdateMachineAuthCallback)); + this.callbacks.Register(new Callback(UpdateMachineAuthCallback)); Console.Write( "Connecting to Steam3..." ); @@ -128,8 +128,10 @@ namespace DepotDownloader if (AppInfo.ContainsKey(appId) || bAborted) return; - Action cbMethodTokens = (appTokens, jobId) => + bool completed = false; + Action cbMethodTokens = (appTokens) => { + completed = true; if (appTokens.AppTokensDenied.Contains(appId)) { Console.WriteLine("Insufficient privileges to get access token for app {0}", appId); @@ -141,17 +143,19 @@ namespace DepotDownloader } }; - using (JobCallback appTokensCallback = new JobCallback(cbMethodTokens, callbacks, steamApps.PICSGetAccessTokens(new List() { appId }, new List() { }))) + using (var appTokensCallback = new Callback(cbMethodTokens, callbacks, steamApps.PICSGetAccessTokens(new List() { appId }, new List() { }))) { do { WaitForCallbacks(); } - while (!appTokensCallback.Completed && !bAborted); + while (!completed && !bAborted); } - Action cbMethod = (appInfo, jobId) => + completed = false; + Action cbMethod = (appInfo) => { + completed = true; Debug.Assert( appInfo.ResponsePending == false ); foreach (var app_value in appInfo.Apps) @@ -175,13 +179,13 @@ namespace DepotDownloader request.Public = false; } - using (JobCallback appInfoCallback = new JobCallback(cbMethod, callbacks, steamApps.PICSGetProductInfo(new List() { request }, new List() { }))) + using (var appInfoCallback = new Callback(cbMethod, callbacks, steamApps.PICSGetProductInfo(new List() { request }, new List() { }))) { do { WaitForCallbacks(); } - while (!appInfoCallback.Completed && !bAborted); + while (!completed && !bAborted); } } @@ -193,8 +197,10 @@ namespace DepotDownloader if (packages.Count == 0 || bAborted) return; - Action cbMethod = (packageInfo, jobId) => + bool completed = false; + Action cbMethod = (packageInfo) => { + completed = true; Debug.Assert( packageInfo.ResponsePending == false ); foreach (var package_value in packageInfo.Packages) @@ -209,13 +215,13 @@ namespace DepotDownloader } }; - using (JobCallback packageInfoCallback = new JobCallback(cbMethod, callbacks, steamApps.PICSGetProductInfo(new List(), packages))) + using (var packageInfoCallback = new Callback(cbMethod, callbacks, steamApps.PICSGetProductInfo(new List(), packages))) { do { WaitForCallbacks(); } - while (!packageInfoCallback.Completed && !bAborted); + while (!completed && !bAborted); } } @@ -231,8 +237,11 @@ namespace DepotDownloader return; } - Action cbMethod = (appTicket, jobId) => + bool completed = false; + Action cbMethod = (appTicket) => { + completed = true; + if (appTicket.Result != EResult.OK) { Console.WriteLine("Unable to get appticket for {0}: {1}", appTicket.AppID, appTicket.Result); @@ -245,13 +254,13 @@ namespace DepotDownloader } }; - using (JobCallback appTicketCallback = new JobCallback(cbMethod, callbacks, steamApps.GetAppOwnershipTicket(appId))) + using (var appTicketCallback = new Callback(cbMethod, callbacks, steamApps.GetAppOwnershipTicket(appId))) { do { WaitForCallbacks(); } - while (!appTicketCallback.Completed && !bAborted); + while (!completed && !bAborted); } } @@ -260,8 +269,11 @@ namespace DepotDownloader if (DepotKeys.ContainsKey(depotId) || bAborted) return; - Action cbMethod = (depotKey, jobId) => + bool completed = false; + + Action cbMethod = (depotKey) => { + completed = true; Console.WriteLine("Got depot key for {0} result: {1}", depotKey.DepotID, depotKey.Result); if (depotKey.Result != EResult.OK) @@ -273,13 +285,13 @@ namespace DepotDownloader DepotKeys[depotKey.DepotID] = depotKey.DepotKey; }; - using ( var depotKeyCallback = new JobCallback( cbMethod, callbacks, steamApps.GetDepotDecryptionKey( depotId, appid ) ) ) + using ( var depotKeyCallback = new Callback( cbMethod, callbacks, steamApps.GetDepotDecryptionKey( depotId, appid ) ) ) { do { WaitForCallbacks(); } - while ( !depotKeyCallback.Completed && !bAborted ); + while ( !completed && !bAborted ); } } @@ -288,8 +300,10 @@ namespace DepotDownloader if (CDNAuthTokens.ContainsKey(Tuple.Create(depotid, host)) || bAborted) return; - Action cbMethod = (cdnAuth, jobId) => + bool completed = false; + Action cbMethod = (cdnAuth) => { + completed = true; Console.WriteLine("Got CDN auth token for {0} result: {1}", host, cdnAuth.Result); if (cdnAuth.Result != EResult.OK) @@ -301,13 +315,13 @@ namespace DepotDownloader CDNAuthTokens[Tuple.Create(depotid, host)] = cdnAuth; }; - using (var cdnAuthCallback = new JobCallback(cbMethod, callbacks, steamApps.GetCDNAuthToken(depotid, host))) + using (var cdnAuthCallback = new Callback(cbMethod, callbacks, steamApps.GetCDNAuthToken(depotid, host))) { do { WaitForCallbacks(); } - while (!cdnAuthCallback.Completed && !bAborted); + while (!completed && !bAborted); } } @@ -448,7 +462,7 @@ namespace DepotDownloader Console.WriteLine("Licenses: {0}", string.Join(", ", licenseQuery)); } - private void UpdateMachineAuthCallback(SteamUser.UpdateMachineAuthCallback machineAuth, JobID jobId) + private void UpdateMachineAuthCallback(SteamUser.UpdateMachineAuthCallback machineAuth) { byte[] hash = Util.SHAHash(machineAuth.Data); Console.WriteLine("Got Machine Auth: {0} {1} {2} {3}", machineAuth.FileName, machineAuth.Offset, machineAuth.BytesToWrite, machineAuth.Data.Length, hash); @@ -470,7 +484,7 @@ namespace DepotDownloader LastError = 0, // result from win32 GetLastError Result = EResult.OK, // if everything went okay, otherwise ~who knows~ - JobID = jobId, // so we respond to the correct server job + JobID = machineAuth.JobID, // so we respond to the correct server job }; // send off our response