Add a package-oriented Platform.ResolvePath() method

This commit is contained in:
Pavel Penev
2015-12-16 23:11:51 +02:00
parent b27cf8ea94
commit 0e53312a1d
4 changed files with 24 additions and 5 deletions

View File

@@ -191,7 +191,7 @@ namespace OpenRA
public static void InitializeSettings(Arguments args) public static void InitializeSettings(Arguments args)
{ {
Settings = new Settings(Platform.ResolvePath("^", "settings.yaml"), args); Settings = new Settings(Platform.ResolvePath(Path.Combine("^", "settings.yaml")), args);
} }
internal static void Initialize(Arguments args) internal static void Initialize(Arguments args)

View File

@@ -95,11 +95,19 @@ namespace OpenRA
public static string GameDir { get { return AppDomain.CurrentDomain.BaseDirectory; } } public static string GameDir { get { return AppDomain.CurrentDomain.BaseDirectory; } }
/// <summary>Replace special character prefixes with full paths</summary> /// <summary>Replaces special character prefixes with full paths.</summary>
public static string ResolvePath(string path) public static string ResolvePath(string path)
{ {
path = path.TrimEnd(new char[] { ' ', '\t' }); path = path.TrimEnd(new char[] { ' ', '\t' });
// If the path contains ':', chances are it is a package path.
// If it isn't, someone passed an already resolved path, which is wrong.
if (path.IndexOf(":", StringComparison.Ordinal) > 1)
{
var split = path.Split(':');
return ResolvePath(split[0], split[1]);
}
// paths starting with ^ are relative to the support dir // paths starting with ^ are relative to the support dir
if (path.StartsWith("^")) if (path.StartsWith("^"))
path = SupportDir + path.Substring(1); path = SupportDir + path.Substring(1);
@@ -111,7 +119,17 @@ namespace OpenRA
return path; return path;
} }
/// <summary>Replace special character prefixes with full paths</summary> /// <summary>Replaces package names with full paths. Avoid using this for non-package paths.</summary>
public static string ResolvePath(string package, string target)
{
// Resolve mod package paths.
if (ModMetadata.AllMods.ContainsKey(package))
package = ModMetadata.CandidateModPaths[package];
return ResolvePath(Path.Combine(package, target));
}
/// <summary>Replace special character prefixes with full paths.</summary>
public static string ResolvePath(params string[] path) public static string ResolvePath(params string[] path)
{ {
return ResolvePath(path.Aggregate(Path.Combine)); return ResolvePath(path.Aggregate(Path.Combine));

View File

@@ -11,6 +11,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using OpenRA.Graphics; using OpenRA.Graphics;
@@ -49,7 +50,7 @@ namespace OpenRA
var resolution = GetResolution(graphicSettings); var resolution = GetResolution(graphicSettings);
var rendererName = serverSettings.Dedicated ? "Null" : graphicSettings.Renderer; var rendererName = serverSettings.Dedicated ? "Null" : graphicSettings.Renderer;
var rendererPath = Platform.ResolvePath(".", "OpenRA.Platforms." + rendererName + ".dll"); var rendererPath = Platform.ResolvePath(Path.Combine(".", "OpenRA.Platforms." + rendererName + ".dll"));
Device = CreateDevice(Assembly.LoadFile(rendererPath), resolution.Width, resolution.Height, graphicSettings.Mode); Device = CreateDevice(Assembly.LoadFile(rendererPath), resolution.Width, resolution.Height, graphicSettings.Mode);

View File

@@ -33,7 +33,7 @@ namespace OpenRA
public Sound(string engineName) public Sound(string engineName)
{ {
var enginePath = Platform.ResolvePath(".", "OpenRA.Platforms." + engineName + ".dll"); var enginePath = Platform.ResolvePath(Path.Combine(".", "OpenRA.Platforms." + engineName + ".dll"));
soundEngine = CreateDevice(Assembly.LoadFile(enginePath)); soundEngine = CreateDevice(Assembly.LoadFile(enginePath));
} }