From 80f0dcf56c170ff41955544586a3e192114a2f78 Mon Sep 17 00:00:00 2001 From: Ryan Kistner Date: Mon, 11 Jun 2012 01:05:40 -0600 Subject: [PATCH] Blob Refactor --HG-- extra : rebase_source : 98e0b6385cc654ff137fa216c4b403be5d36fa26 --- DepotDownloader/CDRManager.cs | 102 ++++++++++----------- DepotDownloader/ContentDownloader.cs | 10 +- DepotDownloader/DepotDownloader.csproj | 3 +- DepotDownloader/DownloadConfig.cs | 5 +- DepotDownloader/Program.cs | 17 +--- DepotDownloader/Properties/AssemblyInfo.cs | 1 - DepotDownloader/ServerCache.cs | 2 - DepotDownloader/Steam3Session.cs | 6 +- DepotDownloader/Util.cs | 4 +- 9 files changed, 60 insertions(+), 90 deletions(-) diff --git a/DepotDownloader/CDRManager.cs b/DepotDownloader/CDRManager.cs index 8630cf58..e36bd4d2 100644 --- a/DepotDownloader/CDRManager.cs +++ b/DepotDownloader/CDRManager.cs @@ -1,79 +1,76 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; using System.IO; -using SteamKit2; -using System.Net; using System.Security.Cryptography; +using SteamKit2; using SteamKit2.Blob; namespace DepotDownloader { class CDR { - [BlobField( FieldKey = CDRFields.eFieldApplicationsRecord, Depth = 1, Complex = true )] - public List Apps { get; set; } + [BlobField(1)] + public List Apps; - [BlobField( FieldKey = CDRFields.eFieldSubscriptionsRecord, Depth = 1, Complex = true )] - public List Subs { get; set; } + [BlobField(2)] + public List Subs; } class App { - [BlobField( FieldKey = CDRAppRecordFields.eFieldName, Depth = 1 )] - public string Name { get; set; } - - [BlobField( FieldKey = CDRAppRecordFields.eFieldAppId, Depth = 1 )] - public int AppID { get; set; } - - [BlobField( FieldKey = CDRAppRecordFields.eFieldCurrentVersionId, Depth = 1 )] - public int CurrentVersion { get; set; } - - [BlobField( FieldKey = CDRAppRecordFields.eFieldVersionsRecord, Complex = true, Depth = 1 )] - public List Versions { get; private set; } - - [BlobField( FieldKey = CDRAppRecordFields.eFieldFilesystemsRecord, Complex = true, Depth = 1 )] - public List FileSystems { get; private set; } - - [BlobField( FieldKey = CDRAppRecordFields.eFieldUserDefinedRecord, Depth = 1 )] - public Dictionary UserDefined { get; private set; } - - [BlobField( FieldKey = CDRAppRecordFields.eFieldBetaVersionId, Depth = 1 )] - public int BetaVersion { get; set; } + [BlobField(2)] + public string Name; + + [BlobField(1)] + public int AppID; + + [BlobField(11)] + public int CurrentVersion; + + [BlobField(10)] + public List Versions; + + [BlobField(12)] + public List FileSystems; + + [BlobField(14)] + public Dictionary UserDefined; + + [BlobField(16)] + public int BetaVersion; } class Sub { - [BlobField( FieldKey = CDRSubRecordFields.eFieldSubId, Depth = 1 )] - public int SubID { get; set; } - - [BlobField( FieldKey = CDRSubRecordFields.eFieldAppIdsRecord, Depth = 1 )] - public List AppIDs { get; private set; } + [BlobField(1)] + public int SubID; + + [BlobField(6)] + public List AppIDs; } class AppVersion { - [BlobField( FieldKey = CDRAppVersionFields.eFieldVersionId )] - public uint VersionID { get; set; } + [BlobField(2)] + public uint VersionID; - [BlobField( FieldKey = CDRAppVersionFields.eFieldDepotEncryptionKey )] - public string DepotEncryptionKey { get; set; } + [BlobField(5)] + public string DepotEncryptionKey; - [BlobField( FieldKey = CDRAppVersionFields.eFieldIsEncryptionKeyAvailable )] - public bool IsEncryptionKeyAvailable { get; set; } + [BlobField(6)] + public bool IsEncryptionKeyAvailable; } class FileSystem { - [BlobField( FieldKey = CDRAppFilesystemFields.eFieldAppId )] - public int AppID { get; set; } + [BlobField(1)] + public int AppID; - [BlobField( FieldKey = CDRAppFilesystemFields.eFieldMountName )] - public string Name { get; set; } + [BlobField(2)] + public string Name; - [BlobField( FieldKey = CDRAppFilesystemFields.eFieldPlatform )] - public string Platform { get; set; } + [BlobField(4)] + public string Platform; } static class CDRManager @@ -82,7 +79,6 @@ namespace DepotDownloader static CDR cdrObj; - public static void Update() { Console.Write( "Updating CDR..." ); @@ -122,12 +118,9 @@ namespace DepotDownloader return; } - - using ( var reader = BlobTypedReader.Create( new MemoryStream( cdr ) ) ) + using(BlobReader reader = BlobReader.CreateFrom(new MemoryStream(cdr))) { - reader.Process(); - - cdrObj = reader.Target; + cdrObj = (CDR)BlobTypedReader.Deserialize(reader, typeof(CDR)); } Console.WriteLine( " Done!" ); @@ -135,12 +128,12 @@ namespace DepotDownloader static App GetAppBlob( int appID ) { - return cdrObj.Apps.Find( ( app ) => app.AppID == appID ); + return cdrObj.Apps.Find( app => app.AppID == appID ); } static Sub GetSubBlob( int subID ) { - return cdrObj.Subs.Find( ( sub ) => sub.SubID == subID ); + return cdrObj.Subs.Find( sub => sub.SubID == subID ); } public static string GetDepotName( int depotId ) @@ -232,7 +225,7 @@ namespace DepotDownloader platformStr = "windows"; else if ( Util.IsMacOSX() ) platformStr = "macos"; - + foreach ( var blobField in appInfoBlob.FileSystems ) { string depotPlatform = blobField.Platform; @@ -288,6 +281,7 @@ namespace DepotDownloader } } } + } // For HL1 server installs, this is hardcoded in hldsupdatetool diff --git a/DepotDownloader/ContentDownloader.cs b/DepotDownloader/ContentDownloader.cs index 87996cd7..60f6b42d 100644 --- a/DepotDownloader/ContentDownloader.cs +++ b/DepotDownloader/ContentDownloader.cs @@ -1,15 +1,13 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; -using System.Text; -using SteamKit2; using System.Net; -using System.IO; -using System.IO.Compression; -using System.Diagnostics; -using System.Text.RegularExpressions; using System.Net.Sockets; +using System.Text; +using System.Text.RegularExpressions; using System.Threading; +using SteamKit2; namespace DepotDownloader { diff --git a/DepotDownloader/DepotDownloader.csproj b/DepotDownloader/DepotDownloader.csproj index 2f879a06..3dbb75c8 100644 --- a/DepotDownloader/DepotDownloader.csproj +++ b/DepotDownloader/DepotDownloader.csproj @@ -43,6 +43,7 @@ 4 AllRules.ruleset x86 + false pdbonly @@ -52,7 +53,7 @@ prompt 4 AllRules.ruleset - x86 + AnyCPU diff --git a/DepotDownloader/DownloadConfig.cs b/DepotDownloader/DownloadConfig.cs index b3470584..1880a7de 100644 --- a/DepotDownloader/DownloadConfig.cs +++ b/DepotDownloader/DownloadConfig.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Collections.Generic; using System.Text.RegularExpressions; namespace DepotDownloader diff --git a/DepotDownloader/Program.cs b/DepotDownloader/Program.cs index e6d4d97e..3beb138c 100644 --- a/DepotDownloader/Program.cs +++ b/DepotDownloader/Program.cs @@ -1,11 +1,8 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using SteamKit2; using System.IO; using System.Text.RegularExpressions; -using SteamKit2.Blob; +using SteamKit2; namespace DepotDownloader { @@ -24,17 +21,7 @@ namespace DepotDownloader ServerCache.Build(); CDRManager.Update(); - - if ( HasParameter( args, "-dumpcdr-xml" ) ) - { - BlobXmlReader bxr; - using ( bxr = BlobXmlReader.Create( "cdr.blob", "cdrdump.xml" ) ) - { - bxr.Process(); - } - - return; - } + return; if (HasParameter( args, "-list" ) ) { diff --git a/DepotDownloader/Properties/AssemblyInfo.cs b/DepotDownloader/Properties/AssemblyInfo.cs index 811f5d1f..ea2570f1 100644 --- a/DepotDownloader/Properties/AssemblyInfo.cs +++ b/DepotDownloader/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following diff --git a/DepotDownloader/ServerCache.cs b/DepotDownloader/ServerCache.cs index a0cee389..8e9479fe 100644 --- a/DepotDownloader/ServerCache.cs +++ b/DepotDownloader/ServerCache.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Net; using SteamKit2; diff --git a/DepotDownloader/Steam3Session.cs b/DepotDownloader/Steam3Session.cs index 24d33127..036f9498 100644 --- a/DepotDownloader/Steam3Session.cs +++ b/DepotDownloader/Steam3Session.cs @@ -1,11 +1,9 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using SteamKit2; -using System.Threading; using System.Collections.ObjectModel; using System.IO; +using System.Linq; +using SteamKit2; namespace DepotDownloader { diff --git a/DepotDownloader/Util.cs b/DepotDownloader/Util.cs index 9a787c7c..cdadb049 100644 --- a/DepotDownloader/Util.cs +++ b/DepotDownloader/Util.cs @@ -1,10 +1,8 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.IO; using System.Runtime.InteropServices; using System.Security.Cryptography; +using System.Text; using Classless.Hasher; namespace DepotDownloader