diff --git a/OpenRA.Game/Manifest.cs b/OpenRA.Game/Manifest.cs index 57168f3aa1..8591017de5 100644 --- a/OpenRA.Game/Manifest.cs +++ b/OpenRA.Game/Manifest.cs @@ -61,13 +61,16 @@ namespace OpenRA readonly TypeDictionary modules = new TypeDictionary(); readonly Dictionary yaml; - public Manifest(string mod) + public Manifest(string modId, string modPath = null) { - var path = Platform.ResolvePath(".", "mods", mod, "mod.yaml"); + if (modPath == null) + modPath = ModMetadata.CandidateModPaths[modId]; + + var path = Path.Combine(modPath, "mod.yaml"); yaml = new MiniYaml(null, MiniYaml.FromFile(path)).ToDictionary(); Mod = FieldLoader.Load(yaml["Metadata"]); - Mod.Id = mod; + Mod.Id = modId; // TODO: Use fieldloader Folders = YamlList(yaml, "Folders", true); @@ -202,21 +205,16 @@ namespace OpenRA static Dictionary LoadMods() { - // Get mods that are in the game folder. - var basePath = Platform.ResolvePath(".", "mods"); - var mods = Directory.GetDirectories(basePath) - .Select(x => x.Substring(basePath.Length + 1)); - var ret = new Dictionary(); - foreach (var mod in mods) + foreach (var mod in ModMetadata.CandidateModPaths) { - if (!File.Exists(Platform.ResolvePath(".", "mods", mod, "mod.yaml"))) + if (!File.Exists(Path.Combine(mod.Value, "mod.yaml"))) continue; try { - var manifest = new Manifest(mod); - ret.Add(mod, manifest); + var manifest = new Manifest(mod.Key, mod.Value); + ret.Add(mod.Key, manifest); } catch (Exception ex) { diff --git a/OpenRA.Game/ModMetadata.cs b/OpenRA.Game/ModMetadata.cs index f99f7bb5e8..09c30e3942 100644 --- a/OpenRA.Game/ModMetadata.cs +++ b/OpenRA.Game/ModMetadata.cs @@ -17,6 +17,7 @@ namespace OpenRA { public class ModMetadata { + public static readonly Dictionary CandidateModPaths = GetCandidateMods(); public static readonly Dictionary AllMods = ValidateMods(); public string Id; @@ -29,16 +30,12 @@ namespace OpenRA static Dictionary ValidateMods() { - var basePath = Platform.ResolvePath(".", "mods"); - var mods = Directory.GetDirectories(basePath) - .Select(x => x.Substring(basePath.Length + 1)); - var ret = new Dictionary(); - foreach (var m in mods) + foreach (var pair in CandidateModPaths) { try { - var yamlPath = Platform.ResolvePath(".", "mods", m, "mod.yaml"); + var yamlPath = Path.Combine(pair.Value, "mod.yaml"); if (!File.Exists(yamlPath)) continue; @@ -47,22 +44,40 @@ namespace OpenRA if (!nd.ContainsKey("Metadata")) continue; - var mod = FieldLoader.Load(nd["Metadata"]); - mod.Id = m; + var metadata = FieldLoader.Load(nd["Metadata"]); + metadata.Id = pair.Key; if (nd.ContainsKey("ContentInstaller")) - mod.Content = FieldLoader.Load(nd["ContentInstaller"]); + metadata.Content = FieldLoader.Load(nd["ContentInstaller"]); - ret.Add(m, mod); + ret.Add(pair.Key, metadata); } catch (Exception ex) { - Console.WriteLine("An exception occurred when trying to load ModMetadata for `{0}`:".F(m)); + Console.WriteLine("An exception occurred when trying to load ModMetadata for `{0}`:".F(pair.Key)); Console.WriteLine(ex.Message); } } return ret; } + + static Dictionary GetCandidateMods() + { + // Get mods that are in the game folder. + var basePath = Platform.ResolvePath(Path.Combine(".", "mods")); + var mods = Directory.GetDirectories(basePath) + .ToDictionary(x => x.Substring(basePath.Length + 1)); + + // Get mods that are in the support folder. + var supportPath = Platform.ResolvePath(Path.Combine("^", "mods")); + if (!Directory.Exists(supportPath)) + return mods; + + foreach (var pair in Directory.GetDirectories(supportPath).ToDictionary(x => x.Substring(supportPath.Length + 1))) + mods.Add(pair.Key, pair.Value); + + return mods; + } } }