dc92fda727c3c26b535a8082f3098bf542649ce8
[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 () {}
26
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                         ApplicationData,\r
32                         CommonApplicationData,\r
33                         CommonProgramFiles,\r
34                         Cookies,\r
35                         DesktopDirectory,\r
36                         Favorites,\r
37                         History,\r
38                         InternetCache,\r
39                         LocalApplicationData,\r
40                         Personal,\r
41                         ProgramFiles,\r
42                         Programs,\r
43                         Recent,\r
44                         SendTo,\r
45                         StartMenu,\r
46                         Startup,\r
47                         System,\r
48                         Templates\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                 [MonoTODO]\r
138                 public static string StackTrace\r
139                 {\r
140                         get\r
141                         {\r
142                                 return null;\r
143                         }\r
144                 }\r
145 \r
146                 /// <summary>\r
147                 /// Get a fully qualified path to the system directory\r
148                 /// </summary>\r
149                 public static string SystemDirectory\r
150                 {\r
151                         get\r
152                         {\r
153                                 return GetFolderPath(SpecialFolder.System);\r
154                         }\r
155                 }\r
156 \r
157                 /// <summary>\r
158                 /// Get the number of milliseconds that have elapsed since the system was booted\r
159                 /// </summary>\r
160                 [MonoTODO]\r
161                 public static int TickCount\r
162                 {\r
163                         get\r
164                         {\r
165                                 return 0;\r
166                                 //return getTickCount();\r
167                         }\r
168                 }\r
169 \r
170                 /// <summary>\r
171                 /// Get UserDomainName\r
172                 /// </summary>\r
173                 [MonoTODO]\r
174                 public static string UserDomainName\r
175                 {\r
176                         get\r
177                         {\r
178                                 return null;\r
179                         }\r
180                 }\r
181 \r
182                 /// <summary>\r
183                 /// Gets a flag indicating whether the process is in interactive mode\r
184                 /// </summary>\r
185                 [MonoTODO]\r
186                 public static bool UserInteractive\r
187                 {\r
188                         get\r
189                         {\r
190                                 return false;\r
191                         }\r
192                 }\r
193 \r
194                 /// <summary>\r
195                 /// Get the user name of current process is running under\r
196                 /// </summary>\r
197                 [MonoTODO]\r
198                 public static string UserName\r
199                 {\r
200                         get\r
201                         {\r
202                                 // TODO: needs more research/work/thought\r
203                                 string result = GetEnvironmentVariable("USERNAME");\r
204                                 if(result == null || result.Equals(string.Empty))\r
205                                 {\r
206                                         result = GetEnvironmentVariable("USER");\r
207                                 }\r
208                                 return result;\r
209                         }\r
210                 }\r
211 \r
212                 /// <summary>\r
213                 /// Get the version of an assembly\r
214                 /// </summary>\r
215                 [MonoTODO]\r
216                 public static Version Version\r
217                 {\r
218                         get\r
219                         {\r
220                                 return null;\r
221                         }\r
222                 }\r
223 \r
224                 /// <summary>\r
225                 /// Get the amount of physical memory mapped to process\r
226                 /// </summary>\r
227                 [MonoTODO]\r
228                 public static long WorkingSet\r
229                 {\r
230                         get\r
231                         {\r
232                                 return 0;\r
233                         }\r
234                 }\r
235 \r
236                 [MethodImplAttribute (MethodImplOptions.InternalCall)]\r
237                 public extern static void Exit(int exitCode);\r
238 \r
239                 /// <summary>\r
240                 /// Substitute environment variables in the argument "name"\r
241                 /// </summary>\r
242                 [MonoTODO]\r
243                 public static string ExpandEnvironmentVariables(string name)\r
244                 {\r
245                         return name;\r
246                 }\r
247 \r
248                 /// <summary>\r
249                 /// Return an array of the command line arguments of the current process\r
250                 /// </summary>\r
251                 [MethodImplAttribute (MethodImplOptions.InternalCall)]\r
252                 public extern static string[] GetCommandLineArgs();\r
253 \r
254                 /// <summary>\r
255                 /// Return a string containing the value of the environment\r
256                 /// variable identifed by parameter "variable"\r
257                 /// </summary>\r
258                 [MethodImplAttribute (MethodImplOptions.InternalCall)]\r
259                 public extern static string GetEnvironmentVariable (string name);\r
260 \r
261                 /// <summary>\r
262                 /// Return a set of all environment variables and their values\r
263                 /// </summary>\r
264            \r
265                 public static IDictionary GetEnvironmentVariables()\r
266                 {\r
267                         Hashtable vars = new Hashtable ();\r
268                         foreach (string name in GetEnvironmentVariableNames ())\r
269                                 vars [name] = GetEnvironmentVariable (name);\r
270                         \r
271                         return vars;\r
272                 }\r
273 \r
274                 /// <summary>\r
275                 /// Returns the fully qualified path of the\r
276                 /// folder specified by the "folder" parameter\r
277                 /// </summary>\r
278                 [MonoTODO]\r
279                 public static string GetFolderPath(SpecialFolder folder)\r
280                 {\r
281                         return null;\r
282                 }\r
283 \r
284                 /// <summary>\r
285                 /// Returns an array of the logical drives\r
286                 /// </summary>\r
287                 [MonoTODO]\r
288                 public static string[] GetLogicalDrives()\r
289                 {\r
290                         return null;\r
291                 }\r
292 \r
293                 // private methods\r
294 \r
295                 [MethodImplAttribute (MethodImplOptions.InternalCall)]\r
296                 private extern static string [] GetEnvironmentVariableNames ();\r
297 \r
298         }\r
299 }\r