Ejemplo n.º 1
0
        /// <summary>
        /// Sets the codepage of a database.
        /// </summary>
        /// <param name="db">Database to set codepage into.</param>
        /// <param name="output">Output with the codepage for the database.</param>
        private void SetDatabaseCodepage(Database db, Output output)
        {
            // write out the _ForceCodepage IDT file
            string idtPath = String.Concat(this.tempFiles.BasePath, Path.DirectorySeparatorChar, "codepage.idt");
            using (StreamWriter idtFile = new StreamWriter(idtPath, true, Encoding.ASCII))
            {
                idtFile.WriteLine(); // dummy column name record
                idtFile.WriteLine(); // dummy column definition record
                idtFile.Write(output.Codepage);
                idtFile.WriteLine("\t_ForceCodepage");
            }

            // try to import the table into the MSI
            try
            {
                db.Import(Path.GetDirectoryName(idtPath), Path.GetFileName(idtPath));
            }
            catch (System.Configuration.ConfigurationException ce)
            {
                throw new WixInvalidCodepageException(SourceLineNumberCollection.FromFileName(output.Path), output.Codepage, ce);
            }
        }
Ejemplo n.º 2
0
Archivo: Binder.cs Proyecto: zooba/wix3
        /// <summary>
        /// Sets the codepage of a database.
        /// </summary>
        /// <param name="db">Database to set codepage into.</param>
        /// <param name="output">Output with the codepage for the database.</param>
        private void SetDatabaseCodepage(Database db, Output output)
        {
            // write out the _ForceCodepage IDT file
            string idtPath = Path.Combine(this.TempFilesLocation, "_ForceCodepage.idt");
            using (StreamWriter idtFile = new StreamWriter(idtPath, false, Encoding.ASCII))
            {
                idtFile.WriteLine(); // dummy column name record
                idtFile.WriteLine(); // dummy column definition record
                idtFile.Write(output.Codepage);
                idtFile.WriteLine("\t_ForceCodepage");
            }

            // try to import the table into the MSI
            try
            {
                db.Import(Path.GetDirectoryName(idtPath), Path.GetFileName(idtPath));
            }
            catch (WixInvalidIdtException)
            {
                // the IDT should be valid, so an invalid code page was given
                throw new WixException(WixErrors.IllegalCodepage(output.Codepage));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Imports a table into the database.
        /// </summary>
        /// <param name="db">Database to import table to.</param>
        /// <param name="output">Output for current database.</param>
        /// <param name="outputTable">Output table to import into database.</param>
        private void ImportTable(Database db, Output output, OutputTable outputTable)
        {
            // write out the table to an IDT file
            string idtPath = Path.Combine(this.tempFiles.BasePath, String.Concat(outputTable.Name, ".idt"));
            StreamWriter idtWriter = null;

            try
            {
                Encoding encoding = (0 == output.Codepage ? Encoding.ASCII : Encoding.GetEncoding(output.Codepage));

                // this is a workaround to prevent the UTF-8 byte order marking (BOM)
                // from being added to the beginning of the idt file - according to
                // MSDN, the default encoding for StreamWriter is a special UTF-8
                // encoding that returns an empty byte[] from GetPreamble
                if (Encoding.UTF8 == encoding)
                {
                    idtWriter = new StreamWriter(idtPath, false);
                }
                else
                {
                    idtWriter = new StreamWriter(idtPath, false, encoding);
                }

                idtWriter.Write(outputTable.ToIdtDefinition(output.ModularizationGuid, 0 == output.IgnoreModularizations.Count ? null : output.IgnoreModularizations));
            }
            finally
            {
                if (null != idtWriter)
                {
                    idtWriter.Close();
                }
            }

            // try to import the table into the MSI
            try
            {
                db.Import(Path.GetDirectoryName(idtPath), Path.GetFileName(idtPath));
            }
            catch (System.Configuration.ConfigurationException ce)
            {
                throw new WixInvalidIdtException(SourceLineNumberCollection.FromFileName(output.Path), outputTable.Name, idtPath, ce);
            }
        }