* Changes which are already detected at runtime, like the addition
* of icalls, do not require an increment.
*/
- private const int mono_corlib_version = 43;
-
+ private const int mono_corlib_version = 54;
+
[MonoTODO]
public enum SpecialFolder
{ // TODO: Determine if these windoze style folder identifiers
public static string StackTrace {
[EnvironmentPermission (SecurityAction.Demand, Unrestricted=true)]
get {
- System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace (1);
+ System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace (1, true);
return trace.ToString ();
}
}
/// </summary>
public static Version Version {
get {
- return new Version (Consts.RuntimeVersion);
+ return new Version (Consts.FxFileVersion);
}
}
#if NET_2_0
- [MonoTODO ("Machine and User targets aren't supported")]
public static string GetEnvironmentVariable (string variable, EnvironmentVariableTarget target)
{
switch (target) {
return GetEnvironmentVariable (variable);
case EnvironmentVariableTarget.Machine:
new EnvironmentPermission (PermissionState.Unrestricted).Demand ();
- // under Windows this reads the LOCAL_MACHINE registry key for env vars
- throw new NotImplementedException ();
+ if (!IsRunningOnWindows)
+ return null;
+ using (Microsoft.Win32.RegistryKey env = Microsoft.Win32.Registry.LocalMachine.OpenSubKey (@"SYSTEM\CurrentControlSet\Control\Session Manager\Environment")) {
+ return env.GetValue (variable).ToString ();
+ }
case EnvironmentVariableTarget.User:
new EnvironmentPermission (PermissionState.Unrestricted).Demand ();
- // under Windows this reads the CURRENT_USER registry key for env vars
- throw new NotImplementedException ();
+ if (!IsRunningOnWindows)
+ return null;
+ using (Microsoft.Win32.RegistryKey env = Microsoft.Win32.Registry.CurrentUser.OpenSubKey ("Environment", false)) {
+ return env.GetValue (variable).ToString ();
+ }
default:
throw new ArgumentException ("target");
}
}
- [MonoTODO ("Machine and User targets aren't supported")]
public static IDictionary GetEnvironmentVariables (EnvironmentVariableTarget target)
{
+ IDictionary variables = (IDictionary)new Hashtable ();
switch (target) {
case EnvironmentVariableTarget.Process:
- return GetEnvironmentVariables ();
+ variables = GetEnvironmentVariables ();
+ break;
case EnvironmentVariableTarget.Machine:
new EnvironmentPermission (PermissionState.Unrestricted).Demand ();
- // under Windows this reads the LOCAL_MACHINE registry key for env vars
- throw new NotImplementedException ();
+ if (IsRunningOnWindows) {
+ using (Microsoft.Win32.RegistryKey env = Microsoft.Win32.Registry.LocalMachine.OpenSubKey (@"SYSTEM\CurrentControlSet\Control\Session Manager\Environment")) {
+ string[] value_names = env.GetValueNames ();
+ foreach (string value_name in value_names)
+ variables.Add (value_name, env.GetValue (value_name));
+ }
+ }
+ break;
case EnvironmentVariableTarget.User:
new EnvironmentPermission (PermissionState.Unrestricted).Demand ();
- // under Windows this reads the CURRENT_USER registry key for env vars
- throw new NotImplementedException ();
+ if (IsRunningOnWindows) {
+ using (Microsoft.Win32.RegistryKey env = Microsoft.Win32.Registry.CurrentUser.OpenSubKey ("Environment")) {
+ string[] value_names = env.GetValueNames ();
+ foreach (string value_name in value_names)
+ variables.Add (value_name, env.GetValue (value_name));
+ }
+ }
+ break;
default:
throw new ArgumentException ("target");
}
+ return variables;
}
- [MonoTODO]
[EnvironmentPermission (SecurityAction.Demand, Unrestricted=true)]
public static void SetEnvironmentVariable (string variable, string value)
{
- InternalSetEnvironmentVariable (variable, value);
+ SetEnvironmentVariable (variable, value, EnvironmentVariableTarget.Process);
}
- [MonoTODO]
- [EnvironmentPermission (SecurityAction.Demand, Unrestricted=true)]
+ [EnvironmentPermission (SecurityAction.Demand, Unrestricted = true)]
public static void SetEnvironmentVariable (string variable, string value, EnvironmentVariableTarget target)
{
+ if (variable == null)
+ throw new ArgumentNullException ("variable");
+ if (variable == String.Empty)
+ throw new ArgumentException ("String cannot be of zero length.", "variable");
+ if (variable.IndexOf ('=') != -1)
+ throw new ArgumentException ("Environment variable name cannot contain an equal character.", "variable");
+ if (variable[0] == '\0')
+ throw new ArgumentException ("The first char in the string is the null character.", "variable");
+
switch (target) {
case EnvironmentVariableTarget.Process:
InternalSetEnvironmentVariable (variable, value);
break;
case EnvironmentVariableTarget.Machine:
- // under Windows this reads the LOCAL_MACHINE registry key for env vars
- throw new NotImplementedException ();
+ if (!IsRunningOnWindows)
+ return;
+ using (Microsoft.Win32.RegistryKey env = Microsoft.Win32.Registry.LocalMachine.OpenSubKey (@"SYSTEM\CurrentControlSet\Control\Session Manager\Environment", true)) {
+ if (value == null || value.Length == 0)
+ env.DeleteValue (variable, false);
+ else
+ env.SetValue (variable, value);
+ }
+ break;
case EnvironmentVariableTarget.User:
- // under Windows this reads the CURRENT_USER registry key for env vars
- throw new NotImplementedException ();
+ if (!IsRunningOnWindows)
+ return;
+ using (Microsoft.Win32.RegistryKey env = Microsoft.Win32.Registry.CurrentUser.OpenSubKey ("Environment", true)) {
+ if (value == null || value.Length == 0)
+ env.DeleteValue (variable, false);
+ else
+ env.SetValue (variable, value);
+ }
+ break;
default:
throw new ArgumentException ("target");
}
}
- // FIXME: to be changed as an icall when implemented
- internal static void InternalSetEnvironmentVariable (string variable, string value)
- {
- throw new NotImplementedException ();
- }
+ [MethodImplAttribute (MethodImplOptions.InternalCall)]
+ internal static extern void InternalSetEnvironmentVariable (string variable, string value);
[MonoTODO]
public static int ProcessorCount {
{
throw new NotImplementedException ();
}
-#endif
-
+#endif
+
// private methods
internal static bool IsRunningOnWindows {