From 11f1bda8f3466c2a06a9d527ded43e2c8f44a2ad Mon Sep 17 00:00:00 2001 From: Tunisiano18 Date: Fri, 20 Sep 2024 09:44:05 +0200 Subject: [PATCH] (WinPCap) Update for AHK V2 to work --- .../winpcap/tools/chocolateyInstall.ps1 | 31 +++++---- .../winpcap/tools/chocolateyUninstall.ps1 | 22 ------- .../packages/winpcap/tools/winpcapInstall.ahk | 63 +++++++------------ 3 files changed, 37 insertions(+), 79 deletions(-) delete mode 100644 deprecated/packages/winpcap/tools/chocolateyUninstall.ps1 diff --git a/deprecated/packages/winpcap/tools/chocolateyInstall.ps1 b/deprecated/packages/winpcap/tools/chocolateyInstall.ps1 index 9796d111407..28ac0685c1e 100644 --- a/deprecated/packages/winpcap/tools/chocolateyInstall.ps1 +++ b/deprecated/packages/winpcap/tools/chocolateyInstall.ps1 @@ -1,20 +1,17 @@ $ErrorActionPreference = 'Stop' +$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" +$url = "$toolsDir\WinPcap_4_1_3.exe" +$ahkExe = 'AutoHotKey' +$ahkFile = "$toolsDir\winpcapInstall.ahk" -$toolsPath = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" -$file = "$toolsPath\WinPcap_4_1_3.exe" +$packageArgs = @{ + packageName = $packageName + fileType = 'EXE' + file = $url + silentArgs = '/S' + softwareName = "Winpcap" + } -Write-Output "Running Autohotkey installer" -$ahkScript = "$toolsPath\winpcapInstall.ahk" - -# program cannot install properly on top of itself -# so if already installed (running choco install winpap --force) -# we first remove it -$softwareNamePattern = 'WinPcap*' -[array] $key = Get-UninstallRegistryKey $softwareNamePattern -if ($key.Count -eq 1) { - $key | ForEach-Object { - AutoHotkey $ahkScript uninstall $_.UninstallString - } -} - -AutoHotkey $ahkScript install $file +Start-Process $ahkExe $ahkFile +Install-ChocolateyInstallPackage @packageArgs +Remove-Item $url -Force -ErrorAction SilentlyContinue | Out-Null diff --git a/deprecated/packages/winpcap/tools/chocolateyUninstall.ps1 b/deprecated/packages/winpcap/tools/chocolateyUninstall.ps1 deleted file mode 100644 index 1df94b3a2d3..00000000000 --- a/deprecated/packages/winpcap/tools/chocolateyUninstall.ps1 +++ /dev/null @@ -1,22 +0,0 @@ -$ErrorActionPreference = 'Stop' - -$softwareNamePattern = 'WinPcap*' - -[array] $key = Get-UninstallRegistryKey $softwareNamePattern -if ($key.Count -eq 1) { - $key | ForEach-Object { - Write-Output "Running Autohotkey uninstaller" - $toolsPath = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" - $ahkScript = "$toolsPath\winpcapInstall.ahk" - AutoHotkey $ahkScript uninstall $_.UninstallString - } -} -elseif ($key.Count -eq 0) { - Write-Warning "$env:ChocolateyPackageName has already been uninstalled by other means." -} -elseif ($key.Count -gt 1) { - Write-Warning "$($key.Count) matches found!" - Write-Warning "To prevent accidental data loss, no programs will be uninstalled." - Write-Warning "Please alert package maintainer the following keys were matched:" - $key | ForEach-Object {Write-Warning "- $($_.DisplayName)"} -} diff --git a/deprecated/packages/winpcap/tools/winpcapInstall.ahk b/deprecated/packages/winpcap/tools/winpcapInstall.ahk index b1d8822c5d0..4f0d5d39325 100644 --- a/deprecated/packages/winpcap/tools/winpcapInstall.ahk +++ b/deprecated/packages/winpcap/tools/winpcapInstall.ahk @@ -1,45 +1,28 @@ -#Requires AutoHotkey v2.0 -; #Warn ; Enable warnings to assist with detecting common errors. -SetWorkingDir(A_ScriptDir) ; Ensures a consistent starting directory. -SetTitleMatchMode("RegEx") +SendMode "Input" ; Recommended for new scripts due to its superior speed and reliability. -if (A_Args.Length < 2) { - MsgBox("Too few arguments given: " . A_Args[1]) - exit -} +WinWait("WinPcap",, 30) -hitEnter() { - BlockInput "On" - Sleep 250 - WinActivate - Send "{Enter}" - BlockInput "Off" - return -} +BlockInput "On" +Sleep 250 +WinActivate +Send "{Enter}" +BlockInput "Off" -run_cmd_enter(title_string, loops, check_string := "") { - WinWait(title_string, check_string, 30) - Loop loops { - hitEnter - } - return -} +BlockInput "On" +Sleep 250 +WinActivate +Send "{Enter}" +BlockInput "Off" -operation := A_Args[1] -runfile := A_Args[2] +BlockInput "On" +Sleep 250 +WinActivate +Send "{Enter}" +BlockInput "Off" -Run runfile -switch operation { - case "uninstall": - uninstallTitle := "WinPcap [\d\.]+ Uninstall" - run_cmd_enter(uninstallTitle, 1) - run_cmd_enter(uninstallTitle, 1, "has been uninstalled") - case "install": - installTitle := "WinPcap [\d\.]+ Setup" - run_cmd_enter(installTitle, 3) - run_cmd_enter(installTitle, 1, "has been installed") - default: - MsgBox("Unsupported operation: " . operation) - exit -} -ExitApp +WinWait("WinPcap", "has been installed", 30) +BlockInput "On" +Sleep 250 +WinActivate +Send "{Enter}" +BlockInput "Off" \ No newline at end of file