Normalize slashes in filepath; explicit regex support (#175)

Fixes #30 #18 #17
pull/190/head
Pavel Djundik 5 years ago committed by GitHub
parent 9d4b87ba60
commit 60b4451417
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -94,12 +94,13 @@ namespace DepotDownloader
if ( !Config.UsingFileList ) if ( !Config.UsingFileList )
return true; 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 ) foreach ( Regex rgx in Config.FilesToDownloadRegex )
{ {
Match m = rgx.Match( filename ); Match m = rgx.Match( filename );

@ -12,7 +12,7 @@ namespace DepotDownloader
public string InstallDirectory { get; set; } public string InstallDirectory { get; set; }
public bool UsingFileList { get; set; } public bool UsingFileList { get; set; }
public List<string> FilesToDownload { get; set; } public HashSet<string> FilesToDownload { get; set; }
public List<Regex> FilesToDownloadRegex { get; set; } public List<Regex> FilesToDownloadRegex { get; set; }
public string BetaPassword { get; set; } public string BetaPassword { get; set; }

@ -53,48 +53,28 @@ namespace DepotDownloader
ContentDownloader.Config.CellID = cellId; ContentDownloader.Config.CellID = cellId;
string fileList = GetParameter<string>( args, "-filelist" ); string fileList = GetParameter<string>( args, "-filelist" );
string[] files = null;
if ( fileList != null ) if ( fileList != null )
{ {
try try
{ {
string fileListData = File.ReadAllText(fileList); string fileListData = await File.ReadAllTextAsync( fileList );
files = fileListData.Split( new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries ); var files = fileListData.Split( new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries );
ContentDownloader.Config.UsingFileList = true; ContentDownloader.Config.UsingFileList = true;
ContentDownloader.Config.FilesToDownload = new List<string>(); ContentDownloader.Config.FilesToDownload = new HashSet<string>( StringComparer.OrdinalIgnoreCase );
ContentDownloader.Config.FilesToDownloadRegex = new List<Regex>(); ContentDownloader.Config.FilesToDownloadRegex = new List<Regex>();
var isWindows = RuntimeInformation.IsOSPlatform( OSPlatform.Windows );
foreach ( var fileEntry in files ) foreach ( var fileEntry in files )
{ {
try if ( fileEntry.StartsWith( "regex:" ) )
{ {
string fileEntryProcessed; Regex rgx = new Regex( fileEntry.Substring( 6 ), RegexOptions.Compiled | RegexOptions.IgnoreCase );
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 );
ContentDownloader.Config.FilesToDownloadRegex.Add( rgx ); 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 ContentDownloader.Config.FilesToDownload.Add( fileEntry.Replace( '\\', '/' ) );
// on Windows
if( isWindows )
{
ContentDownloader.Config.FilesToDownload.Add( fileEntry.Replace( "/", "\\" ) );
}
ContentDownloader.Config.FilesToDownload.Add( fileEntry );
continue;
} }
} }
@ -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( "\t-remember-password\t\t- if set, remember the password for subsequent logins of this user." );
Console.WriteLine(); Console.WriteLine();
Console.WriteLine( "\t-dir <installdir>\t\t- the directory in which to place downloaded files." ); Console.WriteLine( "\t-dir <installdir>\t\t- the directory in which to place downloaded files." );
Console.WriteLine( "\t-filelist <file.txt>\t- a list of files to download (from the manifest). Can optionally use regex to download only certain files." ); Console.WriteLine( "\t-filelist <file.txt>\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( "\t-validate\t\t\t\t- Include checksum verification of files already downloaded" );
Console.WriteLine(); Console.WriteLine();
Console.WriteLine( "\t-manifest-only\t\t\t- downloads a human readable manifest for any depots that would be downloaded." ); Console.WriteLine( "\t-manifest-only\t\t\t- downloads a human readable manifest for any depots that would be downloaded." );

@ -46,7 +46,7 @@ Parameter | Description
-password \<pass> | the password of the account to login to for restricted content. -password \<pass> | the password of the account to login to for restricted content.
-remember-password | if set, remember the password for subsequent logins of this user. -remember-password | if set, remember the password for subsequent logins of this user.
-dir \<installdir> | the directory in which to place downloaded files. -dir \<installdir> | the directory in which to place downloaded files.
-filelist \<file.txt> | a list of files to download (from the manifest). Can optionally use regex to download only certain files. -filelist \<file.txt> | 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 -validate | Include checksum verification of files already downloaded
-manifest-only | downloads a human readable manifest for any depots that would be 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. -cellid \<#> | the overridden CellID of the content server to download from.

Loading…
Cancel
Save