|
2 | 2 | function create_startmenu_shortcuts($manifest, $dir, $global, $arch) {
|
3 | 3 | $shortcuts = @(arch_specific 'shortcuts' $manifest $arch)
|
4 | 4 | $shortcuts | ?{ $_ -ne $null } | % {
|
5 |
| - $target = $_.item(0) |
| 5 | + $target = [System.IO.Path]::Combine($dir, $_.item(0)) |
| 6 | + $target = New-Object System.IO.FileInfo($target) |
6 | 7 | $name = $_.item(1)
|
7 |
| - try { |
| 8 | + $arguments = "" |
| 9 | + $icon = $null |
| 10 | + if($_.length -ge 3) { |
8 | 11 | $arguments = $_.item(2)
|
9 |
| - } catch { |
10 |
| - $arguments = "" |
11 | 12 | }
|
12 |
| - startmenu_shortcut "$dir\$target" $name $global $arguments |
| 13 | + if($_.length -ge 4) { |
| 14 | + $icon = [System.IO.Path]::Combine($dir, $_.item(3)) |
| 15 | + $icon = New-Object System.IO.FileInfo($icon) |
| 16 | + } |
| 17 | + startmenu_shortcut $target $name $arguments $icon $global |
13 | 18 | }
|
14 | 19 | }
|
15 | 20 |
|
16 | 21 | function shortcut_folder($global) {
|
| 22 | + $directory = [System.IO.Path]::Combine([Environment]::GetFolderPath('startmenu'), 'Programs', 'Scoop Apps') |
17 | 23 | if($global) {
|
18 |
| - "$([environment]::getfolderpath('commonstartmenu'))\Programs\Scoop Apps" |
19 |
| - return |
| 24 | + $directory = [System.IO.Path]::Combine([Environment]::GetFolderPath('commonstartmenu'), 'Programs', 'Scoop Apps') |
20 | 25 | }
|
21 |
| - "$([environment]::getfolderpath('startmenu'))\Programs\Scoop Apps" |
| 26 | + return $(ensure $directory) |
22 | 27 | }
|
23 | 28 |
|
24 |
| -function startmenu_shortcut($target, $shortcutName, $global, $arguments) { |
25 |
| - if(!(Test-Path $target)) { |
| 29 | +function startmenu_shortcut([System.IO.FileInfo] $target, $shortcutName, $arguments, [System.IO.FileInfo]$icon, $global) { |
| 30 | + if(!$target.Exists) { |
26 | 31 | Write-Host -f DarkRed "Creating shortcut for $shortcutName ($(fname $target)) failed: Couldn't find $target"
|
27 | 32 | return
|
28 | 33 | }
|
29 |
| - $scoop_startmenu_folder = shortcut_folder $global |
30 |
| - if(!(Test-Path $scoop_startmenu_folder)) { |
31 |
| - New-Item $scoop_startmenu_folder -type Directory |
| 34 | + if($icon -and !$icon.Exists) { |
| 35 | + Write-Host -f DarkRed "Creating shortcut for $shortcutName ($(fname $target)) failed: Couldn't find icon $icon" |
| 36 | + return |
32 | 37 | }
|
33 |
| - $dirname = [System.IO.Path]::GetDirectoryName($shortcutName) |
34 |
| - if ($dirname) { |
35 |
| - $dirname = [io.path]::combine($scoop_startmenu_folder, $dirname) |
36 |
| - if(!(Test-Path $dirname)) { |
37 |
| - New-Item $dirname -type Directory |
38 |
| - } |
| 38 | + |
| 39 | + $scoop_startmenu_folder = shortcut_folder $global |
| 40 | + $subdirectory = [System.IO.Path]::GetDirectoryName($shortcutName) |
| 41 | + if ($subdirectory) { |
| 42 | + $subdirectory = ensure $([System.IO.Path]::Combine($scoop_startmenu_folder, $subdirectory)) |
39 | 43 | }
|
| 44 | + |
40 | 45 | $wsShell = New-Object -ComObject WScript.Shell
|
41 | 46 | $wsShell = $wsShell.CreateShortcut("$scoop_startmenu_folder\$shortcutName.lnk")
|
42 |
| - $wsShell.TargetPath = "$target" |
| 47 | + $wsShell.TargetPath = $target.FullName |
| 48 | + $wsShell.WorkingDirectory = $target.DirectoryName |
43 | 49 | if ($arguments) {
|
44 | 50 | $wsShell.Arguments = $arguments
|
45 | 51 | }
|
| 52 | + if($icon -and $icon.Exists) { |
| 53 | + $wsShell.IconLocation = $icon.FullName |
| 54 | + } |
46 | 55 | $wsShell.Save()
|
47 | 56 | write-host "Creating shortcut for $shortcutName ($(fname $target))"
|
48 | 57 | }
|
|
0 commit comments