/// <summary> /// Main running method for the application. /// </summary> /// <param name="args">Commandline arguments to the application.</param> /// <returns>Returns the application error code.</returns> private int Run(string[] args) { try { // parse the command line this.ParseCommandLine(args); // exit if there was an error parsing the command line (otherwise the logo appears after error messages) if (this.messageHandler.EncounteredError) { return(this.messageHandler.LastErrorNumber); } if (null == this.inputFile || null == this.outputFile) { this.showHelp = true; } if (this.showLogo) { AppCommon.DisplayToolHeader(); } if (this.showHelp) { Console.WriteLine(PyroStrings.HelpMessage); AppCommon.DisplayToolFooter(); return(this.messageHandler.LastErrorNumber); } // Load in transforms ArrayList transforms = new ArrayList(); foreach (string inputTransform in inputTransformsOrdered) { PatchTransform patchTransform = new PatchTransform(inputTransform, inputTransforms[inputTransform]); patchTransform.Message += new MessageEventHandler(this.messageHandler.Display); transforms.Add(patchTransform); } // Create and configure the patch Patch patch = new Patch(); patch.Message += new MessageEventHandler(this.messageHandler.Display); // Create and configure the binder binder = new Microsoft.Tools.WindowsInstallerXml.Binder(); binder.TempFilesLocation = Environment.GetEnvironmentVariable("WIX_TEMP"); binder.WixVariableResolver = this.wixVariableResolver; binder.Message += new MessageEventHandler(this.messageHandler.Display); binder.SuppressAssemblies = this.suppressAssemblies; binder.SuppressFileHashAndInfo = this.suppressFileHashAndInfo; binder.SetMsiAssemblyNameFileVersion = this.setAssemblyFileVersions; // have the binder parse the command line arguments light did not recognize string[] unparsedArgsArray = new string[this.unparsedArgs.Count]; this.unparsedArgs.CopyTo(unparsedArgsArray, 0); StringCollection remainingArgs = this.binder.ParseCommandLine(unparsedArgsArray, this.messageHandler); // Load the extensions bool binderFileManagerLoaded = false; foreach (String extension in this.extensions) { WixExtension wixExtension = WixExtension.Load(extension); binder.AddExtension(wixExtension); patch.AddExtension(wixExtension); if (0 < remainingArgs.Count) { remainingArgs = wixExtension.ParseCommandLine(remainingArgs, this.messageHandler); } if (null != wixExtension.BinderFileManager) { if (binderFileManagerLoaded) { throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, PyroStrings.EXP_CannotLoadBinderFileManager, wixExtension.BinderFileManager.GetType().ToString(), binder.FileManager.ToString()), "ext"); } binder.FileManager = wixExtension.BinderFileManager; binderFileManagerLoaded = true; } } foreach (string parameter in remainingArgs) { this.messageHandler.Display(this, WixWarnings.UnsupportedCommandLineArgument(parameter)); } if (this.messageHandler.EncounteredError) { return(this.messageHandler.LastErrorNumber); } // since the binder is now ready, let's plug dynamic bindpath into file manager this.PrepareDataForFileManager(); // Load the patch patch.Load(this.inputFile); // Copy transforms into output if (0 < transforms.Count) { patch.AttachTransforms(transforms); } if (this.messageHandler.EncounteredError) { return(this.messageHandler.LastErrorNumber); } if (null == this.pdbFile && null != this.outputFile) { this.pdbFile = Path.ChangeExtension(this.outputFile, ".wixpdb"); } binder.PdbFile = suppressWixPdb ? null : this.pdbFile; if (this.suppressFiles) { binder.SuppressAssemblies = true; binder.SuppressFileHashAndInfo = true; } if (null != this.cabCachePath || this.reuseCabinets) { // ensure the cabinet cache path exists if we are going to use it if (null != this.cabCachePath && !Directory.Exists(this.cabCachePath)) { Directory.CreateDirectory(this.cabCachePath); } } binder.AllowEmptyTransforms = this.allowEmptyTransforms; binder.FileManager.ReuseCabinets = this.reuseCabinets; binder.FileManager.CabCachePath = this.cabCachePath; binder.FileManager.Output = patch.PatchOutput; binder.FileManager.DeltaBinaryPatch = this.delta; // Bind the patch to an msp. binder.Bind(patch.PatchOutput, this.outputFile); } catch (WixException we) { this.OnMessage(we.Error); } catch (Exception e) { this.OnMessage(WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); if (e is NullReferenceException || e is SEHException) { throw; } } finally { if (null != binder) { if (this.tidy) { if (!binder.DeleteTempFiles()) { Console.WriteLine(PyroStrings.WAR_FailedToDeleteTempDir, binder.TempFilesLocation); } } else { Console.WriteLine(PyroStrings.INF_TempDirLocatedAt, binder.TempFilesLocation); } } } return(this.messageHandler.LastErrorNumber); }
/// <summary> /// Main running method for the application. /// </summary> /// <param name="args">Commandline arguments to the application.</param> /// <returns>Returns the application error code.</returns> private int Run(string[] args) { try { // parse the command line this.ParseCommandLine(args); // exit if there was an error parsing the command line (otherwise the logo appears after error messages) if (this.messageHandler.EncounteredError) { return this.messageHandler.LastErrorNumber; } if (null == this.inputFile || null == this.outputFile) { this.showHelp = true; } if (this.showLogo) { AppCommon.DisplayToolHeader(); } if (this.showHelp) { Console.WriteLine(PyroStrings.HelpMessage); AppCommon.DisplayToolFooter(); return this.messageHandler.LastErrorNumber; } // Load in transforms ArrayList transforms = new ArrayList(); foreach (string inputTransform in inputTransformsOrdered) { PatchTransform patchTransform = new PatchTransform(inputTransform, inputTransforms[inputTransform]); patchTransform.Message += new MessageEventHandler(this.messageHandler.Display); transforms.Add(patchTransform); } // Create and configure the patch Patch patch = new Patch(); patch.Message += new MessageEventHandler(this.messageHandler.Display); // Create and configure the binder binder = new Microsoft.Tools.WindowsInstallerXml.Binder(); binder.TempFilesLocation = Environment.GetEnvironmentVariable("WIX_TEMP"); binder.WixVariableResolver = this.wixVariableResolver; binder.Message += new MessageEventHandler(this.messageHandler.Display); binder.SuppressAssemblies = this.suppressAssemblies; binder.SuppressFileHashAndInfo = this.suppressFileHashAndInfo; binder.SetMsiAssemblyNameFileVersion = this.setAssemblyFileVersions; // have the binder parse the command line arguments light did not recognize string[] unparsedArgsArray = new string[this.unparsedArgs.Count]; this.unparsedArgs.CopyTo(unparsedArgsArray, 0); StringCollection remainingArgs = this.binder.ParseCommandLine(unparsedArgsArray, this.messageHandler); // Load the extensions bool binderFileManagerLoaded = false; foreach (String extension in this.extensions) { WixExtension wixExtension = WixExtension.Load(extension); binder.AddExtension(wixExtension); patch.AddExtension(wixExtension); if (0 < remainingArgs.Count) { remainingArgs = wixExtension.ParseCommandLine(remainingArgs, this.messageHandler); } if (null != wixExtension.BinderFileManager) { if (binderFileManagerLoaded) { throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, PyroStrings.EXP_CannotLoadBinderFileManager, wixExtension.BinderFileManager.GetType().ToString(), binder.FileManager.ToString()), "ext"); } binder.FileManager = wixExtension.BinderFileManager; binderFileManagerLoaded = true; } } foreach (string parameter in remainingArgs) { this.messageHandler.Display(this, WixWarnings.UnsupportedCommandLineArgument(parameter)); } if (this.messageHandler.EncounteredError) { return this.messageHandler.LastErrorNumber; } // since the binder is now ready, let's plug dynamic bindpath into file manager this.PrepareDataForFileManager(); // Load the patch patch.Load(this.inputFile); // Copy transforms into output if (0 < transforms.Count) { patch.AttachTransforms(transforms); } if (this.messageHandler.EncounteredError) { return this.messageHandler.LastErrorNumber; } if (null == this.pdbFile && null != this.outputFile) { this.pdbFile = Path.ChangeExtension(this.outputFile, ".wixpdb"); } binder.PdbFile = suppressWixPdb ? null : this.pdbFile; if (this.suppressFiles) { binder.SuppressAssemblies = true; binder.SuppressFileHashAndInfo = true; } if (null != this.cabCachePath || this.reuseCabinets) { // ensure the cabinet cache path exists if we are going to use it if (null != this.cabCachePath && !Directory.Exists(this.cabCachePath)) { Directory.CreateDirectory(this.cabCachePath); } } binder.AllowEmptyTransforms = this.allowEmptyTransforms; binder.FileManager.ReuseCabinets = this.reuseCabinets; binder.FileManager.CabCachePath = this.cabCachePath; binder.FileManager.Output = patch.PatchOutput; binder.FileManager.DeltaBinaryPatch = this.delta; // Bind the patch to an msp. binder.Bind(patch.PatchOutput, this.outputFile); } catch (WixException we) { this.OnMessage(we.Error); } catch (Exception e) { this.OnMessage(WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); if (e is NullReferenceException || e is SEHException) { throw; } } finally { if (null != binder) { if (this.tidy) { if (!binder.DeleteTempFiles()) { Console.WriteLine(PyroStrings.WAR_FailedToDeleteTempDir, binder.TempFilesLocation); } } else { Console.WriteLine(PyroStrings.INF_TempDirLocatedAt, binder.TempFilesLocation); } } } return this.messageHandler.LastErrorNumber; }