From b5de0c02c811549d5e15bfc209a1fa9c1f1744d2 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sat, 13 Jul 2024 00:28:18 -0700 Subject: 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 f58ff07d..fca15dbc 100644 --- a/src/dtf/WixToolset.Dtf.WindowsInstaller/CustomActionProxy.cs +++ b/src/dtf/WixToolset.Dtf.WindowsInstaller/CustomActionProxy.cs @@ -101,8 +101,13 @@ namespace WixToolset.Dtf.WindowsInstaller 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 @@ namespace WixToolset.Dtf.WindowsInstaller 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); + } + } } /// -- cgit v1.2.3-55-g6feb