Example #1
0
        public static bool VerifyOSDependency(ref PlatformDetector.OSDependency osd)
        {
            OperatingSystem osVersion = Environment.OSVersion;

            if ((long)osVersion.Version.Major == 4L)
            {
                return((long)osVersion.Version.Major >= (long)osd.dwMajorVersion);
            }
            NativeMethods.OSVersionInfoEx osvi = new NativeMethods.OSVersionInfoEx();
            osvi.dwOSVersionInfoSize = (uint)Marshal.SizeOf((object)osvi);
            osvi.dwMajorVersion      = osd.dwMajorVersion;
            osvi.dwMinorVersion      = osd.dwMinorVersion;
            osvi.dwBuildNumber       = osd.dwBuildNumber;
            osvi.dwPlatformId        = 0U;
            osvi.szCSDVersion        = (string)null;
            osvi.wServicePackMajor   = osd.wServicePackMajor;
            osvi.wServicePackMinor   = osd.wServicePackMinor;
            osvi.wSuiteMask          = osd.suiteName != null ? (ushort)PlatformDetector.NameMap.MapNameToMask(osd.suiteName, (PlatformDetector.NameMap[])PlatformDetector.Suites) : (ushort)0;
            osvi.bProductType        = osd.productName != null ? (byte)PlatformDetector.NameMap.MapNameToMask(osd.productName, (PlatformDetector.NameMap[])PlatformDetector.Products) : (byte)0;
            osvi.bReserved           = (byte)0;
            ulong ConditionMask = 0;
            uint  dwTypeMask    = (uint)(2 | ((int)osd.dwMinorVersion != 0 ? 1 : 0) | ((int)osd.dwBuildNumber != 0 ? 4 : 0) | (osd.suiteName != null ? 64 : 0) | (osd.productName != null ? 128 : 0) | ((int)osd.wServicePackMajor != 0 ? 32 : 0) | ((int)osd.wServicePackMinor != 0 ? 16 : 0));
            ulong num           = NativeMethods.VerSetConditionMask(ConditionMask, 2U, (byte)3);

            if ((int)osd.dwMinorVersion != 0)
            {
                num = NativeMethods.VerSetConditionMask(num, 1U, (byte)3);
            }
            if ((int)osd.dwBuildNumber != 0)
            {
                num = NativeMethods.VerSetConditionMask(num, 4U, (byte)3);
            }
            if (osd.suiteName != null)
            {
                num = NativeMethods.VerSetConditionMask(num, 64U, (byte)6);
            }
            if (osd.productName != null)
            {
                num = NativeMethods.VerSetConditionMask(num, 128U, (byte)1);
            }
            if ((int)osd.wServicePackMajor != 0)
            {
                num = NativeMethods.VerSetConditionMask(num, 32U, (byte)3);
            }
            if ((int)osd.wServicePackMinor != 0)
            {
                num = NativeMethods.VerSetConditionMask(num, 16U, (byte)3);
            }
            bool flag = NativeMethods.VerifyVersionInfo(osvi, dwTypeMask, num);

            if (!flag)
            {
                int lastWin32Error = Marshal.GetLastWin32Error();
                if (lastWin32Error != 1150)
                {
                    throw new Win32Exception(lastWin32Error);
                }
            }
            return(flag);
        }
Example #2
0
        public static void VerifyPlatformDependencies(AssemblyManifest appManifest, AssemblyManifest deployManifest, string tempDir)
        {
            Logger.AddMethodCall("VerifyPlatformDependencies called.");
            string      str1        = (string)null;
            Uri         supportUrl1 = deployManifest.Description.SupportUri;
            bool        flag1       = false;
            DependentOS dependentOs = appManifest.DependentOS;

            if (dependentOs != null)
            {
                PlatformDetector.OSDependency osd = new PlatformDetector.OSDependency((uint)dependentOs.MajorVersion, (uint)dependentOs.MinorVersion, (uint)dependentOs.BuildNumber, (ushort)dependentOs.ServicePackMajor, (ushort)dependentOs.ServicePackMinor, (string)null, (string)null);
                if (!PlatformDetector.VerifyOSDependency(ref osd))
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    string        str2          = ((int)dependentOs.MajorVersion).ToString() + "." + (object)dependentOs.MinorVersion + "." + (object)dependentOs.BuildNumber + "." + (object)dependentOs.ServicePackMajor + (object)dependentOs.ServicePackMinor;
                    stringBuilder.AppendFormat(Resources.GetString("PlatformMicrosoftWindowsOperatingSystem"), (object)str2);
                    string str3 = stringBuilder.ToString();
                    if (dependentOs.SupportUrl != (Uri)null)
                    {
                        supportUrl1 = dependentOs.SupportUrl;
                    }
                    throw new DependentPlatformMissingException(string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Resources.GetString("ErrorMessage_PlatformDetectionFailed"), new object[1] {
                        (object)str3
                    }), supportUrl1);
                }
            }
            if (PlatformDetector.IsWin8orLater() && !appManifest.EntryPoints[0].HostInBrowser)
            {
                flag1 = true;
            }
            Version clrVersion            = Constants.V2CLRVersion;
            string  clrVersionString      = clrVersion.ToString(3);
            string  processorArchitecture = appManifest.Identity.ProcessorArchitecture;
            Uri     supportUrl2           = supportUrl1;

            if (appManifest.CLRDependentAssembly != null)
            {
                clrVersion            = appManifest.CLRDependentAssembly.Identity.Version;
                clrVersionString      = clrVersion.ToString(3);
                processorArchitecture = appManifest.CLRDependentAssembly.Identity.ProcessorArchitecture;
                if (appManifest.CLRDependentAssembly.SupportUrl != (Uri)null)
                {
                    supportUrl2 = appManifest.CLRDependentAssembly.SupportUrl;
                }
                if (appManifest.CLRDependentAssembly.Description != null)
                {
                    str1 = appManifest.CLRDependentAssembly.Description;
                }
            }
            if (deployManifest.CompatibleFrameworks != null)
            {
                bool flag2 = false;
                for (int index = 0; index < deployManifest.CompatibleFrameworks.Frameworks.Count; ++index)
                {
                    if (PlatformDetector.CheckCompatibleFramework(deployManifest.CompatibleFrameworks.Frameworks[index], ref clrVersion, ref clrVersionString, processorArchitecture))
                    {
                        flag2 = true;
                        break;
                    }
                }
                if (!flag2)
                {
                    Uri supportUrl3 = !(deployManifest.CompatibleFrameworks.SupportUrl != (Uri)null) ? supportUrl2 : deployManifest.CompatibleFrameworks.SupportUrl;
                    if (flag1)
                    {
                        return;
                    }
                    throw new CompatibleFrameworkMissingException(string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Resources.GetString("ErrorMessage_CompatiblePlatformDetectionFailed"), new object[1]
                    {
                        (object)PlatformDetector.FormatFrameworkString(deployManifest.CompatibleFrameworks.Frameworks[0])
                    }), supportUrl3, deployManifest.CompatibleFrameworks);
                }
            }
            else
            {
                if (clrVersion >= Constants.V4CLRVersion)
                {
                    throw new InvalidDeploymentException(ExceptionTypes.ManifestSemanticValidation, Resources.GetString("Ex_SemanticallyInvalidDeploymentManifest"), (Exception) new InvalidDeploymentException(ExceptionTypes.InvalidManifest, Resources.GetString("Ex_DepMissingCompatibleFrameworks")));
                }
                if (!NativeMethods.VerifyCLRVersionInfo(clrVersion, processorArchitecture))
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    if (str1 == null)
                    {
                        stringBuilder.AppendFormat(Resources.GetString("PlatformMicrosoftCommonLanguageRuntime"), (object)clrVersionString);
                        str1 = stringBuilder.ToString();
                    }
                    Uri supportUrl3 = supportUrl2;
                    if (flag1)
                    {
                        return;
                    }
                    throw new SupportedRuntimeMissingException(string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Resources.GetString("ErrorMessage_PlatformDetectionFailed"), new object[1] {
                        (object)str1
                    }), supportUrl3, clrVersionString);
                }
            }
            Logger.AddPhaseInformation(Resources.GetString("CompatibleRuntimeFound"), new object[1]
            {
                (object)clrVersionString
            });
            bool flag3 = false;

            if (clrVersion < Constants.V4CLRVersion)
            {
                flag3 = true;
            }
            NativeMethods.CCorRuntimeHost RuntimeHost = (NativeMethods.CCorRuntimeHost)null;
            try
            {
                NativeMethods.IAssemblyCache assemblyCacheInterface = NativeMethods.GetAssemblyCacheInterface(clrVersionString, flag3, out RuntimeHost);
                if (assemblyCacheInterface == null || flag3 && RuntimeHost == null)
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendFormat(Resources.GetString("PlatformMicrosoftCommonLanguageRuntime"), (object)clrVersionString);
                    throw new DependentPlatformMissingException(string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Resources.GetString("ErrorMessage_PlatformDetectionFailed"), new object[1]
                    {
                        (object)stringBuilder.ToString()
                    }), supportUrl2);
                }
                bool flag2 = false;
                bool flag4 = false;
                if (flag3 && !PolicyKeys.SkipSKUDetection())
                {
                    foreach (DependentAssembly dependentAssembly in appManifest.DependentAssemblies)
                    {
                        if (dependentAssembly.IsPreRequisite && PlatformDetector.IsNetFX35SP1ClientSignatureAsm(dependentAssembly.Identity))
                        {
                            flag2 = true;
                        }
                        if (dependentAssembly.IsPreRequisite && PlatformDetector.IsNetFX35SP1FullSignatureAsm(dependentAssembly.Identity))
                        {
                            flag4 = true;
                        }
                    }
                    if (PlatformDetector.GetPlatformNetFx35SKU(assemblyCacheInterface, flag3, RuntimeHost, tempDir) == PlatformDetector.NetFX35SP1SKU.Client35SP1 && !flag2 && !flag4)
                    {
                        throw new DependentPlatformMissingException(string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Resources.GetString("ErrorMessage_PlatformDetectionFailed"), new object[1]
                        {
                            (object)".NET Framework 3.5 SP1"
                        }));
                    }
                }
                foreach (DependentAssembly dependentAssembly in appManifest.DependentAssemblies)
                {
                    if (dependentAssembly.IsPreRequisite && !PlatformDetector.IsCLRDependencyText(dependentAssembly.Identity.Name))
                    {
                        if (!flag3 && (PlatformDetector.IsNetFX35SP1ClientSignatureAsm(dependentAssembly.Identity) || PlatformDetector.IsNetFX35SP1FullSignatureAsm(dependentAssembly.Identity) || "framework".Equals(dependentAssembly.Group, StringComparison.OrdinalIgnoreCase)))
                        {
                            Logger.AddPhaseInformation(Resources.GetString("SkippingSentinalDependentAssembly"), new object[1]
                            {
                                (object)dependentAssembly.Identity.ToString()
                            });
                        }
                        else if (!PlatformDetector.VerifyGACDependency(assemblyCacheInterface, flag3, RuntimeHost, dependentAssembly.Identity, tempDir))
                        {
                            string description;
                            if (dependentAssembly.Description != null)
                            {
                                description = dependentAssembly.Description;
                            }
                            else
                            {
                                ReferenceIdentity identity      = dependentAssembly.Identity;
                                StringBuilder     stringBuilder = new StringBuilder();
                                stringBuilder.AppendFormat(Resources.GetString("PlatformDependentAssemblyVersion"), (object)identity.Name, (object)identity.Version);
                                description = stringBuilder.ToString();
                            }
                            if (dependentAssembly.SupportUrl != (Uri)null)
                            {
                                supportUrl1 = dependentAssembly.SupportUrl;
                            }
                            throw new DependentPlatformMissingException(string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Resources.GetString("ErrorMessage_PlatformGACDetectionFailed"), new object[1]
                            {
                                (object)description
                            }), supportUrl1);
                        }
                    }
                }
            }
            finally
            {
                if (RuntimeHost != null)
                {
                    RuntimeHost.Dispose();
                }
            }
        }
Example #3
0
 public static bool IsWin8orLater()
 {
     PlatformDetector.OSDependency osd = new PlatformDetector.OSDependency(6U, 2U, 0U, (ushort)0, (ushort)0, (string)null, (string)null);
     return(PlatformDetector.VerifyOSDependency(ref osd));
 }