diff --git a/dist/DiscordLyrics-Installer.exe b/dist/DiscordLyrics-Installer.exe index aa10576..e9e1def 100644 Binary files a/dist/DiscordLyrics-Installer.exe and b/dist/DiscordLyrics-Installer.exe differ diff --git a/dist/DiscordLyrics-Installer.ps1 b/dist/DiscordLyrics-Installer.ps1 index 3e00147..10cc804 100644 --- a/dist/DiscordLyrics-Installer.ps1 +++ b/dist/DiscordLyrics-Installer.ps1 @@ -86,14 +86,10 @@ function Invoke-CheckedCommand { [string[]]$Arguments ) - $PreviousErrorActionPreference = $ErrorActionPreference - $ErrorActionPreference = "Continue" - try { - $Output = & $Command @Arguments 2>&1 - $ExitCode = $LASTEXITCODE - } finally { - $ErrorActionPreference = $PreviousErrorActionPreference - } + $ResolvedCommand = Resolve-NativeCommand -Command $Command + $CommandLine = Join-CommandLine -Command $ResolvedCommand -Arguments $Arguments + $Output = & cmd.exe /d /s /c $CommandLine 2>&1 + $ExitCode = $LASTEXITCODE $Text = ($Output | ForEach-Object { "$_" }) -join [Environment]::NewLine if ($Text) { @@ -109,6 +105,56 @@ function Invoke-CheckedCommand { } } +function Resolve-NativeCommand { + param( + [Parameter(Mandatory = $true)] + [string]$Command + ) + + $LookupNames = @($Command) + if ([System.IO.Path]::GetExtension($Command) -eq "") { + $LookupNames = @("$Command.cmd", "$Command.exe", "$Command.bat", $Command) + } + + foreach ($Name in $LookupNames) { + $Found = Get-Command $Name -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1 + if ($Found) { + return $Found.Source + } + } + + return $Command +} + +function Join-CommandLine { + param( + [Parameter(Mandatory = $true)] + [string]$Command, + [string[]]$Arguments = @() + ) + + $Parts = @($Command) + $Arguments + return ($Parts | ForEach-Object { ConvertTo-CommandArgument $_ }) -join " " +} + +function ConvertTo-CommandArgument { + param( + [AllowNull()] + [string]$Value + ) + + if ($null -eq $Value) { + return '""' + } + + $Text = [string]$Value + if ($Text -notmatch '[\s"]') { + return $Text + } + + return '"' + ($Text -replace '"', '\"') + '"' +} + function Download-File { param( [Parameter(Mandatory = $true)] diff --git a/dist/DiscordLyrics-release.zip b/dist/DiscordLyrics-release.zip index e764c98..62bc519 100644 Binary files a/dist/DiscordLyrics-release.zip and b/dist/DiscordLyrics-release.zip differ diff --git a/scripts/DiscordLyrics-Installer.ps1 b/scripts/DiscordLyrics-Installer.ps1 index 3e00147..10cc804 100644 --- a/scripts/DiscordLyrics-Installer.ps1 +++ b/scripts/DiscordLyrics-Installer.ps1 @@ -86,14 +86,10 @@ function Invoke-CheckedCommand { [string[]]$Arguments ) - $PreviousErrorActionPreference = $ErrorActionPreference - $ErrorActionPreference = "Continue" - try { - $Output = & $Command @Arguments 2>&1 - $ExitCode = $LASTEXITCODE - } finally { - $ErrorActionPreference = $PreviousErrorActionPreference - } + $ResolvedCommand = Resolve-NativeCommand -Command $Command + $CommandLine = Join-CommandLine -Command $ResolvedCommand -Arguments $Arguments + $Output = & cmd.exe /d /s /c $CommandLine 2>&1 + $ExitCode = $LASTEXITCODE $Text = ($Output | ForEach-Object { "$_" }) -join [Environment]::NewLine if ($Text) { @@ -109,6 +105,56 @@ function Invoke-CheckedCommand { } } +function Resolve-NativeCommand { + param( + [Parameter(Mandatory = $true)] + [string]$Command + ) + + $LookupNames = @($Command) + if ([System.IO.Path]::GetExtension($Command) -eq "") { + $LookupNames = @("$Command.cmd", "$Command.exe", "$Command.bat", $Command) + } + + foreach ($Name in $LookupNames) { + $Found = Get-Command $Name -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1 + if ($Found) { + return $Found.Source + } + } + + return $Command +} + +function Join-CommandLine { + param( + [Parameter(Mandatory = $true)] + [string]$Command, + [string[]]$Arguments = @() + ) + + $Parts = @($Command) + $Arguments + return ($Parts | ForEach-Object { ConvertTo-CommandArgument $_ }) -join " " +} + +function ConvertTo-CommandArgument { + param( + [AllowNull()] + [string]$Value + ) + + if ($null -eq $Value) { + return '""' + } + + $Text = [string]$Value + if ($Text -notmatch '[\s"]') { + return $Text + } + + return '"' + ($Text -replace '"', '\"') + '"' +} + function Download-File { param( [Parameter(Mandatory = $true)]