[msitools: 1/2] Add IniFile support to Wixl.




commit e246a4f8506b2186b0998441f5bbe416782b47a3
Author: roblabla <unfiltered roblab la>
Date:   Sat Nov 13 02:42:17 2021 +0100

    Add IniFile support to Wixl.
    
    The <IniFile> tag allows creating INI files from an MSI installer. It
    works by populating two MSI tables, IniFile and RemoveIniFile, with
    the filename, section, key and values to add/remove, and scheduling two
    new steps, WriteIniValues and RemoveIniValues, when those tables are not
    empty.

 tools/wixl/builder.vala | 31 ++++++++++++++++++++++++++++
 tools/wixl/msi.vala     | 54 +++++++++++++++++++++++++++++++++++++++++++++++++
 tools/wixl/wix.vala     | 20 ++++++++++++++++++
 3 files changed, 105 insertions(+)
---
diff --git a/tools/wixl/builder.vala b/tools/wixl/builder.vala
index 319006d..193f546 100644
--- a/tools/wixl/builder.vala
+++ b/tools/wixl/builder.vala
@@ -223,6 +223,12 @@ namespace Wixl {
                 add (MSIDefault.Action.RemoveRegistryValues);
                 add (MSIDefault.Action.WriteRegistryValues);
             }
+            if (db.table_ini_file.records.length () > 0) {
+                add (MSIDefault.Action.WriteIniValues);
+            }
+            if (db.table_remove_ini_file.records.length () > 0) {
+                add (MSIDefault.Action.RemoveIniValues);
+            }
             if (db.table_shortcut.records.length () > 0) {
                 add (MSIDefault.Action.RemoveShortcuts);
                 add (MSIDefault.Action.CreateShortcuts);
@@ -810,6 +816,31 @@ namespace Wixl {
             visit_key_element (file);
         }
 
+        enum IniFileAction {
+            [Description (nick = "addLine")]
+            addLine = 0,
+            [Description (nick = "createLine")]
+            createLine = 1,
+            [Description (nick = "removeLine")]
+            removeLine = 2,
+            [Description (nick = "addTag")]
+            addTag = 3,
+            [Description (nick = "removeTag")]
+            removeTag = 4;
+            public static IniFileAction from_string(string s) throws GLib.Error {
+                return enum_from_string<IniFileAction> (s);
+            }
+        }
+        public override void visit_ini_file (WixIniFile inifile) throws GLib.Error {
+            var component = inifile.parent as WixComponent;
+            var action = IniFileAction.from_string (inifile.Action);
+
+            if (action == IniFileAction.addLine || action == IniFileAction.createLine || action == 
IniFileAction.addTag)
+                db.table_ini_file.add (inifile.Id, inifile.Name, inifile.Directory, inifile.Section, 
inifile.Key, inifile.Value, action, component.Id);
+            else
+                db.table_remove_ini_file.add (inifile.Id, inifile.Name, inifile.Directory, inifile.Section, 
inifile.Key, inifile.Value, action, component.Id);
+        }
+
         public override void visit_shortcut (WixShortcut shortcut) throws GLib.Error {
             string? directory = shortcut.Directory;
 
diff --git a/tools/wixl/msi.vala b/tools/wixl/msi.vala
index 495597e..0da92ee 100644
--- a/tools/wixl/msi.vala
+++ b/tools/wixl/msi.vala
@@ -956,6 +956,54 @@ namespace Wixl {
         }
     }
 
+    /* https://docs.microsoft.com/en-us/windows/win32/msi/inifile-table */
+    class MsiTableIniFile: MsiTable {
+        static construct {
+            name = "IniFile";
+            sql_create = "CREATE TABLE `IniFile` (`IniFile` CHAR(72) NOT NULL, `FileName` CHAR(255) NOT NULL 
LOCALIZABLE, `DirProperty` CHAR(72), `Section` CHAR(255) NOT NULL LOCALIZABLE, `Key` CHAR(255) NOT NULL 
LOCALIZABLE, `Value` CHAR(255) NOT NULL LOCALIZABLE, `Action` INT NOT NULL, `Component_` CHAR(72) NOT NULL 
PRIMARY KEY `IniFile`)";
+            sql_insert = "INSERT INTO `IniFile` (`IniFile`, `FileName`, `DirProperty`, `Section`, `Key`, 
Value`, `Action`, `Component_`) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
+        }
+
+        public void add (string IniFile, string FileName, string DirProperty, string Section, string Key, 
string Value, int Action, string Component) throws GLib.Error {
+            var rec = new Libmsi.Record (8);
+            if (!rec.set_string (1, IniFile) ||
+                !rec.set_string (2, FileName) ||
+                !rec.set_string (3, DirProperty) ||
+                !rec.set_string (4, Section) ||
+                !rec.set_string (5, Key) ||
+                !rec.set_string (6, Value) ||
+                !rec.set_int (7, Action) ||
+                !rec.set_string (8, Component))
+                throw new Wixl.Error.FAILED ("failed to add record");
+
+            records.append (rec);
+        }
+    }
+    /* https://docs.microsoft.com/en-us/windows/win32/msi/removeinifile-table */
+    class MsiTableRemoveIniFile: MsiTable {
+        static construct {
+            name = "RemoveIniFile";
+            sql_create = "CREATE TABLE `RemoveIniFile` (`RemoveIniFile` CHAR(72) NOT NULL, `FileName` 
CHAR(255) NOT NULL LOCALIZABLE, `DirProperty` CHAR(72), `Section` CHAR(255) NOT NULL LOCALIZABLE, `Key` 
CHAR(255) NOT NULL LOCALIZABLE, `Value` CHAR(255) LOCALIZABLE, `Action` INT NOT NULL, `Component_` CHAR(72) 
NOT NULL PRIMARY KEY `RemoveIniFile`)";
+            sql_insert = "INSERT INTO `RemoveIniFile` (`RemoveIniFile`, `FileName`, `DirProperty`, 
`Section`, `Key`, Value`, `Action`, `Component_`) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
+        }
+
+        public void add (string IniFile, string FileName, string DirProperty, string Section, string Key, 
string? Value, int Action, string Component) throws GLib.Error {
+            var rec = new Libmsi.Record (8);
+            if (!rec.set_string (1, IniFile) ||
+                !rec.set_string (2, FileName) ||
+                !rec.set_string (3, DirProperty) ||
+                !rec.set_string (4, Section) ||
+                !rec.set_string (5, Key) ||
+                !rec.set_string (6, Value) ||
+                !rec.set_int (7, Action) ||
+                !rec.set_string (8, Component))
+                throw new Wixl.Error.FAILED ("failed to add record");
+
+            records.append (rec);
+        }
+    }
+
+
     class MsiSummaryInfo: Object {
         public Libmsi.SummaryInfo properties;
 
@@ -1040,6 +1088,8 @@ namespace Wixl {
         public MsiTableServiceControl table_service_control;
         public MsiTableServiceInstall table_service_install;
         public MsiTableFile table_file;
+        public MsiTableIniFile table_ini_file;
+        public MsiTableRemoveIniFile table_remove_ini_file;
         public MsiTableAdminExecuteSequence table_admin_execute_sequence;
         public MsiTableAdminUISequence table_admin_ui_sequence;
         public MsiTableAdvtExecuteSequence table_advt_execute_sequence;
@@ -1119,6 +1169,8 @@ namespace Wixl {
             table_service_control = new MsiTableServiceControl ();
             table_service_install = new MsiTableServiceInstall ();
             table_file = new MsiTableFile ();
+            table_ini_file = new MsiTableIniFile ();
+            table_remove_ini_file = new MsiTableRemoveIniFile ();
             table_admin_execute_sequence = new MsiTableAdminExecuteSequence ();
             table_admin_ui_sequence = new MsiTableAdminUISequence ();
             table_advt_execute_sequence = new MsiTableAdvtExecuteSequence ();
@@ -1154,6 +1206,8 @@ namespace Wixl {
                     table_service_control,
                     table_service_install,
                     table_file,
+                    table_ini_file,
+                    table_remove_ini_file,
                     table_streams,
                     table_shortcut,
                     table_upgrade,
diff --git a/tools/wixl/wix.vala b/tools/wixl/wix.vala
index 6b9722d..db63e08 100644
--- a/tools/wixl/wix.vala
+++ b/tools/wixl/wix.vala
@@ -43,6 +43,7 @@ namespace Wixl {
         public abstract void visit_remove_folder (WixRemoveFolder rm) throws GLib.Error;
         public abstract void visit_registry_value (WixRegistryValue reg) throws GLib.Error;
         public abstract void visit_file (WixFile reg) throws GLib.Error;
+        public abstract void visit_ini_file (WixIniFile reg) throws GLib.Error;
         public abstract void visit_shortcut (WixShortcut shortcut) throws GLib.Error;
         public abstract void visit_create_folder (WixCreateFolder folder) throws GLib.Error;
         public abstract void visit_fragment (WixFragment fragment) throws GLib.Error;
@@ -448,6 +449,24 @@ namespace Wixl {
         }
     }
 
+    public class WixIniFile: WixElement {
+        static construct {
+            name = "IniFile";
+        }
+
+        public string Action { get; set; }
+        public string Directory { get; set; }
+        public string Key { get; set; }
+        public string Name { get; set; }
+        public string Section { get; set; }
+        public string Value { get; set; }
+
+
+        public override void accept (WixNodeVisitor visitor) throws GLib.Error {
+            visitor.visit_ini_file (this);
+        }
+    }
+
     public class WixRegistryValue: WixKeyElement {
         static construct {
             name = "RegistryValue";
@@ -1098,6 +1117,7 @@ namespace Wixl {
                 typeof (WixRegistryKey),
                 typeof (WixServiceControl),
                 typeof (WixServiceInstall),
+                typeof (WixIniFile),
             });
         }
 


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