public static void VerifyPlatformDependencies(AssemblyManifest appManifest, AssemblyManifest deployManifest, string tempDir)
 {
     Logger.AddMethodCall("VerifyPlatformDependencies called.");
     string description = null;
     Uri supportUri = deployManifest.Description.SupportUri;
     DependentOS dependentOS = appManifest.DependentOS;
     if (dependentOS != null)
     {
         OSDependency osd = new OSDependency(dependentOS.MajorVersion, dependentOS.MinorVersion, dependentOS.BuildNumber, dependentOS.ServicePackMajor, dependentOS.ServicePackMinor, null, null);
         if (!VerifyOSDependency(ref osd))
         {
             StringBuilder builder = new StringBuilder();
             string str2 = string.Concat(new object[] { dependentOS.MajorVersion, ".", dependentOS.MinorVersion, ".", dependentOS.BuildNumber, ".", dependentOS.ServicePackMajor, dependentOS.ServicePackMinor });
             builder.AppendFormat(Resources.GetString("PlatformMicrosoftWindowsOperatingSystem"), str2);
             description = builder.ToString();
             if (dependentOS.SupportUrl != null)
             {
                 supportUri = dependentOS.SupportUrl;
             }
             throw new DependentPlatformMissingException(string.Format(CultureInfo.CurrentUICulture, Resources.GetString("ErrorMessage_PlatformDetectionFailed"), new object[] { description }), supportUri);
         }
     }
     Version v = Constants.V2CLRVersion;
     string str3 = v.ToString(3);
     string processorArchitecture = appManifest.Identity.ProcessorArchitecture;
     Uri supportUrl = supportUri;
     if (appManifest.CLRDependentAssembly != null)
     {
         v = appManifest.CLRDependentAssembly.Identity.Version;
         str3 = v.ToString(3);
         processorArchitecture = appManifest.CLRDependentAssembly.Identity.ProcessorArchitecture;
         if (appManifest.CLRDependentAssembly.SupportUrl != null)
         {
             supportUrl = appManifest.CLRDependentAssembly.SupportUrl;
         }
         if (appManifest.CLRDependentAssembly.Description != null)
         {
             description = appManifest.CLRDependentAssembly.Description;
         }
     }
     if (deployManifest.CompatibleFrameworks == null)
     {
         if (v >= Constants.V4CLRVersion)
         {
             throw new InvalidDeploymentException(ExceptionTypes.ManifestSemanticValidation, Resources.GetString("Ex_SemanticallyInvalidDeploymentManifest"), new InvalidDeploymentException(ExceptionTypes.InvalidManifest, Resources.GetString("Ex_DepMissingCompatibleFrameworks")));
         }
         if (!VerifyCLRVersionInfo(v, processorArchitecture))
         {
             StringBuilder builder2 = new StringBuilder();
             if (description == null)
             {
                 builder2.AppendFormat(Resources.GetString("PlatformMicrosoftCommonLanguageRuntime"), str3);
                 description = builder2.ToString();
             }
             supportUri = supportUrl;
             throw new SupportedRuntimeMissingException(string.Format(CultureInfo.CurrentUICulture, Resources.GetString("ErrorMessage_PlatformDetectionFailed"), new object[] { description }), supportUri, str3);
         }
     }
     else
     {
         bool flag = false;
         for (int i = 0; i < deployManifest.CompatibleFrameworks.Frameworks.Count; i++)
         {
             if (CheckCompatibleFramework(deployManifest.CompatibleFrameworks.Frameworks[i], ref v, ref str3, processorArchitecture))
             {
                 flag = true;
                 break;
             }
         }
         if (!flag)
         {
             if (deployManifest.CompatibleFrameworks.SupportUrl != null)
             {
                 supportUri = deployManifest.CompatibleFrameworks.SupportUrl;
             }
             else
             {
                 supportUri = supportUrl;
             }
             throw new CompatibleFrameworkMissingException(string.Format(CultureInfo.CurrentUICulture, Resources.GetString("ErrorMessage_CompatiblePlatformDetectionFailed"), new object[] { FormatFrameworkString(deployManifest.CompatibleFrameworks.Frameworks[0]) }), supportUri, deployManifest.CompatibleFrameworks);
         }
     }
     Logger.AddPhaseInformation(Resources.GetString("CompatibleRuntimeFound"), new object[] { str3 });
     bool fetchRuntimeHost = false;
     if (v < Constants.V4CLRVersion)
     {
         fetchRuntimeHost = true;
     }
     using (System.Deployment.Application.NativeMethods.CCorRuntimeHost host = null)
     {
         System.Deployment.Application.NativeMethods.IAssemblyCache assemblyCache = System.Deployment.Application.NativeMethods.GetAssemblyCacheInterface(str3, fetchRuntimeHost, out host);
         if ((assemblyCache == null) || (fetchRuntimeHost && (host == null)))
         {
             StringBuilder builder3 = new StringBuilder();
             builder3.AppendFormat(Resources.GetString("PlatformMicrosoftCommonLanguageRuntime"), str3);
             description = builder3.ToString();
             supportUri = supportUrl;
             throw new DependentPlatformMissingException(string.Format(CultureInfo.CurrentUICulture, Resources.GetString("ErrorMessage_PlatformDetectionFailed"), new object[] { description }), supportUri);
         }
         bool flag3 = false;
         bool flag4 = false;
         if (fetchRuntimeHost && !PolicyKeys.SkipSKUDetection())
         {
             foreach (DependentAssembly assembly in appManifest.DependentAssemblies)
             {
                 if (assembly.IsPreRequisite && IsNetFX35SP1ClientSignatureAsm(assembly.Identity))
                 {
                     flag3 = true;
                 }
                 if (assembly.IsPreRequisite && IsNetFX35SP1FullSignatureAsm(assembly.Identity))
                 {
                     flag4 = true;
                 }
             }
             if (((GetPlatformNetFx35SKU(assemblyCache, fetchRuntimeHost, host, tempDir) == NetFX35SP1SKU.Client35SP1) && !flag3) && !flag4)
             {
                 description = ".NET Framework 3.5 SP1";
                 throw new DependentPlatformMissingException(string.Format(CultureInfo.CurrentUICulture, Resources.GetString("ErrorMessage_PlatformDetectionFailed"), new object[] { description }));
             }
         }
         foreach (DependentAssembly assembly2 in appManifest.DependentAssemblies)
         {
             if (assembly2.IsPreRequisite && !IsCLRDependencyText(assembly2.Identity.Name))
             {
                 if (!fetchRuntimeHost && ((IsNetFX35SP1ClientSignatureAsm(assembly2.Identity) || IsNetFX35SP1FullSignatureAsm(assembly2.Identity)) || "framework".Equals(assembly2.Group, StringComparison.OrdinalIgnoreCase)))
                 {
                     Logger.AddPhaseInformation(Resources.GetString("SkippingSentinalDependentAssembly"), new object[] { assembly2.Identity.ToString() });
                 }
                 else if (!VerifyGACDependency(assemblyCache, fetchRuntimeHost, host, assembly2.Identity, tempDir))
                 {
                     if (assembly2.Description != null)
                     {
                         description = assembly2.Description;
                     }
                     else
                     {
                         ReferenceIdentity identity = assembly2.Identity;
                         StringBuilder builder4 = new StringBuilder();
                         builder4.AppendFormat(Resources.GetString("PlatformDependentAssemblyVersion"), identity.Name, identity.Version);
                         description = builder4.ToString();
                     }
                     if (assembly2.SupportUrl != null)
                     {
                         supportUri = assembly2.SupportUrl;
                     }
                     throw new DependentPlatformMissingException(string.Format(CultureInfo.CurrentUICulture, Resources.GetString("ErrorMessage_PlatformGACDetectionFailed"), new object[] { description }), supportUri);
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        public static void VerifyPlatformDependencies(AssemblyManifest appManifest, AssemblyManifest deployManifest, string tempDir)
        {
            Logger.AddMethodCall("VerifyPlatformDependencies called.");
            string      description = null;
            Uri         supportUri  = deployManifest.Description.SupportUri;
            DependentOS dependentOS = appManifest.DependentOS;

            if (dependentOS != null)
            {
                OSDependency osd = new OSDependency(dependentOS.MajorVersion, dependentOS.MinorVersion, dependentOS.BuildNumber, dependentOS.ServicePackMajor, dependentOS.ServicePackMinor, null, null);
                if (!VerifyOSDependency(ref osd))
                {
                    StringBuilder builder = new StringBuilder();
                    string        str2    = string.Concat(new object[] { dependentOS.MajorVersion, ".", dependentOS.MinorVersion, ".", dependentOS.BuildNumber, ".", dependentOS.ServicePackMajor, dependentOS.ServicePackMinor });
                    builder.AppendFormat(Resources.GetString("PlatformMicrosoftWindowsOperatingSystem"), str2);
                    description = builder.ToString();
                    if (dependentOS.SupportUrl != null)
                    {
                        supportUri = dependentOS.SupportUrl;
                    }
                    throw new DependentPlatformMissingException(string.Format(CultureInfo.CurrentUICulture, Resources.GetString("ErrorMessage_PlatformDetectionFailed"), new object[] { description }), supportUri);
                }
            }
            Version v    = Constants.V2CLRVersion;
            string  str3 = v.ToString(3);
            string  processorArchitecture = appManifest.Identity.ProcessorArchitecture;
            Uri     supportUrl            = supportUri;

            if (appManifest.CLRDependentAssembly != null)
            {
                v    = appManifest.CLRDependentAssembly.Identity.Version;
                str3 = v.ToString(3);
                processorArchitecture = appManifest.CLRDependentAssembly.Identity.ProcessorArchitecture;
                if (appManifest.CLRDependentAssembly.SupportUrl != null)
                {
                    supportUrl = appManifest.CLRDependentAssembly.SupportUrl;
                }
                if (appManifest.CLRDependentAssembly.Description != null)
                {
                    description = appManifest.CLRDependentAssembly.Description;
                }
            }
            if (deployManifest.CompatibleFrameworks == null)
            {
                if (v >= Constants.V4CLRVersion)
                {
                    throw new InvalidDeploymentException(ExceptionTypes.ManifestSemanticValidation, Resources.GetString("Ex_SemanticallyInvalidDeploymentManifest"), new InvalidDeploymentException(ExceptionTypes.InvalidManifest, Resources.GetString("Ex_DepMissingCompatibleFrameworks")));
                }
                if (!VerifyCLRVersionInfo(v, processorArchitecture))
                {
                    StringBuilder builder2 = new StringBuilder();
                    if (description == null)
                    {
                        builder2.AppendFormat(Resources.GetString("PlatformMicrosoftCommonLanguageRuntime"), str3);
                        description = builder2.ToString();
                    }
                    supportUri = supportUrl;
                    throw new SupportedRuntimeMissingException(string.Format(CultureInfo.CurrentUICulture, Resources.GetString("ErrorMessage_PlatformDetectionFailed"), new object[] { description }), supportUri, str3);
                }
            }
            else
            {
                bool flag = false;
                for (int i = 0; i < deployManifest.CompatibleFrameworks.Frameworks.Count; i++)
                {
                    if (CheckCompatibleFramework(deployManifest.CompatibleFrameworks.Frameworks[i], ref v, ref str3, processorArchitecture))
                    {
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    if (deployManifest.CompatibleFrameworks.SupportUrl != null)
                    {
                        supportUri = deployManifest.CompatibleFrameworks.SupportUrl;
                    }
                    else
                    {
                        supportUri = supportUrl;
                    }
                    throw new CompatibleFrameworkMissingException(string.Format(CultureInfo.CurrentUICulture, Resources.GetString("ErrorMessage_CompatiblePlatformDetectionFailed"), new object[] { FormatFrameworkString(deployManifest.CompatibleFrameworks.Frameworks[0]) }), supportUri, deployManifest.CompatibleFrameworks);
                }
            }
            Logger.AddPhaseInformation(Resources.GetString("CompatibleRuntimeFound"), new object[] { str3 });
            bool fetchRuntimeHost = false;

            if (v < Constants.V4CLRVersion)
            {
                fetchRuntimeHost = true;
            }
            using (System.Deployment.Application.NativeMethods.CCorRuntimeHost host = null)
            {
                System.Deployment.Application.NativeMethods.IAssemblyCache assemblyCache = System.Deployment.Application.NativeMethods.GetAssemblyCacheInterface(str3, fetchRuntimeHost, out host);
                if ((assemblyCache == null) || (fetchRuntimeHost && (host == null)))
                {
                    StringBuilder builder3 = new StringBuilder();
                    builder3.AppendFormat(Resources.GetString("PlatformMicrosoftCommonLanguageRuntime"), str3);
                    description = builder3.ToString();
                    supportUri  = supportUrl;
                    throw new DependentPlatformMissingException(string.Format(CultureInfo.CurrentUICulture, Resources.GetString("ErrorMessage_PlatformDetectionFailed"), new object[] { description }), supportUri);
                }
                bool flag3 = false;
                bool flag4 = false;
                if (fetchRuntimeHost && !PolicyKeys.SkipSKUDetection())
                {
                    foreach (DependentAssembly assembly in appManifest.DependentAssemblies)
                    {
                        if (assembly.IsPreRequisite && IsNetFX35SP1ClientSignatureAsm(assembly.Identity))
                        {
                            flag3 = true;
                        }
                        if (assembly.IsPreRequisite && IsNetFX35SP1FullSignatureAsm(assembly.Identity))
                        {
                            flag4 = true;
                        }
                    }
                    if (((GetPlatformNetFx35SKU(assemblyCache, fetchRuntimeHost, host, tempDir) == NetFX35SP1SKU.Client35SP1) && !flag3) && !flag4)
                    {
                        description = ".NET Framework 3.5 SP1";
                        throw new DependentPlatformMissingException(string.Format(CultureInfo.CurrentUICulture, Resources.GetString("ErrorMessage_PlatformDetectionFailed"), new object[] { description }));
                    }
                }
                foreach (DependentAssembly assembly2 in appManifest.DependentAssemblies)
                {
                    if (assembly2.IsPreRequisite && !IsCLRDependencyText(assembly2.Identity.Name))
                    {
                        if (!fetchRuntimeHost && ((IsNetFX35SP1ClientSignatureAsm(assembly2.Identity) || IsNetFX35SP1FullSignatureAsm(assembly2.Identity)) || "framework".Equals(assembly2.Group, StringComparison.OrdinalIgnoreCase)))
                        {
                            Logger.AddPhaseInformation(Resources.GetString("SkippingSentinalDependentAssembly"), new object[] { assembly2.Identity.ToString() });
                        }
                        else if (!VerifyGACDependency(assemblyCache, fetchRuntimeHost, host, assembly2.Identity, tempDir))
                        {
                            if (assembly2.Description != null)
                            {
                                description = assembly2.Description;
                            }
                            else
                            {
                                ReferenceIdentity identity = assembly2.Identity;
                                StringBuilder     builder4 = new StringBuilder();
                                builder4.AppendFormat(Resources.GetString("PlatformDependentAssemblyVersion"), identity.Name, identity.Version);
                                description = builder4.ToString();
                            }
                            if (assembly2.SupportUrl != null)
                            {
                                supportUri = assembly2.SupportUrl;
                            }
                            throw new DependentPlatformMissingException(string.Format(CultureInfo.CurrentUICulture, Resources.GetString("ErrorMessage_PlatformGACDetectionFailed"), new object[] { description }), supportUri);
                        }
                    }
                }
            }
        }
 public static bool VerifyOSDependency(ref OSDependency osd)
 {
     System.Deployment.Application.NativeMethods.OSVersionInfoEx ex;
     OperatingSystem oSVersion = Environment.OSVersion;
     if (oSVersion.Version.Major == 4L)
     {
         if (oSVersion.Version.Major < osd.dwMajorVersion)
         {
             return false;
         }
         return true;
     }
     ex = new System.Deployment.Application.NativeMethods.OSVersionInfoEx {
         dwOSVersionInfoSize = Marshal.SizeOf(ex),
         dwMajorVersion = osd.dwMajorVersion,
         dwMinorVersion = osd.dwMinorVersion,
         dwBuildNumber = osd.dwBuildNumber,
         dwPlatformId = 0,
         szCSDVersion = null,
         wServicePackMajor = osd.wServicePackMajor,
         wServicePackMinor = osd.wServicePackMinor,
         wSuiteMask = (osd.suiteName != null) ? ((ushort) NameMap.MapNameToMask(osd.suiteName, Suites)) : ((ushort) 0),
         bProductType = (osd.productName != null) ? ((byte) NameMap.MapNameToMask(osd.productName, Products)) : ((byte) 0),
         bReserved = 0
     };
     ulong conditionMask = 0L;
     uint dwTypeMask = (uint) ((((((2 | ((osd.dwMinorVersion != 0) ? 1 : 0)) | ((osd.dwBuildNumber != 0) ? 4 : 0)) | ((osd.suiteName != null) ? 0x40 : 0)) | ((osd.productName != null) ? 0x80 : 0)) | ((osd.wServicePackMajor != 0) ? 0x20 : 0)) | ((osd.wServicePackMinor != 0) ? 0x10 : 0));
     conditionMask = System.Deployment.Application.NativeMethods.VerSetConditionMask(conditionMask, 2, 3);
     if (osd.dwMinorVersion != 0)
     {
         conditionMask = System.Deployment.Application.NativeMethods.VerSetConditionMask(conditionMask, 1, 3);
     }
     if (osd.dwBuildNumber != 0)
     {
         conditionMask = System.Deployment.Application.NativeMethods.VerSetConditionMask(conditionMask, 4, 3);
     }
     if (osd.suiteName != null)
     {
         conditionMask = System.Deployment.Application.NativeMethods.VerSetConditionMask(conditionMask, 0x40, 6);
     }
     if (osd.productName != null)
     {
         conditionMask = System.Deployment.Application.NativeMethods.VerSetConditionMask(conditionMask, 0x80, 1);
     }
     if (osd.wServicePackMajor != 0)
     {
         conditionMask = System.Deployment.Application.NativeMethods.VerSetConditionMask(conditionMask, 0x20, 3);
     }
     if (osd.wServicePackMinor != 0)
     {
         conditionMask = System.Deployment.Application.NativeMethods.VerSetConditionMask(conditionMask, 0x10, 3);
     }
     bool flag = System.Deployment.Application.NativeMethods.VerifyVersionInfo(ex, dwTypeMask, conditionMask);
     if (!flag)
     {
         int error = Marshal.GetLastWin32Error();
         if (error != 0x47e)
         {
             throw new Win32Exception(error);
         }
     }
     return flag;
 }
Exemplo n.º 4
0
        public static bool VerifyOSDependency(ref OSDependency osd)
        {
            System.Deployment.Application.NativeMethods.OSVersionInfoEx ex;
            OperatingSystem oSVersion = Environment.OSVersion;

            if (oSVersion.Version.Major == 4L)
            {
                if (oSVersion.Version.Major < osd.dwMajorVersion)
                {
                    return(false);
                }
                return(true);
            }
            ex = new System.Deployment.Application.NativeMethods.OSVersionInfoEx {
                dwOSVersionInfoSize = Marshal.SizeOf(ex),
                dwMajorVersion      = osd.dwMajorVersion,
                dwMinorVersion      = osd.dwMinorVersion,
                dwBuildNumber       = osd.dwBuildNumber,
                dwPlatformId        = 0,
                szCSDVersion        = null,
                wServicePackMajor   = osd.wServicePackMajor,
                wServicePackMinor   = osd.wServicePackMinor,
                wSuiteMask          = (osd.suiteName != null) ? ((ushort)NameMap.MapNameToMask(osd.suiteName, Suites)) : ((ushort)0),
                bProductType        = (osd.productName != null) ? ((byte)NameMap.MapNameToMask(osd.productName, Products)) : ((byte)0),
                bReserved           = 0
            };
            ulong conditionMask = 0L;
            uint  dwTypeMask    = (uint)((((((2 | ((osd.dwMinorVersion != 0) ? 1 : 0)) | ((osd.dwBuildNumber != 0) ? 4 : 0)) | ((osd.suiteName != null) ? 0x40 : 0)) | ((osd.productName != null) ? 0x80 : 0)) | ((osd.wServicePackMajor != 0) ? 0x20 : 0)) | ((osd.wServicePackMinor != 0) ? 0x10 : 0));

            conditionMask = System.Deployment.Application.NativeMethods.VerSetConditionMask(conditionMask, 2, 3);
            if (osd.dwMinorVersion != 0)
            {
                conditionMask = System.Deployment.Application.NativeMethods.VerSetConditionMask(conditionMask, 1, 3);
            }
            if (osd.dwBuildNumber != 0)
            {
                conditionMask = System.Deployment.Application.NativeMethods.VerSetConditionMask(conditionMask, 4, 3);
            }
            if (osd.suiteName != null)
            {
                conditionMask = System.Deployment.Application.NativeMethods.VerSetConditionMask(conditionMask, 0x40, 6);
            }
            if (osd.productName != null)
            {
                conditionMask = System.Deployment.Application.NativeMethods.VerSetConditionMask(conditionMask, 0x80, 1);
            }
            if (osd.wServicePackMajor != 0)
            {
                conditionMask = System.Deployment.Application.NativeMethods.VerSetConditionMask(conditionMask, 0x20, 3);
            }
            if (osd.wServicePackMinor != 0)
            {
                conditionMask = System.Deployment.Application.NativeMethods.VerSetConditionMask(conditionMask, 0x10, 3);
            }
            bool flag = System.Deployment.Application.NativeMethods.VerifyVersionInfo(ex, dwTypeMask, conditionMask);

            if (!flag)
            {
                int error = Marshal.GetLastWin32Error();
                if (error != 0x47e)
                {
                    throw new Win32Exception(error);
                }
            }
            return(flag);
        }