Exemplo n.º 1
0
        /*
         * Dev10 alink had the following fallback behavior.
         *      private uint[] FileVersion
         *      {
         *          get
         *          {
         *              if (fileVersionContents != null)
         *                  return fileVersionContents;
         *              else
         *              {
         *                  System.Diagnostics.Debug.Assert(assemblyVersionContents != null);
         *                  return assemblyVersionContents;
         *              }
         *          }
         *      }
         *
         *      private uint[] ProductVersion
         *      {
         *          get
         *          {
         *              if (productVersionContents != null)
         *                  return productVersionContents;
         *              else
         *                  return this.FileVersion;
         *          }
         *      }
         */

        internal static void AppendVersionToResourceStream(
            Stream resStream,
            bool isDll,
            string fileVersion, //should be [major.minor.build.rev] but doesn't have to be
            string originalFileName,
            string internalName,
            string productVersion,        //4 ints
            Version assemblyVersion,      //individual values must be smaller than 65535
            string fileDescription = " ", //the old compiler put blank here if nothing was user-supplied
            string legalCopyright  = " ", //the old compiler put blank here if nothing was user-supplied
            string?legalTrademarks = null,
            string?productName     = null,
            string?comments        = null,
            string?companyName     = null
            )
        {
            var resWriter = new BinaryWriter(resStream, Encoding.Unicode);

            resStream.Position = (resStream.Position + 3) & ~3;

            const DWORD RT_VERSION = 16;

            var ver = new VersionResourceSerializer(
                isDll,
                comments,
                companyName,
                fileDescription,
                fileVersion,
                internalName,
                legalCopyright,
                legalTrademarks,
                originalFileName,
                productName,
                productVersion,
                assemblyVersion
                );

            var       startPos   = resStream.Position;
            var       dataSize   = ver.GetDataSize();
            const int headerSize = 0x20;

            resWriter.Write((DWORD)dataSize);   //data size
            resWriter.Write((DWORD)headerSize); //header size
            resWriter.Write((WORD)0xFFFF);      //identifies type as ordinal.
            resWriter.Write((WORD)RT_VERSION);  //type
            resWriter.Write((WORD)0xFFFF);      //identifies name as ordinal.
            resWriter.Write((WORD)0x0001);      //only ever 1 ver resource (what Dev10 does)
            resWriter.Write((DWORD)0x00000000); //data version
            resWriter.Write((WORD)0x0030);      //memory flags (this is what the Dev10 compiler uses)
            resWriter.Write((WORD)0x0000);      //languageId
            resWriter.Write((DWORD)0x00000000); //version
            resWriter.Write((DWORD)0x00000000); //characteristics

            ver.WriteVerResource(resWriter);

            System.Diagnostics.Debug.Assert(resStream.Position - startPos == dataSize + headerSize);
        }
Exemplo n.º 2
0
        /*
         * Dev10 alink had the following fallback behavior.
                private uint[] FileVersion
                {
                    get
                    {
                        if (fileVersionContents != null)
                            return fileVersionContents;
                        else
                        {
                            System.Diagnostics.Debug.Assert(assemblyVersionContents != null);
                            return assemblyVersionContents;
                        }
                    }
                }

                private uint[] ProductVersion
                {
                    get
                    {
                        if (productVersionContents != null)
                            return productVersionContents;
                        else
                            return this.FileVersion;
                    }
                }
                */

        internal static void AppendVersionToResourceStream(Stream resStream, bool isDll,
            string fileVersion, //should be [major.minor.build.rev] but doesn't have to be
            string originalFileName,
            string internalName,
            string productVersion,  //4 ints
            Version assemblyVersion, //individual values must be smaller than 65535
            string fileDescription = " ",   //the old compiler put blank here if nothing was user-supplied
            string legalCopyright = " ",    //the old compiler put blank here if nothing was user-supplied
            string legalTrademarks = null,
            string productName = null,
            string comments = null,
            string companyName = null)
        {
            var resWriter = new BinaryWriter(resStream, Encoding.Unicode);
            resStream.Position = (resStream.Position + 3) & ~3;

            const DWORD RT_VERSION = 16;

            var ver = new VersionResourceSerializer(isDll,
                comments,
                companyName,
                fileDescription,
                fileVersion,
                internalName,
                legalCopyright,
                legalTrademarks,
                originalFileName,
                productName,
                productVersion,
                assemblyVersion);

            var startPos = resStream.Position;
            var dataSize = ver.GetDataSize();
            const int headerSize = 0x20;

            resWriter.Write((DWORD)dataSize);    //data size
            resWriter.Write((DWORD)headerSize);                 //header size
            resWriter.Write((WORD)0xFFFF);                      //identifies type as ordinal.
            resWriter.Write((WORD)RT_VERSION);                 //type
            resWriter.Write((WORD)0xFFFF);                      //identifies name as ordinal.
            resWriter.Write((WORD)0x0001);                      //only ever 1 ver resource (what Dev10 does)
            resWriter.Write((DWORD)0x00000000);                 //data version
            resWriter.Write((WORD)0x0030);                      //memory flags (this is what the Dev10 compiler uses)
            resWriter.Write((WORD)0x0000);                      //languageId
            resWriter.Write((DWORD)0x00000000);                 //version
            resWriter.Write((DWORD)0x00000000);                 //characteristics

            ver.WriteVerResource(resWriter);

            System.Diagnostics.Debug.Assert(resStream.Position - startPos == dataSize + headerSize);
        }