Support loading mods from arbitrary locations.

This commit is contained in:
Paul Chote
2016-08-05 19:41:26 +01:00
parent cff8e949d8
commit 3261516b51
5 changed files with 47 additions and 12 deletions

View File

@@ -244,6 +244,16 @@ namespace OpenRA
{
Console.WriteLine("Platform is {0}", Platform.CurrentPlatform);
// Special case handling of Game.Mod argument: if it matches a real filesystem path
// then we use this to override the mod search path, and replace it with the mod id
var modArgument = args.GetValue("Game.Mod", null);
string customModPath = null;
if (modArgument != null && (File.Exists(modArgument) || Directory.Exists(modArgument)))
{
customModPath = modArgument;
args.ReplaceValue("Game.Mod", Path.GetFileNameWithoutExtension(modArgument));
}
InitializeSettings(args);
Log.AddChannel("perf", "perf.log");
@@ -303,7 +313,7 @@ namespace OpenRA
GlobalChat = new GlobalChat();
Mods = new InstalledMods();
Mods = new InstalledMods(customModPath);
Console.WriteLine("Available mods:");
foreach (var mod in Mods)
Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Metadata.Title, mod.Value.Metadata.Version);

View File

@@ -23,9 +23,9 @@ namespace OpenRA
{
readonly Dictionary<string, Manifest> mods;
public InstalledMods()
public InstalledMods(string customModPath)
{
mods = GetInstalledMods();
mods = GetInstalledMods(customModPath);
}
static IEnumerable<Pair<string, string>> GetCandidateMods()
@@ -89,10 +89,14 @@ namespace OpenRA
}
}
static Dictionary<string, Manifest> GetInstalledMods()
static Dictionary<string, Manifest> GetInstalledMods(string customModPath)
{
var ret = new Dictionary<string, Manifest>();
foreach (var pair in GetCandidateMods())
var candidates = GetCandidateMods();
if (customModPath != null)
candidates = candidates.Append(Pair.New(Path.GetFileNameWithoutExtension(customModPath), customModPath));
foreach (var pair in candidates)
{
var mod = LoadMod(pair.First, pair.Second);

View File

@@ -35,5 +35,6 @@ namespace OpenRA
public bool Contains(string key) { return args.ContainsKey(key); }
public string GetValue(string key, string defaultValue) { return Contains(key) ? args[key] : defaultValue; }
public void ReplaceValue(string key, string value) { args[key] = value; }
}
}