mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-11-15 07:05:51 -06:00
3903eaaa24
* Replace Tabs with Spaces to follow the conventions
* Add Preprocessing in Compiler
* Compile from Anywhere you want - Running 'Compile.ps1' Works in any directory you call it from
* Code Formatting Changes
* Result of Preprocessing Step in 'Compile.ps1' Script - Remove Trailing Whitespace Characters
* Make Preprocessing more advanced
* Move Preprocessing to a separate script file
* Make Self Modification impossible for 'tools/Do-PreProcessing.ps1' Script - Make the workingdir same as sync.PSScriptRoot for consistency
* Revert commit b5dffd671f
* Patched a Bug of some Excluded Files not actually get excluded in 'Get-ChildItem' PS Cmdlet
* Update Replace Regex for Code Formatting in 'Do-PreProcessing' Script Tool
* Rename 'Do-PreProcessing' to 'Invoke-Preprocessing' - Update some Comments
* Make 'Invoke-Preprocessing' Modular - Update RegEx to handle more cases - Update Documentation - Add Validations & Useful feedback upon error
* Replace Tabs with Spaces to follow the conventions - 'applications.json' File
* Code Formatting Changes - 'Copy-Files' Private Function
* Update Replace Regex for Code Formatting in 'Invoke-Preprocessing' Script Tool
* Replace Tabs with Spaces to follow the conventions - Make 'ExcludedFiles' validation step check all filepaths before finally checking if any has failed
* Result of 'Invoke-Preprocessing' Script
* Update Replace Regex for Code Formatting in 'Invoke-Preprocessing' Script Tool
97 lines
4.4 KiB
PowerShell
97 lines
4.4 KiB
PowerShell
function Test-WinUtilPackageManager {
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
Checks if Winget and/or Choco are installed
|
|
|
|
.PARAMETER winget
|
|
Check if Winget is installed
|
|
|
|
.PARAMETER choco
|
|
Check if Chocolatey is installed
|
|
|
|
#>
|
|
|
|
Param(
|
|
[System.Management.Automation.SwitchParameter]$winget,
|
|
[System.Management.Automation.SwitchParameter]$choco
|
|
)
|
|
|
|
$status = "not-installed"
|
|
|
|
if ($winget) {
|
|
# Check if Winget is available while getting it's Version if it's available
|
|
$wingetExists = $true
|
|
try {
|
|
$wingetVersionFull = winget --version
|
|
} catch [System.Management.Automation.CommandNotFoundException], [System.Management.Automation.ApplicationFailedException] {
|
|
Write-Warning "Winget was not found due to un-availablity reasons"
|
|
$wingetExists = $false
|
|
} catch {
|
|
Write-Warning "Winget was not found due to un-known reasons, The Stack Trace is:`n$($psitem.Exception.StackTrace)"
|
|
$wingetExists = $false
|
|
}
|
|
|
|
# If Winget is available, Parse it's Version and give proper information to Terminal Output.
|
|
# If it isn't available, the return of this funtion will be "not-installed", indicating that
|
|
# Winget isn't installed/available on The System.
|
|
if ($wingetExists) {
|
|
# Check if Preview Version
|
|
if ($wingetVersionFull.Contains("-preview")) {
|
|
$wingetVersion = $wingetVersionFull.Trim("-preview")
|
|
$wingetPreview = $true
|
|
} else {
|
|
$wingetVersion = $wingetVersionFull
|
|
$wingetPreview = $false
|
|
}
|
|
|
|
# Check if Winget's Version is too old.
|
|
$wingetCurrentVersion = [System.Version]::Parse($wingetVersion.Trim('v'))
|
|
# Grabs the latest release of Winget from the Github API for version check process.
|
|
$response = Invoke-RestMethod -Uri "https://api.github.com/repos/microsoft/Winget-cli/releases/latest" -Method Get -ErrorAction Stop
|
|
$wingetLatestVersion = [System.Version]::Parse(($response.tag_name).Trim('v')) #Stores version number of latest release.
|
|
$wingetOutdated = $wingetCurrentVersion -lt $wingetLatestVersion
|
|
Write-Host "===========================================" -ForegroundColor Green
|
|
Write-Host "--- Winget is installed ---" -ForegroundColor Green
|
|
Write-Host "===========================================" -ForegroundColor Green
|
|
Write-Host "Version: $wingetVersionFull" -ForegroundColor White
|
|
|
|
if (!$wingetPreview) {
|
|
Write-Host " - Winget is a release version." -ForegroundColor Green
|
|
} else {
|
|
Write-Host " - Winget is a preview version. Unexpected problems may occur." -ForegroundColor Yellow
|
|
}
|
|
|
|
if (!$wingetOutdated) {
|
|
Write-Host " - Winget is Up to Date" -ForegroundColor Green
|
|
$status = "installed"
|
|
} else {
|
|
Write-Host " - Winget is Out of Date" -ForegroundColor Red
|
|
$status = "outdated"
|
|
}
|
|
} else {
|
|
Write-Host "===========================================" -ForegroundColor Red
|
|
Write-Host "--- Winget is not installed ---" -ForegroundColor Red
|
|
Write-Host "===========================================" -ForegroundColor Red
|
|
$status = "not-installed"
|
|
}
|
|
}
|
|
|
|
if ($choco) {
|
|
if ((Get-Command -Name choco -ErrorAction Ignore) -and ($chocoVersion = (Get-Item "$env:ChocolateyInstall\choco.exe" -ErrorAction Ignore).VersionInfo.ProductVersion)) {
|
|
Write-Host "===========================================" -ForegroundColor Green
|
|
Write-Host "--- Chocolatey is installed ---" -ForegroundColor Green
|
|
Write-Host "===========================================" -ForegroundColor Green
|
|
Write-Host "Version: v$chocoVersion" -ForegroundColor White
|
|
$status = "installed"
|
|
} else {
|
|
Write-Host "===========================================" -ForegroundColor Red
|
|
Write-Host "--- Chocolatey is not installed ---" -ForegroundColor Red
|
|
Write-Host "===========================================" -ForegroundColor Red
|
|
$status = "not-installed"
|
|
}
|
|
}
|
|
|
|
return $status
|
|
}
|