From 824ca7174a2b6a46d8a4ea50cac41c78e56dc48f Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 11 Feb 2017 02:04:01 -0500 Subject: delve into mod folders that only contain another folder (#208) This fixes a common issue when users unpack mods into a nested folder (e.g. "SomeMod-1.0.0\SomeMod\manifest.json"), which previously wouldn't be recognised as a mod. SMAPI will not do this if the folder contains files or more than one folder, to prevent backup folders and the like from being loaded. --- src/StardewModdingAPI/Program.cs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/StardewModdingAPI/Program.cs') diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index a6302540..91a39042 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -337,9 +337,12 @@ namespace StardewModdingAPI // load mod assemblies List deprecationWarnings = new List(); // queue up deprecation warnings to show after mod list - foreach (string directory in Directory.GetDirectories(Program.ModPath)) + foreach (string directoryPath in Directory.GetDirectories(Program.ModPath)) { - string directoryName = new DirectoryInfo(directory).Name; + // passthrough empty directories + DirectoryInfo directory = new DirectoryInfo(directoryPath); + while (!directory.GetFiles().Any() && directory.GetDirectories().Length == 1) + directory = directory.GetDirectories().First(); // check for cancellation if (Program.CancellationTokenSource.IsCancellationRequested) @@ -349,13 +352,13 @@ namespace StardewModdingAPI } // get helper - IModHelper helper = new ModHelper(directory, Program.ModRegistry); + IModHelper helper = new ModHelper(directory.FullName, Program.ModRegistry); // get manifest path - string manifestPath = Path.Combine(directory, "manifest.json"); + string manifestPath = Path.Combine(directory.FullName, "manifest.json"); if (!File.Exists(manifestPath)) { - Program.Monitor.Log($"Ignored folder \"{directoryName}\" which doesn't have a manifest.json.", LogLevel.Warn); + Program.Monitor.Log($"Ignored folder \"{directory.Name}\" which doesn't have a manifest.json.", LogLevel.Warn); continue; } string errorPrefix = $"Couldn't load mod for manifest '{manifestPath}'"; @@ -434,7 +437,7 @@ namespace StardewModdingAPI deprecationWarnings.Add(() => Program.DeprecationManager.Warn(manifest.Name, $"{nameof(Manifest)}.{nameof(Manifest.PerSaveConfigs)}", "1.0", DeprecationLevel.Info)); try { - string psDir = Path.Combine(directory, "psconfigs"); + string psDir = Path.Combine(directory.FullName, "psconfigs"); Directory.CreateDirectory(psDir); if (!Directory.Exists(psDir)) { @@ -450,7 +453,7 @@ namespace StardewModdingAPI } // validate mod path to simplify errors - string assemblyPath = Path.Combine(directory, manifest.EntryDll); + string assemblyPath = Path.Combine(directory.FullName, manifest.EntryDll); if (!File.Exists(assemblyPath)) { Program.Monitor.Log($"{errorPrefix}: the entry DLL '{manifest.EntryDll}' does not exist.", LogLevel.Error); @@ -501,7 +504,7 @@ namespace StardewModdingAPI mod.ModManifest = manifest; mod.Helper = helper; mod.Monitor = Program.GetSecondaryMonitor(manifest.Name); - mod.PathOnDisk = directory; + mod.PathOnDisk = directory.FullName; // track mod Program.ModRegistry.Add(mod); -- cgit