Files
2026-06-04 11:42:34 +02:00

925 lines
42 KiB
C#

using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Text;
using Microsoft.Win32;
namespace System
{
/// <summary>Provides information about, and means to manipulate, the current environment and platform. This class cannot be inherited.</summary>
/// <filterpriority>1</filterpriority>
// Token: 0x02000666 RID: 1638
[ComVisible(true)]
public static class Environment
{
/// <summary>Gets the command line for this process.</summary>
/// <returns>A string containing command-line arguments.</returns>
/// <filterpriority>1</filterpriority>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Read="Path" />
/// </PermissionSet>
// Token: 0x17000B8B RID: 2955
// (get) Token: 0x06003E26 RID: 15910 RVA: 0x000D3730 File Offset: 0x000D1930
public static string CommandLine
{
get
{
return string.Join(" ", Environment.GetCommandLineArgs());
}
}
/// <summary>Gets or sets the fully qualified path of the current working directory.</summary>
/// <returns>A string containing a directory path. </returns>
/// <exception cref="T:System.ArgumentException">Attempted to set to an empty string (""). </exception>
/// <exception cref="T:System.ArgumentNullException">Attempted to set to null. </exception>
/// <exception cref="T:System.IO.IOException">An I/O error occurred. </exception>
/// <exception cref="T:System.IO.DirectoryNotFoundException">Attempted to set a local path that cannot be found. </exception>
/// <exception cref="T:System.Security.SecurityException">The caller does not have the appropriate permission. </exception>
/// <filterpriority>1</filterpriority>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
/// </PermissionSet>
// Token: 0x17000B8C RID: 2956
// (get) Token: 0x06003E27 RID: 15911 RVA: 0x000D3744 File Offset: 0x000D1944
// (set) Token: 0x06003E28 RID: 15912 RVA: 0x000D374C File Offset: 0x000D194C
public static string CurrentDirectory
{
get
{
return Directory.GetCurrentDirectory();
}
set
{
Directory.SetCurrentDirectory(value);
}
}
/// <summary>Gets or sets the exit code of the process.</summary>
/// <returns>A 32-bit signed integer containing the exit code. The default value is zero.</returns>
/// <filterpriority>1</filterpriority>
// Token: 0x17000B8D RID: 2957
// (get) Token: 0x06003E29 RID: 15913
// (set) Token: 0x06003E2A RID: 15914
public static extern int ExitCode
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
[MethodImpl(MethodImplOptions.InternalCall)]
set;
}
/// <summary>Gets a value indicating whether the common language runtime is shutting down or the current application domain is unloading.</summary>
/// <returns>true if the common language runtime is shutting down or the current <see cref="T:System.AppDomain" /> is unloading; otherwise, false.The current application domain is the <see cref="T:System.AppDomain" /> that contains the object that is calling <see cref="P:System.Environment.HasShutdownStarted" />.</returns>
/// <filterpriority>1</filterpriority>
// Token: 0x17000B8E RID: 2958
// (get) Token: 0x06003E2B RID: 15915
public static extern bool HasShutdownStarted
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
}
// Token: 0x17000B8F RID: 2959
// (get) Token: 0x06003E2C RID: 15916
public static extern string EmbeddingHostName
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
}
// Token: 0x17000B90 RID: 2960
// (get) Token: 0x06003E2D RID: 15917
public static extern bool SocketSecurityEnabled
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
}
// Token: 0x17000B91 RID: 2961
// (get) Token: 0x06003E2E RID: 15918 RVA: 0x000D3754 File Offset: 0x000D1954
public static bool UnityWebSecurityEnabled
{
get
{
return Environment.SocketSecurityEnabled;
}
}
/// <summary>Gets the NetBIOS name of this local computer.</summary>
/// <returns>A string containing the name of this computer.</returns>
/// <exception cref="T:System.InvalidOperationException">The name of this computer cannot be obtained. </exception>
/// <filterpriority>1</filterpriority>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Read="COMPUTERNAME" />
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
/// </PermissionSet>
// Token: 0x17000B92 RID: 2962
// (get) Token: 0x06003E2F RID: 15919
public static extern string MachineName
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
}
/// <summary>Gets the newline string defined for this environment.</summary>
/// <returns>A string containing "\r\n" for non-Unix platforms, or a string containing "\n" for Unix platforms.</returns>
/// <filterpriority>1</filterpriority>
// Token: 0x17000B93 RID: 2963
// (get) Token: 0x06003E30 RID: 15920
public static extern string NewLine
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
}
// Token: 0x17000B94 RID: 2964
// (get) Token: 0x06003E31 RID: 15921
internal static extern PlatformID Platform
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
}
// Token: 0x06003E32 RID: 15922
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern string GetOSVersionString();
/// <summary>Gets an <see cref="T:System.OperatingSystem" /> object that contains the current platform identifier and version number.</summary>
/// <returns>An <see cref="T:System.OperatingSystem" /> object.</returns>
/// <exception cref="T:System.InvalidOperationException">This property was unable to obtain the system version.-or- The obtained platform identifier is not a member of <see cref="T:System.PlatformID" />. </exception>
/// <filterpriority>1</filterpriority>
// Token: 0x17000B95 RID: 2965
// (get) Token: 0x06003E33 RID: 15923 RVA: 0x000D375C File Offset: 0x000D195C
public static OperatingSystem OSVersion
{
get
{
if (Environment.os == null)
{
Version version = Version.CreateFromString(Environment.GetOSVersionString());
PlatformID platform = Environment.Platform;
Environment.os = new OperatingSystem(platform, version);
}
return Environment.os;
}
}
/// <summary>Gets current stack trace information.</summary>
/// <returns>A string containing stack trace information. This value can be <see cref="F:System.String.Empty" />.</returns>
/// <exception cref="T:System.ArgumentOutOfRangeException">The requested stack trace information is out of range. </exception>
/// <filterpriority>1</filterpriority>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" PathDiscovery="*AllFiles*" />
/// </PermissionSet>
// Token: 0x17000B96 RID: 2966
// (get) Token: 0x06003E34 RID: 15924 RVA: 0x000D3798 File Offset: 0x000D1998
public static string StackTrace
{
get
{
StackTrace stackTrace = new StackTrace(0, true);
return stackTrace.ToString();
}
}
/// <summary>Gets the number of milliseconds elapsed since the system started.</summary>
/// <returns>A 32-bit signed integer containing the amount of time in milliseconds that has passed since the last time the computer was started.</returns>
/// <filterpriority>1</filterpriority>
// Token: 0x17000B97 RID: 2967
// (get) Token: 0x06003E35 RID: 15925
public static extern int TickCount
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
}
/// <summary>Gets the network domain name associated with the current user.</summary>
/// <returns>The network domain name associated with the current user.</returns>
/// <exception cref="T:System.PlatformNotSupportedException">The operating system does not support retrieving the network domain name. </exception>
/// <exception cref="T:System.InvalidOperationException">The network domain name cannot be retrieved. </exception>
/// <filterpriority>1</filterpriority>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Read="UserName;UserDomainName" />
/// </PermissionSet>
// Token: 0x17000B98 RID: 2968
// (get) Token: 0x06003E36 RID: 15926 RVA: 0x000D37B4 File Offset: 0x000D19B4
public static string UserDomainName
{
get
{
return Environment.MachineName;
}
}
/// <summary>Gets a value indicating whether the current process is running in user interactive mode.</summary>
/// <returns>true if the current process is running in user interactive mode; otherwise, false.</returns>
/// <filterpriority>1</filterpriority>
// Token: 0x17000B99 RID: 2969
// (get) Token: 0x06003E37 RID: 15927 RVA: 0x000D37BC File Offset: 0x000D19BC
[MonoTODO("Currently always returns false, regardless of interactive state")]
public static bool UserInteractive
{
get
{
return false;
}
}
/// <summary>Gets the user name of the person who is currently logged on to the Windows operating system.</summary>
/// <returns>The user name of the person who is logged on to Windows.</returns>
/// <filterpriority>1</filterpriority>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Read="UserName" />
/// </PermissionSet>
// Token: 0x17000B9A RID: 2970
// (get) Token: 0x06003E38 RID: 15928
public static extern string UserName
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
}
/// <summary>Gets a <see cref="T:System.Version" /> object that describes the major, minor, build, and revision numbers of the common language runtime.</summary>
/// <returns>A <see cref="T:System.Version" /> object.</returns>
/// <filterpriority>1</filterpriority>
// Token: 0x17000B9B RID: 2971
// (get) Token: 0x06003E39 RID: 15929 RVA: 0x000D37C0 File Offset: 0x000D19C0
public static Version Version
{
get
{
return new Version("2.0.50727.1433");
}
}
/// <summary>Gets the amount of physical memory mapped to the process context.</summary>
/// <returns>A 64-bit signed integer containing the number of bytes of physical memory mapped to the process context.</returns>
/// <filterpriority>1</filterpriority>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// </PermissionSet>
// Token: 0x17000B9C RID: 2972
// (get) Token: 0x06003E3A RID: 15930 RVA: 0x000D37CC File Offset: 0x000D19CC
[MonoTODO("Currently always returns zero")]
public static long WorkingSet
{
get
{
return 0L;
}
}
/// <summary>Terminates this process and gives the underlying operating system the specified exit code.</summary>
/// <param name="exitCode">Exit code to be given to the operating system. </param>
/// <exception cref="T:System.Security.SecurityException">The caller does not have sufficient security permission to perform this function. </exception>
/// <filterpriority>1</filterpriority>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
/// </PermissionSet>
// Token: 0x06003E3B RID: 15931
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern void Exit(int exitCode);
/// <summary>Replaces the name of each environment variable embedded in the specified string with the string equivalent of the value of the variable, then returns the resulting string.</summary>
/// <returns>A string with each environment variable replaced by its value.</returns>
/// <param name="name">A string containing the names of zero or more environment variables. Each environment variable is quoted with the percent sign character (%). </param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="name" /> is null. </exception>
/// <filterpriority>1</filterpriority>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// </PermissionSet>
// Token: 0x06003E3C RID: 15932 RVA: 0x000D37D0 File Offset: 0x000D19D0
public static string ExpandEnvironmentVariables(string name)
{
if (name == null)
{
throw new ArgumentNullException("name");
}
int num = name.IndexOf('%');
if (num == -1)
{
return name;
}
int length = name.Length;
int num2;
if (num == length - 1 || (num2 = name.IndexOf('%', num + 1)) == -1)
{
return name;
}
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append(name, 0, num);
Hashtable hashtable = null;
do
{
string text = name.Substring(num + 1, num2 - num - 1);
string text2 = Environment.GetEnvironmentVariable(text);
if (text2 == null && Environment.IsRunningOnWindows)
{
if (hashtable == null)
{
hashtable = Environment.GetEnvironmentVariablesNoCase();
}
text2 = hashtable[text] as string;
}
if (text2 == null)
{
stringBuilder.Append('%');
stringBuilder.Append(text);
num2--;
}
else
{
stringBuilder.Append(text2);
}
int num3 = num2;
num = name.IndexOf('%', num2 + 1);
num2 = ((num != -1 && num2 <= length - 1) ? name.IndexOf('%', num + 1) : (-1));
int num4;
if (num == -1 || num2 == -1)
{
num4 = length - num3 - 1;
}
else if (text2 != null)
{
num4 = num - num3 - 1;
}
else
{
num4 = num - num3;
}
if (num >= num3 || num == -1)
{
stringBuilder.Append(name, num3 + 1, num4);
}
}
while (num2 > -1 && num2 < length);
return stringBuilder.ToString();
}
/// <summary>Returns a string array containing the command-line arguments for the current process.</summary>
/// <returns>An array of string where each element contains a command-line argument. The first element is the executable file name, and the following zero or more elements contain the remaining command-line arguments.</returns>
/// <exception cref="T:System.NotSupportedException">The system does not support command-line arguments. </exception>
/// <filterpriority>1</filterpriority>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Read="Path" />
/// </PermissionSet>
// Token: 0x06003E3D RID: 15933
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern string[] GetCommandLineArgs();
// Token: 0x06003E3E RID: 15934
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern string internalGetEnvironmentVariable(string variable);
/// <summary>Retrieves the value of an environment variable from the current process.</summary>
/// <returns>The value of the environment variable specified by <paramref name="variable" />, or null if the environment variable is not found.</returns>
/// <param name="variable">The name of the environment variable. </param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="variable" /> is null. </exception>
/// <exception cref="T:System.Security.SecurityException">The caller does not have the required permission to perform this operation.</exception>
/// <filterpriority>1</filterpriority>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// </PermissionSet>
// Token: 0x06003E3F RID: 15935 RVA: 0x000D3944 File Offset: 0x000D1B44
public static string GetEnvironmentVariable(string variable)
{
return Environment.internalGetEnvironmentVariable(variable);
}
// Token: 0x06003E40 RID: 15936 RVA: 0x000D394C File Offset: 0x000D1B4C
private static Hashtable GetEnvironmentVariablesNoCase()
{
Hashtable hashtable = new Hashtable(CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default);
foreach (string text in Environment.GetEnvironmentVariableNames())
{
hashtable[text] = Environment.internalGetEnvironmentVariable(text);
}
return hashtable;
}
/// <summary>Retrieves all environment variable names and their values from the current process.</summary>
/// <returns>An <see cref="T:System.Collections.IDictionary" /> that contains all environment variable names and their values; otherwise, an empty dictionary if no environment variables are found.</returns>
/// <exception cref="T:System.Security.SecurityException">The caller does not have the required permission to perform this operation.</exception>
/// <exception cref="T:System.OutOfMemoryException">The buffer is out of memory.</exception>
/// <filterpriority>1</filterpriority>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// </PermissionSet>
// Token: 0x06003E41 RID: 15937 RVA: 0x000D3998 File Offset: 0x000D1B98
public static IDictionary GetEnvironmentVariables()
{
Hashtable hashtable = new Hashtable();
foreach (string text in Environment.GetEnvironmentVariableNames())
{
hashtable[text] = Environment.internalGetEnvironmentVariable(text);
}
return hashtable;
}
// Token: 0x06003E42 RID: 15938
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern string GetWindowsFolderPath(int folder);
/// <summary>Gets the path to the system special folder identified by the specified enumeration.</summary>
/// <returns>The path to the specified system special folder, if that folder physically exists on your computer; otherwise, the empty string ("").A folder will not physically exist if the operating system did not create it, the existing folder was deleted, or the folder is a virtual directory, such as My Computer, which does not correspond to a physical path.</returns>
/// <param name="folder">An enumerated constant that identifies a system special folder. </param>
/// <exception cref="T:System.ArgumentException">
/// <paramref name="folder" /> is not a member of <see cref="T:System.Environment.SpecialFolder" />. </exception>
/// <exception cref="T:System.PlatformNotSupportedException">The current platform is not supported.</exception>
/// <filterpriority>1</filterpriority>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// </PermissionSet>
// Token: 0x06003E43 RID: 15939 RVA: 0x000D39D8 File Offset: 0x000D1BD8
public static string GetFolderPath(Environment.SpecialFolder folder)
{
string text;
if (Environment.IsRunningOnWindows)
{
text = Environment.GetWindowsFolderPath((int)folder);
}
else
{
text = Environment.InternalGetFolderPath(folder);
}
return text;
}
// Token: 0x06003E44 RID: 15940 RVA: 0x000D3A08 File Offset: 0x000D1C08
private static string ReadXdgUserDir(string config_dir, string home_dir, string key, string fallback)
{
string text = Environment.internalGetEnvironmentVariable(key);
if (text != null && text != string.Empty)
{
return text;
}
string text2 = Path.Combine(config_dir, "user-dirs.dirs");
if (!File.Exists(text2))
{
return Path.Combine(home_dir, fallback);
}
try
{
using (StreamReader streamReader = new StreamReader(text2))
{
string text3;
while ((text3 = streamReader.ReadLine()) != null)
{
text3 = text3.Trim();
int num = text3.IndexOf('=');
if (num > 8 && text3.Substring(0, num) == key)
{
string text4 = text3.Substring(num + 1).Trim(new char[] { '"' });
bool flag = false;
if (text4.StartsWith("$HOME/"))
{
flag = true;
text4 = text4.Substring(6);
}
else if (!text4.StartsWith("/"))
{
flag = true;
}
return (!flag) ? text4 : Path.Combine(home_dir, text4);
}
}
}
}
catch (FileNotFoundException)
{
}
return Path.Combine(home_dir, fallback);
}
// Token: 0x06003E45 RID: 15941 RVA: 0x000D3B68 File Offset: 0x000D1D68
internal static string InternalGetFolderPath(Environment.SpecialFolder folder)
{
string text = Environment.internalGetHome();
string text2 = Environment.internalGetEnvironmentVariable("XDG_DATA_HOME");
if (text2 == null || text2 == string.Empty)
{
text2 = Path.Combine(text, ".local");
text2 = Path.Combine(text2, "share");
}
string text3 = Environment.internalGetEnvironmentVariable("XDG_CONFIG_HOME");
if (text3 == null || text3 == string.Empty)
{
text3 = Path.Combine(text, ".config");
}
switch (folder)
{
case Environment.SpecialFolder.Desktop:
case Environment.SpecialFolder.DesktopDirectory:
return Environment.ReadXdgUserDir(text3, text, "XDG_DESKTOP_DIR", "Desktop");
case Environment.SpecialFolder.Programs:
case Environment.SpecialFolder.Favorites:
case Environment.SpecialFolder.Startup:
case Environment.SpecialFolder.Recent:
case Environment.SpecialFolder.SendTo:
case Environment.SpecialFolder.StartMenu:
case Environment.SpecialFolder.Templates:
case Environment.SpecialFolder.InternetCache:
case Environment.SpecialFolder.Cookies:
case Environment.SpecialFolder.History:
case Environment.SpecialFolder.System:
case Environment.SpecialFolder.ProgramFiles:
case Environment.SpecialFolder.CommonProgramFiles:
return string.Empty;
case Environment.SpecialFolder.MyDocuments:
return text;
case Environment.SpecialFolder.MyMusic:
return Environment.ReadXdgUserDir(text3, text, "XDG_MUSIC_DIR", "Music");
case Environment.SpecialFolder.MyComputer:
return string.Empty;
case Environment.SpecialFolder.ApplicationData:
return text3;
case Environment.SpecialFolder.LocalApplicationData:
return text2;
case Environment.SpecialFolder.CommonApplicationData:
return "/usr/share";
case Environment.SpecialFolder.MyPictures:
return Environment.ReadXdgUserDir(text3, text, "XDG_PICTURES_DIR", "Pictures");
}
throw new ArgumentException("Invalid SpecialFolder");
}
/// <summary>Returns an array of string containing the names of the logical drives on the current computer.</summary>
/// <returns>An array of strings where each element contains the name of a logical drive. For example, if the computer's hard drive is the first logical drive, the first element returned is "C:\".</returns>
/// <exception cref="T:System.IO.IOException">An I/O error occurs. </exception>
/// <exception cref="T:System.Security.SecurityException">The caller does not have the required permissions. </exception>
/// <filterpriority>1</filterpriority>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// </PermissionSet>
// Token: 0x06003E46 RID: 15942 RVA: 0x000D3CF8 File Offset: 0x000D1EF8
public static string[] GetLogicalDrives()
{
return Environment.GetLogicalDrivesInternal();
}
// Token: 0x06003E47 RID: 15943
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void internalBroadcastSettingChange();
/// <summary>Retrieves the value of an environment variable from the current process or from the Windows operating system registry key for the current user or local machine.</summary>
/// <returns>The value of the environment variable specified by the <paramref name="variable" /> and <paramref name="target" /> parameters, or null if the environment variable is not found.</returns>
/// <param name="variable">The name of an environment variable.</param>
/// <param name="target">One of the <see cref="T:System.EnvironmentVariableTarget" /> values.</param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="variable" /> is null.</exception>
/// <exception cref="T:System.NotSupportedException">
/// <paramref name="target" /> is <see cref="F:System.EnvironmentVariableTarget.User" /> or <see cref="F:System.EnvironmentVariableTarget.Machine" /> and the current operating system is Windows 95, Windows 98, or Windows Me.</exception>
/// <exception cref="T:System.ArgumentException">
/// <paramref name="target" /> is not a valid <see cref="T:System.EnvironmentVariableTarget" /> value.</exception>
/// <exception cref="T:System.Security.SecurityException">The caller does not have the required permission to perform this operation.</exception>
/// <filterpriority>1</filterpriority>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// <IPermission class="System.Security.Permissions.RegistryPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
/// </PermissionSet>
// Token: 0x06003E48 RID: 15944 RVA: 0x000D3D00 File Offset: 0x000D1F00
public static string GetEnvironmentVariable(string variable, EnvironmentVariableTarget target)
{
switch (target)
{
case EnvironmentVariableTarget.Process:
return Environment.GetEnvironmentVariable(variable);
case EnvironmentVariableTarget.User:
break;
case EnvironmentVariableTarget.Machine:
{
new EnvironmentPermission(PermissionState.Unrestricted).Demand();
if (!Environment.IsRunningOnWindows)
{
return null;
}
using (RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"))
{
object value = registryKey.GetValue(variable);
return (value != null) ? value.ToString() : null;
}
break;
}
default:
goto IL_D7;
}
new EnvironmentPermission(PermissionState.Unrestricted).Demand();
if (!Environment.IsRunningOnWindows)
{
return null;
}
using (RegistryKey registryKey2 = Registry.CurrentUser.OpenSubKey("Environment", false))
{
object value2 = registryKey2.GetValue(variable);
return (value2 != null) ? value2.ToString() : null;
}
IL_D7:
throw new ArgumentException("target");
}
/// <summary>Retrieves all environment variable names and their values from the current process, or from the Windows operating system registry key for the current user or local machine.</summary>
/// <returns>An <see cref="T:System.Collections.IDictionary" /> object that contains all environment variable names and their values from the source specified by the <paramref name="target" /> parameter; otherwise, an empty dictionary if no environment variables are found.</returns>
/// <param name="target">One of the <see cref="T:System.EnvironmentVariableTarget" /> values.</param>
/// <exception cref="T:System.Security.SecurityException">The caller does not have the required permission to perform this operation for the specified value of <paramref name="target" />.</exception>
/// <exception cref="T:System.NotSupportedException">This method cannot be used on Windows 95 or Windows 98 platforms.</exception>
/// <exception cref="T:System.ArgumentException">
/// <paramref name="target" /> contains an illegal value.</exception>
/// <filterpriority>1</filterpriority>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// <IPermission class="System.Security.Permissions.RegistryPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
/// </PermissionSet>
// Token: 0x06003E49 RID: 15945 RVA: 0x000D3E28 File Offset: 0x000D2028
public static IDictionary GetEnvironmentVariables(EnvironmentVariableTarget target)
{
IDictionary dictionary = new Hashtable();
switch (target)
{
case EnvironmentVariableTarget.Process:
dictionary = Environment.GetEnvironmentVariables();
break;
case EnvironmentVariableTarget.User:
new EnvironmentPermission(PermissionState.Unrestricted).Demand();
if (Environment.IsRunningOnWindows)
{
using (RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("Environment"))
{
string[] valueNames = registryKey.GetValueNames();
foreach (string text in valueNames)
{
dictionary.Add(text, registryKey.GetValue(text));
}
}
}
break;
case EnvironmentVariableTarget.Machine:
new EnvironmentPermission(PermissionState.Unrestricted).Demand();
if (Environment.IsRunningOnWindows)
{
using (RegistryKey registryKey2 = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"))
{
string[] valueNames2 = registryKey2.GetValueNames();
foreach (string text2 in valueNames2)
{
dictionary.Add(text2, registryKey2.GetValue(text2));
}
}
}
break;
default:
throw new ArgumentException("target");
}
return dictionary;
}
/// <summary>Creates, modifies, or deletes an environment variable stored in the current process.</summary>
/// <param name="variable">The name of an environment variable. </param>
/// <param name="value">A value to assign to <paramref name="variable" />. </param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="variable" /> is null.</exception>
/// <exception cref="T:System.ArgumentException">
/// <paramref name="variable" /> contains a zero-length string, an initial hexadecimal zero character (0x00), or an equal sign ("="). -or-The length of <paramref name="variable" /> or <paramref name="value" /> is greater than or equal to 32,767 characters.-or-An error occurred during the execution of this operation.</exception>
/// <exception cref="T:System.Security.SecurityException">The caller does not have the required permission to perform this operation. </exception>
/// <filterpriority>1</filterpriority>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// </PermissionSet>
// Token: 0x06003E4A RID: 15946 RVA: 0x000D3F94 File Offset: 0x000D2194
public static void SetEnvironmentVariable(string variable, string value)
{
Environment.SetEnvironmentVariable(variable, value, EnvironmentVariableTarget.Process);
}
/// <summary>Creates, modifies, or deletes an environment variable stored in the current process or in the Windows operating system registry key reserved for the current user or local machine.</summary>
/// <param name="variable">The name of an environment variable.</param>
/// <param name="value">A value to assign to <paramref name="variable" />. </param>
/// <param name="target">One of the <see cref="T:System.EnvironmentVariableTarget" /> values.</param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="variable" /> is null. </exception>
/// <exception cref="T:System.ArgumentException">
/// <paramref name="variable" /> contains a zero-length string, an initial hexadecimal zero character (0x00), or an equal sign ("="). -or-The length of <paramref name="variable" /> is greater than or equal to 32,767 characters.-or-<paramref name="target" /> is not a member of the <see cref="T:System.EnvironmentVariableTarget" /> enumeration. -or-<paramref name="target" /> is <see cref="F:System.EnvironmentVariableTarget.Machine" /> or <see cref="F:System.EnvironmentVariableTarget.User" /> and the length of <paramref name="variable" /> is greater than or equal to 255.-or-<paramref name="target" /> is <see cref="F:System.EnvironmentVariableTarget.Process" /> and the length of <paramref name="value" /> is greater than or equal to 32,767 characters. -or-An error occurred during the execution of this operation.</exception>
/// <exception cref="T:System.NotSupportedException">
/// <paramref name="target" /> is <see cref="F:System.EnvironmentVariableTarget.User" /> or <see cref="F:System.EnvironmentVariableTarget.Machine" /> and the current operating system is Windows 95, Windows 98, or Windows Me.</exception>
/// <exception cref="T:System.Security.SecurityException">The caller does not have the required permission to perform this operation. </exception>
/// <filterpriority>1</filterpriority>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// <IPermission class="System.Security.Permissions.RegistryPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
/// </PermissionSet>
// Token: 0x06003E4B RID: 15947 RVA: 0x000D3FA0 File Offset: 0x000D21A0
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:
Environment.InternalSetEnvironmentVariable(variable, value);
break;
case EnvironmentVariableTarget.User:
{
if (!Environment.IsRunningOnWindows)
{
return;
}
using (RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("Environment", true))
{
if (string.IsNullOrEmpty(value))
{
registryKey.DeleteValue(variable, false);
}
else
{
registryKey.SetValue(variable, value);
}
Environment.internalBroadcastSettingChange();
}
break;
}
case EnvironmentVariableTarget.Machine:
{
if (!Environment.IsRunningOnWindows)
{
return;
}
using (RegistryKey registryKey2 = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment", true))
{
if (string.IsNullOrEmpty(value))
{
registryKey2.DeleteValue(variable, false);
}
else
{
registryKey2.SetValue(variable, value);
}
Environment.internalBroadcastSettingChange();
}
break;
}
default:
throw new ArgumentException("target");
}
}
// Token: 0x06003E4C RID: 15948
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void InternalSetEnvironmentVariable(string variable, string value);
/// <summary>Terminates a process but does not execute any active try-finally blocks or finalizers.</summary>
/// <param name="message">A message that explains why the process was terminated, or null if no explanation is provided. </param>
// Token: 0x06003E4D RID: 15949 RVA: 0x000D412C File Offset: 0x000D232C
[MonoTODO("Not implemented")]
public static void FailFast(string message)
{
throw new NotImplementedException();
}
/// <summary>Gets the number of processors on the current machine.</summary>
/// <returns>The 32-bit signed integer that specifies the number of processors on the current machine. There is no default.</returns>
/// <filterpriority>1</filterpriority>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Read="NUMBER_OF_PROCESSORS" />
/// </PermissionSet>
// Token: 0x17000B9D RID: 2973
// (get) Token: 0x06003E4E RID: 15950
public static extern int ProcessorCount
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
}
// Token: 0x17000B9E RID: 2974
// (get) Token: 0x06003E4F RID: 15951 RVA: 0x000D4134 File Offset: 0x000D2334
internal static bool IsRunningOnWindows
{
get
{
return Environment.Platform < PlatformID.Unix;
}
}
// Token: 0x06003E50 RID: 15952
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern string[] GetLogicalDrivesInternal();
// Token: 0x06003E51 RID: 15953
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern string[] GetEnvironmentVariableNames();
// Token: 0x06003E52 RID: 15954
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern string GetMachineConfigPath();
// Token: 0x06003E53 RID: 15955
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern string internalGetHome();
// Token: 0x040018DE RID: 6366
private const int mono_corlib_version = 82;
// Token: 0x040018DF RID: 6367
private static OperatingSystem os;
/// <summary>Specifies enumerated constants used to retrieve directory paths to system special folders.</summary>
// Token: 0x02000667 RID: 1639
[ComVisible(true)]
public enum SpecialFolder
{
/// <summary>The "My Documents" folder.</summary>
// Token: 0x040018E1 RID: 6369
MyDocuments = 5,
/// <summary>The logical Desktop rather than the physical file system location.</summary>
// Token: 0x040018E2 RID: 6370
Desktop = 0,
/// <summary>The "My Computer" folder. </summary>
// Token: 0x040018E3 RID: 6371
MyComputer = 17,
/// <summary>The directory that contains the user's program groups.</summary>
// Token: 0x040018E4 RID: 6372
Programs = 2,
/// <summary>The directory that serves as a common repository for documents.</summary>
// Token: 0x040018E5 RID: 6373
Personal = 5,
/// <summary>The directory that serves as a common repository for the user's favorite items.</summary>
// Token: 0x040018E6 RID: 6374
Favorites,
/// <summary>The directory that corresponds to the user's Startup program group.</summary>
// Token: 0x040018E7 RID: 6375
Startup,
/// <summary>The directory that contains the user's most recently used documents.</summary>
// Token: 0x040018E8 RID: 6376
Recent,
/// <summary>The directory that contains the Send To menu items.</summary>
// Token: 0x040018E9 RID: 6377
SendTo,
/// <summary>The directory that contains the Start menu items.</summary>
// Token: 0x040018EA RID: 6378
StartMenu = 11,
/// <summary>The "My Music" folder.</summary>
// Token: 0x040018EB RID: 6379
MyMusic = 13,
/// <summary>The directory used to physically store file objects on the desktop.</summary>
// Token: 0x040018EC RID: 6380
DesktopDirectory = 16,
/// <summary>The directory that serves as a common repository for document templates.</summary>
// Token: 0x040018ED RID: 6381
Templates = 21,
/// <summary>The directory that serves as a common repository for application-specific data for the current roaming user.</summary>
// Token: 0x040018EE RID: 6382
ApplicationData = 26,
/// <summary>The directory that serves as a common repository for application-specific data that is used by the current, non-roaming user.</summary>
// Token: 0x040018EF RID: 6383
LocalApplicationData = 28,
/// <summary>The directory that serves as a common repository for temporary Internet files.</summary>
// Token: 0x040018F0 RID: 6384
InternetCache = 32,
/// <summary>The directory that serves as a common repository for Internet cookies.</summary>
// Token: 0x040018F1 RID: 6385
Cookies,
/// <summary>The directory that serves as a common repository for Internet history items.</summary>
// Token: 0x040018F2 RID: 6386
History,
/// <summary>The directory that serves as a common repository for application-specific data that is used by all users.</summary>
// Token: 0x040018F3 RID: 6387
CommonApplicationData,
/// <summary>The System directory.</summary>
// Token: 0x040018F4 RID: 6388
System = 37,
/// <summary>The program files directory.</summary>
// Token: 0x040018F5 RID: 6389
ProgramFiles,
/// <summary>The "My Pictures" folder.</summary>
// Token: 0x040018F6 RID: 6390
MyPictures,
/// <summary>The directory for components that are shared across applications.</summary>
// Token: 0x040018F7 RID: 6391
CommonProgramFiles = 43
}
}
}