From e5a3b9fffe8a4d6531270c429862fc811ad94196 Mon Sep 17 00:00:00 2001 From: Herp Derpinstine Date: Sat, 7 Dec 2024 23:15:20 -0600 Subject: [PATCH] Fixed an issue with Extended Folder Scanning not running without strict definition of Folder Names --- MelonLoader/Melons/MelonFolderHandler.cs | 38 ++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/MelonLoader/Melons/MelonFolderHandler.cs b/MelonLoader/Melons/MelonFolderHandler.cs index ddc1f1d6..0d4fd644 100644 --- a/MelonLoader/Melons/MelonFolderHandler.cs +++ b/MelonLoader/Melons/MelonFolderHandler.cs @@ -159,6 +159,36 @@ private static void FindMelonFolders( } } + private static void ScanExtraFolders(eScanType scanType, + string path, + ref List userLibDirectories, + ref List pluginDirectories, + ref List modDirectories) + { + string[] directories = Directory.GetDirectories(path, "*", SearchOption.TopDirectoryOnly); + if ((directories == null) + || (directories.Length <= 0)) + return; + + foreach (var dir in directories) + { + if (userLibDirectories.Contains(dir) + || pluginDirectories.Contains(dir) + || modDirectories.Contains(dir)) + continue; + + ScanExtraFolders(scanType, dir, ref userLibDirectories, ref pluginDirectories, ref modDirectories); + + // Add to Directories List + if (scanType == eScanType.UserLibs) + userLibDirectories.Add(dir); + else if (scanType == eScanType.Plugins) + pluginDirectories.Add(dir); + else + modDirectories.Add(dir); + } + } + private static void ScanFolder(eScanType scanType, string path, ref List userLibDirectories, @@ -193,7 +223,10 @@ private static void ScanFolder(eScanType scanType, // Is UserLibs Scan? if (scanType == eScanType.UserLibs) + { + ScanExtraFolders(scanType, dir, ref userLibDirectories, ref pluginDirectories, ref modDirectories); userLibDirectories.Add(dir); // Add to Directories List + } else { // Check for Deeper Melon Folder @@ -201,12 +234,11 @@ private static void ScanFolder(eScanType scanType, if (Directory.Exists(melonPath)) { pluginDirectories.Add(melonPath); - ScanFolder(scanType, melonPath, ref userLibDirectories, ref pluginDirectories, ref modDirectories); + ScanFolder(eScanType.Plugins, melonPath, ref userLibDirectories, ref pluginDirectories, ref modDirectories); } if (scanType == eScanType.Mods) { - // Check for Deeper Melon Folder melonPath = Path.Combine(dir, "Mods"); if (Directory.Exists(melonPath)) { @@ -215,6 +247,8 @@ private static void ScanFolder(eScanType scanType, } } + ScanExtraFolders(scanType, dir, ref userLibDirectories, ref pluginDirectories, ref modDirectories); + // Add to Directories List if (scanType == eScanType.Mods) modDirectories.Add(dir);