Mon Apr 29 15:32:02 CEST 2002 Paolo Molaro <lupus@ximian.com>
[mono.git] / mcs / class / corlib / System / Environment.cs
index 21dab88c2d1dd6a08ab972c7ec90c66d395cbb01..dc92fda727c3c26b535a8082f3098bf542649ce8 100644 (file)
@@ -5,26 +5,26 @@
 // 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.Diagnostics;\r
 using System.Collections;\r
 using System.Security;\r
-using System.PAL;\r
 using System.Security.Permissions;\r
-using System.Runtime.InteropServices;\r
+using System.Runtime.CompilerServices;\r
 \r
 namespace System\r
 {\r
        public sealed class Environment\r
        {\r
-               private static OpSys _os = Platform.OS;\r
-\r
-               [TODO]\r
+               private Environment () {}
+
+               [MonoTODO]\r
                public enum SpecialFolder\r
                {       // TODO: Determine if these windoze style folder identifiers \r
                        //       have unix/linux counterparts\r
@@ -53,13 +53,14 @@ namespace System
                /// <summary>\r
                /// Gets the command line for this process\r
                /// </summary>\r
-               [TODO]\r
                public static string CommandLine\r
                {       // TODO: Coordinate with implementor of EnvironmentPermissionAttribute\r
-                       [EnvironmentPermissionAttribute(SecurityAction.Demand, Read = "COMMANDLINE")]\r
+                       // [EnvironmentPermissionAttribute(SecurityAction.Demand, Read = "COMMANDLINE")]\r
                        get\r
                        {\r
-                               return _os.CommandLine;\r
+                               // FIXME: we may need to quote, but any sane person\r
+                               // should use GetCommandLineArgs () instead.\r
+                               return String.Join ("", GetCommandLineArgs ());\r
                        }\r
                }\r
 \r
@@ -74,22 +75,23 @@ namespace System
                        // 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
+                       // [EnvironmentPermissionAttribute(SecurityAction.Demand, Unrestricted = true)]\r
                        get\r
                        {\r
-                               return _os.GetCurrentDirectory();\r
+                               return MonoIO.GetCurrentDirectory ();\r
                        }\r
-                       [SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]\r
+                       [MonoTODO("disabled because of compile error. Need mcs magic.")]\r
+                       //[SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]\r
                        set\r
                        {\r
-                               _os.SetCurrentDirectory(value);\r
+                               MonoIO.SetCurrentDirectory (value);\r
                        }\r
                }\r
 \r
                /// <summary>\r
                /// Gets or sets the exit code of this process\r
                /// </summary>\r
-               [TODO]\r
+               [MonoTODO]\r
                public static int ExitCode\r
                {       // TODO: find a way to implement this property\r
                        get\r
@@ -105,39 +107,34 @@ namespace System
                /// <summary>\r
                /// Gets the name of the local computer\r
                /// </summary>\r
-               public static string MachineName\r
-               {\r
-                       get\r
-                       {\r
-                               return _os.MachineName;\r
-                       }\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 static string NewLine\r
-               {\r
-                       get\r
-                       {\r
-                               return _os.NewLineSequence;\r
-                       }\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
-               public static OperatingSystem OSVersion\r
-               {\r
+               [MonoTODO]\r
+               public static OperatingSystem OSVersion {\r
                        get\r
                        {\r
-                               return _os.OSVersion;\r
+                               return null;\r
                        }\r
                }\r
 \r
                /// <summary>\r
                /// Get StackTrace\r
                /// </summary>\r
+               [MonoTODO]\r
                public static string StackTrace\r
                {\r
                        get\r
@@ -160,6 +157,7 @@ namespace System
                /// <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
@@ -172,6 +170,7 @@ namespace System
                /// <summary>\r
                /// Get UserDomainName\r
                /// </summary>\r
+               [MonoTODO]\r
                public static string UserDomainName\r
                {\r
                        get\r
@@ -183,6 +182,7 @@ namespace System
                /// <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
@@ -194,7 +194,7 @@ namespace System
                /// <summary>\r
                /// Get the user name of current process is running under\r
                /// </summary>\r
-               [TODO]\r
+               [MonoTODO]\r
                public static string UserName\r
                {\r
                        get\r
@@ -212,6 +212,7 @@ namespace System
                /// <summary>\r
                /// Get the version of an assembly\r
                /// </summary>\r
+               [MonoTODO]\r
                public static Version Version\r
                {\r
                        get\r
@@ -223,6 +224,7 @@ namespace System
                /// <summary>\r
                /// Get the amount of physical memory mapped to process\r
                /// </summary>\r
+               [MonoTODO]\r
                public static long WorkingSet\r
                {\r
                        get\r
@@ -231,13 +233,13 @@ namespace System
                        }\r
                }\r
 \r
-               public static void Exit(int exitCode)\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
@@ -246,21 +248,15 @@ namespace System
                /// <summary>\r
                /// Return an array of the command line arguments of the current process\r
                /// </summary>\r
-               public static string[] GetCommandLineArgs()\r
-               {\r
-                       char[] delimiter = new char[1];\r
-                       delimiter[0] = ' ';\r
-                       return _os.CommandLine.Split(delimiter);\r
-               }\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
-               public static string GetEnvironmentVariable(string variable)\r
-               {\r
-                       return _os.GetEnvironmentVariable(variable);\r
-               }\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
@@ -268,13 +264,18 @@ namespace System
           \r
                public static IDictionary GetEnvironmentVariables()\r
                {\r
-                       return _os.EnvironmentVariables;\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
@@ -283,10 +284,16 @@ namespace System
                /// <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