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 // Created: Saturday, August 11, 2001
\r
10 //------------------------------------------------------------------------------
\r
14 using System.Diagnostics;
\r
15 using System.Collections;
\r
16 using System.Security;
\r
18 using System.Security.Permissions;
\r
19 using System.Runtime.InteropServices;
\r
23 public sealed class Environment
\r
25 private static OpSys _os = Platform.OS;
\r
27 public enum SpecialFolder
\r
28 { // TODO: Determine if these windoze style folder identifiers
\r
29 // have unix/linux counterparts
\r
31 CommonApplicationData,
\r
38 LocalApplicationData,
\r
50 // TODO: Make sure the security attributes do what I expect
\r
53 /// Gets the command line for this process
\r
55 public static string CommandLine
\r
56 { // TODO: Coordinate with implementor of EnvironmentPermissionAttribute
\r
57 [EnvironmentPermissionAttribute(SecurityAction.Demand, Read = "COMMANDLINE")]
\r
60 return _os.CommandLine;
\r
65 /// Gets or sets the current directory. Actually this is supposed to get
\r
66 /// and/or set the process start directory acording to the documentation
\r
67 /// but actually test revealed at beta2 it is just Getting/Setting the CurrentDirectory
\r
69 public static string CurrentDirectory
\r
71 // originally it was my thought that the external call would be made in
\r
72 // the directory class however that class has additional security requirements
\r
73 // so the Directory class will call this class for its get/set current directory
\r
75 [EnvironmentPermissionAttribute(SecurityAction.Demand, Unrestricted = true)]
\r
78 return _os.GetCurrentDirectory();
\r
80 [SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
\r
83 _os.SetCurrentDirectory(value);
\r
88 /// Gets or sets the exit code of this process
\r
90 public static int ExitCode
\r
91 { // TODO: find a way to implement this property
\r
102 /// Gets the name of the local computer
\r
104 public static string MachineName
\r
108 return _os.MachineName;
\r
113 /// Gets the standard new line value
\r
115 public static string NewLine
\r
119 return _os.NewLineSequence;
\r
124 /// Gets the current OS version information
\r
126 public static OperatingSystem OSVersion
\r
130 return _os.OSVersion;
\r
137 public static string StackTrace
\r
146 /// Get a fully qualified path to the system directory
\r
148 public static string SystemDirectory
\r
152 return GetFolderPath(SpecialFolder.System);
\r
157 /// Get the number of milliseconds that have elapsed since the system was booted
\r
159 public static int TickCount
\r
164 //return getTickCount();
\r
169 /// Get UserDomainName
\r
171 public static string UserDomainName
\r
180 /// Gets a flag indicating whether the process is in interactive mode
\r
182 public static bool UserInteractive
\r
191 /// Get the user name of current process is running under
\r
193 public static string UserName
\r
197 // TODO: needs more research/work/thought
\r
198 string result = GetEnvironmentVariable("USERNAME");
\r
199 if(result == null || result.Equals(string.Empty))
\r
201 result = GetEnvironmentVariable("USER");
\r
208 /// Get the version of an assembly
\r
210 public static Version Version
\r
219 /// Get the amount of physical memory mapped to process
\r
221 public static long WorkingSet
\r
229 public static void Exit(int exitCode)
\r
234 /// Substitute environment variables in the argument "name"
\r
236 public static string ExpandEnvironmentVariables(string name)
\r
242 /// Return an array of the command line arguments of the current process
\r
244 public static string[] GetCommandLineArgs()
\r
246 char[] delimiter = new char[1];
\r
247 delimiter[0] = ' ';
\r
248 return _os.CommandLine.Split(delimiter);
\r
252 /// Return a string containing the value of the environment
\r
253 /// variable identifed by parameter "variable"
\r
255 public static string GetEnvironmentVariable(string variable)
\r
257 return _os.GetEnvironmentVariable(variable);
\r
261 /// Return a set of all environment variables and their values
\r
264 public static IDictionary GetEnvironmentVariables()
\r
266 return _os.EnvironmentVariables;
\r
270 /// Returns the fully qualified path of the
\r
271 /// folder specified by the "folder" parameter
\r
273 public static string GetFolderPath(SpecialFolder folder)
\r
279 /// Returns an array of the logical drives
\r
281 public static string[] GetLogicalDrives()
\r