예제 #1
0
        /// <summary>
        /// Decompile the MessageQueueGroupPermission table.
        /// </summary>
        /// <param name="table">The table to decompile.</param>
        private void DecompileMessageQueueGroupPermissionTable(Table table)
        {
            foreach (Row row in table.Rows)
            {
                Msmq.MessageQueuePermission queuePermission = new Msmq.MessageQueuePermission();

                queuePermission.Id = (string)row[0];

                if (null != row[2])
                {
                    queuePermission.MessageQueue = (string)row[2];
                }

                queuePermission.Group = (string)row[3];

                DecompileMessageQueuePermissionAttributes(row, queuePermission);

                Wix.Component component = (Wix.Component) this.Core.GetIndexedElement("Component", (string)row[1]);
                if (null != component)
                {
                    component.AddChild(queuePermission);
                }
                else
                {
                    this.Core.OnMessage(WixWarnings.ExpectedForeignRow(row.SourceLineNumbers, table.Name, row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter), "Component_", (string)row[1], "Component"));
                }
            }
        }
        /// <summary>
        /// Harvest a WiX document.
        /// </summary>
        /// <param name="argument">The argument for harvesting.</param>
        /// <returns>The harvested Fragment.</returns>
        public override Wix.Fragment[] Harvest(string argument)
        {
            DirectoryHarvester directoryHarvester = new DirectoryHarvester();

            directoryHarvester.Core = this.Core;
            directoryHarvester.KeepEmptyDirectories = true;

            IIsWebSiteHarvester iisWebSiteHarvester = new IIsWebSiteHarvester();

            iisWebSiteHarvester.Core = this.Core;

            IIs.WebSite webSite = iisWebSiteHarvester.HarvestWebSite(argument);

            Wix.Component component = new Wix.Component();
            component.AddChild(new Wix.CreateFolder());
            component.AddChild(webSite);

            this.Core.RootDirectory = webSite.Directory;
            Wix.Directory directory = directoryHarvester.HarvestDirectory(webSite.Directory, true);
            directory.AddChild(component);

            Wix.Fragment fragment = new Wix.Fragment();
            fragment.AddChild(directory);

            return(new Wix.Fragment[] { fragment });
        }
        /// <summary>
        /// Harvest a file.
        /// </summary>
        /// <param name="argument">The path of the file.</param>
        /// <returns>A harvested file.</returns>
        public override Wix.Fragment[] Harvest(string argument)
        {
            if (null == argument)
            {
                throw new ArgumentNullException("argument");
            }

            if (null == this.rootedDirectoryRef)
            {
                this.rootedDirectoryRef = "TARGETDIR";
            }

            string fullPath = Path.GetFullPath(argument);

            Wix.DirectoryRef directoryRef = new Wix.DirectoryRef();
            directoryRef.Id = this.rootedDirectoryRef;

            Wix.File file = this.HarvestFile(fullPath);

            if (!this.suppressRootDirectory)
            {
                file.Source = String.Concat("SourceDir\\", Path.GetFileName(Path.GetDirectoryName(fullPath)), "\\", Path.GetFileName(fullPath));
            }

            Wix.Component component = new Wix.Component();
            component.AddChild(file);

            Wix.Directory directory = new Wix.Directory();

            if (this.suppressRootDirectory)
            {
                directoryRef.AddChild(component);
            }
            else
            {
                string directoryPath = Path.GetDirectoryName(Path.GetFullPath(argument));
                directory.Name = Path.GetFileName(directoryPath);

                if (this.setUniqueIdentifiers)
                {
                    directory.Id = this.Core.GenerateIdentifier(DirectoryPrefix, directoryRef.Id, directory.Name);
                }
                directory.AddChild(component);
                directoryRef.AddChild(directory);
            }

            if (this.setUniqueIdentifiers)
            {
                file.Id      = this.Core.GenerateIdentifier(FilePrefix, (this.suppressRootDirectory) ? directoryRef.Id : directory.Id, Path.GetFileName(file.Source));
                component.Id = this.Core.GenerateIdentifier(ComponentPrefix, (this.suppressRootDirectory) ? directoryRef.Id : directory.Id, file.Id);
            }

            Wix.Fragment fragment = new Wix.Fragment();
            fragment.AddChild(directoryRef);

            return(new Wix.Fragment[] { fragment });
        }
예제 #4
0
        /// <summary>
        /// Converts the registry key to a WiX component element.
        /// </summary>
        /// <param name="sr">The registry file stream.</param>
        /// <param name="directory">A WiX directory reference.</param>
        /// <param name="root">The root key.</param>
        /// <param name="line">The current line.</param>
        private void ConvertKey(StreamReader sr, ref Wix.Directory directory, Wix.RegistryRootType root, string line)
        {
            Wix.Component component = new Wix.Component();

            component.Id      = this.Core.GenerateIdentifier(ComponentPrefix, line);
            component.KeyPath = Wix.YesNoType.yes;

            this.ConvertValues(sr, ref component, root, line);
            directory.AddChild(component);
        }
예제 #5
0
        /// <summary>
        /// Decompile the MsiDriverPackages table.
        /// </summary>
        /// <param name="table">The table to decompile.</param>
        private void DecompileMsiDriverPackagesTable(Table table)
        {
            foreach (Row row in table.Rows)
            {
                DifxApp.Driver driver = new DifxApp.Driver();

                int attributes = (int)row[1];
                if (0x1 == (attributes & 0x1))
                {
                    driver.ForceInstall = DifxApp.YesNoType.yes;
                }

                if (0x2 == (attributes & 0x2))
                {
                    driver.PlugAndPlayPrompt = DifxApp.YesNoType.no;
                }

                if (0x4 == (attributes & 0x4))
                {
                    driver.AddRemovePrograms = DifxApp.YesNoType.no;
                }

                if (0x8 == (attributes & 0x8))
                {
                    driver.Legacy = DifxApp.YesNoType.yes;
                }

                if (0x10 == (attributes & 0x10))
                {
                    driver.DeleteFiles = DifxApp.YesNoType.yes;
                }

                if (null != row[2])
                {
                    driver.Sequence = (int)row[2];
                }

                Wix.Component component = (Wix.Component) this.Core.GetIndexedElement("Component", (string)row[0]);
                if (null != component)
                {
                    component.AddChild(driver);
                }
                else
                {
                    this.Core.OnMessage(WixWarnings.ExpectedForeignRow(row.SourceLineNumbers, table.Name, row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter), "Component", (string)row[0], "Component"));
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Decompiles the WixDependencyProvider table.
        /// </summary>
        /// <param name="table">The table to decompile.</param>
        private void DecompileWixDependencyProviderTable(Table table)
        {
            foreach (Row row in table.Rows)
            {
                Provides provides = new Provides();

                provides.Id  = (string)row[0];
                provides.Key = (string)row[2];

                if (null != row[3])
                {
                    provides.Version = (string)row[3];
                }

                if (null != row[4])
                {
                    provides.DisplayName = (string)row[4];
                }

                // Nothing to parse for attributes currently.

                Wix.Component component = (Wix.Component) this.Core.GetIndexedElement("Component", (string)row[1]);
                if (null != component)
                {
                    component.AddChild(provides);
                }
                else
                {
                    this.Core.OnMessage(WixWarnings.ExpectedForeignRow(row.SourceLineNumbers, table.Name, row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter), "Component_", (string)row[1], "Component"));
                }

                // Index the provider to parent the RequiresRef elements.
                this.Core.IndexElement(row, provides);

                // Add the provider-specific registry keys to be removed during finalization.
                // Only remove specific keys that the compiler writes.
                string keyProvides = String.Concat(DependencyCommon.RegistryRoot, provides.Key);

                this.registryValues.Add(keyProvides, null);
                this.registryValues.Add(keyProvides, "Version");
                this.registryValues.Add(keyProvides, "DisplayName");
                this.registryValues.Add(keyProvides, "Attributes");

                // Cache the provider key.
                this.keyCache[provides.Id] = provides.Key;
            }
        }
예제 #7
0
        /// <summary>
        /// Walks a directory structure obtaining Component Id's and Standard Directory Id's.
        /// </summary>
        /// <param name="directory">The Directory to walk.</param>
        /// <returns>true if the directory is TARGETDIR.</returns>
        private bool WalkDirectory(Wix.Directory directory)
        {
            bool isTargetDir = false;

            if ("TARGETDIR" == directory.Id)
            {
                isTargetDir = true;
            }

            string standardDirectoryId = null;

            if (Melter.StartsWithStandardDirectoryId(directory.Id, out standardDirectoryId) && !isTargetDir)
            {
                this.AddSetPropertyCustomAction(directory.Id, String.Format(CultureInfo.InvariantCulture, "[{0}]", standardDirectoryId));
            }

            foreach (Wix.ISchemaElement child in directory.Children)
            {
                Wix.Directory childDir = child as Wix.Directory;
                if (null != childDir)
                {
                    if (isTargetDir)
                    {
                        this.primaryDirectoryRef.AddChild(child);
                    }
                    this.WalkDirectory(childDir);
                }
                else
                {
                    Wix.Component childComponent = child as Wix.Component;
                    if (null != childComponent)
                    {
                        if (isTargetDir)
                        {
                            this.primaryDirectoryRef.AddChild(child);
                        }
                        this.AddComponentRef(childComponent);
                    }
                }
            }

            return(isTargetDir);
        }
        /// <summary>
        /// Mutate the WebFilter elements.
        /// </summary>
        private void MutateWebFilters()
        {
            IdentifierGenerator identifierGenerator = null;

            if (this.setUniqueIdentifiers)
            {
                identifierGenerator = new IdentifierGenerator("WebFilter");

                // index all the existing identifiers and names
                foreach (IIs.WebFilter webFilter in this.webFilters)
                {
                    if (null != webFilter.Id)
                    {
                        identifierGenerator.IndexExistingIdentifier(webFilter.Id);
                    }
                    else
                    {
                        identifierGenerator.IndexName(webFilter.Name);
                    }
                }
            }

            foreach (IIs.WebFilter webFilter in this.webFilters)
            {
                if (this.setUniqueIdentifiers && null == webFilter.Id)
                {
                    webFilter.Id = identifierGenerator.GetIdentifier(webFilter.Name);
                }

                // harvest the file for this WebFilter
                Wix.Directory directory = this.HarvestUniqueDirectory(Path.GetDirectoryName(webFilter.Path), false);

                Wix.Component component = new Wix.Component();
                directory.AddChild(component);

                Wix.File file = this.fileHarvester.HarvestFile(webFilter.Path);
                component.AddChild(file);
            }
        }
        /// <summary>
        /// Harvest a performance category.
        /// </summary>
        /// <param name="argument">The name of the performance category.</param>
        /// <returns>A harvested performance category.</returns>
        public override Wix.Fragment[] Harvest(string argument)
        {
            if (null == argument)
            {
                throw new ArgumentNullException("argument");
            }

            Util.PerformanceCategory perf = this.HarvestPerformanceCategory(argument);

            Wix.Component component = new Wix.Component();
            component.Id      = this.Core.CreateIdentifierFromFilename(argument);
            component.KeyPath = Wix.YesNoType.yes;
            component.AddChild(perf);

            Wix.Directory directory = new Wix.Directory();
            directory.Id = "TARGETDIR";
            //directory.Name = directory.Id;
            directory.AddChild(component);

            Wix.Fragment fragment = new Wix.Fragment();
            fragment.AddChild(directory);

            return(new Wix.Fragment[] { fragment });
        }
        /// <summary>
        /// Mutate the Component elements.
        /// </summary>
        private void MutateComponents()
        {
            if (this.setUniqueIdentifiers)
            {
                IdentifierGenerator identifierGenerator = new IdentifierGenerator("Component");

                // index all the existing identifiers
                foreach (Wix.Component component in this.components)
                {
                    if (null != component.Id)
                    {
                        identifierGenerator.IndexExistingIdentifier(component.Id);
                    }
                }

                // index all the web site identifiers
                foreach (IIs.WebSite webSite in this.webSites)
                {
                    if (webSite.ParentElement is Wix.Component)
                    {
                        identifierGenerator.IndexName(webSite.Id);
                    }
                }

                // create an identifier for each component based on its child web site identifier
                foreach (IIs.WebSite webSite in this.webSites)
                {
                    Wix.Component component = webSite.ParentElement as Wix.Component;

                    if (null != component)
                    {
                        component.Id = identifierGenerator.GetIdentifier(webSite.Id);
                    }
                }
            }
        }
예제 #11
0
        /// <summary>
        /// Decompile the WixHttpUrlReservation table.
        /// </summary>
        /// <param name="table">The table to decompile.</param>
        private void DecompileWixHttpUrlReservationTable(Table table)
        {
            foreach (Row row in table.Rows)
            {
                Http.UrlReservation urlReservation = new Http.UrlReservation();
                urlReservation.Id = (string)row[0];
                switch ((int)row[1])
                {
                case HttpConstants.heReplace:
                default:
                    urlReservation.HandleExisting = Http.UrlReservation.HandleExistingType.replace;
                    break;

                case HttpConstants.heIgnore:
                    urlReservation.HandleExisting = Http.UrlReservation.HandleExistingType.ignore;
                    break;

                case HttpConstants.heFail:
                    urlReservation.HandleExisting = Http.UrlReservation.HandleExistingType.fail;
                    break;
                }
                urlReservation.Sddl = (string)row[2];
                urlReservation.Url  = (string)row[3];

                Wix.Component component = (Wix.Component) this.Core.GetIndexedElement("Component", (string)row[4]);
                if (null != component)
                {
                    component.AddChild(urlReservation);
                }
                else
                {
                    this.Core.OnMessage(WixWarnings.ExpectedForeignRow(row.SourceLineNumbers, table.Name, row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter), "Component_", (string)row[2], "Component"));
                }
                this.Core.IndexElement(row, urlReservation);
            }
        }
예제 #12
0
        /// <summary>
        /// Decompile the MessageQueue table.
        /// </summary>
        /// <param name="table">The table to decompile.</param>
        private void DecompileMessageQueueTable(Table table)
        {
            foreach (Row row in table.Rows)
            {
                Msmq.MessageQueue queue = new Msmq.MessageQueue();

                queue.Id = (string)row[0];

                if (null != row[2])
                {
                    queue.BasePriority = (int)row[2];
                }

                if (null != row[3])
                {
                    queue.JournalQuota = (int)row[3];
                }

                queue.Label = (string)row[4];

                if (null != row[5])
                {
                    queue.MulticastAddress = (string)row[5];
                }

                queue.PathName = (string)row[6];

                if (null != row[7])
                {
                    switch ((MsmqCompiler.MqiMessageQueuePrivacyLevel)row[7])
                    {
                    case MsmqCompiler.MqiMessageQueuePrivacyLevel.None:
                        queue.PrivLevel = Msmq.MessageQueue.PrivLevelType.none;
                        break;

                    case MsmqCompiler.MqiMessageQueuePrivacyLevel.Optional:
                        queue.PrivLevel = Msmq.MessageQueue.PrivLevelType.optional;
                        break;

                    case MsmqCompiler.MqiMessageQueuePrivacyLevel.Body:
                        queue.PrivLevel = Msmq.MessageQueue.PrivLevelType.body;
                        break;

                    default:
                        break;
                    }
                }

                if (null != row[8])
                {
                    queue.Quota = (int)row[8];
                }

                if (null != row[9])
                {
                    queue.ServiceTypeGuid = (string)row[9];
                }

                int attributes = (int)row[10];

                if (0 != (attributes & (int)MsmqCompiler.MqiMessageQueueAttributes.Authenticate))
                {
                    queue.Authenticate = Msmq.YesNoType.yes;
                }

                if (0 != (attributes & (int)MsmqCompiler.MqiMessageQueueAttributes.Journal))
                {
                    queue.Journal = Msmq.YesNoType.yes;
                }

                if (0 != (attributes & (int)MsmqCompiler.MqiMessageQueueAttributes.Transactional))
                {
                    queue.Transactional = Msmq.YesNoType.yes;
                }

                Wix.Component component = (Wix.Component) this.Core.GetIndexedElement("Component", (string)row[1]);
                if (null != component)
                {
                    component.AddChild(queue);
                }
                else
                {
                    this.Core.OnMessage(WixWarnings.ExpectedForeignRow(row.SourceLineNumbers, table.Name, row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter), "Component_", (string)row[1], "Component"));
                }
            }
        }
예제 #13
0
        /// <summary>
        /// Decompile the WixFirewallException table.
        /// </summary>
        /// <param name="table">The table to decompile.</param>
        private void DecompileWixFirewallExceptionTable(Table table)
        {
            foreach (Row row in table.Rows)
            {
                Firewall.FirewallException fire = new Firewall.FirewallException();
                fire.Id   = (string)row[0];
                fire.Name = (string)row[1];

                string[] addresses = ((string)row[2]).Split(',');
                if (1 == addresses.Length)
                {
                    // special-case the Scope attribute values
                    if ("*" == addresses[0])
                    {
                        fire.Scope = Firewall.FirewallException.ScopeType.any;
                    }
                    else if ("LocalSubnet" == addresses[0])
                    {
                        fire.Scope = Firewall.FirewallException.ScopeType.localSubnet;
                    }
                    else
                    {
                        FirewallDecompiler.AddRemoteAddress(fire, addresses[0]);
                    }
                }
                else
                {
                    foreach (string address in addresses)
                    {
                        FirewallDecompiler.AddRemoteAddress(fire, address);
                    }
                }

                if (!row.IsColumnEmpty(3))
                {
                    fire.Port = (string)row[3];
                }

                if (!row.IsColumnEmpty(4))
                {
                    switch (Convert.ToInt32(row[4]))
                    {
                    case FirewallConstants.NET_FW_IP_PROTOCOL_TCP:
                        fire.Protocol = Firewall.FirewallException.ProtocolType.tcp;
                        break;

                    case FirewallConstants.NET_FW_IP_PROTOCOL_UDP:
                        fire.Protocol = Firewall.FirewallException.ProtocolType.udp;
                        break;
                    }
                }

                if (!row.IsColumnEmpty(5))
                {
                    fire.Program = (string)row[5];
                }

                if (!row.IsColumnEmpty(6))
                {
                    int attr = Convert.ToInt32(row[6]);
                    if (0x1 == (attr & 0x1)) // feaIgnoreFailures
                    {
                        fire.IgnoreFailure = Firewall.YesNoType.yes;
                    }
                }

                if (!row.IsColumnEmpty(7))
                {
                    switch (Convert.ToInt32(row[7]))
                    {
                    case FirewallConstants.NET_FW_PROFILE2_DOMAIN:
                        fire.Profile = Firewall.FirewallException.ProfileType.domain;
                        break;

                    case FirewallConstants.NET_FW_PROFILE2_PRIVATE:
                        fire.Profile = Firewall.FirewallException.ProfileType.@private;
                        break;

                    case FirewallConstants.NET_FW_PROFILE2_PUBLIC:
                        fire.Profile = Firewall.FirewallException.ProfileType.@public;
                        break;

                    case FirewallConstants.NET_FW_PROFILE2_ALL:
                        fire.Profile = Firewall.FirewallException.ProfileType.all;
                        break;
                    }
                }

                // Description column is new in v3.6
                if (9 < row.Fields.Length && !row.IsColumnEmpty(9))
                {
                    fire.Description = (string)row[9];
                }

                if (!row.IsColumnEmpty(10))
                {
                    switch (Convert.ToInt32(row[10]))
                    {
                    case FirewallConstants.NET_FW_RULE_DIR_IN:
                        fire.Direction = Firewall.FirewallException.DirectionType.@in;
                        break;

                    case FirewallConstants.NET_FW_RULE_DIR_OUT:
                        fire.Direction = Firewall.FirewallException.DirectionType.@out;
                        break;
                    }
                }

                Wix.Component component = (Wix.Component) this.Core.GetIndexedElement("Component", (string)row[8]);
                if (null != component)
                {
                    component.AddChild(fire);
                }
                else
                {
                    this.Core.OnMessage(WixWarnings.ExpectedForeignRow(row.SourceLineNumbers, table.Name, row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter), "Component_", (string)row[6], "Component"));
                }
            }
        }
        /// <summary>
        /// Decompile the SqlDatabase table.
        /// </summary>
        /// <param name="table">The table to decompile.</param>
        private void DecompileSqlDatabaseTable(Table table)
        {
            foreach (Row row in table.Rows)
            {
                Sql.SqlDatabase sqlDatabase = new Sql.SqlDatabase();

                sqlDatabase.Id = (string)row[0];

                if (null != row[1])
                {
                    sqlDatabase.Server = (string)row[1];
                }

                if (null != row[2])
                {
                    sqlDatabase.Instance = (string)row[2];
                }

                sqlDatabase.Database = (string)row[3];

                if (null != row[5])
                {
                    sqlDatabase.User = (string)row[5];
                }

                // the FileSpec_ and FileSpec_Log columns will be handled in FinalizeSqlFileSpecTable

                if (null != row[8])
                {
                    int attributes = (int)row[8];

                    if (SqlCompiler.DbCreateOnInstall == (attributes & SqlCompiler.DbCreateOnInstall))
                    {
                        sqlDatabase.CreateOnInstall = Sql.YesNoType.yes;
                    }

                    if (SqlCompiler.DbDropOnUninstall == (attributes & SqlCompiler.DbDropOnUninstall))
                    {
                        sqlDatabase.DropOnUninstall = Sql.YesNoType.yes;
                    }

                    if (SqlCompiler.DbContinueOnError == (attributes & SqlCompiler.DbContinueOnError))
                    {
                        sqlDatabase.ContinueOnError = Sql.YesNoType.yes;
                    }

                    if (SqlCompiler.DbDropOnInstall == (attributes & SqlCompiler.DbDropOnInstall))
                    {
                        sqlDatabase.DropOnInstall = Sql.YesNoType.yes;
                    }

                    if (SqlCompiler.DbCreateOnUninstall == (attributes & SqlCompiler.DbCreateOnUninstall))
                    {
                        sqlDatabase.CreateOnUninstall = Sql.YesNoType.yes;
                    }

                    if (SqlCompiler.DbConfirmOverwrite == (attributes & SqlCompiler.DbConfirmOverwrite))
                    {
                        sqlDatabase.ConfirmOverwrite = Sql.YesNoType.yes;
                    }

                    if (SqlCompiler.DbCreateOnReinstall == (attributes & SqlCompiler.DbCreateOnReinstall))
                    {
                        sqlDatabase.CreateOnReinstall = Sql.YesNoType.yes;
                    }

                    if (SqlCompiler.DbDropOnReinstall == (attributes & SqlCompiler.DbDropOnReinstall))
                    {
                        sqlDatabase.DropOnReinstall = Sql.YesNoType.yes;
                    }
                }

                if (null != row[4])
                {
                    Wix.Component component = (Wix.Component) this.Core.GetIndexedElement("Component", (string)row[4]);

                    if (null != component)
                    {
                        component.AddChild(sqlDatabase);
                    }
                    else
                    {
                        this.Core.OnMessage(WixWarnings.ExpectedForeignRow(row.SourceLineNumbers, table.Name, row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter), "Component_", (string)row[4], "Component"));
                    }
                }
                else
                {
                    this.Core.RootElement.AddChild(sqlDatabase);
                }
                this.Core.IndexElement(row, sqlDatabase);
            }
        }
        /// <summary>
        /// Finalize the SqlScript table.
        /// </summary>
        /// <param name="tables">The collection of all tables.</param>
        /// <remarks>
        /// The SqlScript and SqlString tables contain a foreign key into the SqlDatabase
        /// and Component tables.  Depending upon the parent of the SqlDatabase
        /// element, the SqlScript and SqlString elements are nested under either the
        /// SqlDatabase or the Component element.
        /// </remarks>
        private void FinalizeSqlScriptAndSqlStringTables(TableIndexedCollection tables)
        {
            Table sqlDatabaseTable = tables["SqlDatabase"];
            Table sqlScriptTable   = tables["SqlScript"];
            Table sqlStringTable   = tables["SqlString"];

            Hashtable sqlDatabaseRows = new Hashtable();

            // index each SqlDatabase row by its primary key
            if (null != sqlDatabaseTable)
            {
                foreach (Row row in sqlDatabaseTable.Rows)
                {
                    sqlDatabaseRows.Add(row[0], row);
                }
            }

            if (null != sqlScriptTable)
            {
                foreach (Row row in sqlScriptTable.Rows)
                {
                    Sql.SqlScript sqlScript = (Sql.SqlScript) this.Core.GetIndexedElement(row);

                    Row    sqlDatabaseRow    = (Row)sqlDatabaseRows[row[1]];
                    string databaseComponent = (string)sqlDatabaseRow[4];

                    // determine if the SqlScript element should be nested under the database or another component
                    if (null != databaseComponent && databaseComponent == (string)row[2])
                    {
                        Sql.SqlDatabase sqlDatabase = (Sql.SqlDatabase) this.Core.GetIndexedElement(sqlDatabaseRow);

                        sqlDatabase.AddChild(sqlScript);
                    }
                    else // nest under the component of the SqlDatabase row
                    {
                        Wix.Component component = (Wix.Component) this.Core.GetIndexedElement("Component", (string)row[2]);

                        // set the Database value
                        sqlScript.SqlDb = (string)row[1];

                        if (null != component)
                        {
                            component.AddChild(sqlScript);
                        }
                        else
                        {
                            this.Core.OnMessage(WixWarnings.ExpectedForeignRow(row.SourceLineNumbers, sqlScriptTable.Name, row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter), "Component_", (string)row[2], "Component"));
                        }
                    }
                }
            }

            if (null != sqlStringTable)
            {
                foreach (Row row in sqlStringTable.Rows)
                {
                    Sql.SqlString sqlString = (Sql.SqlString) this.Core.GetIndexedElement(row);

                    Row    sqlDatabaseRow    = (Row)sqlDatabaseRows[row[1]];
                    string databaseComponent = (string)sqlDatabaseRow[4];

                    // determine if the SqlScript element should be nested under the database or another component
                    if (null != databaseComponent && databaseComponent == (string)row[2])
                    {
                        Sql.SqlDatabase sqlDatabase = (Sql.SqlDatabase) this.Core.GetIndexedElement(sqlDatabaseRow);

                        sqlDatabase.AddChild(sqlString);
                    }
                    else // nest under the component of the SqlDatabase row
                    {
                        Wix.Component component = (Wix.Component) this.Core.GetIndexedElement("Component", (string)row[2]);

                        // set the Database value
                        sqlString.SqlDb = (string)row[1];

                        if (null != component)
                        {
                            component.AddChild(sqlString);
                        }
                        else
                        {
                            this.Core.OnMessage(WixWarnings.ExpectedForeignRow(row.SourceLineNumbers, sqlStringTable.Name, row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter), "Component_", (string)row[2], "Component"));
                        }
                    }
                }
            }
        }
예제 #16
0
        /// <summary>
        /// Converts the registry values to WiX regisry key element.
        /// </summary>
        /// <param name="sr">The registry file stream.</param>
        /// <param name="component">A WiX component reference.</param>
        /// <param name="root">The root key.</param>
        /// <param name="line">The current line.</param>
        private void ConvertValues(StreamReader sr, ref Wix.Component component, Wix.RegistryRootType root, string line)
        {
            string name  = null;
            string value = null;

            Wix.RegistryValue.TypeType type;
            Wix.RegistryKey            registryKey = new Wix.RegistryKey();

            registryKey.Root = root;
            registryKey.Key  = line;

            while (this.GetValue(sr, ref name, ref value, out type))
            {
                Wix.RegistryValue registryValue = new Wix.RegistryValue();
                ArrayList         charArray;

                // Don't specifiy name for default attribute
                if (!string.IsNullOrEmpty(name))
                {
                    registryValue.Name = name;
                }

                registryValue.Type = type;

                switch (type)
                {
                case Wix.RegistryValue.TypeType.binary:
                    registryValue.Value = value.Replace(",", string.Empty).ToUpper();
                    break;

                case Wix.RegistryValue.TypeType.integer:
                    registryValue.Value = Int32.Parse(value, NumberStyles.HexNumber).ToString();
                    break;

                case Wix.RegistryValue.TypeType.expandable:
                    charArray = this.ConvertCharList(value);
                    value     = string.Empty;

                    // create the string, remove the terminating null
                    for (int i = 0; i < charArray.Count; i++)
                    {
                        if ('\0' != (char)charArray[i])
                        {
                            value += charArray[i];
                        }
                    }

                    registryValue.Value = value;
                    break;

                case Wix.RegistryValue.TypeType.multiString:
                    charArray = this.ConvertCharList(value);
                    value     = string.Empty;

                    // Convert the character array to a string so we can simply split it at the nulls, ignore the final null null.
                    for (int i = 0; i < (charArray.Count - 2); i++)
                    {
                        value += charArray[i];
                    }

                    // Although the value can use [~] the preffered way is to use MultiStringValue
                    string[] parts = value.Split("\0".ToCharArray());
                    foreach (string part in parts)
                    {
                        Wix.MultiStringValue multiStringValue = new Wix.MultiStringValue();
                        multiStringValue.Content = part;
                        registryValue.AddChild(multiStringValue);
                    }

                    break;

                case Wix.RegistryValue.TypeType.@string:
                    // Remove \\ and \"
                    value = value.ToString().Replace("\\\"", "\"");
                    value = value.ToString().Replace(@"\\", @"\");
                    // Escape [ and ]
                    value = value.ToString().Replace(@"[", @"[\[]");
                    value = value.ToString().Replace(@"]", @"[\]]");
                    // This undoes the duplicate escaping caused by the second replace
                    value = value.ToString().Replace(@"[\[[\]]", @"[\[]");
                    // Escape $
                    value = value.ToString().Replace(@"$", @"$$");

                    registryValue.Value = value;
                    break;

                default:
                    throw new ApplicationException(String.Format("Did not recognize the type of reg value on line {0}", this.currentLineNumber));
                }

                registryKey.AddChild(registryValue);
            }

            // Make sure empty keys are created
            if (null == value)
            {
                registryKey.ForceCreateOnInstall = Wix.YesNoType.yes;
            }

            component.AddChild(registryKey);
        }
예제 #17
0
 /// <summary>
 /// Adds a ComponentRef to the main ComponentGroup.
 /// </summary>
 /// <param name="component">The component to add.</param>
 private void AddComponentRef(Wix.Component component)
 {
     Wix.ComponentRef componentRef = new Wix.ComponentRef();
     componentRef.Id = component.Id;
     this.componentGroup.AddChild(componentRef);
 }
예제 #18
0
        /// <summary>
        /// Harvest a directory.
        /// </summary>
        /// <param name="path">The path of the directory.</param>
        /// <param name="relativePath">The relative path that will be used when harvesting.</param>
        /// <param name="directory">The directory for this path.</param>
        /// <returns>The number of files harvested.</returns>
        private int HarvestDirectory(string path, string relativePath, Wix.Directory directory)
        {
            int fileCount = 0;

            // harvest the child directories
            foreach (string childDirectoryPath in Directory.GetDirectories(path))
            {
                Wix.Directory childDirectory = new Wix.Directory();

                childDirectory.Name       = Path.GetFileName(childDirectoryPath);
                childDirectory.FileSource = childDirectoryPath;

                if (this.setUniqueIdentifiers)
                {
                    childDirectory.Id = this.Core.GenerateIdentifier(DirectoryPrefix, directory.Id, childDirectory.Name);
                }

                int childFileCount = this.HarvestDirectory(childDirectoryPath, String.Concat(relativePath, childDirectory.Name, "\\"), childDirectory);

                // keep the directory if it contained any files (or empty directories are being kept)
                if (0 < childFileCount || this.keepEmptyDirectories)
                {
                    directory.AddChild(childDirectory);
                }

                fileCount += childFileCount;
            }

            // harvest the files
            string[] files = Directory.GetFiles(path);
            if (0 < files.Length)
            {
                foreach (string filePath in Directory.GetFiles(path))
                {
                    string fileName = Path.GetFileName(filePath);

                    Wix.Component component = new Wix.Component();

                    Wix.File file = this.fileHarvester.HarvestFile(filePath);
                    file.Source = String.Concat(relativePath, fileName);

                    if (this.setUniqueIdentifiers)
                    {
                        file.Id      = this.Core.GenerateIdentifier(FilePrefix, directory.Id, fileName);
                        component.Id = this.Core.GenerateIdentifier(ComponentPrefix, directory.Id, file.Id);
                    }

                    component.AddChild(file);

                    directory.AddChild(component);
                }
            }
            else if (0 == fileCount && this.keepEmptyDirectories)
            {
                Wix.Component component = new Wix.Component();
                component.KeyPath = Wix.YesNoType.yes;

                if (this.setUniqueIdentifiers)
                {
                    component.Id = this.Core.GenerateIdentifier(ComponentPrefix, directory.Id);
                }

                Wix.CreateFolder createFolder = new Wix.CreateFolder();
                component.AddChild(createFolder);

                directory.AddChild(component);
            }

            return(fileCount + files.Length);
        }
예제 #19
0
        /// <summary>
        /// Creates a component group with a given name.
        /// </summary>
        /// <param name="wix">The Wix document element.</param>
        private void CreateComponentGroup(Wix.Wix wix)
        {
            Wix.ComponentGroup componentGroup = new Wix.ComponentGroup();
            componentGroup.Id = this.componentGroupName;
            this.componentGroups.Add(componentGroup);

            Wix.Fragment cgFragment = new Wix.Fragment();
            cgFragment.AddChild(componentGroup);
            wix.AddChild(cgFragment);

            int componentCount = 0;

            for (; componentCount < this.components.Count; componentCount++)
            {
                Wix.Component c = this.components[componentCount] as Wix.Component;

                if (this.createFragments)
                {
                    if (c.ParentElement is Wix.Directory)
                    {
                        Wix.Directory parentDirectory = c.ParentElement as Wix.Directory;

                        componentGroup.AddChild(c);
                        c.Directory = parentDirectory.Id;
                        parentDirectory.RemoveChild(c);
                    }
                    else if (c.ParentElement is Wix.DirectoryRef)
                    {
                        Wix.DirectoryRef parentDirectory = c.ParentElement as Wix.DirectoryRef;

                        componentGroup.AddChild(c);
                        c.Directory = parentDirectory.Id;
                        parentDirectory.RemoveChild(c);

                        // Remove whole fragment if moving the component to the component group just leaves an empty DirectoryRef
                        if (0 < fragments.Count && parentDirectory.ParentElement is Wix.Fragment)
                        {
                            Wix.Fragment parentFragment = parentDirectory.ParentElement as Wix.Fragment;
                            int          childCount     = 0;
                            foreach (Wix.ISchemaElement element in parentFragment.Children)
                            {
                                childCount++;
                            }

                            // Component should always have an Id but the SortedList creation allows for null and bases the name on the fragment count which we cannot reverse engineer here.
                            if (1 == childCount && !String.IsNullOrEmpty(c.Id))
                            {
                                int removeIndex = fragments.IndexOfKey(String.Concat("Component:", c.Id));
                                if (0 <= removeIndex)
                                {
                                    fragments.RemoveAt(removeIndex);
                                }
                            }
                        }
                    }
                }
                else
                {
                    Wix.ComponentRef componentRef = new Wix.ComponentRef();
                    componentRef.Id = c.Id;
                    componentGroup.AddChild(componentRef);
                }
            }
        }