-
Notifications
You must be signed in to change notification settings - Fork 2
/
Profile.cpp
397 lines (334 loc) · 12 KB
/
Profile.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
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
/******************************************************************************
** (C) Chris Oldwood
**
** MODULE: PROFILE.CPP
** COMPONENT: The Application.
** DESCRIPTION: CProfile class definition.
**
*******************************************************************************
*/
#include "Common.hpp"
#include "Profile.hpp"
#include "Cache.hpp"
#include <WCL/RegKey.hpp>
/******************************************************************************
**
** Class constants.
**
*******************************************************************************
*/
const tchar* CProfile::DEF_UT_PROFILE_NAME = TXT("UT");
const tchar* CProfile::DEF_UT2003_PROFILE_NAME = TXT("UT2003");
const tchar* CProfile::DEF_UT2004_PROFILE_NAME = TXT("UT2004");
const tchar* CProfile::DEF_TO_PROFILE_NAME = TXT("Tactical Ops");
const tchar* CProfile::DEF_ROOT_DIR = TXT("C:\\UnrealTournament");
const tchar* CProfile::DEF_CACHE_DIR = TXT("Cache");
const tchar* CProfile::DEF_CACHE_IDX_FILE = TXT("cache.ini");
const tchar* CProfile::DEF_CACHE_FILE_EXT = TXT("uxx");
const tchar* CProfile::DEF_SYSTEM_DIR = TXT("System");
const tchar* CProfile::DEF_MAPS_DIR = TXT("Maps");
const tchar* CProfile::DEF_TEXTURES_DIR = TXT("Textures");
const tchar* CProfile::DEF_SOUNDS_DIR = TXT("Sounds");
const tchar* CProfile::DEF_MUSIC_DIR = TXT("Music");
const tchar* CProfile::DEF_CONFIG_FILE = TXT("UnrealTournament.ini");
const tchar* CProfile::DEF_CACHE_TMP_DIR = TXT("..\\.");
const tchar* CProfile::DEF_CACHE_TMP_MASK = TXT("????.tmp");
const tchar* CProfile::DEF_MESH_DIR = TXT("StaticMeshes");
const tchar* CProfile::DEF_ANIM_DIR = TXT("Animations");
const tchar* CProfile::DEF_KARMA_DIR = TXT("KarmaData");
const tchar* CProfile::DEF_2003_CONFIG_FILE = TXT("UT2003.ini");
const tchar* CProfile::DEF_2004_CONFIG_FILE = TXT("UT2004.ini");
const tchar* CProfile::DEF_TO_CONFIG_FILE = TXT("TacticalOps.ini");
const tchar* CProfile::s_pszFormats[3] = { TXT("UT"), TXT("UT2003"), TXT("UT2004") };
/******************************************************************************
** Method: Constructor.
**
** Description: .
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
CProfile::CProfile()
: m_nFormat(UT_FORMAT)
, m_bReadOnly(false)
{
}
/******************************************************************************
** Method: Destructor.
**
** Description: .
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
CProfile::~CProfile()
{
}
/******************************************************************************
** Method: IsValidType()
**
** Description: Queries if the file extension is a valid UT file extension.
**
** Parameters: strExt The file extension.
**
** Returns: true or false.
**
*******************************************************************************
*/
bool CProfile::IsValidType(const CString& strExt)
{
return ( (strExt == TXT(".u") ) || (strExt == TXT(".int"))
|| (strExt == TXT(".unr")) || (strExt == TXT(".ut2"))
|| (strExt == TXT(".utx")) || (strExt == TXT(".uax"))
|| (strExt == TXT(".umx")) || (strExt == TXT(".ogg"))
|| (strExt == TXT(".usx")) || (strExt == TXT(".ukx"))
|| (strExt == TXT(".ka") ) );
}
/******************************************************************************
** Method: GetFileType()
**
** Description: Gets the file type from the files extension.
**
** Parameters: strExt The file extension.
**
** Returns: The file type or UNKNOWN_FILE.
**
*******************************************************************************
*/
tchar CProfile::GetFileType(const CString& strExt)
{
if ((strExt == TXT(".u")) || (strExt == TXT(".int")) || (strExt == TXT("")))
{
return SYSTEM_FILE;
}
else if ((strExt == TXT(".unr")) || (strExt == TXT(".ut2")))
{
return MAP_FILE;
}
else if (strExt == TXT(".utx"))
{
return TEXTURE_FILE;
}
else if (strExt == TXT(".uax"))
{
return SOUND_FILE;
}
else if ((strExt == TXT(".umx")) || (strExt == TXT(".ogg")))
{
return MUSIC_FILE;
}
else if (strExt == TXT(".usx"))
{
return MESH_FILE;
}
else if (strExt == TXT(".ukx"))
{
return ANIM_FILE;
}
else if (strExt == TXT(".ka"))
{
return KARMA_FILE;
}
ASSERT_FALSE();
return UNKNOWN_FILE;
}
/******************************************************************************
** Method: GetTypeDir()
**
** Description: Gets the directory which stores the given file type.
**
** Parameters: cType The file type.
**
** Returns: The directory.
**
*******************************************************************************
*/
CPath CProfile::GetTypeDir(tchar cType)
{
switch (cType)
{
case SYSTEM_FILE: return m_strSystemDir;
case MAP_FILE: return m_strMapDir;
case TEXTURE_FILE: return m_strTextureDir;
case SOUND_FILE: return m_strSoundDir;
case MUSIC_FILE: return m_strMusicDir;
case MESH_FILE: return m_strMeshDir;
case ANIM_FILE: return m_strAnimDir;
case KARMA_FILE: return m_strKarmaDir;
}
ASSERT_FALSE();
return TXT("");
}
/******************************************************************************
** Method: Compare()
**
** Description: Compare function used to sort the Profiles collection.
**
** Parameters: See qsort().
**
** Returns: See qsort().
**
*******************************************************************************
*/
bool CProfile::Compare(const CProfile* pProfile1, const CProfile* pProfile2)
{
ASSERT((pProfile1 != nullptr) && (pProfile2 != nullptr));
return (tstrcmp((pProfile1)->m_strName, (pProfile2)->m_strName) < 0);
}
/******************************************************************************
** Method: DetectUT()
**
** Description: Attempt to detect a UT installation.
**
** Parameters: None.
**
** Returns: A profile or nullptr, if none found.
**
*******************************************************************************
*/
CProfile* CProfile::DetectUT()
{
WCL::RegKey oKey;
// Try and find the regkey that contains the UT base path.
if (!WCL::RegKey::Exists(HKEY_LOCAL_MACHINE, TXT("SOFTWARE\\Unreal Technology\\Installed Apps\\UnrealTournament")))
return nullptr;
oKey.Open(HKEY_LOCAL_MACHINE, TXT("SOFTWARE\\Unreal Technology\\Installed Apps\\UnrealTournament"), KEY_READ);
// Get the UT base path.
CPath strBaseDir = oKey.ReadStringValue(TXT("Folder"), TXT(""));
if (strBaseDir == TXT(""))
return nullptr;
CProfile* pProfile = new CProfile();
// Create a profile for UT.
pProfile->m_strName = DEF_UT_PROFILE_NAME;
pProfile->m_nFormat = UT_FORMAT;
pProfile->m_strCacheDir = CPath(strBaseDir, DEF_CACHE_DIR );
pProfile->m_bReadOnly = false;
pProfile->m_strSystemDir = CPath(strBaseDir, DEF_SYSTEM_DIR );
pProfile->m_strMapDir = CPath(strBaseDir, DEF_MAPS_DIR );
pProfile->m_strTextureDir = CPath(strBaseDir, DEF_TEXTURES_DIR);
pProfile->m_strSoundDir = CPath(strBaseDir, DEF_SOUNDS_DIR );
pProfile->m_strMusicDir = CPath(strBaseDir, DEF_MUSIC_DIR );
pProfile->m_strConfigFile = CPath(pProfile->m_strSystemDir, DEF_CONFIG_FILE);
return pProfile;
}
/******************************************************************************
** Method: DetectUT2003()
**
** Description: Attempt to detect a UT2003 installation.
**
** Parameters: None.
**
** Returns: A profile or nullptr, if none found.
**
*******************************************************************************
*/
CProfile* CProfile::DetectUT2003()
{
WCL::RegKey oKey;
// Try and find the regkey that contains the UT2003 base path.
if (!WCL::RegKey::Exists(HKEY_LOCAL_MACHINE, TXT("SOFTWARE\\Unreal Technology\\Installed Apps\\UT2003")))
return nullptr;
oKey.Open(HKEY_LOCAL_MACHINE, TXT("SOFTWARE\\Unreal Technology\\Installed Apps\\UT2003"), KEY_READ);
// Get the UT2003 base path.
CPath strBaseDir = oKey.ReadStringValue(TXT("Folder"), TXT(""));
if (strBaseDir == TXT(""))
return nullptr;
CProfile* pProfile = new CProfile();
// Create a profile for UT2003.
pProfile->m_strName = DEF_UT2003_PROFILE_NAME;
pProfile->m_nFormat = UT2003_FORMAT;
pProfile->m_strCacheDir = CPath(strBaseDir, DEF_CACHE_DIR );
pProfile->m_bReadOnly = false;
pProfile->m_strSystemDir = CPath(strBaseDir, DEF_SYSTEM_DIR );
pProfile->m_strMapDir = CPath(strBaseDir, DEF_MAPS_DIR );
pProfile->m_strTextureDir = CPath(strBaseDir, DEF_TEXTURES_DIR);
pProfile->m_strSoundDir = CPath(strBaseDir, DEF_SOUNDS_DIR );
pProfile->m_strMusicDir = CPath(strBaseDir, DEF_MUSIC_DIR );
pProfile->m_strMeshDir = CPath(strBaseDir, DEF_MESH_DIR );
pProfile->m_strAnimDir = CPath(strBaseDir, DEF_ANIM_DIR );
pProfile->m_strKarmaDir = CPath(strBaseDir, DEF_KARMA_DIR );
pProfile->m_strConfigFile = CPath(pProfile->m_strSystemDir, DEF_2003_CONFIG_FILE);
return pProfile;
}
/******************************************************************************
** Method: DetectUT2004()
**
** Description: Attempt to detect a UT2004 installation.
**
** Parameters: None.
**
** Returns: A profile or nullptr, if none found.
**
*******************************************************************************
*/
CProfile* CProfile::DetectUT2004()
{
WCL::RegKey oKey;
// Try and find the regkey that contains the UT2004 base path.
if (!WCL::RegKey::Exists(HKEY_LOCAL_MACHINE, TXT("SOFTWARE\\Unreal Technology\\Installed Apps\\UT2004")))
return nullptr;
oKey.Open(HKEY_LOCAL_MACHINE, TXT("SOFTWARE\\Unreal Technology\\Installed Apps\\UT2004"), KEY_READ);
// Get the UT2004 base path.
CPath strBaseDir = oKey.ReadStringValue(TXT("Folder"), TXT(""));
if (strBaseDir == TXT(""))
return nullptr;
CProfile* pProfile = new CProfile();
// Create a profile for UT2004.
pProfile->m_strName = DEF_UT2004_PROFILE_NAME;
pProfile->m_nFormat = UT2004_FORMAT;
pProfile->m_strCacheDir = CPath(strBaseDir, DEF_CACHE_DIR );
pProfile->m_bReadOnly = false;
pProfile->m_strSystemDir = CPath(strBaseDir, DEF_SYSTEM_DIR );
pProfile->m_strMapDir = CPath(strBaseDir, DEF_MAPS_DIR );
pProfile->m_strTextureDir = CPath(strBaseDir, DEF_TEXTURES_DIR);
pProfile->m_strSoundDir = CPath(strBaseDir, DEF_SOUNDS_DIR );
pProfile->m_strMusicDir = CPath(strBaseDir, DEF_MUSIC_DIR );
pProfile->m_strMeshDir = CPath(strBaseDir, DEF_MESH_DIR );
pProfile->m_strAnimDir = CPath(strBaseDir, DEF_ANIM_DIR );
pProfile->m_strKarmaDir = CPath(strBaseDir, DEF_KARMA_DIR );
pProfile->m_strConfigFile = CPath(pProfile->m_strSystemDir, DEF_2004_CONFIG_FILE);
return pProfile;
}
/******************************************************************************
** Method: DetectTacOps()
**
** Description: Attempt to detect a Tactical Ops installation.
**
** Parameters: None.
**
** Returns: A profile or nullptr, if none found.
**
*******************************************************************************
*/
CProfile* CProfile::DetectTacOps()
{
WCL::RegKey oKey;
// Try and find the regkey that contains the TO base path.
if (!WCL::RegKey::Exists(HKEY_LOCAL_MACHINE, TXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Tactical Ops")))
return nullptr;
oKey.Open(HKEY_LOCAL_MACHINE, TXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Tactical Ops"), KEY_READ);
// Get the TO base path.
CPath strBaseDir = oKey.ReadStringValue(TXT("InstallLocation"), TXT(""));
if (strBaseDir == TXT(""))
return nullptr;
CProfile* pProfile = new CProfile();
// Create a profile for TO.
pProfile->m_strName = DEF_TO_PROFILE_NAME;
pProfile->m_nFormat = UT_FORMAT;
pProfile->m_strCacheDir = CPath(strBaseDir, DEF_CACHE_DIR );
pProfile->m_bReadOnly = false;
pProfile->m_strConfigFile = CPath(strBaseDir / DEF_SYSTEM_DIR, DEF_TO_CONFIG_FILE);
strBaseDir /= TXT("TacticalOps");
pProfile->m_strSystemDir = CPath(strBaseDir, DEF_SYSTEM_DIR );
pProfile->m_strMapDir = CPath(strBaseDir, DEF_MAPS_DIR );
pProfile->m_strTextureDir = CPath(strBaseDir, DEF_TEXTURES_DIR);
pProfile->m_strSoundDir = CPath(strBaseDir, DEF_SOUNDS_DIR );
pProfile->m_strMusicDir = CPath(strBaseDir, DEF_MUSIC_DIR );
return pProfile;
}