Example #1
0
        private static void AddFiles(XmlDocument document, System.Deployment.Application.Manifest.File[] files)
        {
            XmlNamespaceManager namespaceMgr = ManifestGenerator.GetNamespaceMgr(document);
            XmlElement          assemblyNode = (XmlElement)document.SelectSingleNode("/asmv1:assembly", namespaceMgr);

            foreach (System.Deployment.Application.Manifest.File file in files)
            {
                ManifestGenerator.AddFile(document, assemblyNode, file);
            }
        }
Example #2
0
        public static void GenerateGACDetectionManifest(ReferenceIdentity refId, string outputManifest)
        {
            XmlDocument document = ManifestGenerator.CloneAssemblyTemplate();

            if (ManifestGenerator.GACDetectionTempManifestAsmId == null)
            {
                Interlocked.CompareExchange(ref ManifestGenerator.GACDetectionTempManifestAsmId, (object)new DefinitionIdentity("GACDetectionTempManifest, version=1.0.0.0, type=win32"), (object)null);
            }
            ManifestGenerator.InjectIdentityXml(document, (DefinitionIdentity)ManifestGenerator.GACDetectionTempManifestAsmId);
            ManifestGenerator.AddDependencies(document, new DependentAssembly[1]
            {
                new DependentAssembly(refId)
            });
            using (FileStream fileStream = System.IO.File.Open(outputManifest, FileMode.CreateNew, FileAccess.Write))
                document.Save((Stream)fileStream);
        }
Example #3
0
 public static bool VerifyGACDependencyXP(ReferenceIdentity refId, string tempDir)
 {
     if (!PlatformSpecific.OnXPOrAbove)
     {
         return(false);
     }
     using (TempFile tempFile = new TempFile(tempDir, ".manifest"))
     {
         ManifestGenerator.GenerateGACDetectionManifest(refId, tempFile.Path);
         IntPtr actCtxW = NativeMethods.CreateActCtxW(new NativeMethods.ACTCTXW(tempFile.Path));
         if (!(actCtxW != NativeMethods.INVALID_HANDLE_VALUE))
         {
             return(false);
         }
         NativeMethods.ReleaseActCtx(actCtxW);
         return(true);
     }
 }
Example #4
0
 public static bool VerifyGACDependencyXP(ReferenceIdentity refId, string tempDir)
 {
     if (!PlatformSpecific.OnXPOrAbove)
     {
         return(false);
     }
     using (TempFile file = new TempFile(tempDir, ".manifest"))
     {
         ManifestGenerator.GenerateGACDetectionManifest(refId, file.Path);
         System.Deployment.Application.NativeMethods.ACTCTXW actCtx = new System.Deployment.Application.NativeMethods.ACTCTXW(file.Path);
         IntPtr hActCtx = System.Deployment.Application.NativeMethods.CreateActCtxW(actCtx);
         if (hActCtx != System.Deployment.Application.NativeMethods.INVALID_HANDLE_VALUE)
         {
             System.Deployment.Application.NativeMethods.ReleaseActCtx(hActCtx);
             return(true);
         }
         return(false);
     }
 }
Example #5
0
        public static DefinitionIdentity GenerateManifest(ReferenceIdentity suggestedReferenceIdentity, AssemblyManifest manifest, string outputManifest)
        {
            DefinitionIdentity asmId = manifest.Identity;

            if (manifest.RawXmlBytes != null)
            {
                using (FileStream fileStream = System.IO.File.Open(outputManifest, FileMode.CreateNew, FileAccess.Write))
                    fileStream.Write(manifest.RawXmlBytes, 0, manifest.RawXmlBytes.Length);
            }
            else
            {
                XmlDocument document = ManifestGenerator.CloneAssemblyTemplate();
                asmId = new DefinitionIdentity(suggestedReferenceIdentity);
                ManifestGenerator.InjectIdentityXml(document, asmId);
                ManifestGenerator.AddFiles(document, manifest.Files);
                ManifestGenerator.AddDependencies(document, manifest.DependentAssemblies);
                using (FileStream fileStream = System.IO.File.Open(outputManifest, FileMode.CreateNew, FileAccess.Write))
                    document.Save((Stream)fileStream);
            }
            return(asmId);
        }
Example #6
0
        private static void AddDependencies(XmlDocument document, DependentAssembly[] dependentAssemblies)
        {
            Hashtable           hashtable    = new Hashtable();
            XmlNamespaceManager namespaceMgr = ManifestGenerator.GetNamespaceMgr(document);
            XmlElement          xmlElement   = (XmlElement)document.SelectSingleNode("/asmv1:assembly", namespaceMgr);

            foreach (DependentAssembly dependentAssembly in dependentAssemblies)
            {
                if (!hashtable.Contains((object)dependentAssembly.Identity))
                {
                    XmlElement element1 = document.CreateElement("dependency", "urn:schemas-microsoft-com:asm.v1");
                    xmlElement.AppendChild((XmlNode)element1);
                    XmlElement element2 = document.CreateElement("dependentAssembly", "urn:schemas-microsoft-com:asm.v1");
                    element1.AppendChild((XmlNode)element2);
                    ReferenceIdentity  identity = dependentAssembly.Identity;
                    DefinitionIdentity asmId    = new DefinitionIdentity(identity);
                    XmlElement         assemblyIdentityElement = ManifestGenerator.CreateAssemblyIdentityElement(document, asmId);
                    element2.AppendChild((XmlNode)assemblyIdentityElement);
                    hashtable.Add((object)identity, (object)asmId);
                }
            }
        }
Example #7
0
        private static void InjectIdentityXml(XmlDocument document, DefinitionIdentity asmId)
        {
            XmlElement assemblyIdentityElement = ManifestGenerator.CreateAssemblyIdentityElement(document, asmId);

            document.DocumentElement.AppendChild((XmlNode)assemblyIdentityElement);
        }