From 062d6387692d074f502176296f361c52026b96d5 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Fri, 19 Mar 2021 07:47:43 -0700 Subject: Improve finding files relative to Core.Native assembly Should fix unit testing issues when .cub files cannot be found. --- src/WixToolset.Core.Native/WindowsInstallerValidator.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/WixToolset.Core.Native/WindowsInstallerValidator.cs') diff --git a/src/WixToolset.Core.Native/WindowsInstallerValidator.cs b/src/WixToolset.Core.Native/WindowsInstallerValidator.cs index d013e5f9..9f4b26a3 100644 --- a/src/WixToolset.Core.Native/WindowsInstallerValidator.cs +++ b/src/WixToolset.Core.Native/WindowsInstallerValidator.cs @@ -86,9 +86,6 @@ namespace WixToolset.Core.Native var previousHwnd = IntPtr.Zero; InstallUIHandler previousUIHandler = null; - var baseCubePath = Path.Combine(Path.GetDirectoryName(typeof(WindowsInstallerValidator).Assembly.Location), CubesFolder); - var cubeFiles = this.CubeFiles.Select(s => Path.Combine(baseCubePath, s)).ToList(); - try { using (var database = new Database(this.DatabasePath, OpenDatabase.Direct)) @@ -116,11 +113,18 @@ namespace WixToolset.Core.Native } // Merge in the cube databases. - foreach (var cubeFile in cubeFiles) + foreach (var cubeFile in this.CubeFiles) { + var findCubeFile = typeof(WindowsInstallerValidator).Assembly.FindFileRelativeToAssembly(Path.Combine(CubesFolder, cubeFile), searchNativeDllDirectories: false); + + if (!findCubeFile.Found) + { + throw new WixException(ErrorMessages.CubeFileNotFound(findCubeFile.Path)); + } + try { - using (var cubeDatabase = new Database(cubeFile, OpenDatabase.ReadOnly)) + using (var cubeDatabase = new Database(findCubeFile.Path, OpenDatabase.ReadOnly)) { try { @@ -136,7 +140,7 @@ namespace WixToolset.Core.Native { if (0x6E == e.NativeErrorCode) // ERROR_OPEN_FAILED { - throw new WixException(ErrorMessages.CubeFileNotFound(cubeFile)); + throw new WixException(ErrorMessages.CubeFileNotFound(findCubeFile.Path)); } throw; -- cgit v1.2.3-55-g6feb