From 648f370f7966b2738c1446601057d888bbd2c70f Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Fri, 3 Jun 2022 17:48:57 -0500 Subject: Make PathGetSystemPath return an array of paths ordered by preference. --- src/test/burn/WixTestTools/BundleVerifier.cs | 12 +++- src/test/burn/WixToolsetTest.BurnE2E/CacheTests.cs | 68 ++++++++++++++++++++++ 2 files changed, 78 insertions(+), 2 deletions(-) (limited to 'src/test') diff --git a/src/test/burn/WixTestTools/BundleVerifier.cs b/src/test/burn/WixTestTools/BundleVerifier.cs index 594b19aa..103171cd 100644 --- a/src/test/burn/WixTestTools/BundleVerifier.cs +++ b/src/test/burn/WixTestTools/BundleVerifier.cs @@ -15,7 +15,8 @@ namespace WixTestTools public partial class BundleInstaller { public const string DependencyRegistryRoot = "Software\\Classes\\Installer\\Dependencies"; - public const string FULL_BURN_POLICY_REGISTRY_PATH = "SOFTWARE\\WOW6432Node\\Policies\\WiX\\Burn"; + public const string FULL_BURN_POLICY_REGISTRY_PATH = "SOFTWARE\\Policies\\WiX\\Burn"; + public const string FULL_BURN_POLICY_REGISTRY_PATH_WOW6432NODE = "SOFTWARE\\WOW6432Node\\Policies\\WiX\\Burn"; public const string PACKAGE_CACHE_FOLDER_NAME = "Package Cache"; public string BundlePdb { get; } @@ -35,12 +36,19 @@ namespace WixTestTools return this.BundleSymbol; } + public string GetFullBurnPolicyRegistryPath() + { + var bundleSymbol = this.GetBundleSymbol(); + var x64 = bundleSymbol.Platform != Platform.X86; + return x64 ? FULL_BURN_POLICY_REGISTRY_PATH : FULL_BURN_POLICY_REGISTRY_PATH_WOW6432NODE; + } + public string GetPackageCachePathForCacheId(string cacheId, bool perMachine) { string cachePath; if (perMachine) { - using var policyKey = Registry.LocalMachine.OpenSubKey(FULL_BURN_POLICY_REGISTRY_PATH); + using var policyKey = Registry.LocalMachine.OpenSubKey(this.GetFullBurnPolicyRegistryPath()); var redirectedCachePath = policyKey?.GetValue("PackageCache") as string; cachePath = redirectedCachePath ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), PACKAGE_CACHE_FOLDER_NAME); } diff --git a/src/test/burn/WixToolsetTest.BurnE2E/CacheTests.cs b/src/test/burn/WixToolsetTest.BurnE2E/CacheTests.cs index 6c8250d9..f5a1cda8 100644 --- a/src/test/burn/WixToolsetTest.BurnE2E/CacheTests.cs +++ b/src/test/burn/WixToolsetTest.BurnE2E/CacheTests.cs @@ -5,6 +5,7 @@ namespace WixToolsetTest.BurnE2E using System; using System.Collections.Generic; using System.IO; + using Microsoft.Win32; using WixBuildTools.TestSupport; using WixTestTools; using WixToolset.Mba.Core; @@ -201,5 +202,72 @@ namespace WixToolsetTest.BurnE2E packageB.VerifyInstalled(true); } } + + [RuntimeFact] + public void CanGetEngineWorkingDirectoryFromCommandLine() + { + var bundleA = this.CreateBundleInstaller("BundleA"); + var testBAController = this.CreateTestBAController(); + + testBAController.SetImmediatelyQuit(); + + using (var dfs = new DisposableFileSystem()) + { + var baseTempPath = dfs.GetFolder(true); + var logPath = bundleA.Install(0, $"-burn.engine.working.directory=\"{baseTempPath}\""); + LogVerifier.MessageInLogFileRegex(logPath, $"Burn x86 v4.*, Windows v.* \\(Build .*: Service Pack .*\\), path: {baseTempPath.Replace("\\", "\\\\")}\\\\.*\\\\.cr\\\\BundleA.exe"); + } + } + + [RuntimeFact] + public void CanGetEngineWorkingDirectoryFromPolicy() + { + var deletePolicyKey = false; + string originalPolicyValue = null; + + var bundleA = this.CreateBundleInstaller("BundleA"); + var testBAController = this.CreateTestBAController(); + var policyPath = bundleA.GetFullBurnPolicyRegistryPath(); + + testBAController.SetImmediatelyQuit(); + + try + { + using (var dfs = new DisposableFileSystem()) + { + var baseTempPath = dfs.GetFolder(true); + + var policyKey = Registry.LocalMachine.OpenSubKey(policyPath, writable: true); + if (policyKey == null) + { + policyKey = Registry.LocalMachine.CreateSubKey(policyPath, writable: true); + deletePolicyKey = true; + } + + using (policyKey) + { + originalPolicyValue = policyKey.GetValue("EngineWorkingDirectory") as string; + policyKey.SetValue("EngineWorkingDirectory", baseTempPath); + } + + var logPath = bundleA.Install(); + LogVerifier.MessageInLogFileRegex(logPath, $"Burn x86 v4.*, Windows v.* \\(Build .*: Service Pack .*\\), path: {baseTempPath.Replace("\\", "\\\\")}\\\\.*\\\\.cr\\\\BundleA.exe"); + } + } + finally + { + if (deletePolicyKey) + { + Registry.LocalMachine.DeleteSubKeyTree(policyPath); + } + else if (originalPolicyValue != null) + { + using (var policyKey = Registry.LocalMachine.CreateSubKey(policyPath, writable: true)) + { + policyKey.SetValue("EngineWorkingDirectory", originalPolicyValue); + } + } + } + } } } -- cgit v1.2.3-55-g6feb