Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(shortcuts): find target in dir and Path #6244

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- **commands**: Handling broken aliases ([#6141](https://github.com/ScoopInstaller/Scoop/issues/6141))
- **shim:** Do not suppress `stderr`, properly check `wslpath`/`cygpath` command first ([#6114](https://github.com/ScoopInstaller/Scoop/issues/6114))
- **scoop-bucket:** Add missing import for `no_junction` envs ([#6181](https://github.com/ScoopInstaller/Scoop/issues/6181))
- **shortcuts**: Add target match in Path and correctly set working directory ([#6243](https://github.com/ScoopInstaller/Scoop/issues/6243))

### Code Refactoring

Expand Down
20 changes: 15 additions & 5 deletions lib/shortcuts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@
function create_startmenu_shortcuts($manifest, $dir, $global, $arch) {
$shortcuts = @(arch_specific 'shortcuts' $manifest $arch)
$shortcuts | Where-Object { $_ -ne $null } | ForEach-Object {
$target = [System.IO.Path]::Combine($dir, $_.item(0))
$target = New-Object System.IO.FileInfo($target)
$name = $_.item(1)
$executable = $_.item(0)
if (Test-Path "$dir\$executable" -PathType leaf) {
$target = "$dir\$executable"
} elseif (Test-Path $executable -PathType leaf) {
$target = $executable
} else {
$target = (Get-Command $executable).Source
}
if (!$target) {
Write-Host -f DarkRed "Creating shortcut for $shortcutName ($(fname $executable)) failed: Couldn't find $executable"
return
}
$arguments = ''
$icon = $null
if ($_.length -ge 3) {
Expand All @@ -15,7 +25,7 @@ function create_startmenu_shortcuts($manifest, $dir, $global, $arch) {
$icon = New-Object System.IO.FileInfo($icon)
}
$arguments = (substitute $arguments @{ '$dir' = $dir; '$original_dir' = $original_dir; '$persist_dir' = $persist_dir })
startmenu_shortcut $target $name $arguments $icon $global
startmenu_shortcut $target $name $arguments $icon $global $dir
}
}

Expand All @@ -28,7 +38,7 @@ function shortcut_folder($global) {
return Convert-Path (ensure ([System.IO.Path]::Combine([Environment]::GetFolderPath($startmenu), 'Programs', 'Scoop Apps')))
}

function startmenu_shortcut([System.IO.FileInfo] $target, $shortcutName, $arguments, [System.IO.FileInfo]$icon, $global) {
function startmenu_shortcut([System.IO.FileInfo] $target, $shortcutName, $arguments, [System.IO.FileInfo]$icon, $global, $workingdir) {
if (!$target.Exists) {
Write-Host -f DarkRed "Creating shortcut for $shortcutName ($(fname $target)) failed: Couldn't find $target"
return
Expand All @@ -47,7 +57,7 @@ function startmenu_shortcut([System.IO.FileInfo] $target, $shortcutName, $argume
$wsShell = New-Object -ComObject WScript.Shell
$wsShell = $wsShell.CreateShortcut("$scoop_startmenu_folder\$shortcutName.lnk")
$wsShell.TargetPath = $target.FullName
$wsShell.WorkingDirectory = $target.DirectoryName
$wsShell.WorkingDirectory = $workingdir
if ($arguments) {
$wsShell.Arguments = $arguments
}
Expand Down