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
28 public enum SpecialFolder
\r
29 { // TODO: Determine if these windoze style folder identifiers
\r
30 // have unix/linux counterparts
\r
32 CommonApplicationData,
\r
39 LocalApplicationData,
\r
51 // TODO: Make sure the security attributes do what I expect
\r
54 /// Gets the command line for this process
\r
57 public static string CommandLine
\r
58 { // TODO: Coordinate with implementor of EnvironmentPermissionAttribute
\r
59 [EnvironmentPermissionAttribute(SecurityAction.Demand, Read = "COMMANDLINE")]
\r
62 return _os.CommandLine;
\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
71 public static string CurrentDirectory
\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
77 [EnvironmentPermissionAttribute(SecurityAction.Demand, Unrestricted = true)]
\r
80 return _os.GetCurrentDirectory();
\r
82 [MonoTODO("disabled because of compile error. Need mcs magic.")]
\r
83 //[SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
\r
86 _os.SetCurrentDirectory(value);
\r
91 /// Gets or sets the exit code of this process
\r
94 public static int ExitCode
\r
95 { // TODO: find a way to implement this property
\r
98 throw new NotImplementedException ();
\r
102 throw new NotImplementedException ();
\r
107 /// Gets the name of the local computer
\r
109 public static string MachineName
\r
113 return _os.MachineName;
\r
118 /// Gets the standard new line value
\r
120 public static string NewLine
\r
124 return _os.NewLineSequence;
\r
129 /// Gets the current OS version information
\r
131 public static OperatingSystem OSVersion
\r
135 return _os.OSVersion;
\r
142 public static string StackTrace
\r
151 /// Get a fully qualified path to the system directory
\r
153 public static string SystemDirectory
\r
157 return GetFolderPath(SpecialFolder.System);
\r
162 /// Get the number of milliseconds that have elapsed since the system was booted
\r
164 public static int TickCount
\r
169 //return getTickCount();
\r
174 /// Get UserDomainName
\r
176 public static string UserDomainName
\r
185 /// Gets a flag indicating whether the process is in interactive mode
\r
187 public static bool UserInteractive
\r
196 /// Get the user name of current process is running under
\r
199 public static string UserName
\r
203 // TODO: needs more research/work/thought
\r
204 string result = GetEnvironmentVariable("USERNAME");
\r
205 if(result == null || result.Equals(string.Empty))
\r
207 result = GetEnvironmentVariable("USER");
\r
214 /// Get the version of an assembly
\r
216 public static Version Version
\r
225 /// Get the amount of physical memory mapped to process
\r
227 public static long WorkingSet
\r
235 public static void Exit(int exitCode)
\r
240 /// Substitute environment variables in the argument "name"
\r
242 public static string ExpandEnvironmentVariables(string name)
\r
248 /// Return an array of the command line arguments of the current process
\r
250 public static string[] GetCommandLineArgs()
\r
252 char[] delimiter = new char[1];
\r
253 delimiter[0] = ' ';
\r
254 return _os.CommandLine.Split(delimiter);
\r
258 /// Return a string containing the value of the environment
\r
259 /// variable identifed by parameter "variable"
\r
261 public static string GetEnvironmentVariable(string variable)
\r
263 return _os.GetEnvironmentVariable(variable);
\r
267 /// Return a set of all environment variables and their values
\r
270 public static IDictionary GetEnvironmentVariables()
\r
272 return _os.EnvironmentVariables;
\r
276 /// Returns the fully qualified path of the
\r
277 /// folder specified by the "folder" parameter
\r
279 public static string GetFolderPath(SpecialFolder folder)
\r
285 /// Returns an array of the logical drives
\r
287 public static string[] GetLogicalDrives()
\r