From 266c4acc040355c52db614ddbfd29235124c5924 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 25 Mar 2020 14:56:43 -0400 Subject: [PATCH] Normalize forward slashes in filelists on Win --- DepotDownloader/Program.cs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/DepotDownloader/Program.cs b/DepotDownloader/Program.cs index 26d15e99..5b6e5f65 100644 --- a/DepotDownloader/Program.cs +++ b/DepotDownloader/Program.cs @@ -5,7 +5,7 @@ using System.Text.RegularExpressions; using SteamKit2; using System.ComponentModel; using System.Threading.Tasks; - +using System.Runtime.InteropServices; namespace DepotDownloader { class Program @@ -55,15 +55,33 @@ namespace DepotDownloader ContentDownloader.Config.FilesToDownload = new List(); ContentDownloader.Config.FilesToDownloadRegex = new List(); + var isWindows = RuntimeInformation.IsOSPlatform( OSPlatform.Windows ); foreach ( var fileEntry in files ) { try { - Regex rgx = new Regex( fileEntry, RegexOptions.Compiled | RegexOptions.IgnoreCase ); + 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 ); ContentDownloader.Config.FilesToDownloadRegex.Add( rgx ); } catch { + // 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; }