/// <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; }
/// <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); } }
/// <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), hashInterop); if (0 != error) { throw new MsiException(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; }