Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified dist/DiscordLyrics-Installer.exe
Binary file not shown.
62 changes: 54 additions & 8 deletions dist/DiscordLyrics-Installer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)]
Expand Down
Binary file modified dist/DiscordLyrics-release.zip
Binary file not shown.
62 changes: 54 additions & 8 deletions scripts/DiscordLyrics-Installer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)]
Expand Down
Loading