Exemplo n.º 1
0
 public static void FixResourceCase(AssemblyManifestDeclaration manifest)
 {
     foreach (var resource in manifest.Resources)
     {
         if (resource.Name.StartsWith("costura.", StringComparison.OrdinalIgnoreCase))
         {
             resource.Name = resource.Name.ToLowerInvariant();
         }
     }
 }
Exemplo n.º 2
0
        public override bool Execute()
        {
            // Find configuration:
            var annotations =
                annotationsService.GetAnnotationsOfType(typeof(PackerAttribute), false, true);
            PackerAttribute config = new PackerAttribute();

            if (annotations.MoveNext())
            {
                config = Configuration.Read(annotations.Current);
            }

            // Find gatherable assemblies:
            string[] paths = Project.Properties["ReferenceCopyLocalPaths"]?.Split('|') ?? new string[0];

            AssemblyManifestDeclaration manifest = Project.Module.AssemblyManifest;

            // I have no idea what this is doing:
            ResourceCaseFixer.FixResourceCase(manifest);

            // Embed resources:
            var  checksums = new Checksums();
            bool unmanagedFromProcessor = NativeResourcesProcessor.ProcessNativeResources(manifest, !config.DisableCompression, checksums);
            var  resourceEmbedder       = new ResourceEmbedder(manifest);

            resourceEmbedder.EmbedResources(config, paths, checksums);
            bool unmanagedFromEmbedder = resourceEmbedder.HasUnmanaged;

            // Load references:
            var assets = new Assets(Project.Module);
            AssemblyLoaderInfo info = AssemblyLoaderInfo.LoadAssemblyLoader(config.CreateTemporaryAssemblies,
                                                                            unmanagedFromEmbedder || unmanagedFromProcessor,
                                                                            Project.Module);

            // Alter code:
            string resourcesHash = ResourceHash.CalculateHash(manifest);

            new AttachCallSynthesis().SynthesizeCallToAttach(config, Project, info);
            new ResourceNameFinder(info, manifest, assets).FillInStaticConstructor(
                config.CreateTemporaryAssemblies,
                config.PreloadOrder,
                resourcesHash,
                checksums);

            return(true);
        }
Exemplo n.º 3
0
        public static string CalculateHash(AssemblyManifestDeclaration manifest)
        {
            var data = manifest.Resources
                       .OrderBy(r => r.Name)
                       .Where(r => r.Name.StartsWith("costura"))
                       .Select(r => r.ContentStreamProvider())
                       .ToArray();
            ConcatenatedStream allStream = new ConcatenatedStream(data);

            using (var md5 = MD5.Create())
            {
                var hashBytes = md5.ComputeHash(allStream);

                var sb = new StringBuilder();
                for (var i = 0; i < hashBytes.Length; i++)
                {
                    sb.Append(hashBytes[i].ToString("X2"));
                }

                allStream.ResetAllToZero();
                return(sb.ToString());
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Calculates checksums for costura-processed unmanaged resources of the assembly, and returns true if
        /// any unprocessed resources exist.
        /// </summary>
        public static bool ProcessNativeResources(AssemblyManifestDeclaration manifest, bool compress, Checksums checksums)
        {
            var  unprocessedNameMatch = new Regex(@"^(.*\.)?costura(32|64)\.", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
            var  processedNameMatch   = new Regex(@"^costura(32|64)\.", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
            bool hasUnmanaged         = false;

            foreach (var resource in manifest.Resources)
            {
                var match = unprocessedNameMatch.Match(resource.Name);
                if (match.Success)
                {
                    resource.Name = resource.Name.Substring(match.Groups[1].Length).ToLowerInvariant();
                    hasUnmanaged  = true;
                }

                if (processedNameMatch.IsMatch(resource.Name))
                {
                    using (var stream = resource.ContentStreamProvider())
                    {
                        if (compress && resource.Name.EndsWith(".compressed", StringComparison.OrdinalIgnoreCase))
                        {
                            using (var compressStream = new DeflateStream(stream, CompressionMode.Decompress))
                            {
                                checksums.Add(resource.Name, Checksums.CalculateChecksum(compressStream));
                            }
                        }
                        else
                        {
                            checksums.Add(resource.Name, Checksums.CalculateChecksum(stream));
                        }
                    }
                }
            }

            return(hasUnmanaged);
        }
 public ResourceNameFinder(AssemblyLoaderInfo info, AssemblyManifestDeclaration manifest, Assets assets)
 {
     this.info     = info;
     this.manifest = manifest;
     this.assets   = assets;
 }
Exemplo n.º 6
0
 public AssemblyTreeNode( AssemblyManifestDeclaration assembly ) : base( assembly, TreeViewImage.Assembly )
 {
     this.Text = assembly.Name;
 }
Exemplo n.º 7
0
 public ResourceEmbedder(AssemblyManifestDeclaration manifest)
 {
     this.manifest = manifest;
 }
 public AssemblyTreeNode(AssemblyManifestDeclaration assembly) : base(assembly, TreeViewImage.Assembly)
 {
     this.Text = assembly.Name;
 }