-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFavouritesDlg.cpp
297 lines (243 loc) · 7.08 KB
/
FavouritesDlg.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
/******************************************************************************
** (C) Chris Oldwood
**
** MODULE: FAVOURITESDLG.CPP
** COMPONENT: The Application
** DESCRIPTION: CFavouritesDlg class definition.
**
*******************************************************************************
*/
#include "Common.hpp"
#include "FavouritesDlg.hpp"
#include "FavFileDlg.hpp"
#include "UTSvrBrowser.hpp"
#include <WCL/RegKey.hpp>
/******************************************************************************
**
** Local variables.
**
*******************************************************************************
*/
static const tchar* SEL_FOLDER_MSG = TXT("Select The UT System Folder\ne.g. C:\\UnrealTournament\\System");
/******************************************************************************
** Method: Default constructor.
**
** Description: .
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
CFavouritesDlg::CFavouritesDlg()
: CDialog(IDD_FAVOURITES)
, m_oFavFiles()
{
DEFINE_CTRL_TABLE
CTRL(IDC_GRID, &m_lvGrid)
END_CTRL_TABLE
DEFINE_CTRLMSG_TABLE
CMD_CTRLMSG(IDC_DETECT, BN_CLICKED, &CFavouritesDlg::OnDetect)
CMD_CTRLMSG(IDC_ADD, BN_CLICKED, &CFavouritesDlg::OnAdd )
CMD_CTRLMSG(IDC_EDIT, BN_CLICKED, &CFavouritesDlg::OnEdit )
CMD_CTRLMSG(IDC_REMOVE, BN_CLICKED, &CFavouritesDlg::OnRemove)
END_CTRLMSG_TABLE
}
/******************************************************************************
** Method: OnInitDialog()
**
** Description: Initialise the dialog.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CFavouritesDlg::OnInitDialog()
{
// Set grid style.
// m_lvGrid.Font(CFont(ANSI_FIXED_FONT));
m_lvGrid.FullRowSelect(true);
// m_lvGrid.GridLines(true);
// Create grid columns.
m_lvGrid.InsertColumn(MOD_NAME, TXT("Mod"), 100, LVCFMT_LEFT);
m_lvGrid.InsertColumn(MOD_FILE, TXT("File"), 325, LVCFMT_LEFT);
// Load grid...
for (size_t i = 0; i < m_oFavFiles.RowCount(); ++i)
{
CRow& oRow = m_oFavFiles[i];
int nRow = m_lvGrid.ItemCount();
// Add to the grid.
m_lvGrid.InsertItem(nRow, oRow[CFavFiles::MOD_NAME]);
m_lvGrid.ItemText (nRow, MOD_FILE, oRow[CFavFiles::MOD_FILE]);
m_lvGrid.ItemPtr (nRow, &oRow);
}
// Select 1st row by default.
if (m_lvGrid.ItemCount() > 0)
m_lvGrid.Select(0);
}
/******************************************************************************
** Method: OnOk()
**
** Description: The OK button was pressed.
**
** Parameters: None.
**
** Returns: true or false.
**
*******************************************************************************
*/
bool CFavouritesDlg::OnOk()
{
return true;
}
/******************************************************************************
** Method: OnDetect()
**
** Description: Attempt to auto-detect the mod config files.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CFavouritesDlg::OnDetect()
{
WCL::RegKey oKey;
CPath strFolder;
// 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")))
{
oKey.Open(HKEY_LOCAL_MACHINE, TXT("SOFTWARE\\Unreal Technology\\Installed Apps\\UnrealTournament"), KEY_READ);
strFolder = oKey.ReadStringValue(TXT("Folder"), TXT("")) / TXT("System");
}
// Detect failed?
if (strFolder.Empty())
{
// Notify user.
if (QueryMsg(TXT("Failed to detect the UT installation.\n\nDo you want to locate it manually?")) != IDYES)
return;
// Query user for folder.
if (!strFolder.SelectDir(*this, SEL_FOLDER_MSG))
return;
}
// For all mods.
for (size_t i = 0; i < App.m_oMods.RowCount(); ++i)
{
CRow& oMod = App.m_oMods[i];
// Mod already configured?
if (m_oFavFiles.SelectRow(CFavFiles::MOD_NAME, oMod[CMods::MOD_NAME].ToValue()) != nullptr)
continue;
// Favs file not available?
if (tstrlen(oMod[CMods::FAVS_FILE]) == 0)
continue;
CPath strIniFile(strFolder, oMod[CMods::FAVS_FILE]);
// Config file doesn't exist?
if (!strIniFile.Exists())
continue;
// Add to favourite config files table.
CRow& oRow = m_oFavFiles.CreateRow();
oRow[CFavFiles::MOD_NAME] = oMod[CMods::MOD_NAME];
oRow[CFavFiles::MOD_FILE] = strIniFile;
m_oFavFiles.InsertRow(oRow);
int nRow = m_lvGrid.ItemCount();
// Add to the grid.
m_lvGrid.InsertItem(nRow, oRow[CFavFiles::MOD_NAME]);
m_lvGrid.ItemText (nRow, MOD_FILE, oRow[CFavFiles::MOD_FILE]);
m_lvGrid.ItemPtr (nRow, &oRow);
}
}
/******************************************************************************
** Method: OnAdd()
**
** Description: Add a favourites file for a mod.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CFavouritesDlg::OnAdd()
{
CFavFileDlg Dlg;
Dlg.m_pFavFiles = &m_oFavFiles;
if (Dlg.RunModal(*this) == IDOK)
{
// Update table.
CRow& oRow = m_oFavFiles.CreateRow();
oRow[CFavFiles::MOD_NAME] = Dlg.m_strMod;
oRow[CFavFiles::MOD_FILE] = Dlg.m_strFile;
m_oFavFiles.InsertRow(oRow, false);
// Update view.
int nRow = m_lvGrid.ItemCount();
m_lvGrid.InsertItem(nRow, oRow[CFavFiles::MOD_NAME]);
m_lvGrid.ItemText (nRow, MOD_FILE, oRow[CFavFiles::MOD_FILE]);
m_lvGrid.ItemPtr (nRow, &oRow);
// Make selection.
m_lvGrid.Select(nRow);
}
}
/******************************************************************************
** Method: OnEdit()
**
** Description: Edit the selected mods favourites file.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CFavouritesDlg::OnEdit()
{
int nSel = m_lvGrid.Selection();
// No selection?
if (nSel == LB_ERR)
return;
// Extract the selected row.
CRow& oRow = *static_cast<CRow*>(m_lvGrid.ItemPtr(nSel));
CFavFileDlg Dlg;
Dlg.m_pFavFiles = &m_oFavFiles;
Dlg.m_strMod = oRow[CFavFiles::MOD_NAME];
Dlg.m_strFile = oRow[CFavFiles::MOD_FILE];
// Show the editing dialog.
if (Dlg.RunModal(*this) == IDOK)
{
// Update table.
oRow[CFavFiles::MOD_FILE] = Dlg.m_strFile;
// Update view.
m_lvGrid.ItemText(nSel, MOD_NAME, oRow[CFavFiles::MOD_NAME]);
m_lvGrid.ItemText(nSel, MOD_FILE, oRow[CFavFiles::MOD_FILE]);
}
}
/******************************************************************************
** Method: OnRemove()
**
** Description: Remove the selected mods favourites file.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CFavouritesDlg::OnRemove()
{
size_t nSel = m_lvGrid.Selection();
// No selection?
if (nSel == LB_ERR)
return;
// Extract the selected row.
CRow& oRow = *static_cast<CRow*>(m_lvGrid.ItemPtr(nSel));
// Remove from table and view.
m_oFavFiles.DeleteRow(oRow);
m_lvGrid.DeleteItem(nSel);
// Update selection.
if (nSel == m_lvGrid.ItemCount())
--nSel;
m_lvGrid.Select(nSel);
}