From f3316a017b73bf12cf1a66e3d03a63e29c437cb1 Mon Sep 17 00:00:00 2001 From: rbalsleyMSFT <53497092+rbalsleyMSFT@users.noreply.github.com> Date: Wed, 10 Sep 2025 11:31:53 -0700 Subject: [PATCH] feat: Add restore defaults and centralize cleanup logic Introduces a "Restore Defaults" feature in the UI to reset the environment. This action removes generated configuration files, ISOs, downloaded apps, updates, drivers, and FFUs. The post-build cleanup logic is refactored from the main build script into a new common function. This new function is used by both the standard build process and the new restore defaults feature, promoting code reuse and simplifying maintenance. --- FFUDevelopment/BuildFFUVM.ps1 | 57 +-------- FFUDevelopment/BuildFFUVM_UI.xaml | 1 + .../FFU.Common/FFU.Common.Cleanup.psm1 | 109 ++++++++++++++++ FFUDevelopment/FFU.Common/FFU.Common.psd1 | 3 +- .../FFUUI.Core/FFUUI.Core.Config.psm1 | 120 ++++++++++++++++++ .../FFUUI.Core/FFUUI.Core.Handlers.psm1 | 10 +- .../FFUUI.Core/FFUUI.Core.Initialize.psm1 | 5 +- 7 files changed, 247 insertions(+), 58 deletions(-) create mode 100644 FFUDevelopment/FFU.Common/FFU.Common.Cleanup.psm1 diff --git a/FFUDevelopment/BuildFFUVM.ps1 b/FFUDevelopment/BuildFFUVM.ps1 index 7bee540..362fdce 100644 --- a/FFUDevelopment/BuildFFUVM.ps1 +++ b/FFUDevelopment/BuildFFUVM.ps1 @@ -5893,59 +5893,10 @@ If ($RemoveFFU) { } Set-Progress -Percentage 99 -Message "Finalizing and cleaning up..." -If ($CleanupCaptureISO) { - try { - If (Test-Path -Path $CaptureISO) { - WriteLog "Removing $CaptureISO" - Remove-Item -Path $CaptureISO -Force - WriteLog "Removal complete" - } - } - catch { - Writelog "Removing $CaptureISO failed with error $_" - throw $_ - } -} -If ($CleanupDeployISO) { - try { - If (Test-Path -Path $DeployISO) { - WriteLog "Removing $DeployISO" - Remove-Item -Path $DeployISO -Force - WriteLog "Removal complete" - } - } - catch { - Writelog "Removing $DeployISO failed with error $_" - throw $_ - } -} -If ($CleanupAppsISO) { - try { - If (Test-Path -Path $AppsISO) { - WriteLog "Removing $AppsISO" - Remove-Item -Path $AppsISO -Force - WriteLog "Removal complete" - } - } - catch { - Writelog "Removing $AppsISO failed with error $_" - throw $_ - } -} -If ($CleanupDrivers) { - try { - #Remove files in $Driversfolder, but keep $DriversFolder - If (Test-Path -Path $Driversfolder) { - WriteLog "Removing files in $Driversfolder" - Remove-Item -Path $Driversfolder\* -Force -Recurse - WriteLog "Removal complete" - } - } - catch { - Writelog "Removing $Driversfolder\* failed with error $_" - throw $_ - } -} +# Delegated post-build cleanup to common module +Invoke-FFUPostBuildCleanup -RootPath $FFUDevelopmentPath -AppsPath $AppsPath -DriversPath $Driversfolder -FFUCapturePath $FFUCaptureLocation -CaptureISOPath $CaptureISO -DeployISOPath $DeployISO -AppsISOPath $AppsISO -RemoveCaptureISO:$CleanupCaptureISO -RemoveDeployISO:$CleanupDeployISO -RemoveAppsISO:$CleanupAppsISO -RemoveDrivers:$CleanupDrivers -RemoveFFU:$RemoveFFU -RemoveApps:$RemoveApps -RemoveUpdates:$RemoveUpdates + +# Remove KBPath for cached vhdx files if ($AllowVHDXCaching) { try { If (Test-Path -Path $KBPath) { diff --git a/FFUDevelopment/BuildFFUVM_UI.xaml b/FFUDevelopment/BuildFFUVM_UI.xaml index 96ab64b..4c13da2 100644 --- a/FFUDevelopment/BuildFFUVM_UI.xaml +++ b/FFUDevelopment/BuildFFUVM_UI.xaml @@ -816,6 +816,7 @@ +