Debian Codegraph @

editor/OrphanRemoveDlg.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 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/editor/OrphanRemoveDlg.cpp $
21 * $Revision: 1.1.1.1 $
22 * $Date: 2003-08-26 03:57:38 $
23 * $Author: kevinb $
24 *
25 * Orphan file delete
26 *
27 * $Log: not supported by cvs2svn $
28 *
29 * 4 4/09/99 3:46p Jeff
30 * handle new texture sound names
31 *
32 * 3 3/19/99 10:34a Jeff
33 * enable/disable controls when thinking
34 *
35 * 2 3/18/99 8:41p Jeff
36 * created orphan hunter dialog
37 *
38 * $NoKeywords: $
39 */
40
41 // OrphanRemoveDlg.cpp : implementation file
42 //
43
44 #include "stdafx.h"
45 #include "editor.h"
46 #include "OrphanRemoveDlg.h"
47 #include "manage.h"
48 #include "doorpage.h"
49 #include "gamefilepage.h"
50 #include "genericpage.h"
51 #include "shippage.h"
52 #include "soundpage.h"
53 #include "texpage.h"
54 #include "weaponpage.h"
55 #include "ddio.h"
56 #include "mem.h"
57
58 #ifdef _DEBUG
59 #define new DEBUG_NEW
60 #undef THIS_FILE
61 static char THIS_FILE[] = __FILE__;
62 #endif
63
64 /////////////////////////////////////////////////////////////////////////////
65 // COrphanRemoveDlg dialog
66
67 COrphanRemoveDlg::COrphanRemoveDlg(CWnd *pParent /*=NULL*/) : CDialog(COrphanRemoveDlg::IDD, pParent) {
68 //{{AFX_DATA_INIT(COrphanRemoveDlg)
69 // NOTE: the ClassWizard will add member initialization here
70 //}}AFX_DATA_INIT
71 }
72
73 void COrphanRemoveDlg::DoDataExchange(CDataExchange *pDX) {
74 CDialog::DoDataExchange(pDX);
75 //{{AFX_DATA_MAP(COrphanRemoveDlg)
76 DDX_Control(pDX, IDC_LIST, m_List);
77 //}}AFX_DATA_MAP
78 }
79
80 BEGIN_MESSAGE_MAP(COrphanRemoveDlg, CDialog)
81 //{{AFX_MSG_MAP(COrphanRemoveDlg)
82 ON_CBN_SELCHANGE(IDC_DIRECTORY, OnSelchangeDirectory)
83 //}}AFX_MSG_MAP
84 END_MESSAGE_MAP()
85
86 /////////////////////////////////////////////////////////////////////////////
87 // COrphanRemoveDlg message handlers
88
89 bool HasFilesCheckedOut(void) {
90 int i;
91 for (i = 0; i < MAX_TRACKLOCKS; i++) {
92 if (GlobalTrackLocks[i].used) {
93 return true;
94 }
95 }
96 return false;
97 }
98
99 bool IsFileInGameFile(char *filename) {
100 int i;
101
102 for (i = 0; i < MAX_GAMEFILES; i++) {
103 if (Gamefiles[i].used) {
104 if (!stricmp(Gamefiles[i].name, filename)) {
105 return true;
106 }
107 }
108 }
109 return false;
110 }
111
112 bool IsFileInDoorPage(char *filename) {
113 mngs_door_page doorpage;
114 int i;
115
116 for (i = 0; i < MAX_DOORS; i++) {
117 if (Doors[i].used) {
118 mng_AssignDoorToDoorPage(i, &doorpage);
119 if (!stricmp(doorpage.close_sound_name, filename))
120 return true;
121 if (!stricmp(doorpage.image_name, filename))
122 return true;
123 if (!stricmp(doorpage.open_sound_name, filename))
124 return true;
125 }
126 }
127 return false;
128 }
129
130 bool IsFileInGenericPage(char *filename) {
131 mngs_generic_page genericpage;
132 int i;
133 int j, x;
134
135 for (i = 0; i < MAX_OBJECT_IDS; i++) {
136 if (Object_info[i].type != OBJ_NONE) {
137 mng_AssignObjInfoToGenericPage(i, &genericpage);
138
139 if (!stricmp(filename, genericpage.image_name))
140 return true;
141 if (!stricmp(filename, genericpage.med_image_name))
142 return true;
143 if (!stricmp(filename, genericpage.lo_image_name))
144 return true;
145 for (j = 0; j < MAX_OBJ_SOUNDS; j++) {
146 if (!stricmp(filename, genericpage.sound_name[j]))
147 return true;
148 }
149 for (j = 0; j < MAX_AI_SOUNDS; j++) {
150 if (!stricmp(filename, genericpage.ai_sound_name[j]))
151 return true;
152 }
153 for (x = 0; x < MAX_WBS_PER_OBJ; x++) {
154 for (j = 0; j < MAX_WB_FIRING_MASKS; j++) {
155 if (!stricmp(filename, genericpage.fire_sound_name[x][j]))
156 return true;
157 }
158 for (j = 0; j < MAX_WB_GUNPOINTS; j++) {
159 if (!stricmp(filename, genericpage.weapon_name[x][j]))
160 return true;
161 }
162 }
163
164 for (x = 0; x < NUM_MOVEMENT_CLASSES; x++)
165 for (j = 0; j < NUM_ANIMS_PER_CLASS; j++) {
166 if (!stricmp(filename, genericpage.anim_sound_name[x][j]))
167 return true;
168 }
169 for (j = 0; j < MAX_DSPEW_TYPES; j++) {
170 if (!stricmp(filename, genericpage.dspew_name[j]))
171 return true;
172 }
173
174 if (genericpage.objinfo_struct.description) {
175 mem_free(genericpage.objinfo_struct.description);
176 }
177 }
178 }
179 return false;
180 }
181
182 bool IsFileInShipPage(char *filename) {
183 mngs_ship_page shippage;
184 int i;
185 int j;
186 int x;
187
188 for (i = 0; i < MAX_SHIPS; i++) {
189 if (Ships[i].used) {
190 mng_AssignShipToShipPage(i, &shippage);
191
192 if (!stricmp(filename, shippage.image_name))
193 return true;
194 if (!stricmp(filename, shippage.dying_image_name))
195 return true;
196 if (!stricmp(filename, shippage.med_image_name))
197 return true;
198 if (!stricmp(filename, shippage.lo_image_name))
199 return true;
200 for (j = 0; j < MAX_PLAYER_WEAPONS; j++) {
201 for (x = 0; x < MAX_WB_GUNPOINTS; x++) {
202 if (!stricmp(filename, shippage.weapon_name[j][x]))
203 return true;
204 }
205 for (x = 0; x < MAX_WB_FIRING_MASKS; x++) {
206 if (!stricmp(filename, shippage.fire_sound_name[j][x]))
207 return true;
208 }
209 if (!stricmp(filename, shippage.firing_sound_name[j]))
210 return true;
211 if (!stricmp(filename, shippage.release_sound_name[j]))
212 return true;
213 if (!stricmp(filename, shippage.spew_powerup_name[j]))
214 return true;
215 }
216 }
217 }
218
219 return false;
220 }
221
222 bool IsFileInSoundPage(char *filename) {
223 mngs_sound_page soundpage;
224 int i;
225
226 for (i = 0; i < MAX_SOUNDS; i++) {
227 if (Sounds[i].used) {
228 mng_AssignSoundToSoundPage(i, &soundpage);
229 if (!stricmp(filename, soundpage.raw_name))
230 return true;
231 }
232 }
233
234 return false;
235 }
236
237 bool IsFileInTexturePage(char *filename) {
238 mngs_texture_page texpage;
239 int i;
240
241 for (i = 0; i < MAX_TEXTURES; i++) {
242 if (GameTextures[i].used) {
243 mng_AssignTextureToTexPage(i, &texpage);
244
245 if (!stricmp(filename, texpage.bitmap_name))
246 return true;
247
248 if (!stricmp(filename, texpage.destroy_name))
249 return true;
250
251 if (!stricmp(filename, texpage.sound_name))
252 return true;
253 }
254 }
255 return false;
256 }
257
258 bool IsFileInWeaponPage(char *filename) {
259 mngs_weapon_page weappage;
260 int i, j;
261
262 for (i = 0; i < MAX_WEAPONS; i++) {
263 if (Weapons[i].used) {
264 mng_AssignWeaponToWeaponPage(i, &weappage);
265
266 if (!stricmp(filename, weappage.hud_image_name))
267 return true;
268 if (!stricmp(filename, weappage.fire_image_name))
269 return true;
270 if (!stricmp(filename, weappage.explode_image_name))
271 return true;
272 if (!stricmp(filename, weappage.smoke_image_name))
273 return true;
274 if (!stricmp(filename, weappage.scorch_image_name))
275 return true;
276 if (!stricmp(filename, weappage.icon_name))
277 return true;
278 if (!stricmp(filename, weappage.spawn_name))
279 return true;
280 if (!stricmp(filename, weappage.alternate_spawn_name))
281 return true;
282 if (!stricmp(filename, weappage.particle_name))
283 return true;
284 if (!stricmp(filename, weappage.robot_spawn_name))
285 return true;
286 for (j = 0; j < MAX_WEAPON_SOUNDS; j++) {
287 if (!stricmp(filename, weappage.sound_name[j]))
288 return true;
289 }
290 }
291 }
292
293 return false;
294 }
295
296 void COrphanRemoveDlg::Enable(bool enable) {
297 CWnd *wnd;
298
299 wnd = (CWnd *)GetDlgItem(IDOK);
300 wnd->EnableWindow(enable);
301
302 wnd = (CWnd *)GetDlgItem(IDCANCEL);
303 wnd->EnableWindow(enable);
304
305 wnd = (CWnd *)GetDlgItem(IDC_DIRECTORY);
306 wnd->EnableWindow(enable);
307 }
308
309 void COrphanRemoveDlg::SetStatus(char *status) {
310 CWnd *stat = (CWnd *)GetDlgItem(IDC_STATUS);
311 stat->SetWindowText(status);
312 Descent->defer();
313 }
314
315 void COrphanRemoveDlg::OnOK() {
316 if (HasFilesCheckedOut()) {
317 OutrageMessageBox("You can't have any files checked out file doing this operation");
318 return;
319 }
320
321 if (MessageBox("Are you sure you want to remove the orphans permanently?", NULL, MB_YESNO) != IDYES)
322 return;
323 SetStatus("Deleting Files");
324
325 char directory[_MAX_PATH];
326 CString dir;
327 CComboBox *combo = (CComboBox *)GetDlgItem(IDC_DIRECTORY);
328 int sel = combo->GetCurSel();
329 if (sel == -1)
330 return;
331 combo->GetLBText(sel, dir);
332
333 ddio_MakePath(directory, LocalD3Dir, "data", dir.GetBuffer(0), NULL);
334 char fullpath[_MAX_PATH];
335
336 int size = m_List.GetCount();
337 for (int i = 0; i < size; i++) {
338 if (m_List.GetCheck(i)) {
339 // it's checked...delete!
340 m_List.GetText(i, dir);
341 ddio_MakePath(fullpath, directory, dir.GetBuffer(0), NULL);
342 ddio_DeleteFile(fullpath);
343 }
344 }
345
346 SetStatus("Ready...");
347
348 OnSelchangeDirectory();
349 }
350
351 char *orphan_ignore[] = {
352 ".", "..", "dallasfuncs.cpp", "osiris_common.h", "osiris_import.h", "osiris_vector.h",
353 "anarchy.str", "coop.str", "ctf.str", "entropy.str", "dmfc.str", "d3.str",
354 "hoard.str", "dp_modem.str", "dp_serial.str", "hyper.str", "ipxclient.str", "lanclient.str",
355 "monster.str", "mtclient.str", "tanarchy.str"};
356 int num_orphan_ignore = sizeof(orphan_ignore) / sizeof(char *);
357
358 bool IsFileUsed(char *filename) {
359 bool found = false;
360
361 for (int i = 0; i < num_orphan_ignore; i++) {
362 if (!stricmp(filename, orphan_ignore[i])) {
363 found = true;
364 goto done;
365 }
366 }
367
368 if (!found)
369 found = IsFileInGameFile(filename);
370 if (!found)
371 found = IsFileInWeaponPage(filename);
372 if (!found)
373 found = IsFileInSoundPage(filename);
374 if (!found)
375 found = IsFileInShipPage(filename);
376 if (!found)
377 found = IsFileInDoorPage(filename);
378 if (!found)
379 found = IsFileInTexturePage(filename);
380 if (!found)
381 found = IsFileInGenericPage(filename);
382
383 done:
384 Descent->defer();
385
386 return found;
387 }
388
389 int filelen(char *filename, char *dir) {
390 char path[_MAX_PATH];
391 ddio_MakePath(path, dir, filename, NULL);
392 CFILE *cf = cfopen(filename, "rb");
393 if (!cf)
394 return 0;
395
396 int len = cfilelength(cf);
397 cfclose(cf);
398 return len;
399 }
400
401 bool isdirectory(char *filename, char *basepath) {
402 char fullpath[_MAX_PATH];
403 ddio_MakePath(fullpath, basepath, filename, NULL);
404 char olddir[_MAX_PATH];
405
406 ddio_GetWorkingDir(olddir, _MAX_PATH);
407 if (ddio_SetWorkingDir(fullpath)) {
408 ddio_SetWorkingDir(olddir);
409 return true;
410 }
411 return false;
412 }
413
414 void COrphanRemoveDlg::OnSelchangeDirectory() {
415 CString dir;
416 CComboBox *combo = (CComboBox *)GetDlgItem(IDC_DIRECTORY);
417 int sel = combo->GetCurSel();
418 if (sel == -1)
419 return;
420
421 SetStatus("Updating File List");
422
423 Enable(false);
424
425 combo->GetLBText(sel, dir);
426 m_List.ResetContent();
427
428 char fullpath[_MAX_PATH];
429 ddio_MakePath(fullpath, LocalD3Dir, "data", dir.GetBuffer(0), NULL);
430 char oldpath[_MAX_PATH];
431 ddio_GetWorkingDir(oldpath, _MAX_PATH);
432 ddio_SetWorkingDir(fullpath);
433
434 char filename[_MAX_PATH];
435 int num_files = 0;
436 int total_filesize = 0;
437 CWnd *stats = (CWnd *)GetDlgItem(IDC_STATS);
438 char data[256];
439
440 sprintf(data, "Num Files: %d\r\nSize: %dK", 0, 0);
441 stats->SetWindowText(data);
442
443 if (ddio_FindFileStart("*.*", filename)) {
444 if (!isdirectory(filename, fullpath) && !IsFileUsed(filename)) {
445 m_List.AddString(filename);
446 num_files++;
447 total_filesize += filelen(filename, fullpath);
448 sprintf(data, "Num Files: %d\r\nSize: %dK", num_files, total_filesize / 1024);
449 stats->SetWindowText(data);
450 }
451
452 while (ddio_FindNextFile(filename)) {
453 if (!isdirectory(filename, fullpath) && !IsFileUsed(filename)) {
454 m_List.AddString(filename);
455 num_files++;
456 total_filesize += filelen(filename, fullpath);
457 sprintf(data, "Num Files: %d\r\nSize: %dK", num_files, total_filesize / 1024);
458 stats->SetWindowText(data);
459 }
460 }
461 }
462 ddio_FindFileClose();
463
464 ddio_SetWorkingDir(oldpath);
465
466 // select all
467 for (int i = 0; i < num_files; i++) {
468 m_List.SetCheck(i, 1);
469 m_List.SetSel(i, TRUE);
470 }
471
472 SetStatus("Ready...");
473
474 Enable(true);
475 }
476
477 extern char *DirectoryNames[];
478 extern int NumDirectoryNames;
479
480 BOOL COrphanRemoveDlg::OnInitDialog() {
481 CDialog::OnInitDialog();
482 CComboBox *combo = (CComboBox *)GetDlgItem(IDC_DIRECTORY);
483
484 for (int i = 0; i < NumDirectoryNames; i++) {
485 combo->AddString(DirectoryNames[i]);
486 }
487
488 Enable(true);
489
490 SetStatus("Ready...");
491
492 return TRUE;
493 }
494
495 void COrphanRemoveDlg::OnCancel() { CDialog::OnCancel(); }