Added support for 'Scoop Package Manager'.

This commit is contained in:
Rohan Barar 2024-07-24 18:27:02 +10:00
parent ba86f338bf
commit 3298dd12b8

View File

@ -1,20 +1,29 @@
<#
'Get-Icon' Source:
https://github.com/proxb/PowerShell_Scripts/blob/master/Get-Icon.ps1
'Get-Icon' License:
The MIT License (MIT)
Copyright (c)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#>
Function Get-Icon {
<#
Get-Icon License:
License
The MIT License (MIT)
Copyright (c)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#>
<#
.SYNOPSIS
Gets the icon from a file
@ -147,7 +156,6 @@ Function Get-Icon {
-----------
Returns the bytes representation of the icon. -Join was used in this for the sake
of displaying all of the data.
#>
[cmdletbinding(
DefaultParameterSetName = '__DefaultParameterSetName'
@ -204,23 +212,98 @@ Function Get-Icon {
}
}
### SEQUENTIAL LOGIC ###
# Print bash commands to define three new arrays.
"NAMES=()"
"ICONS=()"
"EXES=()"
# Search for installed applications.
# WINDOWS REGISTRY.
Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\*" |
Select-Object -Property "(default)" -Unique |
Where-Object {$_."(default)" -ne $null} |
ForEach-Object {
$Exe = $_."(default)".Trim('"')
$Item = Get-Item $Exe
if ($Item.VersionInfo.FileDescription) {
$Name = $Item.VersionInfo.FileDescription.Trim() -replace " ", " "
# Remove leading and trailing double quotation marks from the path.
$exePath = $_."(default)".Trim('"')
# Get the application name.
if ((Get-Item $exePath).VersionInfo.FileDescription) {
# Remove leading/trailing whitespace and replace multiple spaces with a single space.
$exeName = (Get-Item $exePath).VersionInfo.FileDescription.Trim() -replace '\s+', ' '
} else {
$Name = [System.IO.Path]::GetFileNameWithoutExtension($Exe)
# Get the executable file name without the file extension.
$exeName = [System.IO.Path]::GetFileNameWithoutExtension($exePath)
}
# Store the application icon as a base-64 string.
$exeIcon = Get-Icon -Path $exePath -ToBase64
# Output the results as bash commands that append the results to several bash arrays.
"NAMES+=(""$exeName"")"
"EXES+=(""$exePath"")"
"ICONS+=(""$exeIcon"")"
}
# SCOOP PACKAGE MANAGER
# Specify the 'scoop' shims directory.
$scoopDir = "$HOME\scoop\shims"
# Check if the 'scoop' shims directory exists.
if (Test-Path -Path $scoopDir -PathType Container) {
# Initialise an empty array to store executable paths.
$exePaths = @()
# Get all '.shim' files.
$shimFiles = Get-ChildItem -Path $scoopDir -Filter *.shim
# Loop through each '.shim' file to extract the executable path.
foreach ($shimFile in $shimFiles) {
# Read the content of the '.shim' file.
$shimFileContent = Get-Content -Path $shimFile.FullName
# Extract the path using regex, exiting the loop after the first match is found.
$exePath = ""
foreach ($line in $shimFileContent) {
# '^\s*path\s*=\s*"([^"]+)"'
# ^ --> Asserts the start of the line.
# \s* --> Matches any whitespace characters (zero or more times).
# path --> Matches the literal string "path".
# \s*=\s* --> Matches an equal sign = surrounded by optional whitespace characters.
# " --> Matches an initial double quote.
# ([^"]+) --> Captures one or more characters that are not ", representing the path inside the double quotes.
# " --> Matches a final double quote.
if ($line -match '^\s*path\s*=\s*"([^"]+)"') {
$exePath = $matches[1]
break
}
}
# Add extracted path to the array
$exePaths += $exePath
}
# Loop through the extracted executable file paths.
foreach ($exePath in $exePaths) {
# Get the application name.
if ((Get-Item $exePath).VersionInfo.FileDescription) {
# Remove leading/trailing whitespace and replace multiple spaces with a single space.
$exeName = (Get-Item $exePath).VersionInfo.FileDescription.Trim() -replace '\s+', ' '
} else {
# Get the executable file name without the file extension.
$exeName = [System.IO.Path]::GetFileNameWithoutExtension($exePath)
}
# Add the 'scoop' tag to the application name.
$exeName = "[Scoop] " + $exeName
# Store the application icon as a base-64 string.
$exeIcon = Get-Icon -Path $exePath -ToBase64
# Output the results as bash commands that append the results to several bash arrays.
"NAMES+=(""$exeName"")"
"EXES+=(""$exePath"")"
"ICONS+=(""$exeIcon"")"
}
$Icon = Get-Icon -Path $Exe -ToBase64
#Get-ItemProperty $Exe -Name VersionInfo
"NAMES+=(""$Name"")"
"EXES+=(""$Exe"")"
"ICONS+=(""$Icon"")"
}