From f11dd05096900a2502023ce4c05d11b9195dd763 Mon Sep 17 00:00:00 2001 From: Scott Ehlert Date: Wed, 29 Jun 2011 01:45:22 -0500 Subject: [PATCH] Exclude files listed in reslists/*/exclude.lst when using the -game parameter. This functionality matches hldsupdatetool. --- DepotDownloader/ContentDownloader.cs | 62 +++++++++++++++++++++++++++- DepotDownloader/Program.cs | 4 +- 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/DepotDownloader/ContentDownloader.cs b/DepotDownloader/ContentDownloader.cs index 03a2c1cb..4ac16eb8 100644 --- a/DepotDownloader/ContentDownloader.cs +++ b/DepotDownloader/ContentDownloader.cs @@ -51,7 +51,60 @@ namespace DepotDownloader return true; } - public static void Download( int depotId, int depotVersion, int cellId, string username, string password, bool onlyManifest, string installDir, string[] fileList ) + static string[] GetExcludeList( ContentServerClient.StorageSession session, Steam2Manifest manifest ) + { + string[] excludeList = null; + + for ( int x = 0 ; x < manifest.Nodes.Count ; ++x ) + { + var dirEntry = manifest.Nodes[ x ]; + if ( dirEntry.Name == "exclude.lst" && + dirEntry.FullName.StartsWith( "reslists" + Path.DirectorySeparatorChar ) && + ( dirEntry.Attributes & Steam2Manifest.Node.Attribs.EncryptedFile ) == 0 ) + { + string excludeFile = Encoding.UTF8.GetString( session.DownloadFile( dirEntry ) ); + excludeList = excludeFile.Split( new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries ); + break; + } + } + + return excludeList; + } + + static bool IsFileExcluded( string file, string[] excludeList ) + { + if ( excludeList == null || file.Length < 1 ) + return false; + + foreach ( string e in excludeList ) + { + int wildPos = e.IndexOf( "*" ); + + if ( wildPos == -1 ) + { + if ( file.StartsWith( e ) ) + return true; + continue; + } + + if ( wildPos == 0 ) + { + if ( e.Length == 1 || file.EndsWith( e.Substring( 1 ) ) ) + return true; + continue; + } + + string start = e.Substring( 0, wildPos ); + string end = e.Substring( wildPos + 1, e.Length - wildPos - 1 ); + + if ( file.StartsWith( start ) && file.EndsWith( end ) ) + return true; + } + + return false; + } + + public static void Download( int depotId, int depotVersion, int cellId, string username, string password, bool onlyManifest, bool gameServer, string installDir, string[] fileList ) { if ( !CreateDirectories( depotId, depotVersion, ref installDir ) ) { @@ -134,6 +187,10 @@ namespace DepotDownloader } byte[] cryptKey = CDRManager.GetDepotEncryptionKey( depotId, depotVersion ); + string[] excludeList = null; + + if ( gameServer ) + excludeList = GetExcludeList( session, manifest ); for ( int x = 0 ; x < manifest.Nodes.Count ; ++x ) { @@ -150,6 +207,9 @@ namespace DepotDownloader continue; } + if ( gameServer && IsFileExcluded( dirEntry.FullName, excludeList ) ) + continue; + if ( fileList != null ) { bool bMatched = false; diff --git a/DepotDownloader/Program.cs b/DepotDownloader/Program.cs index 1ccd48cb..76bab20a 100644 --- a/DepotDownloader/Program.cs +++ b/DepotDownloader/Program.cs @@ -106,7 +106,7 @@ namespace DepotDownloader if ( !bGameserver ) { - ContentDownloader.Download( depotId, depotVersion, cellId, username, password, !bDebot, installDir, files ); + ContentDownloader.Download( depotId, depotVersion, cellId, username, password, !bDebot, bGameserver, installDir, files ); } else { @@ -124,7 +124,7 @@ namespace DepotDownloader string depotName = CDRManager.GetDepotName( currentDepotId ); Console.WriteLine( "Downloading \"{0}\" version {1} ...", depotName, depotVersion ); - ContentDownloader.Download( currentDepotId, depotVersion, cellId, username, password, false, installDir, files ); + ContentDownloader.Download( currentDepotId, depotVersion, cellId, username, password, false, bGameserver, installDir, files ); } } }