-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEditProfileDlg.cpp
More file actions
462 lines (393 loc) · 12.6 KB
/
EditProfileDlg.cpp
File metadata and controls
462 lines (393 loc) · 12.6 KB
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
/******************************************************************************
** (C) Chris Oldwood
**
** MODULE: EDITPROFILEDLG.CPP
** COMPONENT: The Application.
** DESCRIPTION: CEditProfileDlg class definition.
**
*******************************************************************************
*/
#include "Common.hpp"
#include "EditProfileDlg.hpp"
#include "UTCMGRApp.hpp"
#include "HelpTopics.h"
/******************************************************************************
**
** Local variables.
**
*******************************************************************************
*/
static const tchar* SEL_FOLDER_MSG = TXT("Select The UT/UT2003/UT2004/Mod Base Folder\n")
TXT("e.g. C:\\UnrealTournament");
/******************************************************************************
** Method: Default constructor.
**
** Description: .
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
CEditProfileDlg::CEditProfileDlg()
: CDialog(IDD_EDIT_PROFILE)
, m_strLastPath(CProfile::DEF_ROOT_DIR)
{
DEFINE_CTRL_TABLE
CTRL(IDC_NAME, &m_ebName )
CTRL(IDC_FORMAT, &m_cbFormat )
CTRL(IDC_CACHE_DIR, &m_ebCacheDir )
CTRL(IDC_READ_ONLY, &m_ckReadOnly )
CTRL(IDC_SYSTEM_DIR, &m_ebSystemDir )
CTRL(IDC_MAPS_DIR, &m_ebMapDir )
CTRL(IDC_TEXTURES_DIR, &m_ebTextureDir)
CTRL(IDC_SOUNDS_DIR, &m_ebSoundDir )
CTRL(IDC_MUSIC_DIR, &m_ebMusicDir )
CTRL(IDC_MESH_DIR, &m_ebMeshDir )
CTRL(IDC_ANIM_DIR, &m_ebAnimDir )
CTRL(IDC_KARMA_DIR, &m_ebKarmaDir )
CTRL(IDC_CONFIG_FILE, &m_ebConfigFile)
END_CTRL_TABLE
DEFINE_CTRLMSG_TABLE
CMD_CTRLMSG(IDC_FORMAT, CBN_SELCHANGE, &CEditProfileDlg::OnSelectFormat )
CMD_CTRLMSG(IDC_BROWSE_CACHE, BN_CLICKED, &CEditProfileDlg::OnBrowseCache )
CMD_CTRLMSG(IDC_BROWSE_SYSTEM, BN_CLICKED, &CEditProfileDlg::OnBrowseSystem )
CMD_CTRLMSG(IDC_BROWSE_MAPS, BN_CLICKED, &CEditProfileDlg::OnBrowseMaps )
CMD_CTRLMSG(IDC_BROWSE_TEXTURES, BN_CLICKED, &CEditProfileDlg::OnBrowseTextures)
CMD_CTRLMSG(IDC_BROWSE_SOUNDS, BN_CLICKED, &CEditProfileDlg::OnBrowseSounds )
CMD_CTRLMSG(IDC_BROWSE_MUSIC, BN_CLICKED, &CEditProfileDlg::OnBrowseMusic )
CMD_CTRLMSG(IDC_BROWSE_MESHS, BN_CLICKED, &CEditProfileDlg::OnBrowseMeshes )
CMD_CTRLMSG(IDC_BROWSE_ANIMS, BN_CLICKED, &CEditProfileDlg::OnBrowseAnims )
CMD_CTRLMSG(IDC_BROWSE_KARMA, BN_CLICKED, &CEditProfileDlg::OnBrowseKarma )
CMD_CTRLMSG(IDC_BROWSE_CONFIG, BN_CLICKED, &CEditProfileDlg::OnBrowseCfgFile )
CMD_CTRLMSG(IDC_QUICK_SETUP, BN_CLICKED, &CEditProfileDlg::OnQuickSetup )
END_CTRLMSG_TABLE
}
/******************************************************************************
** Method: OnInitDialog()
**
** Description: Initialise the dialog.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CEditProfileDlg::OnInitDialog()
{
// Initialise formats combo.
for (int i = 0; i < CProfile::NUM_FORMATS; ++i)
m_cbFormat.Add(CProfile::s_pszFormats[i]);
// Load the current config.
m_ebName.Text(m_oProfile.m_strName);
m_cbFormat.CurSel(m_oProfile.m_nFormat);
m_ebCacheDir.Text(m_oProfile.m_strCacheDir);
m_ckReadOnly.Check(m_oProfile.m_bReadOnly);
m_ebSystemDir.Text(m_oProfile.m_strSystemDir);
m_ebMapDir.Text(m_oProfile.m_strMapDir);
m_ebTextureDir.Text(m_oProfile.m_strTextureDir);
m_ebSoundDir.Text(m_oProfile.m_strSoundDir);
m_ebMusicDir.Text(m_oProfile.m_strMusicDir);
m_ebMeshDir.Text(m_oProfile.m_strMeshDir);
m_ebAnimDir.Text(m_oProfile.m_strAnimDir);
m_ebKarmaDir.Text(m_oProfile.m_strKarmaDir);
m_ebConfigFile.Text(m_oProfile.m_strConfigFile);
// Initialise control string lengths.
m_ebName.TextLimit(MAX_PATH);
m_ebCacheDir.TextLimit(MAX_PATH);
m_ebSystemDir.TextLimit(MAX_PATH);
m_ebMapDir.TextLimit(MAX_PATH);
m_ebTextureDir.TextLimit(MAX_PATH);
m_ebSoundDir.TextLimit(MAX_PATH);
m_ebMusicDir.TextLimit(MAX_PATH);
m_ebMeshDir.TextLimit(MAX_PATH);
m_ebAnimDir.TextLimit(MAX_PATH);
m_ebKarmaDir.TextLimit(MAX_PATH);
m_ebConfigFile.TextLimit(MAX_PATH);
// Cannot edit profile name.
if (m_oProfile.m_strName != TXT(""))
m_ebName.Enable(false);
OnSelectFormat();
}
/******************************************************************************
** Method: OnOk()
**
** Description: User pressed OK.
**
** Parameters: None.
**
** Returns: true or false.
**
*******************************************************************************
*/
bool CEditProfileDlg::OnOk()
{
// Get settings.
CString strName = m_ebName.Text();
size_t nFormat = m_cbFormat.CurSel();
CPath strCacheDir = m_ebCacheDir.Text();
CPath strSystemDir = m_ebSystemDir.Text();
CPath strMapDir = m_ebMapDir.Text();
CPath strTextureDir = m_ebTextureDir.Text();
CPath strSoundDir = m_ebSoundDir.Text();
CPath strMusicDir = m_ebMusicDir.Text();
CPath strMeshDir = m_ebMeshDir.Text();
CPath strAnimDir = m_ebAnimDir.Text();
CPath strKarmaDir = m_ebKarmaDir.Text();
CPath strConfigFile = m_ebConfigFile.Text();
// Validate profile name.
if (strName.Length() == 0)
{
AlertMsg(TXT("Please supply a name for the profile."));
m_ebName.Focus();
return false;
}
if ( (m_oProfile.m_strName == TXT("")) && (App.FindProfile(strName) != nullptr) )
{
AlertMsg(TXT("The profile name should be unique."));
m_ebName.Focus();
return false;
}
// Validate common paths.
if (!ValidatePath(strCacheDir, m_ebCacheDir, TXT("cache folder")))
return false;
if (!ValidatePath(strSystemDir, m_ebSystemDir, TXT("system folder")))
return false;
if (!ValidatePath(strMapDir, m_ebMapDir, TXT("maps folder")))
return false;
if (!ValidatePath(strTextureDir, m_ebTextureDir, TXT("textures folder")))
return false;
if (!ValidatePath(strSoundDir, m_ebSoundDir, TXT("sounds folder")))
return false;
if (!ValidatePath(strMusicDir, m_ebMusicDir, TXT("music folder")))
return false;
// Validate UT2003/4 specific paths.
if ((nFormat == CProfile::UT2003_FORMAT) || (nFormat == CProfile::UT2004_FORMAT))
{
if (!ValidatePath(strMeshDir, m_ebMeshDir, TXT("static meshes folder")))
return false;
if (!ValidatePath(strAnimDir, m_ebAnimDir, TXT("animations folder")))
return false;
if (!ValidatePath(strKarmaDir, m_ebKarmaDir, TXT("karma data folder")))
return false;
}
if (!ValidatePath(strConfigFile, m_ebConfigFile, TXT("config file")))
return false;
// Update profile.
m_oProfile.m_strName = strName;
m_oProfile.m_nFormat = static_cast<int>(nFormat);
m_oProfile.m_strCacheDir = strCacheDir;
m_oProfile.m_bReadOnly = m_ckReadOnly.IsChecked();
m_oProfile.m_strSystemDir = strSystemDir;
m_oProfile.m_strMapDir = strMapDir;
m_oProfile.m_strTextureDir = strTextureDir;
m_oProfile.m_strSoundDir = strSoundDir;
m_oProfile.m_strMusicDir = strMusicDir;
m_oProfile.m_strMeshDir = strMeshDir;
m_oProfile.m_strAnimDir = strAnimDir;
m_oProfile.m_strKarmaDir = strKarmaDir;
m_oProfile.m_strConfigFile = strConfigFile;
return true;
}
/******************************************************************************
** Method: OnSelectFormat()
**
** Description: New format selected, update UI.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CEditProfileDlg::OnSelectFormat()
{
size_t nFormat = m_cbFormat.CurSel();
// Enable/Disable depending on UT/UT2003.
m_ebMeshDir.ReadOnly(nFormat == CProfile::UT_FORMAT);
m_ebAnimDir.ReadOnly(nFormat == CProfile::UT_FORMAT);
m_ebKarmaDir.ReadOnly(nFormat == CProfile::UT_FORMAT);
// Clear non UT controls.
if (nFormat == CProfile::UT_FORMAT)
{
m_ebMeshDir.Text(TXT(""));
m_ebAnimDir.Text(TXT(""));
m_ebKarmaDir.Text(TXT(""));
}
}
/******************************************************************************
** Method: OnBrowse*()
**
** Description: Handlers to show directory/file selection dialog.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CEditProfileDlg::OnBrowseCache()
{
OnBrowseDir(m_ebCacheDir);
}
void CEditProfileDlg::OnBrowseSystem()
{
OnBrowseDir(m_ebSystemDir);
}
void CEditProfileDlg::OnBrowseMaps()
{
OnBrowseDir(m_ebMapDir);
}
void CEditProfileDlg::OnBrowseTextures()
{
OnBrowseDir(m_ebTextureDir);
}
void CEditProfileDlg::OnBrowseSounds()
{
OnBrowseDir(m_ebSoundDir);
}
void CEditProfileDlg::OnBrowseMusic()
{
OnBrowseDir(m_ebMusicDir);
}
void CEditProfileDlg::OnBrowseMeshes()
{
OnBrowseDir(m_ebMeshDir);
}
void CEditProfileDlg::OnBrowseAnims()
{
OnBrowseDir(m_ebAnimDir);
}
void CEditProfileDlg::OnBrowseKarma()
{
OnBrowseDir(m_ebKarmaDir);
}
void CEditProfileDlg::OnBrowseDir(CEditBox& ebPath)
{
CPath strDir = ebPath.Text();
// If empty start from last path.
if (strDir == TXT(""))
strDir = m_strLastPath;
// Show Select Directory common dialog.
if (strDir.SelectDir(*this, TXT("Select Folder"), strDir))
{
// Display path.
ebPath.Text(strDir);
// Use path as starting point for next selection.
m_strLastPath = strDir;
}
}
void CEditProfileDlg::OnBrowseCfgFile()
{
// File extensions.
static tchar szExts[] = { TXT("INI Files (*.ini)\0*.ini\0")
TXT("All Files (*.*)\0*.*\0")
TXT("\0\0") };
CPath strDir = m_ebConfigFile.Text();
// If empty start from last path.
if (strDir == TXT(""))
strDir = m_strLastPath;
CPath strFile;
// Show Select File common dialog.
if (strFile.Select(*this, CPath::SelectFile, szExts, TXT("ini"), strDir))
{
// Display path.
m_ebConfigFile.Text(strFile);
}
}
/******************************************************************************
** Method: OnQuickSetup()
**
** Description: Fills in all paths based on an inital base directory.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CEditProfileDlg::OnQuickSetup()
{
CPath strBaseDir;
// Select the base directory.
if (!strBaseDir.SelectDir(*this, SEL_FOLDER_MSG))
return;
// Create the full path to the System folder.
CPath strSysDir(strBaseDir, CProfile::DEF_SYSTEM_DIR);
// Set common paths.
m_cbFormat.CurSel (CProfile::UT_FORMAT);
m_ebCacheDir.Text (CPath(strBaseDir, CProfile::DEF_CACHE_DIR ));
m_ebSystemDir.Text (CPath(strBaseDir, CProfile::DEF_SYSTEM_DIR ));
m_ebMapDir.Text (CPath(strBaseDir, CProfile::DEF_MAPS_DIR ));
m_ebTextureDir.Text(CPath(strBaseDir, CProfile::DEF_TEXTURES_DIR));
m_ebSoundDir.Text (CPath(strBaseDir, CProfile::DEF_SOUNDS_DIR ));
m_ebMusicDir.Text (CPath(strBaseDir, CProfile::DEF_MUSIC_DIR ));
m_ebConfigFile.Text(CPath(strSysDir, CProfile::DEF_CONFIG_FILE ));
// Check for UT2004.
CPath strUT2003Cfg(strSysDir, CProfile::DEF_2003_CONFIG_FILE);
CPath strUT2004Cfg(strSysDir, CProfile::DEF_2004_CONFIG_FILE);
if (strUT2003Cfg.Exists() || strUT2004Cfg.Exists())
{
// Set common paths.
m_ebMeshDir.Text (CPath(strBaseDir, CProfile::DEF_MESH_DIR ));
m_ebAnimDir.Text (CPath(strBaseDir, CProfile::DEF_ANIM_DIR ));
m_ebKarmaDir.Text(CPath(strBaseDir, CProfile::DEF_KARMA_DIR));
// Set UT2003 paths.
if (strUT2003Cfg.Exists())
{
m_ebConfigFile.Text(strUT2003Cfg);
m_cbFormat.CurSel(CProfile::UT2003_FORMAT);
}
// Set UT2004 paths.
if (strUT2004Cfg.Exists())
{
m_ebConfigFile.Text(strUT2004Cfg);
m_cbFormat.CurSel(CProfile::UT2004_FORMAT);
}
}
OnSelectFormat();
}
/******************************************************************************
** Method: OnHelp()
**
** Description: Help requested for the dialog.
**
** Parameters: See HELPINFO.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CEditProfileDlg::OnHelp(HELPINFO& /*oInfo*/)
{
// Show the dialogs help topic.
App.m_oHelpFile.Topic(IDH_EDITPROFDLG);
}
/******************************************************************************
** Method: ValidatePath()
**
** Description: Checks if the path is valid and if not queries the user if they
** want to allow it anyway.
**
** Parameters: strPath The path.
** ebControl The control where the path is enetered.
** pszName The name for the path.
**
** Returns: true or false.
**
*******************************************************************************
*/
bool CEditProfileDlg::ValidatePath(const CPath& strPath, CEditBox& ebControl, const tchar* pszName)
{
ASSERT(pszName != nullptr);
// Path valid?
if (strPath.Exists())
return true;
// User allowing path anyway?
if (QueryMsg(TXT("The %s is invalid.\n\nDo you want to allow it?"), pszName) == IDYES)
return true;
ebControl.Focus();
return false;
}