예제 #1
0
        /// <summary>
        /// Harvest a directory.
        /// </summary>
        /// <param name="argument">The path of the directory.</param>
        /// <returns>The harvested directory.</returns>
        public override Wix.Fragment[] Harvest(string argument)
        {
            if (null == argument)
            {
                throw new ArgumentNullException("argument");
            }

            Wix.Directory directory = this.HarvestDirectory(argument, "SourceDir\\", true);

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

            if (this.suppressRootDirectory)
            {
                foreach (Wix.ISchemaElement element in directory.Children)
                {
                    directoryRef.AddChild(element);
                }
            }
            else
            {
                directoryRef.AddChild(directory);
            }

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

            return(new Wix.Fragment[] { fragment });
        }
예제 #2
0
        /// <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");
            }

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

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

            string directoryPath = Path.GetDirectoryName(Path.GetFullPath(argument));

            Wix.Directory directory = new Wix.Directory();
            directory.FileSource = directoryPath;
            directory.Name       = Path.GetFileName(directoryPath);
            directory.AddChild(component);

            Wix.DirectoryRef directoryRef = new Wix.DirectoryRef();
            directoryRef.Id = "TARGETDIR";
            directoryRef.AddChild(directory);

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

            return(fragment);
        }
예제 #3
0
        /// <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
파일: Melter.cs 프로젝트: Jeremiahf/wix3
        /// <summary>
        /// Creates a new melter object.
        /// </summary>
        /// <param name="decompiler">The decompiler to use during the melting process.</param>
        /// <param name="id">The Id to use for the ComponentGroup, DirectoryRef, and WixVariables. If null, defaults to the Module's Id</param>
        public Melter(Decompiler decompiler, string id)
        {
            this.core = new MelterCore(this.Message);

            this.componentGroup = new Wix.ComponentGroup();
            this.fragment = new Wix.Fragment();
            this.primaryDirectoryRef = new Wix.DirectoryRef();

            this.decompiler = decompiler;
            this.id = id;

            if (null == this.decompiler)
            {
                this.core.OnMessage(WixErrors.ExpectedDecompiler("The melting process"));
            }
        }
예제 #5
0
        /// <summary>
        /// Creates a new melter object.
        /// </summary>
        /// <param name="decompiler">The decompiler to use during the melting process.</param>
        /// <param name="id">The Id to use for the ComponentGroup, DirectoryRef, and WixVariables. If null, defaults to the Module's Id</param>
        public Melter(Decompiler decompiler, string id)
        {
            this.core = new MelterCore(this.Message);

            this.componentGroup      = new Wix.ComponentGroup();
            this.fragment            = new Wix.Fragment();
            this.primaryDirectoryRef = new Wix.DirectoryRef();

            this.decompiler = decompiler;
            this.id         = id;

            if (null == this.decompiler)
            {
                this.core.OnMessage(WixErrors.ExpectedDecompiler("The melting process"));
            }
        }
예제 #6
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);
                }
            }
        }
예제 #7
0
        /// <summary>
        /// Builds a setup package to the specified output path.
        /// </summary>
        /// <param name="outputPath">Location to build the setup package to.</param>
        /// <param name="outputSourcePath">Optional path where the package's .wxs file will be written.</param>
        public bool Build(string outputPath, string outputSourcePath)
        {
            this.buildError = null; // clear out any previous errors

            int currentProgress = 0;
            int totalProgress = 7;

            // calculate the upper progress
            if (outputSourcePath != null)
            {
                ++totalProgress;
            }
            if (this.previousPackagePath != null)
            {
                ++totalProgress;
            }

            this.VerifyRequiredInformation();

            if (!this.OnProgress(currentProgress++, totalProgress, "Initialized package builder..."))
            {
                return false;
            }

            // Calculate where everything is going
            string localSetupExe = outputPath;
            string localSetupFeed = Path.Combine(Path.GetDirectoryName(outputPath), Path.GetFileName(this.updateUrl.AbsolutePath));

            Uri urlSetupExe = new Uri(this.updateUrl, Path.GetFileName(localSetupExe));
            Uri urlSetupFeed = new Uri(this.updateUrl, Path.GetFileName(localSetupFeed));

            Guid previousUpgradeCode = Guid.Empty;
            Version previousVersion = null;
            Uri previousSetupFeed = null;

            // if a previous package was provided, go read the key information out of it now
            if (this.previousPackagePath != null)
            {
                if (!this.OnProgress(currentProgress++, totalProgress, "Reading previous package..."))
                {
                    return false;
                }

                this.ReadPreviousPackage(this.previousPackagePath, out previousUpgradeCode, out previousVersion, out previousSetupFeed);
            }

            //
            // if a upgrade code and/or version has not been specified use one
            // from the previous package or create new.
            //
            if (this.upgradeCode == Guid.Empty)
            {
                if (previousUpgradeCode == Guid.Empty)
                {
                    this.upgradeCode = Guid.NewGuid();
                }
                else
                {
                    this.upgradeCode = previousUpgradeCode;
                }
            }

            if (this.version == null)
            {
                if (previousVersion == null)
                {
                    FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(Path.Combine(this.applicationRoot.Content, this.applicationEntry.Content));
                    this.version = new Version(fileVersionInfo.FileVersion);
                }
                else
                {
                    this.version = previousVersion;
                }
            }

            // verify that new data is okay when compared to previous package
            if (previousUpgradeCode != Guid.Empty && previousUpgradeCode != this.upgradeCode)
            {
                this.OnMessage(ClickThroughErrors.UpgradeCodeChanged(previousUpgradeCode, this.upgradeCode));
            }
            if (previousVersion != null && previousVersion >= this.version)
            {
                this.OnMessage(ClickThroughErrors.NewVersionIsNotGreater(previousVersion, this.version));
            }

            if (this.buildError != null)
            {
                throw new InvalidOperationException(String.Format(this.buildError.ResourceManager.GetString(this.buildError.ResourceName), this.buildError.MessageArgs));
            }
            else if (!this.OnProgress(currentProgress++, totalProgress, "Processing package information..."))
            {
                return false;
            }

            // Product information
            Application application = new Application();
            application.Product.Id = Guid.NewGuid().ToString();
            application.Product.Language = "1033";
            application.Product.Manufacturer = this.manufacturerName.Content;
            application.Product.Name = this.applicationName.Content;
            application.Package.Description = this.description.Content;
            application.Product.UpgradeCode = this.upgradeCode.ToString();
            application.Product.Version = this.version.ToString();

            Wix.WixVariable variable = new Wix.WixVariable();
            variable = new Wix.WixVariable();
            variable.Id = "ProductName";
            variable.Value = application.Product.Name;
            application.Product.AddChild(variable);

            variable = new Wix.WixVariable();
            variable.Id = "ProductCode";
            variable.Value = application.Product.Id;
            application.Product.AddChild(variable);

            variable = new Wix.WixVariable();
            variable.Id = "ProductVersion";
            variable.Value = application.Product.Version;
            application.Product.AddChild(variable);

            variable = new Wix.WixVariable();
            variable.Id = "ShortcutFileId";
            variable.Value = "todoFileIdHere";
            application.Product.AddChild(variable);

            // Upgrade logic
            Wix.Upgrade upgrade = new Wix.Upgrade();
            upgrade.Id = application.Product.UpgradeCode;
            application.Product.AddChild(upgrade);

            Wix.UpgradeVersion minUpgrade = new Wix.UpgradeVersion();
            minUpgrade.Minimum = application.Product.Version;
            minUpgrade.OnlyDetect = Wix.YesNoType.yes;
            minUpgrade.Property = "NEWERVERSIONDETECTED";
            upgrade.AddChild(minUpgrade);

            Wix.UpgradeVersion maxUpgrade = new Wix.UpgradeVersion();
            maxUpgrade.Maximum = application.Product.Version;
            maxUpgrade.IncludeMaximum = Wix.YesNoType.no;
            maxUpgrade.Property = "OLDERVERSIONBEINGUPGRADED";
            upgrade.AddChild(maxUpgrade);

            // Update Feed
            Wix.Property property = new Wix.Property();
            property.Id = "ARPURLUPDATEINFO";
            property.Value = urlSetupFeed.AbsoluteUri;
            application.Product.AddChild(property);

#if false
            // Directory tree
            Wix.DirectoryRef applicationCacheRef = new Wix.DirectoryRef();
            applicationCacheRef.Id = "ApplicationsCacheFolder";
            application.Product.AddChild(applicationCacheRef);
#endif

            Wix.DirectoryRef directoryRef = new Wix.DirectoryRef();
            directoryRef.Id = "ApplicationsFolder";
            application.Product.AddChild(directoryRef);

            this.applicationRootDirectory.Name = String.Concat(application.Product.UpgradeCode, "v", application.Product.Version);
            directoryRef.AddChild(this.applicationRootDirectory);

#if false
            // System registry keys
            Wix.Component registryComponent = new Wix.Component();
            registryComponent.Id = "SystemVersionRegistryKeyComponent";
            registryComponent.Guid = Guid.NewGuid().ToString();
            directoryRef.AddChild(registryComponent);

            Wix.Registry productRegKey = new Wix.Registry();
            productRegKey.Root = Wix.RegistryRootType.HKCU;
            productRegKey.Key = @"Software\WiX\ClickThrough\Applications\[UpgradeCode]";
            productRegKey.Action = Wix.Registry.ActionType.createKeyAndRemoveKeyOnUninstall; 
            registryComponent.AddChild(productRegKey);

            Wix.Registry versionRegKey = new Wix.Registry();
            versionRegKey.Name = "Version";
            versionRegKey.Type = Wix.Registry.TypeType.@string;
            versionRegKey.Value = "[ProductVersion]";
            productRegKey.AddChild(versionRegKey);

            Wix.Registry sourceRegKey = new Wix.Registry();
            sourceRegKey.Name = "UpdateInfoSource";
            sourceRegKey.Type = Wix.Registry.TypeType.@string;
            sourceRegKey.Value = "[ARPURLUPDATEINFO]";
            productRegKey.AddChild(sourceRegKey);

            // Shortcut
            Wix.DirectoryRef programMenuRef = new Wix.DirectoryRef();
            programMenuRef.Id = "ProgramMenuFolder";
            Wix.Directory shortcutsDirectory = new Wix.Directory();
            shortcutsDirectory.Id = "ThisAppShortcuts";
            shortcutsDirectory.LongName = application.Product.Name;
            shortcutsDirectory.Name = "AppSCDir";
            programMenuRef.AddChild(shortcutsDirectory);
            application.Product.AddChild(programMenuRef);

            Wix.Component shortcutsComponent = new Wix.Component();
            shortcutsComponent.Id = "ThisApplicationShortcutComponent";
            shortcutsComponent.Guid = Guid.NewGuid().ToString();
            shortcutsComponent.KeyPath = Wix.YesNoType.yes;
            shortcutsDirectory.AddChild(shortcutsComponent);

            Wix.CreateFolder shortcutsCreateFolder = new Wix.CreateFolder();
            shortcutsComponent.AddChild(shortcutsCreateFolder);

            Wix.Shortcut shortcut = this.GetShortcut(this.applicationEntry.Content, rootDirectory, shortcutsDirectory);
            shortcutsComponent.AddChild(shortcut);

            // Remove cached MSI file.
            Wix.Component removeComponent = new Wix.Component();
            removeComponent.Id = "ThisApplicationRemoveComponent";
            removeComponent.Guid = Guid.NewGuid().ToString();
            removeComponent.KeyPath = Wix.YesNoType.yes;
            applicationCacheRef.AddChild(removeComponent);

            Wix.RemoveFile cacheRemoveFile = new Wix.RemoveFile();
            cacheRemoveFile.Id = "ThisApplicationRemoveCachedMsi";
            cacheRemoveFile.Directory = "ApplicationsCacheFolder";
            cacheRemoveFile.Name = "unknown.msi";
            cacheRemoveFile.LongName = String.Concat("{", application.Product.Id.ToUpper(CultureInfo.InvariantCulture), "}v", application.Version.ToString(), ".msi");
            cacheRemoveFile.On = Wix.RemoveFile.OnType.uninstall;
            removeComponent.AddChild(cacheRemoveFile);

            Wix.RemoveFile cacheRemoveFolder = new Wix.RemoveFile();
            cacheRemoveFolder.Id = "ThisApplicationRemoveCacheFolder";
            cacheRemoveFolder.Directory = "ApplicationsCacheFolder";
            cacheRemoveFolder.On = Wix.RemoveFile.OnType.uninstall;
            removeComponent.AddChild(cacheRemoveFolder);

            Wix.RemoveFile applicationRemoveFolder = new Wix.RemoveFile();
            applicationRemoveFolder.Id = "ThisApplicationRemoveApplicationsFolder";
            applicationRemoveFolder.Directory = "ApplicationsFolder";
            applicationRemoveFolder.On = Wix.RemoveFile.OnType.uninstall;
            removeComponent.AddChild(applicationRemoveFolder);
#endif
            // Feature tree
            Wix.FeatureRef applicationFeatureRef = new Wix.FeatureRef();
            applicationFeatureRef.Id = "ApplicationFeature";
            application.Product.AddChild(applicationFeatureRef);

#if false
            Wix.Feature applicationFeature = new Wix.Feature();
            applicationFeature.Id = "ApplicationFeature";
            applicationFeature.Display = "expand";
            applicationFeature.Level = 1;
            applicationFeature.Absent = Wix.Feature.AbsentType.disallow;
            applicationFeature.AllowAdvertise = Wix.Feature.AllowAdvertiseType.yes;
            applicationFeature.InstallDefault = Wix.Feature.InstallDefaultType.local;
            applicationFeature.TypicalDefault = Wix.Feature.TypicalDefaultType.install;
            application.Product.AddChild(applicationFeature);

            Wix.ComponentRef shortcutsComponentRef = new Wix.ComponentRef();
            shortcutsComponentRef.Id = shortcutsComponent.Id;
            applicationFeature.AddChild(shortcutsComponentRef);

            Wix.ComponentRef removeComponentRef = new Wix.ComponentRef();
            removeComponentRef.Id = removeComponent.Id;
            applicationFeature.AddChild(removeComponentRef);
#endif

            Wix.ComponentRef[] componentRefs = this.GetComponentRefs(this.applicationRootDirectory);
            foreach (Wix.ComponentRef componentRef in componentRefs)
            {
                applicationFeatureRef.AddChild(componentRef);
            }

            if (!this.OnProgress(currentProgress++, totalProgress, "Serializing package information into XML..."))
            {
                return false;
            }

            // serialize to an xml string
            string xml;
            using (StringWriter sw = new StringWriter())
            {
                XmlTextWriter writer = null;
                try
                {
                    writer = new XmlTextWriter(sw);

                    application.WixRoot.OutputXml(writer);

                    xml = sw.ToString();
                }
                finally
                {
                    if (writer != null)
                    {
                        writer.Close();
                    }
                }
            }

            // load the xml into a document
            XmlDocument sourceDoc = new XmlDocument();
            sourceDoc.LoadXml(xml);

            if (outputSourcePath != null)
            {
                if (!this.OnProgress(currentProgress++, totalProgress, "Saving .wxs file..."))
                {
                    return false;
                }

                sourceDoc.Save(outputSourcePath);
            }

            // generate the MSI, create the setup.exe, and generate the RSS feed.
            string outputMsi = null;
            try
            {
                outputMsi = Path.GetTempFileName();

                if (!this.OnProgress(currentProgress++, totalProgress, "Generating .msi file..."))
                {
                    return false;
                }

                this.GenerateMsi(sourceDoc, outputMsi);
                if (this.buildError != null)
                {
                    throw new InvalidOperationException(String.Format(this.buildError.ResourceManager.GetString(this.buildError.ResourceName), this.buildError.MessageArgs));
                }

                string assemblyPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

                if (!this.OnProgress(currentProgress++, totalProgress, "Generating setup bootstrapper..."))
                {
                    return false;
                }

                /*
                NativeMethods.CREATE_SETUP_PACKAGE[] createSetup = new Microsoft.Tools.WindowsInstallerXml.ClickThrough.NativeMethods.CREATE_SETUP_PACKAGE[1];
                createSetup[0].fPrivileged = false;
                createSetup[0].fCache = true;
                createSetup[0].wzSourcePath = outputMsi;

                int hr = NativeMethods.CreateSetup(Path.Combine(assemblyPath, "setup.exe"), createSetup, createSetup.Length, localSetupExe);
                */
                int hr = NativeMethods.CreateSimpleSetup(Path.Combine(assemblyPath, "setup.exe"), outputMsi, localSetupExe);
                if (hr != 0)
                {
                    this.OnMessage(ClickThroughErrors.FailedSetupExeCreation(Path.Combine(assemblyPath, "setup.exe"), localSetupExe));
                }

                if (!this.OnProgress(currentProgress++, totalProgress, "Generating update feed..."))
                {
                    return false;
                }
                this.GenerateRssFeed(localSetupFeed, localSetupExe, urlSetupExe, application.Product.Id, application.Product.UpgradeCode, application.Product.Version);
            }
            finally
            {
                this.OnProgress(currentProgress++, totalProgress, "Cleaning up...");
                if (outputMsi != null)
                {
                    File.Delete(outputMsi);
                }
            }

            if (this.buildError != null)
            {
                throw new InvalidOperationException(String.Format(this.buildError.ResourceManager.GetString(this.buildError.ResourceName), this.buildError.MessageArgs));
            }
            else if (!this.OnProgress(currentProgress++, totalProgress, "Package build complete."))
            {
                return false;
            }

            return true;
        }
예제 #8
0
        /// <summary>
        /// Creates WiX fragments for files in one output group.
        /// </summary>
        /// <param name="projectFile">VS MSBuild project file.</param>
        /// <param name="buildOutputs">Dictionary of build outputs retrieved from an MSBuild run on the project file.</param>
        /// <param name="pog">Project output group parameters.</param>
        /// <param name="fragmentList">List to which generated fragments will be added.</param>
        /// <returns>Count of harvested files.</returns>
        private int HarvestProjectOutputGroup(string projectFile, IDictionary buildOutputs, ProjectOutputGroup pog, IList fragmentList)
        {
            string projectName = Path.GetFileNameWithoutExtension(projectFile);
            string projectBaseDir = null;

            if (this.ProjectName != null)
            {
                projectName = this.ProjectName;
            }

            string sanitizedProjectName = HarvesterCore.GetIdentifierFromName(projectName);

            Wix.IParentElement harvestParent;

            if (this.GenerateType == GenerateType.Container)
            {
                Wix.Container container = new Wix.Container();
                harvestParent = container;

                container.Name = String.Format(CultureInfo.InvariantCulture, DirectoryIdFormat, sanitizedProjectName, pog.Name);
            }
            else if (this.GenerateType == GenerateType.PayloadGroup)
            {
                Wix.PayloadGroup container = new Wix.PayloadGroup();
                harvestParent = container;

                container.Id = String.Format(CultureInfo.InvariantCulture, DirectoryIdFormat, sanitizedProjectName, pog.Name);
            }
            else if (this.GenerateType == GenerateType.PackageGroup)
            {
                Wix.PackageGroup container = new Wix.PackageGroup();
                harvestParent = container;

                container.Id = String.Format(CultureInfo.InvariantCulture, DirectoryIdFormat, sanitizedProjectName, pog.Name);
            }
            else
            {
                Wix.DirectoryRef directoryRef = new Wix.DirectoryRef();
                harvestParent = directoryRef;

                if (!String.IsNullOrEmpty(this.directoryIds))
                {
                    directoryRef.Id = this.directoryIds;
                }
                else if (this.setUniqueIdentifiers)
                {
                    directoryRef.Id = String.Format(CultureInfo.InvariantCulture, DirectoryIdFormat, sanitizedProjectName, pog.Name);
                }
                else
                {
                    directoryRef.Id = HarvesterCore.GetIdentifierFromName(String.Format(CultureInfo.InvariantCulture, VSProjectHarvester.DirectoryIdFormat, sanitizedProjectName, pog.Name));
                }

                this.directoryRefSeed = this.Core.GenerateIdentifier(DirectoryPrefix, this.projectGUID, pog.Name);
            }

            IEnumerable pogFiles = buildOutputs[pog.BuildOutputGroup] as IEnumerable;
            if (pogFiles == null)
            {
                throw new WixException(VSErrors.MissingProjectOutputGroup(
                    projectFile, pog.BuildOutputGroup));
            }

            if (pog.FileSource == "ProjectDir")
            {
                projectBaseDir = Path.GetDirectoryName(projectFile) + "\\";
            }

            int harvestCount = this.HarvestProjectOutputGroupFiles(projectBaseDir, projectName, pog.Name, pog.FileSource, pogFiles, harvestParent);

            if (this.GenerateType == GenerateType.Container)
            {
                // harvestParent must be a Container at this point
                Wix.Container container = harvestParent as Wix.Container;

                Wix.Fragment fragment = new Wix.Fragment();
                fragment.AddChild(container);
                fragmentList.Add(fragment);
            }
            else if (this.GenerateType == GenerateType.PackageGroup)
            {
                // harvestParent must be a PackageGroup at this point
                Wix.PackageGroup packageGroup = harvestParent as Wix.PackageGroup;

                Wix.Fragment fragment = new Wix.Fragment();
                fragment.AddChild(packageGroup);
                fragmentList.Add(fragment);
            }
            else if (this.GenerateType == GenerateType.PayloadGroup)
            {
                // harvestParent must be a Container at this point
                Wix.PayloadGroup payloadGroup = harvestParent as Wix.PayloadGroup;

                Wix.Fragment fragment = new Wix.Fragment();
                fragment.AddChild(payloadGroup);
                fragmentList.Add(fragment);
            }
            else
            {
                // harvestParent must be a DirectoryRef at this point
                Wix.DirectoryRef directoryRef = harvestParent as Wix.DirectoryRef;

                if (harvestCount > 0)
                {
                    Wix.Fragment drf = new Wix.Fragment();
                    drf.AddChild(directoryRef);
                    fragmentList.Add(drf);
                }

                Wix.ComponentGroup cg = new Wix.ComponentGroup();

                if (this.setUniqueIdentifiers || !String.IsNullOrEmpty(this.directoryIds))
                {
                    cg.Id = String.Format(CultureInfo.InvariantCulture, DirectoryIdFormat, sanitizedProjectName, pog.Name);
                }
                else
                {
                    cg.Id = directoryRef.Id;
                }

                if (harvestCount > 0)
                {
                    this.AddComponentsToComponentGroup(directoryRef, cg);
                }

                Wix.Fragment cgf = new Wix.Fragment();
                cgf.AddChild(cg);
                fragmentList.Add(cgf);
            }

            return harvestCount;
        }
예제 #9
0
파일: FileHarvester.cs 프로젝트: zooba/wix3
        /// <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 };
        }
예제 #10
0
        /// <summary>
        /// Generates the .wxs file for the application.
        /// </summary>
        /// <returns>XmlDocument containing the .wxs file for the application.</returns>
        private XmlDocument GenerateSourceFile()
        {
            XmlDocument sourceDoc = null;

            // Ensure the root application directory has been calculated and the
            // new PackageCode is generated.
            this.GetRootDirectory(false);

            if (this.productCode == Guid.Empty)
            {
                this.productCode = Guid.NewGuid();
            }

            // Build up the product information.
            Wix.Wix wix = new Wix.Wix();

            Wix.Product product = new Wix.Product();
            product.Id           = this.productCode.ToString();
            product.Language     = this.language;
            product.Manufacturer = this.manufacturer;
            product.Name         = this.name;
            product.UpgradeCode  = this.upgradeCode.ToString();
            product.Version      = this.version.ToString();
            wix.AddChild(product);

            Wix.Package package = new Wix.Package();
            package.Compressed = Wix.YesNoType.yes;
            if (null != this.description)
            {
                package.Description = this.description;
            }

            package.InstallerVersion = 200;
            product.AddChild(package);

            Wix.WixVariable variable = new Wix.WixVariable();
            variable       = new Wix.WixVariable();
            variable.Id    = "ProductName";
            variable.Value = product.Name;
            product.AddChild(variable);

            variable       = new Wix.WixVariable();
            variable.Id    = "ProductCode";
            variable.Value = product.Id;
            product.AddChild(variable);

            variable       = new Wix.WixVariable();
            variable.Id    = "ProductVersion";
            variable.Value = product.Version;
            product.AddChild(variable);

            variable       = new Wix.WixVariable();
            variable.Id    = "ShimPath";
            variable.Value = this.shimPath;
            product.AddChild(variable);

            variable       = new Wix.WixVariable();
            variable.Id    = "ShimClsid";
            variable.Value = this.ShimClsid.ToString("B");
            product.AddChild(variable);

            variable       = new Wix.WixVariable();
            variable.Id    = "ShimProgId";
            variable.Value = this.shimProgid;
            product.AddChild(variable);

            // Upgrade logic.
            Wix.Upgrade upgrade = new Wix.Upgrade();
            upgrade.Id = product.UpgradeCode;
            product.AddChild(upgrade);

            Wix.UpgradeVersion minUpgrade = new Wix.UpgradeVersion();
            minUpgrade.Minimum    = product.Version;
            minUpgrade.OnlyDetect = Wix.YesNoType.yes;
            minUpgrade.Property   = "NEWERVERSIONDETECTED";
            upgrade.AddChild(minUpgrade);

            Wix.UpgradeVersion maxUpgrade = new Wix.UpgradeVersion();
            maxUpgrade.Maximum        = product.Version;
            maxUpgrade.IncludeMaximum = Wix.YesNoType.no;
            maxUpgrade.Property       = "OLDERVERSIONBEINGUPGRADED";
            upgrade.AddChild(maxUpgrade);

            // Update feed property.
            Wix.Property property = new Wix.Property();
            property.Id    = "ARPURLUPDATEINFO";
            property.Value = this.updateUrl.AbsoluteUri;
            product.AddChild(property);

            // Root the application's directory tree in the applications folder.
            Wix.DirectoryRef applicationsFolderRef = new Wix.DirectoryRef();
            applicationsFolderRef.Id = "ApplicationsFolder";
            product.AddChild(applicationsFolderRef);

            this.rootDirectory.Name = String.Concat(product.Id, "v", product.Version);
            applicationsFolderRef.AddChild(this.rootDirectory);

            // Add the shim to the root directory.
            Wix.Component shimComponent = this.GenerateShimComponent();
            this.rootDirectory.AddChild(shimComponent);

            // Add all of the Components to the Feature tree.
            Wix.FeatureRef applicationFeatureRef = new Wix.FeatureRef();
            applicationFeatureRef.Id = "ApplicationFeature";
            product.AddChild(applicationFeatureRef);

            Wix.ComponentRef[] componentRefs = this.GetComponentRefs(this.rootDirectory);
            foreach (Wix.ComponentRef componentRef in componentRefs)
            {
                applicationFeatureRef.AddChild(componentRef);
            }

            // Serialize product information to an xml string.
            string xml;

            using (StringWriter sw = new StringWriter())
            {
                XmlTextWriter writer = null;
                try
                {
                    writer = new XmlTextWriter(sw);

                    wix.OutputXml(writer);

                    xml = sw.ToString();
                }
                finally
                {
                    if (writer != null)
                    {
                        writer.Close();
                    }
                }
            }

            // Load the xml into a document.
            sourceDoc = new XmlDocument();
            sourceDoc.LoadXml(xml);

            return(sourceDoc);
        }
예제 #11
0
        /// <summary>
        /// Mutate the directories.
        /// </summary>
        private void MutateDirectories()
        {
            // assign all identifiers before fragmenting (because fragmenting requires them all to be present)
            if (this.setUniqueIdentifiers)
            {
                IdentifierGenerator identifierGenerator = new IdentifierGenerator("Directory");

                // index all the existing identifiers and names
                foreach (Wix.Directory directory in this.directories)
                {
                    if (null != directory.Id)
                    {
                        identifierGenerator.IndexExistingIdentifier(directory.Id);
                    }
                    else
                    {
                        identifierGenerator.IndexName(directory.Name);
                    }
                }

                foreach (Wix.Directory directory in this.directories)
                {
                    if (null == directory.Id)
                    {
                        directory.Id = identifierGenerator.GetIdentifier(directory.Name);
                    }
                }
            }

            foreach (Wix.Directory directory in this.directories)
            {
                if (this.createFragments)
                {
                    if (directory.ParentElement is Wix.Directory)
                    {
                        Wix.Directory parentDirectory = (Wix.Directory)directory.ParentElement;

                        // parent directory must have an identifier to create a reference to it
                        if (null == parentDirectory.Id)
                        {
                            return;
                        }

                        // create a new Fragment
                        Wix.Fragment fragment = new Wix.Fragment();
                        this.fragments.Add(String.Concat("Directory:", ("TARGETDIR" == directory.Id ? null : (null != directory.Id ? directory.Id : this.fragments.Count.ToString()))), fragment);

                        // create a new DirectoryRef
                        Wix.DirectoryRef directoryRef = new Wix.DirectoryRef();
                        directoryRef.Id = parentDirectory.Id;
                        fragment.AddChild(directoryRef);

                        // move the Directory from the parent Directory to DirectoryRef
                        parentDirectory.RemoveChild(directory);
                        directoryRef.AddChild(directory);
                    }
                    else if (directory.ParentElement == this.rootElement)
                    {
                        // create a new Fragment
                        Wix.Fragment fragment = new Wix.Fragment();
                        this.fragments.Add(String.Concat("Directory:", ("TARGETDIR" == directory.Id ? null : (null != directory.Id ? directory.Id : this.fragments.Count.ToString()))), fragment);

                        // move the Directory from the root element to the Fragment
                        this.rootElement.RemoveChild(directory);
                        fragment.AddChild(directory);
                    }
                }
            }
        }
예제 #12
0
        /// <summary>
        /// Builds a setup package to the specified output path.
        /// </summary>
        /// <param name="outputPath">Location to build the setup package to.</param>
        /// <param name="outputSourcePath">Optional path where the package's .wxs file will be written.</param>
        public bool Build(string outputPath, string outputSourcePath)
        {
            this.buildError = null; // clear out any previous errors

            int currentProgress = 0;
            int totalProgress   = 7;

            // calculate the upper progress
            if (outputSourcePath != null)
            {
                ++totalProgress;
            }
            if (this.previousPackagePath != null)
            {
                ++totalProgress;
            }

            this.VerifyRequiredInformation();

            if (!this.OnProgress(currentProgress++, totalProgress, "Initialized package builder..."))
            {
                return(false);
            }

            // Calculate where everything is going
            string localSetupExe  = outputPath;
            string localSetupFeed = Path.Combine(Path.GetDirectoryName(outputPath), Path.GetFileName(this.updateUrl.AbsolutePath));

            Uri urlSetupExe  = new Uri(this.updateUrl, Path.GetFileName(localSetupExe));
            Uri urlSetupFeed = new Uri(this.updateUrl, Path.GetFileName(localSetupFeed));

            Guid    previousUpgradeCode = Guid.Empty;
            Version previousVersion     = null;
            Uri     previousSetupFeed   = null;

            // if a previous package was provided, go read the key information out of it now
            if (this.previousPackagePath != null)
            {
                if (!this.OnProgress(currentProgress++, totalProgress, "Reading previous package..."))
                {
                    return(false);
                }

                this.ReadPreviousPackage(this.previousPackagePath, out previousUpgradeCode, out previousVersion, out previousSetupFeed);
            }

            //
            // if a upgrade code and/or version has not been specified use one
            // from the previous package or create new.
            //
            if (this.upgradeCode == Guid.Empty)
            {
                if (previousUpgradeCode == Guid.Empty)
                {
                    this.upgradeCode = Guid.NewGuid();
                }
                else
                {
                    this.upgradeCode = previousUpgradeCode;
                }
            }

            if (this.version == null)
            {
                if (previousVersion == null)
                {
                    FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(Path.Combine(this.applicationRoot.Content, this.applicationEntry.Content));
                    this.version = new Version(fileVersionInfo.FileVersion);
                }
                else
                {
                    this.version = previousVersion;
                }
            }

            // verify that new data is okay when compared to previous package
            if (previousUpgradeCode != Guid.Empty && previousUpgradeCode != this.upgradeCode)
            {
                this.OnMessage(ClickThroughErrors.UpgradeCodeChanged(previousUpgradeCode, this.upgradeCode));
            }
            if (previousVersion != null && previousVersion >= this.version)
            {
                this.OnMessage(ClickThroughErrors.NewVersionIsNotGreater(previousVersion, this.version));
            }

            if (this.buildError != null)
            {
                throw new InvalidOperationException(String.Format(this.buildError.ResourceManager.GetString(this.buildError.ResourceName), this.buildError.MessageArgs));
            }
            else if (!this.OnProgress(currentProgress++, totalProgress, "Processing package information..."))
            {
                return(false);
            }

            // Product information
            Application application = new Application();

            application.Product.Id           = Guid.NewGuid().ToString();
            application.Product.Language     = "1033";
            application.Product.Manufacturer = this.manufacturerName.Content;
            application.Product.Name         = this.applicationName.Content;
            application.Package.Description  = this.description.Content;
            application.Product.UpgradeCode  = this.upgradeCode.ToString();
            application.Product.Version      = this.version.ToString();

            Wix.WixVariable variable = new Wix.WixVariable();
            variable       = new Wix.WixVariable();
            variable.Id    = "ProductName";
            variable.Value = application.Product.Name;
            application.Product.AddChild(variable);

            variable       = new Wix.WixVariable();
            variable.Id    = "ProductCode";
            variable.Value = application.Product.Id;
            application.Product.AddChild(variable);

            variable       = new Wix.WixVariable();
            variable.Id    = "ProductVersion";
            variable.Value = application.Product.Version;
            application.Product.AddChild(variable);

            variable       = new Wix.WixVariable();
            variable.Id    = "ShortcutFileId";
            variable.Value = "todoFileIdHere";
            application.Product.AddChild(variable);

            // Upgrade logic
            Wix.Upgrade upgrade = new Wix.Upgrade();
            upgrade.Id = application.Product.UpgradeCode;
            application.Product.AddChild(upgrade);

            Wix.UpgradeVersion minUpgrade = new Wix.UpgradeVersion();
            minUpgrade.Minimum    = application.Product.Version;
            minUpgrade.OnlyDetect = Wix.YesNoType.yes;
            minUpgrade.Property   = "NEWERVERSIONDETECTED";
            upgrade.AddChild(minUpgrade);

            Wix.UpgradeVersion maxUpgrade = new Wix.UpgradeVersion();
            maxUpgrade.Maximum        = application.Product.Version;
            maxUpgrade.IncludeMaximum = Wix.YesNoType.no;
            maxUpgrade.Property       = "OLDERVERSIONBEINGUPGRADED";
            upgrade.AddChild(maxUpgrade);

            // Update Feed
            Wix.Property property = new Wix.Property();
            property.Id    = "ARPURLUPDATEINFO";
            property.Value = urlSetupFeed.AbsoluteUri;
            application.Product.AddChild(property);

#if false
            // Directory tree
            Wix.DirectoryRef applicationCacheRef = new Wix.DirectoryRef();
            applicationCacheRef.Id = "ApplicationsCacheFolder";
            application.Product.AddChild(applicationCacheRef);
#endif

            Wix.DirectoryRef directoryRef = new Wix.DirectoryRef();
            directoryRef.Id = "ApplicationsFolder";
            application.Product.AddChild(directoryRef);

            this.applicationRootDirectory.Name = String.Concat(application.Product.UpgradeCode, "v", application.Product.Version);
            directoryRef.AddChild(this.applicationRootDirectory);

#if false
            // System registry keys
            Wix.Component registryComponent = new Wix.Component();
            registryComponent.Id   = "SystemVersionRegistryKeyComponent";
            registryComponent.Guid = Guid.NewGuid().ToString();
            directoryRef.AddChild(registryComponent);

            Wix.Registry productRegKey = new Wix.Registry();
            productRegKey.Root   = Wix.RegistryRootType.HKCU;
            productRegKey.Key    = @"Software\WiX\ClickThrough\Applications\[UpgradeCode]";
            productRegKey.Action = Wix.Registry.ActionType.createKeyAndRemoveKeyOnUninstall;
            registryComponent.AddChild(productRegKey);

            Wix.Registry versionRegKey = new Wix.Registry();
            versionRegKey.Name  = "Version";
            versionRegKey.Type  = Wix.Registry.TypeType.@string;
            versionRegKey.Value = "[ProductVersion]";
            productRegKey.AddChild(versionRegKey);

            Wix.Registry sourceRegKey = new Wix.Registry();
            sourceRegKey.Name  = "UpdateInfoSource";
            sourceRegKey.Type  = Wix.Registry.TypeType.@string;
            sourceRegKey.Value = "[ARPURLUPDATEINFO]";
            productRegKey.AddChild(sourceRegKey);

            // Shortcut
            Wix.DirectoryRef programMenuRef = new Wix.DirectoryRef();
            programMenuRef.Id = "ProgramMenuFolder";
            Wix.Directory shortcutsDirectory = new Wix.Directory();
            shortcutsDirectory.Id       = "ThisAppShortcuts";
            shortcutsDirectory.LongName = application.Product.Name;
            shortcutsDirectory.Name     = "AppSCDir";
            programMenuRef.AddChild(shortcutsDirectory);
            application.Product.AddChild(programMenuRef);

            Wix.Component shortcutsComponent = new Wix.Component();
            shortcutsComponent.Id      = "ThisApplicationShortcutComponent";
            shortcutsComponent.Guid    = Guid.NewGuid().ToString();
            shortcutsComponent.KeyPath = Wix.YesNoType.yes;
            shortcutsDirectory.AddChild(shortcutsComponent);

            Wix.CreateFolder shortcutsCreateFolder = new Wix.CreateFolder();
            shortcutsComponent.AddChild(shortcutsCreateFolder);

            Wix.Shortcut shortcut = this.GetShortcut(this.applicationEntry.Content, rootDirectory, shortcutsDirectory);
            shortcutsComponent.AddChild(shortcut);

            // Remove cached MSI file.
            Wix.Component removeComponent = new Wix.Component();
            removeComponent.Id      = "ThisApplicationRemoveComponent";
            removeComponent.Guid    = Guid.NewGuid().ToString();
            removeComponent.KeyPath = Wix.YesNoType.yes;
            applicationCacheRef.AddChild(removeComponent);

            Wix.RemoveFile cacheRemoveFile = new Wix.RemoveFile();
            cacheRemoveFile.Id        = "ThisApplicationRemoveCachedMsi";
            cacheRemoveFile.Directory = "ApplicationsCacheFolder";
            cacheRemoveFile.Name      = "unknown.msi";
            cacheRemoveFile.LongName  = String.Concat("{", application.Product.Id.ToUpper(CultureInfo.InvariantCulture), "}v", application.Version.ToString(), ".msi");
            cacheRemoveFile.On        = Wix.RemoveFile.OnType.uninstall;
            removeComponent.AddChild(cacheRemoveFile);

            Wix.RemoveFile cacheRemoveFolder = new Wix.RemoveFile();
            cacheRemoveFolder.Id        = "ThisApplicationRemoveCacheFolder";
            cacheRemoveFolder.Directory = "ApplicationsCacheFolder";
            cacheRemoveFolder.On        = Wix.RemoveFile.OnType.uninstall;
            removeComponent.AddChild(cacheRemoveFolder);

            Wix.RemoveFile applicationRemoveFolder = new Wix.RemoveFile();
            applicationRemoveFolder.Id        = "ThisApplicationRemoveApplicationsFolder";
            applicationRemoveFolder.Directory = "ApplicationsFolder";
            applicationRemoveFolder.On        = Wix.RemoveFile.OnType.uninstall;
            removeComponent.AddChild(applicationRemoveFolder);
#endif
            // Feature tree
            Wix.FeatureRef applicationFeatureRef = new Wix.FeatureRef();
            applicationFeatureRef.Id = "ApplicationFeature";
            application.Product.AddChild(applicationFeatureRef);

#if false
            Wix.Feature applicationFeature = new Wix.Feature();
            applicationFeature.Id             = "ApplicationFeature";
            applicationFeature.Display        = "expand";
            applicationFeature.Level          = 1;
            applicationFeature.Absent         = Wix.Feature.AbsentType.disallow;
            applicationFeature.AllowAdvertise = Wix.Feature.AllowAdvertiseType.yes;
            applicationFeature.InstallDefault = Wix.Feature.InstallDefaultType.local;
            applicationFeature.TypicalDefault = Wix.Feature.TypicalDefaultType.install;
            application.Product.AddChild(applicationFeature);

            Wix.ComponentRef shortcutsComponentRef = new Wix.ComponentRef();
            shortcutsComponentRef.Id = shortcutsComponent.Id;
            applicationFeature.AddChild(shortcutsComponentRef);

            Wix.ComponentRef removeComponentRef = new Wix.ComponentRef();
            removeComponentRef.Id = removeComponent.Id;
            applicationFeature.AddChild(removeComponentRef);
#endif

            Wix.ComponentRef[] componentRefs = this.GetComponentRefs(this.applicationRootDirectory);
            foreach (Wix.ComponentRef componentRef in componentRefs)
            {
                applicationFeatureRef.AddChild(componentRef);
            }

            if (!this.OnProgress(currentProgress++, totalProgress, "Serializing package information into XML..."))
            {
                return(false);
            }

            // serialize to an xml string
            string xml;
            using (StringWriter sw = new StringWriter())
            {
                XmlTextWriter writer = null;
                try
                {
                    writer = new XmlTextWriter(sw);

                    application.WixRoot.OutputXml(writer);

                    xml = sw.ToString();
                }
                finally
                {
                    if (writer != null)
                    {
                        writer.Close();
                    }
                }
            }

            // load the xml into a document
            XmlDocument sourceDoc = new XmlDocument();
            sourceDoc.LoadXml(xml);

            if (outputSourcePath != null)
            {
                if (!this.OnProgress(currentProgress++, totalProgress, "Saving .wxs file..."))
                {
                    return(false);
                }

                sourceDoc.Save(outputSourcePath);
            }

            // generate the MSI, create the setup.exe, and generate the RSS feed.
            string outputMsi = null;
            try
            {
                outputMsi = Path.GetTempFileName();

                if (!this.OnProgress(currentProgress++, totalProgress, "Generating .msi file..."))
                {
                    return(false);
                }

                this.GenerateMsi(sourceDoc, outputMsi);
                if (this.buildError != null)
                {
                    throw new InvalidOperationException(String.Format(this.buildError.ResourceManager.GetString(this.buildError.ResourceName), this.buildError.MessageArgs));
                }

                string assemblyPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

                if (!this.OnProgress(currentProgress++, totalProgress, "Generating setup bootstrapper..."))
                {
                    return(false);
                }

                /*
                 * NativeMethods.CREATE_SETUP_PACKAGE[] createSetup = new Microsoft.Tools.WindowsInstallerXml.ClickThrough.NativeMethods.CREATE_SETUP_PACKAGE[1];
                 * createSetup[0].fPrivileged = false;
                 * createSetup[0].fCache = true;
                 * createSetup[0].wzSourcePath = outputMsi;
                 *
                 * int hr = NativeMethods.CreateSetup(Path.Combine(assemblyPath, "setup.exe"), createSetup, createSetup.Length, localSetupExe);
                 */
                int hr = NativeMethods.CreateSimpleSetup(Path.Combine(assemblyPath, "setup.exe"), outputMsi, localSetupExe);
                if (hr != 0)
                {
                    this.OnMessage(ClickThroughErrors.FailedSetupExeCreation(Path.Combine(assemblyPath, "setup.exe"), localSetupExe));
                }

                if (!this.OnProgress(currentProgress++, totalProgress, "Generating update feed..."))
                {
                    return(false);
                }
                this.GenerateRssFeed(localSetupFeed, localSetupExe, urlSetupExe, application.Product.Id, application.Product.UpgradeCode, application.Product.Version);
            }
            finally
            {
                this.OnProgress(currentProgress++, totalProgress, "Cleaning up...");
                if (outputMsi != null)
                {
                    File.Delete(outputMsi);
                }
            }

            if (this.buildError != null)
            {
                throw new InvalidOperationException(String.Format(this.buildError.ResourceManager.GetString(this.buildError.ResourceName), this.buildError.MessageArgs));
            }
            else if (!this.OnProgress(currentProgress++, totalProgress, "Package build complete."))
            {
                return(false);
            }

            return(true);
        }
예제 #13
0
        /// <summary>
        /// Mutate the components.
        /// </summary>
        private void MutateComponents()
        {
            IdentifierGenerator identifierGenerator = new IdentifierGenerator("Component");

            if (TemplateType.Module == this.templateType)
            {
                identifierGenerator.MaxIdentifierLength = IdentifierGenerator.MaxModuleIdentifierLength;
            }

            foreach (Wix.Component component in this.components)
            {
                if (null == component.Id)
                {
                    string firstFileId = string.Empty;

                    // attempt to create a possible identifier from the first file identifier in the component
                    foreach (Wix.File file in component[typeof(Wix.File)])
                    {
                        firstFileId = file.Id;
                        break;
                    }

                    if (string.IsNullOrEmpty(firstFileId))
                    {
                        firstFileId = GetGuid();
                    }

                    component.Id = identifierGenerator.GetIdentifier(firstFileId);
                }

                if (null == component.Guid)
                {
                    if (this.AutogenerateGuids)
                    {
                        component.Guid = "*";
                    }
                    else
                    {
                        component.Guid = this.GetGuid();
                    }
                }

                if (this.createFragments && component.ParentElement is Wix.Directory)
                {
                    Wix.Directory directory = (Wix.Directory)component.ParentElement;

                    // parent directory must have an identifier to create a reference to it
                    if (null == directory.Id)
                    {
                        break;
                    }

                    if (this.rootElement is Wix.Module)
                    {
                        // add a ComponentRef for the Component
                        Wix.ComponentRef componentRef = new Wix.ComponentRef();
                        componentRef.Id = component.Id;
                        this.rootElement.AddChild(componentRef);
                    }

                    // create a new Fragment
                    Wix.Fragment fragment = new Wix.Fragment();
                    this.fragments.Add(String.Concat("Component:", (null != component.Id ? component.Id : this.fragments.Count.ToString())), fragment);

                    // create a new DirectoryRef
                    Wix.DirectoryRef directoryRef = new Wix.DirectoryRef();
                    directoryRef.Id = directory.Id;
                    fragment.AddChild(directoryRef);

                    // move the Component from the the Directory to the DirectoryRef
                    directory.RemoveChild(component);
                    directoryRef.AddChild(component);
                }
            }
        }
예제 #14
0
        /// <summary>
        /// Generates the .wxs file for the application.
        /// </summary>
        /// <returns>XmlDocument containing the .wxs file for the application.</returns>
        private XmlDocument GenerateSourceFile()
        {
            XmlDocument sourceDoc = null;

            // Ensure the root application directory has been calculated and the 
            // new PackageCode is generated.
            this.GetRootDirectory(false);

            if (this.productCode == Guid.Empty)
            {
                this.productCode = Guid.NewGuid();
            }

            // Build up the product information.
            Wix.Wix wix = new Wix.Wix();

            Wix.Product product = new Wix.Product();
            product.Id = this.productCode.ToString();
            product.Language = this.language;
            product.Manufacturer = this.manufacturer;
            product.Name = this.name;
            product.UpgradeCode = this.upgradeCode.ToString();
            product.Version = this.version.ToString();
            wix.AddChild(product);

            Wix.Package package = new Wix.Package();
            package.Compressed = Wix.YesNoType.yes;
            if (null != this.description)
            {
                package.Description = this.description;
            }

            package.InstallerVersion = 200;
            product.AddChild(package);

            Wix.WixVariable variable = new Wix.WixVariable();
            variable = new Wix.WixVariable();
            variable.Id = "ProductName";
            variable.Value = product.Name;
            product.AddChild(variable);

            variable = new Wix.WixVariable();
            variable.Id = "ProductCode";
            variable.Value = product.Id;
            product.AddChild(variable);

            variable = new Wix.WixVariable();
            variable.Id = "ProductVersion";
            variable.Value = product.Version;
            product.AddChild(variable);

            variable = new Wix.WixVariable();
            variable.Id = "ShimPath";
            variable.Value = this.shimPath;
            product.AddChild(variable);

            variable = new Wix.WixVariable();
            variable.Id = "ShimClsid";
            variable.Value = this.ShimClsid.ToString("B");
            product.AddChild(variable);

            variable = new Wix.WixVariable();
            variable.Id = "ShimProgId";
            variable.Value = this.shimProgid;
            product.AddChild(variable);

            // Upgrade logic.
            Wix.Upgrade upgrade = new Wix.Upgrade();
            upgrade.Id = product.UpgradeCode;
            product.AddChild(upgrade);

            Wix.UpgradeVersion minUpgrade = new Wix.UpgradeVersion();
            minUpgrade.Minimum = product.Version;
            minUpgrade.OnlyDetect = Wix.YesNoType.yes;
            minUpgrade.Property = "NEWERVERSIONDETECTED";
            upgrade.AddChild(minUpgrade);

            Wix.UpgradeVersion maxUpgrade = new Wix.UpgradeVersion();
            maxUpgrade.Maximum = product.Version;
            maxUpgrade.IncludeMaximum = Wix.YesNoType.no;
            maxUpgrade.Property = "OLDERVERSIONBEINGUPGRADED";
            upgrade.AddChild(maxUpgrade);

            // Update feed property.
            Wix.Property property = new Wix.Property();
            property.Id = "ARPURLUPDATEINFO";
            property.Value = this.updateUrl.AbsoluteUri;
            product.AddChild(property);

            // Root the application's directory tree in the applications folder.
            Wix.DirectoryRef applicationsFolderRef = new Wix.DirectoryRef();
            applicationsFolderRef.Id = "ApplicationsFolder";
            product.AddChild(applicationsFolderRef);

            this.rootDirectory.Name = String.Concat(product.Id, "v", product.Version);
            applicationsFolderRef.AddChild(this.rootDirectory);

            // Add the shim to the root directory.
            Wix.Component shimComponent = this.GenerateShimComponent();
            this.rootDirectory.AddChild(shimComponent);

            // Add all of the Components to the Feature tree.
            Wix.FeatureRef applicationFeatureRef = new Wix.FeatureRef();
            applicationFeatureRef.Id = "ApplicationFeature";
            product.AddChild(applicationFeatureRef);

            Wix.ComponentRef[] componentRefs = this.GetComponentRefs(this.rootDirectory);
            foreach (Wix.ComponentRef componentRef in componentRefs)
            {
                applicationFeatureRef.AddChild(componentRef);
            }

            // Serialize product information to an xml string.
            string xml;
            using (StringWriter sw = new StringWriter())
            {
                XmlTextWriter writer = null;
                try
                {
                    writer = new XmlTextWriter(sw);

                    wix.OutputXml(writer);

                    xml = sw.ToString();
                }
                finally
                {
                    if (writer != null)
                    {
                        writer.Close();
                    }
                }
            }

            // Load the xml into a document.
            sourceDoc = new XmlDocument();
            sourceDoc.LoadXml(xml);

            return sourceDoc;
        }
예제 #15
0
        /// <summary>
        /// Harvest a directory.
        /// </summary>
        /// <param name="argument">The path of the directory.</param>
        /// <returns>The harvested directory.</returns>
        public override Wix.Fragment[] Harvest(string argument)
        {
            if (null == argument)
            {
                throw new ArgumentNullException("argument");
            }

            Wix.Directory directory = this.HarvestDirectory(argument, "SourceDir\\", true);

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

            if (this.suppressRootDirectory)
            {
                foreach (Wix.ISchemaElement element in directory.Children)
                {
                    directoryRef.AddChild(element);
                }
            }
            else
            {
                directoryRef.AddChild(directory);
            }

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

            return new Wix.Fragment[] { fragment };
        }
예제 #16
0
        /// <summary>
        /// Mutate the directories.
        /// </summary>
        private void MutateDirectories()
        {
            if (!this.setUniqueIdentifiers)
            {
                // assign all identifiers before fragmenting (because fragmenting requires them all to be present)
                IdentifierGenerator identifierGenerator = new IdentifierGenerator("Directory");
                if (TemplateType.Module == this.templateType)
                {
                    identifierGenerator.MaxIdentifierLength = IdentifierGenerator.MaxModuleIdentifierLength;
                }

                foreach (Wix.Directory directory in this.directories)
                {
                    if (null == directory.Id)
                    {
                        directory.Id = identifierGenerator.GetIdentifier(directory.Name);
                    }
                }
            }

            if (this.createFragments)
            {
                foreach (Wix.Directory directory in this.directories)
                {
                    if (directory.ParentElement is Wix.Directory)
                    {
                        Wix.Directory parentDirectory = (Wix.Directory)directory.ParentElement;

                        // parent directory must have an identifier to create a reference to it
                        if (null == parentDirectory.Id)
                        {
                            return;
                        }

                        // create a new Fragment
                        Wix.Fragment fragment = new Wix.Fragment();
                        this.fragments.Add(String.Concat("Directory:", ("TARGETDIR" == directory.Id ? null : (null != directory.Id ? directory.Id : this.fragments.Count.ToString()))), fragment);

                        // create a new DirectoryRef
                        Wix.DirectoryRef directoryRef = new Wix.DirectoryRef();
                        directoryRef.Id = parentDirectory.Id;
                        fragment.AddChild(directoryRef);

                        // move the Directory from the parent Directory to DirectoryRef
                        parentDirectory.RemoveChild(directory);
                        directoryRef.AddChild(directory);
                    }
                    else if (directory.ParentElement is Wix.Fragment)
                    {
                        // When creating fragments, remove any top-level Directory elements;
                        // the fragments should be pulled in by their DirectoryRefs instead.
                        Wix.Fragment parent = (Wix.Fragment)directory.ParentElement;
                        parent.RemoveChild(directory);

                        // Remove the fragment if it is empty.
                        if (parent.Children.GetEnumerator().Current == null && parent.ParentElement != null)
                        {
                            ((Wix.IParentElement)parent.ParentElement).RemoveChild(parent);
                        }
                    }
                    else if (directory.ParentElement == this.rootElement)
                    {
                        // create a new Fragment
                        Wix.Fragment fragment = new Wix.Fragment();
                        this.fragments.Add(String.Concat("Directory:", ("TARGETDIR" == directory.Id ? null : (null != directory.Id ? directory.Id : this.fragments.Count.ToString()))), fragment);

                        // move the Directory from the root element to the Fragment
                        this.rootElement.RemoveChild(directory);
                        fragment.AddChild(directory);
                    }
                }
            }
        }
예제 #17
0
        /// <summary>
        /// Mutate the components.
        /// </summary>
        private void MutateComponents()
        {
            IdentifierGenerator identifierGenerator = new IdentifierGenerator("Component");
            if (TemplateType.Module == this.templateType)
            {
                identifierGenerator.MaxIdentifierLength = IdentifierGenerator.MaxModuleIdentifierLength;
            }

            foreach (Wix.Component component in this.components)
            {
                if (null == component.Id)
                {
                    string firstFileId = string.Empty;

                    // attempt to create a possible identifier from the first file identifier in the component
                    foreach (Wix.File file in component[typeof(Wix.File)])
                    {
                        firstFileId = file.Id;
                        break;
                    }

                    if (string.IsNullOrEmpty(firstFileId))
                    {
                        firstFileId = GetGuid();
                    }

                    component.Id = identifierGenerator.GetIdentifier(firstFileId);
                }

                if (null == component.Guid)
                {
                    if (this.AutogenerateGuids)
                    {
                        component.Guid = "*";
                    }
                    else
                    {
                        component.Guid = this.GetGuid();
                    }
                }

                if (this.createFragments && component.ParentElement is Wix.Directory)
                {
                    Wix.Directory directory = (Wix.Directory)component.ParentElement;

                    // parent directory must have an identifier to create a reference to it
                    if (null == directory.Id)
                    {
                        break;
                    }

                    if (this.rootElement is Wix.Module)
                    {
                        // add a ComponentRef for the Component
                        Wix.ComponentRef componentRef = new Wix.ComponentRef();
                        componentRef.Id = component.Id;
                        this.rootElement.AddChild(componentRef);
                    }

                    // create a new Fragment
                    Wix.Fragment fragment = new Wix.Fragment();
                    this.fragments.Add(String.Concat("Component:", (null != component.Id ? component.Id : this.fragments.Count.ToString())), fragment);

                    // create a new DirectoryRef
                    Wix.DirectoryRef directoryRef = new Wix.DirectoryRef();
                    directoryRef.Id = directory.Id;
                    fragment.AddChild(directoryRef);

                    // move the Component from the the Directory to the DirectoryRef
                    directory.RemoveChild(component);
                    directoryRef.AddChild(component);
                }
            }
        }
예제 #18
0
        /// <summary>
        /// Mutate the directories.
        /// </summary>
        private void MutateDirectories()
        {
            if (!this.setUniqueIdentifiers)
            {
                // assign all identifiers before fragmenting (because fragmenting requires them all to be present)
                IdentifierGenerator identifierGenerator = new IdentifierGenerator("Directory");
                if (TemplateType.Module == this.templateType)
                {
                    identifierGenerator.MaxIdentifierLength = IdentifierGenerator.MaxModuleIdentifierLength;
                }

                foreach (Wix.Directory directory in this.directories)
                {
                    if (null == directory.Id)
                    {
                        directory.Id = identifierGenerator.GetIdentifier(directory.Name);
                    }
                }
            }

            if (this.createFragments)
            {
                foreach (Wix.Directory directory in this.directories)
                {
                    if (directory.ParentElement is Wix.Directory)
                    {
                        Wix.Directory parentDirectory = (Wix.Directory)directory.ParentElement;

                        // parent directory must have an identifier to create a reference to it
                        if (null == parentDirectory.Id)
                        {
                            return;
                        }

                        // create a new Fragment
                        Wix.Fragment fragment = new Wix.Fragment();
                        this.fragments.Add(String.Concat("Directory:", ("TARGETDIR" == directory.Id ? null : (null != directory.Id ? directory.Id : this.fragments.Count.ToString()))), fragment);

                        // create a new DirectoryRef
                        Wix.DirectoryRef directoryRef = new Wix.DirectoryRef();
                        directoryRef.Id = parentDirectory.Id;
                        fragment.AddChild(directoryRef);

                        // move the Directory from the parent Directory to DirectoryRef
                        parentDirectory.RemoveChild(directory);
                        directoryRef.AddChild(directory);
                    }
                    else if (directory.ParentElement is Wix.Fragment)
                    {
                        // When creating fragments, remove any top-level Directory elements;
                        // the fragments should be pulled in by their DirectoryRefs instead.
                        Wix.Fragment parent = (Wix.Fragment)directory.ParentElement;
                        parent.RemoveChild(directory);

                        // Remove the fragment if it is empty.
                        if (parent.Children.GetEnumerator().Current == null && parent.ParentElement != null)
                        {
                            ((Wix.IParentElement)parent.ParentElement).RemoveChild(parent);
                        }
                    }
                    else if (directory.ParentElement == this.rootElement)
                    {
                        // create a new Fragment
                        Wix.Fragment fragment = new Wix.Fragment();
                        this.fragments.Add(String.Concat("Directory:", ("TARGETDIR" == directory.Id ? null : (null != directory.Id ? directory.Id : this.fragments.Count.ToString()))), fragment);

                        // move the Directory from the root element to the Fragment
                        this.rootElement.RemoveChild(directory);
                        fragment.AddChild(directory);
                    }
                }
            }
        }
예제 #19
0
        /// <summary>
        /// Mutate the components.
        /// </summary>
        private void MutateComponents()
        {
            IdentifierGenerator identifierGenerator = null;

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

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

                        // attempt to create a possible identifier from the first file identifier in the component
                        foreach (Wix.File file in component[typeof(Wix.File)])
                        {
                            firstFileId = file.Id;
                            break;
                        }

                        identifierGenerator.IndexName(firstFileId);
                    }
                }
            }

            foreach (Wix.Component component in this.components)
            {
                if (this.setUniqueIdentifiers && null == component.Id)
                {
                    string firstFileId = string.Empty;

                    // attempt to create a possible identifier from the first file identifier in the component
                    foreach (Wix.File file in component[typeof(Wix.File)])
                    {
                        firstFileId = file.Id;
                        break;
                    }

                    component.Id = identifierGenerator.GetIdentifier(firstFileId);
                }

                if (null == component.Guid)
                {
                    component.Guid = this.GetGuid();
                }

                if (this.createFragments && component.ParentElement is Wix.Directory)
                {
                    Wix.Directory directory = (Wix.Directory)component.ParentElement;

                    // parent directory must have an identifier to create a reference to it
                    if (null == directory.Id)
                    {
                        break;
                    }

                    if (this.rootElement is Wix.Module)
                    {
                        // add a ComponentRef for the Component
                        Wix.ComponentRef componentRef = new Wix.ComponentRef();
                        componentRef.Id = component.Id;
                        this.rootElement.AddChild(componentRef);
                    }

                    // create a new Fragment
                    Wix.Fragment fragment = new Wix.Fragment();
                    this.fragments.Add(String.Concat("Component:", (null != component.Id ? component.Id : this.fragments.Count.ToString())), fragment);

                    // create a new DirectoryRef
                    Wix.DirectoryRef directoryRef = new Wix.DirectoryRef();
                    directoryRef.Id = directory.Id;
                    fragment.AddChild(directoryRef);

                    // move the Component from the the Directory to the DirectoryRef
                    directory.RemoveChild(component);
                    directoryRef.AddChild(component);
                }
            }
        }