diff --git a/DepotDownloader/ContentDownloader.cs b/DepotDownloader/ContentDownloader.cs index 23d167df..209fa9bb 100644 --- a/DepotDownloader/ContentDownloader.cs +++ b/DepotDownloader/ContentDownloader.cs @@ -94,12 +94,13 @@ namespace DepotDownloader if ( !Config.UsingFileList ) return true; - foreach ( string fileListEntry in Config.FilesToDownload ) + filename = filename.Replace( '\\', '/' ); + + if ( Config.FilesToDownload.Contains( filename ) ) { - if ( fileListEntry.Equals( filename, StringComparison.OrdinalIgnoreCase ) ) - return true; + return true; } - + foreach ( Regex rgx in Config.FilesToDownloadRegex ) { Match m = rgx.Match( filename ); diff --git a/DepotDownloader/DownloadConfig.cs b/DepotDownloader/DownloadConfig.cs index 2d27bf26..14d1638c 100644 --- a/DepotDownloader/DownloadConfig.cs +++ b/DepotDownloader/DownloadConfig.cs @@ -12,7 +12,7 @@ namespace DepotDownloader public string InstallDirectory { get; set; } public bool UsingFileList { get; set; } - public List FilesToDownload { get; set; } + public HashSet FilesToDownload { get; set; } public List FilesToDownloadRegex { get; set; } public string BetaPassword { get; set; } diff --git a/DepotDownloader/Program.cs b/DepotDownloader/Program.cs index c522c7e4..cf7b0f33 100644 --- a/DepotDownloader/Program.cs +++ b/DepotDownloader/Program.cs @@ -53,48 +53,28 @@ namespace DepotDownloader ContentDownloader.Config.CellID = cellId; string fileList = GetParameter( args, "-filelist" ); - string[] files = null; if ( fileList != null ) { try { - string fileListData = File.ReadAllText(fileList); - files = fileListData.Split( new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries ); + string fileListData = await File.ReadAllTextAsync( fileList ); + var files = fileListData.Split( new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries ); ContentDownloader.Config.UsingFileList = true; - ContentDownloader.Config.FilesToDownload = new List(); + ContentDownloader.Config.FilesToDownload = new HashSet( StringComparer.OrdinalIgnoreCase ); ContentDownloader.Config.FilesToDownloadRegex = new List(); - - var isWindows = RuntimeInformation.IsOSPlatform( OSPlatform.Windows ); + foreach ( var fileEntry in files ) { - try + if ( fileEntry.StartsWith( "regex:" ) ) { - string fileEntryProcessed; - if ( isWindows ) - { - // On Windows, ensure that forward slashes can match either forward or backslashes in depot paths - fileEntryProcessed = fileEntry.Replace( "/", "[\\\\|/]" ); - } - else - { - // On other systems, treat / normally - fileEntryProcessed = fileEntry; - } - Regex rgx = new Regex( fileEntryProcessed, RegexOptions.Compiled | RegexOptions.IgnoreCase ); + Regex rgx = new Regex( fileEntry.Substring( 6 ), RegexOptions.Compiled | RegexOptions.IgnoreCase ); ContentDownloader.Config.FilesToDownloadRegex.Add( rgx ); } - catch + else { - // For anything that can't be processed as a Regex, allow both forward and backward slashes to match - // on Windows - if( isWindows ) - { - ContentDownloader.Config.FilesToDownload.Add( fileEntry.Replace( "/", "\\" ) ); - } - ContentDownloader.Config.FilesToDownload.Add( fileEntry ); - continue; + ContentDownloader.Config.FilesToDownload.Add( fileEntry.Replace( '\\', '/' ) ); } } @@ -403,7 +383,7 @@ namespace DepotDownloader Console.WriteLine( "\t-remember-password\t\t- if set, remember the password for subsequent logins of this user." ); Console.WriteLine(); Console.WriteLine( "\t-dir \t\t- the directory in which to place downloaded files." ); - Console.WriteLine( "\t-filelist \t- a list of files to download (from the manifest). Can optionally use regex to download only certain files." ); + Console.WriteLine( "\t-filelist \t- a list of files to download (from the manifest). Prefix file path with 'regex:' if you want to match with regex." ); Console.WriteLine( "\t-validate\t\t\t\t- Include checksum verification of files already downloaded" ); Console.WriteLine(); Console.WriteLine( "\t-manifest-only\t\t\t- downloads a human readable manifest for any depots that would be downloaded." ); diff --git a/README.md b/README.md index e71b5519..f08783fb 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Parameter | Description -password \ | the password of the account to login to for restricted content. -remember-password | if set, remember the password for subsequent logins of this user. -dir \ | the directory in which to place downloaded files. --filelist \ | a list of files to download (from the manifest). Can optionally use regex to download only certain files. +-filelist \ | a list of files to download (from the manifest). Prefix file path with `regex:` if you want to match with regex. -validate | Include checksum verification of files already downloaded -manifest-only | downloads a human readable manifest for any depots that would be downloaded. -cellid \<#> | the overridden CellID of the content server to download from.