Skip to content

Commit

Permalink
Merge pull request #2308 from brogers5/opera/ahk-uninstall
Browse files Browse the repository at this point in the history
  • Loading branch information
AdmiringWorm authored Oct 3, 2023
2 parents cd37618 + 1526a54 commit 5aeea3a
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 1 deletion.
1 change: 1 addition & 0 deletions automatic/opera/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The Opera web browser makes the Web fast and fun, giving you a better web browse
- `/NoAutostart` - Do not add Opera autostart entry
- `/NoDesktopShortcut` - Do not create desktop shortcut for Opera
- `/NoTaskbarShortcut` - Do not pin Opera to taskbar
- `/RemoveUserData` - Remove Opera's user data during uninstallation.

These parameters can be passed to the installer with the use of `--params`.
For example: `--params '"/NoAutostart /NoDesktopShortcut /NoTaskbarShortcut"'`
Expand Down
4 changes: 4 additions & 0 deletions automatic/opera/opera.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ For example: `--params '"/NoAutostart /NoDesktopShortcut /NoTaskbarShortcut"'`
<releaseNotes>https://blogs.opera.com/desktop/changelog-for-102/#b4880.78</releaseNotes>
<tags>browser opera cross-platform internet admin</tags>
<packageSourceUrl>https://github.com/chocolatey-community/chocolatey-packages/tree/master/automatic/opera</packageSourceUrl>
<dependencies>
<dependency id="chocolatey-core.extension" version="1.4.0" />
<dependency id="autohotkey.portable" version="2.0.0" />
</dependencies>
</metadata>
<files>
<file src="tools\**" target="tools" />
Expand Down
17 changes: 16 additions & 1 deletion automatic/opera/tools/chocolateyUninstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,32 @@

$packageName = $env:chocolateyPackageName
$softwareNamePattern = 'Opera*'
$toolsDir = "$(Split-Path -Parent $MyInvocation.MyCommand.Definition)"

[array] $key = Get-UninstallRegistryKey $softwareNamePattern
if ($key.Count -eq 1) {
$key | ForEach-Object {
$packageArgs = @{
packageName = $packageName
silentArgs = "/uninstall /silent"
silentArgs = "/uninstall"
fileType = 'EXE'
validExitCodes = @(0)
file = $_.UninstallString.replace(' /uninstall', '').trim('"')
}

$installLocation = Get-AppInstallLocation -AppNamePattern $softwareNamePattern
if ($null -ne $installLocation) {
Remove-Process -PathFilter "$([regex]::Escape($installLocation)).*" | Out-Null
}

$pp = Get-PackageParameters
$ahkArgList = New-Object Collections.Generic.List[string]
$ahkArgList.Add($(Join-Path -Path $toolsDir -ChildPath 'uninstall.ahk'))
if ($pp.RemoveUserData) {
$ahkArgList.Add('/RemoveUserData')
}

Start-Process -FilePath 'AutoHotKey.exe' -ArgumentList $ahkArgList
Uninstall-ChocolateyPackage @packageArgs
}
}
Expand Down
67 changes: 67 additions & 0 deletions automatic/opera/tools/uninstall.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#Requires AutoHotkey v2.0
#NoTrayIcon
#SingleInstance Force
#Warn
DetectHiddenText "Off"
DetectHiddenWindows "Off"
SetControlDelay 20
SendMode "Input"
SetTitleMatchMode 3 ;Exact
SetWinDelay 100

ShouldRemoveUserData := False
for i, param in A_Args
{
if (!StrCompare("/RemoveUserData", param))
{
ShouldRemoveUserData := True
break
}
}

UninstallerProcessName := "installer.exe"
MainWindowClass := "InstallerMainWindow"
MainWindowTitle := "ahk_class " MainWindowClass " ahk_exe " UninstallerProcessName
WinWait MainWindowTitle

if (ShouldRemoveUserData)
{
RemoveUserDataCheckbox := "Button12"
;For some reason, neither ControlClick nor ControlSetChecked will tick the checkbox
ControlSend "{Space}", RemoveUserDataCheckbox, MainWindowTitle
}

UninstallButton := "Button3"
;This window's buttons may not work reliably with ControlClick if mouse-up events are delayed.
;Send spaces with ControlSend instead for increased reliability.
ControlSend "{Space}", UninstallButton, MainWindowTitle

;If the user has launched Opera at least once, a survey page may show up.
Sleep 200
FirstRadioButton := "Button13" ;The positioning of each option is randomized and may vary
SurveyPageVisible := ControlGetVisible(FirstRadioButton, MainWindowTitle)
if (SurveyPageVisible) {
;Skip over the survey
ControlSend "{Space}", UninstallButton, MainWindowTitle
}

DialogWindowClass := "#32770"
DialogWindowTitle := "ahk_class " DialogWindowClass " ahk_exe " UninstallerProcessName
WinWait DialogWindowTitle

YesButton := "Button1"
ControlClick YesButton, DialogWindowTitle,,,, "NA"

TryAgainButton := "Button6"
while !WinWaitClose(MainWindowTitle,, 1) {
try {
TryAgainButtonVisible := ControlGetVisible(TryAgainButton, MainWindowTitle)
if (TryAgainButtonVisible) {
;Allow the user an opportunity to see the uninstaller has failed, then try again
Sleep 2000
ControlSend "{Space}", TryAgainButton, MainWindowTitle
}
}
}

ExitApp

0 comments on commit 5aeea3a

Please sign in to comment.