From 590c667a1ecd97a79056daf44dc75bdc7580cb9a Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sat, 13 Jul 2024 00:28:18 -0700 Subject: [PATCH] Reset current directory so SFXCA directory can be cleaned up Fixes 8630 --- .../CustomActionProxy.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/dtf/WixToolset.Dtf.WindowsInstaller/CustomActionProxy.cs b/src/dtf/WixToolset.Dtf.WindowsInstaller/CustomActionProxy.cs index f58ff07de..fca15dbcb 100644 --- a/src/dtf/WixToolset.Dtf.WindowsInstaller/CustomActionProxy.cs +++ b/src/dtf/WixToolset.Dtf.WindowsInstaller/CustomActionProxy.cs @@ -101,8 +101,13 @@ public static int InvokeCustomAction(int sessionHandle, string entryPoint, return (int) ActionResult.Failure; } + string originalDirectory = null; + try { + // Remember the original directory so we can restore it later. + originalDirectory = Environment.CurrentDirectory; + // Set the current directory to the location of the extracted files. Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory; @@ -142,6 +147,20 @@ public static int InvokeCustomAction(int sessionHandle, string entryPoint, session.Log(ex.ToString()); return (int) ActionResult.Failure; } + finally + { + try + { + if (!String.IsNullOrEmpty(originalDirectory)) + { + Environment.CurrentDirectory = originalDirectory; + } + } + catch (Exception ex) + { + session.Log("Failed to restore current directory after running custom action: {0}", ex.Message); + } + } } ///