MonoGenericClass::initialize runtime icall only needs fields.
[mono.git] / mcs / class / corlib / System / Environment.cs
index 5007762b951af4b97d04f9bc2810dba8e69e50c6..496fdc7c46b7ff7a885ab64a196accb25dfdec12 100644 (file)
@@ -39,6 +39,7 @@ using System.Security;
 using System.Security.Permissions;
 using System.Text;
 using System.Runtime.InteropServices;
+using System.Threading;
 
 namespace System {
 
@@ -55,7 +56,7 @@ namespace System {
                 * of icalls, do not require an increment.
                 */
 #pragma warning disable 169
-               private const int mono_corlib_version = 94;
+               private const int mono_corlib_version = 104;
 #pragma warning restore 169
 
                [ComVisible (true)]
@@ -84,7 +85,7 @@ namespace System {
                        ProgramFiles = 0x26,
                        MyPictures = 0x27,
                        CommonProgramFiles = 0x2b,
-#if NET_4_0 || MOONLIGHT
+#if NET_4_0 || MOONLIGHT || MOBILE
                        MyVideos = 0x0e,
 #endif
 #if NET_4_0
@@ -168,6 +169,14 @@ namespace System {
                                Directory.SetCurrentDirectory (value);
                        }
                }
+               
+#if NET_4_5
+               public static int CurrentManagedThreadId {
+                       get {
+                               return Thread.CurrentThread.ManagedThreadId;
+                       }
+               }
+#endif
 
                /// <summary>
                /// Gets or sets the exit code of this process
@@ -197,12 +206,21 @@ namespace System {
                        get;
                }
 
+               [MethodImplAttribute (MethodImplOptions.InternalCall)]
+               extern static string GetNewLine ();
+
+               static string nl;
                /// <summary>
                /// Gets the standard new line value
                /// </summary>
-               public extern static string NewLine {
-                       [MethodImplAttribute (MethodImplOptions.InternalCall)]
-                       get;
+               public static string NewLine {
+                       get {
+                               if (nl != null)
+                                       return nl;
+
+                               nl = GetNewLine ();
+                               return nl;
+                       }
                }
 
                //
@@ -348,6 +366,7 @@ namespace System {
                                // If value not found, add %FOO to stream,
                                //  and use the closing % for the next iteration.
                                // If value found, expand it in place of %FOO%
+                               int realOldOff2 = off2;
                                if (value == null) {
                                        result.Append ('%');
                                        result.Append (var);
@@ -371,7 +390,7 @@ namespace System {
                                // If value not found in current iteration, but a % was found for next iteration,
                                //  use text from current closing % to the next %.
                                else
-                                       textLen = off1 - oldOff2;
+                                       textLen = off1 - realOldOff2;
                                if(off1 >= oldOff2 || off1 == -1)
                                        result.Append (name, oldOff2+1, textLen);
                        } while (off2 > -1 && off2 < len);
@@ -468,7 +487,6 @@ namespace System {
                        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)
@@ -597,14 +615,20 @@ namespace System {
                                return ReadXdgUserDir (config, home, "XDG_DESKTOP_DIR", "Desktop");
 
                        case SpecialFolder.MyMusic:
-                               return ReadXdgUserDir (config, home, "XDG_MUSIC_DIR", "Music");
+                               if (Platform == PlatformID.MacOSX)
+                                       return Path.Combine (home, "Music");
+                               else
+                                       return ReadXdgUserDir (config, home, "XDG_MUSIC_DIR", "Music");
 
                        case SpecialFolder.MyPictures:
-                               return ReadXdgUserDir (config, home, "XDG_PICTURES_DIR", "Pictures");
+                               if (Platform == PlatformID.MacOSX)
+                                       return Path.Combine (home, "Pictures");
+                               else
+                                       return ReadXdgUserDir (config, home, "XDG_PICTURES_DIR", "Pictures");
                        
                        case SpecialFolder.Templates:
                                return ReadXdgUserDir (config, home, "XDG_TEMPLATES_DIR", "Templates");
-#if NET_4_0 || MOONLIGHT
+#if NET_4_0 || MOONLIGHT || MOBILE
                        case SpecialFolder.MyVideos:
                                return ReadXdgUserDir (config, home, "XDG_VIDEOS_DIR", "Videos");
 #endif
@@ -612,22 +636,46 @@ namespace System {
                        case SpecialFolder.CommonTemplates:
                                return "/usr/share/templates";
                        case SpecialFolder.Fonts:
+                               if (Platform == PlatformID.MacOSX)
+                                       return Path.Combine (home, "Library", "Fonts");
+                               
                                return Path.Combine (home, ".fonts");
 #endif
                        // these simply dont exist on Linux
                        // The spec says if a folder doesnt exist, we
                        // should return ""
                        case SpecialFolder.Favorites:
+                               if (Platform == PlatformID.MacOSX)
+                                       return Path.Combine (home, "Library", "Favorites");
+                               else
+                                       return String.Empty;
+                               
+                       case SpecialFolder.ProgramFiles:
+                               if (Platform == PlatformID.MacOSX)
+                                       return "/Applications";
+                               else
+                                       return String.Empty;
+
+                       case SpecialFolder.InternetCache:
+                               if (Platform == PlatformID.MacOSX)
+                                       return Path.Combine (home, "Library", "Caches");
+                               else
+                                       return String.Empty;
+
+#if NET_4_0
+                               // #2873
+                       case SpecialFolder.UserProfile:
+                               return home;
+#endif
+
                        case SpecialFolder.Programs:
                        case SpecialFolder.SendTo:
                        case SpecialFolder.StartMenu:
                        case SpecialFolder.Startup:
                        case SpecialFolder.Cookies:
                        case SpecialFolder.History:
-                       case SpecialFolder.InternetCache:
                        case SpecialFolder.Recent:
                        case SpecialFolder.CommonProgramFiles:
-                       case SpecialFolder.ProgramFiles:
                        case SpecialFolder.System:
 #if NET_4_0
                        case SpecialFolder.NetworkShortcuts:
@@ -637,7 +685,6 @@ namespace System {
                        case SpecialFolder.CommonDesktopDirectory:
                        case SpecialFolder.PrinterShortcuts:
                        case SpecialFolder.Windows:
-                       case SpecialFolder.UserProfile:
                        case SpecialFolder.SystemX86:
                        case SpecialFolder.ProgramFilesX86:
                        case SpecialFolder.CommonProgramFilesX86:
@@ -789,7 +836,7 @@ namespace System {
                        throw new NotImplementedException ();
                }
 
-#if NET_4_0 || MOONLIGHT
+#if NET_4_0 || MOONLIGHT || MOBILE
                [SecurityCritical]
                public static void FailFast (string message, Exception exception)
                {
@@ -864,6 +911,11 @@ namespace System {
                                return (platform == 4 || platform == 128 || platform == 6);
                        }
                }
+               static internal bool IsMacOS {
+                       get {
+                               return Environment.Platform == PlatformID.MacOSX;
+                       }
+               }
        }
 }