Skip to content

Commit

Permalink
Removed [CommonIO]::DetectCommand(), not used
Browse files Browse the repository at this point in the history
  • Loading branch information
SibTiger committed Dec 29, 2024
1 parent de2a7ab commit a45ec60
Showing 1 changed file with 1 addition and 111 deletions.
112 changes: 1 addition & 111 deletions Scripts/CommonIO.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<# PowerShell Compact-Archive Tool
<# PowerShell Compact-Archive Tool
# Copyright (C) 2025
#
# This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -335,116 +335,6 @@ class CommonIO

#region External Command Functions

<# Detect Command [Test]
# -------------------------------
# Documentation:
# This function will help to determine if the external command or command (in general terms)
# could be detected with the given path and if the command is a supported command type.
# If the file or command we want to ultimately execute is not detected in the filesystem or
# the file we want to use is not the proper executable type, then the detection will return
# false - indicating that the command cannot be used.
# -------------------------------
# Inputs:
# [string] Command
# The external executable or command to test.
# [string] Type
# The type of command that will be executed.
# See Get-Command "CommandType"
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/get-command
# -------------------------------
# Output:
# [bool] Detected Code
# $false = Failure to detect the external executable or was not the proper command type.
# $true = Successfully detected the external executable.
# -------------------------------
#>
static [bool] DetectCommand([string] $command, ` # Executable or command to run
[string] $type) # Command type
{
# Declarations and Initializations
# ----------------------------------------
[string] $commandDebugInfo = $null; # This will contain any additional information that could be useful when
# debugging, but only if the command target was found.
[bool] $exitCode = $false; # The detection code that will be returned based on the results;
# if the command was found or not.
# ----------------------------------------


# Try to detect the requested command
try
{
# We will use this variable to capture output provided from the Get-Command.
[System.Object] $debugInfo = $null;

# Try to detect the requested command
$debugInfo = Get-Command -Name $command `
-CommandType $type `
-ErrorAction Stop;

# Setup the information that was provided from the Get-Command
$commandDebugInfo = ("Application Information Gathered by System:`r`n" + `
"`t`tCommand Name:`t`t$($debugInfo.Name)`r`n" + `
"`t`tCommand Path:`t`t$($debugInfo.Source)`r`n" + `
"`t`tCommand Version:`t$($debugInfo.Version)`r`n" + `
"`t`tCommand Type:`t`t$($debugInfo.CommandType)");

# The command was detected
$exitCode = $true;
} # Try - Find Command



# Caught an error
catch
{
# Because the Get-Command could not find the executable binary file, this
# condition will be triggered. There's really nothing to do within this
# condition - but to help prevent from the application from prematurely
# terminating. Everything is handled within the Finally condition.
;
} # Catch - Error; Command not Found



# Process any further protocol after the detection
Finally
{
# Message level that will be presented in the log file.
[LogMessageLevel] $msgLevel = [LogMessageLevel]::Warning;

# If the operation was successful, change the message level accordingly
if ($exitCode)
{
$msgLevel = [LogMessageLevel]::Verbose;
} # If : Successful operation


# * * * * * * * * * * * * * * * * * * *
# Debugging
# --------------

# Generate the initial message
[string] $logMessage = "Tried to find the $($type) named $($command); detected result was $($exitCode)";

# Generate any additional information that might be useful
[string] $logAdditionalMSG = $commandDebugInfo;

# Pass the information to the logging system
[Logging]::LogProgramActivity($logMessage, ` # Initial message
$logAdditionalMSG, ` # Additional information
$msgLevel); # Message level

# * * * * * * * * * * * * * * * * * * *
} # Finally : Protocol after detection


# Return the results
return $exitCode;
} # DetectCommand()




<# Execute Command - Logging
# -------------------------------
# Documentation:
Expand Down

0 comments on commit a45ec60

Please sign in to comment.