Skip to content

Commit dd87232

Browse files
authored
Merge pull request #1 from 3tmp/2.0.0_alpha
2.0.0 alpha
2 parents e20ebe7 + b503c7d commit dd87232

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+7896
-882
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
Config.ini
1+
Config.ini
2+
test*.ahk
3+
log.txt

Application.ahk

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
class Application extends _Object
2+
{
3+
static _applicationName := "Stronghold Hotkeys"
4+
, _iniPath := "Config.ini"
5+
, _logger := LoggerFactory.GetLogger(Application)
6+
7+
__New()
8+
{
9+
this._settingsModel := ""
10+
this._settingsController := ""
11+
this._settingsGui := ""
12+
this._hotkeyHandler := ""
13+
this._updateChecker := ""
14+
15+
this._errorLogger := ""
16+
this._exitLogger := ""
17+
}
18+
19+
Initialize()
20+
{
21+
; Set up the logger
22+
If (IsDebuggerAttatched())
23+
{
24+
LoggerFactory.SetMinLogLevel(_logLevel.Trace)
25+
LoggerFactory.SetBufferSize(1)
26+
}
27+
Else
28+
{
29+
LoggerFactory.SetMinLogLevel(_logLevel.Warn)
30+
LoggerFactory.SetBufferSize(1)
31+
}
32+
this._errorLogger := LoggerFactory.GetErrorLogger()
33+
this._exitLogger := LoggerFactory.GetExitLogger()
34+
35+
Application._logger.Info("App is starting up...")
36+
Application._logger.Info("Version: " Stronghold_Version())
37+
38+
If (IsDebuggerAttatched())
39+
{
40+
Application._logger.Info("App is running in dev mode.")
41+
}
42+
43+
this._registerWindowGroups()
44+
45+
; Create the settings model from the config file (if it exists), otherwise create a default one
46+
If (FileExist(Application._iniPath))
47+
{
48+
Application._logger.Trace("Applying the saved settings.")
49+
readConfig := FileRead(Application._iniPath)
50+
this._settingsModel := SettingsModel.FromIniString(readConfig)
51+
}
52+
Else
53+
{
54+
Application._logger.Trace("No saved settings. Use the default settings.")
55+
this._settingsModel := SettingsModel.Default()
56+
}
57+
58+
this._settingsController := new SettingsController(this._settingsModel, Application._iniPath)
59+
60+
this._hotkeyHandler := new StrongholdHotkeyHandler(this._settingsController, this._settingsModel)
61+
this._updateChecker := new UpdatesChecker(this._settingsController, this._settingsModel)
62+
63+
; Set up the tray menu (has to be done before the gui to ensure the Stronghold icon in the window title bar)
64+
TrayMenu.Instance.Init(this)
65+
66+
; Only show the gui when no config file exists (usually the first load), or if the app is in dev mode
67+
If (!FileExist(Application._iniPath) || IsDebuggerAttatched())
68+
{
69+
this._settingsController.SaveToFile()
70+
this._getOrCreateSettingsGui().Show()
71+
}
72+
73+
Application._logger.Info("App startup finished.")
74+
}
75+
76+
; Get a reference to a settings gui instance
77+
SettingsGui[]
78+
{
79+
Get
80+
{
81+
Return this._getOrCreateSettingsGui()
82+
}
83+
}
84+
85+
; The central application exit point
86+
ExitApp()
87+
{
88+
Application._logger.Info("App is shutting down...")
89+
ExitApp
90+
}
91+
92+
; Register the Stronghold window groups via the GroupAdd command
93+
_registerWindowGroups()
94+
{
95+
static isRegistered := false
96+
If (isRegistered)
97+
{
98+
Return
99+
}
100+
101+
For each, group in EWindowGroups
102+
{
103+
GroupAdd(group, StrongholdManager.WindowTitles[group])
104+
}
105+
isRegistered := true
106+
}
107+
108+
_getOrCreateSettingsGui()
109+
{
110+
If (this._settingsGui == "" || this._settingsGui.IsDestroyed)
111+
{
112+
title := Stronghold_Version().Format(GetLanguage().Title)
113+
this._settingsGui := new SettingsGui(this._settingsController, this._settingsModel, title)
114+
}
115+
Return this._settingsGui
116+
}
117+
}

Build/Compiler.ahk

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@ global resultFileExe := "Stronghold.exe"
77
global buildMinimal := true
88
global resultFileExeMinimal := "Stronghold_minimal.exe"
99

10+
global mainFileName := "Main.ahk"
11+
global mainMinimalName := "Minimal_Autoclicker.ahk"
1012
global mainPath := GetFullPathName(A_ScriptDir "\..\")
1113
SetWorkingDir, % mainPath
1214

13-
If (!FileExist("Stronghold.ahk"))
15+
If (!FileExist(mainFileName))
1416
{
1517
MsgBox,, Error, The Main file does not exist
1618
ExitApp
1719
}
1820

1921
output := ""
2022

21-
For each, line in FileToLineArray(FileRead("Stronghold.ahk"))
23+
For each, line in FileToLineArray(FileRead(mainFileName))
2224
{
2325
line := removeIndent ? Trim(line) : line
2426

@@ -49,15 +51,15 @@ If (FileExist("Build\" resultFileExe))
4951
{
5052
FileDelete("Build\" resultFileExe)
5153
}
52-
CompileWithAhk2Exe("Stronghold.ahk", resultFileExe)
54+
CompileWithAhk2Exe("Build\" resultFileAhk, resultFileExe)
5355

5456
If (buildMinimal)
5557
{
5658
If (FileExist("Build\" resultFileExeMinimal))
5759
{
5860
FileDelete("Build\" resultFileExeMinimal)
5961
}
60-
CompileWithAhk2Exe("Minimal_Autoclicker.ahk", resultFileExeMinimal)
62+
CompileWithAhk2Exe(mainMinimalName, resultFileExeMinimal)
6163
}
6264

6365
Msgbox,, Finish, Compiling the files finished
@@ -114,10 +116,11 @@ FileToLineArray(file)
114116
}
115117

116118
; Retrieves the full path and file name of the specified file.
117-
GetFullPathName(fileName, longName := 0)
119+
GetFullPathName(fileName)
118120
{
119-
; 522 is 260 (MAX_PATH) plus null termination character and Unicode
120-
size := (VarSetCapacity(lpFilePath, longName ? longName * 2 : 522) // 2) - 1
121-
res := DllCall("Kernel32.dll\GetFullPathName", "Str", fileName, "UInt", size, "Str", lpFilePath, "Int", 0)
122-
Return res ? lpFilePath : ""
121+
static MAX_PATH := 260
122+
; +1 for the null terminating character
123+
VarSetCapacity(lpFilePath, (MAX_PATH + 1) * 2)
124+
res := DllCall("Kernel32.dll\GetFullPathName", "Str", fileName, "UInt", MAX_PATH, "Str", lpFilePath, "Int", 0)
125+
Return lpFilePath
123126
}

0 commit comments

Comments
 (0)