From 5cbe0f0fc9383d21886f7eb717cb859e63454154 Mon Sep 17 00:00:00 2001 From: HeroponRikiBestest Date: Mon, 10 Nov 2025 11:59:40 -0500 Subject: [PATCH 1/6] fix --- ProtectionScan/Features/MainFeature.cs | 34 +++++++++++++++++--------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/ProtectionScan/Features/MainFeature.cs b/ProtectionScan/Features/MainFeature.cs index 263f5bbc..84521a2d 100644 --- a/ProtectionScan/Features/MainFeature.cs +++ b/ProtectionScan/Features/MainFeature.cs @@ -263,6 +263,10 @@ private void WriteProtectionResultJson(string path, Dictionary(); var trimmedPath = path.TrimEnd(['\\', '/']); + + // Move nested dictionary into final dictionary with the base path as a key. + //var finalDictionary = new Dictionary>(); + //finalDictionary.Add(trimmedPath, nestedDictionary); // Sort the keys for consistent output string[] keys = [.. protections.Keys]; @@ -283,7 +287,7 @@ private void WriteProtectionResultJson(string path, Dictionary>() - { - {trimmedPath, nestedDictionary} - }; - + // Create the output data - serializedData = System.Text.Json.JsonSerializer.Serialize(finalDictionary, jsonSerializerOptions); + serializedData = System.Text.Json.JsonSerializer.Serialize(nestedDictionary, jsonSerializerOptions); } else { @@ -334,15 +332,30 @@ private void WriteProtectionResultJson(string path, DictionaryThe scanned protection(s) for a given file private static void InsertNode(Dictionary nestedDictionary, string path, + string fullPath, string[] protections, List<(Dictionary, string, string[])> modifyNodeList) { - var current = nestedDictionary; + var pathParts = path.Split(Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries); + if (pathParts.Length <= 0) + { + modifyNodeList.Add((nestedDictionary, fullPath, protections)); + return; + } + + var current = nestedDictionary; + if (!current.ContainsKey(fullPath)) + current[fullPath] = new Dictionary(); + + current = (Dictionary)current[fullPath]; + + // Traverses the nested dictionary until the "leaf" dictionary is reached. for (int i = 0; i < pathParts.Length - 1; i++) { + var part = pathParts[i]; // Inserts new subdictionaries if one doesn't already exist @@ -366,7 +379,6 @@ private static void InsertNode(Dictionary nestedDictionary, current = (Dictionary)current[part]; } - // If the "leaf" dictionary has been reached, add the file and its protections. current.Add(pathParts[^1], protections); } #endif From d835df93ef03e6ade0a1865493bcfb9aac7a2a7a Mon Sep 17 00:00:00 2001 From: HeroponRikiBestest Date: Mon, 10 Nov 2025 12:01:11 -0500 Subject: [PATCH 2/6] add comment back --- ProtectionScan/Features/MainFeature.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/ProtectionScan/Features/MainFeature.cs b/ProtectionScan/Features/MainFeature.cs index 84521a2d..911acd62 100644 --- a/ProtectionScan/Features/MainFeature.cs +++ b/ProtectionScan/Features/MainFeature.cs @@ -379,6 +379,7 @@ private static void InsertNode(Dictionary nestedDictionary, current = (Dictionary)current[part]; } + // If the "leaf" dictionary has been reached, add the file and its protections. current.Add(pathParts[^1], protections); } #endif From 74c2f4544a29549d3b8e1c3450373d22dbcfdb52 Mon Sep 17 00:00:00 2001 From: HeroponRikiBestest Date: Mon, 10 Nov 2025 12:02:51 -0500 Subject: [PATCH 3/6] slight simplification --- ProtectionScan/Features/MainFeature.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ProtectionScan/Features/MainFeature.cs b/ProtectionScan/Features/MainFeature.cs index 911acd62..782884ba 100644 --- a/ProtectionScan/Features/MainFeature.cs +++ b/ProtectionScan/Features/MainFeature.cs @@ -345,11 +345,10 @@ private static void InsertNode(Dictionary nestedDictionary, return; } - var current = nestedDictionary; - if (!current.ContainsKey(fullPath)) - current[fullPath] = new Dictionary(); + if (!nestedDictionary.ContainsKey(fullPath)) + nestedDictionary[fullPath] = new Dictionary(); - current = (Dictionary)current[fullPath]; + var current = (Dictionary)nestedDictionary[fullPath]; // Traverses the nested dictionary until the "leaf" dictionary is reached. From b65ad528e934f8c3f44f1e5e5beb4fe95a58a72c Mon Sep 17 00:00:00 2001 From: HeroponRikiBestest Date: Mon, 10 Nov 2025 12:03:08 -0500 Subject: [PATCH 4/6] Remove newline --- ProtectionScan/Features/MainFeature.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/ProtectionScan/Features/MainFeature.cs b/ProtectionScan/Features/MainFeature.cs index 782884ba..9479b16b 100644 --- a/ProtectionScan/Features/MainFeature.cs +++ b/ProtectionScan/Features/MainFeature.cs @@ -350,7 +350,6 @@ private static void InsertNode(Dictionary nestedDictionary, var current = (Dictionary)nestedDictionary[fullPath]; - // Traverses the nested dictionary until the "leaf" dictionary is reached. for (int i = 0; i < pathParts.Length - 1; i++) { From 61e839b06250076bb2650891110a7c47d5432f62 Mon Sep 17 00:00:00 2001 From: HeroponRikiBestest Date: Mon, 10 Nov 2025 12:03:22 -0500 Subject: [PATCH 5/6] Remove newline --- ProtectionScan/Features/MainFeature.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/ProtectionScan/Features/MainFeature.cs b/ProtectionScan/Features/MainFeature.cs index 9479b16b..961fe95b 100644 --- a/ProtectionScan/Features/MainFeature.cs +++ b/ProtectionScan/Features/MainFeature.cs @@ -336,9 +336,7 @@ private static void InsertNode(Dictionary nestedDictionary, string[] protections, List<(Dictionary, string, string[])> modifyNodeList) { - var pathParts = path.Split(Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries); - if (pathParts.Length <= 0) { modifyNodeList.Add((nestedDictionary, fullPath, protections)); From 3746666ecf46aeb6101db03e3d80a380aa0d344a Mon Sep 17 00:00:00 2001 From: HeroponRikiBestest Date: Mon, 10 Nov 2025 12:28:37 -0500 Subject: [PATCH 6/6] Fix --- ProtectionScan/Features/MainFeature.cs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/ProtectionScan/Features/MainFeature.cs b/ProtectionScan/Features/MainFeature.cs index 961fe95b..61edd476 100644 --- a/ProtectionScan/Features/MainFeature.cs +++ b/ProtectionScan/Features/MainFeature.cs @@ -376,7 +376,28 @@ private static void InsertNode(Dictionary nestedDictionary, } // If the "leaf" dictionary has been reached, add the file and its protections. - current.Add(pathParts[^1], protections); + if (current.ContainsKey(pathParts[^1])) + { + var array1 = (string[])current[pathParts[^1]]; + var array2 = protections; + + string[] result = new string[array1.Length + array2.Length]; + for (int i = 0; i < array1.Length; i++) + { + result[i] = array1[i]; + } + + for (int i = 0; i < array2.Length; i++) + { + result[array1.Length + i] = array2[i]; + } + + current[pathParts[^1]] = result; + } + else + { + current.Add(pathParts[^1], protections); + } } #endif }