From af1a9550b78305a0572d054db0a19330c031f411 Mon Sep 17 00:00:00 2001 From: Nicholas Gautier Date: Fri, 13 Dec 2024 00:11:04 -0700 Subject: [PATCH] Revised ExtractArchive() and CreateArchive() When an error occurs, present a message box to the user when something happens. #94 --- Scripts/DefaultCompress.ps1 | 96 ++++++++++++++++++++++++++++++++++--- 1 file changed, 90 insertions(+), 6 deletions(-) diff --git a/Scripts/DefaultCompress.ps1 b/Scripts/DefaultCompress.ps1 index 06a39a80..75a3741c 100644 --- a/Scripts/DefaultCompress.ps1 +++ b/Scripts/DefaultCompress.ps1 @@ -1493,7 +1493,7 @@ class DefaultCompress # Generate a message to display to the user. [string] $displayErrorMessage = ("Unable to extract data from the compressed file:`r`n" + ` - "`t`t" + $fileName + "`r`n" + ` + "`t" + $fileName + "`r`n" + ` "The Log directories could not be created!`r`n" + ` "Please make sure that you have sufficient privileges to create directories in:`r`n" + ` "`t" + $global:_PROGRAMDATA_LOCAL_PROGRAM_LOGS_PATH_); @@ -1547,7 +1547,7 @@ class DefaultCompress # Generate a message to display to the user. [string] $displayErrorMessage = ("Unable to extract data from the compressed file:`r`n" + ` - "`t`t" + $fileName + "`r`n" + ` + "`t" + $fileName + "`r`n" + ` "The PowerShell Module, " + $this.GetPowerShellModuleName() + ` ", was not detected!`r`n" + ` "Because the PowerShell Module was not found, it is not possible " + ` @@ -1601,17 +1601,21 @@ class DefaultCompress # Generate a message to display to the user. [string] $displayErrorMessage = ("Unable to extract data from the compressed file:`r`n" + ` - "`t`t" + $fileName + "`r`n" + ` + "`t" + $fileName + "`r`n" + ` "The path to the compressed file is not correct.`r`n" + ` "The path given to the compressed file:`r`n" + ` - "`t" + $file); + "`t" + $file + "`r`n" + ` + "The output path given was:`r`n" + ` + "`t" + $outputPath); # Generate the initial message - [string] $logMessage = "Unable to extract data from the compressed file because the path was not correct!"; + [string] $logMessage = "Unable to extract data from the compressed file because the output path was not correct!"; # Generate any additional information that might be useful [string] $logAdditionalMSG = "The Archive Data File Path Given: `r`n" + ` - "`t`t" + $file; + "`t`t" + $file + "`r`n" + ` + "`tOutput Path Given was:`r`n" + ` + "`t`t" + $outputPath; # Pass the information to the logging system [Logging]::LogProgramActivity($logMessage, ` # Initial message @@ -1645,6 +1649,13 @@ class DefaultCompress # Debugging # -------------- + # Generate a message to display to the user. + [string] $displayErrorMessage = ("Unable to extract data from the compressed file:`r`n" + ` + "`t" + $fileName + "`r`n" + ` + "The output path was not correct.`r`n" + ` + "The output path given was:`r`n" + ` + "`t" + $outputPath); + # Generate the initial message [string] $logMessage = "Unable to extract the archive data file because the output directory could not be found!"; @@ -1657,6 +1668,15 @@ class DefaultCompress $logAdditionalMSG, ` # Additional information [LogMessageLevel]::Error); # Message level + # Display a message to the user that something went horribly wrong + # and log that same message for referencing purpose. + [Logging]::DisplayMessage($displayErrorMessage, ` # Message to display + [LogMessageLevel]::Error); # Message level + + # Alert the user through a message box as well that an issue had occurred; + # the message will be brief as the full details remain within the terminal. + [CommonGUI]::MessageBox($logMessage, [System.Windows.MessageBoxImage]::Hand) | Out-Null; + # * * * * * * * * * * * * * * * * * * * @@ -1706,6 +1726,13 @@ class DefaultCompress # Debugging # -------------- + # Generate a message to display to the user. + [string] $displayErrorMessage = ("Unable to extract data from the compressed file:`r`n" + ` + "`t" + $fileName + "`r`n" + ` + "It was not possible to create the output directory as needed.`r`n" + ` + "Output Directory Path:`r`n" + ` + "`t" + $extractPath); + # Generate the initial message [string] $logMessage = "Unable to extract the archive data file because the extracting directory could not be created!"; @@ -1719,6 +1746,15 @@ class DefaultCompress $logAdditionalMSG, ` # Additional information [LogMessageLevel]::Error); # Message level + # Display a message to the user that something went horribly wrong + # and log that same message for referencing purpose. + [Logging]::DisplayMessage($displayErrorMessage, ` # Message to display + [LogMessageLevel]::Error); # Message level + + # Alert the user through a message box as well that an issue had occurred; + # the message will be brief as the full details remain within the terminal. + [CommonGUI]::MessageBox($logMessage, [System.Windows.MessageBoxImage]::Hand) | Out-Null; + # * * * * * * * * * * * * * * * * * * * @@ -2093,6 +2129,13 @@ class DefaultCompress # Debugging # -------------- + # Generate a message to display to the user. + [string] $displayErrorMessage = ("Unable to verify the compressed file:`r`n" + ` + "`t`t" + $targetFileName + "`r`n" + ` + "The path to the compressed file is not correct.`r`n" + ` + "The path given to the compressed file:`r`n" + ` + "`t" + $targetFile); + # Generate the initial message [string] $logMessage = "Unable to create a new archive file due to logging complications!"; @@ -2111,6 +2154,15 @@ class DefaultCompress $logAdditionalMSG, ` # Additional information [LogMessageLevel]::Error); # Message level + # Display a message to the user that something went horribly wrong + # and log that same message for referencing purpose. + [Logging]::DisplayMessage($displayErrorMessage, ` # Message to display + [LogMessageLevel]::Error); # Message level + + # Alert the user through a message box as well that an issue had occurred; + # the message will be brief as the full details remain within the terminal. + [CommonGUI]::MessageBox($logMessage, [System.Windows.MessageBoxImage]::Hand) | Out-Null; + # * * * * * * * * * * * * * * * * * * * @@ -2143,6 +2195,15 @@ class DefaultCompress $logAdditionalMSG, ` # Additional information [LogMessageLevel]::Error); # Message level + # Display a message to the user that something went horribly wrong + # and log that same message for referencing purpose. + [Logging]::DisplayMessage($displayErrorMessage, ` # Message to display + [LogMessageLevel]::Error); # Message level + + # Alert the user through a message box as well that an issue had occurred; + # the message will be brief as the full details remain within the terminal. + [CommonGUI]::MessageBox($logMessage, [System.Windows.MessageBoxImage]::Hand) | Out-Null; + # * * * * * * * * * * * * * * * * * * * @@ -2174,6 +2235,15 @@ class DefaultCompress $logAdditionalMSG, ` # Additional information [LogMessageLevel]::Error); # Message level + # Display a message to the user that something went horribly wrong + # and log that same message for referencing purpose. + [Logging]::DisplayMessage($displayErrorMessage, ` # Message to display + [LogMessageLevel]::Error); # Message level + + # Alert the user through a message box as well that an issue had occurred; + # the message will be brief as the full details remain within the terminal. + [CommonGUI]::MessageBox($logMessage, [System.Windows.MessageBoxImage]::Hand) | Out-Null; + # * * * * * * * * * * * * * * * * * * * @@ -2193,6 +2263,11 @@ class DefaultCompress # Debugging # -------------- + # Generate a message to display to the user. + [string] $displayErrorMessage = ("Unable to create a new compress file, " + $archiveFileNameRequest + ", " + ` + "because the source files could not be found with the given path:`r`n" + ` + "`t" + $targetDirectory + "`r`n"); + # Generate the initial message [string] $logMessage = "Unable to create the archive data file because the target directory could not be found!"; @@ -2206,6 +2281,15 @@ class DefaultCompress $logAdditionalMSG, ` # Additional information [LogMessageLevel]::Error); # Message level + # Display a message to the user that something went horribly wrong + # and log that same message for referencing purpose. + [Logging]::DisplayMessage($displayErrorMessage, ` # Message to display + [LogMessageLevel]::Error); # Message level + + # Alert the user through a message box as well that an issue had occurred; + # the message will be brief as the full details remain within the terminal. + [CommonGUI]::MessageBox($logMessage, [System.Windows.MessageBoxImage]::Hand) | Out-Null; + # * * * * * * * * * * * * * * * * * * *