Test 1715290913 fix ugly ifs (#1957)

* fix nested ifs

* Compile Winutil

* fix syntax

* Compile Winutil

* Add Spotify and Choco Fallback

* Compile Winutil

---------

Co-authored-by: ty802 <ty802@users.noreply.github.com>
Co-authored-by: Chris Titus <contact@christitus.com>
Co-authored-by: ChrisTitusTech <ChrisTitusTech@users.noreply.github.com>
This commit is contained in:
kian yamamoto 2024-05-09 22:49:23 -05:00 committed by GitHub
parent 8eb51560d8
commit 565f9c310c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 110 additions and 36 deletions

1
.gitignore vendored
View File

@ -44,3 +44,4 @@ Microsoft.PowerShell.ConsoleHost.dll
microwin.log
True
test.ps1
winutil.ps1

View File

@ -1687,6 +1687,14 @@
"link": "https://bitsum.com/",
"winget": "BitSum.ProcessLasso"
},
"WPFInstallspotify": {
"category": "Multimedia Tools",
"choco": "spotify",
"content": "Spotify",
"description": "Spotify is a digital music service that gives you access to millions of songs, podcasts, and videos from artists all over the world.",
"link": "https://www.spotify.com/",
"winget": "Spotify.Spotify"
},
"WPFInstallprocessmonitor": {
"category": "Microsoft Tools",
"choco": "procexp",

View File

@ -34,23 +34,37 @@ Function Install-WinUtilProgramWinget {
# This is up to the individual package maintainers to enable these options. Aka. not as clean as Linux Package Managers.
try {
$status = $(Start-Process -FilePath "winget" -ArgumentList "install --id $Program --silent --accept-source-agreements --accept-package-agreements" -Wait -PassThru).ExitCode
if($status -ne 0){
if($status -eq 0){
Write-Host "$Program installed successfully."
continue
}
Write-Host "Attempt with User scope"
$status = $(Start-Process -FilePath "winget" -ArgumentList "install --id $Program --scope user --silent --accept-source-agreements --accept-package-agreements" -Wait -PassThru).ExitCode
if($status -ne 0){
Write-Host "Attempt with Unelevated prompt"
$status = $(Start-Process -FilePath "powershell" -ArgumentList "-Command Start-Process winget -ArgumentList 'install --id $Program --silent --accept-source-agreements --accept-package-agreements' -Verb runAsUser" -Wait -PassThru).ExitCode
if($status -ne 0){
Write-Host "Failed to install $Program."
} else {
Write-Host "$Program installed successfully with Unelevated prompt."
}
} else {
if($status -eq 0){
Write-Host "$Program installed successfully with User scope."
continue
}
Write-Host "Attempt with User prompt"
$userChoice = [System.Windows.MessageBox]::Show("Do you want to attempt $Program installation with specific user credentials? Select 'Yes' to proceed or 'No' to skip.", "User Credential Prompt", [System.Windows.MessageBoxButton]::YesNo)
if ($userChoice -eq 'Yes') {
$getcreds = Get-Credential
$process = Start-Process -FilePath "winget" -ArgumentList "install --id $Program --silent --accept-source-agreements --accept-package-agreements" -Credential $getcreds -PassThru
Wait-Process -Id $process.Id
$status = $process.ExitCode
} else {
Write-Host "$Program installed successfully."
Write-Host "Skipping installation with specific user credentials."
}
if($status -eq 0){
Write-Host "$Program installed successfully with User prompt."
continue
}
Write-Host "Attempting installation with Chocolatey as a fallback method"
$status = $(Start-Process -FilePath "choco" -ArgumentList "install $Program -y" -Wait -PassThru).ExitCode
if($status -eq 0){
Write-Host "$Program installed successfully using Chocolatey."
continue
}
Write-Host "Failed to install $Program. You need to install it manually... Sorry!"
} catch {
Write-Host "Failed to install $Program due to an error: $_"
}

View File

@ -10,7 +10,7 @@
Author : Chris Titus @christitustech
Runspace Author: @DeveloperDurp
GitHub : https://github.com/ChrisTitusTech
Version : 24.05.09
#>
param (
[switch]$Debug,
@ -47,7 +47,7 @@ Add-Type -AssemblyName System.Windows.Forms
# Variable to sync between runspaces
$sync = [Hashtable]::Synchronized(@{})
$sync.PSScriptRoot = $PSScriptRoot
$sync.version = "24.05.09"
$sync.version = "24.05.10"
$sync.configs = @{}
$sync.ProcessRunning = $false
@ -733,23 +733,37 @@ Function Install-WinUtilProgramWinget {
# This is up to the individual package maintainers to enable these options. Aka. not as clean as Linux Package Managers.
try {
$status = $(Start-Process -FilePath "winget" -ArgumentList "install --id $Program --silent --accept-source-agreements --accept-package-agreements" -Wait -PassThru).ExitCode
if($status -ne 0){
if($status -eq 0){
Write-Host "$Program installed successfully."
continue
}
Write-Host "Attempt with User scope"
$status = $(Start-Process -FilePath "winget" -ArgumentList "install --id $Program --scope user --silent --accept-source-agreements --accept-package-agreements" -Wait -PassThru).ExitCode
if($status -ne 0){
Write-Host "Attempt with Unelevated prompt"
$status = $(Start-Process -FilePath "powershell" -ArgumentList "-Command Start-Process winget -ArgumentList 'install --id $Program --silent --accept-source-agreements --accept-package-agreements' -Verb runAsUser" -Wait -PassThru).ExitCode
if($status -ne 0){
Write-Host "Failed to install $Program."
} else {
Write-Host "$Program installed successfully with Unelevated prompt."
}
} else {
if($status -eq 0){
Write-Host "$Program installed successfully with User scope."
continue
}
Write-Host "Attempt with User prompt"
$userChoice = [System.Windows.MessageBox]::Show("Do you want to attempt $Program installation with specific user credentials? Select 'Yes' to proceed or 'No' to skip.", "User Credential Prompt", [System.Windows.MessageBoxButton]::YesNo)
if ($userChoice -eq 'Yes') {
$getcreds = Get-Credential
$process = Start-Process -FilePath "winget" -ArgumentList "install --id $Program --silent --accept-source-agreements --accept-package-agreements" -Credential $getcreds -PassThru
Wait-Process -Id $process.Id
$status = $process.ExitCode
} else {
Write-Host "$Program installed successfully."
Write-Host "Skipping installation with specific user credentials."
}
if($status -eq 0){
Write-Host "$Program installed successfully with User prompt."
continue
}
Write-Host "Attempting installation with Chocolatey as a fallback method"
$status = $(Start-Process -FilePath "choco" -ArgumentList "install $Program -y" -Wait -PassThru).ExitCode
if($status -eq 0){
Write-Host "$Program installed successfully using Chocolatey."
continue
}
Write-Host "Failed to install $Program. You need to install it manually... Sorry!"
} catch {
Write-Host "Failed to install $Program due to an error: $_"
}
@ -6709,6 +6723,14 @@ $sync.configs.applications = '{
"link": "https://bitsum.com/",
"winget": "BitSum.ProcessLasso"
},
"WPFInstallspotify": {
"category": "Multimedia Tools",
"choco": "spotify",
"content": "Spotify",
"description": "Spotify is a digital music service that gives you access to millions of songs, podcasts, and videos from artists all over the world.",
"link": "https://www.spotify.com/",
"winget": "Spotify.Spotify"
},
"WPFInstallprocessmonitor": {
"category": "Microsoft Tools",
"choco": "procexp",
@ -12208,6 +12230,9 @@ $inputXML = '<Window x:Class="WinUtility.MainWindow"
<CheckBox Name="WPFInstallsharex" Content="ShareX (Screenshots)" ToolTip="ShareX is a free and open-source screen capture and file sharing tool. It supports various capture methods and offers advanced features for editing and sharing screenshots." Margin="0,0,2,0"/><TextBlock Name="WPFInstallsharexLink" Style="{StaticResource HoverTextBlockStyle}" Text="(?)" ToolTip="https://getsharex.com/" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<CheckBox Name="WPFInstallspotify" Content="Spotify" ToolTip="Spotify is a digital music service that gives you access to millions of songs, podcasts, and videos from artists all over the world." Margin="0,0,2,0"/><TextBlock Name="WPFInstallspotifyLink" Style="{StaticResource HoverTextBlockStyle}" Text="(?)" ToolTip="https://www.spotify.com/" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<CheckBox Name="WPFInstallstrawberry" Content="Strawberry (Music Player)" ToolTip="Strawberry is an open-source music player that focuses on music collection management and audio quality. It supports various audio formats and features a clean user interface." Margin="0,0,2,0"/><TextBlock Name="WPFInstallstrawberryLink" Style="{StaticResource HoverTextBlockStyle}" Text="(?)" ToolTip="https://www.strawberrymusicplayer.org/" />
</StackPanel>
<StackPanel Orientation="Horizontal">
@ -12219,6 +12244,10 @@ $inputXML = '<Window x:Class="WinUtility.MainWindow"
<StackPanel Orientation="Horizontal">
<CheckBox Name="WPFInstallvideomass" Content="Videomass" ToolTip="Videomass by GianlucaPernigotto is a cross-platform GUI for FFmpeg, streamlining multimedia file processing with batch conversions and user-friendly features." Margin="0,0,2,0"/><TextBlock Name="WPFInstallvideomassLink" Style="{StaticResource HoverTextBlockStyle}" Text="(?)" ToolTip="https://jeanslack.github.io/Videomass/" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<CheckBox Name="WPFInstallvlc" Content="VLC (Video Player)" ToolTip="VLC Media Player is a free and open-source multimedia player that supports a wide range of audio and video formats. It is known for its versatility and cross-platform compatibility." Margin="0,0,2,0"/><TextBlock Name="WPFInstallvlcLink" Style="{StaticResource HoverTextBlockStyle}" Text="(?)" ToolTip="https://www.videolan.org/vlc/" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<CheckBox Name="WPFInstallvlc" Content="VLC (Video Player)" ToolTip="VLC Media Player is a free and open-source multimedia player that supports a wide range of audio and video formats. It is known for its versatility and cross-platform compatibility." Margin="0,0,2,0"/><TextBlock Name="WPFInstallvlcLink" Style="{StaticResource HoverTextBlockStyle}" Text="(?)" ToolTip="https://www.videolan.org/vlc/" />
</StackPanel>
@ -12439,6 +12468,7 @@ $inputXML = '<Window x:Class="WinUtility.MainWindow"
<StackPanel Orientation="Horizontal">
<CheckBox Name="WPFInstalllinkshellextension" Content="Link Shell extension" ToolTip="Link Shell Extension (LSE) provides for the creation of Hardlinks, Junctions, Volume Mountpoints, Symbolic Links, a folder cloning process that utilises Hardlinks or Symbolic Links and a copy process taking care of Junctions, Symbolic Links, and Hardlinks. LSE, as its name implies is implemented as a Shell extension and is accessed from Windows Explorer, or similar file/folder managers." Margin="0,0,2,0"/><TextBlock Name="WPFInstalllinkshellextensionLink" Style="{StaticResource HoverTextBlockStyle}" Text="(?)" ToolTip="https://schinagl.priv.at/nt/hardlinkshellext/hardlinkshellext.html" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<CheckBox Name="WPFInstalllivelywallpaper" Content="Lively Wallpaper" ToolTip="Free and open-source software that allows users to set animated desktop wallpapers and screensavers." Margin="0,0,2,0"/><TextBlock Name="WPFInstalllivelywallpaperLink" Style="{StaticResource HoverTextBlockStyle}" Text="(?)" ToolTip="https://www.rocksdanister.com/lively/" />
</StackPanel>
@ -12446,11 +12476,20 @@ $inputXML = '<Window x:Class="WinUtility.MainWindow"
<CheckBox Name="WPFInstalllocalsend" Content="LocalSend" ToolTip="An open source cross-platform alternative to AirDrop." Margin="0,0,2,0"/><TextBlock Name="WPFInstalllocalsendLink" Style="{StaticResource HoverTextBlockStyle}" Text="(?)" ToolTip="https://localsend.org/" />
</StackPanel>
</StackPanel>
</Border>
<Border Grid.Row="1" Grid.Column="4">
<StackPanel Background="{MainBackgroundColor}" SnapsToDevicePixels="True">
<StackPanel Orientation="Horizontal">
<CheckBox Name="WPFInstalllivelywallpaper" Content="Lively Wallpaper" ToolTip="Free and open-source software that allows users to set animated desktop wallpapers and screensavers." Margin="0,0,2,0"/><TextBlock Name="WPFInstalllivelywallpaperLink" Style="{StaticResource HoverTextBlockStyle}" Text="(?)" ToolTip="https://www.rocksdanister.com/lively/" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<CheckBox Name="WPFInstalllocalsend" Content="LocalSend" ToolTip="An open source cross-platform alternative to AirDrop." Margin="0,0,2,0"/><TextBlock Name="WPFInstalllocalsendLink" Style="{StaticResource HoverTextBlockStyle}" Text="(?)" ToolTip="https://localsend.org/" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<CheckBox Name="WPFInstalllockhunter" Content="LockHunter" ToolTip="LockHunter is a free tool to delete files blocked by something you do not know." Margin="0,0,2,0"/><TextBlock Name="WPFInstalllockhunterLink" Style="{StaticResource HoverTextBlockStyle}" Text="(?)" ToolTip="https://lockhunter.com/" />
</StackPanel>
<StackPanel Orientation="Horizontal">

View File

@ -604,6 +604,9 @@
<CheckBox Name="WPFInstallsharex" Content="ShareX (Screenshots)" ToolTip="ShareX is a free and open-source screen capture and file sharing tool. It supports various capture methods and offers advanced features for editing and sharing screenshots." Margin="0,0,2,0"/><TextBlock Name="WPFInstallsharexLink" Style="{StaticResource HoverTextBlockStyle}" Text="(?)" ToolTip="https://getsharex.com/" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<CheckBox Name="WPFInstallspotify" Content="Spotify" ToolTip="Spotify is a digital music service that gives you access to millions of songs, podcasts, and videos from artists all over the world." Margin="0,0,2,0"/><TextBlock Name="WPFInstallspotifyLink" Style="{StaticResource HoverTextBlockStyle}" Text="(?)" ToolTip="https://www.spotify.com/" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<CheckBox Name="WPFInstallstrawberry" Content="Strawberry (Music Player)" ToolTip="Strawberry is an open-source music player that focuses on music collection management and audio quality. It supports various audio formats and features a clean user interface." Margin="0,0,2,0"/><TextBlock Name="WPFInstallstrawberryLink" Style="{StaticResource HoverTextBlockStyle}" Text="(?)" ToolTip="https://www.strawberrymusicplayer.org/" />
</StackPanel>
<StackPanel Orientation="Horizontal">
@ -619,6 +622,9 @@
<CheckBox Name="WPFInstallvlc" Content="VLC (Video Player)" ToolTip="VLC Media Player is a free and open-source multimedia player that supports a wide range of audio and video formats. It is known for its versatility and cross-platform compatibility." Margin="0,0,2,0"/><TextBlock Name="WPFInstallvlcLink" Style="{StaticResource HoverTextBlockStyle}" Text="(?)" ToolTip="https://www.videolan.org/vlc/" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<CheckBox Name="WPFInstallvlc" Content="VLC (Video Player)" ToolTip="VLC Media Player is a free and open-source multimedia player that supports a wide range of audio and video formats. It is known for its versatility and cross-platform compatibility." Margin="0,0,2,0"/><TextBlock Name="WPFInstallvlcLink" Style="{StaticResource HoverTextBlockStyle}" Text="(?)" ToolTip="https://www.videolan.org/vlc/" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<CheckBox Name="WPFInstallvoicemeeter" Content="Voicemeeter (Audio)" ToolTip="Voicemeeter is a virtual audio mixer that allows you to manage and enhance audio streams on your computer. It is commonly used for audio recording and streaming purposes." Margin="0,0,2,0"/><TextBlock Name="WPFInstallvoicemeeterLink" Style="{StaticResource HoverTextBlockStyle}" Text="(?)" ToolTip="https://www.vb-audio.com/Voicemeeter/" />
</StackPanel>
<StackPanel Orientation="Horizontal">
@ -847,6 +853,12 @@
<Border Grid.Row="1" Grid.Column="4">
<StackPanel Background="{MainBackgroundColor}" SnapsToDevicePixels="True">
<StackPanel Orientation="Horizontal">
<CheckBox Name="WPFInstalllivelywallpaper" Content="Lively Wallpaper" ToolTip="Free and open-source software that allows users to set animated desktop wallpapers and screensavers." Margin="0,0,2,0"/><TextBlock Name="WPFInstalllivelywallpaperLink" Style="{StaticResource HoverTextBlockStyle}" Text="(?)" ToolTip="https://www.rocksdanister.com/lively/" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<CheckBox Name="WPFInstalllocalsend" Content="LocalSend" ToolTip="An open source cross-platform alternative to AirDrop." Margin="0,0,2,0"/><TextBlock Name="WPFInstalllocalsendLink" Style="{StaticResource HoverTextBlockStyle}" Text="(?)" ToolTip="https://localsend.org/" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<CheckBox Name="WPFInstalllockhunter" Content="LockHunter" ToolTip="LockHunter is a free tool to delete files blocked by something you do not know." Margin="0,0,2,0"/><TextBlock Name="WPFInstalllockhunterLink" Style="{StaticResource HoverTextBlockStyle}" Text="(?)" ToolTip="https://lockhunter.com/" />
</StackPanel>
<StackPanel Orientation="Horizontal">