Skip to content

Commit d2fbd30

Browse files
Fix launcher generation issues
1 parent f1e1f90 commit d2fbd30

File tree

9 files changed

+89
-49
lines changed

9 files changed

+89
-49
lines changed

LauncherLib/Launcher/Launcher.ahk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Launcher {
1919
this.game := game
2020

2121
if (!options.hasKey("runThenWait")) {
22-
options.runThenWait := true
22+
options.runThenWait := false
2323
}
2424

2525
this.options := options

Lib/BuildFile/BuildFile.ahk

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class BuildFile {
1717
}
1818
}
1919

20-
__New(app, config, launcherDir, key, extension, filePath := "", autoBuild := true) {
20+
__New(app, config, launcherDir, key, extension, filePath := "") {
2121
this.app := app
2222
this.appDir := app.AppConfig.AppDir
2323
this.tempDir := app.tempDir . "\BuildFiles\" . key
@@ -30,16 +30,14 @@ class BuildFile {
3030
if (this.FilePath == "") {
3131
this.FilePath := this.launcherDir . "\" . this.key . this.extension
3232
}
33-
34-
if (autoBuild) {
35-
this.Build()
36-
}
3733
}
3834

3935
Build() {
36+
return this.FilePath
4037
}
4138

4239
Cleanup() {
40+
return true
4341
}
4442

4543
Delete() {

Lib/BuildFile/ComposableBuildFile.ahk

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ class ComposableBuildFile extends BuildFile {
22
Build() {
33
base.Build()
44
this.Delete()
5-
this.ComposeFile()
5+
result := this.ComposeFile()
66
this.Cleanup()
7+
8+
return result
79
}
810

911
ComposeFile() {
10-
12+
return this.FilePath
1113
}
1214
}

Lib/BuildFile/CopyableBuildFile.ahk

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,24 @@ class CopyableBuildFile extends BuildFile {
3030
}
3131
}
3232

33-
__New(app, config, launcherDir, key, extension, filePath := "", autoBuild := true, sourcePath := "") {
33+
__New(app, config, launcherDir, key, extension, filePath := "", sourcePath := "") {
3434
this.sourcePathValue := sourcePath
35-
base.__New(app, config, launcherDir, key, extension, filePath, autoBuild)
35+
base.__New(app, config, launcherDir, key, extension, filePath)
3636
}
3737

3838
Build() {
3939
base.Build()
40-
4140
path := this.Locate()
41+
result := path
4242

4343
if (path != "" && path != this.FilePath) {
4444
this.SourcePath := path
45-
this.Copy()
45+
result := this.Copy()
4646
}
4747

4848
this.Cleanup()
49+
50+
return result
4951
}
5052

5153
Locate() {
@@ -66,16 +68,21 @@ class CopyableBuildFile extends BuildFile {
6668
FileSelectFile, file, 1,, % this.key . ": " . this.RequestMessage, % this.SelectFilter
6769

6870
if (file == "") {
69-
MsgBox, "No file selected."
70-
ExitApp, -1
71+
MsgBox, "No file selected. Skipping build file. This might cause the entire launcher to be skipped."
7172
}
7273

7374
return file
7475
}
7576

7677
Copy() {
77-
if (this.FilePath != "" and this.SourcePath != "" and this.SourcePath != this.FilePath) {
78+
if (this.FilePath == "" || this.SourcePath == "") {
79+
return false
80+
}
81+
82+
if (this.SourcePath != this.FilePath) {
7883
FileCopy, % this.SourcePath, % this.FilePath, true
7984
}
85+
86+
return this.FilePath
8087
}
8188
}

Lib/BuildFile/GameAhkFile.ahk

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class GameAhkFile extends ComposableBuildFile {
2-
__New(app, config, launcherDir, key, filePath := "", autoBuild := true) {
3-
base.__New(app, config, launcherDir, key, ".ahk", filePath, autoBuild)
2+
__New(app, config, launcherDir, key, filePath := "") {
3+
base.__New(app, config, launcherDir, key, ".ahk", filePath)
44
}
55

66
ComposeFile() {
@@ -13,6 +13,8 @@ class GameAhkFile extends ComposableBuildFile {
1313
FileAppend, % "gameObj := new " . this.config.gameClass . "(""" . this.appDir . """, """ . this.key . """, """ . this.config.gameType . """, config)`n", % this.FilePath
1414
FileAppend, % "launcherObj := new " . this.config.launcherClass . "(""" . this.appDir . """, """ . this.key . """, """ . this.config.launcherType . """, gameObj, config)`n", % this.FilePath
1515
FileAppend, % "launcherObj.LaunchGame()`n", % this.FilePath
16+
17+
return this.FilePath
1618
}
1719

1820
ConvertObjectToCode(typeConfig) {

Lib/BuildFile/GameExeFile.ahk

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
class GameExeFile extends ComposableBuildFile {
2-
__New(app, config, launcherDir, key, filePath := "", autoBuild := true) {
3-
base.__New(app, config, launcherDir, key, ".exe", filePath, autoBuild)
2+
__New(app, config, launcherDir, key, filePath := "") {
3+
base.__New(app, config, launcherDir, key, ".exe", filePath)
44
}
55

66
ComposeFile() {
77
assetsDir := this.app.AppConfig.AssetsDir . "\" . this.key
88

99
exePath := this.FilePath
1010
iconPath := assetsDir . "\" . this.key . ".ico"
11-
ahkPath := this.launcherDir . "\" . this.key . ".ahk"
11+
ahkPath := assetsDir . "\" . this.key . ".ahk"
1212

13-
ahk2ExePath := this.app.AppConfig.AppDir . "\Vendor\AutoHotKey\Compiler\Ahk2Exe.exe"
13+
ahk2ExePath := this.appDir . "\Vendor\AutoHotKey\Compiler\Ahk2Exe.exe"
1414

1515
RunWait, %ahk2ExePath% /in "%ahkPath%" /out "%exePath%" /icon "%iconPath%"
16+
17+
return this.FilePath
1618
}
1719
}

Lib/BuildFile/IconFile.ahk

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@ class IconFile extends CopyableBuildFile {
22
requestMessage := "Select an icon file or an exe to extract the icon from"
33
selectFilter := "Icons (*.ico; *.exe; *.ocx; *.dll; *.cpl)"
44

5-
__New(app, config, launcherDir, key, filePath := "", autoBuild := true) {
5+
__New(app, config, launcherDir, key, filePath := "") {
66
sourcePath := config.HasKey("iconSrc") ? config.iconSrc : ""
7-
base.__New(app, config, launcherDir, key, ".ico", filePath, autoBuild, sourcePath)
7+
base.__New(app, config, launcherDir, key, ".ico", filePath, sourcePath)
88
}
99

1010
Cleanup() {
1111
base.Cleanup()
1212

1313
iconsDir := this.tempDir . "\icons"
1414
FileRemoveDir, %iconsDir%, true
15+
16+
return true
1517
}
1618

1719
Locate() {
@@ -21,7 +23,11 @@ class IconFile extends CopyableBuildFile {
2123
SplitPath, path,,, fileExt
2224

2325
if (fileExt != "ico") {
24-
path := this.ExtractGameIcon(path)
26+
path := this.ExtractIcon(path)
27+
28+
if (path == "") {
29+
this.Locate()
30+
}
2531
}
2632
}
2733

@@ -30,36 +36,40 @@ class IconFile extends CopyableBuildFile {
3036

3137
ExtractIcon(path) {
3238
iconsDir := this.tempDir . "\icons"
33-
iconsCount := 0
39+
3440
iconFilePath := ""
41+
iconsExtPath := this.appDir . "\Vendor\IconsExt\iconsext.exe"
3542

3643
FileCreateDir, %iconsDir%
37-
RunWait, %appDir%\Vendor\IconsExt\iconsext.exe /save "%path%" "%iconsDir%" -icons,, Hide
44+
RunWait, %iconsExtPath% /save "%path%" "%iconsDir%" -icons,, Hide
3845

46+
iconsCount := 0
3947
glob := iconsDir . "\*.ico"
4048
Loop, %glob% {
4149
iconsCount := A_Index
4250
iconFilePath := A_LoopFilePath
4351
}
4452

4553
if (iconsCount == 0) {
46-
MsgBox, No icons count be extracted from %exeFile%.
47-
this.Cleanup()
48-
ExitApp, -1
49-
}
50-
51-
if (iconsCount > 1) {
54+
MsgBox, No icons could be extracted from %exeFile%. Please try another file.
5255
iconFilePath := ""
53-
FileSelectFile, iconFilePath,, %iconsDir%, Select the correct icon from the extracted files, Icons (*.ico)
56+
this.Cleanup()
57+
} else {
58+
if (iconsCount > 1) {
59+
iconFilePath := ""
60+
FileSelectFile, iconFilePath,, %iconsDir%, Select the correct icon from the extracted files, Icons (*.ico)
5461

55-
if (iconFilePath == "") {
56-
MsgBox, "Canceled icon selection."
57-
this.Cleanup()
58-
ExitApp, -1
62+
if (iconFilePath == "") {
63+
MsgBox, "Canceled icon selection. Please try again."
64+
this.Cleanup()
65+
}
5966
}
6067
}
6168

62-
this.sourcePath := iconFilePath
63-
return this.sourcePath
69+
if (iconFilePath != "") {
70+
this.sourcePath := iconFilePath
71+
}
72+
73+
return iconFilePath
6474
}
6575
}

Lib/BuildFile/ShortcutFile.ahk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ class ShortcutFile extends CopyableBuildFile {
22
requestMessage := "Select the game shortcut"
33
selectFilter := "Shortcuts (*.lnk; *.url; *.exe)"
44

5-
__New(app, config, launcherDir, key, filePath := "", autoBuild := true) {
5+
__New(app, config, launcherDir, key, filePath := "") {
66
sourcePath := config.HasKey("shortcutSrc") ? config.shortcutSrc : ""
7-
base.__New(app, config, launcherDir, key, ".lnk", filePath, autoBuild, sourcePath)
7+
base.__New(app, config, launcherDir, key, ".lnk", filePath, sourcePath)
88
}
99

1010
Locate() {
@@ -29,7 +29,7 @@ class ShortcutFile extends CopyableBuildFile {
2929

3030
Copy() {
3131
this.DetermineExtension()
32-
base.Copy()
32+
return base.Copy()
3333
}
3434

3535
DetermineExtension() {

Lib/Builder/Builder.ahk

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,44 @@ class Builder {
1111

1212
Build() {
1313
launcherDir := this.app.AppConfig.LauncherDir
14+
assetsDir := this.app.AppConfig.AssetsDir
15+
16+
if (launcherDir == "" or assetsDir == "") {
17+
MsgBox, Required directories not set in configuration. Skipping.
18+
return false
19+
}
1420

1521
if (this.app.AppConfig.IndividualDirs) {
1622
launcherDir .= "\" . this.key
1723
}
18-
19-
assetsDir := this.app.AppConfig.AssetsDir . "\" . this.key
24+
assetsDir .= "\" . this.key
2025

2126
FileCreateDir, %launcherDir%
2227
FileCreateDir, %assetsDir%
2328

24-
new IconFile(this.app, this.config, assetsDir, this.key)
29+
iconObj := new IconFile(this.app, this.config, assetsDir, this.key)
30+
iconResult := iconObj.Build()
2531

32+
shortcutResult := !this.config.requiresShortcutFile ; Default to true if shortcut isn't required
2633
if (this.config.requiresShortcutFile) {
27-
new ShortcutFile(this.app, this.config, assetsDir, this.key)
34+
shortcutObj := new ShortcutFile(this.app, this.config, assetsDir, this.key)
35+
shortcutResult := shortcutObj.Build()
2836
}
2937

30-
new GameAhkFile(this.app, this.config, launcherDir, this.key)
31-
new GameExeFile(this.app, this.config, launcherDir, this.key)
38+
ahkResult := false
39+
exeResult := false
3240

33-
return true
41+
if (iconResult and shortcutResult) {
42+
gameAhkObj := new GameAhkFile(this.app, this.config, assetsDir, this.key)
43+
gameAhkResult := gameAhkObj.Build()
44+
45+
if (gameAhkResult) {
46+
gameExeObj := new GameExeFile(this.app, this.config, launcherDir, this.key)
47+
gameExeResult := gameExeObj.Build()
48+
}
49+
50+
}
51+
52+
return exeResult
3453
}
3554
}

0 commit comments

Comments
 (0)