Mercurial > repos > IBBoard
diff Constants.cs @ 117:e9f3a4ddf772
* Add Mono for Android version of .csproj file
* Update Constants to allow initialisation where we can't pull defaults (e.g. Mono for Android)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 14 Jul 2012 15:24:17 +0100 |
parents | 27b6aa1e98e8 |
children |
line wrap: on
line diff
--- a/Constants.cs Tue Jun 26 20:09:01 2012 +0100 +++ b/Constants.cs Sat Jul 14 15:24:17 2012 +0100 @@ -14,28 +14,55 @@ { public static readonly char DirectoryChar = Path.DirectorySeparatorChar; public static readonly string DirectoryString = Path.DirectorySeparatorChar.ToString(); - private static string executablePath = AppDomain.CurrentDomain.BaseDirectory.TrimEnd(DirectoryChar); + private static string executablePath; + private static string userDataPath; + private static bool initialised; static Constants() { - string appDataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); - string exe = Environment.GetCommandLineArgs()[0]; - exe = Path.GetFileNameWithoutExtension(exe); - userDataPath = Path.Combine(Path.Combine(appDataDir, "IBBoard"), exe); + if (AppDomain.CurrentDomain.BaseDirectory != null && Environment.GetCommandLineArgs() != null) + { + string exe = Environment.GetCommandLineArgs()[0]; + Initialise(Path.GetFileNameWithoutExtension(exe), AppDomain.CurrentDomain.BaseDirectory); + } + } + + private static void Initialise(string appName, string baseDir) + { + string appDataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); + userDataPath = Path.Combine(Path.Combine(appDataDir, "IBBoard"), appName); + executablePath = baseDir; + initialised = true; + } + + public static void Initialise(string appName) + { + if (initialised) + { + throw new InvalidOperationException("IBBoard.Constants have already been initialised"); + } + + Initialise(appName, ""); } /// <summary> /// Gets the path of the directory that contains the executable. /// </summary> /// <value> - /// The path that the executable is in. + /// The path that the executable is in, or an empty string if it cannot be determined /// </value> public static string ExecutablePath { - get { return executablePath; } + get + { + if (!initialised) + { + throw new InvalidOperationException("IBBoard.Constants have not been initialised"); + } + + return executablePath; + } } - - private static string userDataPath; /// <summary> /// Gets the standard user data path for this app. This follows a convention of using the app name for the folder @@ -46,7 +73,15 @@ /// </value> public static string UserDataPath { - get { return userDataPath; } + get + { + if (!initialised) + { + throw new InvalidOperationException("IBBoard.Constants have not been initialised"); + } + + return userDataPath; + } } } }