Skip to content

Commit

Permalink
PayloadGroup/FileGlob: Support providing a subfolder prefix for the p…
Browse files Browse the repository at this point in the history
…ayloads' Name attribute. The payloads will be extracted to the provided subfolder
  • Loading branch information
nirbar committed Nov 26, 2024
1 parent 16e9eb5 commit 1e14be0
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/PanelSwWixExtension/PanelSwOptimizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ private void ResolveFileGlob()
{
Identifier id = _parseHelper.CreateIdentifier("glb", glb.PayloadGroup_, recursiveDir, Path.GetFileName(fullPath));
string fileName = Path.Combine(recursiveDir, Path.GetFileName(fullPath));
if (!string.IsNullOrEmpty(glb.PayloadPrefix))
{
fileName = Path.Combine(glb.PayloadPrefix, fileName);
}

section.AddSymbol(new WixBundlePayloadSymbol(glb.SourceLineNumbers, id) { SourceFile = new IntermediateFieldPathValue() { Path = fullPath }, Name = fileName });
section.AddSymbol(new WixGroupSymbol(glb.SourceLineNumbers, id) { ChildId = id.Id, ChildType = ComplexReferenceChildType.Payload, ParentId = glb.PayloadGroup_, ParentType = ComplexReferenceParentType.PayloadGroup });
Expand Down
10 changes: 10 additions & 0 deletions src/PanelSwWixExtension/PanelSwWixCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,7 @@ private void ParseFileGlobElement(IntermediateSection section, XElement element)
string feature_ = null;
string componentGroup_ = null;
string payloadGroup_ = null;
string payloadPrefix = null;

foreach (XAttribute attrib in element.Attributes())
{
Expand All @@ -1091,6 +1092,9 @@ private void ParseFileGlobElement(IntermediateSection section, XElement element)
case "Exclude":
exclude = ParseHelper.GetAttributeValue(sourceLineNumbers, attrib);
break;
case "PayloadPrefix":
payloadPrefix = ParseHelper.GetAttributeValue(sourceLineNumbers, attrib);
break;
default:
ParseHelper.UnexpectedAttribute(element, attrib);
break;
Expand Down Expand Up @@ -1133,6 +1137,11 @@ private void ParseFileGlobElement(IntermediateSection section, XElement element)
break;
}

if (string.IsNullOrEmpty(payloadGroup_) && !string.IsNullOrEmpty(payloadPrefix))
{
XAttribute pldPreAttrib = element.Attributes().FirstOrDefault(a => a.Name.LocalName.Equals("PayloadPrefix"));
ParseHelper.UnexpectedAttribute(element, pldPreAttrib);
}
if (!string.IsNullOrEmpty(payloadGroup_) && !string.IsNullOrEmpty(directory))
{
XAttribute dirAttrib = element.Attributes().FirstOrDefault(a => a.Name.LocalName.Equals("Directory"));
Expand Down Expand Up @@ -1166,6 +1175,7 @@ private void ParseFileGlobElement(IntermediateSection section, XElement element)
globRow.ComponentGroup_ = componentGroup_;
globRow.Feature_ = feature_;
globRow.PayloadGroup_ = payloadGroup_;
globRow.PayloadPrefix = payloadPrefix;

if (!string.IsNullOrEmpty(include) || !string.IsNullOrEmpty(exclude))
{
Expand Down
7 changes: 7 additions & 0 deletions src/PanelSwWixExtension/Symbols/PSW_FileGlob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static IEnumerable<ColumnDefinition> ColumnDefinitions
new ColumnDefinition(nameof(Feature_), ColumnType.String, 72, false, true, ColumnCategory.Identifier, modularizeType: ColumnModularizeType.None, keyTable: "Feature", keyColumn: 1),
new ColumnDefinition(nameof(ComponentGroup_), ColumnType.String, 72, false, true, ColumnCategory.Identifier, modularizeType: ColumnModularizeType.None),
new ColumnDefinition(nameof(PayloadGroup_), ColumnType.String, 72, false, true, ColumnCategory.Identifier, modularizeType: ColumnModularizeType.None),
new ColumnDefinition(nameof(PayloadPrefix), ColumnType.String, 72, false, true, ColumnCategory.Text, modularizeType: ColumnModularizeType.None),
};
}
}
Expand Down Expand Up @@ -64,5 +65,11 @@ public string PayloadGroup_
get => Fields[4].AsString();
set => this.Set(4, value);
}

public string PayloadPrefix
{
get => Fields[5].AsString();
set => this.Set(5, value);
}
}
}
5 changes: 5 additions & 0 deletions src/PanelSwWixExtension/Xsd/PanelSwWixExtension.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@
<xs:documentation>Glob pattern. For example, '**\TextFiles\**\*.txt'</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="PayloadPrefix" type="xs:string" use="optional">
<xs:annotation>
<xs:documentation>When nested under a PayloadGroup, the payloads will be extracted to the provided subfolder</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>

Expand Down
2 changes: 1 addition & 1 deletion src/UnitTests/ContainerTemplateUT/ContainerTemplateUT.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<PanelSW:Pattern Exclude="\**\AccountNamesUT\**"/>
</PanelSW:FileGlob>

<PanelSW:FileGlob SourceDir="!(bindpath.UT)" Include="**\AccountNamesUT\**"/>
<PanelSW:FileGlob SourceDir="!(bindpath.UT)" Include="**\AccountNamesUT\**" PayloadPrefix="my\sub\folder"/>
</PayloadGroup>
</Fragment>
</Wix>
7 changes: 7 additions & 0 deletions src/UnitTests/FileOperationsUT/FileOperationsUT.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<Property Id="MSIFASTINSTALL" Value="1"/>
<SetProperty Id="NONEXISTENT_FOLDER" Value="[OriginalDatabase].doesnt_exist" Before="AppSearch" Sequence="both"/>
<SetProperty Id="NONEXISTENT_FOLDER2" Value="[OriginalDatabase].doesnt_exist" Before="AppSearch" Sequence="both"/>

<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="Test">
Expand Down Expand Up @@ -41,6 +42,12 @@
<File Source="$(sys.SOURCEFILEDIR)\run-test.bat" Name="run-test-on-repair.bat"/>
<PanelSW:RemoveFolderEx Property="REMOVE_ON_REPAIR" On="install"/>
</Component>

<!-- Never installed -->
<Component Guid="" Condition="Installed And Not Installed">
<File Source="$(sys.SOURCEFILEDIR)\run-test.bat" Name="never.bat"/>
<PanelSW:RemoveFolderEx Property="NONEXISTENT_FOLDER2" On="both"/>
</Component>
</ComponentGroup>

<StandardDirectory Id="ProgramFiles6432Folder">
Expand Down

0 comments on commit 1e14be0

Please sign in to comment.