Skip to content

Commit

Permalink
fix(install): fix uninstall bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
psoukie committed Feb 1, 2023
1 parent ac81645 commit 1b7adf1
Showing 1 changed file with 64 additions and 30 deletions.
94 changes: 64 additions & 30 deletions source/uninstall.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,85 @@ See the LICENSE file in the root folder for details.
*/

full_command_line := DllCall("GetCommandLine", "str")

uninstall := New clsUninstall

Return

class clsUninstall {
__New() {
MsgBox , 1, % "Uninstall ZipChord", % "This will uninstall ZipChord. Dictionaries and other files you have created will stay untouched."
global full_command_line
if (RegExMatch(full_command_line, " /restart(?!\S)")) {
this._Unintstall()
}
MsgBox , 1, % "Uninstall ZipChord", % "This will uninstall ZipChord.`n`nDictionaries and other files you have created will stay untouched."
IfMsgBox Cancel
return
ExitApp
SetWorkingDir, % A_Temp
Process, Close, % "zipchord.exe"
this.CreateUninstallScript(2000)
this._DeleteRegistry()
this._CheckAdmin()
this._RunUninstallScript()
}
_Unintstall() {
Process, Close, % "zipchord.exe"
FileDelete, % A_ScriptDir . "\locales.ini"
FileDelete, % A_ScriptDir . "\LICENSE.txt"
FileDelete, % A_ScriptDir . "\zipchord.exe"
FileDelete, % A_ScriptDir . "\uninstall.exe"
FileDelete, % A_Startup . "\ZipChord.lnk"
SetWorkingDir, % A_Temp
this._RunUninstallScript()
}
_DeleteRegistry() {
RegDelete, % "HKEY_CURRENT_USER\Software\ZipChord"
RegDelete, % "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\ZipChord"
this.Destruct(3000)
}
Destruct(delay) {
_CheckAdmin() {
if (A_ScriptDir == A_ProgramFiles . "\ZipChord" && !A_IsAdmin) {
MsgBox , 1, % "Uninstall ZipChord", % "To remove ZipChord from Program Files, you will need to provide Admin access on the next screen."
IfMsgBox Cancel
ExitApp
try
{
if A_IsCompiled
Run *RunAs "%A_ScriptFullPath%" /restart, % A_Temp
else
Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%", % A_Temp
}
return true
}
}
CreateUninstallScript(delay) {
app_data_folder := % A_AppData . "\ZipChord"
programs_folder := % A_Programs . "\ZipChord"
FileDelete, % A_Temp . "\deleteself.vbs"
FileDelete, % A_Temp . "\ZC_uninstall.vbs"
; Adapts code by cooljeans and SKAN from https://www.autohotkey.com/board/topic/1488-make-exe-file-delete-itself/
FileAppend,
(
Wscript.Sleep %delay%
Dim fso, MyFile, ZCfolder
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.GetFile("%A_ScriptFullPath%")
MyFile.Delete
If fso.FolderExists("%A_ScriptDir%") Then
Set ZCfolder = fso.GetFolder("%A_ScriptDir%")
If ZCfolder.Files.Count = 0 And ZCfolder.SubFolders.Count = 0 Then ZCfolder.Delete(true)
End If
If fso.FolderExists("%programs_folder%") Then
Set ZCfolder = fso.GetFolder("%programs_folder%")
If ZCfolder Then ZCfolder.Delete(true)
End If
fso.DeleteFile WScript.ScriptFullName
MsgBox("Uninstallation of ZipChord was completed.")
Set fso = Nothing
)
, % A_Temp . "\deleteself.vbs"
Run, % A_Temp . "\deleteself.vbs"
(LTrim
Wscript.Sleep %delay%
Dim fso, myfile, files, myfolder, folders
Set fso = CreateObject("Scripting.FileSystemObject")
files = Array("%A_ScriptFullPath%", "%app_data_folder%\locales.ini", "%app_data_folder%\LICENSE.txt", "%A_ScriptDir%\zipchord.exe", "%A_ScriptDir%\zipchord.ico", "%A_Startup%\ZipChord.lnk")
For each file in files
If fso.FileExists(file) Then
Set myfile = fso.GetFile(file)
myfile.Delete(true)
End If
Next
folders = Array("%A_ScriptDir%", "%app_data_folder%", "%programs_folder%")
For each folder in folders
If fso.FolderExists(folder) Then
Set myfolder = fso.GetFolder(folder)
End If
If (myfolder = "%programs_folder%") Or (myfolder.Files.Count = 0 And myfolder.SubFolders.Count = 0) Then
myfolder.Delete(true)
End If
Next
fso.DeleteFile WScript.ScriptFullName
Set fso = Nothing
)
, % A_Temp . "\ZC_uninstall.vbs"
}
_RunUninstallScript() {
Run, % "cscript.exe " . A_InitialWorkingDir . "\ZC_uninstall.vbs"
ExitApp
programs_folder := programs_folder ; to bypass syntax warning
}
Expand Down

0 comments on commit 1b7adf1

Please sign in to comment.