From 0019969cf846c76936493fa34c9a0343a7fe7478 Mon Sep 17 00:00:00 2001 From: 0xffhh <56194755+0xffhh@users.noreply.github.com> Date: Wed, 18 Nov 2020 19:30:37 +0100 Subject: [PATCH] Fixed a bug which occured on systems where Switch.System.IO.UseLegacyPathHandling is turned on caused an InvalidCharacter exception to be thrown because NT paths contain invalid characters (?) in legacy mode. (#7) Co-authored-by: Henri --- src/SauronEye/Searcher.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/SauronEye/Searcher.cs b/src/SauronEye/Searcher.cs index ecf78f5..bcbbcdc 100644 --- a/src/SauronEye/Searcher.cs +++ b/src/SauronEye/Searcher.cs @@ -191,8 +191,15 @@ public ContentsSearcher(IEnumerable directories, List keywords, // Searches the contents of filtered files. Does not care about exceptions. public void Search() { foreach (String dir in Directories) { - try { - var fileInfo = new FileInfo(ConvertToNTPath(dir)); + try { + bool usingLegacyPathHandling = false; + AppContext.TryGetSwitch("Switch.System.IO.UseLegacyPathHandling", out usingLegacyPathHandling); + var dirToCheck = dir; + if (!usingLegacyPathHandling) + { + dirToCheck = ConvertToNTPath(dir); + } + var fileInfo = new FileInfo(dirToCheck); string fileContents; if (Convert.ToUInt64(fileInfo.Length) < 1024 * this.MAX_FILE_SIZE) {