From 8ebde131206f1502cbff2055941ffe52e2802439 Mon Sep 17 00:00:00 2001 From: Charles Baker Date: Thu, 24 Oct 2024 13:13:26 +1300 Subject: Add bal:DisplayFilesInUseDialogCondition to disable Files In Use dialog Disabling display skips showing the "Files In Use" dialog and returning a result as if the user had chosen to ignore the dialog and reboot in the case of files that were unable to be replaced. --- .../IPackageInfo.cs | 5 +++ .../PackageInfo.cs | 4 ++ src/api/burn/balutil/balinfo.cpp | 4 ++ src/api/burn/balutil/inc/balinfo.h | 1 + .../stdbas/WixStandardBootstrapperApplication.cpp | 52 +++++++++++++++------- .../BalExtensionFixture.cs | 39 ++++++++++++++++ .../InternalUIBAFixture.cs | 3 +- .../TestData/Overridable/WrongCaseBundle.wxs | 2 +- .../TestData/WixIuiBa/IuibaWarnings.wxs | 2 +- .../DisplayFilesInUseDialogConditionBundle.wxs | 12 +++++ src/ext/Bal/wixext/BalBurnBackendExtension.cs | 22 +++++++++ src/ext/Bal/wixext/BalCompiler.cs | 14 ++++++ src/ext/Bal/wixext/BalWarnings.cs | 6 +++ .../Bal/wixext/Symbols/WixBalPackageInfoSymbol.cs | 8 ++++ src/xsd/bal.xsd | 15 +++++++ 15 files changed, 169 insertions(+), 20 deletions(-) create mode 100644 src/ext/Bal/test/WixToolsetTest.BootstrapperApplications/TestData/WixStdBa/DisplayFilesInUseDialogConditionBundle.wxs (limited to 'src') diff --git a/src/api/burn/WixToolset.BootstrapperApplicationApi/IPackageInfo.cs b/src/api/burn/WixToolset.BootstrapperApplicationApi/IPackageInfo.cs index e2512584..9b5e74cb 100644 --- a/src/api/burn/WixToolset.BootstrapperApplicationApi/IPackageInfo.cs +++ b/src/api/burn/WixToolset.BootstrapperApplicationApi/IPackageInfo.cs @@ -27,6 +27,11 @@ namespace WixToolset.BootstrapperApplicationApi /// string DisplayInternalUICondition { get; } + /// + /// The authored bal:DisplayFilesInUseDialogCondition. + /// + string DisplayFilesInUseDialogCondition { get; } + /// /// The package's display name. /// diff --git a/src/api/burn/WixToolset.BootstrapperApplicationApi/PackageInfo.cs b/src/api/burn/WixToolset.BootstrapperApplicationApi/PackageInfo.cs index e835f9ea..81a8869f 100644 --- a/src/api/burn/WixToolset.BootstrapperApplicationApi/PackageInfo.cs +++ b/src/api/burn/WixToolset.BootstrapperApplicationApi/PackageInfo.cs @@ -120,6 +120,9 @@ namespace WixToolset.BootstrapperApplicationApi /// public string DisplayInternalUICondition { get; internal set; } + /// + public string DisplayFilesInUseDialogCondition { get; internal set; } + /// public string ProductCode { get; internal set; } @@ -363,6 +366,7 @@ namespace WixToolset.BootstrapperApplicationApi var package = (PackageInfo)ipackage; package.DisplayInternalUICondition = BootstrapperApplicationData.GetAttribute(node, "DisplayInternalUICondition"); + package.DisplayFilesInUseDialogCondition = BootstrapperApplicationData.GetAttribute(node, "DisplayFilesInUseDialogCondition"); } nodes = root.Select("/p:BootstrapperApplicationData/p:WixPrereqInformation", namespaceManager); diff --git a/src/api/burn/balutil/balinfo.cpp b/src/api/burn/balutil/balinfo.cpp index 38c4bd18..ff0dfd9f 100644 --- a/src/api/burn/balutil/balinfo.cpp +++ b/src/api/burn/balutil/balinfo.cpp @@ -291,6 +291,7 @@ DAPI_(void) BalInfoUninitialize( ReleaseStr(pBundle->packages.rgPackages[i].sczDescription); ReleaseStr(pBundle->packages.rgPackages[i].sczId); ReleaseStr(pBundle->packages.rgPackages[i].sczDisplayInternalUICondition); + ReleaseStr(pBundle->packages.rgPackages[i].sczDisplayFilesInUseDialogCondition); ReleaseStr(pBundle->packages.rgPackages[i].sczProductCode); ReleaseStr(pBundle->packages.rgPackages[i].sczUpgradeCode); ReleaseStr(pBundle->packages.rgPackages[i].sczVersion); @@ -517,6 +518,9 @@ static HRESULT ParseBalPackageInfoFromXml( hr = XmlGetAttributeEx(pNode, L"DisplayInternalUICondition", &pPackage->sczDisplayInternalUICondition); ExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get DisplayInternalUICondition setting for package."); + hr = XmlGetAttributeEx(pNode, L"DisplayFilesInUseDialogCondition", &pPackage->sczDisplayFilesInUseDialogCondition); + ExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get DisplayFilesInUseDialogCondition setting for package."); + hr = XmlGetAttributeEx(pNode, L"PrimaryPackageType", &scz); ExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get PrimaryPackageType setting for package."); diff --git a/src/api/burn/balutil/inc/balinfo.h b/src/api/burn/balutil/inc/balinfo.h index 234284f6..8baee844 100644 --- a/src/api/burn/balutil/inc/balinfo.h +++ b/src/api/burn/balutil/inc/balinfo.h @@ -54,6 +54,7 @@ typedef struct _BAL_INFO_PACKAGE BOOL fPermanent; BOOL fVital; LPWSTR sczDisplayInternalUICondition; + LPWSTR sczDisplayFilesInUseDialogCondition; LPWSTR sczProductCode; LPWSTR sczUpgradeCode; LPWSTR sczVersion; diff --git a/src/ext/Bal/stdbas/WixStandardBootstrapperApplication.cpp b/src/ext/Bal/stdbas/WixStandardBootstrapperApplication.cpp index 6cfe0b4c..ddb2d1c5 100644 --- a/src/ext/Bal/stdbas/WixStandardBootstrapperApplication.cpp +++ b/src/ext/Bal/stdbas/WixStandardBootstrapperApplication.cpp @@ -1231,34 +1231,52 @@ public: // IBootstrapperApplication __inout int* pResult ) { + HRESULT hr = S_OK; + BAL_INFO_PACKAGE* pPackage = NULL; + BOOL fShowFilesInUseDialog = TRUE; if (!m_fShowingInternalUiThisPackage && wzPackageId && *wzPackageId) { BalLog(BOOTSTRAPPER_LOG_LEVEL_VERBOSE, "Package %ls has %d applications holding files in use.", wzPackageId, cFiles); - switch (source) + hr = BalInfoFindPackageById(&m_Bundle.packages, wzPackageId, &pPackage); + if (SUCCEEDED(hr) && pPackage->sczDisplayFilesInUseDialogCondition) { - case BOOTSTRAPPER_FILES_IN_USE_TYPE_MSI: - if (m_fShowStandardFilesInUse) - { - return ShowMsiFilesInUse(cFiles, rgwzFiles, source, pResult); - } - break; - case BOOTSTRAPPER_FILES_IN_USE_TYPE_MSI_RM: - if (m_fShowRMFilesInUse) - { - return ShowMsiFilesInUse(cFiles, rgwzFiles, source, pResult); - } - break; - case BOOTSTRAPPER_FILES_IN_USE_TYPE_NETFX: - if (m_fShowNetfxFilesInUse) + hr = BalEvaluateCondition(pPackage->sczDisplayFilesInUseDialogCondition, &fShowFilesInUseDialog); + BalExitOnFailure(hr, "Failed to evaluate condition for package '%ls': %ls", wzPackageId, pPackage->sczDisplayFilesInUseDialogCondition); + } + + if (fShowFilesInUseDialog) + { + switch (source) { - return ShowNetfxFilesInUse(cFiles, rgwzFiles, pResult); + case BOOTSTRAPPER_FILES_IN_USE_TYPE_MSI: + if (m_fShowStandardFilesInUse) + { + return ShowMsiFilesInUse(cFiles, rgwzFiles, source, pResult); + } + break; + case BOOTSTRAPPER_FILES_IN_USE_TYPE_MSI_RM: + if (m_fShowRMFilesInUse) + { + return ShowMsiFilesInUse(cFiles, rgwzFiles, source, pResult); + } + break; + case BOOTSTRAPPER_FILES_IN_USE_TYPE_NETFX: + if (m_fShowNetfxFilesInUse) + { + return ShowNetfxFilesInUse(cFiles, rgwzFiles, pResult); + } + break; } - break; + } + else + { + *pResult = IDIGNORE; } } + LExit: return __super::OnExecuteFilesInUse(wzPackageId, cFiles, rgwzFiles, nRecommendation, source, pResult); } diff --git a/src/ext/Bal/test/WixToolsetTest.BootstrapperApplications/BalExtensionFixture.cs b/src/ext/Bal/test/WixToolsetTest.BootstrapperApplications/BalExtensionFixture.cs index 07d3dacb..576e7c6c 100644 --- a/src/ext/Bal/test/WixToolsetTest.BootstrapperApplications/BalExtensionFixture.cs +++ b/src/ext/Bal/test/WixToolsetTest.BootstrapperApplications/BalExtensionFixture.cs @@ -55,6 +55,44 @@ namespace WixToolsetTest.BootstrapperApplications } } + [TestMethod] + public void CanBuildUsingDisplayFilesInUseDialogCondition() + { + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var bundleFile = Path.Combine(baseFolder, "bin", "test.exe"); + var bundleSourceFolder = TestData.Get(@"TestData\WixStdBa"); + var intermediateFolder = Path.Combine(baseFolder, "obj"); + var baFolderPath = Path.Combine(baseFolder, "ba"); + var extractFolderPath = Path.Combine(baseFolder, "extract"); + + var compileResult = WixRunner.Execute(new[] + { + "build", + Path.Combine(bundleSourceFolder, "DisplayFilesInUseDialogConditionBundle.wxs"), + "-ext", TestData.Get(@"WixToolset.BootstrapperApplications.wixext.dll"), + "-intermediateFolder", intermediateFolder, + "-bindpath", Path.Combine(bundleSourceFolder, "data"), + "-o", bundleFile, + }); + compileResult.AssertSuccess(); + + Assert.IsTrue(File.Exists(bundleFile)); + + var extractResult = BundleExtractor.ExtractBAContainer(null, bundleFile, baFolderPath, extractFolderPath); + extractResult.AssertSuccess(); + + var balPackageInfos = extractResult.GetBADataTestXmlLines("/ba:BootstrapperApplicationData/ba:WixBalPackageInfo"); + WixAssert.CompareLineByLine(new string[] + { + "", + }, balPackageInfos); + + Assert.IsTrue(File.Exists(Path.Combine(baFolderPath, "thm.wxl"))); + } + } + [TestMethod] public void CanBuildUsingBootstrapperApplicationId() { @@ -298,6 +336,7 @@ namespace WixToolsetTest.BootstrapperApplications { "bal:Condition/@Condition contains the built-in Variable 'WixBundleAction', which is not available when it is evaluated. (Unavailable Variables are: 'WixBundleAction'.). Rewrite the condition to avoid Variables that are never valid during its evaluation.", "Overridable variable 'TEST1' collides with 'Test1' with Bundle/@CommandLineVariables value 'caseInsensitive'.", + "The *Package/@bal:DisplayFilesInUseDialogCondition attribute's value '=' is not a valid bundle condition.", "The *Package/@bal:DisplayInternalUICondition attribute's value '=' is not a valid bundle condition.", "The location of the Variable related to the previous error.", }, messages.ToArray()); diff --git a/src/ext/Bal/test/WixToolsetTest.BootstrapperApplications/InternalUIBAFixture.cs b/src/ext/Bal/test/WixToolsetTest.BootstrapperApplications/InternalUIBAFixture.cs index 72e31540..7b4d00fc 100644 --- a/src/ext/Bal/test/WixToolsetTest.BootstrapperApplications/InternalUIBAFixture.cs +++ b/src/ext/Bal/test/WixToolsetTest.BootstrapperApplications/InternalUIBAFixture.cs @@ -168,6 +168,7 @@ namespace WixToolsetTest.BootstrapperApplications "WixInternalUIBootstrapperApplication does not support the value of 'force' for Cache on prereq packages. Prereq packages are only cached when they need to be installed.", "WixInternalUIBootstrapperApplication ignores InstallCondition for the primary package so that the MSI UI is always shown.", "WixInternalUIBootstrapperApplication ignores DisplayInternalUICondition for the primary package so that the MSI UI is always shown.", + "WixInternalUIBootstrapperApplication ignores DisplayFilesInUseDialogCondition for the primary package so that the MSI UI is always shown.", "When using WixInternalUIBootstrapperApplication, all prereq packages should be before the primary package in the chain. The prereq packages are always installed before the primary package.", }, compileResult.Messages.Select(m => m.ToString()).ToArray()); @@ -181,7 +182,7 @@ namespace WixToolsetTest.BootstrapperApplications var balPackageInfos = extractResult.GetBADataTestXmlLines("/ba:BootstrapperApplicationData/ba:WixBalPackageInfo"); WixAssert.CompareLineByLine(new string[] { - "", + "", }, balPackageInfos); var mbaPrereqInfos = extractResult.GetBADataTestXmlLines("/ba:BootstrapperApplicationData/ba:WixPrereqInformation"); diff --git a/src/ext/Bal/test/WixToolsetTest.BootstrapperApplications/TestData/Overridable/WrongCaseBundle.wxs b/src/ext/Bal/test/WixToolsetTest.BootstrapperApplications/TestData/Overridable/WrongCaseBundle.wxs index 67dfc589..33b2d64c 100644 --- a/src/ext/Bal/test/WixToolsetTest.BootstrapperApplications/TestData/Overridable/WrongCaseBundle.wxs +++ b/src/ext/Bal/test/WixToolsetTest.BootstrapperApplications/TestData/Overridable/WrongCaseBundle.wxs @@ -9,7 +9,7 @@ - + diff --git a/src/ext/Bal/test/WixToolsetTest.BootstrapperApplications/TestData/WixIuiBa/IuibaWarnings.wxs b/src/ext/Bal/test/WixToolsetTest.BootstrapperApplications/TestData/WixIuiBa/IuibaWarnings.wxs index 2cf9787d..9c9aa0f8 100644 --- a/src/ext/Bal/test/WixToolsetTest.BootstrapperApplications/TestData/WixIuiBa/IuibaWarnings.wxs +++ b/src/ext/Bal/test/WixToolsetTest.BootstrapperApplications/TestData/WixIuiBa/IuibaWarnings.wxs @@ -6,7 +6,7 @@ - + diff --git a/src/ext/Bal/test/WixToolsetTest.BootstrapperApplications/TestData/WixStdBa/DisplayFilesInUseDialogConditionBundle.wxs b/src/ext/Bal/test/WixToolsetTest.BootstrapperApplications/TestData/WixStdBa/DisplayFilesInUseDialogConditionBundle.wxs new file mode 100644 index 00000000..1041eb39 --- /dev/null +++ b/src/ext/Bal/test/WixToolsetTest.BootstrapperApplications/TestData/WixStdBa/DisplayFilesInUseDialogConditionBundle.wxs @@ -0,0 +1,12 @@ + + + + + + + + + + + diff --git a/src/ext/Bal/wixext/BalBurnBackendExtension.cs b/src/ext/Bal/wixext/BalBurnBackendExtension.cs index 82195549..5831bb8a 100644 --- a/src/ext/Bal/wixext/BalBurnBackendExtension.cs +++ b/src/ext/Bal/wixext/BalBurnBackendExtension.cs @@ -51,6 +51,11 @@ namespace WixToolset.BootstrapperApplications writer.WriteAttributeString("DisplayInternalUICondition", balPackageInfoSymbol.DisplayInternalUICondition); } + if (balPackageInfoSymbol.DisplayFilesInUseDialogCondition != null) + { + writer.WriteAttributeString("DisplayFilesInUseDialogCondition", balPackageInfoSymbol.DisplayFilesInUseDialogCondition); + } + if (balPackageInfoSymbol.PrimaryPackageType != BalPrimaryPackageType.None) { writer.WriteAttributeString("PrimaryPackageType", balPackageInfoSymbol.PrimaryPackageType.ToString().ToLower()); @@ -104,6 +109,7 @@ namespace WixToolset.BootstrapperApplications this.VerifyBalConditions(section); this.VerifyDisplayInternalUICondition(section); + this.VerifyDisplayFilesInUseDialogCondition(section); this.VerifyOverridableVariables(section); var balBaSymbol = section.Symbols.OfType().SingleOrDefault(); @@ -195,6 +201,17 @@ namespace WixToolset.BootstrapperApplications } } + private void VerifyDisplayFilesInUseDialogCondition(IntermediateSection section) + { + foreach (var balPackageInfoSymbol in section.Symbols.OfType().ToList()) + { + if (balPackageInfoSymbol.DisplayFilesInUseDialogCondition != null) + { + this.BackendHelper.ValidateBundleCondition(balPackageInfoSymbol.SourceLineNumbers, "*Package", "bal:DisplayFilesInUseDialogCondition", balPackageInfoSymbol.DisplayFilesInUseDialogCondition, BundleConditionPhase.Plan); + } + } + } + private void VerifyPrimaryPackages(IntermediateSection section, SourceLineNumber baSourceLineNumbers) { WixBalPackageInfoSymbol defaultPrimaryPackage = null; @@ -420,6 +437,11 @@ namespace WixToolset.BootstrapperApplications { this.Messaging.Write(BalWarnings.IuibaPrimaryPackageDisplayInternalUICondition(packageSymbol.SourceLineNumbers)); } + + if (balPackageInfoSymbol.DisplayFilesInUseDialogCondition != null) + { + this.Messaging.Write(BalWarnings.IuibaPrimaryPackageDisplayFilesInUseDialogCondition(packageSymbol.SourceLineNumbers)); + } } private void VerifyOverridableVariables(IntermediateSection section) diff --git a/src/ext/Bal/wixext/BalCompiler.cs b/src/ext/Bal/wixext/BalCompiler.cs index 35c86233..b7d5f679 100644 --- a/src/ext/Bal/wixext/BalCompiler.cs +++ b/src/ext/Bal/wixext/BalCompiler.cs @@ -200,6 +200,20 @@ namespace WixToolset.BootstrapperApplications break; } break; + case "DisplayFilesInUseDialogCondition": + switch (parentElement.Name.LocalName) + { + case "MsiPackage": + case "MspPackage": + var displayFilesInUseDialogCondition = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attribute); + var packageInfo = this.GetBalPackageInfoSymbol(section, sourceLineNumbers, packageId); + packageInfo.DisplayFilesInUseDialogCondition = displayFilesInUseDialogCondition; + break; + default: + this.ParseHelper.UnexpectedAttribute(parentElement, attribute); + break; + } + break; case "PrimaryPackageType": { var primaryPackageType = BalPrimaryPackageType.None; diff --git a/src/ext/Bal/wixext/BalWarnings.cs b/src/ext/Bal/wixext/BalWarnings.cs index 8c5d892f..f86837f9 100644 --- a/src/ext/Bal/wixext/BalWarnings.cs +++ b/src/ext/Bal/wixext/BalWarnings.cs @@ -23,6 +23,11 @@ namespace WixToolset.BootstrapperApplications return Message(sourceLineNumbers, Ids.IuibaPrimaryPackageDisplayInternalUICondition, "WixInternalUIBootstrapperApplication ignores DisplayInternalUICondition for the primary package so that the MSI UI is always shown."); } + public static Message IuibaPrimaryPackageDisplayFilesInUseDialogCondition(SourceLineNumber sourceLineNumbers) + { + return Message(sourceLineNumbers, Ids.IuibaPrimaryPackageDisplayFilesInUseDialogCondition, "WixInternalUIBootstrapperApplication ignores DisplayFilesInUseDialogCondition for the primary package so that the MSI UI is always shown."); + } + public static Message IuibaPrimaryPackageInstallCondition(SourceLineNumber sourceLineNumbers) { return Message(sourceLineNumbers, Ids.IuibaPrimaryPackageInstallCondition, "WixInternalUIBootstrapperApplication ignores InstallCondition for the primary package so that the MSI UI is always shown."); @@ -56,6 +61,7 @@ namespace WixToolset.BootstrapperApplications IuibaPrimaryPackageDisplayInternalUICondition = 6504, IuibaPrereqPackageAfterPrimaryPackage = 6505, DeprecatedBAFactoryAssemblyAttribute = 6506, + IuibaPrimaryPackageDisplayFilesInUseDialogCondition = 6507, } } } diff --git a/src/ext/Bal/wixext/Symbols/WixBalPackageInfoSymbol.cs b/src/ext/Bal/wixext/Symbols/WixBalPackageInfoSymbol.cs index e2636d33..6e90c2b9 100644 --- a/src/ext/Bal/wixext/Symbols/WixBalPackageInfoSymbol.cs +++ b/src/ext/Bal/wixext/Symbols/WixBalPackageInfoSymbol.cs @@ -14,6 +14,7 @@ namespace WixToolset.BootstrapperApplications new IntermediateFieldDefinition(nameof(WixBalPackageInfoSymbolFields.PackageId), IntermediateFieldType.String), new IntermediateFieldDefinition(nameof(WixBalPackageInfoSymbolFields.DisplayInternalUICondition), IntermediateFieldType.String), new IntermediateFieldDefinition(nameof(WixBalPackageInfoSymbolFields.PrimaryPackageType), IntermediateFieldType.Number), + new IntermediateFieldDefinition(nameof(WixBalPackageInfoSymbolFields.DisplayFilesInUseDialogCondition), IntermediateFieldType.String), }, typeof(WixBalPackageInfoSymbol)); } @@ -28,6 +29,7 @@ namespace WixToolset.BootstrapperApplications.Symbols PackageId, DisplayInternalUICondition, PrimaryPackageType, + DisplayFilesInUseDialogCondition, } public enum BalPrimaryPackageType @@ -68,5 +70,11 @@ namespace WixToolset.BootstrapperApplications.Symbols get => (BalPrimaryPackageType)this.Fields[(int)WixBalPackageInfoSymbolFields.PrimaryPackageType].AsNumber(); set => this.Set((int)WixBalPackageInfoSymbolFields.PrimaryPackageType, (int)value); } + + public string DisplayFilesInUseDialogCondition + { + get => this.Fields[(int)WixBalPackageInfoSymbolFields.DisplayFilesInUseDialogCondition].AsString(); + set => this.Set((int)WixBalPackageInfoSymbolFields.DisplayFilesInUseDialogCondition, value); + } } } diff --git a/src/xsd/bal.xsd b/src/xsd/bal.xsd index ff4142ad..59c1f91e 100644 --- a/src/xsd/bal.xsd +++ b/src/xsd/bal.xsd @@ -623,6 +623,21 @@ + + + + Specifies whether the bundle allows the Files In Use dialog to be displayed for the MSI or MSP package. If not + specified (the default) or the condition evaluates to true, the Files In Use dialog prompts the user during full + bundle UI to close applications to release the file. Otherwise, the dialog is not displayed and the package might + require a restart when files are in use. + + + + + + + + -- cgit v1.2.3-55-g6feb