Mercurial > repos > IBBoard
annotate Constants.cs @ 120:780169621672
* Remove rogue print statement
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 06 Nov 2012 20:51:49 +0000 |
parents | e9f3a4ddf772 |
children |
rev | line source |
---|---|
16 | 1 // This file (Constants.cs) is a part of the IBBoard library and is copyright 2009 IBBoard. |
2 // | |
3 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. | |
4 | |
37 | 5 using System; |
6 using System.IO; | |
7 | |
8 namespace IBBoard | |
9 { | |
10 /// <summary> | |
11 /// Summary description for Constants. | |
12 /// </summary> | |
13 public class Constants | |
14 { | |
15 public static readonly char DirectoryChar = Path.DirectorySeparatorChar; | |
0
961030992bd2
Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
16 public static readonly string DirectoryString = Path.DirectorySeparatorChar.ToString(); |
117
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
17 private static string executablePath; |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
18 private static string userDataPath; |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
19 private static bool initialised; |
0
961030992bd2
Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
20 |
961030992bd2
Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
21 static Constants() |
37 | 22 { |
117
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
23 if (AppDomain.CurrentDomain.BaseDirectory != null && Environment.GetCommandLineArgs() != null) |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
24 { |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
25 string exe = Environment.GetCommandLineArgs()[0]; |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
26 Initialise(Path.GetFileNameWithoutExtension(exe), AppDomain.CurrentDomain.BaseDirectory); |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
27 } |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
28 } |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
29 |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
30 private static void Initialise(string appName, string baseDir) |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
31 { |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
32 string appDataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
33 userDataPath = Path.Combine(Path.Combine(appDataDir, "IBBoard"), appName); |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
34 executablePath = baseDir; |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
35 initialised = true; |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
36 } |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
37 |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
38 public static void Initialise(string appName) |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
39 { |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
40 if (initialised) |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
41 { |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
42 throw new InvalidOperationException("IBBoard.Constants have already been initialised"); |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
43 } |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
44 |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
45 Initialise(appName, ""); |
0
961030992bd2
Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
46 } |
961030992bd2
Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
47 |
108
27b6aa1e98e8
Re #12: Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
107
diff
changeset
|
48 /// <summary> |
27b6aa1e98e8
Re #12: Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
107
diff
changeset
|
49 /// Gets the path of the directory that contains the executable. |
27b6aa1e98e8
Re #12: Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
107
diff
changeset
|
50 /// </summary> |
27b6aa1e98e8
Re #12: Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
107
diff
changeset
|
51 /// <value> |
117
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
52 /// The path that the executable is in, or an empty string if it cannot be determined |
108
27b6aa1e98e8
Re #12: Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
107
diff
changeset
|
53 /// </value> |
0
961030992bd2
Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
54 public static string ExecutablePath |
961030992bd2
Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
55 { |
117
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
56 get |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
57 { |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
58 if (!initialised) |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
59 { |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
60 throw new InvalidOperationException("IBBoard.Constants have not been initialised"); |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
61 } |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
62 |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
63 return executablePath; |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
64 } |
0
961030992bd2
Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
65 } |
108
27b6aa1e98e8
Re #12: Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
107
diff
changeset
|
66 |
27b6aa1e98e8
Re #12: Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
107
diff
changeset
|
67 /// <summary> |
27b6aa1e98e8
Re #12: Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
107
diff
changeset
|
68 /// Gets the standard user data path for this app. This follows a convention of using the app name for the folder |
27b6aa1e98e8
Re #12: Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
107
diff
changeset
|
69 /// and putting it in a folder called "IBBoard" to avoid collisions. |
27b6aa1e98e8
Re #12: Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
107
diff
changeset
|
70 /// </summary> |
27b6aa1e98e8
Re #12: Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
107
diff
changeset
|
71 /// <value> |
27b6aa1e98e8
Re #12: Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
107
diff
changeset
|
72 /// The user data path, following the IBBoard convention. |
27b6aa1e98e8
Re #12: Document classes and methods
IBBoard <dev@ibboard.co.uk>
parents:
107
diff
changeset
|
73 /// </value> |
0
961030992bd2
Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
74 public static string UserDataPath |
961030992bd2
Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
75 { |
117
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
76 get |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
77 { |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
78 if (!initialised) |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
79 { |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
80 throw new InvalidOperationException("IBBoard.Constants have not been initialised"); |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
81 } |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
82 |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
83 return userDataPath; |
e9f3a4ddf772
* Add Mono for Android version of .csproj file
IBBoard <dev@ibboard.co.uk>
parents:
108
diff
changeset
|
84 } |
0
961030992bd2
Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
85 } |
37 | 86 } |
87 } |