2002-08-20 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / corlib / System / Environment.cs
1 //------------------------------------------------------------------------------\r
2 // \r
3 // System.Environment.cs \r
4 //\r
5 // Copyright (C) 2001 Moonlight Enterprises, All Rights Reserved\r
6 // \r
7 // Author:         Jim Richardson, develop@wtfo-guru.com\r
8 //                 Dan Lewis (dihlewis@yahoo.co.uk)\r
9 // Created:        Saturday, August 11, 2001 \r
10 //\r
11 //------------------------------------------------------------------------------\r
12 \r
13 using System;\r
14 using System.IO;\r
15 //using System.Diagnostics;\r
16 using System.Collections;\r
17 using System.Security;\r
18 using System.Security.Permissions;\r
19 using System.Runtime.CompilerServices;\r
20 \r
21 namespace System\r
22 {\r
23         public sealed class Environment\r
24         {\r
25                 private Environment () {}\r
26 \r
27                 [MonoTODO]\r
28                 public enum SpecialFolder\r
29                 {       // TODO: Determine if these windoze style folder identifiers \r
30                         //       have unix/linux counterparts\r
31                         Programs = 0x02,\r
32                         Personal = 0x05,\r
33                         Favorites = 0x06,\r
34                         Startup = 0x07,\r
35                         Recent = 0x08,\r
36                         SendTo = 0x09,\r
37                         StartMenu = 0x0b,\r
38                         DesktopDirectory = 0x10,\r
39                         Templates = 0x15,\r
40                         ApplicationData = 0x1a,\r
41                         LocalApplicationData = 0x1c,\r
42                         InternetCache = 0x20,\r
43                         Cookies = 0x21,\r
44                         History = 0x22,\r
45                         CommonApplicationData   = 0x23,\r
46                         System = 0x25,\r
47                         ProgramFiles = 0x26,\r
48                         CommonProgramFiles = 0x2b,\r
49                 }\r
50 \r
51                 // TODO: Make sure the security attributes do what I expect\r
52                         \r
53                 /// <summary>\r
54                 /// Gets the command line for this process\r
55                 /// </summary>\r
56                 public static string CommandLine\r
57                 {       // TODO: Coordinate with implementor of EnvironmentPermissionAttribute\r
58                         // [EnvironmentPermissionAttribute(SecurityAction.Demand, Read = "COMMANDLINE")]\r
59                         get\r
60                         {\r
61                                 // FIXME: we may need to quote, but any sane person\r
62                                 // should use GetCommandLineArgs () instead.\r
63                                 return String.Join (" ", GetCommandLineArgs ());\r
64                         }\r
65                 }\r
66 \r
67                 /// <summary>\r
68                 /// Gets or sets the current directory. Actually this is supposed to get\r
69                 /// and/or set the process start directory acording to the documentation\r
70                 /// but actually test revealed at beta2 it is just Getting/Setting the CurrentDirectory\r
71                 /// </summary>\r
72                 public static string CurrentDirectory\r
73                 {\r
74                         // originally it was my thought that the external call would be made in\r
75                         // the directory class however that class has additional security requirements\r
76                         // so the Directory class will call this class for its get/set current directory\r
77                         \r
78                         // [EnvironmentPermissionAttribute(SecurityAction.Demand, Unrestricted = true)]\r
79                         get\r
80                         {\r
81                                 return MonoIO.GetCurrentDirectory ();\r
82                         }\r
83                         [MonoTODO("disabled because of compile error. Need mcs magic.")]\r
84                         //[SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]\r
85                         set\r
86                         {\r
87                                 MonoIO.SetCurrentDirectory (value);\r
88                         }\r
89                 }\r
90 \r
91                 /// <summary>\r
92                 /// Gets or sets the exit code of this process\r
93                 /// </summary>\r
94                 [MonoTODO]\r
95                 public static int ExitCode\r
96                 {       // TODO: find a way to implement this property\r
97                         get\r
98                         {\r
99                                 throw new NotImplementedException ();\r
100                         }\r
101                         set\r
102                         {\r
103                                 throw new NotImplementedException ();\r
104                         }\r
105                 }\r
106 \r
107                 /// <summary>\r
108                 /// Gets the name of the local computer\r
109                 /// </summary>\r
110                 public extern static string MachineName {\r
111                         [MethodImplAttribute (MethodImplOptions.InternalCall)]\r
112                         get;\r
113                 }\r
114 \r
115                 /// <summary>\r
116                 /// Gets the standard new line value\r
117                 /// </summary>\r
118                 public extern static string NewLine {\r
119                         [MethodImplAttribute (MethodImplOptions.InternalCall)]\r
120                         get;\r
121                 }\r
122 \r
123                 /// <summary>\r
124                 /// Gets the current OS version information\r
125                 /// </summary>\r
126                 [MonoTODO]\r
127                 public static OperatingSystem OSVersion {\r
128                         get\r
129                         {\r
130                                 return null;\r
131                         }\r
132                 }\r
133 \r
134                 /// <summary>\r
135                 /// Get StackTrace\r
136                 /// </summary>\r
137                 public static string StackTrace {\r
138                         get {\r
139                                 try {\r
140                                         throw new Exception ();\r
141                                 } catch (Exception e) {\r
142                                         return e.StackTrace;\r
143                                 }\r
144                         }\r
145                 }\r
146 \r
147                 /// <summary>\r
148                 /// Get a fully qualified path to the system directory\r
149                 /// </summary>\r
150                 public static string SystemDirectory\r
151                 {\r
152                         get\r
153                         {\r
154                                 return GetFolderPath(SpecialFolder.System);\r
155                         }\r
156                 }\r
157 \r
158                 /// <summary>\r
159                 /// Get the number of milliseconds that have elapsed since the system was booted\r
160                 /// </summary>\r
161                 public extern static int TickCount {\r
162                         [MethodImplAttribute (MethodImplOptions.InternalCall)]\r
163                         get;\r
164                 }\r
165 \r
166                 /// <summary>\r
167                 /// Get UserDomainName\r
168                 /// </summary>\r
169                 [MonoTODO]\r
170                 public static string UserDomainName {\r
171                         get {\r
172                                 return MachineName;\r
173                         }\r
174                 }\r
175 \r
176                 /// <summary>\r
177                 /// Gets a flag indicating whether the process is in interactive mode\r
178                 /// </summary>\r
179                 [MonoTODO]\r
180                 public static bool UserInteractive\r
181                 {\r
182                         get\r
183                         {\r
184                                 return false;\r
185                         }\r
186                 }\r
187 \r
188                 /// <summary>\r
189                 /// Get the user name of current process is running under\r
190                 /// </summary>\r
191                 [MonoTODO]\r
192                 public static string UserName\r
193                 {\r
194                         get\r
195                         {\r
196                                 // TODO: needs more research/work/thought\r
197                                 string result = GetEnvironmentVariable("USERNAME");\r
198                                 if(result == null || result.Equals(string.Empty))\r
199                                 {\r
200                                         result = GetEnvironmentVariable("USER");\r
201                                 }\r
202                                 return result;\r
203                         }\r
204                 }\r
205 \r
206                 /// <summary>\r
207                 /// Get the version of the common language runtime \r
208                 /// </summary>\r
209                 [MonoTODO]\r
210                 public static Version Version {\r
211                         get {\r
212                                 return new Version();\r
213                         }\r
214                 }\r
215 \r
216                 /// <summary>\r
217                 /// Get the amount of physical memory mapped to process\r
218                 /// </summary>\r
219                 [MonoTODO]\r
220                 public static long WorkingSet\r
221                 {\r
222                         get\r
223                         {\r
224                                 return 0;\r
225                         }\r
226                 }\r
227 \r
228                 [MethodImplAttribute (MethodImplOptions.InternalCall)]\r
229                 public extern static void Exit(int exitCode);\r
230 \r
231                 /// <summary>\r
232                 /// Substitute environment variables in the argument "name"\r
233                 /// </summary>\r
234                 [MonoTODO]\r
235                 public static string ExpandEnvironmentVariables(string name)\r
236                 {\r
237                         return name;\r
238                 }\r
239 \r
240                 /// <summary>\r
241                 /// Return an array of the command line arguments of the current process\r
242                 /// </summary>\r
243                 [MethodImplAttribute (MethodImplOptions.InternalCall)]\r
244                 public extern static string[] GetCommandLineArgs();\r
245 \r
246                 /// <summary>\r
247                 /// Return a string containing the value of the environment\r
248                 /// variable identifed by parameter "variable"\r
249                 /// </summary>\r
250                 [MethodImplAttribute (MethodImplOptions.InternalCall)]\r
251                 public extern static string GetEnvironmentVariable (string name);\r
252 \r
253                 /// <summary>\r
254                 /// Return a set of all environment variables and their values\r
255                 /// </summary>\r
256            \r
257                 public static IDictionary GetEnvironmentVariables()\r
258                 {\r
259                         Hashtable vars = new Hashtable ();\r
260                         foreach (string name in GetEnvironmentVariableNames ())\r
261                                 vars [name] = GetEnvironmentVariable (name);\r
262                         \r
263                         return vars;\r
264                 }\r
265 \r
266                 /// <summary>\r
267                 /// Returns the fully qualified path of the\r
268                 /// folder specified by the "folder" parameter\r
269                 /// </summary>\r
270                 [MonoTODO]\r
271                 public static string GetFolderPath(SpecialFolder folder)\r
272                 {\r
273                         return null;\r
274                 }\r
275 \r
276                 /// <summary>\r
277                 /// Returns an array of the logical drives\r
278                 /// </summary>\r
279                 [MonoTODO]\r
280                 public static string[] GetLogicalDrives()\r
281                 {\r
282                         return null;\r
283                 }\r
284 \r
285                 // private methods\r
286 \r
287                 [MethodImplAttribute (MethodImplOptions.InternalCall)]\r
288                 private extern static string [] GetEnvironmentVariableNames ();\r
289 \r
290         }\r
291 }\r