Exemplo n.º 1
0
 internal static Win32Exception CreateSafeWin32Exception()
 {
     return(SharedUtils.CreateSafeWin32Exception(0));
 }
Exemplo n.º 2
0
        internal static string GetLatestBuildDllDirectory(string machineName)
        {
            string             result             = "";
            RegistryKey        registryKey        = null;
            RegistryKey        registryKey2       = null;
            RegistryPermission registryPermission = new RegistryPermission(PermissionState.Unrestricted);

            registryPermission.Assert();
            try
            {
                if (machineName.Equals("."))
                {
                    return(SharedUtils.GetLocalBuildDirectory());
                }
                registryKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, machineName);
                if (registryKey == null)
                {
                    throw new InvalidOperationException("RegKeyMissingShort");
                }
                registryKey2 = registryKey.OpenSubKey("SOFTWARE\\Microsoft\\.NETFramework");
                if (registryKey2 != null)
                {
                    string text = (string)registryKey2.GetValue("InstallRoot");
                    if (text != null && text != string.Empty)
                    {
                        string text2 = string.Concat(new object[]
                        {
                            "v",
                            Environment.Version.Major,
                            ".",
                            Environment.Version.Minor
                        });
                        RegistryKey registryKey3 = registryKey2.OpenSubKey("policy");
                        string      text3        = null;
                        if (registryKey3 != null)
                        {
                            try
                            {
                                RegistryKey registryKey4 = registryKey3.OpenSubKey(text2);
                                if (registryKey4 != null)
                                {
                                    try
                                    {
                                        text3 = text2 + "." + SharedUtils.GetLargestBuildNumberFromKey(registryKey4);
                                        goto IL_29A;
                                    }
                                    finally
                                    {
                                        registryKey4.Close();
                                    }
                                }
                                string[] subKeyNames = registryKey3.GetSubKeyNames();
                                int[]    array       = new int[]
                                {
                                    -1,
                                    -1,
                                    -1
                                };
                                for (int i = 0; i < subKeyNames.Length; i++)
                                {
                                    string text4 = subKeyNames[i];
                                    if (text4.Length > 1 && text4[0] == 'v' && text4.Contains("."))
                                    {
                                        int[] array2 = new int[]
                                        {
                                            -1,
                                            -1,
                                            -1
                                        };
                                        string[] array3 = text4.Substring(1).Split(new char[]
                                        {
                                            '.'
                                        });
                                        if (array3.Length == 2 && int.TryParse(array3[0], out array2[0]) && int.TryParse(array3[1], out array2[1]))
                                        {
                                            RegistryKey registryKey5 = registryKey3.OpenSubKey(text4);
                                            if (registryKey5 != null)
                                            {
                                                try
                                                {
                                                    array2[2] = SharedUtils.GetLargestBuildNumberFromKey(registryKey5);
                                                    if (array2[0] > array[0] || (array2[0] == array[0] && array2[1] > array[1]))
                                                    {
                                                        array = array2;
                                                    }
                                                }
                                                finally
                                                {
                                                    registryKey5.Close();
                                                }
                                            }
                                        }
                                    }
                                }
                                text3 = string.Concat(new object[]
                                {
                                    "v",
                                    array[0],
                                    ".",
                                    array[1],
                                    ".",
                                    array[2]
                                });
                                IL_29A :;
                            }
                            finally
                            {
                                registryKey3.Close();
                            }
                            if (text3 != null && text3 != string.Empty)
                            {
                                StringBuilder stringBuilder = new StringBuilder();
                                stringBuilder.Append(text);
                                if (!text.EndsWith("\\", StringComparison.Ordinal))
                                {
                                    stringBuilder.Append("\\");
                                }
                                stringBuilder.Append(text3);
                                result = stringBuilder.ToString();
                            }
                        }
                    }
                }
            }
            catch
            {
            }
            finally
            {
                if (registryKey2 != null)
                {
                    registryKey2.Close();
                }
                if (registryKey != null)
                {
                    registryKey.Close();
                }
                CodeAccessPermission.RevertAssert();
            }
            return(result);
        }