New tests.
[mono.git] / mcs / class / corlib / System / Environment.cs
index 7dd1a3c3bc1549fbcadb1b16faa4c8065035de55..91e02d48e58781e6b323b30f1a0728e30f38fe79 100644 (file)
@@ -42,18 +42,9 @@ using System.Runtime.InteropServices;
 
 namespace System {
 
-#if NET_2_0
        [ComVisible (true)]
-#endif
-#if NET_2_0
        public static class Environment {
-#else
-       public sealed class Environment {
 
-               private Environment ()
-               {
-               }
-#endif
                /*
                 * This is the version number of the corlib-runtime interface. When
                 * making changes to this interface (by changing the layout
@@ -63,21 +54,16 @@ namespace System {
                 * Changes which are already detected at runtime, like the addition
                 * of icalls, do not require an increment.
                 */
-               private const int mono_corlib_version = 74;
+#pragma warning disable 169
+               private const int mono_corlib_version = 90;
+#pragma warning restore 169
 
-#if NET_2_0
                [ComVisible (true)]
-#endif
                public enum SpecialFolder
-               {       // TODO: Determine if these windoze style folder identifiers 
-                       //       have unix/linux counterparts
-#if NET_2_0
+               {       
                        MyDocuments = 0x05,
-#endif
-#if NET_1_1
                        Desktop = 0x00,
                        MyComputer = 0x11,
-#endif
                        Programs = 0x02,
                        Personal = 0x05,
                        Favorites = 0x06,
@@ -98,6 +84,43 @@ namespace System {
                        ProgramFiles = 0x26,
                        MyPictures = 0x27,
                        CommonProgramFiles = 0x2b,
+#if NET_4_0 || MOONLIGHT
+                       MyVideos = 0x0e,
+#endif
+#if NET_4_0
+                       NetworkShortcuts = 0x13,
+                       Fonts = 0x14,
+                       CommonStartMenu = 0x16,
+                       CommonPrograms = 0x17,
+                       CommonStartup = 0x18,
+                       CommonDesktopDirectory = 0x19,
+                       PrinterShortcuts = 0x1b,
+                       Windows = 0x24,
+                       UserProfile = 0x28,
+                       SystemX86 = 0x29,
+                       ProgramFilesX86 = 0x2a,
+                       CommonProgramFilesX86 = 0x2c,
+                       CommonTemplates = 0x2d,
+                       CommonDocuments = 0x2e,
+                       CommonAdminTools = 0x2f,
+                       AdminTools = 0x30,
+                       CommonMusic = 0x35,
+                       CommonPictures = 0x36,
+                       CommonVideos = 0x37,
+                       Resources = 0x38,
+                       LocalizedResources = 0x39,
+                       CommonOemLinks = 0x3a,
+                       CDBurning = 0x3b,
+#endif
+               }
+
+#if NET_4_0
+               public
+#endif
+               enum SpecialFolderOption {
+                       None = 0,
+                       DoNotVerify = 0x4000,
+                       Create = 0x8000
                }
 
                /// <summary>
@@ -138,10 +161,7 @@ namespace System {
                        set;
                }
 
-#if NET_1_1
-               static
-#endif
-               public extern bool HasShutdownStarted
+               static public extern bool HasShutdownStarted
                {
                        [MethodImplAttribute (MethodImplOptions.InternalCall)]
                        get;
@@ -203,7 +223,7 @@ namespace System {
                                return trace.ToString ();
                        }
                }
-
+#if !NET_2_1
                /// <summary>
                /// Get a fully qualified path to the system directory
                /// </summary>
@@ -212,7 +232,7 @@ namespace System {
                                return GetFolderPath (SpecialFolder.System);
                        }
                }
-
+#endif
                /// <summary>
                /// Get the number of milliseconds that have elapsed since the system was booted
                /// </summary>
@@ -355,9 +375,11 @@ namespace System {
                /// </summary>
                public static string GetEnvironmentVariable (string variable)
                {
+#if !NET_2_1
                        if (SecurityManager.SecurityEnabled) {
                                new EnvironmentPermission (EnvironmentPermissionAccess.Read, variable).Demand ();
                        }
+#endif
                        return internalGetEnvironmentVariable (variable);
                }
 
@@ -376,7 +398,7 @@ namespace System {
                /// <summary>
                /// Return a set of all environment variables and their values
                /// </summary>
-#if NET_2_0
+#if !NET_2_1
                public static IDictionary GetEnvironmentVariables ()
                {
                        StringBuilder sb = null;
@@ -422,6 +444,16 @@ namespace System {
                /// </summary>
                public static string GetFolderPath (SpecialFolder folder)
                {
+                       return GetFolderPath (folder, SpecialFolderOption.None);
+               }
+#if NET_4_0
+               [MonoTODO ("Figure out the folder path for all the new values in SpecialFolder. Use the 'option' argument.")]
+               public
+#endif
+               static string GetFolderPath(SpecialFolder folder, SpecialFolderOption option)
+               {
+                       SecurityManager.EnsureElevatedPermissions (); // this is a no-op outside moonlight
+
                        string dir = null;
 
                        if (Environment.IsRunningOnWindows) {
@@ -429,10 +461,11 @@ namespace System {
                        } else {
                                dir = InternalGetFolderPath (folder);
                        }
-
+#if !NET_2_1
                        if ((dir != null) && (dir.Length > 0) && SecurityManager.SecurityEnabled) {
                                new FileIOPermission (FileIOPermissionAccess.PathDiscovery, dir).Demand ();
                        }
+#endif
                        return dir;
                }
 
@@ -500,23 +533,24 @@ namespace System {
                        }
 
                        switch (folder) {
-#if NET_1_1
                        // MyComputer is a virtual directory
                        case SpecialFolder.MyComputer:
                                return String.Empty;
-#endif
+
                        // personal == ~
                        case SpecialFolder.Personal:
+#if MONOTOUCH
+                               return Path.Combine (home, "Documents");
+#else
                                return home;
+#endif
                        // use FDO's CONFIG_HOME. This data will be synced across a network like the windows counterpart.
                        case SpecialFolder.ApplicationData:
                                return config;
                        //use FDO's DATA_HOME. This is *NOT* synced
                        case SpecialFolder.LocalApplicationData:
                                return data;
-#if NET_1_1
                        case SpecialFolder.Desktop:
-#endif
                        case SpecialFolder.DesktopDirectory:
                                return ReadXdgUserDir (config, home, "XDG_DESKTOP_DIR", "Desktop");
 
@@ -557,7 +591,7 @@ namespace System {
                        return GetLogicalDrivesInternal ();
                }
 
-#if NET_2_0
+#if !NET_2_1
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                private static extern void internalBroadcastSettingChange ();
 
@@ -671,27 +705,47 @@ namespace System {
 
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                internal static extern void InternalSetEnvironmentVariable (string variable, string value);
-
-               public static extern int ProcessorCount {
-                       [EnvironmentPermission (SecurityAction.Demand, Read="NUMBER_OF_PROCESSORS")]
-                       [MethodImplAttribute (MethodImplOptions.InternalCall)]
-                       get;                    
-               }
-
-               [MonoTODO ("Not implemented")]
+#endif
                [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode=true)]
                public static void FailFast (string message)
                {
                        throw new NotImplementedException ();
                }
+
+#if NET_4_0 || MOONLIGHT
+               [SecurityCritical]
+               public static void FailFast (string message, Exception exception)
+               {
+                       throw new NotImplementedException ();
+               }
 #endif
 
+#if NET_4_0
+               public static bool Is64BitOperatingSystem {
+                       get { return IntPtr.Size == 8; } // FIXME: is this good enough?
+               }
+
+               public static bool Is64BitProcess {
+                       get { return Is64BitOperatingSystem; }
+               }
+
+               public static int SystemPageSize {
+                       get { return GetPageSize (); }
+               }
+#endif
+
+               public static extern int ProcessorCount {
+                       [EnvironmentPermission (SecurityAction.Demand, Read="NUMBER_OF_PROCESSORS")]
+                       [MethodImplAttribute (MethodImplOptions.InternalCall)]
+                       get;                    
+               }
+
                // private methods
 
                internal static bool IsRunningOnWindows {
                        get { return ((int) Platform < 4); }
                }
-
+#if !NET_2_1
                //
                // Used by gacutil.exe
                //
@@ -708,7 +762,9 @@ namespace System {
                        }
                }
 #pragma warning restore 169
-
+               [MethodImplAttribute (MethodImplOptions.InternalCall)]
+               internal extern static string internalGetGacPath ();
+#endif
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                private extern static string [] GetLogicalDrivesInternal ();
 
@@ -719,10 +775,18 @@ namespace System {
                internal extern static string GetMachineConfigPath ();
 
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
-               internal extern static string internalGetGacPath ();
+               internal extern static string internalGetHome ();
 
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
-               internal extern static string internalGetHome ();
+               internal extern static int GetPageSize ();
+
+               static internal bool IsUnix {
+                       get {
+                               int platform = (int) Environment.Platform;
+
+                               return (platform == 4 || platform == 128 || platform == 6);
+                       }
+               }
        }
 }