FixedFileVersionInfo.cs :  » Installers-Generators » WiX » Microsoft » Deployment » Resources » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Installers Generators » WiX 
WiX » Microsoft » Deployment » Resources » FixedFileVersionInfo.cs
//---------------------------------------------------------------------
// <copyright file="FixedFileVersionInfo.cs" company="Microsoft">
//    Copyright (c) Microsoft Corporation.  All rights reserved.
//    
//    The use and distribution terms for this software are covered by the
//    Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
//    which can be found in the file CPL.TXT at the root of this distribution.
//    By using this software in any fashion, you are agreeing to be bound by
//    the terms of this license.
//    
//    You must not remove this notice, or any other, from this software.
// </copyright>
// <summary>
// Part of the Deployment Tools Foundation project.
// </summary>
//---------------------------------------------------------------------

namespace Microsoft.Deployment.Resources{
    using System;
    using System.IO;
    using System.Text;
    using System.Reflection;
    using System.Collections;
    using System.Globalization;
    using System.Diagnostics.CodeAnalysis;

    internal class FixedFileVersionInfo
    {
        public FixedFileVersionInfo()
        {
            // Set reasonable defaults
            this.signature = 0xFEEF04BD;
            this.structVersion = 0x00010000; // v1.0
            this.FileVersion = new Version(0, 0, 0, 0);
            this.ProductVersion = new Version(0, 0, 0, 0);
            this.FileFlagsMask = VersionBuildTypes.Debug | VersionBuildTypes.Prerelease;
            this.FileFlags = VersionBuildTypes.None;
            this.FileOS = VersionFileOS.NT_WINDOWS32;
            this.FileType = VersionFileType.Application;
            this.FileSubtype = VersionFileSubtype.Unknown;
            this.Timestamp = DateTime.MinValue;
        }

        private uint signature;
        private uint structVersion;

        public Version FileVersion
        {
            get
            {
                return this.fileVersion;
            }

            set
            {
                if (value == null)
                {
                    throw new InvalidOperationException();
                }

                this.fileVersion = value;
            }
        }
        private Version fileVersion;

        public Version ProductVersion
        {
            get
            {
                return this.productVersion;
            }

            set
            {
                if (value == null)
                {
                    throw new InvalidOperationException();
                }

                this.productVersion = value;
            }
        }
        private Version productVersion;

        public VersionBuildTypes FileFlagsMask
        {
            get { return this.fileFlagsMask; }
            set { this.fileFlagsMask = value; }
        }
        private VersionBuildTypes fileFlagsMask;

        public VersionBuildTypes FileFlags
        {
            get { return this.fileFlags; }
            set { this.fileFlags = value; }
        }
        private VersionBuildTypes fileFlags;

        [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        public VersionFileOS FileOS
        {
            get { return this.fileOS; }
            set { this.fileOS = value; }
        }
        private VersionFileOS fileOS;

        public VersionFileType FileType
        {
            get { return this.fileType; }
            set { this.fileType = value; }
        }
        private VersionFileType fileType;

        public VersionFileSubtype FileSubtype
        {
            get { return this.fileSubtype; }
            set { this.fileSubtype = value; }
        }
        private VersionFileSubtype fileSubtype;

        public DateTime Timestamp
        {
            get { return this.timestamp; }
            set { this.timestamp = value; }
        }
        private DateTime timestamp;

        public void Read(BinaryReader reader)
        {
            this.signature = reader.ReadUInt32();
            this.structVersion = reader.ReadUInt32();
            this.fileVersion = UInt64ToVersion(reader.ReadUInt64());
            this.productVersion = UInt64ToVersion(reader.ReadUInt64());
            this.fileFlagsMask = (VersionBuildTypes) reader.ReadInt32();
            this.fileFlags = (VersionBuildTypes) reader.ReadInt32();
            this.fileOS = (VersionFileOS) reader.ReadInt32();
            this.fileType = (VersionFileType) reader.ReadInt32();
            this.fileSubtype = (VersionFileSubtype) reader.ReadInt32();
            this.timestamp = UInt64ToDateTime(reader.ReadUInt64());
        }

        public void Write(BinaryWriter writer)
        {
            writer.Write(this.signature);
            writer.Write(this.structVersion);
            writer.Write(VersionToUInt64(this.fileVersion));
            writer.Write(VersionToUInt64(this.productVersion));
            writer.Write((int) this.fileFlagsMask);
            writer.Write((int) this.fileFlags);
            writer.Write((int) this.fileOS);
            writer.Write((int) this.fileType);
            writer.Write((int) this.fileSubtype);
            writer.Write(DateTimeToUInt64(this.timestamp));
        }

        public static explicit operator FixedFileVersionInfo(byte[] bytesValue)
        {
            FixedFileVersionInfo ffviValue = new FixedFileVersionInfo();
            using (BinaryReader reader = new BinaryReader(new MemoryStream(bytesValue, false)))
            {
                ffviValue.Read(reader);
            }
            return ffviValue;
        }

        public static explicit operator byte[](FixedFileVersionInfo ffviValue)
        {
            const int FFVI_LENGTH = 52;

            byte[] bytesValue = new byte[FFVI_LENGTH];
            using (BinaryWriter writer = new BinaryWriter(new MemoryStream(bytesValue, true)))
            {
                ffviValue.Write(writer);
            }
            return bytesValue;
        }

        private static Version UInt64ToVersion(ulong version)
        {
            return new Version((int) ((version >> 16) & 0xFFFF), (int) (version & 0xFFFF), (int) (version >> 48), (int) ((version >> 32) & 0xFFFF));
        }
        private static ulong VersionToUInt64(Version version)
        {
            return (((ulong) (ushort) version.Major) << 16) | ((ulong) (ushort) version.Minor)
                | (((ulong) (ushort) version.Build) << 48) | (((ulong) (ushort) version.Revision) << 32);
        }

        private static DateTime UInt64ToDateTime(ulong dateTime)
        {
            return (dateTime == 0 ? DateTime.MinValue : DateTime.FromFileTime((long) dateTime));
        }
        private static ulong DateTimeToUInt64(DateTime dateTime)
        {
            return (dateTime == DateTime.MinValue ? 0 : (ulong) dateTime.ToFileTime());
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.