forked from ScoopInstaller/Scoop
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scoop-reset.ps1
90 lines (72 loc) · 2.59 KB
/
scoop-reset.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Usage: scoop reset <app>
# Summary: Reset an app to resolve conflicts
# Help: Used to resolve conflicts in favor of a particular app. For example,
# if you've installed 'python' and 'python27', you can use 'scoop reset' to switch between
# using one or the other.
. "$PSScriptRoot\..\lib\core.ps1"
. "$PSScriptRoot\..\lib\manifest.ps1"
. "$PSScriptRoot\..\lib\help.ps1"
. "$PSScriptRoot\..\lib\getopt.ps1"
. "$PSScriptRoot\..\lib\install.ps1"
. "$PSScriptRoot\..\lib\versions.ps1"
. "$PSScriptRoot\..\lib\shortcuts.ps1"
reset_aliases
$opt, $apps, $err = getopt $args
if($err) { "scoop reset: $err"; exit 1 }
if(!$apps) { error '<app> missing'; my_usage; exit 1 }
if($apps -eq '*') {
$local = installed_apps $false | ForEach-Object { ,@($_, $false) }
$global = installed_apps $true | ForEach-Object { ,@($_, $true) }
$apps = @($local) + @($global)
}
$apps | ForEach-Object {
($app, $global) = $_
$app, $bucket, $version = parse_app $app
if(($global -eq $null) -and (installed $app $true)) {
# set global flag when running reset command on specific app
$global = $true
}
if($app -eq 'scoop') {
# skip scoop
return
}
if(!(installed $app)) {
error "'$app' isn't installed"
return
}
if ($null -eq $version) {
$version = Select-CurrentVersion -AppName $app -Global:$global
}
$manifest = installed_manifest $app $version $global
# if this is null we know the version they're resetting to
# is not installed
if ($manifest -eq $null) {
error "'$app ($version)' isn't installed"
return
}
if($global -and !(is_admin)) {
warn "'$app' ($version) is a global app. You need admin rights to reset it. Skipping."
return
}
write-host "Resetting $app ($version)."
$dir = resolve-path (versiondir $app $version $global)
$original_dir = $dir
$persist_dir = persistdir $app $global
#region Workaround for #2952
if (test_running_process $app $global) {
continue
}
#endregion Workaround for #2952
$install = install_info $app $version $global
$architecture = $install.architecture
$dir = link_current $dir
create_shims $manifest $dir $global $architecture
create_startmenu_shortcuts $manifest $dir $global $architecture
env_add_path $manifest $dir $global $architecture
env_set $manifest $dir $global $architecture
# unlink all potential old link before re-persisting
unlink_persist_data $manifest $original_dir
persist_data $manifest $original_dir $persist_dir
persist_permission $manifest $global
}
exit 0