Пример #1
0
 /// <summary>
 /// Adds a file to the cabinet with an optional MSI file hash.
 /// </summary>
 /// <param name="file">The file to add.</param>
 /// <param name="token">The token for the file.</param>
 /// <param name="fileHash">The MSI file hash of the file.</param>
 private void AddFile(string file, string token, MsiInterop.MSIFILEHASHINFO fileHash)
 {
     try
     {
         NativeMethods.CreateCabAddFile(file, token, fileHash, this.handle);
     }
     catch (COMException ce)
     {
         if (0x80004005 == unchecked ((uint)ce.ErrorCode)) // E_FAIL
         {
             throw new WixException(WixErrors.CreateCabAddFileFailed());
         }
         else if (0x80070070 == unchecked ((uint)ce.ErrorCode)) // ERROR_DISK_FULL
         {
             throw new WixException(WixErrors.CreateCabInsufficientDiskSpace());
         }
         else
         {
             throw;
         }
     }
     catch (DirectoryNotFoundException)
     {
         throw new WixFileNotFoundException(file);
     }
     catch (FileNotFoundException)
     {
         throw new WixFileNotFoundException(file);
     }
 }
Пример #2
0
        /// <summary>
        /// Adds a file to the cabinet.
        /// </summary>
        /// <param name="fileRow">The filerow of the file to add.</param>
        public void AddFile(FileRow fileRow)
        {
            MsiInterop.MSIFILEHASHINFO hashInterop = new MsiInterop.MSIFILEHASHINFO();

            if (null != fileRow.HashRow)
            {
                hashInterop.FileHashInfoSize = 20;
                hashInterop.Data0            = (int)fileRow.HashRow[2];
                hashInterop.Data1            = (int)fileRow.HashRow[3];
                hashInterop.Data2            = (int)fileRow.HashRow[4];
                hashInterop.Data3            = (int)fileRow.HashRow[5];

                this.AddFile(fileRow.Source, fileRow.File, hashInterop);
            }
            else
            {
                this.AddFile(fileRow.Source, fileRow.File);
            }
        }
Пример #3
0
        /// <summary>
        /// Adds a file to the cabinet.
        /// </summary>
        /// <param name="fileFacade">The file facade of the file to add.</param>
        public void AddFile(FileFacade fileFacade)
        {
            MsiInterop.MSIFILEHASHINFO hashInterop = new MsiInterop.MSIFILEHASHINFO();

            if (null != fileFacade.Hash)
            {
                hashInterop.FileHashInfoSize = 20;
                hashInterop.Data0            = (int)fileFacade.Hash[2];
                hashInterop.Data1            = (int)fileFacade.Hash[3];
                hashInterop.Data2            = (int)fileFacade.Hash[4];
                hashInterop.Data3            = (int)fileFacade.Hash[5];

                this.AddFile(fileFacade.WixFile.Source, fileFacade.File.File, hashInterop);
            }
            else
            {
                this.AddFile(fileFacade.WixFile.Source, fileFacade.File.File);
            }
        }
Пример #4
0
        /// <summary>
        /// Takes the path to a file and returns a 128-bit hash of that file.
        /// </summary>
        /// <param name="filePath">Path to file that is to be hashed.</param>
        /// <param name="options">The value in this column must be 0. This parameter is reserved for future use.</param>
        /// <param name="hash">Int array that receives the returned file hash information.</param>
        internal static void GetFileHash(string filePath, int options, out int[] hash)
        {
            MsiInterop.MSIFILEHASHINFO hashInterop = new MsiInterop.MSIFILEHASHINFO();
            hashInterop.FileHashInfoSize = 20;

            int error = MsiInterop.MsiGetFileHash(filePath, Convert.ToUInt32(options), ref hashInterop);

            if (0 != error)
            {
                throw new Win32Exception(error);
            }

            Debug.Assert(20 == hashInterop.FileHashInfoSize);

            hash    = new int[4];
            hash[0] = hashInterop.Data0;
            hash[1] = hashInterop.Data1;
            hash[2] = hashInterop.Data2;
            hash[3] = hashInterop.Data3;
        }
Пример #5
0
        /// <summary>
        /// Takes the path to a file and returns a 128-bit hash of that file.
        /// </summary>
        /// <param name="filePath">Path to file that is to be hashed.</param>
        /// <param name="options">The value in this column must be 0. This parameter is reserved for future use.</param>
        /// <param name="hash">Int array that receives the returned file hash information.</param>
        public static void GetFileHash(string filePath, int options, out int[] hash)
        {
            MsiInterop.MSIFILEHASHINFO hashInterop = new MsiInterop.MSIFILEHASHINFO();
            hashInterop.fileHashInfoSize = 20;

            uint er = MsiInterop.MsiGetFileHash(filePath, 0, ref hashInterop);

            if (110 == er)
            {
                throw new System.IO.FileNotFoundException("Failed to find file for hashing.", filePath);
            }
            else if (0 != er)
            {
                throw new ApplicationException(String.Format("Unknown error while getting hash of file: {0}, system error: {1}", filePath, er));   // TODO: come up with a real exception to throw
            }

            hash    = new int[4];
            hash[0] = hashInterop.data0;
            hash[1] = hashInterop.data1;
            hash[2] = hashInterop.data2;
            hash[3] = hashInterop.data3;
        }
Пример #6
0
 internal static extern void CreateCabAddFile(string file, string token, MsiInterop.MSIFILEHASHINFO fileHash, IntPtr contextHandle);