From 841f87564a3e8503ef325b1a118f8b5a0ca1f5ac Mon Sep 17 00:00:00 2001 From: Ken Hoo <158048821+mrkenhoo@users.noreply.github.com> Date: Sun, 11 Feb 2024 17:01:04 +0100 Subject: [PATCH] Improve handling of Adobe's CC Cleaner tool Implement a try-catch-finally struct to do a better handling of Adobe's Creative Cloud Cleaner tool downloading and running of such program. This will allow to see any errors that occurs if the URL changes or the tool fails to run. I also have moved the cleaning up process to the finally part of the structure, as it makes the most sense. This tries to fix the issue #1563. --- .../Invoke-WPFRunAdobeCCCleanerTool.ps1 | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/functions/public/Invoke-WPFRunAdobeCCCleanerTool.ps1 b/functions/public/Invoke-WPFRunAdobeCCCleanerTool.ps1 index 263abc06..84768974 100644 --- a/functions/public/Invoke-WPFRunAdobeCCCleanerTool.ps1 +++ b/functions/public/Invoke-WPFRunAdobeCCCleanerTool.ps1 @@ -11,18 +11,22 @@ function Invoke-WPFRunAdobeCCCleanerTool { Write-Host "The Adobe Creative Cloud Cleaner tool is hosted at" Write-Host "$url" - # Don't show the progress because it will slow down the download speed - $ProgressPreference='SilentlyContinue' + try { + # Don't show the progress because it will slow down the download speed + $ProgressPreference='SilentlyContinue' - Invoke-WebRequest -Uri $url -OutFile "$env:TEMP\AdobeCreativeCloudCleanerTool.exe" -UseBasicParsing -ErrorAction SilentlyContinue -Verbose + Invoke-WebRequest -Uri $url -OutFile "$env:TEMP\AdobeCreativeCloudCleanerTool.exe" -UseBasicParsing -ErrorAction SilentlyContinue -Verbose - # Revert back the ProgressPreference variable to the default value since we got the file desired - $ProgressPreference='Continue' + # Revert back the ProgressPreference variable to the default value since we got the file desired + $ProgressPreference='Continue' - Start-Process -FilePath "$env:TEMP\AdobeCreativeCloudCleanerTool.exe" -Wait -ErrorAction SilentlyContinue -Verbose - - if (Test-Path -Path "$env:TEMP\AdobeCreativeCloudCleanerTool.exe") { - Write-Host "Cleaning up..." - Remove-Item -Path "$env:TEMP\AdobeCreativeCloudCleanerTool.exe" -Verbose + Start-Process -FilePath "$env:TEMP\AdobeCreativeCloudCleanerTool.exe" -Wait -ErrorAction SilentlyContinue -Verbose + } catch { + Write-Error $_.Exception.Message + } finally { + if (Test-Path -Path "$env:TEMP\AdobeCreativeCloudCleanerTool.exe") { + Write-Host "Cleaning up..." + Remove-Item -Path "$env:TEMP\AdobeCreativeCloudCleanerTool.exe" -Verbose + } } }