summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Program.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-02-11 02:04:01 -0500
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-02-11 02:04:01 -0500
commit824ca7174a2b6a46d8a4ea50cac41c78e56dc48f (patch)
tree897844c270aea82dc4ef63f64aefa40665c8a187 /src/StardewModdingAPI/Program.cs
parent46b7d7a4001e209d7201ed5cad38cad2f1ad2a7f (diff)
downloadSMAPI-824ca7174a2b6a46d8a4ea50cac41c78e56dc48f.tar.gz
SMAPI-824ca7174a2b6a46d8a4ea50cac41c78e56dc48f.tar.bz2
SMAPI-824ca7174a2b6a46d8a4ea50cac41c78e56dc48f.zip
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.
Diffstat (limited to 'src/StardewModdingAPI/Program.cs')
-rw-r--r--src/StardewModdingAPI/Program.cs19
1 files changed, 11 insertions, 8 deletions
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<Action> deprecationWarnings = new List<Action>(); // 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);