|
28 | 28 | "Set-Content \"$dir\\install-context.reg\" $reg_content -Encoding ASCII" |
29 | 29 | ], |
30 | 30 | "pre_uninstall": [ |
31 | | - "Stop-Process -Name 'everything' -Force -ErrorAction SilentlyContinue", |
32 | | - "if ($(Get-Service -Name Everything -ErrorAction SilentlyContinue).Status -ne 'Stopped') {", |
33 | | - " if (!(is_admin)) { error 'Admin rights are required to stop Everything service'; break }", |
34 | | - " Stop-Service -Name 'Everything' -Force -ErrorAction SilentlyContinue | Out-Null", |
| 31 | + "$appPathPattern = (Split-Path $dir -Parent).Replace('\\', '\\\\')", |
| 32 | + "", |
| 33 | + "$processes = Get-Process -Name 'everything' -ErrorAction SilentlyContinue", |
| 34 | + " | Where-Object { $_.Path -match $appPathPattern }", |
| 35 | + "info \"Found $($processes.Length) Everything process(es) to stop\"", |
| 36 | + "foreach ($process in $processes) {", |
| 37 | + " Stop-Process -Id $process.Id -Force -ErrorAction SilentlyContinue", |
35 | 38 | "}", |
36 | | - "if ((Get-Service -Name Everything -ErrorAction SilentlyContinue) -and ($cmd -eq 'uninstall')) {", |
37 | | - " if (!(is_admin)) { error 'Admin rights are required to remove Everything service'; break }", |
38 | | - " sc.exe delete 'Everything'", |
| 39 | + "", |
| 40 | + "$services = Get-Service -Name Everything* -ErrorAction SilentlyContinue", |
| 41 | + " | Where-Object { $_.BinaryPathName -match $appPathPattern }", |
| 42 | + "", |
| 43 | + "if ($services.Length -gt 1) {", |
| 44 | + " error 'Multiple Everything services found, this is likely a bug with this manifest.'", |
| 45 | + " break", |
| 46 | + "} elseif ($services.Length -eq 0) {", |
| 47 | + " info 'No Everything service found, continuing with uninstall.'", |
| 48 | + "} else {", |
| 49 | + " $service = $services[0]", |
| 50 | + " $serviceName = $service.Name", |
| 51 | + " info \"Found Everything service: $serviceName\"", |
| 52 | + "", |
| 53 | + " if (!(is_admin)) {", |
| 54 | + " error 'Administrator rights are required to manage Windows services'", |
| 55 | + " break", |
| 56 | + " }", |
| 57 | + "", |
| 58 | + " if ($service.Status -ne 'Stopped') {", |
| 59 | + " info 'Stopping service'", |
| 60 | + " Stop-Service -Name $serviceName -Force | Out-Null", |
| 61 | + " }", |
| 62 | + "", |
| 63 | + " if ($cmd -eq 'uninstall') {", |
| 64 | + " info 'Removing service'", |
| 65 | + " sc.exe delete $serviceName", |
| 66 | + " }", |
39 | 67 | "}", |
| 68 | + "", |
40 | 69 | "if ($cmd -eq 'uninstall') { reg import \"$dir\\uninstall-context.reg\" }", |
| 70 | + "", |
41 | 71 | "Get-ChildItem \"$dir\\*\" -Include 'Bookmarks*.csv', 'Everything.lng', 'Everything*.db', 'Everything*.ini', 'Filters*.csv', 'Plugins*.ini', 'Run History*.csv', 'Search History*.csv' | Copy-Item -Destination \"$persist_dir\" -ErrorAction SilentlyContinue -Force" |
42 | 72 | ], |
43 | 73 | "bin": "Everything.exe", |
|
0 commit comments