Add a package-oriented Platform.ResolvePath() method
This commit is contained in:
@@ -191,7 +191,7 @@ namespace OpenRA
|
||||
|
||||
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)
|
||||
|
||||
@@ -95,11 +95,19 @@ namespace OpenRA
|
||||
|
||||
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)
|
||||
{
|
||||
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
|
||||
if (path.StartsWith("^"))
|
||||
path = SupportDir + path.Substring(1);
|
||||
@@ -111,7 +119,17 @@ namespace OpenRA
|
||||
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)
|
||||
{
|
||||
return ResolvePath(path.Aggregate(Path.Combine));
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using OpenRA.Graphics;
|
||||
@@ -49,7 +50,7 @@ namespace OpenRA
|
||||
var resolution = GetResolution(graphicSettings);
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace OpenRA
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user