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
+ }
0 commit comments