Add Platform.SystemSupportDir for shared user data.

This commit is contained in:
Paul Chote
2017-06-22 19:50:50 +01:00
committed by reaperrr
parent 372d940936
commit e69f129fed

View File

@@ -64,15 +64,19 @@ namespace OpenRA
}
}
/// <summary>
/// Directory containing user-specific support files (settings, maps, replays, game data, etc).
/// The directory will automatically be created if it does not exist when this is queried.
/// </summary>
public static string SupportDir { get { return supportDir.Value; } }
static Lazy<string> supportDir = Exts.Lazy(GetSupportDir);
static string GetSupportDir()
{
// Use a local directory in the game root if it exists
var supportDir = Path.Combine(GameDir, "Support");
if (Directory.Exists(supportDir))
return supportDir + Path.DirectorySeparatorChar;
// Use a local directory in the game root if it exists (shared with the system support dir)
var localSupportDir = Path.Combine(GameDir, "Support");
if (Directory.Exists(localSupportDir))
return localSupportDir + Path.DirectorySeparatorChar;
var dir = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
@@ -95,6 +99,33 @@ namespace OpenRA
return dir + Path.DirectorySeparatorChar;
}
/// <summary>
/// Directory containing system-wide support files (mod metadata).
/// This directory is not guaranteed to exist or be writable.
/// Consumers are expected to check the validity of the returned value, and
/// fall back to the user support directory if necessary.
/// </summary>
public static string SystemSupportDir { get { return systemSupportDir.Value; } }
static Lazy<string> systemSupportDir = Exts.Lazy(GetSystemSupportDir);
static string GetSystemSupportDir()
{
// Use a local directory in the game root if it exists (shared with the system support dir)
var localSupportDir = Path.Combine(GameDir, "Support");
if (Directory.Exists(localSupportDir))
return localSupportDir + Path.DirectorySeparatorChar;
switch (CurrentPlatform)
{
case PlatformType.Windows:
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "OpenRA") + Path.DirectorySeparatorChar;
case PlatformType.OSX:
return "/Library/Application Support/OpenRA/";
default:
return "/var/games/openra/";
}
}
public static string GameDir
{
get