From 49f1209035aac1fcfad5dbbe25f7b2306d3be86c Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Thu, 7 Dec 2017 14:19:05 -0800 Subject: Support MSI backends creating custom tables and remove WixToolset.Data.WindowsInstaller --- .../Msi/Database.cs | 65 ++-------------------- .../Msi/WixInvalidIdtException.cs | 33 +++++++++++ 2 files changed, 39 insertions(+), 59 deletions(-) create mode 100644 src/WixToolset.Core.WindowsInstaller/Msi/WixInvalidIdtException.cs (limited to 'src/WixToolset.Core.WindowsInstaller/Msi') diff --git a/src/WixToolset.Core.WindowsInstaller/Msi/Database.cs b/src/WixToolset.Core.WindowsInstaller/Msi/Database.cs index 801ebdde..ccb0e6cf 100644 --- a/src/WixToolset.Core.WindowsInstaller/Msi/Database.cs +++ b/src/WixToolset.Core.WindowsInstaller/Msi/Database.cs @@ -3,13 +3,11 @@ namespace WixToolset.Msi { using System; - using System.ComponentModel; using System.Globalization; using System.IO; - using System.Text; using System.Threading; - using WixToolset.Data; using WixToolset.Core.Native; + using WixToolset.Data; /// /// Wrapper class for managing MSI API database handles. @@ -25,8 +23,7 @@ namespace WixToolset.Msi /// Persist mode to use when opening the database. public Database(string path, OpenDatabase type) { - uint handle = 0; - int error = MsiInterop.MsiOpenDatabase(path, new IntPtr((int)type), out handle); + int error = MsiInterop.MsiOpenDatabase(path, new IntPtr((int)type), out var handle); if (0 != error) { throw new MsiException(error); @@ -153,9 +150,9 @@ namespace WixToolset.Msi /// Specifies the name of the exported table archive file. public void Export(string tableName, string folderPath, string fileName) { - if (null == folderPath || 0 == folderPath.Length) + if (String.IsNullOrEmpty(folderPath)) { - folderPath = System.Environment.CurrentDirectory; + folderPath = Environment.CurrentDirectory; } int error = MsiInterop.MsiDatabaseExport(this.Handle, tableName, folderPath, fileName); @@ -241,63 +238,13 @@ namespace WixToolset.Msi /// primary key columns for a specified table. public Record PrimaryKeys(string tableName) { - uint recordHandle; - int error = MsiInterop.MsiDatabaseGetPrimaryKeys(this.Handle, tableName, out recordHandle); - if (0 != error) + var error = MsiInterop.MsiDatabaseGetPrimaryKeys(this.Handle, tableName, out var recordHandle); + if (error != 0) { throw new MsiException(error); } return new Record(recordHandle); } - - /// - /// Imports a table into the database. - /// - /// Codepage of the database to import table to. - /// Table to import into database. - /// The base directory where intermediate files are created. - /// Whether to keep columns added in a transform. - public void ImportTable(int codepage, Table table, string baseDirectory, bool keepAddedColumns) - { - // write out the table to an IDT file - string idtPath = Path.Combine(baseDirectory, String.Concat(table.Name, ".idt")); - Encoding encoding; - - // If UTF8 encoding, use the UTF8-specific constructor to avoid writing - // the byte order mark at the beginning of the file - if (Encoding.UTF8.CodePage == codepage) - { - encoding = new UTF8Encoding(false, true); - } - else - { - if (0 == codepage) - { - codepage = Encoding.ASCII.CodePage; - } - - encoding = Encoding.GetEncoding(codepage, new EncoderExceptionFallback(), new DecoderExceptionFallback()); - } - - using (StreamWriter idtWriter = new StreamWriter(idtPath, false, encoding)) - { - table.ToIdtDefinition(idtWriter, keepAddedColumns); - } - - // try to import the table into the MSI - try - { - this.Import(idtPath); - } - catch (WixInvalidIdtException) - { - table.ValidateRows(); - - // If ValidateRows finds anything it doesn't like, it throws. Otherwise, we'll - // throw WixInvalidIdtException here which is caught in light and turns off tidy. - throw new WixInvalidIdtException(idtPath, table.Name); - } - } } } diff --git a/src/WixToolset.Core.WindowsInstaller/Msi/WixInvalidIdtException.cs b/src/WixToolset.Core.WindowsInstaller/Msi/WixInvalidIdtException.cs new file mode 100644 index 00000000..a603d5a7 --- /dev/null +++ b/src/WixToolset.Core.WindowsInstaller/Msi/WixInvalidIdtException.cs @@ -0,0 +1,33 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +namespace WixToolset.Msi +{ + using System; + using WixToolset.Data; + + /// + /// WiX invalid idt exception. + /// + [Serializable] + public sealed class WixInvalidIdtException : WixException + { + /// + /// Instantiate a new WixInvalidIdtException. + /// + /// The invalid idt file. + public WixInvalidIdtException(string idtFile) : + base(WixDataErrors.InvalidIdt(new SourceLineNumber(idtFile), idtFile)) + { + } + + /// + /// Instantiate a new WixInvalidIdtException. + /// + /// The invalid idt file. + /// The table name of the invalid idt file. + public WixInvalidIdtException(string idtFile, string tableName) : + base(WixDataErrors.InvalidIdt(new SourceLineNumber(idtFile), idtFile, tableName)) + { + } + } +} -- cgit v1.2.3-55-g6feb