1 //------------------------------------------------------------------------------
\r
3 // System.Environment.cs
\r
5 // Copyright (C) 2001 Moonlight Enterprises, All Rights Reserved
\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
11 //------------------------------------------------------------------------------
\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
23 public sealed class Environment
\r
25 private Environment () {}
\r
28 public enum SpecialFolder
\r
29 { // TODO: Determine if these windoze style folder identifiers
\r
30 // have unix/linux counterparts
\r
38 DesktopDirectory = 0x10,
\r
40 ApplicationData = 0x1a,
\r
41 LocalApplicationData = 0x1c,
\r
42 InternetCache = 0x20,
\r
45 CommonApplicationData = 0x23,
\r
47 ProgramFiles = 0x26,
\r
48 CommonProgramFiles = 0x2b,
\r
51 // TODO: Make sure the security attributes do what I expect
\r
54 /// Gets the command line for this process
\r
56 public static string CommandLine
\r
57 { // TODO: Coordinate with implementor of EnvironmentPermissionAttribute
\r
58 // [EnvironmentPermissionAttribute(SecurityAction.Demand, Read = "COMMANDLINE")]
\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
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
72 public static string CurrentDirectory
\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
78 // [EnvironmentPermissionAttribute(SecurityAction.Demand, Unrestricted = true)]
\r
81 return MonoIO.GetCurrentDirectory ();
\r
83 [MonoTODO("disabled because of compile error. Need mcs magic.")]
\r
84 //[SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
\r
87 MonoIO.SetCurrentDirectory (value);
\r
92 /// Gets or sets the exit code of this process
\r
95 public static int ExitCode
\r
96 { // TODO: find a way to implement this property
\r
99 throw new NotImplementedException ();
\r
103 throw new NotImplementedException ();
\r
108 /// Gets the name of the local computer
\r
110 public extern static string MachineName {
\r
111 [MethodImplAttribute (MethodImplOptions.InternalCall)]
\r
116 /// Gets the standard new line value
\r
118 public extern static string NewLine {
\r
119 [MethodImplAttribute (MethodImplOptions.InternalCall)]
\r
124 /// Gets the current OS version information
\r
127 public static OperatingSystem OSVersion {
\r
137 public static string StackTrace {
\r
140 throw new Exception ();
\r
141 } catch (Exception e) {
\r
142 return e.StackTrace;
\r
148 /// Get a fully qualified path to the system directory
\r
150 public static string SystemDirectory
\r
154 return GetFolderPath(SpecialFolder.System);
\r
159 /// Get the number of milliseconds that have elapsed since the system was booted
\r
161 public extern static int TickCount {
\r
162 [MethodImplAttribute (MethodImplOptions.InternalCall)]
\r
167 /// Get UserDomainName
\r
170 public static string UserDomainName {
\r
172 return MachineName;
\r
177 /// Gets a flag indicating whether the process is in interactive mode
\r
180 public static bool UserInteractive
\r
189 /// Get the user name of current process is running under
\r
192 public static string UserName
\r
196 // TODO: needs more research/work/thought
\r
197 string result = GetEnvironmentVariable("USERNAME");
\r
198 if(result == null || result.Equals(string.Empty))
\r
200 result = GetEnvironmentVariable("USER");
\r
207 /// Get the version of the common language runtime
\r
210 public static Version Version {
\r
212 return new Version();
\r
217 /// Get the amount of physical memory mapped to process
\r
220 public static long WorkingSet
\r
228 [MethodImplAttribute (MethodImplOptions.InternalCall)]
\r
229 public extern static void Exit(int exitCode);
\r
232 /// Substitute environment variables in the argument "name"
\r
235 public static string ExpandEnvironmentVariables(string name)
\r
241 /// Return an array of the command line arguments of the current process
\r
243 [MethodImplAttribute (MethodImplOptions.InternalCall)]
\r
244 public extern static string[] GetCommandLineArgs();
\r
247 /// Return a string containing the value of the environment
\r
248 /// variable identifed by parameter "variable"
\r
250 [MethodImplAttribute (MethodImplOptions.InternalCall)]
\r
251 public extern static string GetEnvironmentVariable (string name);
\r
254 /// Return a set of all environment variables and their values
\r
257 public static IDictionary GetEnvironmentVariables()
\r
259 Hashtable vars = new Hashtable ();
\r
260 foreach (string name in GetEnvironmentVariableNames ())
\r
261 vars [name] = GetEnvironmentVariable (name);
\r
267 /// Returns the fully qualified path of the
\r
268 /// folder specified by the "folder" parameter
\r
271 public static string GetFolderPath(SpecialFolder folder)
\r
277 /// Returns an array of the logical drives
\r
280 public static string[] GetLogicalDrives()
\r
287 [MethodImplAttribute (MethodImplOptions.InternalCall)]
\r
288 private extern static string [] GetEnvironmentVariableNames ();
\r