2002-01-14 Miguel de Icaza <miguel@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 // Created:        Saturday, August 11, 2001 \r
9 //\r
10 //------------------------------------------------------------------------------\r
11 \r
12 using System;\r
13 using System.IO;\r
14 using System.Diagnostics;\r
15 using System.Collections;\r
16 using System.Security;\r
17 using System.PAL;\r
18 using System.Security.Permissions;\r
19 using System.Runtime.InteropServices;\r
20 \r
21 namespace System\r
22 {\r
23         public sealed class Environment\r
24         {\r
25                 private static OpSys _os = Platform.OS;\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                         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                 [MonoTODO]\r
57                 public static string CommandLine\r
58                 {       // TODO: Coordinate with implementor of EnvironmentPermissionAttribute\r
59                         [EnvironmentPermissionAttribute(SecurityAction.Demand, Read = "COMMANDLINE")]\r
60                         get\r
61                         {\r
62                                 return _os.CommandLine;\r
63                         }\r
64                 }\r
65 \r
66                 /// <summary>\r
67                 /// Gets or sets the current directory. Actually this is supposed to get\r
68                 /// and/or set the process start directory acording to the documentation\r
69                 /// but actually test revealed at beta2 it is just Getting/Setting the CurrentDirectory\r
70                 /// </summary>\r
71                 public static string CurrentDirectory\r
72                 {\r
73                         // originally it was my thought that the external call would be made in\r
74                         // the directory class however that class has additional security requirements\r
75                         // so the Directory class will call this class for its get/set current directory\r
76                         \r
77                         [EnvironmentPermissionAttribute(SecurityAction.Demand, Unrestricted = true)]\r
78                         get\r
79                         {\r
80                                 return _os.GetCurrentDirectory();\r
81                         }\r
82                         [MonoTODO("disabled because of compile error. Need mcs magic.")]\r
83                         //[SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]\r
84                         set\r
85                         {\r
86                                 _os.SetCurrentDirectory(value);\r
87                         }\r
88                 }\r
89 \r
90                 /// <summary>\r
91                 /// Gets or sets the exit code of this process\r
92                 /// </summary>\r
93                 [MonoTODO]\r
94                 public static int ExitCode\r
95                 {       // TODO: find a way to implement this property\r
96                         get\r
97                         {\r
98                                 throw new NotImplementedException ();\r
99                         }\r
100                         set\r
101                         {\r
102                                 throw new NotImplementedException ();\r
103                         }\r
104                 }\r
105 \r
106                 /// <summary>\r
107                 /// Gets the name of the local computer\r
108                 /// </summary>\r
109                 public static string MachineName\r
110                 {\r
111                         get\r
112                         {\r
113                                 return _os.MachineName;\r
114                         }\r
115                 }\r
116 \r
117                 /// <summary>\r
118                 /// Gets the standard new line value\r
119                 /// </summary>\r
120                 public static string NewLine\r
121                 {\r
122                         get\r
123                         {\r
124                                 return _os.NewLineSequence;\r
125                         }\r
126                 }\r
127 \r
128                 /// <summary>\r
129                 /// Gets the current OS version information\r
130                 /// </summary>\r
131                 public static OperatingSystem OSVersion\r
132                 {\r
133                         get\r
134                         {\r
135                                 return _os.OSVersion;\r
136                         }\r
137                 }\r
138 \r
139                 /// <summary>\r
140                 /// Get StackTrace\r
141                 /// </summary>\r
142                 public static string StackTrace\r
143                 {\r
144                         get\r
145                         {\r
146                                 return null;\r
147                         }\r
148                 }\r
149 \r
150                 /// <summary>\r
151                 /// Get a fully qualified path to the system directory\r
152                 /// </summary>\r
153                 public static string SystemDirectory\r
154                 {\r
155                         get\r
156                         {\r
157                                 return GetFolderPath(SpecialFolder.System);\r
158                         }\r
159                 }\r
160 \r
161                 /// <summary>\r
162                 /// Get the number of milliseconds that have elapsed since the system was booted\r
163                 /// </summary>\r
164                 public static int TickCount\r
165                 {\r
166                         get\r
167                         {\r
168                                 return 0;\r
169                                 //return getTickCount();\r
170                         }\r
171                 }\r
172 \r
173                 /// <summary>\r
174                 /// Get UserDomainName\r
175                 /// </summary>\r
176                 public static string UserDomainName\r
177                 {\r
178                         get\r
179                         {\r
180                                 return null;\r
181                         }\r
182                 }\r
183 \r
184                 /// <summary>\r
185                 /// Gets a flag indicating whether the process is in interactive mode\r
186                 /// </summary>\r
187                 public static bool UserInteractive\r
188                 {\r
189                         get\r
190                         {\r
191                                 return false;\r
192                         }\r
193                 }\r
194 \r
195                 /// <summary>\r
196                 /// Get the user name of current process is running under\r
197                 /// </summary>\r
198                 [MonoTODO]\r
199                 public static string UserName\r
200                 {\r
201                         get\r
202                         {\r
203                                 // TODO: needs more research/work/thought\r
204                                 string result = GetEnvironmentVariable("USERNAME");\r
205                                 if(result == null || result.Equals(string.Empty))\r
206                                 {\r
207                                         result = GetEnvironmentVariable("USER");\r
208                                 }\r
209                                 return result;\r
210                         }\r
211                 }\r
212 \r
213                 /// <summary>\r
214                 /// Get the version of an assembly\r
215                 /// </summary>\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                 public static long WorkingSet\r
228                 {\r
229                         get\r
230                         {\r
231                                 return 0;\r
232                         }\r
233                 }\r
234 \r
235                 public static void Exit(int exitCode)\r
236                 { \r
237                 }\r
238 \r
239                 /// <summary>\r
240                 /// Substitute environment variables in the argument "name"\r
241                 /// </summary>\r
242                 public static string ExpandEnvironmentVariables(string name)\r
243                 {\r
244                         return name;\r
245                 }\r
246 \r
247                 /// <summary>\r
248                 /// Return an array of the command line arguments of the current process\r
249                 /// </summary>\r
250                 public static string[] GetCommandLineArgs()\r
251                 {\r
252                         char[] delimiter = new char[1];\r
253                         delimiter[0] = ' ';\r
254                         return _os.CommandLine.Split(delimiter);\r
255                 }\r
256 \r
257                 /// <summary>\r
258                 /// Return a string containing the value of the environment\r
259                 /// variable identifed by parameter "variable"\r
260                 /// </summary>\r
261                 public static string GetEnvironmentVariable(string variable)\r
262                 {\r
263                         return _os.GetEnvironmentVariable(variable);\r
264                 }\r
265 \r
266                 /// <summary>\r
267                 /// Return a set of all environment variables and their values\r
268                 /// </summary>\r
269            \r
270                 public static IDictionary GetEnvironmentVariables()\r
271                 {\r
272                         return _os.EnvironmentVariables;\r
273                 }\r
274 \r
275                 /// <summary>\r
276                 /// Returns the fully qualified path of the\r
277                 /// folder specified by the "folder" parameter\r
278                 /// </summary>\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                 public static string[] GetLogicalDrives()\r
288                 {\r
289                         return null;\r
290                 }\r
291 \r
292         }\r
293 }\r