Skip to content

Commit

Permalink
ExecuteCommand: Support scheduling commands relative to one another (…
Browse files Browse the repository at this point in the history
…explictly add the deferred CA to InstallExecuteSequence)
  • Loading branch information
nirbar committed Dec 27, 2023
1 parent 367c58a commit 82a6d32
Show file tree
Hide file tree
Showing 10 changed files with 338 additions and 25 deletions.
4 changes: 2 additions & 2 deletions PanelSwCustomActions/ExecOnComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ extern "C" UINT __stdcall ExecuteCommand(MSIHANDLE hInstall)
hr = cad.AddExec(szCommand, (LPCWSTR)szWorkingFolder, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, isAsync ? Flags::ASync : 0, errorHandling);
ExitOnFailure(hr, "Failed to create command");

hr = cad.DoDeferredAction((LPCWSTR)szId);
ExitOnFailure(hr, "Failed to schedule deferred custom action");
hr = cad.SetCustomActionData((LPCWSTR)szId);
ExitOnFailure(hr, "Failed to set CustomActionData");

LExit:
er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
Expand Down
72 changes: 72 additions & 0 deletions PanelSwWixExtension/MessageResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

123 changes: 123 additions & 0 deletions PanelSwWixExtension/MessageResources.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ExecuteCommandSequence" xml:space="preserve">
<value>The InstallExecuteSequence table contains action '{1}' in between actions required for ExecuteCommand action '{0}'. Please schedule commands to execute after '{0}' or before 'Prepare{0}'</value>
</data>
</root>
42 changes: 42 additions & 0 deletions PanelSwWixExtension/PanelSwWiBackendBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ public override IReadOnlyCollection<TableDefinition> TableDefinitions
new TableDefinition(nameof(PSW_ExecOnComponent), PSW_ExecOnComponent.SymbolDefinition, PSW_ExecOnComponent.ColumnDefinitions, symbolIdIsPrimaryKey: true),
new TableDefinition(nameof(PSW_ExecOnComponent_Environment), PSW_ExecOnComponent_Environment.SymbolDefinition, PSW_ExecOnComponent_Environment.ColumnDefinitions, symbolIdIsPrimaryKey: false),
new TableDefinition(nameof(PSW_ExecOnComponent_ExitCode), PSW_ExecOnComponent_ExitCode.SymbolDefinition, PSW_ExecOnComponent_ExitCode.ColumnDefinitions, symbolIdIsPrimaryKey: false),
new TableDefinition(nameof(PSW_ExecuteCommand), PSW_ExecuteCommand.SymbolDefinition, PSW_ExecuteCommand.ColumnDefinitions, symbolIdIsPrimaryKey: true, unreal: true),
new TableDefinition(nameof(PSW_FileRegex), PSW_FileRegex.SymbolDefinition, PSW_FileRegex.ColumnDefinitions, symbolIdIsPrimaryKey: true),
new TableDefinition(nameof(PSW_ForceVersion), PSW_ForceVersion.SymbolDefinition, PSW_ForceVersion.ColumnDefinitions, symbolIdIsPrimaryKey: false),
new TableDefinition(nameof(PSW_InstallUtil), PSW_InstallUtil.SymbolDefinition, PSW_InstallUtil.ColumnDefinitions, symbolIdIsPrimaryKey: false),
Expand Down Expand Up @@ -547,8 +548,49 @@ public override void SymbolsFinalized(IntermediateSection section)
GetSplitFiles();
ResolveTaskScheduler();
DuplicateFolder(section);
CheckExecuteCommandSequences();
}

private void CheckExecuteCommandSequences()
{
List<PSW_ExecuteCommand> executeCommands = new List<PSW_ExecuteCommand>();
List<WixActionSymbol> wixActions = new List<WixActionSymbol>();
foreach (IntermediateSection intermediate in base.Context.IntermediateRepresentation.Sections)
{
foreach (IntermediateSymbol symbol in intermediate.Symbols)
{
if (symbol is PSW_ExecuteCommand exc)
{
executeCommands.Add(exc);
}
if (symbol is WixActionSymbol act)
{
wixActions.Add(act);
}
}
}

foreach (PSW_ExecuteCommand executeCommand in executeCommands)
{
string prepareId = $"Prepare{executeCommand.Id.Id}";
string schedId = $"Sched{executeCommand.Id.Id}";
string prepareFullId = $"InstallExecuteSequence/{prepareId}";
string schedFullId = $"InstallExecuteSequence/{schedId}";

IEnumerable<WixActionSymbol> actionRows = wixActions.Where(action => action.SequenceTable.Equals(SequenceTable.InstallExecuteSequence) && (
executeCommand.Id.Id.Equals(action.Before) && !schedFullId.Equals(action.Id.Id)) /* Actions that might be sequnced before PSW_ExecuteCommand */
|| (schedId.Equals(action.Before) && !prepareFullId.Equals(action.Id.Id)) /* Before Sched, but not Prepare*/
|| (schedId.Equals(action.After) && !executeCommand.Id.Id.Equals(action.Id.Id)) /* After Sched, but not PSW_ExecuteCommand*/
|| (prepareId.Equals(action.After) && !schedFullId.Equals(action.Id.Id)) /* After Prepare, but not Sched*/
);
foreach (WixActionSymbol action in actionRows)
{
string otherId = action.Id.Id.Remove(0, "InstallExecuteSequence/".Length);
Messaging.Write(PanelSwWixErrorMessages.ExecuteCommandSequence(action.SourceLineNumbers, executeCommand.Id.Id, otherId));
}
}
}

private void DuplicateFolder(IntermediateSection section)
{
List<PSW_DuplicateFolder> duplicateFolders = new List<PSW_DuplicateFolder>();
Expand Down
14 changes: 12 additions & 2 deletions PanelSwWixExtension/PanelSwWixCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,8 @@ private void ParseExecuteCommand(IntermediateSection section, XElement element)
string cad = json.ToString();
cad = Regex.Replace(cad, "([\\[\\]\\{\\}])", "[\\$1]");

section.AddSymbol(new PSW_ExecuteCommand(sourceLineNumbers, new Identifier(AccessModifier.Global, id)));

CustomActionSymbol prepareCA = section.AddSymbol(new CustomActionSymbol(sourceLineNumbers, new Identifier(AccessModifier.Global, $"Prepare{id}")));
prepareCA.ExecutionType = CustomActionExecutionType.Immediate;
prepareCA.Source = "PSW_ExecuteCommand";
Expand Down Expand Up @@ -1070,8 +1072,8 @@ private void ParseExecuteCommand(IntermediateSection section, XElement element)
schedCadSched.Action = schedCAD.Id.Id;
schedCadSched.SequenceTable = SequenceTable.InstallExecuteSequence;
schedCadSched.Condition = condition;
schedCadSched.Before = before;
schedCadSched.After = after;
schedCadSched.Before = id;
schedCadSched.After = null;
schedCadSched.Overridable = false;

// 3. PanelSwCustomActions::CommonDeferred
Expand All @@ -1083,6 +1085,14 @@ private void ParseExecuteCommand(IntermediateSection section, XElement element)
deferredCA.TargetType = CustomActionTargetType.Dll;
deferredCA.Impersonate = impersonate;
deferredCA.Hidden = true;

WixActionSymbol deferredCASched = section.AddSymbol(new WixActionSymbol(sourceLineNumbers, new Identifier(AccessModifier.Global, $"InstallExecuteSequence/{id}")));
deferredCASched.Action = deferredCA.Id.Id;
deferredCASched.SequenceTable = SequenceTable.InstallExecuteSequence;
deferredCASched.Condition = condition;
deferredCASched.Before = before;
deferredCASched.After = after;
deferredCASched.Overridable = false;
}

private void ParseWebsiteConfigElement(IntermediateSection section, XElement element, string component)
Expand Down
Loading

0 comments on commit 82a6d32

Please sign in to comment.