Skip to content

Commit

Permalink
Merge pull request #40 from kain64/master
Browse files Browse the repository at this point in the history
[Bootstrapper] support exit code feature
  • Loading branch information
oleg-shilo authored Mar 18, 2017
2 parents e7fb87d + 438a4ac commit 8ed3a06
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 1 deletion.
37 changes: 37 additions & 0 deletions Source/src/WixSharp.Test/BootstrapperTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using WixSharp.Bootstrapper;
Expand Down Expand Up @@ -202,5 +203,41 @@ public void Should_Resolve_NoLicenseType()
</Bundle>";
Assert.Equal(expected, xml);
}

[Fact]
public void ExitCodeTest1()
{
var package = new ExePackage(@"c:\1.exe");
package.ExitCodes.Add(new ExitCode()
{
Behavior = BehaviorValues.error,
Value = "1001"

});
package.ExitCodes.Add(new ExitCode()
{
Behavior = BehaviorValues.forceReboot,
Value = "1002"
});
package.ExitCodes.Add(new ExitCode()
{
Behavior = BehaviorValues.scheduleReboot,
Value = "1003"
});
package.ExitCodes.Add(new ExitCode()
{
Behavior = BehaviorValues.success,
Value = "1004"
});
package.ExitCodes.Add(new ExitCode()
{
Behavior = BehaviorValues.success,
});

var xml = package.ToXml().First().ToString();
string expected =
"<ExePackage SourceFile=\"c:\\1.exe\">\r\n <ExitCode Behavior=\"error\" Value=\"1001\" />\r\n <ExitCode Behavior=\"forceReboot\" Value=\"1002\" />\r\n <ExitCode Behavior=\"scheduleReboot\" Value=\"1003\" />\r\n <ExitCode Behavior=\"success\" Value=\"1004\" />\r\n <ExitCode Behavior=\"success\" />\r\n</ExePackage>";
Assert.Equal(expected, xml);
}
}
}
67 changes: 66 additions & 1 deletion Source/src/WixSharp/Bootstrapper/Packages.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;
using System.Collections.Generic;
using Microsoft.Win32;
using System.Linq;
using System.Xml.Linq;
Expand Down Expand Up @@ -102,13 +104,14 @@ public class ExePackage : Package
/// </summary>
public ExePackage()
{
ExitCodes = new List<ExitCode>();
}

/// <summary>
/// Initializes a new instance of the <see cref="ExePackage"/> class.
/// </summary>
/// <param name="path">The path.</param>
public ExePackage(string path)
public ExePackage(string path):this()
{
//Name = System.IO.Path.GetFileName(path).Expand();
SourceFile = path;
Expand Down Expand Up @@ -146,6 +149,13 @@ public ExePackage(string path)
[Xml]
public string DetectCondition;

/// <summary>
/// Describes map of exit code returned from executable package to a bootstrapper behavior.
///http://wixtoolset.org/documentation/manual/v3/xsd/wix/exitcode.html
/// </summary>
public List<ExitCode> ExitCodes;


/// <summary>
/// Emits WiX XML.
/// </summary>
Expand All @@ -162,9 +172,14 @@ public override XContainer[] ToXml()
root.AddAttributes(this.Attributes)
.Add(this.MapToXmlAttributes());


if (Payloads.Any())
Payloads.ForEach(p => root.Add(new XElement("Payload", new XAttribute("SourceFile", p))));

foreach (var exitCode in ExitCodes)
{
root.Add(exitCode.ToXElement());
}
return new[] { root };
}
}
Expand Down Expand Up @@ -296,7 +311,57 @@ public override XContainer[] ToXml()
return new[] { new XElement("RollbackBoundary") };
}
}

public class ExitCode
{
/// <summary>
/// Exit code returned from executable package.
/// If no value is provided it means all values not explicitly set default to this behavior.
/// </summary>
[Xml]
public string Value;
/// <summary>
/// Choose one of the supported behaviors error codes: success, error, scheduleReboot, forceReboot.
/// This attribute's value must be one of the following:
/// success
/// error
/// scheduleReboot
/// forceReboot
/// </summary>
[Xml]
public BehaviorValues Behavior;

public XElement ToXElement()
{
var element = new XElement("ExitCode", new XAttribute("Behavior", Behavior));
if (Value != null)
{
element.Add(new XAttribute("Value", Value));
}
return element;
}
}
#pragma warning disable 1591

public enum BehaviorValues
{
/// <summary>
/// return success on specified error code
/// </summary>
success,
/// <summary>
/// return error on specified error code
/// </summary>
error,
/// <summary>
/// schedule reboot on specified error code
/// </summary>
scheduleReboot,
/// <summary>
/// force reboot on specified error code
/// </summary>
forceReboot,
}
public enum SearchResult
{
/// <summary>
Expand Down

0 comments on commit 8ed3a06

Please sign in to comment.