Skip to content

Commit 120fbd3

Browse files
Clean up old files within installers
1 parent 28b26bd commit 120fbd3

File tree

3 files changed

+40
-17
lines changed

3 files changed

+40
-17
lines changed

Lib/Launchpad/Installer/DependencyInstaller.ahk

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,22 @@ class DependencyInstaller extends InstallerBase {
22
name := "Dependency Installer"
33

44
__New(version, appState, cache, extraComponents := "", tmpDir := "") {
5+
; TODO: Remove dependency on A_ScriptDir
6+
installDir := A_ScriptDir
57
components := []
6-
dbVersion := "1.0.2"
8+
cleanupFiles := []
79

810
ahkUrl := "https://www.autohotkey.com/download/2.0/AutoHotkey_" . A_AhkVersion . ".zip"
911
components.Push(DownloadableInstallerComponent(A_AhkVersion, ahkUrl, true, "Vendor\AutoHotKey", appState, "AutoHotKey", cache, "Dependencies", true, tmpDir, false))
10-
11-
;mpressUrl := "https://github.com/bmcclure/launcher-db/releases/download/" . dbVersion . "/mpress.exe"
12-
;mpressPath := "Vendor\AutoHotKey\Compiler\mpress.exe"
13-
;mpressComponent := DownloadableInstallerComponent(dbVersion, mpressUrl, false, mpressPath, appState, "Mpress", cache, "AutoHotKey", true, tmpDir, false)
14-
;components.Push(mpressComponent)
15-
16-
;ahk2ExeUrl := "https://github.com/bmcclure/launcher-db/releases/download/" . dbVersion . "/Ahk2Exe.exe"
17-
;ahk2ExePath := "Vendor\AutoHotKey\Compiler\Ahk2Exe.exe"
18-
;ahk2ExeComponent := DownloadableInstallerComponent(dbVersion, ahk2ExeUrl, false, ahk2ExePath, appState, "Ahk2Exe", cache, "AutoHotKey", true, tmpDir, false)
19-
;components.Push(ahk2ExeComponent)
20-
21-
; TODO: Remove dependency on A_ScriptDir
22-
ahkBins := A_ScriptDir . "\Resources\Dependencies\AHkBins.zip"
23-
dest := A_ScriptDir . "\Vendor\AutoHotKey\Compiler"
12+
13+
ahkDir := installDir . "\Vendor\AutoHotKey"
14+
cleanupFiles.Push(ahkDir . "\AutoHotKeyU32.exe")
15+
cleanupFiles.Push(ahkDir . "\AutoHotKeyU64.exe")
16+
cleanupFiles.Push(ahkDir . "\Compiler\Unicode 32-bit.bin")
17+
cleanupFiles.Push(ahkDir . "\Compiler\Unicode 64-bit.bin")
18+
19+
ahkBins := installDir . "\Resources\Dependencies\AHkBins.zip"
20+
dest := ahkDir . "\Compiler"
2421
ahkBinsComponent := CopyableInstallerComponent(A_AhkVersion, ahkBins, true, dest, appState, "AhkBins", cache, "Dependencies", true, tmpDir, false, "Ahk2Exe.exe")
2522
components.Push(ahkBinsComponent)
2623

@@ -38,6 +35,6 @@ class DependencyInstaller extends InstallerBase {
3835
}
3936
}
4037

41-
super.__New(version, appState, "Dependencies", cache, components, tmpDir := "")
38+
super.__New(version, appState, "Dependencies", cache, components, tmpDir, cleanupFiles)
4239
}
4340
}

Lib/Shared/AppLib/Installer/InstallerBase.ahk

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class InstallerBase {
1313
tmpDir := ""
1414
parentComponent := ""
1515

16-
__New(version, appState, stateKey, cache, components := "", tmpDir := "") {
16+
__New(version, appState, stateKey, cache, components := "", tmpDir := "", cleanupFiles := "") {
1717
this.cache := cache
1818
this.version := version
1919
this.appState := appState
@@ -22,6 +22,12 @@ class InstallerBase {
2222
this.scriptFile := scriptFile
2323
this.scriptDir := scriptDir
2424

25+
if (Type(cleanupFiles) != "Array") {
26+
cleanupFiles := [cleanupFiles]
27+
}
28+
29+
this.cleanupFiles := cleanupFiles
30+
2531
if (tmpDir == "") {
2632
tmpDir := A_Temp . "\Launchpad\Installers"
2733
}
@@ -85,6 +91,12 @@ class InstallerBase {
8591
}
8692
}
8793

94+
for index, cleanupFile in this.cleanupFiles {
95+
if (FileExist(cleanupFile)) {
96+
FileDelete(cleanupFile)
97+
}
98+
}
99+
88100
this.appState.SetComponentInstalled(this.stateKey, success)
89101

90102
return success

Lib/Shared/AppLib/Installer/InstallerComponent/InstallerComponentBase.ahk

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ class InstallerComponentBase {
5353
throw MethodNotImplementedException("InstallerComponentBase", "UninstallAction")
5454
}
5555

56+
CleanupPreviousVersionsAction() {
57+
return true ; Cleanup is optional
58+
}
59+
5660
/**
5761
* IMPLEMENTED METHODS
5862
*/
@@ -72,13 +76,23 @@ class InstallerComponentBase {
7276
return true
7377
}
7478

79+
this.CleanupPreviousVersionsAction()
7580
this.InstallAction()
7681

7782
this.appState.SetVersion(this.stateKey, this.version)
7883
this.appState.SetComponentInstalled(this.stateKey, true)
7984
return true
8085
}
8186

87+
CleanupPreviousVersions() {
88+
if (this.onlyCompiled && !A_IsCompiled) {
89+
return true
90+
}
91+
92+
this.CleanupPreviousVersionsAction()
93+
return true
94+
}
95+
8296
Uninstall() {
8397
if (this.onlyCompiled && !A_IsCompiled) {
8498
return true

0 commit comments

Comments
 (0)