[msitools] wixl: add MsiFileHash table



commit f5b7ac49999b1d843176eedb3dc880e8977a5d64
Author: Marc-André Lureau <marcandre lureau gmail com>
Date:   Mon Nov 11 19:39:25 2013 +0100

    wixl: add MsiFileHash table

 tools/wixl/builder.vala |   12 ++++++++++++
 tools/wixl/msi.vala     |   12 ++++++++++--
 tools/wixl/util.vala    |   19 +++++++++++++++++++
 3 files changed, 41 insertions(+), 2 deletions(-)
---
diff --git a/tools/wixl/builder.vala b/tools/wixl/builder.vala
index 130cdf3..22233fe 100644
--- a/tools/wixl/builder.vala
+++ b/tools/wixl/builder.vala
@@ -198,6 +198,17 @@ namespace Wixl {
         }
 
         List<WixMedia> medias;
+        private void hash_files () throws GLib.Error {
+            foreach (var rec in db.table_file.records) {
+                var f = rec.get_data<WixFile> ("wixfile");
+                var component = f.parent as WixComponent;
+                if (component.in_feature.length () == 0)
+                    continue;
+
+                db.table_file_hash.add_with_file (f.Id, f.file);
+            }
+        }
+
         private void build_cabinet () throws GLib.Error {
             var sequence = 0;
 
@@ -262,6 +273,7 @@ namespace Wixl {
             property_update ();
             shortcut_target ();
             sequence_actions ();
+            hash_files ();
             build_cabinet ();
 
             return db;
diff --git a/tools/wixl/msi.vala b/tools/wixl/msi.vala
index 61e34d3..ee61dd6 100644
--- a/tools/wixl/msi.vala
+++ b/tools/wixl/msi.vala
@@ -20,7 +20,6 @@ namespace Wixl {
         }
     }
 
-#if 0
     class MsiTableFileHash: MsiTable {
         static construct {
             name = "MsiFileHash";
@@ -43,8 +42,14 @@ namespace Wixl {
 
             records.append (rec);
         }
+
+        public void add_with_file (string FileId, File file) throws GLib.Error {
+            int hash1 = 0, hash2 = 0, hash3 = 0, hash4 = 0;
+
+            compute_md5 (file, ref hash1, ref hash2, ref hash3, ref hash4);
+            add (FileId, hash1, hash2, hash3, hash4);
+        }
     }
-#endif
 
     class MsiTableIcon: MsiTable {
         static construct {
@@ -789,6 +794,7 @@ namespace Wixl {
         public MsiTableRegLocator table_reg_locator;
         public MsiTableCreateFolder table_create_folder;
         public MsiTableSignature table_signature;
+        public MsiTableFileHash table_file_hash;
 
         public HashTable<string, MsiTable> tables;
 
@@ -854,6 +860,7 @@ namespace Wixl {
             table_custom_action = new MsiTableCustomAction ();
             table_reg_locator = new MsiTableRegLocator ();
             table_create_folder = new MsiTableCreateFolder ();
+            table_file_hash = new MsiTableFileHash ();
 
             foreach (var t in new MsiTable[] {
                     table_admin_execute_sequence,
@@ -883,6 +890,7 @@ namespace Wixl {
                     table_custom_action,
                     table_reg_locator,
                     table_create_folder,
+                    table_file_hash,
                     new MsiTableError (),
                     new MsiTableValidation ()
                 }) {
diff --git a/tools/wixl/util.vala b/tools/wixl/util.vala
index d91baca..ca2183c 100644
--- a/tools/wixl/util.vala
+++ b/tools/wixl/util.vala
@@ -168,6 +168,25 @@ namespace Wixl {
         return -1;
     }
 
+    public void compute_md5 (File file, ref int hash1, ref int hash2, ref int hash3, ref int hash4) throws 
GLib.Error {
+        var checksum = new Checksum (ChecksumType.MD5);
+        var stream = file.read ();
+        uint8 fbuf[4096];
+        size_t size;
+
+        while ((size = stream.read (fbuf)) > 0) {
+            checksum.update (fbuf, size);
+        }
+
+        int buffer[4];
+        size_t buflen = 16;
+        checksum.get_digest ((uint8[])buffer, ref buflen);
+        hash1 = buffer[0];
+        hash2 = buffer[1];
+        hash3 = buffer[2];
+        hash4 = buffer[3];
+    }
+
     public class UnixInputStream : GLib.InputStream {
         public int fd { get; set construct; }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]