aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2020-06-27 23:53:04 -0700
committerRob Mensching <rob@firegiant.com>2020-06-27 23:55:33 -0700
commit48aea40184697a5394875e07aac2293da10875bb (patch)
treeff6a12ecd4e57375d080a937705927ee6393edf9 /src
parentc8e5b2b045b35bd6e5b8b2021a3173df16500887 (diff)
downloadwix-48aea40184697a5394875e07aac2293da10875bb.tar.gz
wix-48aea40184697a5394875e07aac2293da10875bb.tar.bz2
wix-48aea40184697a5394875e07aac2293da10875bb.zip
Handle multiple Condition conversions
Diffstat (limited to 'src')
-rw-r--r--src/WixToolset.Converters/WixConverter.cs24
-rw-r--r--src/test/WixToolsetTest.Converters/ConditionFixture.cs12
2 files changed, 27 insertions, 9 deletions
diff --git a/src/WixToolset.Converters/WixConverter.cs b/src/WixToolset.Converters/WixConverter.cs
index 7ac64710..86a1bfba 100644
--- a/src/WixToolset.Converters/WixConverter.cs
+++ b/src/WixToolset.Converters/WixConverter.cs
@@ -416,8 +416,9 @@ namespace WixToolset.Converters
416 416
417 private void ConvertControlElement(XElement element) 417 private void ConvertControlElement(XElement element)
418 { 418 {
419 var xCondition = element.Element(ConditionElementName); 419 var remove = new List<XElement>();
420 if (xCondition != null) 420
421 foreach (var xCondition in element.Elements(ConditionElementName))
421 { 422 {
422 var action = UppercaseFirstChar(xCondition.Attribute("Action")?.Value); 423 var action = UppercaseFirstChar(xCondition.Attribute("Action")?.Value);
423 if (!String.IsNullOrEmpty(action) && 424 if (!String.IsNullOrEmpty(action) &&
@@ -425,9 +426,14 @@ namespace WixToolset.Converters
425 this.OnError(ConverterTestType.InnerTextDeprecated, element, "Using {0} element text is deprecated. Use the '{1}Condition' attribute instead.", xCondition.Name.LocalName, action)) 426 this.OnError(ConverterTestType.InnerTextDeprecated, element, "Using {0} element text is deprecated. Use the '{1}Condition' attribute instead.", xCondition.Name.LocalName, action))
426 { 427 {
427 element.Add(new XAttribute(action + "Condition", text)); 428 element.Add(new XAttribute(action + "Condition", text));
428 xCondition.Remove(); 429 remove.Add(xCondition);
429 } 430 }
430 } 431 }
432
433 for (var i = remove.Count - 1; i >= 0; i--)
434 {
435 remove[i].Remove();
436 }
431 } 437 }
432 438
433 private void ConvertComponentElement(XElement element) 439 private void ConvertComponentElement(XElement element)
@@ -517,8 +523,9 @@ namespace WixToolset.Converters
517 523
518 private void ConvertFragmentElement(XElement element) 524 private void ConvertFragmentElement(XElement element)
519 { 525 {
520 var xCondition = element.Element(ConditionElementName); 526 var remove = new List<XElement>();
521 if (xCondition != null) 527
528 foreach (var xCondition in element.Elements(ConditionElementName))
522 { 529 {
523 var message = xCondition.Attribute("Message")?.Value; 530 var message = xCondition.Attribute("Message")?.Value;
524 531
@@ -530,9 +537,14 @@ namespace WixToolset.Converters
530 new XAttribute("Condition", text), 537 new XAttribute("Condition", text),
531 new XAttribute("Message", message) 538 new XAttribute("Message", message)
532 )); 539 ));
533 xCondition.Remove(); 540 remove.Add(xCondition);
534 } 541 }
535 } 542 }
543
544 for (var i = remove.Count - 1; i >= 0; i--)
545 {
546 remove[i].Remove();
547 }
536 } 548 }
537 549
538 private void ConvertEmbeddedChainerElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Condition"); 550 private void ConvertEmbeddedChainerElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Condition");
diff --git a/src/test/WixToolsetTest.Converters/ConditionFixture.cs b/src/test/WixToolsetTest.Converters/ConditionFixture.cs
index 3fa7c031..1b8a7604 100644
--- a/src/test/WixToolsetTest.Converters/ConditionFixture.cs
+++ b/src/test/WixToolsetTest.Converters/ConditionFixture.cs
@@ -20,6 +20,7 @@ namespace WixToolsetTest.Converters
20 " <UI>", 20 " <UI>",
21 " <Dialog Id='Dlg1'>", 21 " <Dialog Id='Dlg1'>",
22 " <Control Id='Control1'>", 22 " <Control Id='Control1'>",
23 " <Condition Action='disable'>x=y</Condition>",
23 " <Condition Action='hide'>a&lt;>b</Condition>", 24 " <Condition Action='hide'>a&lt;>b</Condition>",
24 " </Control>", 25 " </Control>",
25 " </Dialog>", 26 " </Dialog>",
@@ -33,7 +34,8 @@ namespace WixToolsetTest.Converters
33 " <Fragment>", 34 " <Fragment>",
34 " <UI>", 35 " <UI>",
35 " <Dialog Id=\"Dlg1\">", 36 " <Dialog Id=\"Dlg1\">",
36 " <Control Id=\"Control1\" HideCondition=\"a&lt;&gt;b\">", 37 " <Control Id=\"Control1\" DisableCondition=\"x=y\" HideCondition=\"a&lt;&gt;b\">",
38 " ",
37 " ", 39 " ",
38 " </Control>", 40 " </Control>",
39 " </Dialog>", 41 " </Dialog>",
@@ -48,7 +50,7 @@ namespace WixToolsetTest.Converters
48 var converter = new WixConverter(messaging, 2, null, null); 50 var converter = new WixConverter(messaging, 2, null, null);
49 51
50 var errors = converter.ConvertDocument(document); 52 var errors = converter.ConvertDocument(document);
51 Assert.Equal(3, errors); 53 Assert.Equal(4, errors);
52 54
53 var actualLines = UnformattedDocumentLines(document); 55 var actualLines = UnformattedDocumentLines(document);
54 CompareLineByLine(expected, actualLines); 56 CompareLineByLine(expected, actualLines);
@@ -136,6 +138,9 @@ namespace WixToolsetTest.Converters
136 " <Condition Message='Stop the install'>", 138 " <Condition Message='Stop the install'>",
137 " 1&lt;2", 139 " 1&lt;2",
138 " </Condition>", 140 " </Condition>",
141 " <Condition Message='Do not stop'>",
142 " 1=2",
143 " </Condition>",
139 " </Fragment>", 144 " </Fragment>",
140 "</Wix>"); 145 "</Wix>");
141 146
@@ -144,6 +149,7 @@ namespace WixToolsetTest.Converters
144 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">", 149 "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
145 " <Fragment>", 150 " <Fragment>",
146 " <Launch Condition=\"1&lt;2\" Message=\"Stop the install\" />", 151 " <Launch Condition=\"1&lt;2\" Message=\"Stop the install\" />",
152 " <Launch Condition=\"1=2\" Message=\"Do not stop\" />",
147 " </Fragment>", 153 " </Fragment>",
148 "</Wix>" 154 "</Wix>"
149 }; 155 };
@@ -154,7 +160,7 @@ namespace WixToolsetTest.Converters
154 var converter = new WixConverter(messaging, 2, null, null); 160 var converter = new WixConverter(messaging, 2, null, null);
155 161
156 var errors = converter.ConvertDocument(document); 162 var errors = converter.ConvertDocument(document);
157 Assert.Equal(3, errors); 163 Assert.Equal(4, errors);
158 164
159 var actualLines = UnformattedDocumentLines(document); 165 var actualLines = UnformattedDocumentLines(document);
160 CompareLineByLine(expected, actualLines); 166 CompareLineByLine(expected, actualLines);