summarylogtreecommitdiffstats
path: root/mods-in-user-dir.patch
blob: 04883912c136a9d9d50e5d6022f29382fbe5c828 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
diff --git a/Source/Mod/Core/ModLoader.cs b/Source/Mod/Core/ModLoader.cs
index 105ed63..bb0a2d4 100644
--- a/Source/Mod/Core/ModLoader.cs
+++ b/Source/Mod/Core/ModLoader.cs
@@ -9,15 +9,15 @@ public static class ModLoader
 {
 	public const string ModsFolder = "Mods";
 
-	private static string? modsFolderPath = null;
+	private static string[]? modsFolderPaths = null;
 
 	internal static List<string> FailedToLoadMods = [];
 
-	public static string ModFolderPath
+	public static string[] ModFolderPaths
 	{
 		get
 		{
-			if (modsFolderPath == null)
+			if (modsFolderPaths == null)
 			{
 				var baseFolder = AppContext.BaseDirectory;
 				var searchUpPath = "";
@@ -26,10 +26,15 @@ public static class ModLoader
 					searchUpPath = Path.Join(searchUpPath, "..");
 				if (!Directory.Exists(Path.Join(baseFolder, searchUpPath, ModsFolder)))
 					throw new Exception($"Unable to find {ModsFolder} Directory from '{baseFolder}'");
-				modsFolderPath = Path.Join(baseFolder, searchUpPath, ModsFolder);
+				var modsFolderPath = Path.Join(baseFolder, searchUpPath, ModsFolder);
+				var userModsFolderPath = Path.Join(App.UserPath, ModsFolder);
+				if (Directory.Exists(userModsFolderPath))
+					modsFolderPaths = [modsFolderPath, userModsFolderPath];
+				else
+					modsFolderPaths = [modsFolderPath];
 			}
 
-			return modsFolderPath;
+			return modsFolderPaths;
 		}
 	}
 
@@ -51,7 +56,7 @@ public static class ModLoader
 		List<(ModInfo, IModFilesystem)> modInfos = [];
 
 		// Find all mods in directories:
-		foreach (var modDir in Directory.EnumerateDirectories(ModFolderPath))
+		foreach (var modDir in ModFolderPaths.SelectMany(path => Directory.EnumerateDirectories(path, "*.zip")))
 		{
 			var modName = Path.GetFileNameWithoutExtension(modDir)!; // Todo: read from some metadata file
 			var fs = new FolderModFilesystem(modDir);
@@ -73,7 +78,7 @@ public static class ModLoader
 		}
 
 		// Find all mods in zips:
-		foreach (var modZip in Directory.EnumerateFiles(ModFolderPath, "*.zip"))
+		foreach (var modZip in ModFolderPaths.SelectMany(path => Directory.EnumerateFiles(path, "*.zip")))
 		{
 			var modName = Path.GetFileNameWithoutExtension(modZip)!; // Todo: read from some metadata file
 			var fs = new ZipModFilesystem(modZip);