Debian Codegraph @

editor/FilePageDialog.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 // FilePageDialog.cpp : implementation file
20 //
21
22 #include "stdafx.h"
23 #include "editor.h"
24 #include "ddio.h"
25 #include "gamefile.h"
26 #include "gamefilepage.h"
27 #include "FilePageDialog.h"
28 #include "EditLineDialog.h"
29 #include "pserror.h"
30 #include "mem.h"
31 #include "FilePageAddDlg.h"
32
33 #ifdef _DEBUG
34 #define new DEBUG_NEW
35 #undef THIS_FILE
36 static char THIS_FILE[] = __FILE__;
37 #endif
38
39 char *DirectoryNames[] = {"Graphics", "Rooms", "Sounds", "Models", "Levels", "Briefings",
40 "Misc", "Art", "Scripts", "Music", "Voice"};
41 int NumDirectoryNames = sizeof(DirectoryNames) / sizeof(char *);
42
43 /////////////////////////////////////////////////////////////////////////////
44 // CFilePageDialog dialog
45
46 CFilePageDialog::CFilePageDialog(CWnd *pParent /*=NULL*/) : CDialog(CFilePageDialog::IDD, pParent) {
47 //{{AFX_DATA_INIT(CFilePageDialog)
48 m_DirectoryFilter = _T("");
49 //}}AFX_DATA_INIT
50 }
51
52 void CFilePageDialog::DoDataExchange(CDataExchange *pDX) {
53 CDialog::DoDataExchange(pDX);
54 //{{AFX_DATA_MAP(CFilePageDialog)
55 DDX_Control(pDX, IDC_CHECKEDOUT_LIST, m_CheckedOutListCtrl);
56 DDX_Control(pDX, IDC_FILELIST, m_FileListCtrl);
57 DDX_CBString(pDX, IDC_DIRECTORY_FILTER, m_DirectoryFilter);
58 //}}AFX_DATA_MAP
59 }
60
61 BEGIN_MESSAGE_MAP(CFilePageDialog, CDialog)
62 //{{AFX_MSG_MAP(CFilePageDialog)
63 ON_BN_CLICKED(IDC_ADD_FILE, OnAddFile)
64 ON_BN_CLICKED(IDC_CHECKIN_FILE, OnCheckinFile)
65 ON_BN_CLICKED(IDC_DELETE_FILE, OnDeleteFile)
66 ON_BN_CLICKED(IDC_LOCK_FILE, OnLockFile)
67 ON_BN_CLICKED(IDC_OVERRIDE, OnOverride)
68 ON_BN_CLICKED(IDC_FILES_OUT, OnFilesOut)
69 ON_CBN_SELCHANGE(IDC_DIRECTORY_FILTER, OnSelchangeDirectoryFilter)
70 //}}AFX_MSG_MAP
71 END_MESSAGE_MAP()
72
73 /////////////////////////////////////////////////////////////////////////////
74 // CFilePageDialog message handlers
75
76 void CFilePageDialog::OnAddFile() {
77 if (!Network_up) {
78 OutrageMessageBox("Sorry babe, the network is down. This action is a no-no.\n");
79 return;
80 }
81
82 CFilePageAddDlg dlg;
83
84 dlg.SetInitialPath(LocalD3Dir);
85 if (dlg.DoModal() != IDOK)
86 return;
87
88 char cur_name[100];
89 char pathname[100], name[100], extension[100];
90 int gamefile_handle;
91
92 if (dlg.m_NumberOfSelectedFiles > 0) {
93 ASSERT(dlg.m_SelectedFiles);
94 ASSERT(dlg.m_SelectedDestDir);
95 }
96
97 for (int q = 0; q < dlg.m_NumberOfSelectedFiles; q++) {
98 ASSERT(dlg.m_SelectedFiles[q]);
99 if (!dlg.m_SelectedFiles[q])
100 continue;
101
102 // Okay, we selected a file. Lets do what needs to be done here.
103 ddio_SplitPath(dlg.m_SelectedFiles[q], pathname, name, extension);
104 sprintf(cur_name, "%s%s", name, extension);
105
106 if ((FindGamefileName(cur_name)) != -1) {
107 char buffer[512];
108 sprintf(buffer, "%s already exists in the manage system", cur_name);
109 OutrageMessageBox(buffer);
110 continue;
111 }
112
113 gamefile_handle = AllocGamefile();
114 strcpy(Gamefiles[gamefile_handle].name, cur_name);
115 strcpy(Gamefiles[gamefile_handle].dir_name, dlg.m_SelectedDestDir);
116
117 // Finally, save a local copy of the model/anim and alloc a tracklock
118 mprintf(0, "Making a copy of '%s' locally...\n", cur_name);
119
120 char destname[100];
121 ddio_MakePath(destname, LocalD3Dir, "data", dlg.m_SelectedDestDir, Gamefiles[gamefile_handle].name, NULL);
122 if (stricmp(destname, dlg.m_SelectedFiles[q])) // only copy if they are different
123 cf_CopyFile(destname, dlg.m_SelectedFiles[q]);
124
125 mng_AllocTrackLock(cur_name, PAGETYPE_GAMEFILE);
126
127 // D3EditState.current_gamefile=gamefile_handle;
128 }
129
130 UpdateDialog();
131 }
132
133 void CFilePageDialog::UpdateDialog() {
134 int i;
135 CCheckListBox *list;
136 list = (CCheckListBox *)GetDlgItem(IDC_FILELIST);
137 list->ResetContent();
138 bool all_files = false;
139
140 CComboBox *combo = (CComboBox *)GetDlgItem(IDC_DIRECTORY_FILTER);
141 combo->GetLBText(combo->GetCurSel(), m_DirectoryFilter);
142 if (!stricmp(m_DirectoryFilter.GetBuffer(0), "All Directories")) {
143 all_files = true;
144 }
145
146 for (i = 0; i < MAX_GAMEFILES; i++) {
147
148 if (Gamefiles[i].used && (mng_FindTrackLock(Gamefiles[i].name, PAGETYPE_GAMEFILE) == -1)) {
149 if (all_files) {
150 list->AddString(Gamefiles[i].name);
151 } else {
152 if (!stricmp(Gamefiles[i].dir_name, m_DirectoryFilter.GetBuffer(0))) {
153 list->AddString(Gamefiles[i].name);
154 }
155 }
156 }
157 }
158
159 list = (CCheckListBox *)GetDlgItem(IDC_CHECKEDOUT_LIST);
160 list->ResetContent();
161
162 for (i = 0; i < MAX_TRACKLOCKS; i++) {
163 if (GlobalTrackLocks[i].used && GlobalTrackLocks[i].pagetype == PAGETYPE_GAMEFILE) {
164 list->AddString(GlobalTrackLocks[i].name);
165 }
166 }
167 }
168
169 int CFilePageDialog::CreateIndexMap(int **index_map, int listbox_id) {
170 int r, n;
171 CCheckListBox *list = (CCheckListBox *)GetDlgItem(listbox_id);
172 if (!list)
173 return 0;
174
175 int listbox_size = list->GetCount();
176 int listbox_count = 0;
177 for (r = 0; r < listbox_size; r++) {
178 if (list->GetCheck(r))
179 listbox_count++;
180 }
181 if (listbox_count == 0)
182 return 0;
183
184 int *map;
185
186 map = *index_map = (int *)mem_malloc(sizeof(int) * listbox_count);
187 if (!map)
188 return 0;
189 n = 0;
190 for (r = 0; r < listbox_size; r++) {
191 if (list->GetCheck(r)) {
192 map[n] = r;
193 n++;
194 }
195 }
196 return listbox_count;
197 }
198
199 int FindGameFile(char *name) {
200 for (int i = 0; i < MAX_GAMEFILES; i++) {
201 if (Gamefiles[i].used && !stricmp(name, Gamefiles[i].name))
202 return i;
203 }
204 return -1;
205 }
206
207 void CFilePageDialog::OnCheckinFile() {
208 int r, n;
209 mngs_Pagelock temp_pl;
210
211 if (Num_gamefiles < 1)
212 return;
213
214 int *listbox_map;
215 int listbox_count = CreateIndexMap(&listbox_map, IDC_CHECKEDOUT_LIST);
216 if (!listbox_count)
217 return;
218
219 if (!mng_MakeLocker()) {
220 mem_free(listbox_map);
221 return;
222 }
223
224 CCheckListBox *list = (CCheckListBox *)GetDlgItem(IDC_CHECKEDOUT_LIST);
225 char buffer[_MAX_PATH], ext[_MAX_EXT];
226
227 for (int i = 0; i < listbox_count; i++) {
228 list->GetText(listbox_map[i], buffer);
229 ddio_SplitPath(buffer, NULL, NULL, ext);
230 if ((!stricmp(ext, ".d3l")) || (!stricmp(ext, ".cpp"))) {
231 if (MessageBox("Tisk Tisk, Now there you go, ignoring Jeff when he told you not to check levels and scripts\nin "
232 "through this dialog. Are you sure you want to ignore Jeff?\n(He doesn't like to be ignored)",
233 buffer, MB_YESNO) != IDYES)
234 continue;
235 }
236
237 n = FindGameFile(buffer);
238 if (n == -1)
239 continue;
240
241 // Make sure we own this gamefile
242 strcpy(temp_pl.name, Gamefiles[n].name);
243 temp_pl.pagetype = PAGETYPE_GAMEFILE;
244
245 r = mng_CheckIfPageOwned(&temp_pl, TableUser);
246 if (r < 0)
247 OutrageMessageBox(ErrorString);
248 else if (r == 0)
249 OutrageMessageBox(InfoString);
250 else {
251 // Change the pagelock state to UNLOCKED
252 strcpy(temp_pl.holder, "UNLOCKED");
253 if (!mng_ReplacePagelock(temp_pl.name, &temp_pl)) {
254 MessageBox(ErrorString, "Error!");
255 continue;
256 } else {
257 // Now actually replace the copy on the net with our local one
258
259 if (!mng_ReplacePage(Gamefiles[n].name, Gamefiles[n].name, n, PAGETYPE_GAMEFILE, 0))
260 OutrageMessageBox(ErrorString);
261 else {
262 // Save this gamefile file to the network for all
263
264 char destname[100], srcname[100];
265
266 ddio_MakePath(srcname, LocalD3Dir, "data", Gamefiles[n].dir_name, Gamefiles[n].name, NULL);
267 ddio_MakePath(destname, NetD3Dir, "data", Gamefiles[n].dir_name, Gamefiles[n].name, NULL);
268
269 cf_CopyFile(destname, srcname);
270
271 //@@OutrageMessageBox ("File checked in.");
272
273 // Delete it from local pagefile if its there
274 int dret = mng_DeletePage(Gamefiles[n].name, PAGETYPE_GAMEFILE, 1);
275 ASSERT(dret == 1);
276
277 // Free the tracklock
278 int p = mng_FindTrackLock(Gamefiles[n].name, PAGETYPE_GAMEFILE);
279 ASSERT(p != -1);
280 mng_FreeTrackLock(p);
281 }
282 }
283 }
284 }
285
286 mng_EraseLocker();
287 OutrageMessageBox("File(s) checked in.");
288 mem_free(listbox_map);
289 UpdateDialog();
290 }
291
292 void CFilePageDialog::OnDeleteFile() {
293 int n;
294 int answer, tl;
295 mngs_Pagelock pl;
296
297 if (Num_gamefiles < 1)
298 return;
299
300 int *listbox_map;
301 int listbox_count = CreateIndexMap(&listbox_map, IDC_CHECKEDOUT_LIST);
302 if (!listbox_count)
303 return;
304
305 if (!mng_MakeLocker()) {
306 mem_free(listbox_map);
307 return;
308 }
309
310 CCheckListBox *list = (CCheckListBox *)GetDlgItem(IDC_CHECKEDOUT_LIST);
311 char buffer[_MAX_PATH];
312
313 for (int i = 0; i < listbox_count; i++) {
314 list->GetText(listbox_map[i], buffer);
315 n = FindGameFile(buffer);
316 if (n == -1)
317 continue;
318
319 // Check to see if we even have it locked
320 if ((tl = mng_FindTrackLock(Gamefiles[n].name, PAGETYPE_GAMEFILE)) == -1) {
321 OutrageMessageBox("This gamefile is not yours to delete. Lock first.");
322 continue;
323 }
324
325 // Make sure its to be deleted
326 answer = MessageBox("Are you sure you want to delete this gamefile?", Gamefiles[n].name, MB_YESNO);
327 if (answer == IDNO)
328 continue;
329
330 strcpy(pl.name, Gamefiles[n].name);
331 pl.pagetype = PAGETYPE_GAMEFILE;
332
333 // Check to see if this is a local gamefile only. If so, only delete it locally
334 if (mng_CheckIfPageOwned(&pl, TableUser) != 1) {
335 mng_FreeTrackLock(tl);
336 if (!mng_DeletePage(Gamefiles[n].name, PAGETYPE_GAMEFILE, 1)) {
337 mprintf(0, ErrorString);
338 Int3();
339 }
340 } else // if its network, delete it from both the net and local drives
341 {
342
343 mng_FreeTrackLock(tl);
344 mng_DeletePage(Gamefiles[n].name, PAGETYPE_GAMEFILE, 1);
345 mng_DeletePage(Gamefiles[n].name, PAGETYPE_GAMEFILE, 0);
346 mng_DeletePagelock(Gamefiles[n].name, PAGETYPE_GAMEFILE);
347 }
348
349 FreeGamefile(n);
350 }
351
352 mng_EraseLocker();
353 OutrageMessageBox("Gamefile(s) deleted.");
354 mem_free(listbox_map);
355 UpdateDialog();
356 }
357
358 void CFilePageDialog::OnLockFile() {
359 int r, n;
360 mngs_Pagelock temp_pl;
361 mngs_gamefile_page gamefilepage;
362
363 if (Num_gamefiles < 1)
364 return;
365
366 int *listbox_map;
367 int listbox_count = CreateIndexMap(&listbox_map, IDC_FILELIST);
368 if (!listbox_count)
369 return;
370
371 if (!mng_MakeLocker()) {
372 mem_free(listbox_map);
373 return;
374 }
375
376 CCheckListBox *list = (CCheckListBox *)GetDlgItem(IDC_FILELIST);
377 char buffer[_MAX_PATH], ext[_MAX_EXT];
378
379 for (int i = 0; i < listbox_count; i++) {
380 list->GetText(listbox_map[i], buffer);
381 ddio_SplitPath(buffer, NULL, NULL, ext);
382 if ((!stricmp(ext, ".d3l")) || (!stricmp(ext, ".cpp"))) {
383 if (MessageBox("Tisk Tisk, Now there you go, ignoring Jeff when he told you not to check levels and scripts\nout "
384 "through this dialog. Are you sure you want to ignore Jeff?\n(He doesn't like to be ignored)",
385 buffer, MB_YESNO) != IDYES)
386 continue;
387 }
388
389 n = FindGameFile(buffer);
390 if (n == -1)
391 continue;
392
393 // Make sure it can be locked
394 strcpy(temp_pl.name, Gamefiles[n].name);
395 temp_pl.pagetype = PAGETYPE_GAMEFILE;
396
397 r = mng_CheckIfPageLocked(&temp_pl);
398 if (r == 2) {
399 int answer;
400 answer = OutrageMessageBox(MBOX_YESNO, "This page is not even in the table file, or the database maybe corrupt. "
401 "Override to 'Unlocked'? (Select NO if you don't know what you're doing)");
402 if (answer == IDYES) {
403 strcpy(temp_pl.holder, "UNLOCKED");
404 if (!mng_ReplacePagelock(temp_pl.name, &temp_pl))
405 MessageBox(ErrorString, "Error!");
406 }
407 } else if (r < 0)
408 OutrageMessageBox(ErrorString);
409 else if (r == 1)
410 OutrageMessageBox(InfoString);
411 else {
412
413 // Everything is ok. Tell the network we're locking it and get a copy to
414 // our local drive
415 strcpy(temp_pl.holder, TableUser);
416
417 // Search thru the net pagefile and get a new copy in RAM in case anyone
418 // changed it since we started the editor
419 if (mng_FindSpecificGamefilePage(temp_pl.name, &gamefilepage, 0)) {
420 if (mng_AssignGamefilePageToGamefile(&gamefilepage, n)) {
421 if (!mng_ReplacePage(Gamefiles[n].name, Gamefiles[n].name, n, PAGETYPE_GAMEFILE, 1)) {
422 OutrageMessageBox("There was problem writing that page locally!");
423 continue;
424 } else {
425
426 if (!mng_ReplacePagelock(temp_pl.name, &temp_pl)) {
427 MessageBox(ErrorString, "Error!");
428 continue;
429 }
430 }
431
432 } else
433 OutrageMessageBox("There was a problem loading this gamefile. You might encounter problems in dealing with "
434 "it. Good luck!");
435
436 mng_AllocTrackLock(Gamefiles[n].name, PAGETYPE_GAMEFILE);
437
438 } else
439 OutrageMessageBox("Couldn't find that gamefile in the table file!");
440 }
441 }
442
443 mng_EraseLocker();
444 OutrageMessageBox("File(s) locked.");
445 mem_free(listbox_map);
446 UpdateDialog();
447 }
448
449 BOOL CFilePageDialog::OnInitDialog() {
450 CDialog::OnInitDialog();
451
452 CComboBox *combo = (CComboBox *)GetDlgItem(IDC_DIRECTORY_FILTER);
453 combo->ResetContent();
454 combo->AddString("All Directories");
455 for (int i = 0; i < NumDirectoryNames; i++) {
456 combo->AddString(DirectoryNames[i]);
457 }
458
459 combo->SetCurSel(0);
460 UpdateData(true);
461
462 UpdateDialog();
463
464 return TRUE; // return TRUE unless you set the focus to a control
465 // EXCEPTION: OCX Property Pages should return FALSE
466 }
467
468 void CFilePageDialog::OnOverride() {
469 int n;
470 mngs_Pagelock temp_pl;
471
472 if (Num_gamefiles < 1)
473 return;
474
475 int *listbox_map;
476 int listbox_count = CreateIndexMap(&listbox_map, IDC_FILELIST);
477 if (!listbox_count)
478 return;
479
480 CCheckListBox *list = (CCheckListBox *)GetDlgItem(IDC_FILELIST);
481 char buffer[_MAX_PATH];
482
483 for (int i = 0; i < listbox_count; i++) {
484 list->GetText(listbox_map[i], buffer);
485 n = FindGameFile(buffer);
486 if (n == -1)
487 continue;
488
489 strcpy(temp_pl.name, Gamefiles[n].name);
490 temp_pl.pagetype = PAGETYPE_GAMEFILE;
491
492 mng_OverrideToUnlocked(&temp_pl);
493 }
494
495 mem_free(listbox_map);
496 }
497
498 void CFilePageDialog::OnFilesOut() {
499 char str[10000];
500 int total = 0;
501
502 mng_DisplayLockList(TableUser);
503
504 sprintf(str, "User %s has these files held locally:\n\n", TableUser);
505 for (int i = 0; i < MAX_TRACKLOCKS; i++) {
506 if (GlobalTrackLocks[i].used && GlobalTrackLocks[i].pagetype == PAGETYPE_GAMEFILE) {
507 char temp[90];
508
509 sprintf(temp, "%s", GlobalTrackLocks[i].name);
510 strcat(str, temp);
511 strcat(str, "\n");
512 total++;
513 }
514 }
515
516 if (total != 0) {
517 // Display that string
518 MessageBox(str, "Game files", MB_OK);
519 }
520 }
521
522 void CFilePageDialog::OnSelchangeDirectoryFilter() {
523 UpdateData(true);
524 UpdateDialog();
525 }
526
527 ////////////////////////////////////////////////////////////////////
528 /////////////////////////////////////////////////////////////////////////////