diff --git a/src/GamePlatform.cs b/src/GamePlatform.cs index f2a40fc..e38a309 100644 --- a/src/GamePlatform.cs +++ b/src/GamePlatform.cs @@ -307,6 +307,10 @@ namespace Microsoft.Xna.Framework internal abstract Keys GetKeyFromScancode(Keys scancode); + internal abstract string GetStorageRoot(); + + internal abstract bool IsStoragePathConnected(string path); + #endregion #region Private Methods diff --git a/src/SDL2/SDL2_GamePlatform.cs b/src/SDL2/SDL2_GamePlatform.cs index e721cc2..34439c9 100644 --- a/src/SDL2/SDL2_GamePlatform.cs +++ b/src/SDL2/SDL2_GamePlatform.cs @@ -861,6 +861,68 @@ namespace Microsoft.Xna.Framework return SDL2_KeyboardUtil.KeyFromScancode(scancode); } + internal override string GetStorageRoot() + { + if (OSVersion.Equals("Windows")) + { + return Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), + "SavedGames" + ); + } + if (OSVersion.Equals("Mac OS X")) + { + string osConfigDir = Environment.GetEnvironmentVariable("HOME"); + if (String.IsNullOrEmpty(osConfigDir)) + { + return "."; // Oh well. + } + osConfigDir += "/Library/Application Support"; + return osConfigDir; + } + if (OSVersion.Equals("Linux")) + { + // Assuming a non-OSX Unix platform will follow the XDG. Which it should. + string osConfigDir = Environment.GetEnvironmentVariable("XDG_DATA_HOME"); + if (String.IsNullOrEmpty(osConfigDir)) + { + osConfigDir = Environment.GetEnvironmentVariable("HOME"); + if (String.IsNullOrEmpty(osConfigDir)) + { + return "."; // Oh well. + } + osConfigDir += "/.local/share"; + } + return osConfigDir; + } + throw new Exception("StorageDevice: Platform.OSVersion not handled!"); + } + + internal override bool IsStoragePathConnected(string path) + { + if ( OSVersion.Equals("Linux") || + OSVersion.Equals("Mac OS X") ) + { + /* Linux and Mac use locally connected storage in the user's + * home location, which should always be "connected". + */ + return true; + } + if (OSVersion.Equals("Windows")) + { + try + { + return new DriveInfo(path).IsReady; + } + catch + { + // The storageRoot path is invalid / has been removed. + return false; + } + } + throw new Exception("StorageDevice: Platform.OSVersion not handled!"); + } + #endregion #region Protected GamePlatform Methods diff --git a/src/Storage/StorageDevice.cs b/src/Storage/StorageDevice.cs index 4113251..a1b59fb 100644 --- a/src/Storage/StorageDevice.cs +++ b/src/Storage/StorageDevice.cs @@ -55,27 +55,7 @@ namespace Microsoft.Xna.Framework.Storage { get { - if ( Game.Instance.Platform.OSVersion.Equals("Linux") || - Game.Instance.Platform.OSVersion.Equals("Mac OS X") ) - { - /* Linux and Mac use locally connected storage in the user's - * home location, which should always be "connected". - */ - return true; - } - else if (Game.Instance.Platform.OSVersion.Equals("Windows")) - { - try - { - return new DriveInfo(storageRoot).IsReady; - } - catch - { - // The storageRoot path is invalid / has been removed. - return false; - } - } - throw new Exception("StorageDevice: Platform.OSVersion not handled!"); + return Game.Instance.Platform.IsStoragePathConnected(storageRoot); } } @@ -113,7 +93,7 @@ namespace Microsoft.Xna.Framework.Storage #region Private Static Variables - private static readonly string storageRoot = GetStorageRoot(); + private static readonly string storageRoot = Game.Instance.Platform.GetStorageRoot(); #endregion @@ -371,46 +351,5 @@ namespace Microsoft.Xna.Framework.Storage } #endregion - - #region Private Static OS User Directory Path Method - - private static string GetStorageRoot() - { - if (Game.Instance.Platform.OSVersion.Equals("Windows")) - { - return Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), - "SavedGames" - ); - } - if (Game.Instance.Platform.OSVersion.Equals("Mac OS X")) - { - string osConfigDir = Environment.GetEnvironmentVariable("HOME"); - if (String.IsNullOrEmpty(osConfigDir)) - { - return "."; // Oh well. - } - osConfigDir += "/Library/Application Support"; - return osConfigDir; - } - if (Game.Instance.Platform.OSVersion.Equals("Linux")) - { - // Assuming a non-OSX Unix platform will follow the XDG. Which it should. - string osConfigDir = Environment.GetEnvironmentVariable("XDG_DATA_HOME"); - if (String.IsNullOrEmpty(osConfigDir)) - { - osConfigDir = Environment.GetEnvironmentVariable("HOME"); - if (String.IsNullOrEmpty(osConfigDir)) - { - return "."; // Oh well. - } - osConfigDir += "/.local/share"; - } - return osConfigDir; - } - throw new Exception("StorageDevice: Platform.OSVersion not handled!"); - } - - #endregion } }