Skip to content

Commit

Permalink
Issue #206: WixQuietExecAction and deferred
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-shilo committed Nov 25, 2017
1 parent d6a84d5 commit 45c72ff
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ static public void Main(string[] args)
{
UI = WUI.WixUI_ProgressOnly,
Name = "CustomActionTest",
Actions = new[] { new WixQuietExecAction("notepad.exe", @"C:\boot.ini")}
Actions = new[] { new WixQuietExecAction("notepad.exe", @"C:\boot.ini") }
};

project.PreserveTempFiles = true;
project.BuildMsi();
}
}



}
Binary file modified Source/src/WixSharp.Samples/WixSharp.dll
Binary file not shown.
16 changes: 8 additions & 8 deletions Source/src/WixSharp.Samples/WixSharp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3047,7 +3047,7 @@
var project =
new Project("MyProduct",
new Dir(@"%ProgramFiles64Folder%\My Company\My Product",
new EventSourceEx
new EventSource
{
Name = "ROOT Builder",
Log = "Application",
Expand Down Expand Up @@ -3078,7 +3078,7 @@
var project =
new Project("MyProduct",
new Dir(@"%ProgramFiles64Folder%\My Company\My Product",
new EventSourceEx
new EventSource
{
Name = "ROOT Builder",
Log = "Application",
Expand Down Expand Up @@ -13763,20 +13763,20 @@
</member>
<member name="T:WixSharp.WixQuietExecAction">
<summary>
Defines WiX <c>QtExecCmdLineAction</c> CustomAction.
Defines WiX <c>QtExecCmdLineAction</c> CustomAction.
<para>
This class is loseley mapped to the <c>WixQuietExec</c> WiX element. WixQuietExec superseeds older CAQuietExec as well as fixes a few
This class is loseley mapped to the <c>WixQuietExec</c> WiX element. WixQuietExec superseeds older CAQuietExec as well as fixes a few
runtime artefacts WiX CAQuietExec was associated with.
</para>
<para><see cref="T:WixSharp.WixQuietExecAction"/> executes specified application with optional arguments.
You do not have to specify full path to the application to be executed as long as its directory
is well-known (e.g. listed in system environment variable <c>PATH</c>) on the target system.</para>
<remarks>
<see cref="T:WixSharp.WixQuietExecAction"/> often needs to be executed with the elevated privileges. Thus after instantiation it will have
<see cref="T:WixSharp.WixQuietExecAction"/> often needs to be executed with the elevated privileges. Thus after instantiation it will have
<see cref="F:WixSharp.Action.Impersonate"/> set to <c>false</c> and <see cref="F:WixSharp.Action.Execute"/> set to <c>Execute.deferred</c> to allow elevating.
</remarks>
</summary>

<example>The following is a complete setup script defining <see cref="T:WixSharp.WixQuietExecAction"/> for
opening <c>bool.ini</c> file in <c>Notepad.exe</c>:
<code>
Expand All @@ -13788,7 +13788,7 @@
Name = "CustomActionTest",
Actions = new[] { new WixQuietExecAction("notepad.exe", @"C:\boot.ini") },
};

Compiler.BuildMsi(project);
}
</code>
Expand Down Expand Up @@ -13879,7 +13879,7 @@
</member>
<member name="F:WixSharp.WixQuietExecAction.ActionName">
<summary>
WixQuietExec or CAQuietExec
WixQuietExec or CAQuietExec
</summary>
</member>
<member name="T:ExternalTool">
Expand Down
38 changes: 24 additions & 14 deletions Source/src/WixSharp/Action.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#region Licence...

/*
The MIT License (MIT)
Copyright (c) 2014 Oleg Shilo
Permission is hereby granted,
Permission is hereby granted,
free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
Expand All @@ -23,14 +24,15 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#endregion

#endregion Licence...

namespace WixSharp
{
/// <summary>
/// Defines generic WiX CustomAction.
/// Defines generic WiX CustomAction.
/// <para>
/// This class does not contain any public constructor and is only to be used
/// This class does not contain any public constructor and is only to be used
/// as a base class for deriving specialized CustomActions (e.g. <see cref="ManagedAction"></see>)
/// or for declaring heterogeneous collections.
/// </para>
Expand All @@ -40,8 +42,8 @@ namespace WixSharp
/// <code>
/// var project = new Project()
/// {
/// Actions = new WixSharp.Action[]
/// {
/// Actions = new WixSharp.Action[]
/// {
/// new ManagedAction(@"FindSQLServerInstance"),
/// new QtCmdLineAction("notepad.exe", @"C:\boot.ini"))
/// },
Expand All @@ -50,17 +52,13 @@ namespace WixSharp
/// </example>
public partial class Action : WixEntity
{
/// <summary>
/// Global counter which is used as suffix for the automatically generated action name. This counter is used by
/// Wix# engine to avoid naming collision and indicate <c>CustomActions</c> declaration order.
/// </summary>
protected static int count = 0;
/// <summary>
/// Default constructor. Creates instance of the <see cref="Action"></see> class.
/// </summary>
protected Action()
{
}

/// <summary>
/// Creates instance of the <see cref="Action"></see> class with properties initialized with specified parameters.
/// </summary>
Expand All @@ -69,6 +67,7 @@ protected Action(Id id)
{
Id = id.Value;
}

/// <summary>
/// Creates instance of the <see cref="Action"></see> class with properties initialized with specified parameters.
/// </summary>
Expand All @@ -83,6 +82,7 @@ protected Action(Return returnType, When when, Step step, Condition condition)
When = when;
Condition = condition;
}

/// <summary>
/// Creates instance of the <see cref="Action"></see> class with properties initialized with specified parameters.
/// </summary>
Expand All @@ -99,6 +99,7 @@ protected Action(Id id, Return returnType, When when, Step step, Condition condi
When = when;
Condition = condition;
}

/// <summary>
/// Creates instance of the <see cref="Action"></see> class with properties initialized with specified parameters.
/// </summary>
Expand All @@ -115,6 +116,7 @@ protected Action(Return returnType, When when, Step step, Condition condition, S
When = when;
Condition = condition;
}

/// <summary>
/// Creates instance of the <see cref="Action"></see> class with properties initialized with specified parameters.
/// </summary>
Expand All @@ -133,37 +135,45 @@ protected Action(Id id, Return returnType, When when, Step step, Condition condi
When = when;
Condition = condition;
}

/// <summary>
/// Defines <see cref="Execute"/> the action associated with.
/// </summary>
public Execute Execute = Execute.immediate;

/// <summary>
/// This attribute specifies whether the Windows Installer, which executes as LocalSystem, should impersonate the user context of the
/// installing user when executing this custom action. Typically the value should be <c>true</c>, except when the custom action needs
/// installing user when executing this custom action. Typically the value should be <c>true</c>, except when the custom action needs
/// elevated privileges to apply changes to the machine.
/// </summary>
public bool? Impersonate;

/// <summary>
/// Defines <see cref="Sequence"/> the action belongs to.
/// </summary>
public Sequence Sequence = Sequence.InstallExecuteSequence;

/// <summary>
/// Defines <see cref="Return"/> type of the action.
/// </summary>
public Return Return = Return.asyncNoWait;

/// <summary>
/// Defines at what <see cref="Step"/> the action should be executed during the installation.
/// </summary>
public Step Step = Step.PreviousActionOrInstallInitialize;

/// <summary>
/// Defines order <see cref="When"/> the action should be executed with respect to the action <see cref="Step"/>.
/// </summary>
public When When = When.After;

/// <summary>
/// Defines the launch <see cref="Condition"/>, which is to be checked during the installation to
/// Defines the launch <see cref="Condition"/>, which is to be checked during the installation to
/// determine if the actions should be executed.
/// </summary>
public Condition Condition = Condition.NOT_Installed;

/// <summary>
/// The sequence number for this action. Mutually exclusive with Before, After, and OnExit of <see cref="When"/> field.
/// </summary>
Expand All @@ -180,4 +190,4 @@ public override string ToString()
return Name;
}
}
}
}
2 changes: 1 addition & 1 deletion Source/src/WixSharp/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2990,7 +2990,7 @@ static void ProcessCustomActions(Project wProject, XElement product)
else if (wAction is WixQuietExecAction)
{
var quietExecAction = (WixQuietExecAction)wAction;
var cmdLineActionId = wAction.Name.Expand();
var cmdLineActionId = wAction.Id;
var setCmdLineActionId = "Set_" + cmdLineActionId;

product.AddElement(
Expand Down
1 change: 0 additions & 1 deletion Source/src/WixSharp/WixEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ public static string IncrementalIdFor(WixEntity entity)
if (entity.GetType() != typeof(Dir) && entity.GetType().BaseType != typeof(Dir) && entity.Name.IsNotEmpty())
rawName = IO.Path.GetFileName(entity.Name).Expand();

//limit 120 chars
//Maximum allowed length for a stream name is 62 characters long; In some cases more but to play it safe keep 62 limit
//
//Note: the total limit 62 needs to include in some cases MSI auto prefix (e.g. table name) ~15 chars
Expand Down
27 changes: 18 additions & 9 deletions Source/src/WixSharp/WixQuietExec.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#region Licence...

/*
The MIT License (MIT)
Copyright (c) 2016 Oleg Shilo
Permission is hereby granted,
Permission is hereby granted,
free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
Expand All @@ -23,27 +24,28 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#endregion

#endregion Licence...

using IO = System.IO;

namespace WixSharp
{
/// <summary>
/// Defines WiX <c>QtExecCmdLineAction</c> CustomAction.
/// Defines WiX <c>QtExecCmdLineAction</c> CustomAction.
/// <para>
/// This class is loseley mapped to the <c>WixQuietExec</c> WiX element. WixQuietExec superseeds older CAQuietExec as well as fixes a few
/// This class is loseley mapped to the <c>WixQuietExec</c> WiX element. WixQuietExec superseeds older CAQuietExec as well as fixes a few
/// runtime artefacts WiX CAQuietExec was associated with.
/// </para>
/// <para><see cref="WixQuietExecAction"/> executes specified application with optional arguments.
/// You do not have to specify full path to the application to be executed as long as its directory
/// is well-known (e.g. listed in system environment variable <c>PATH</c>) on the target system.</para>
/// <remarks>
/// <see cref="WixQuietExecAction"/> often needs to be executed with the elevated privileges. Thus after instantiation it will have
/// <see cref="WixQuietExecAction"/> often needs to be executed with the elevated privileges. Thus after instantiation it will have
/// <see cref="Action.Impersonate"/> set to <c>false</c> and <see cref="Action.Execute"/> set to <c>Execute.deferred</c> to allow elevating.
/// </remarks>
/// </summary>
///
///
/// <example>The following is a complete setup script defining <see cref="WixQuietExecAction"/> for
/// opening <c>bool.ini</c> file in <c>Notepad.exe</c>:
/// <code>
Expand All @@ -55,7 +57,7 @@ namespace WixSharp
/// Name = "CustomActionTest",
/// Actions = new[] { new WixQuietExecAction("notepad.exe", @"C:\boot.ini") },
/// };
///
///
/// Compiler.BuildMsi(project);
/// }
/// </code>
Expand All @@ -79,9 +81,10 @@ public WixQuietExecAction(string appPath, string args)
{
AppPath = appPath;
Args = args;
Name = "Action" + (++count) + "_WixQuietExec_" + IO.Path.GetFileName(appPath);
Name = "WixQuietExec_" + IO.Path.GetFileName(appPath);
Return = Return.check;
}

/// <summary>
/// Executes a new instance of the <see cref="WixQuietExecAction"/> class with properties/fields initialized with specified parameters.
/// </summary>
Expand All @@ -96,6 +99,7 @@ public WixQuietExecAction(Id id, string appPath, string args)
Name = "Action" + (++count) + "_WixQuietExec_" + IO.Path.GetFileName(appPath);
Return = Return.check;
}

/// <summary>
/// Executes a new instance of the <see cref="WixQuietExecAction"/> class with properties/fields initialized with specified parameters.
/// </summary>
Expand All @@ -112,6 +116,7 @@ public WixQuietExecAction(string appPath, string args, Return returnType, When w
Args = args;
Name = "Action" + (++count) + "_WixQuietExec_" + IO.Path.GetFileName(appPath);
}

/// <summary>
/// Executes a new instance of the <see cref="WixQuietExecAction"/> class with properties/fields initialized with specified parameters.
/// </summary>
Expand All @@ -129,6 +134,7 @@ public WixQuietExecAction(Id id, string appPath, string args, Return returnType,
Args = args;
Name = "Action" + (++count) + "_WixQuietExec_" + IO.Path.GetFileName(appPath);
}

/// <summary>
/// Executes a new instance of the <see cref="WixQuietExecAction"/> class with properties/fields initialized with specified parameters.
/// </summary>
Expand All @@ -146,6 +152,7 @@ public WixQuietExecAction(string appPath, string args, Return returnType, When w
Args = args;
Name = "Action" + (++count) + "_WixQuietExec_" + IO.Path.GetFileName(appPath);
}

/// <summary>
/// Executes a new instance of the <see cref="WixQuietExecAction"/> class with properties/fields initialized with specified parameters.
/// </summary>
Expand All @@ -169,6 +176,7 @@ public WixQuietExecAction(Id id, string appPath, string args, Return returnType,
/// Path to the application to be executed. This can be a file name only if the location of the application is well-known.
/// </summary>
public string AppPath = "";

/// <summary>
/// The arguments to be passed to the application during the execution.
/// </summary>
Expand All @@ -178,8 +186,9 @@ public WixQuietExecAction(Id id, string appPath, string args, Return returnType,
/// WixQuietExecCmdLine or QtExecCmdLine
/// </summary>
public string CommandLineProperty = "WixQuietExecCmdLine";

/// <summary>
/// WixQuietExec or CAQuietExec
/// WixQuietExec or CAQuietExec
/// </summary>
public string ActionName = "WixQuietExec";
}
Expand Down

0 comments on commit 45c72ff

Please sign in to comment.