Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ESC = [char]0x1b
- $ALTC = "$ESC[?1049h"
- $MAINC = "$ESC[?1049l"
- $global:CACHELIST = $null
- [Int] $MainPad = 75
- [Int] $NamePad = 40
- [Int] $StatePad = $MainPad - $NamePad
- $ListApps =
- (
- "Google.Chrome",
- "Mozilla.Firefox",
- "Spotify.Spotify",
- "Discord.Discord",
- "BraveSoftware.BraveBrowser",
- "Valve.Steam",
- "VideoLAN.VLC",
- "EpicGames.EpicGamesLauncher",
- "Telegram.TelegramDesktop",
- "BlenderFoundation.Blender",
- "Microsoft.VisualStudio.2022.Community",
- "UnityTechnologies.UnityHub"
- )
- function GetAppList
- {
- if($null -eq $global:CACHELIST)
- {
- $global:CACHELIST = winget list
- }
- return $global:CACHELIST
- }
- function IsAppInstalled([String] $Id)
- {
- $list = GetAppList
- $selected = $list | Select-String -Pattern "$Id " -CaseSensitive -SimpleMatch
- return $selected.Length -gt 0
- }
- function GetStringStatus
- {
- param($IsAppInstalled, $IsAppSelected)
- if($IsAppSelected)
- {
- if($IsAppInstalled)
- {
- return "$ESC[31mTo Uninstall".PadRight($StatePad + 4)
- }
- else
- {
- return "$ESC[38;2;155;135;12mTo Install".PadRight($StatePad + 17)
- }
- }
- else
- {
- if($IsAppInstalled)
- {
- return "$ESC[32mInstalled".PadRight($StatePad + 4)
- }
- else
- {
- return "$ESC[38;2;100;100;100mNot Installed".PadRight($StatePad + 18)
- }
- }
- }
- function MakeAppsInfo
- {
- $result = @()
- for ($IndexApp=0; $IndexApp -lt $ListApps.Length; $IndexApp+=1 )
- {
- $app = [string]$ListApps[$IndexApp]
- $IsInstalled = IsAppInstalled($app)
- $result += [PSCustomObject]@{
- Index = $IndexApp
- Name = $app
- IsInstalled=$IsInstalled
- IsSelected=$false
- }
- }
- return , $result
- }
- function PrintApps
- {
- Param($Appsinfo, $CurIndex)
- foreach ($info in $Appsinfo)
- {
- if($info.Index -Eq $CurIndex)
- {
- $host.ui.Write("$ESC[47;30m")
- }
- else
- {
- $host.ui.Write("$ESC[0m")
- }
- $name = $info.Name.PadRight($NamePad)
- $StringStatus = GetStringStatus -IsAppInstalled $info.IsInstalled -IsAppSelected $info.IsSelected
- Write-Host "$name $StringStatus"
- }
- Write-Host "$ESC[0m"
- }
- function PrintInfoNavigation {
- $info = "$ESC[39m$ESC[48;5;8m Up/Down Arrows - $ESC[36mMove$ESC[39m; Enter - $ESC[36mApply$ESC[39m; Spacebar - $ESC[36mSelect$ESC[39m; ESC - $ESC[36mExit"
- Write-Host $info.PadRight($MainPad + 49)
- $host.ui.Write("$ESC[0m")
- }
- function ApplyChanges
- {
- param ($Appsinfo)
- foreach ($info in $Appsinfo)
- {
- if($info.IsSelected)
- {
- if($info.IsInstalled)
- {
- winget uninstall --id $info.Name
- }
- else
- {
- winget install --id $info.Name
- }
- }
- }
- }
- function main()
- {
- Write-Host("Gathering information...")
- $Appsinfo = MakeAppsInfo
- $CurIndex = 0
- [bool] $isFinished = $false
- [bool] $GoApply = $false
- while($isFinished -eq $false)
- {
- $CurIndex = [Math]::Max(0, [Math]::Min($Appsinfo.Length - 1, $CurIndex))
- $Host.UI.RawUI.CursorPosition = @{ X = 0; Y = 0 }
- PrintApps -Appsinfo $Appsinfo -CurIndex $CurIndex
- PrintInfoNavigation
- $key = [System.Console]::ReadKey($true).Key
- switch ($key)
- {
- "UpArrow" { $CurIndex -= 1 }
- "DownArrow" { $CurIndex += 1 }
- "Enter" { $isFinished = $true; $GoApply = $true }
- "Spacebar" { $Appsinfo[$CurIndex].IsSelected = !$Appsinfo[$CurIndex].IsSelected }
- "Escape" { $isFinished = $true; }
- Default {}
- }
- }
- $Host.UI.RawUI.CursorPosition = @{ X = 0; Y = 0 }
- Clear-Host
- if($GoApply)
- {
- ApplyChanges -Appsinfo $Appsinfo
- Write-Output "Press any key..."
- [System.Console]::ReadKey($true) | Out-Null
- }
- }
- $host.ui.Write($ALTC)
- $Host.UI.RawUI.CursorPosition = @{ X = 0; Y = 0 }
- Clear-Host
- main;
- $host.ui.Write($MAINC)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement