Mon Apr 29 15:32:02 CEST 2002 Paolo Molaro <lupus@ximian.com>
[mono.git] / mcs / class / corlib / System / Environment.cs
index fba26d07214c9e1864fcb2433d64000d0e853ecb..dc92fda727c3c26b535a8082f3098bf542649ce8 100644 (file)
-//------------------------------------------------------------------------------
-// 
-// System.Environment.cs 
-//
-// Copyright (C) 2001 Moonlight Enterprises, All Rights Reserved
-// 
-// Author:         Jim Richardson, develop@wtfo-guru.com
-// Created:        Saturday, August 11, 2001 
-//
-//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------\r
+// \r
+// System.Environment.cs \r
+//\r
+// Copyright (C) 2001 Moonlight Enterprises, All Rights Reserved\r
+// \r
+// Author:         Jim Richardson, develop@wtfo-guru.com\r
+//                 Dan Lewis (dihlewis@yahoo.co.uk)\r
+// Created:        Saturday, August 11, 2001 \r
+//\r
+//------------------------------------------------------------------------------\r
+\r
+using System;\r
+using System.IO;\r
+//using System.Diagnostics;\r
+using System.Collections;\r
+using System.Security;\r
+using System.Security.Permissions;\r
+using System.Runtime.CompilerServices;\r
+\r
+namespace System\r
+{\r
+       public sealed class Environment\r
+       {\r
+               private Environment () {}
 
-using System;
-using System.IO;
-using System.Diagnostics;
-using System.Collections;
-using System.Security;
-using System.Security.Permissions;
-
-namespace System
-{
-       public sealed class Environment
-       {
-               public enum SpecialFolder
-               {       // TODO: Determine if these windoze style folder identifiers 
-                       //       have unix/linux counterparts
-                       ApplicationData,
-                       CommonApplicationData,
-                       CommonProgramFiles,
-                       Cookies,
-                       DesktopDirectory,
-                       Favorites,
-                       History,
-                       InternetCache,
-                       LocalApplicationData,
-                       Personal,
-                       ProgramFiles,
-                       Programs,
-                       Recent,
-                       SendTo,
-                       StartMenu,
-                       Startup,
-                       System,
-                       Templates
-               }
-
-               // TODO: Make sure the security attributes do what I expect
-                       
-               /// <summary>
-               /// Gets the command line for this process
-               /// </summary>
-               public static string CommandLine
-               {       // TODO: Coordinate with implementor of EnvironmentPermissionAttribute
-                       [EnvironmentPermissionAttribute(SecurityAction.Demand, Read = "COMMANDLINE")]
-                       get
-                       {
-                               return PlatformSpecific.getCommandLine();
-                       }
-               }
-
-               /// <summary>
-               /// Gets or sets the current directory. Actually this is supposed to get
-               /// and/or set the process start directory acording to the documentation
-               /// but actually test revealed at beta2 it is just Getting/Setting the CurrentDirectory
-               /// </summary>
-               public static string CurrentDirectory
-               {
-                       // originally it was my thought that the external call would be made in
-                       // the directory class however that class has additional security requirements
-                       // so the Directory class will call this class for its get/set current directory
-                       
-                       [EnvironmentPermissionAttribute(SecurityAction.Demand, Unrestricted = true)]
-                       get
-                       {
-                               return PlatformSpecific.getCurrentDirectory();
-                       }
-                       [SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
-                       set
-                       {
-                               PlatformSpecific.setCurrentDirectory(value);
-                       }
-               }
-
-               /// <summary>
-               /// Gets or sets the exit code of this process
-               /// </summary>
-               public static int ExitCode
-               {       // TODO: find a way to implement this property
-                       get
-                       {
-                               return 0;
-                       }
-                       set
-                       {
-                       }
-               }
-
-               /// <summary>
-               /// Gets the name of the local computer
-               /// </summary>
-               public static string MachineName
-               {
-                       get
-                       {
-                               return PlatformSpecific.getMachineName();
-                       }
-               }
-
-               /// <summary>
-               /// Gets the standard new line value
-               /// </summary>
-               public static string NewLine
-               {
-                       get
-                       {
-                               return PlatformSpecific.NewLine;
-                       }
-               }
-
-               /// <summary>
-               /// Gets the current OS version information
-               /// </summary>
-               public static OperatingSystem OSVersion
-               {
-                       get
-                       {
-                               return PlatformSpecific.getOSVersion();
-                       }
-               }
-
-               /// <summary>
-               /// Get StackTrace
-               /// </summary>
-               public static string StackTrace
-               {
-                       get
-                       {
-                               return null;
-                       }
-               }
-
-               /// <summary>
-               /// Get a fully qualified path to the system directory
-               /// </summary>
-               public static string SystemDirectory
-               {
-                       get
-                       {
-                               return GetFolderPath(SpecialFolder.System);
-                       }
-               }
-
-               /// <summary>
-               /// Get the number of milliseconds that have elapsed since the system was booted
-               /// </summary>
-               public static int TickCount
-               {
-                       get
-                       {
-                               return 0;
-                               //return getTickCount();
-                       }
-               }
-
-               /// <summary>
-               /// Get UserDomainName
-               /// </summary>
-               public static string UserDomainName
-               {
-                       get
-                       {
-                               return null;
-                       }
-               }
-
-               /// <summary>
-               /// Gets a flag indicating whether the process is in interactive mode
-               /// </summary>
-               public static bool UserInteractive
-               {
-                       get
-                       {
-                               return false;
-                       }
-               }
-
-               /// <summary>
-               /// Get the user name of current process is running under
-               /// </summary>
-               public static string UserName
-               {
-                       get
-                       {
-                               // TODO: needs more research/work/thought
-                               string result = GetEnvironmentVariable("USERNAME");
-                               if(result == null || result.Equals(string.Empty))
-                               {
-                                       result = GetEnvironmentVariable("USER");
-                               }
-                               return result;
-                       }
-               }
-
-               /// <summary>
-               /// Get the version of an assembly
-               /// </summary>
-               public static Version Version
-               {
-                       get
-                       {
-                               return null;
-                       }
-               }
-
-               /// <summary>
-               /// Get the amount of physical memory mapped to process
-               /// </summary>
-               public static long WorkingSet
-               {
-                       get
-                       {
-                               return 0;
-                       }
-               }
-
-               public static void Exit(int exitCode)
-               { 
-               }
-
-               /// <summary>
-               /// Substitute environment variables in the argument "name"
-               /// </summary>
-               public static string ExpandEnvironmentVariables(string name)
-               {
-                       return name;
-               }
-
-               /// <summary>
-               /// Return an array of the command line arguments of the current process
-               /// </summary>
-               public static string[] GetCommandLineArgs()
-               {
-                       char[] delimiter = new char[1];
-                       delimiter[0] = ' ';
-                       return PlatformSpecific.getCommandLine().Split(delimiter);
-               }
-
-               /// <summary>
-               /// Return a string containing the value of the environment
-               /// variable identifed by parameter "variable"
-               /// </summary>
-               public static string GetEnvironmentVariable(string variable)
-               {
-                       return (string)(getEnvironmentStrings()[variable]);
-               }
-
-               /// <summary>
-               /// Return a set of all environment variables and their values
-               /// </summary>
-          
-               public static IDictionary getEnvironmentStrings()
-               {
-                       // could cache these in a member variable, but that
-                       // wouldn't be very safe because the environment is
-                       // dyanamic ya know
-                       string strEnv = PlatformSpecific.getEnvironment();\r
-                       char[] delimiter = new char[1];\r
-                       delimiter[0] = '\t';
-                       string[] arEnv = strEnv.Split(delimiter);
-                       string[] arStr;
-                       Hashtable ht = new Hashtable();
-                       foreach(string str in arEnv)
+               [MonoTODO]\r
+               public enum SpecialFolder\r
+               {       // TODO: Determine if these windoze style folder identifiers \r
+                       //       have unix/linux counterparts\r
+                       ApplicationData,\r
+                       CommonApplicationData,\r
+                       CommonProgramFiles,\r
+                       Cookies,\r
+                       DesktopDirectory,\r
+                       Favorites,\r
+                       History,\r
+                       InternetCache,\r
+                       LocalApplicationData,\r
+                       Personal,\r
+                       ProgramFiles,\r
+                       Programs,\r
+                       Recent,\r
+                       SendTo,\r
+                       StartMenu,\r
+                       Startup,\r
+                       System,\r
+                       Templates\r
+               }\r
+\r
+               // TODO: Make sure the security attributes do what I expect\r
+                       \r
+               /// <summary>\r
+               /// Gets the command line for this process\r
+               /// </summary>\r
+               public static string CommandLine\r
+               {       // TODO: Coordinate with implementor of EnvironmentPermissionAttribute\r
+                       // [EnvironmentPermissionAttribute(SecurityAction.Demand, Read = "COMMANDLINE")]\r
+                       get\r
                        {\r
-                               delimiter[0] = '=';
-                               arStr = str.Split(delimiter, 2);
-                               switch(arStr.Length)
-                               {
-                               case 1:
-                                       ht.Add(arStr[0], "");
-                                       break;
-                               case 2:
-                                       ht.Add(arStr[0], arStr[1]);
-                                       break;
-                               default:
-                                       Debug.Assert(false);    // this shouldn't happen
-                                       break;
-                               }
-                       }
-                       return ht;
-               }
-
-               /// <summary>
-               /// Returns the fully qualified path of the
-               /// folder specified by the "folder" parameter
-               /// </summary>
-               public static string GetFolderPath(SpecialFolder folder)
-               {
-                       return null;
-               }
-
-               /// <summary>
-               /// Returns an array of the logical drives
-               /// </summary>
-               public static string[] GetLogicalDrives()
-               {
-                       return null;
-               }
-
-       }
-}
+                               // FIXME: we may need to quote, but any sane person\r
+                               // should use GetCommandLineArgs () instead.\r
+                               return String.Join ("", GetCommandLineArgs ());\r
+                       }\r
+               }\r
+\r
+               /// <summary>\r
+               /// Gets or sets the current directory. Actually this is supposed to get\r
+               /// and/or set the process start directory acording to the documentation\r
+               /// but actually test revealed at beta2 it is just Getting/Setting the CurrentDirectory\r
+               /// </summary>\r
+               public static string CurrentDirectory\r
+               {\r
+                       // originally it was my thought that the external call would be made in\r
+                       // the directory class however that class has additional security requirements\r
+                       // so the Directory class will call this class for its get/set current directory\r
+                       \r
+                       // [EnvironmentPermissionAttribute(SecurityAction.Demand, Unrestricted = true)]\r
+                       get\r
+                       {\r
+                               return MonoIO.GetCurrentDirectory ();\r
+                       }\r
+                       [MonoTODO("disabled because of compile error. Need mcs magic.")]\r
+                       //[SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]\r
+                       set\r
+                       {\r
+                               MonoIO.SetCurrentDirectory (value);\r
+                       }\r
+               }\r
+\r
+               /// <summary>\r
+               /// Gets or sets the exit code of this process\r
+               /// </summary>\r
+               [MonoTODO]\r
+               public static int ExitCode\r
+               {       // TODO: find a way to implement this property\r
+                       get\r
+                       {\r
+                               throw new NotImplementedException ();\r
+                       }\r
+                       set\r
+                       {\r
+                               throw new NotImplementedException ();\r
+                       }\r
+               }\r
+\r
+               /// <summary>\r
+               /// Gets the name of the local computer\r
+               /// </summary>\r
+               public extern static string MachineName {\r
+                       [MethodImplAttribute (MethodImplOptions.InternalCall)]\r
+                       get;\r
+               }\r
+\r
+               /// <summary>\r
+               /// Gets the standard new line value\r
+               /// </summary>\r
+               public extern static string NewLine {\r
+                       [MethodImplAttribute (MethodImplOptions.InternalCall)]\r
+                       get;\r
+               }\r
+\r
+               /// <summary>\r
+               /// Gets the current OS version information\r
+               /// </summary>\r
+               [MonoTODO]\r
+               public static OperatingSystem OSVersion {\r
+                       get\r
+                       {\r
+                               return null;\r
+                       }\r
+               }\r
+\r
+               /// <summary>\r
+               /// Get StackTrace\r
+               /// </summary>\r
+               [MonoTODO]\r
+               public static string StackTrace\r
+               {\r
+                       get\r
+                       {\r
+                               return null;\r
+                       }\r
+               }\r
+\r
+               /// <summary>\r
+               /// Get a fully qualified path to the system directory\r
+               /// </summary>\r
+               public static string SystemDirectory\r
+               {\r
+                       get\r
+                       {\r
+                               return GetFolderPath(SpecialFolder.System);\r
+                       }\r
+               }\r
+\r
+               /// <summary>\r
+               /// Get the number of milliseconds that have elapsed since the system was booted\r
+               /// </summary>\r
+               [MonoTODO]\r
+               public static int TickCount\r
+               {\r
+                       get\r
+                       {\r
+                               return 0;\r
+                               //return getTickCount();\r
+                       }\r
+               }\r
+\r
+               /// <summary>\r
+               /// Get UserDomainName\r
+               /// </summary>\r
+               [MonoTODO]\r
+               public static string UserDomainName\r
+               {\r
+                       get\r
+                       {\r
+                               return null;\r
+                       }\r
+               }\r
+\r
+               /// <summary>\r
+               /// Gets a flag indicating whether the process is in interactive mode\r
+               /// </summary>\r
+               [MonoTODO]\r
+               public static bool UserInteractive\r
+               {\r
+                       get\r
+                       {\r
+                               return false;\r
+                       }\r
+               }\r
+\r
+               /// <summary>\r
+               /// Get the user name of current process is running under\r
+               /// </summary>\r
+               [MonoTODO]\r
+               public static string UserName\r
+               {\r
+                       get\r
+                       {\r
+                               // TODO: needs more research/work/thought\r
+                               string result = GetEnvironmentVariable("USERNAME");\r
+                               if(result == null || result.Equals(string.Empty))\r
+                               {\r
+                                       result = GetEnvironmentVariable("USER");\r
+                               }\r
+                               return result;\r
+                       }\r
+               }\r
+\r
+               /// <summary>\r
+               /// Get the version of an assembly\r
+               /// </summary>\r
+               [MonoTODO]\r
+               public static Version Version\r
+               {\r
+                       get\r
+                       {\r
+                               return null;\r
+                       }\r
+               }\r
+\r
+               /// <summary>\r
+               /// Get the amount of physical memory mapped to process\r
+               /// </summary>\r
+               [MonoTODO]\r
+               public static long WorkingSet\r
+               {\r
+                       get\r
+                       {\r
+                               return 0;\r
+                       }\r
+               }\r
+\r
+               [MethodImplAttribute (MethodImplOptions.InternalCall)]\r
+               public extern static void Exit(int exitCode);\r
+\r
+               /// <summary>\r
+               /// Substitute environment variables in the argument "name"\r
+               /// </summary>\r
+               [MonoTODO]\r
+               public static string ExpandEnvironmentVariables(string name)\r
+               {\r
+                       return name;\r
+               }\r
+\r
+               /// <summary>\r
+               /// Return an array of the command line arguments of the current process\r
+               /// </summary>\r
+               [MethodImplAttribute (MethodImplOptions.InternalCall)]\r
+               public extern static string[] GetCommandLineArgs();\r
+\r
+               /// <summary>\r
+               /// Return a string containing the value of the environment\r
+               /// variable identifed by parameter "variable"\r
+               /// </summary>\r
+               [MethodImplAttribute (MethodImplOptions.InternalCall)]\r
+               public extern static string GetEnvironmentVariable (string name);\r
+\r
+               /// <summary>\r
+               /// Return a set of all environment variables and their values\r
+               /// </summary>\r
+          \r
+               public static IDictionary GetEnvironmentVariables()\r
+               {\r
+                       Hashtable vars = new Hashtable ();\r
+                       foreach (string name in GetEnvironmentVariableNames ())\r
+                               vars [name] = GetEnvironmentVariable (name);\r
+                       \r
+                       return vars;\r
+               }\r
+\r
+               /// <summary>\r
+               /// Returns the fully qualified path of the\r
+               /// folder specified by the "folder" parameter\r
+               /// </summary>\r
+               [MonoTODO]\r
+               public static string GetFolderPath(SpecialFolder folder)\r
+               {\r
+                       return null;\r
+               }\r
+\r
+               /// <summary>\r
+               /// Returns an array of the logical drives\r
+               /// </summary>\r
+               [MonoTODO]\r
+               public static string[] GetLogicalDrives()\r
+               {\r
+                       return null;\r
+               }\r
+\r
+               // private methods\r
+\r
+               [MethodImplAttribute (MethodImplOptions.InternalCall)]\r
+               private extern static string [] GetEnvironmentVariableNames ();\r
+\r
+       }\r
+}\r