From b9eb4642463d924487b71ef3953e7b43c0f16e5f Mon Sep 17 00:00:00 2001 From: PenguinKeeper7 <64717060+PenguinKeeper7@users.noreply.github.com> Date: Sat, 31 Dec 2022 19:03:18 +0000 Subject: [PATCH 1/2] Add implementation for all path types Avoid errors with Directory.GetFiles when specifying an absolute path. Old error: ``` Unhandled exception. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Second path fragment must not be a drive or UNC name. (Parameter 'expression') ``` --- CatalogPlugin.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/CatalogPlugin.cs b/CatalogPlugin.cs index c5895ff..e58ecb3 100644 --- a/CatalogPlugin.cs +++ b/CatalogPlugin.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -14,10 +14,23 @@ public class CatalogPlugin : PluginBase public static void Process(CatalogOptions options) { - //Validate and display arguments var currentDirectory = Directory.GetCurrentDirectory(); - var fileEntries = Directory.GetFiles(currentDirectory, options.InputPath, SearchOption.AllDirectories); + string[] fileEntries = { }; + + //Absolute path + if (Path.IsPathFullyQualified(options.InputPath)) + { + string path = options.InputPath.Replace("/", "\\"); + int pos = path.LastIndexOf('\\'); + if (File.Exists(options.InputPath) || Directory.Exists(options.InputPath)) + fileEntries = Directory.GetFiles(path[..pos], path[(pos + 1)..], SearchOption.AllDirectories); + } + //Relative path + else + fileEntries = Directory.GetFiles(currentDirectory, options.InputPath, SearchOption.AllDirectories); + + //Validate and display arguments if (fileEntries.Length == 0) { WriteError($"No .txt files found for {options.InputPath}"); From d367f84ff32c281b9c267103a0d1037ea3046604 Mon Sep 17 00:00:00 2001 From: PenguinKeeper7 <64717060+PenguinKeeper7@users.noreply.github.com> Date: Sat, 31 Dec 2022 19:07:57 +0000 Subject: [PATCH 2/2] Update CatalogPlugin.cs Fold slashes to / instead of \ for Linux compatibility --- CatalogPlugin.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/CatalogPlugin.cs b/CatalogPlugin.cs index e58ecb3..9ba6594 100644 --- a/CatalogPlugin.cs +++ b/CatalogPlugin.cs @@ -20,8 +20,8 @@ public static void Process(CatalogOptions options) //Absolute path if (Path.IsPathFullyQualified(options.InputPath)) { - string path = options.InputPath.Replace("/", "\\"); - int pos = path.LastIndexOf('\\'); + string path = options.InputPath.Replace("\\", "/"); + int pos = path.LastIndexOf('/'); if (File.Exists(options.InputPath) || Directory.Exists(options.InputPath)) fileEntries = Directory.GetFiles(path[..pos], path[(pos + 1)..], SearchOption.AllDirectories); @@ -29,7 +29,7 @@ public static void Process(CatalogOptions options) //Relative path else fileEntries = Directory.GetFiles(currentDirectory, options.InputPath, SearchOption.AllDirectories); - + //Validate and display arguments if (fileEntries.Length == 0) { @@ -137,7 +137,7 @@ public static void Process(CatalogOptions options) } } - #pragma warning disable SYSLIB0021 +#pragma warning disable SYSLIB0021 //We keep using Sha1Managed for performance reasons using (var sha1 = new SHA1Managed()) { @@ -281,7 +281,7 @@ private static async Task DoXReference(CatalogOptions options) { //Create a new lock object for this hex key _locks.Add($"{hex1}{hex2}", new SemaphoreSlim(1, 1)); - } + } } //Loop through each file with this prefix in the output folder @@ -313,7 +313,7 @@ private static async Task DoXReference(CatalogOptions options) tasks.Remove(completedTask); } } - + //We now have 256 files full of associated words, a word can appear multiple times, but only in one file //Loop through each file, combine entries, then optimise the file bucketCount = 0; @@ -341,7 +341,7 @@ private static async Task DoXReference(CatalogOptions options) WriteProgress($"Optimising files", bucketCount, 256); tasks.Remove(completedTask); - } + } } } @@ -449,7 +449,7 @@ private static async Task WriteFiles(Dictionary> { var output = new Dictionary>(); - #pragma warning disable SYSLIB0021 +#pragma warning disable SYSLIB0021 //We keep using Sha1Managed for performance reasons using (var sha1 = new SHA1Managed()) { @@ -522,7 +522,7 @@ private static async Task WriteFiles(Dictionary> //When the task is ready, always release the semaphore. _locks[de.Key].Release(); } - } + } } //Sort by key, and optimise key/words