diff --git a/OpenRA.Game/Platform.cs b/OpenRA.Game/Platform.cs index 61b3d3fa8a..60d6c4ba87 100644 --- a/OpenRA.Game/Platform.cs +++ b/OpenRA.Game/Platform.cs @@ -64,15 +64,19 @@ namespace OpenRA } } + /// + /// 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. + /// public static string SupportDir { get { return supportDir.Value; } } static Lazy 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; } + /// + /// 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. + /// + public static string SystemSupportDir { get { return systemSupportDir.Value; } } + static Lazy 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