From 43ebc4623fc1e36f5f2957ae2ba0acbfc4028270 Mon Sep 17 00:00:00 2001 From: Nicholas Gautier Date: Sat, 22 Oct 2022 14:55:38 -0500 Subject: [PATCH 1/4] Updated Titlebar shown in Clean Mode When the program is running in 'Clean Mode', the Titlebar will no longer display the project information as the project has no relevance within this mode. --- Scripts/Clean.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scripts/Clean.ps1 b/Scripts/Clean.ps1 index 5146fefa..d3679cf4 100644 --- a/Scripts/Clean.ps1 +++ b/Scripts/Clean.ps1 @@ -93,7 +93,7 @@ function clean() # Provide a new Window Title - [CommonIO]::SetTerminalWindowTitle("$($Global:_PROGRAMNAME_) (Version $($Global:_VERSION_)) for $([ProjectInformation]::projectName) - $([ProjectInformation]::codeName)"); + [CommonIO]::SetTerminalWindowTitle("$($Global:_PROGRAMNAME_) (Version $($Global:_VERSION_)) - Clean Mode"); # Load the user's configurations, if available. From 4054ad2d40fb46bdd94ed6d3968ca000f40655ba Mon Sep 17 00:00:00 2001 From: Nicholas Gautier Date: Sun, 23 Oct 2022 01:00:28 -0500 Subject: [PATCH 2/4] Changed all references of Uninstall to Deep Clean Because of the Uninstaller that will be part of the installation package, it is no longer necessary to allow PSCAT to have some sort of Uninstall functionality built-in. With that side, the program will also no longer prompt the user in regards to removal of the application. --- Scripts/Clean.ps1 | 44 ++++++----------------------- Scripts/Launcher/Launcher.ps1 | 4 +-- Scripts/Program Modes/Uninstall.ps1 | 26 ++++++++--------- Scripts/StartUpArguments.ps1 | 2 +- Scripts/help.ps1 | 2 +- Scripts/main.ps1 | 6 ++-- 6 files changed, 29 insertions(+), 55 deletions(-) diff --git a/Scripts/Clean.ps1 b/Scripts/Clean.ps1 index d3679cf4..5a5fadbe 100644 --- a/Scripts/Clean.ps1 +++ b/Scripts/Clean.ps1 @@ -31,7 +31,7 @@ # - Compiled Builds # - Log files # - Report files - # - Uninstall + # - Deep Cleanup # - Compiled Builds # - Log files # - Report files @@ -119,14 +119,14 @@ function clean() } # Clean Up Mode - # Uninstall Mode - {($_ -eq [CleanUpModeType]::Uninstall)} + # Deep Clean Up Mode + {($_ -eq [CleanUpModeType]::DeepCleanUp)} { - # Let the user know that the application is uninstalling itself. - [CommonIO]::WriteToBuffer("Uninstalling`r`n`r`n", + ` + # Let the user know that the application is performing a deep cleanup. + [CommonIO]::WriteToBuffer("Deep Clean Up`r`n`r`n", + ` [LogMessageLevel]::Warning, + ` $false); - } # Uninstall Mode + } # Deep Clean Up Mode } # switch : Program Mode @@ -195,7 +195,7 @@ function clean() # Delete the user configuration file - if ($programMode -eq [CleanUpModeType]::Uninstall) + if ($programMode -eq [CleanUpModeType]::DeepCleanUp) { [CommonIO]::WriteToBuffer("`tUser Configuration`r`n`t`t$GLOBAL:_PROGRAMDATA_ROOT_ROAMING_PATH_", + ` [LogMessageLevel]::Warning, + ` @@ -215,7 +215,7 @@ function clean() [LogMessageLevel]::Error, + ` $false); } # if : Failed to Delete Directory - Logs\Reports - } # if : Uninstall + } # if : Deep Clean Up @@ -246,32 +246,6 @@ function clean() - # Program Files - # ----------- - # ----------- - - - # Let the user know that they will need to expunge the program files manually, but if and only if the Uninstall flag is raised. - if ($programMode -eq [CleanUpModeType]::Uninstall) - { - [CommonIO]::WriteToBuffer("`tProgram Files", + ` - [LogMessageLevel]::Warning, + ` - $false); - - - # Because it is going to take large amounts of time to make this functionality work, it is best to have the user to delete the directory themselves. - # NOTE: This approach is mainly for Power Users; others will benefit from the Installer packages. - [CommonIO]::WriteToBuffer("`t`tIn order to delete the $($GLOBAL:_PROGRAMNAME_) Program Files, you will have to delete following directory:", + ` - [LogMessageLevel]::Attention, + ` - $false); - - - [CommonIO]::WriteToBuffer("`t`t$GLOBAL:_SCRIPTPATH_", + ` - [LogMessageLevel]::Warning, + ` - $false); - } # if : Uninstall - - # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ @@ -329,5 +303,5 @@ enum CleanUpModeType { Nothing = 0; # No cleaning is required CleanUp = 1; # Standard Cleanup Operation - Uninstall = 2; # Uninstall the Application + DeepCleanUp = 2; # Deep Cleanup Operation } # CleanUpModeType \ No newline at end of file diff --git a/Scripts/Launcher/Launcher.ps1 b/Scripts/Launcher/Launcher.ps1 index d63afaa3..abbc42bc 100644 --- a/Scripts/Launcher/Launcher.ps1 +++ b/Scripts/Launcher/Launcher.ps1 @@ -52,7 +52,7 @@ Program Mode [integer value] 0 = Normal mode; compile projects (Default) 1 = Clean up mode; remove some generated data - 2 = Uninstall mode; removes all generated data + 2 = Deep clean up mode; removes all generated data .OUTPUTS Operation Return Code @@ -111,7 +111,7 @@ param( # Software runs normally, no changes. # 1 = Clean Up Mode # Deletes all builds, logs, and report files. - # 2 = Uninstall Mode + # 2 = Deep Clean Up Mode # Deletes all builds, logs, report files, and user configuration. [Parameter(Mandatory=$false)] [ValidateRange(0, 2)] diff --git a/Scripts/Program Modes/Uninstall.ps1 b/Scripts/Program Modes/Uninstall.ps1 index 4ce747b2..10869886 100644 --- a/Scripts/Program Modes/Uninstall.ps1 +++ b/Scripts/Program Modes/Uninstall.ps1 @@ -24,7 +24,7 @@ Deletes data that was generated by the PowerShell Compact-Archive Tool, includes user configuration files. .DESCRIPTION - This tool will provide a special instruction to the PowerShell Compact-Archive Tool to perform an uninstall operation. + This tool will provide a special instruction to the PowerShell Compact-Archive Tool to perform a deep clean-up operation. In doing so, the PowerShell Compact-Archive Tool will expunge files that had previously generated as well as remove the current user configuration files. @@ -51,7 +51,7 @@ 502 = Unable to load the required dependencies. .EXAMPLE - .\Uninstall.ps1 + .\DeepClean.ps1 .LINK https://github.com/SibTiger/PowerShell-Compact-Archive-Tool @@ -92,7 +92,7 @@ function Initialization() Set-Variable -Name "__PSCAT_OPERATION_CODE__" -Value 2 ` -Option ReadOnly -Scope Global -ErrorAction SilentlyContinue ` -Visibility Public ` - -Description "Signifies the 'Uninstall' Operation mode in PowerShell Compact-Archive Tool."; + -Description "Signifies the 'Deep Clean' Operation mode in PowerShell Compact-Archive Tool."; # Exit Codes : Cannot Find PSCAT Set-Variable -Name "__EXITCODE_CANNOT_FIND_PSCAT__" -Value 500 ` @@ -166,12 +166,12 @@ function Uninitialization() # POP, however due to the nature of the 'Pipe' in POSH - it was more trouble than what it was # worth. Thus, switching to OOP was necessary to assure that I can move information as I want # without it getting ridiculous.... -Class Uninstall +Class DeepClean { # Launch the PowerShell Compact-Archive Tool # ------------------------------- # Documentation: - # This function will execute the PowerShell Compact-Archive Tool and set the Program Mode to 'Uninstall'. + # This function will execute the PowerShell Compact-Archive Tool and set the Program Mode to 'Deep Clean'. # ------------------------------- # Output: # [Int] Exit Code @@ -227,11 +227,11 @@ Class Uninstall # Display the error message to the user - [Uninstall]::DisplayErrorMessage($errorMessage); + [DeepClean]::DisplayErrorMessage($errorMessage); # Allow the user to read the message. - [Uninstall]::FetchEnterKey(); + [DeepClean]::FetchEnterKey(); # Return the error code that we were unable to start PSCAT Launcher. @@ -370,7 +370,7 @@ Class Uninstall # Try to detect if the PowerShell Compact-Archive Tool Launcher had been found. - if (![Uninstall]::TestFilePath($Global:__PSCAT_COMPLETE_PATH__)) + if (![DeepClean]::TestFilePath($Global:__PSCAT_COMPLETE_PATH__)) { # Because we cannot find the PSCAT Launcher, we cannot continue. # Generate the error message @@ -384,11 +384,11 @@ Class Uninstall # We already have the error message provided to us already, all that we have to do is show the message. - [Uninstall]::DisplayErrorMessage($errorMessage); + [DeepClean]::DisplayErrorMessage($errorMessage); # Allow the user to read the message. - [Uninstall]::FetchEnterKey(); + [DeepClean]::FetchEnterKey(); } # if : Unable to find PSCAT Launcher @@ -396,7 +396,7 @@ Class Uninstall else { # Execute PSCAT Launcher - $exitCode = [Uninstall]::LaunchPSCAT(); + $exitCode = [DeepClean]::LaunchPSCAT(); } # Else : Launch the Application @@ -404,7 +404,7 @@ Class Uninstall # Provide the operation exit code return $exitCode; } # main() -} # Uninstall +} # DeepClean @@ -426,7 +426,7 @@ Initialization; # Start the program and then return the exit code upon terminating. -$returnState = [Uninstall]::main(); +$returnState = [DeepClean]::main(); # Thrash the program's global variables. diff --git a/Scripts/StartUpArguments.ps1 b/Scripts/StartUpArguments.ps1 index b3ca5a00..fe1251ca 100644 --- a/Scripts/StartUpArguments.ps1 +++ b/Scripts/StartUpArguments.ps1 @@ -41,7 +41,7 @@ param( # Software runs normally, no changes. # 1 = Clean Up Mode # Deletes all builds, logs, and report files. - # 2 = Uninstall Mode + # 2 = Deep Clean Up Mode # Deletes all builds, logs, report files, and user configuration. [Parameter(Mandatory=$false)] [ValidateRange(0, 2)] diff --git a/Scripts/help.ps1 b/Scripts/help.ps1 index 54ef4c61..18a1a987 100644 --- a/Scripts/help.ps1 +++ b/Scripts/help.ps1 @@ -56,7 +56,7 @@ Program Mode [integer value] 0 = Normal mode; compile projects (Default) 1 = Clean up mode; remove some generated data - 2 = Uninstall mode; removes all generated data + 2 = Deep clean up mode; removes all generated data .OUTPUTS Operation Return Code diff --git a/Scripts/main.ps1 b/Scripts/main.ps1 index bfc1a117..3a5b2f6e 100644 --- a/Scripts/main.ps1 +++ b/Scripts/main.ps1 @@ -152,13 +152,13 @@ CreateDirectories | Out-Null; -# Should the program launch in Clean-Up\Uninstall mode? +# Should the program launch in (Deep) Clean-Up mode? if (($programMode -gt 0) -and ` ($programMode -le 2)) { - # Launch the cleanup\uninstall mode. + # Launch the (deep) cleanup mode. $returnState = clean -programMode $programMode; -} # Clean Mode +} # Clean-Up Mode # Run the application normally else From 5e6b2f36ac97bf46ad88dc5ef76427f54f6ed9de Mon Sep 17 00:00:00 2001 From: Nicholas Gautier Date: Sun, 23 Oct 2022 01:30:55 -0500 Subject: [PATCH 3/4] Removed Program Modes directory Removed the Program Modes directory, including: Clean.ps1 and Uninstall.ps1. The reason for this change is simply due to the Batch scripts - through the Windows Installer. As such, the user can simply use the Batch scripts to easily launch the PSCAT program, regardless if POSH scripts are allowed to be executed within the user's environment -- bypassing the Set-ExecutionPolicy. --- .../Scripts/Installation Files/Files.iss | 8 - Scripts/Program Modes/Clean.ps1 | 439 ----------------- Scripts/Program Modes/Uninstall.ps1 | 440 ------------------ 3 files changed, 887 deletions(-) delete mode 100644 Scripts/Program Modes/Clean.ps1 delete mode 100644 Scripts/Program Modes/Uninstall.ps1 diff --git a/Installer/Scripts/Installation Files/Files.iss b/Installer/Scripts/Installation Files/Files.iss index fb1f1fa7..1ee0e30c 100644 --- a/Installer/Scripts/Installation Files/Files.iss +++ b/Installer/Scripts/Installation Files/Files.iss @@ -34,14 +34,6 @@ Source: "Scripts\Launcher\Launcher.ps1"; \ DestDir: "{app}\Bin\"; \ Flags: confirmoverwrite touch; -Source: "Scripts\Program Modes\Clean.ps1"; \ - DestDir: "{app}\Bin\"; \ - Flags: confirmoverwrite touch; - -Source: "Scripts\Program Modes\Uninstall.ps1"; \ - DestDir: "{app}\Bin\"; \ - Flags: confirmoverwrite touch; - Source: "Installer\Product Assets\Bootstrap\Bootstrap Loader.bat"; \ DestDir: "{app}\Bootstrap\"; \ Flags: confirmoverwrite touch; diff --git a/Scripts/Program Modes/Clean.ps1 b/Scripts/Program Modes/Clean.ps1 deleted file mode 100644 index 92cf12b4..00000000 --- a/Scripts/Program Modes/Clean.ps1 +++ /dev/null @@ -1,439 +0,0 @@ -<# PowerShell Compact-Archive Tool - # Copyright (C) 2022 - # - # This program is free software: you can redistribute it and/or modify - # it under the terms of the GNU General Public License as published by - # the Free Software Foundation, either version 3 of the License, or - # (at your option) any later version. - # - # This program is distributed in the hope that it will be useful, - # but WITHOUT ANY WARRANTY; without even the implied warranty of - # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - # GNU General Public License for more details. - # - # You should have received a copy of the GNU General Public License - # along with this program. If not, see . - #> - - - - - -<# -.SYNOPSIS - Deletes data that was generated by PowerShell Compact-Archive Tool. - -.DESCRIPTION - This tool will provide a special instruction to the PowerShell Compact-Archive Tool to perform a clean-up operation. - In doing so, the PowerShell Compact-Archive Tool will expunge files that had previously generated. - - Tools that this program utilizes are: - PowerShell Core 7.1.x Minimum - This is required in order for the PSCAT software to work properly. - PowerShell Compact-Archive Tool (version 1.1.0 minimum) - This specifies which version of PSCAT supports this functionality. - -.NOTES - Author: Nicholas Gautier - Email: Nicholas.Gautier.Tiger@GMail.com - Project Website: https://github.com/SibTiger/PowerShell-Compact-Archive-Tool - -.INPUTS - Nothing is to be given or to be provided from a command or pipe. - -.OUTPUTS - Operation Return Code - 0 = Operation was Successful - 1 = General Failure - 500 = Unable to find the PowerShell Compact-Archive Tool. - 501 = Unable to launch the PowerShell Compact-Archive Tool. - 502 = Unable to load the required dependencies. - -.EXAMPLE - .\cleanup.ps1 - -.LINK - https://github.com/SibTiger/PowerShell-Compact-Archive-Tool -#> - - - - - -# Initialization -# ------------------------------- -# Documentation: -# This function will initialize all of the required variables that we will need within this application. -# This is mainly to help when needing to maintain this application over future generations of PSCAT. -# ------------------------------- -function Initialization() -{ - # PSCAT Filename - Set-Variable -Name "__PSCAT_FILENAME__" -Value "Launcher.ps1" ` - -Option ReadOnly -Scope Global -ErrorAction SilentlyContinue ` - -Visibility Public ` - -Description "PowerShell Compact-Archive Tool's Launcher filename"; - - # PSCAT Absolute Path - # NOTE: This script should reside with the PSCAT application. - Set-Variable -Name "__PSCAT_FULL_PATH__" -Value $PSScriptRoot ` - -Option ReadOnly -Scope Global -ErrorAction SilentlyContinue ` - -Visibility Private ` - -Description "Base path in which the PSCAT application will reside"; - - # PSCAT Complete Path - Set-Variable -Name "__PSCAT_COMPLETE_PATH__" -Value "$($GLOBAL:__PSCAT_FULL_PATH__)\$($GLOBAL:__PSCAT_FILENAME__)" ` - -Option ReadOnly -Scope Global -ErrorAction SilentlyContinue ` - -Visibility Public ` - -Description "PowerShell Compact-Archive Tool's absolute path - including filename."; - - # PSCAT Operation Code - Set-Variable -Name "__PSCAT_OPERATION_CODE__" -Value 1 ` - -Option ReadOnly -Scope Global -ErrorAction SilentlyContinue ` - -Visibility Public ` - -Description "Signifies the 'Clean' Operation mode in PowerShell Compact-Archive Tool."; - - # Exit Codes : Cannot Find PSCAT - Set-Variable -Name "__EXITCODE_CANNOT_FIND_PSCAT__" -Value 500 ` - -Option ReadOnly -Scope Global -ErrorAction SilentlyContinue ` - -Visibility Public ` - -Description "Exit Code signifying that the PowerShell Compact-Archive Tool could not be found."; - - # Exit Codes : Failed Launch PSCAT - Set-Variable -Name "__EXITCODE_FAILED_TO_LAUNCH_PSCAT__" -Value 501 ` - -Option ReadOnly -Scope Global -ErrorAction SilentlyContinue ` - -Visibility Public ` - -Description "Exit Code Signifying that the PowerShell Compact-Archive Tool could not be started."; -} # Initialization() - - - - - -# Uninitialization -# ------------------------------- -# Documentation: -# This function will remove all of the global variables that had been declared and initialize by this shellscript. -# This will help to cleanup unnecessary variables from the user's terminal environment. -# ------------------------------- -function Uninitialization() -{ - # PSCAT Filename - Remove-Variable -Name "__PSCAT_FILENAME__" ` - -Scope Global ` - -Force ` - -ErrorAction SilentlyContinue; - - # PSCAT Absolute Path - Remove-Variable -Name "__PSCAT_FULL_PATH__" ` - -Scope Global ` - -Force ` - -ErrorAction SilentlyContinue; - - # PSCAT Complete Path - Remove-Variable -Name "__PSCAT_COMPLETE_PATH__" ` - -Scope Global ` - -Force ` - -ErrorAction SilentlyContinue; - - # PSCAT Operation Code - Remove-Variable -Name "__PSCAT_OPERATION_CODE__" ` - -Scope Global ` - -Force ` - -ErrorAction SilentlyContinue; - - # Exit Codes : Cannot Find PSCAT - Remove-Variable -Name "__EXITCODE_CANNOT_FIND_PSCAT__" ` - -Scope Global ` - -Force ` - -ErrorAction SilentlyContinue; - - # Exit Codes : Failed Launch PSCAT - Remove-Variable -Name "__EXITCODE_FAILED_TO_LAUNCH_PSCAT__" ` - -Scope Global ` - -Force ` - -ErrorAction SilentlyContinue; -} # Uninitialization() - - - - - -# This class provides the main operations in order to get the job done. -# Fun-Fact, I am explicitly using OOP as I can control the return information. Previously I did use -# POP, however due to the nature of the 'Pipe' in POSH - it was more trouble than what it was -# worth. Thus, switching to OOP was necessary to assure that I can move information as I want -# without it getting ridiculous.... -Class Clean -{ - # Launch the PowerShell Compact-Archive Tool - # ------------------------------- - # Documentation: - # This function will execute the PowerShell Compact-Archive Tool and set the Program Mode to 'Clean'. - # ------------------------------- - # Output: - # [Int] Exit Code - # This is the exit code provided by the PowerShell Compact-Archive Tool program. - # ------------------------------- - hidden static [Int32] LaunchPSCAT() - { - # Declarations and Initializations - # -------------------------------------- - # We are going to use 'Splatting' to make this easier to construct the Invoke-Expression arguments. - [System.Collections.Hashtable] $hashArguments = [System.Collections.Hashtable]::New(); - - # Error Message - # Chief Reason for Error - [string] $errorTitle = "((REASON IS NOT KNOWN))"; - # -------------------------------------- - - - - # Construct the arguments - $hashArguments = @{ - Command = "& "".\$($Global:__PSCAT_FILENAME__)"" -ProgramMode $Global:__PSCAT_OPERATION_CODE__"; - ErrorAction = "Stop"; - } # Invoke-Expression Arguments - - - - # Try to launch PowerShell Compact-Archive Tool Launcher application - try - { - # Launch the PowerShell Compact-Archive Tool Launcher program - Invoke-Expression @hashArguments; - - # Operation was successful - return $LASTEXITCODE; - } # Try: Launch PSCAT Launcher - - - # Caught an error during Launch - catch - { - # Provide the error message - $errorTitle = "Failed to launch PowerShell Compact-Archive Tool Launcher!" - } # Catch: Caught an error - - - - # Generate the full error message - [string] $errorMessage = ("$($errorTitle)`r`n" + ` - "Tried to use this command: $($hashArguments.Command)`r`n" + ` - "Other properties that were used:`r`n" + ` - "`tError Action: $($hashArguments.ErrorAction)"); - - - # Display the error message to the user - [Clean]::DisplayErrorMessage($errorMessage); - - - # Allow the user to read the message. - [Clean]::FetchEnterKey(); - - - # Return the error code that we were unable to start PSCAT Launcher. - return $Global:__EXITCODE_FAILED_TO_LAUNCH_PSCAT__; - } # LaunchPSCAT() - - - - - - - # Test File Path - # ------------------------------- - # Documentation: - # This function will inspect the complete path in which the file supposedly resides. - # ------------------------------- - # Output: - # [Bool] Exist Result - # $True - File exists within the given path. - # $False - File could not be found with the provided path. - # ------------------------------- - hidden static [bool] TestFilePath([string] $pathToExamine) - { - # Check to see if we can find the file - if (Test-Path -LiteralPath "$($pathToExamine)" -PathType Leaf) - { - # Found the target file - return $true; - } # if : Found Target - - - # Unable to find the target file - return $false; - } # TestFilePath() - - - - - - - # Display Error Message - # ------------------------------- - # Documentation: - # This function will provide centralized way into creating an error message that will be - # displayed to the user's terminal buffer. - # We will only provide a static error message, such that the format does not change. - # ------------------------------- - hidden static [void] DisplayErrorMessage([string] $errorMessage) - { - # Declarations and Initializations - # -------------------------------------------- - # Create the message package that we will need to show the user that we were unable to find the PSCAT tool. - [System.Management.Automation.HostInformationMessage] $messagePackage = ` - [System.Management.Automation.HostInformationMessage]::New(); - # -------------------------------------------- - - - - # Generate the message package such that it grabs the user's attention immediately. - $messagePackage.BackgroundColor = "Black"; - $messagePackage.ForegroundColor = "Red"; - $messagePackage.Message = ("`r`n`r`n" + ` - "`t`t CRITICAL ERROR `r`n" + ` - "------------------------------------------------------`r`n" + ` - "$($errorMessage)`r`n" + ` - "------------------------------------------------------`r`n"); - $messagePackage.NoNewLine = $false; - - - # Display the error message to the user - Write-Information $messagePackage ` - -InformationAction Continue; - } # DisplayErrorMessage() - - - - - - - # Fetch Enter Key - # ------------------------------- - # Documentation: - # With this function, we can momentarily pause the application such that the user may view the messages - # before terminal's buffer is cleared, the terminal is about to exit, or before the buffer gets flooded - # with verbose or additional messages. - # - # As such, we want the user to read the messages before the content is lost. - # ------------------------------- - hidden static [void] FetchEnterKey() - { - # Declarations and Initializations - # -------------------------------------------- - # Create the Message Package, we will need this to tell the user to press the 'Enter' key. - [System.Management.Automation.HostInformationMessage] $messagePackage = ` - [System.Management.Automation.HostInformationMessage]::New(); - # -------------------------------------------- - - - - # Create the message package - $messagePackage.BackgroundColor = "Black"; - $messagePackage.ForegroundColor = "White"; - $messagePackage.Message = ("`r`n`r`n"+ ` - "Press the Enter key to continue. . ."); - $messagePackage.NoNewLine = $false; - - - # Display the message to the user - Write-Information $messagePackage ` - -InformationAction Continue; - - - # Momentarily stop the application from further executing until the user provides the - # enter key character. - (Get-Host).UI.ReadLine(); - } # FetchEnterKey() - - - - - - - # Main - # ------------------------------- - # Documentation: - # This function is essentially are main entry point into this program; this is our driver. - # ------------------------------- - static [Int32] main() - { - # Declarations and Initializations - # -------------------------------------- - # We will use this variable to signify the entire operation's status. - [int32] $exitCode = 0; - # -------------------------------------- - - - - # Try to detect if the PowerShell Compact-Archive Tool Launcher had been found. - if (![Clean]::TestFilePath($Global:__PSCAT_COMPLETE_PATH__)) - { - # Because we cannot find the PSCAT Launcher, we cannot continue. - # Generate the error message - [string] $errorMessage = ("Failed to locate $($Global:__PSCAT_FILENAME__)`r`n" + ` - "Expected Path was:`r`n" + ` - "`t$($Global:__PSCAT_COMPLETE_PATH__)"); - - - # Adjust the return code to signify that an error had been reached. - $exitCode = $Global:__EXITCODE_CANNOT_FIND_PSCAT__; - - - # We already have the error message provided to us already, all that we have to do is show the message. - [Clean]::DisplayErrorMessage($errorMessage); - - - # Allow the user to read the message. - [Clean]::FetchEnterKey(); - } # if : Unable to find PSCAT Launcher - - - # If we successfully found PSCAT Launcher, then run the program. - else - { - # Execute PSCAT Launcher - $exitCode = [Clean]::LaunchPSCAT(); - } # Else : Launch the Application - - - - # Provide the operation exit code - return $exitCode; - } # main() -} # Clean - - - - - -#region Special Program Variables - -# This will contain all of the information stored within the pipe. Now, I am using this -# as I will need to capture the exit code that is returned from the main application's -# function. -[System.Object[]] $returnState = $null; - -#endregion - - - - -# Initialize the global variables that we will use within this program. -Initialization; - - -# Start the program and then return the exit code upon terminating. -$returnState = [Clean]::main(); - - -# Thrash the program's global variables. -Uninitialization; - - -# Try to retrieve the exit code that was returned by the main application and then -# return it to the Operating System. -# NOTE: We use the very last index as that was the very last item that was added -# into the Pipe. And this last item - is our exit code. -exit $returnState[$returnState.Length - 1]; \ No newline at end of file diff --git a/Scripts/Program Modes/Uninstall.ps1 b/Scripts/Program Modes/Uninstall.ps1 deleted file mode 100644 index 10869886..00000000 --- a/Scripts/Program Modes/Uninstall.ps1 +++ /dev/null @@ -1,440 +0,0 @@ -<# PowerShell Compact-Archive Tool - # Copyright (C) 2022 - # - # This program is free software: you can redistribute it and/or modify - # it under the terms of the GNU General Public License as published by - # the Free Software Foundation, either version 3 of the License, or - # (at your option) any later version. - # - # This program is distributed in the hope that it will be useful, - # but WITHOUT ANY WARRANTY; without even the implied warranty of - # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - # GNU General Public License for more details. - # - # You should have received a copy of the GNU General Public License - # along with this program. If not, see . - #> - - - - - -<# -.SYNOPSIS - Deletes data that was generated by the PowerShell Compact-Archive Tool, includes user configuration files. - -.DESCRIPTION - This tool will provide a special instruction to the PowerShell Compact-Archive Tool to perform a deep clean-up operation. - In doing so, the PowerShell Compact-Archive Tool will expunge files that had previously generated as well as remove - the current user configuration files. - - Tools that this program utilizes are: - PowerShell Core 7.1.x Minimum - This is required in order for the PSCAT software to work properly. - PowerShell Compact-Archive Tool (version 1.1.0 minimum) - This specifies which version of PSCAT supports this functionality. - -.NOTES - Author: Nicholas Gautier - Email: Nicholas.Gautier.Tiger@GMail.com - Project Website: https://github.com/SibTiger/PowerShell-Compact-Archive-Tool - -.INPUTS - Nothing is to be given or to be provided from a command or pipe. - -.OUTPUTS - Operation Return Code - 0 = Operation was Successful - 1 = General Failure - 500 = Unable to find the PowerShell Compact-Archive Tool. - 501 = Unable to launch the PowerShell Compact-Archive Tool. - 502 = Unable to load the required dependencies. - -.EXAMPLE - .\DeepClean.ps1 - -.LINK - https://github.com/SibTiger/PowerShell-Compact-Archive-Tool -#> - - - - - -# Initialization -# ------------------------------- -# Documentation: -# This function will initialize all of the required variables that we will need within this application. -# This is mainly to help when needing to maintain this application over future generations of PSCAT. -# ------------------------------- -function Initialization() -{ - # PSCAT Filename - Set-Variable -Name "__PSCAT_FILENAME__" -Value "Launcher.ps1" ` - -Option ReadOnly -Scope Global -ErrorAction SilentlyContinue ` - -Visibility Public ` - -Description "PowerShell Compact-Archive Tool's Launcher filename"; - - # PSCAT Absolute Path - # NOTE: This script should reside with the PSCAT application. - Set-Variable -Name "__PSCAT_FULL_PATH__" -Value $PSScriptRoot ` - -Option ReadOnly -Scope Global -ErrorAction SilentlyContinue ` - -Visibility Private ` - -Description "Base path in which the PSCAT application will reside"; - - # PSCAT Complete Path - Set-Variable -Name "__PSCAT_COMPLETE_PATH__" -Value "$($GLOBAL:__PSCAT_FULL_PATH__)\$($GLOBAL:__PSCAT_FILENAME__)" ` - -Option ReadOnly -Scope Global -ErrorAction SilentlyContinue ` - -Visibility Public ` - -Description "PowerShell Compact-Archive Tool's absolute path - including filename."; - - # PSCAT Operation Code - Set-Variable -Name "__PSCAT_OPERATION_CODE__" -Value 2 ` - -Option ReadOnly -Scope Global -ErrorAction SilentlyContinue ` - -Visibility Public ` - -Description "Signifies the 'Deep Clean' Operation mode in PowerShell Compact-Archive Tool."; - - # Exit Codes : Cannot Find PSCAT - Set-Variable -Name "__EXITCODE_CANNOT_FIND_PSCAT__" -Value 500 ` - -Option ReadOnly -Scope Global -ErrorAction SilentlyContinue ` - -Visibility Public ` - -Description "Exit Code signifying that the PowerShell Compact-Archive Tool could not be found."; - - # Exit Codes : Failed Launch PSCAT - Set-Variable -Name "__EXITCODE_FAILED_TO_LAUNCH_PSCAT__" -Value 501 ` - -Option ReadOnly -Scope Global -ErrorAction SilentlyContinue ` - -Visibility Public ` - -Description "Exit Code Signifying that the PowerShell Compact-Archive Tool could not be started."; -} # Initialization() - - - - - -# Uninitialization -# ------------------------------- -# Documentation: -# This function will remove all of the global variables that had been declared and initialize by this shellscript. -# This will help to cleanup unnecessary variables from the user's terminal environment. -# ------------------------------- -function Uninitialization() -{ - # PSCAT Filename - Remove-Variable -Name "__PSCAT_FILENAME__" ` - -Scope Global ` - -Force ` - -ErrorAction SilentlyContinue; - - # PSCAT Absolute Path - Remove-Variable -Name "__PSCAT_FULL_PATH__" ` - -Scope Global ` - -Force ` - -ErrorAction SilentlyContinue; - - # PSCAT Complete Path - Remove-Variable -Name "__PSCAT_COMPLETE_PATH__" ` - -Scope Global ` - -Force ` - -ErrorAction SilentlyContinue; - - # PSCAT Operation Code - Remove-Variable -Name "__PSCAT_OPERATION_CODE__" ` - -Scope Global ` - -Force ` - -ErrorAction SilentlyContinue; - - # Exit Codes : Cannot Find PSCAT - Remove-Variable -Name "__EXITCODE_CANNOT_FIND_PSCAT__" ` - -Scope Global ` - -Force ` - -ErrorAction SilentlyContinue; - - # Exit Codes : Failed Launch PSCAT - Remove-Variable -Name "__EXITCODE_FAILED_TO_LAUNCH_PSCAT__" ` - -Scope Global ` - -Force ` - -ErrorAction SilentlyContinue; -} # Uninitialization() - - - - - - -# This class provides the main operations in order to get the job done. -# Fun-Fact, I am explicitly using OOP as I can control the return information. Previously I did use -# POP, however due to the nature of the 'Pipe' in POSH - it was more trouble than what it was -# worth. Thus, switching to OOP was necessary to assure that I can move information as I want -# without it getting ridiculous.... -Class DeepClean -{ - # Launch the PowerShell Compact-Archive Tool - # ------------------------------- - # Documentation: - # This function will execute the PowerShell Compact-Archive Tool and set the Program Mode to 'Deep Clean'. - # ------------------------------- - # Output: - # [Int] Exit Code - # This is the exit code provided by the PowerShell Compact-Archive Tool program. - # ------------------------------- - hidden static [Int32] LaunchPSCAT() - { - # Declarations and Initializations - # -------------------------------------- - # We are going to use 'Splatting' to make this easier to construct the Invoke-Expression arguments. - [System.Collections.Hashtable] $hashArguments = [System.Collections.Hashtable]::New(); - - # Error Message - # Chief Reason for Error - [string] $errorTitle = "((REASON IS NOT KNOWN))"; - # -------------------------------------- - - - - # Construct the arguments - $hashArguments = @{ - Command = "& "".\$($Global:__PSCAT_FILENAME__)"" -ProgramMode $Global:__PSCAT_OPERATION_CODE__"; - ErrorAction = "Stop"; - } # Invoke-Expression Arguments - - - - # Try to launch PowerShell Compact-Archive Tool Launcher application - try - { - # Launch the PowerShell Compact-Archive Tool Launcher program - Invoke-Expression @hashArguments; - - # Operation was successful - return $LASTEXITCODE; - } # Try: Launch PSCAT Launcher - - - # Caught an error during Launch - catch - { - # Provide the error message - $errorTitle = "Failed to launch PowerShell Compact-Archive Tool Launcher!" - } # Catch: Caught an error - - - - # Generate the full error message - [string] $errorMessage = ("$($errorTitle)`r`n" + ` - "Tried to use this command: $($hashArguments.Command)`r`n" + ` - "Other properties that were used:`r`n" + ` - "`tError Action: $($hashArguments.ErrorAction)"); - - - # Display the error message to the user - [DeepClean]::DisplayErrorMessage($errorMessage); - - - # Allow the user to read the message. - [DeepClean]::FetchEnterKey(); - - - # Return the error code that we were unable to start PSCAT Launcher. - return $Global:__EXITCODE_FAILED_TO_LAUNCH_PSCAT__; - } # LaunchPSCAT() - - - - - - - # Test File Path - # ------------------------------- - # Documentation: - # This function will inspect the complete path in which the file supposedly resides. - # ------------------------------- - # Output: - # [Bool] Exist Result - # $True - File exists within the given path. - # $False - File could not be found with the provided path. - # ------------------------------- - hidden static [bool] TestFilePath([string] $pathToExamine) - { - # Check to see if we can find the file - if (Test-Path -LiteralPath "$($pathToExamine)" -PathType Leaf) - { - # Found the target file - return $true; - } # if : Found Target - - - # Unable to find the target file - return $false; - } # TestFilePath() - - - - - - - # Display Error Message - # ------------------------------- - # Documentation: - # This function will provide centralized way into creating an error message that will be - # displayed to the user's terminal buffer. - # We will only provide a static error message, such that the format does not change. - # ------------------------------- - hidden static [void] DisplayErrorMessage([string] $errorMessage) - { - # Declarations and Initializations - # -------------------------------------------- - # Create the message package that we will need to show the user that we were unable to find the PSCAT tool. - [System.Management.Automation.HostInformationMessage] $messagePackage = ` - [System.Management.Automation.HostInformationMessage]::New(); - # -------------------------------------------- - - - - # Generate the message package such that it grabs the user's attention immediately. - $messagePackage.BackgroundColor = "Black"; - $messagePackage.ForegroundColor = "Red"; - $messagePackage.Message = ("`r`n`r`n" + ` - "`t`t CRITICAL ERROR `r`n" + ` - "------------------------------------------------------`r`n" + ` - "$($errorMessage)`r`n" + ` - "------------------------------------------------------`r`n"); - $messagePackage.NoNewLine = $false; - - - # Display the error message to the user - Write-Information $messagePackage ` - -InformationAction Continue; - } # DisplayErrorMessage() - - - - - - - # Fetch Enter Key - # ------------------------------- - # Documentation: - # With this function, we can momentarily pause the application such that the user may view the messages - # before terminal's buffer is cleared, the terminal is about to exit, or before the buffer gets flooded - # with verbose or additional messages. - # - # As such, we want the user to read the messages before the content is lost. - # ------------------------------- - hidden static [void] FetchEnterKey() - { - # Declarations and Initializations - # -------------------------------------------- - # Create the Message Package, we will need this to tell the user to press the 'Enter' key. - [System.Management.Automation.HostInformationMessage] $messagePackage = ` - [System.Management.Automation.HostInformationMessage]::New(); - # -------------------------------------------- - - - - # Create the message package - $messagePackage.BackgroundColor = "Black"; - $messagePackage.ForegroundColor = "White"; - $messagePackage.Message = ("`r`n`r`n"+ ` - "Press the Enter key to continue. . ."); - $messagePackage.NoNewLine = $false; - - - # Display the message to the user - Write-Information $messagePackage ` - -InformationAction Continue; - - - # Momentarily stop the application from further executing until the user provides the - # enter key character. - (Get-Host).UI.ReadLine(); - } # FetchEnterKey() - - - - - - - # Main - # ------------------------------- - # Documentation: - # This function is essentially are main entry point into this program; this is our driver. - # ------------------------------- - static [Int32] main() - { - # Declarations and Initializations - # -------------------------------------- - # We will use this variable to signify the entire operation's status. - [int32] $exitCode = 0; - # -------------------------------------- - - - - # Try to detect if the PowerShell Compact-Archive Tool Launcher had been found. - if (![DeepClean]::TestFilePath($Global:__PSCAT_COMPLETE_PATH__)) - { - # Because we cannot find the PSCAT Launcher, we cannot continue. - # Generate the error message - [string] $errorMessage = ("Failed to locate $($Global:__PSCAT_FILENAME__)`r`n" + ` - "Expected Path was:`r`n" + ` - "`t$($Global:__PSCAT_COMPLETE_PATH__)"); - - - # Adjust the return code to signify that an error had been reached. - $exitCode = $Global:__EXITCODE_CANNOT_FIND_PSCAT__; - - - # We already have the error message provided to us already, all that we have to do is show the message. - [DeepClean]::DisplayErrorMessage($errorMessage); - - - # Allow the user to read the message. - [DeepClean]::FetchEnterKey(); - } # if : Unable to find PSCAT Launcher - - - # If we successfully found PSCAT Launcher, then run the program. - else - { - # Execute PSCAT Launcher - $exitCode = [DeepClean]::LaunchPSCAT(); - } # Else : Launch the Application - - - - # Provide the operation exit code - return $exitCode; - } # main() -} # DeepClean - - - - -#region Special Program Variables - -# This will contain all of the information stored within the pipe. Now, I am using this -# as I will need to capture the exit code that is returned from the main application's -# function. -[System.Object[]] $returnState = $null; - -#endregion - - - - -# Initialize the global variables that we will use within this program. -Initialization; - - -# Start the program and then return the exit code upon terminating. -$returnState = [DeepClean]::main(); - - -# Thrash the program's global variables. -Uninitialization; - - -# Try to retrieve the exit code that was returned by the main application and then -# return it to the Operating System. -# NOTE: We use the very last index as that was the very last item that was added -# into the Pipe. And this last item - is our exit code. -exit $returnState[$returnState.Length - 1]; \ No newline at end of file From f6ea06d4539070b49a43a7c55226c31b1545d761 Mon Sep 17 00:00:00 2001 From: Nicholas Gautier Date: Sun, 23 Oct 2022 15:11:03 -0500 Subject: [PATCH 4/4] Beta Version! There's still some work to be done, but I am confident with what the program to do at this moment. --- Installer/Scripts/Project Information.iss | 4 ++-- Scripts/Initializations.ps1 | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Installer/Scripts/Project Information.iss b/Installer/Scripts/Project Information.iss index 8608a57d..813ab75a 100644 --- a/Installer/Scripts/Project Information.iss +++ b/Installer/Scripts/Project Information.iss @@ -31,8 +31,8 @@ #define public _PRODUCT_NAME_FULL_ "PowerShell Compact-Archive Tool" #define public _PRODUCT_NAME_SHORT_ "PSCAT" #define public _PRODUCT_VERSION_ "1.1.0" -#define public _PRODUCT_VERSION_CODENAME_ "Cordis" -#define public _PRODUCT_VERSION_DATE_ "2022.05.22" +#define public _PRODUCT_VERSION_CODENAME_ "Cordis [Beta Version]" +#define public _PRODUCT_VERSION_DATE_ "23.05.2022" #define public _PRODUCT_WEBSITE_HOMEPAGE_ "https://github.com/SibTiger/PowerShell-Compact-Archive-Tool" #define public _PRODUCT_WEBSITE_SUPPORT_ "https://github.com/SibTiger/PowerShell-Compact-Archive-Tool/wiki" #define public _PRODUCT_WEBSITE_UPDATES_ "https://github.com/SibTiger/PowerShell-Compact-Archive-Tool/releases" diff --git a/Scripts/Initializations.ps1 b/Scripts/Initializations.ps1 index b4795b24..c271c588 100644 --- a/Scripts/Initializations.ps1 +++ b/Scripts/Initializations.ps1 @@ -73,7 +73,7 @@ function InitializationProgramIdentity() -Description "The short name of the application"; # Version - Set-Variable -Name "_VERSION_" -Value "1.1.0 - Alpha" ` + Set-Variable -Name "_VERSION_" -Value "1.1.0 - Beta" ` -Option ReadOnly -Scope Global -ErrorAction SilentlyContinue ` -Visibility Public ` -Description "The version of the application"; @@ -87,7 +87,7 @@ function InitializationProgramIdentity() # Release Date # Date Format: DD.MM.YYYY with leading zeros - Set-Variable -Name "_RELEASEDATE_" -Value "xx.03.2022" ` + Set-Variable -Name "_RELEASEDATE_" -Value "23.10.2022" ` -Option ReadOnly -Scope Global -ErrorAction SilentlyContinue ` -Visibility Public ` -Description "The date in which the version of the application was released.";