-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProfileCfgDlg.cpp
337 lines (277 loc) · 7.62 KB
/
ProfileCfgDlg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/******************************************************************************
** (C) Chris Oldwood
**
** MODULE: PROFILECFGDLG.CPP
** COMPONENT: The Application.
** DESCRIPTION: CProfileCfgDlg class definition.
**
*******************************************************************************
*/
#include "Common.hpp"
#include "ProfileCfgDlg.hpp"
#include "EditProfileDlg.hpp"
#include "HelpTopics.h"
#include "DetectedDlg.hpp"
#include <Core/Algorithm.hpp>
#include "UTCMGRApp.hpp"
#include <WCL/BusyCursor.hpp>
/******************************************************************************
** Method: Default constructor.
**
** Description: .
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
CProfileCfgDlg::CProfileCfgDlg()
: CDialog(IDD_PROFILES)
, m_bReScan(false)
{
DEFINE_CTRL_TABLE
CTRL(IDC_PROFILES, &m_lbProfiles)
END_CTRL_TABLE
DEFINE_CTRLMSG_TABLE
CMD_CTRLMSG(IDC_ADD, BN_CLICKED, &CProfileCfgDlg::OnAdd )
CMD_CTRLMSG(IDC_EDIT, BN_CLICKED, &CProfileCfgDlg::OnEdit )
CMD_CTRLMSG(IDC_REMOVE, BN_CLICKED, &CProfileCfgDlg::OnRemove)
CMD_CTRLMSG(IDC_DETECT, BN_CLICKED, &CProfileCfgDlg::OnDetect)
CMD_CTRLMSG(IDC_PROFILES, LBN_DBLCLK, &CProfileCfgDlg::OnDblClkProfile)
END_CTRLMSG_TABLE
}
/******************************************************************************
** Method: OnInitDialog()
**
** Description: Initialise the dialog.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CProfileCfgDlg::OnInitDialog()
{
const size_t first = 0;
// Load the profiles listbox.
for (uint i = 0; i < App.m_aoProfiles.size(); ++i)
{
CProfile* pProfile = App.m_aoProfiles[i];
size_t n = m_lbProfiles.Add(pProfile->m_strName);
m_lbProfiles.ItemPtr(n, pProfile);
}
// Select the first by default.
m_lbProfiles.CurSel(first);
}
/******************************************************************************
** Method: OnAdd()
**
** Description: Add a new profile.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CProfileCfgDlg::OnAdd()
{
CEditProfileDlg Dlg;
// Show profile editing dialog.
if (Dlg.RunModal(*this) == IDOK)
{
CProfile* pProfile = new CProfile(Dlg.m_oProfile);
// Add to collection.
App.m_aoProfiles.push_back(pProfile);
// Add to view.
size_t n = m_lbProfiles.Add(pProfile->m_strName);
m_lbProfiles.ItemPtr(n, pProfile);
m_lbProfiles.CurSel(n);
// Mark profiles as modified.
App.m_nModified |= App.PROFILES;
}
}
/******************************************************************************
** Method: OnEdit()
**
** Description: Edit the selected profile.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CProfileCfgDlg::OnEdit()
{
size_t nSel = m_lbProfiles.CurSel();
// No selection?
if (nSel == CB_ERR)
return;
CEditProfileDlg Dlg;
CProfile* pProfile = static_cast<CProfile*>(m_lbProfiles.ItemPtr(nSel));
// Get selected profile details.
Dlg.m_oProfile = *pProfile;
// Show profile editing dialog.
if (Dlg.RunModal(*this) == IDOK)
{
// Update profile.
*pProfile = Dlg.m_oProfile;
// Rescan, if the active one.
if (pProfile == App.m_pProfile)
m_bReScan = true;
// Mark profiles as modified.
App.m_nModified |= App.PROFILES;
}
}
/******************************************************************************
** Method: OnRemove()
**
** Description: Remove the selected profile.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CProfileCfgDlg::OnRemove()
{
size_t nSel = m_lbProfiles.CurSel();
// No selection?
if (nSel == CB_ERR)
return;
// Get selected profile details.
CProfile* pProfile = static_cast<CProfile*>(m_lbProfiles.ItemPtr(nSel));
// Check we're not deleting the active profile.
if (pProfile == App.m_pProfile)
{
AlertMsg(TXT("You cannot delete the active profile."));
return;
}
// Check we're not deleting the default.
if (pProfile->m_strName == App.m_strDefProfile)
{
AlertMsg(TXT("You cannot delete the default profile."));
return;
}
// Remove from collection.
Core::deleteValue(App.m_aoProfiles, pProfile);
// Remove from view.
m_lbProfiles.Delete(nSel);
if (nSel == m_lbProfiles.Count())
nSel--;
m_lbProfiles.CurSel(nSel);
// Mark profiles as modified.
App.m_nModified |= App.PROFILES;
}
/******************************************************************************
** Method: OnDblClkProfile()
**
** Description: Double-clicked a profile, edit it.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CProfileCfgDlg::OnDblClkProfile()
{
OnEdit();
}
/******************************************************************************
** Method: OnDetect()
**
** Description: Detect any new UT installations.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CProfileCfgDlg::OnDetect()
{
CBusyCursor oBusyCursor;
CProfile* profile = nullptr;
CProfiles aoProfiles;
// Look for a UT installation.
if ((profile = CProfile::DetectUT()) != nullptr)
aoProfiles.push_back(profile);
// Look for a UT2003 installation.
if ((profile = CProfile::DetectUT2003()) != nullptr)
aoProfiles.push_back(profile);
// Look for a UT2004 installation.
if ((profile = CProfile::DetectUT2004()) != nullptr)
aoProfiles.push_back(profile);
// Look for a Tactical Ops installation.
if ((profile = CProfile::DetectTacOps()) != nullptr)
aoProfiles.push_back(profile);
// Remove any duplicates.
for (CProfiles::reverse_iterator oIter = aoProfiles.rbegin(); oIter != aoProfiles.rend(); ++oIter)
{
CProfile* pProfile = *oIter;
// Profile name already used OR already configured?
if ( (App.FindProfile(pProfile->m_strName) != nullptr)
|| (App.FindProfileByCfgFile(pProfile->m_strConfigFile) != nullptr) )
{
CProfiles::iterator oPos = (oIter+1).base();
delete *oPos;
aoProfiles.erase(oPos);
}
}
// Nothing new detected?
if (aoProfiles.empty())
{
NotifyMsg(TXT("No new installations were detected."));
return;
}
CDetectedDlg Dlg;
// App profiles to dialog.
for (uint i = 0; i < aoProfiles.size(); ++i)
{
CProfile* pProfile = aoProfiles[i];
Dlg.m_astrNames.Add(pProfile->m_strName);
Dlg.m_astrFolders.Add(pProfile->m_strConfigFile.Directory().Directory());
}
// Query user to confirm new profiles.
if (Dlg.RunModal(*this) == IDOK)
{
// Copy to main profiles array.
for (CProfiles::reverse_iterator oIter = aoProfiles.rbegin(); oIter != aoProfiles.rend(); ++oIter)
{
CProfile* pProfile = *oIter;
// Add to collection.
App.m_aoProfiles.push_back(pProfile);
// Add to view.
size_t n = m_lbProfiles.Add(pProfile->m_strName);
m_lbProfiles.ItemPtr(n, pProfile);
m_lbProfiles.CurSel(n);
}
// Detach from temporary array.
aoProfiles.clear();
// Mark profiles as modified.
App.m_nModified |= App.PROFILES;
}
// Cleanup.
Core::deleteAll(aoProfiles);
}
/******************************************************************************
** Method: OnHelp()
**
** Description: Help requested for the dialog.
**
** Parameters: See HELPINFO.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CProfileCfgDlg::OnHelp(HELPINFO& /*oInfo*/)
{
// Show the dialogs help topic.
App.m_oHelpFile.Topic(IDH_PROFILESDLG);
}