Example #1
0
        protected override void AppendDefaultVersionResource(Stream resourceStream)
        {
            var    sourceAssembly = SourceAssembly;
            string fileVersion    = sourceAssembly.FileVersion ?? sourceAssembly.Identity.Version.ToString();

            Win32ResourceConversions.AppendVersionToResourceStream(resourceStream,
                                                                   !this.Options.OutputKind.IsApplication(),
                                                                   fileVersion: fileVersion,
                                                                   originalFileName: this.SourceModule.Name,
                                                                   internalName: this.SourceModule.Name,
                                                                   productVersion: sourceAssembly.InformationalVersion ?? fileVersion,
                                                                   fileDescription: sourceAssembly.Title ?? " ",    //alink would give this a blank if nothing was supplied.
                                                                   legalCopyright: sourceAssembly.Copyright ?? " ", //alink would give this a blank if nothing was supplied.
                                                                   legalTrademarks: sourceAssembly.Trademark,
                                                                   productName: sourceAssembly.Product,
                                                                   comments: sourceAssembly.Description,
                                                                   companyName: sourceAssembly.Company,
                                                                   assemblyVersion: sourceAssembly.Identity.Version
                                                                   );
        }
Example #2
0
        public void BasicResources()
        {
            System.IO.MemoryStream strm = new System.IO.MemoryStream();
            Microsoft.CodeAnalysis.Compilation.AppendNullResource(strm);

            //choose version values such that they would cause overflow when shifted as an int
            Win32ResourceConversions.AppendVersionToResourceStream(strm,
                                                                   true,
                                                                   "41220.41221.41222.41223",
                                                                   "originalFilenameMuddy.dll",
                                                                   "internalNameZep.dll",
                                                                   "41224.41225.41226.41227",      //4 ints
                                                                   new Version(41220, 41220, 41220, 41220),
                                                                   "this is the file description", //the old compiler put blank here if nothing was user-supplied
                                                                   "this is the legal copyright",  //the old compiler put blank here if nothing was user-supplied
                                                                   "this is the legal trademark",
                                                                   "product name the testproduct",
                                                                   "some comments",
                                                                   "testcompany");

            var xmlExpectedVersion = @"<?xml version=""1.0"" encoding=""utf-16""?>
<VersionResource Size=""1124"">
  <VS_FIXEDFILEINFO FileVersionMS=""a104a105"" FileVersionLS=""a106a107"" ProductVersionMS=""a108a109"" ProductVersionLS=""a10aa10b"" />
  <KeyValuePair Key=""Comments"" Value=""some comments"" />
  <KeyValuePair Key=""CompanyName"" Value=""testcompany"" />
  <KeyValuePair Key=""FileDescription"" Value=""this is the file description"" />
  <KeyValuePair Key=""FileVersion"" Value=""41220.41221.41222.41223"" />
  <KeyValuePair Key=""InternalName"" Value=""internalNameZep.dll"" />
  <KeyValuePair Key=""LegalCopyright"" Value=""this is the legal copyright"" />
  <KeyValuePair Key=""LegalTrademarks"" Value=""this is the legal trademark"" />
  <KeyValuePair Key=""OriginalFilename"" Value=""originalFilenameMuddy.dll"" />
  <KeyValuePair Key=""ProductName"" Value=""product name the testproduct"" />
  <KeyValuePair Key=""ProductVersion"" Value=""41224.41225.41226.41227"" />
  <KeyValuePair Key=""Assembly Version"" Value=""41220.41220.41220.41220"" />
</VersionResource>";

            System.IO.MemoryStream mft = new System.IO.MemoryStream();
            var manifestContents       = Resources.ResourceManager.GetObject("defaultWin32Manifest");

            Win32ResourceConversions.AppendManifestToResourceStream(strm, new System.IO.MemoryStream((byte[])manifestContents), false);

            var icon = Resources.ResourceManager.GetObject("Roslyn_ico");

            Win32ResourceConversions.AppendIconToResourceStream(strm, new System.IO.MemoryStream((byte[])icon));

            strm.Position = 0;

            var resources = CvtResFile.ReadResFile(strm);

            foreach (var r in resources)
            {
                if (r.pstringType.Ordinal == 16)    //version
                {
                    string rsrcInXml;

                    unsafe
                    {
                        fixed(byte *p = (r.data))
                        rsrcInXml = Win32Res.VersionResourceToXml((IntPtr)p);
                    }

                    Assert.Equal(xmlExpectedVersion, rsrcInXml);
                }
                else if (r.pstringType.Ordinal == 24)    //manifest
                {
                    Assert.Equal((byte[])manifestContents, r.data);
                }
                else if (r.pstringType.Ordinal == 14)    //icon group
                {
                    //first three words of the data contain 0, 1, iconCount.
                    short[] threeWords = new short[3];

                    unsafe
                    {
                        fixed(byte *p = (r.data))
                        {
                            Marshal.Copy((IntPtr)p, threeWords, 0, 3);
                        }
                    }

                    //find all of the individual icons in the resources.

                    for (short i = 0; i < threeWords[2]; i++)
                    {
                        bool found = false;
                        foreach (var rInner in resources)
                        {
                            if ((rInner.pstringName.Ordinal == i + 1) && //ICON IDs start at 1
                                (rInner.pstringType.Ordinal == 3))       //RT_ICON
                            {
                                found = true;
                                break;
                            }
                        }

                        Assert.True(found);
                    }
                }
            }
        }