Debian Codegraph @

editor/ScriptLevelInterface.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/ScriptLevelInterface.cpp $
21 * $Revision: 1.1.1.1 $
22 * $Date: 2003-08-26 03:57:38 $
23 * $Author: kevinb $
24 *
25 * ScriptLevelInterface.cpp : implementation file
26 *
27 * $Log: not supported by cvs2svn $
28 *
29 * 24 5/11/99 12:13p Jason
30 * added checks for messed up gamefiles
31 *
32 * 23 2/25/99 12:34p Jeff
33 * don't display message that someone has a file checked out during mass
34 * compile
35 *
36 * 22 2/24/99 9:39p Jeff
37 * only sync scripts when needed
38 *
39 * 21 2/23/99 11:52p Jeff
40 * new script dll sync dialog
41 *
42 * 20 2/21/99 8:04p Jeff
43 * better handling of out-of-sync scripts
44 *
45 * 19 2/18/99 8:29p Nate
46 * commented out some manage code
47 *
48 * 18 2/18/99 10:58a Jeff
49 * added a 'find in files' for gamefiles manage system
50 *
51 * 17 2/17/99 6:54p Jeff
52 * added check box for auto check in/out scripts with levels...fix
53 * checksum mprintf bug
54 *
55 * 16 2/09/99 4:43p Jeff
56 * fixed resource leak
57 *
58 * 15 2/01/99 11:55a Jeff
59 * automatically check in/out .msg and .str files
60 *
61 * 14 1/13/99 5:01p Jeff
62 * don't auto-checkin dll if the .cpp doesn't get checked in for a new
63 * file
64 *
65 * 13 1/11/99 3:34p Jeff
66 * added checks for when going editor->game to see if scripts are out of
67 * date, if so give the option of breaking out. Add some options to mass
68 * script compiler, along with a toolbar shortcut.
69 *
70 * 12 1/05/99 4:54p Jeff
71 * save the last script edited and set the on init
72 *
73 * 11 1/05/99 4:33p Jeff
74 * when "Display non checkout files" is checked, display the .cpp files in
75 * the directory...not just whats in the table file
76 *
77 * 10 12/21/98 6:41p Jeff
78 * auto-compile, check in and check back out for when new scripts are
79 * created. (yes must be said to the data update)
80 *
81 * 9 12/20/98 9:57p Jeff
82 * added ability to display scripts not checked out. don't display
83 * message on checkin/out
84 *
85 * 8 12/18/98 12:11p Jeff
86 * created a function to determine a script's type and hooked it in
87 *
88 * 7 12/18/98 12:11p Jeff
89 * added mass script compile dialog
90 *
91 * 6 12/18/98 10:40a Jeff
92 * save out settings to registry
93 *
94 * 5 12/13/98 7:50p Jeff
95 * automatically add new DLLs that aren't in the manage
96 * system...implemented create new script function, even though it's still
97 * in infancy.
98 *
99 * 4 12/13/98 3:10a Jeff
100 * fixed some bugs. Automatically check in/out/etc .dll when operating
101 * with .cpp. Hooked in compiler and compiler configuration. Very
102 * complete.
103 *
104 * 3 12/11/98 10:34p Jeff
105 * Updated the script/level interface, all manage system integration is
106 * complete. External Script Editor loading is setup too.
107 *
108 * 2 12/11/98 5:50p Jeff
109 * implemented and added changes regarding Level&Scripting manage system
110 * and compiler interface
111 *
112 * $NoKeywords: $
113 */
114
115 // ScriptLevelInterface.cpp : implementation file
116 //
117
118 #include "stdafx.h"
119 #include "editor.h"
120 #include "ScriptLevelInterface.h"
121 #include "CreateNewScriptDlg.h"
122 #include "VirtualCompilerConfig.h"
123 #include "ScriptMassCompile.h"
124 #include "gamefile.h"
125 #include "gamefilepage.h"
126 #include "descent.h"
127 #include "mono.h"
128 #include "ddio.h"
129 #include "pserror.h"
130 #include "manage.h"
131 #include "mem.h"
132 #include "ScriptCompilerAPI.h"
133 #include "AppDatabase.h"
134 #include "Descent.h"
135 #include "ScriptSyncDialog.h"
136
137 #ifdef _DEBUG
138 #define new DEBUG_NEW
139 #undef THIS_FILE
140 static char THIS_FILE[] = __FILE__;
141 #endif
142
143 bool AddNewGameFile(char *fullpath, char *directory);
144 bool DeleteGamefile(char *tempbuffer);
145 bool CheckInGamefile(char *tempbuffer, bool giveok);
146 bool CheckOutGamefile(char *tempbuffer, bool show_ok_confirmation, bool report_who_has_locked = true);
147
148 char LastScriptSelected[256];
149 bool Scripts_need_sync = true;
150
151 /////////////////////////////////////////////////////////////////////////////
152 // CScriptLevelInterface dialog
153
154 CScriptLevelInterface::CScriptLevelInterface(CWnd *pParent /*=NULL*/) : CDialog(CScriptLevelInterface::IDD, pParent) {
155 //{{AFX_DATA_INIT(CScriptLevelInterface)
156 m_ViewType = -1;
157 m_ScriptType = 0;
158 m_ShowNonCheckedOut = FALSE;
159 m_AutoCheckScripts = FALSE;
160 //}}AFX_DATA_INIT
161
162 InCritical = false;
163 }
164
165 void CScriptLevelInterface::DoDataExchange(CDataExchange *pDX) {
166 CDialog::DoDataExchange(pDX);
167 //{{AFX_DATA_MAP(CScriptLevelInterface)
168 DDX_Control(pDX, IDC_LIST_AVAILABLE, m_ListAvailable);
169 DDX_Control(pDX, IDC_LIST_CHECKEDOUT, m_ListCheckedOut);
170 DDX_Control(pDX, IDC_SELECTED_SCRIPT, m_ScriptToCompile);
171 DDX_Radio(pDX, IDC_RADIO_LEVELS, m_ViewType);
172 DDX_Radio(pDX, IDC_SCRIPTGAME, m_ScriptType);
173 DDX_Check(pDX, IDC_LIST_NONCHECKED_OUT, m_ShowNonCheckedOut);
174 DDX_Check(pDX, IDC_AUTOCHECKSCRIPTS, m_AutoCheckScripts);
175 //}}AFX_DATA_MAP
176 }
177
178 BEGIN_MESSAGE_MAP(CScriptLevelInterface, CDialog)
179 //{{AFX_MSG_MAP(CScriptLevelInterface)
180 ON_BN_CLICKED(IDC_CHECKOUT, OnCheckout)
181 ON_BN_CLICKED(IDC_CHECKIN, OnCheckin)
182 ON_BN_CLICKED(IDC_UNDOCHECKOUT, OnUndocheckout)
183 ON_BN_CLICKED(IDC_RADIO_SCRIPTS, OnRadioScripts)
184 ON_BN_CLICKED(IDC_RADIO_LEVELS, OnRadioLevels)
185 ON_BN_CLICKED(IDC_COMPILE, OnCompile)
186 ON_BN_CLICKED(IDC_EDITSCRIPT, OnEditscript)
187 ON_CBN_CLOSEUP(IDC_SELECTED_SCRIPT, OnCloseupSelectedScript)
188 ON_BN_CLICKED(IDC_ADDNEW, OnAddnew)
189 ON_BN_CLICKED(IDC_DELETE, OnDelete)
190 ON_BN_CLICKED(IDC_CREATESCRIPT, OnCreatescript)
191 ON_WM_CLOSE()
192 ON_WM_DESTROY()
193 ON_BN_CLICKED(IDC_CONFIGCOMPILER, OnConfigcompiler)
194 ON_BN_CLICKED(IDC_MASSCOMPILE, OnMasscompile)
195 ON_CBN_SELCHANGE(IDC_SELECTED_SCRIPT, OnSelchangeSelectedScript)
196 ON_BN_CLICKED(IDC_LIST_NONCHECKED_OUT, OnListNoncheckedOut)
197 //}}AFX_MSG_MAP
198 END_MESSAGE_MAP()
199
200 /////////////////////////////////////////////////////////////////////////////
201 // CScriptLevelInterface message handlers
202
203 void CScriptLevelInterface::SetStatus(char *str) {
204 CWnd *wnd = (CWnd *)GetDlgItem(IDC_STATUS);
205 wnd->SetWindowText(str);
206 Descent->defer();
207 }
208
209 void CScriptLevelInterface::OnCheckout() {
210 UpdateData(true);
211 InCritical = true;
212 SetStatus("Checking out files");
213 if (m_ViewType == 0) {
214 // we're working with levels & level scripts
215 if (CheckOutLevels())
216 UpdateDialog();
217 } else {
218 // we're working with game scripts
219 if (CheckOutScripts())
220 UpdateDialog();
221 }
222 InCritical = false;
223 SetStatus("Ready");
224 Scripts_need_sync = true;
225 }
226
227 void CScriptLevelInterface::OnCheckin() {
228 UpdateData(true);
229 InCritical = true;
230 SetStatus("Checking in files");
231 if (m_ViewType == 0) {
232 // we're working with levels & level scripts
233 if (CheckInLevels())
234 UpdateDialog();
235 } else {
236 // we're working with game scripts
237 if (CheckInScripts())
238 UpdateDialog();
239 }
240 InCritical = false;
241 SetStatus("Ready");
242 }
243
244 void CScriptLevelInterface::OnUndocheckout() {
245 UpdateData(true);
246 InCritical = true;
247 SetStatus("Undoing Checkout on files");
248 if (m_ViewType == 0) {
249 // we're working with levels & level scripts
250 if (UndoCheckOutLevels())
251 UpdateDialog();
252 } else {
253 // we're working with game scripts
254 if (UndoCheckOutScripts())
255 UpdateDialog();
256 }
257 InCritical = false;
258 SetStatus("Ready");
259 Scripts_need_sync = true;
260 }
261
262 void CScriptLevelInterface::OnRadioScripts() { UpdateDialog(); }
263
264 void CScriptLevelInterface::OnRadioLevels() { UpdateDialog(); }
265
266 CEdit *CompileOutputWindow;
267 CString CompileOutputData;
268
269 void CompileOutputCallback(char *str) {
270 CompileOutputData += str;
271 CompileOutputWindow->SetWindowText(CompileOutputData);
272 }
273
274 void CScriptLevelInterface::OnCompile() {
275 UpdateData(true);
276
277 SetStatus("Compiling...");
278
279 bool dll_exist = true;
280
281 char buffer[_MAX_PATH], filename[_MAX_PATH];
282 m_ScriptToCompile.GetLBText(m_ScriptToCompile.GetCurSel(), buffer);
283 ddio_SplitPath(buffer, NULL, filename, NULL);
284 strcat(filename, ".dll");
285 if (!cfexist(filename)) {
286 // there isn't a dll yet...lets make sure one isn't in the manage system
287 bool found;
288 int i;
289
290 found = false;
291 for (i = 0; i < MAX_GAMEFILES; i++) {
292 if (Gamefiles[i].used && (!stricmp(filename, Gamefiles[i].name))) {
293 found = true;
294 break;
295 }
296 }
297
298 if (!found) {
299 // ok there wasn't one in the gamefiles make sure there isn't a tracklocked
300 if (mng_FindTrackLock(filename, PAGETYPE_GAMEFILE) == -1) {
301 // there isn't one in the track lock...this is our first compile!
302 dll_exist = false;
303 }
304 }
305 }
306
307 tCompilerInfo ci;
308 ci.callback = CompileOutputCallback;
309 ci.script_type = (m_ScriptType == 0) ? ST_GAME : ST_LEVEL;
310 strcpy(ci.source_filename, buffer);
311 CompileOutputWindow = (CEdit *)GetDlgItem(IDC_COMPILER_OUTPUT);
312 CompileOutputData = "";
313
314 ScriptCompile(&ci);
315
316 SetStatus("Ready");
317 CompileOutputData = ""; // no need for this to hang around
318
319 if (!dll_exist && cfexist(filename)) {
320 // yeah! we created a dll, ask the user if they want to put it into the manage system
321 if (Network_up) {
322 sprintf(buffer,
323 "Congratulations! It looks like a dll was successfully created. I\ndon't see the DLL in the manage "
324 "system, so\nwould you like me to add it into the manage system for you?(HIGHLY recommended)");
325 if (MessageBox(buffer, "Congratulations", MB_YESNO) == IDYES) {
326 ddio_MakePath(buffer, LocalScriptDir, filename, NULL);
327 if (!cfexist(buffer)) {
328 sprintf(buffer,
329 "I can't seem to find %s in your data\\scripts directory...Sorry,\nbut I can't automatically add it "
330 "for you.\nYou'll have to manually add %s into the manage system.",
331 filename, filename);
332 MessageBox(buffer, "Uh Oh!", MB_OK);
333 } else {
334 if (AddNewGameFile(buffer, "scripts")) {
335 sprintf(buffer,
336 "%s has been added into the manage system. Don't forget to check it in to make sure it stays in "
337 "the\nmanage system!",
338 filename);
339 MessageBox(buffer, "Success", MB_OK);
340 } else {
341 sprintf(buffer,
342 "There was a problem adding %s\ninto the manage system. You'll have\nto do it automatically.",
343 filename);
344 MessageBox(buffer, "Error", MB_OK);
345 }
346 }
347 }
348 } else {
349 sprintf(buffer, "Doh! Congratulations! You compiled the DLL successfully. However,\nI don't see it in the "
350 "manage system. I'd offer to add it\nautomatically for you, but you said NO to the\ndata "
351 "update. You'll have to add it manually.");
352 MessageBox(buffer, "Doh!", MB_OK);
353 }
354 }
355 }
356
357 void CScriptLevelInterface::OnEditscript() {
358 CComboBox *combo = (CComboBox *)GetDlgItem(IDC_SELECTED_SCRIPT);
359 if (!combo)
360 return;
361
362 char tempbuf[_MAX_PATH], fullpath[_MAX_PATH];
363
364 int index = combo->GetCurSel();
365 combo->GetLBText(index, tempbuf);
366
367 if (m_ShowNonCheckedOut && (mng_FindTrackLock(tempbuf, PAGETYPE_GAMEFILE) == -1)) {
368 // display a warning that this file is not checked out
369 MessageBox("This file is NOT checked out, you'll lose all changes on your\nnext data update!", "Warning", MB_OK);
370 }
371
372 ddio_MakePath(fullpath, LocalScriptDir, tempbuf, NULL);
373 if (!cfexist(fullpath)) {
374 sprintf(tempbuf, "Weird, I couldn't find %s to open...", fullpath);
375 MessageBox(tempbuf, "Error", MB_OK);
376 return;
377 }
378
379 SHELLEXECUTEINFO sei;
380
381 sei.cbSize = sizeof(sei);
382 sei.fMask = SEE_MASK_NOCLOSEPROCESS;
383 sei.hwnd = m_hWnd;
384 sei.lpVerb = "open";
385 sei.lpFile = fullpath;
386 sei.lpParameters = NULL;
387 sei.lpDirectory = LocalScriptDir;
388 sei.nShow = SW_NORMAL;
389
390 // int res = (int)ShellExecute(m_hWnd,"open",fullpath,NULL,LocalScriptDir,0);
391 int res;
392
393 ShellExecuteEx(&sei);
394 res = (int)sei.hInstApp;
395
396 if (res <= 32) {
397 char buffer[256];
398 switch (res) {
399 case 0:
400 strcpy(buffer, "The operating system is out of memory or resources.");
401 break;
402 case ERROR_FILE_NOT_FOUND:
403 strcpy(buffer, "The specified file was not found.");
404 break;
405 case ERROR_PATH_NOT_FOUND:
406 strcpy(buffer, "The specified path was not found.");
407 break;
408 case ERROR_BAD_FORMAT:
409 strcpy(buffer, "The .exe file is invalid (non-Win32� .exe or error in .exe image).");
410 break;
411 case SE_ERR_ACCESSDENIED:
412 strcpy(buffer, "The operating system denied access to the specified file.");
413 break;
414 case SE_ERR_ASSOCINCOMPLETE:
415 strcpy(buffer, "The file name association is incomplete or invalid.");
416 break;
417 case SE_ERR_DDEBUSY:
418 strcpy(buffer, "The DDE transaction could not be completed because other DDE transactions were being processed.");
419 break;
420 case SE_ERR_DDEFAIL:
421 strcpy(buffer, "The DDE transaction failed.");
422 break;
423 case SE_ERR_DDETIMEOUT:
424 strcpy(buffer, "The DDE transaction could not be completed because the request timed out.");
425 break;
426 case SE_ERR_DLLNOTFOUND:
427 strcpy(buffer, "The specified dynamic-link library was not found.");
428 break;
429 // case SE_ERR_FNF:
430 // strcpy(buffer,"The specified file was not found.");
431 // break;
432 case SE_ERR_NOASSOC:
433 strcpy(buffer, "There is no application associated with the given file name extension.\nGet Jeff and he'll fix "
434 "this problem for you quickly and easily.");
435 break;
436 case SE_ERR_OOM:
437 strcpy(buffer, "There was not enough memory to complete the operation.");
438 break;
439 // case SE_ERR_PNF:
440 // strcpy(buffer,"The specified path was not found.");
441 // break;
442 case SE_ERR_SHARE:
443 strcpy(buffer, "A sharing violation occurred.");
444 break;
445 default:
446 strcpy(buffer, "An unknown error occurred");
447 break;
448 }
449 MessageBox(buffer, "Error", MB_OK);
450 }
451
452 Scripts_need_sync = true;
453 }
454
455 void CScriptLevelInterface::OnCloseupSelectedScript() {
456 UpdateData(true);
457
458 SetStatus("Determining script type...");
459
460 char buffer[_MAX_PATH];
461 int currsel = m_ScriptToCompile.GetCurSel();
462 if (currsel >= 0) {
463 m_ScriptToCompile.GetLBText(currsel, buffer);
464
465 strcpy(LastScriptSelected, buffer);
466
467 uint8_t type = DetermineScriptType(buffer);
468
469 switch (type) {
470 case ST_GAME:
471 m_ScriptType = 0;
472 break;
473 case ST_LEVEL:
474 m_ScriptType = 1;
475 break;
476 }
477
478 UpdateData(false);
479 }
480
481 SetStatus("Ready");
482 }
483
484 void CScriptLevelInterface::OnSelchangeSelectedScript() { OnCloseupSelectedScript(); }
485
486 void CScriptLevelInterface::UpdateAvailableWithLevels() {
487 CCheckListBox *list = (CCheckListBox *)GetDlgItem(IDC_LIST_AVAILABLE);
488 if (!list)
489 return;
490
491 list->ResetContent();
492
493 SetStatus("Updating available levels");
494
495 char buffer[_MAX_PATH];
496 int length;
497
498 for (int i = 0; i < MAX_GAMEFILES; i++) {
499 if (Gamefiles[i].used) {
500 // we're only adding .d3l's to this list
501 length = strlen(Gamefiles[i].name);
502 if (!stricmp(&Gamefiles[i].name[length - 4], ".d3l") &&
503 (mng_FindTrackLock(Gamefiles[i].name, PAGETYPE_GAMEFILE) == -1)) {
504 strcpy(buffer, Gamefiles[i].name);
505 buffer[length - 4] = '\0';
506 list->AddString(buffer);
507 }
508 }
509 }
510
511 SetStatus("Ready");
512 }
513
514 void CScriptLevelInterface::UpdateAvailableWithScripts() {
515 CCheckListBox *list = (CCheckListBox *)GetDlgItem(IDC_LIST_AVAILABLE);
516 if (!list)
517 return;
518
519 list->ResetContent();
520
521 SetStatus("Updating available scripts");
522
523 char buffer[_MAX_PATH];
524 int length;
525
526 for (int i = 0; i < MAX_GAMEFILES; i++) {
527 if (Gamefiles[i].used) {
528 // we're only adding .d3l's to this list
529 length = strlen(Gamefiles[i].name);
530 if (!stricmp(&Gamefiles[i].name[length - 4], ".cpp") &&
531 (mng_FindTrackLock(Gamefiles[i].name, PAGETYPE_GAMEFILE) == -1)) {
532 strcpy(buffer, Gamefiles[i].name);
533 buffer[length - 4] = '\0';
534 list->AddString(buffer);
535 }
536 }
537 }
538
539 SetStatus("Ready");
540 }
541
542 void CScriptLevelInterface::UpdateCheckedOutWithLevels() {
543 CCheckListBox *list = (CCheckListBox *)GetDlgItem(IDC_LIST_CHECKEDOUT);
544 if (!list)
545 return;
546
547 list->ResetContent();
548
549 SetStatus("Updating checked out levels");
550
551 char buffer[_MAX_PATH];
552 int length;
553
554 for (int i = 0; i < MAX_TRACKLOCKS; i++) {
555 if (GlobalTrackLocks[i].used && GlobalTrackLocks[i].pagetype == PAGETYPE_GAMEFILE) {
556
557 length = strlen(GlobalTrackLocks[i].name);
558 if (!stricmp(&GlobalTrackLocks[i].name[length - 4], ".d3l")) {
559 strcpy(buffer, GlobalTrackLocks[i].name);
560 buffer[length - 4] = '\0';
561 list->AddString(buffer);
562 }
563 }
564 }
565
566 SetStatus("Ready");
567 }
568
569 void CScriptLevelInterface::UpdateCheckedOutWithScripts() {
570 CCheckListBox *list = (CCheckListBox *)GetDlgItem(IDC_LIST_CHECKEDOUT);
571 if (!list)
572 return;
573
574 list->ResetContent();
575
576 SetStatus("Updating checked out scripts");
577
578 char buffer[_MAX_PATH];
579 int length;
580
581 for (int i = 0; i < MAX_TRACKLOCKS; i++) {
582 if (GlobalTrackLocks[i].used && GlobalTrackLocks[i].pagetype == PAGETYPE_GAMEFILE) {
583
584 length = strlen(GlobalTrackLocks[i].name);
585 if (!stricmp(&GlobalTrackLocks[i].name[length - 4], ".cpp")) {
586 strcpy(buffer, GlobalTrackLocks[i].name);
587 buffer[length - 4] = '\0';
588 list->AddString(buffer);
589 }
590 }
591 }
592
593 SetStatus("Ready");
594 }
595
596 void CScriptLevelInterface::UpdateScriptListWithLevels() {
597 CComboBox *combo = (CComboBox *)GetDlgItem(IDC_SELECTED_SCRIPT);
598 if (!combo)
599 return;
600
601 combo->ResetContent();
602
603 SetStatus("Updating script list of level scripts");
604
605 char buffer[_MAX_PATH];
606 int length, i;
607
608 if (m_ShowNonCheckedOut) {
609 char olddir[_MAX_PATH];
610 ddio_GetWorkingDir(olddir, _MAX_PATH);
611 ddio_SetWorkingDir(LocalScriptDir);
612
613 for (i = 0; i < MAX_GAMEFILES; i++) {
614 if (Gamefiles[i].used) {
615 // look for d3l's
616 length = strlen(Gamefiles[i].name);
617
618 if (length > 4 && !stricmp(&Gamefiles[i].name[length - 4], ".d3l")) {
619 strcpy(buffer, Gamefiles[i].name);
620 buffer[length - 4] = '\0';
621 strcat(buffer, ".cpp");
622
623 // ok we have a d3l, look to see if there is a script available for it
624 char temp[_MAX_PATH];
625 if (ddio_FindFileStart(buffer, temp)) {
626 combo->AddString(buffer);
627 }
628 ddio_FindFileClose();
629 /*
630 for ( int j=0; j<MAX_GAMEFILES;j++){
631 if(!stricmp(Gamefiles[j].name,buffer)){
632 //we found a corresponding script
633 combo->AddString(buffer);
634 break;
635 }
636 }
637 */
638 }
639 }
640 }
641
642 ddio_SetWorkingDir(olddir);
643 } else {
644
645 for (i = 0; i < MAX_TRACKLOCKS; i++) {
646 if (GlobalTrackLocks[i].used && GlobalTrackLocks[i].pagetype == PAGETYPE_GAMEFILE) {
647
648 // look for checked out d3l's
649 length = strlen(GlobalTrackLocks[i].name);
650
651 if (length > 4 && !stricmp(&GlobalTrackLocks[i].name[length - 4], ".d3l")) {
652 strcpy(buffer, GlobalTrackLocks[i].name);
653 buffer[length - 4] = '\0';
654 strcat(buffer, ".cpp");
655
656 // ok we have a checked out d3l, look to see if there is a script available for it
657 for (int j = 0; j < MAX_TRACKLOCKS; j++) {
658 if (!stricmp(GlobalTrackLocks[j].name, buffer)) {
659 // we found a corresponding script...
660 combo->AddString(buffer);
661 break;
662 }
663 }
664 }
665 }
666 }
667 }
668
669 if (LastScriptSelected[0] != '\0' && cfexist(LastScriptSelected))
670 combo->SetCurSel(combo->FindStringExact(0, LastScriptSelected));
671 else
672 combo->SetCurSel(0);
673
674 SetStatus("Ready");
675 }
676
677 void CScriptLevelInterface::UpdateScriptListWithScripts() {
678 CComboBox *combo = (CComboBox *)GetDlgItem(IDC_SELECTED_SCRIPT);
679 if (!combo)
680 return;
681
682 combo->ResetContent();
683
684 SetStatus("Updating script list with scripts");
685
686 char buffer[_MAX_PATH];
687 int length, i;
688
689 if (m_ShowNonCheckedOut) {
690 char olddir[_MAX_PATH];
691 ddio_GetWorkingDir(olddir, _MAX_PATH);
692 ddio_SetWorkingDir(LocalScriptDir);
693
694 if (ddio_FindFileStart("*.cpp", buffer)) {
695 combo->AddString(buffer);
696 while (ddio_FindNextFile(buffer)) {
697 combo->AddString(buffer);
698 }
699 }
700 ddio_FindFileClose();
701
702 ddio_SetWorkingDir(olddir);
703
704 /*
705 for (i=0;i<MAX_GAMEFILES;i++){
706 if(Gamefiles[i].used){
707
708 //look for cpp's
709 length = strlen(Gamefiles[i].name);
710
711 if(length>4 && !stricmp(&Gamefiles[i].name[length-4],".cpp")){
712 strcpy(buffer,Gamefiles[i].name);
713 combo->AddString(buffer);
714 }
715 }
716 }
717 */
718
719 } else {
720
721 for (i = 0; i < MAX_TRACKLOCKS; i++) {
722 if (GlobalTrackLocks[i].used && GlobalTrackLocks[i].pagetype == PAGETYPE_GAMEFILE) {
723
724 // look for checked out cpp's
725 length = strlen(GlobalTrackLocks[i].name);
726
727 if (length > 4 && !stricmp(&GlobalTrackLocks[i].name[length - 4], ".cpp")) {
728 strcpy(buffer, GlobalTrackLocks[i].name);
729 combo->AddString(buffer);
730 }
731 }
732 }
733 }
734
735 if (LastScriptSelected[0] != '\0' && cfexist(LastScriptSelected))
736 combo->SetCurSel(combo->FindStringExact(0, LastScriptSelected));
737 else
738 combo->SetCurSel(0);
739
740 SetStatus("Ready");
741 }
742
743 void CScriptLevelInterface::UpdateDialog() {
744 UpdateData(true);
745
746 CWnd *stat1, *stat2;
747 stat1 = (CWnd *)GetDlgItem(IDC_AVAILABLE_GRP);
748 stat2 = (CWnd *)GetDlgItem(IDC_CHECKEDOUT_GRP);
749
750 if (m_ViewType == 0) {
751 // we're working with levels & level scripts
752 UpdateAvailableWithLevels();
753 UpdateCheckedOutWithLevels();
754 UpdateScriptListWithLevels();
755 stat1->SetWindowText("Levels Available");
756 stat2->SetWindowText("Levels CheckedOut");
757 } else {
758 // we're working with game scripts
759 UpdateAvailableWithScripts();
760 UpdateCheckedOutWithScripts();
761 UpdateScriptListWithScripts();
762 stat1->SetWindowText("Scripts Available");
763 stat2->SetWindowText("Scripts CheckedOut");
764 }
765 }
766
767 BOOL CScriptLevelInterface::OnInitDialog() {
768 CDialog::OnInitDialog();
769 int value;
770 bool bvalue;
771
772 // restore settings
773 if (Database->read_int("EditorScriptViewType", &value)) {
774 m_ViewType = value;
775 } else {
776 m_ViewType = 0;
777 }
778
779 if (Database->read_int("EditorScriptType", &value)) {
780 m_ScriptType = value;
781 } else {
782 m_ScriptType = 0;
783 }
784
785 if (Database->read("EditorScriptShowNonCheckedOut", &bvalue)) {
786 m_ShowNonCheckedOut = bvalue;
787 } else {
788 m_ShowNonCheckedOut = 0;
789 }
790
791 if (Database->read("EditorAutoCheckScriptsWithLevels", &bvalue)) {
792 m_AutoCheckScripts = bvalue;
793 } else {
794 m_AutoCheckScripts = 0;
795 }
796
797 value = 256;
798 if (!Database->read("EditorLastScript", LastScriptSelected, &value)) {
799 LastScriptSelected[0] = '\0';
800 }
801
802 UpdateData(false);
803 UpdateDialog();
804
805 SetStatus("Ready");
806
807 return TRUE;
808 }
809
810 void CScriptLevelInterface::OnAddnew() {
811 InCritical = true;
812 SetStatus("Adding new files");
813
814 if (m_ViewType == 0) {
815 // we're working with levels & level scripts
816 if (AddNewLevel())
817 UpdateDialog();
818 } else {
819 // we're working with game scripts
820 if (AddNewScript())
821 UpdateDialog();
822 }
823 InCritical = false;
824 SetStatus("Ready");
825 Scripts_need_sync = true;
826 }
827
828 void CScriptLevelInterface::OnDelete() {
829 UpdateData(true);
830 InCritical = true;
831 SetStatus("Deleting files");
832
833 if (m_ViewType == 0) {
834 if (DeleteLevel())
835 UpdateDialog();
836 } else {
837 if (DeleteScript())
838 UpdateDialog();
839 }
840
841 InCritical = false;
842 SetStatus("Ready");
843 }
844
845 void CScriptLevelInterface::OnCreatescript() {
846 CCreateNewScriptDlg dlg;
847
848 if (dlg.DoModal()) {
849 int i;
850 char filename[_MAX_PATH];
851 strcpy(filename, dlg.m_Filename.GetBuffer(0));
852
853 // see if we should add this to the manage system
854 for (i = 0; i < MAX_GAMEFILES; i++) {
855 if (Gamefiles[i].used && (!stricmp(Gamefiles[i].name, filename))) {
856 // ok we found the file...no need to add it
857 break;
858 }
859 }
860
861 bool on_network = false;
862
863 if (i < MAX_GAMEFILES || (mng_FindTrackLock(filename, PAGETYPE_GAMEFILE) != -1)) {
864 char buffer[_MAX_PATH];
865 sprintf(buffer,
866 "Just so you know, %s\nalready exists in the manage system, do you still want\nto create a new file of "
867 "the same name?",
868 filename);
869 on_network = true;
870 if (MessageBox(buffer, "Warning", MB_YESNO) != IDYES)
871 return;
872 }
873
874 if (!ScriptCreateEmptyScript(filename, (dlg.m_ScriptType == 0) ? ST_LEVEL : ST_GAME)) {
875 MessageBox("Unable to create file", "Error", MB_OK);
876 return;
877 }
878
879 bool added_to_network = false;
880
881 // we never found the file in the manage system
882 if (!on_network) {
883 if (Network_up) {
884 char buffer[_MAX_PATH + 100];
885 sprintf(buffer, "Do you want to add\n%s\nto the network?", filename);
886
887 if (cfexist(filename) && MessageBox(buffer, "Add to Data", MB_YESNO) == IDYES) {
888 ddio_MakePath(buffer, LocalScriptDir, filename, NULL);
889 AddNewGameFile(buffer, "scripts");
890 UpdateDialog();
891 added_to_network = true;
892 }
893 } else {
894 // doh! they didn't say yes
895 char buffer[_MAX_PATH];
896 sprintf(buffer, "I would ask you if you wanted to add the new\nscript to the manage system, but\nsince you "
897 "said no to the data update, you'll have\nto add it manually");
898 MessageBox(buffer, "Doh!", MB_OK);
899 }
900
901 // now auto-compile the DLL
902 SetStatus("Initial Compile");
903 tCompilerInfo ci;
904 ci.callback = CompileOutputCallback;
905 ci.script_type = (dlg.m_ScriptType == 0) ? ST_LEVEL : ST_GAME;
906 strcpy(ci.source_filename, filename);
907 CompileOutputWindow = (CEdit *)GetDlgItem(IDC_COMPILER_OUTPUT);
908 CompileOutputData = "";
909 ScriptCompile(&ci);
910
911 if (Network_up) {
912 SetStatus("Adding compiled script to manage system");
913 char dllname[_MAX_PATH], buffer[_MAX_PATH];
914 ddio_SplitPath(filename, NULL, dllname, NULL);
915 strcat(dllname, ".dll");
916 if (cfexist(dllname) && added_to_network) {
917 ddio_MakePath(buffer, LocalScriptDir, dllname, NULL);
918 AddNewGameFile(buffer, "scripts");
919 UpdateDialog();
920 }
921
922 SetStatus("Auto-Checking in");
923
924 try_again:
925 if (!mng_MakeLocker())
926 goto try_again;
927
928 bool sscr = CheckInGamefile(filename, false);
929 bool cscr = CheckInGamefile(dllname, false);
930
931 SetStatus("Auto-Checking out");
932 if (sscr)
933 CheckOutGamefile(filename, false);
934 if (cscr)
935 CheckOutGamefile(dllname, false);
936
937 mng_EraseLocker();
938 }
939 }
940 }
941
942 SetStatus("Ready");
943 }
944
945 void CScriptLevelInterface::OnConfigcompiler() {
946 CVirtualCompilerConfig dlg;
947
948 SetStatus("Configuring Compiler");
949 dlg.DoModal();
950 SetStatus("Ready");
951 }
952
953 void CScriptLevelInterface::OnClose() {
954 if (InCritical)
955 return;
956
957 CDialog::OnClose();
958 }
959
960 void CScriptLevelInterface::OnDestroy() { CDialog::OnDestroy(); }
961
962 void CScriptLevelInterface::OnOK() {
963 UpdateData(true);
964
965 // write out settings
966 Database->write("EditorScriptViewType", m_ViewType);
967 Database->write("EditorScriptType", m_ScriptType);
968 Database->write("EditorScriptShowNonCheckedOut", m_ShowNonCheckedOut);
969 Database->write("EditorLastScript", LastScriptSelected, strlen(LastScriptSelected) + 1);
970 Database->write("EditorAutoCheckScriptsWithLevels", m_AutoCheckScripts);
971
972 CDialog::OnOK();
973 }
974
975 void CScriptLevelInterface::OnMasscompile() {
976 CScriptMassCompile dlg;
977 SetStatus("Mass compiling scripts...");
978 dlg.DoModal();
979 UpdateDialog();
980 SetStatus("Ready");
981 }
982
983 void CScriptLevelInterface::OnListNoncheckedOut() { UpdateDialog(); }
984
985 // ======================File Checkin/Checkout Functions======================
986 bool CScriptLevelInterface::AddNewLevel(void) {
987 char filename[255];
988
989 if (!Network_up) {
990 OutrageMessageBox("You need to say Yes on the initial data update, in order to\nadd files\n");
991 return false;
992 }
993
994 // Get the filename of the representing image
995 CString filter = "Descent III Levels (*.d3l)|*.d3l||";
996
997 if (!OpenFileDialog(this, (LPCTSTR)filter, filename, Current_files_dir, sizeof(Current_files_dir)))
998 return false;
999
1000 return AddNewGameFile(filename, "levels");
1001 }
1002
1003 bool CScriptLevelInterface::AddNewScript(void) {
1004 char filename[255];
1005
1006 if (!Network_up) {
1007 OutrageMessageBox("You need to say Yes on the initial data update, in order to\nadd files\n");
1008 return false;
1009 }
1010
1011 // Get the filename of the representing image
1012 CString filter = "Descent III Script Source (*.cpp)|*.cpp|Descent III Compiled Script (*.dll)|*.dll||";
1013
1014 if (!OpenFileDialog(this, (LPCTSTR)filter, filename, Current_files_dir, sizeof(Current_files_dir)))
1015 return false;
1016
1017 return AddNewGameFile(filename, "scripts");
1018 }
1019
1020 bool DeleteGamefile(char *tempbuffer) {
1021 int tl;
1022 mngs_Pagelock pl;
1023 bool removed = false;
1024
1025 // verify that we have it locked
1026 if ((tl = mng_FindTrackLock(tempbuffer, PAGETYPE_GAMEFILE)) == -1) {
1027 OutrageMessageBox("%s is not yours to delete. Hmmm. Get Jeff", tempbuffer);
1028 Int3();
1029 return false;
1030 }
1031
1032 strcpy(pl.name, tempbuffer);
1033 pl.pagetype = PAGETYPE_GAMEFILE;
1034
1035 // Check to see if this is a local gamefile only. If so, only delete it locally
1036 if (mng_CheckIfPageOwned(&pl, TableUser) != 1) {
1037 mng_FreeTrackLock(tl);
1038 if (!mng_DeletePage(tempbuffer, PAGETYPE_GAMEFILE, 1)) {
1039 mprintf(0, ErrorString);
1040 Int3();
1041 } else {
1042 removed = true;
1043 }
1044 } else { // if its network, delete it from both the net and local drives
1045 mng_FreeTrackLock(tl);
1046 mng_DeletePage(tempbuffer, PAGETYPE_GAMEFILE, 1);
1047 mng_DeletePage(tempbuffer, PAGETYPE_GAMEFILE, 0);
1048 mng_DeletePagelock(tempbuffer, PAGETYPE_GAMEFILE);
1049 removed = true;
1050 }
1051
1052 if (removed) {
1053 for (int gf = 0; gf < MAX_GAMEFILES; gf++) {
1054 if (Gamefiles[gf].used && (!stricmp(tempbuffer, Gamefiles[gf].name))) {
1055 FreeGamefile(gf);
1056 break;
1057 }
1058 }
1059 }
1060
1061 return true;
1062 }
1063
1064 bool AddNewGameFile(char *fullpath, char *directory) {
1065 char cur_name[100];
1066 char pathname[100], name[100], extension[100];
1067 int gamefile_handle;
1068
1069 if (!Network_up) {
1070 return false;
1071 }
1072
1073 // Okay, we selected a file. Lets do what needs to be done here.
1074 ddio_SplitPath(fullpath, pathname, name, extension);
1075 sprintf(cur_name, "%s%s", name, extension);
1076
1077 if ((FindGamefileName(cur_name)) != -1) {
1078 OutrageMessageBox("There is already a file with that name. Rename the file and then try to add it.");
1079 return false;
1080 }
1081
1082 gamefile_handle = AllocGamefile();
1083
1084 strcpy(Gamefiles[gamefile_handle].name, cur_name);
1085 strcpy(Gamefiles[gamefile_handle].dir_name, directory);
1086
1087 // Finally, save a local copy of the model/anim and alloc a tracklock
1088 mprintf(0, "Making a copy of this file locally...\n");
1089
1090 char destname[100];
1091 ddio_MakePath(destname, LocalD3Dir, "data", directory, Gamefiles[gamefile_handle].name, NULL);
1092 if (stricmp(destname, fullpath)) // only copy if they are different
1093 cf_CopyFile(destname, fullpath);
1094
1095 mng_AllocTrackLock(cur_name, PAGETYPE_GAMEFILE);
1096 return true;
1097 }
1098
1099 bool CheckInGamefile(char *tempbuffer, bool show_ok_confirmation) {
1100 mngs_Pagelock temp_pl;
1101 int r, n;
1102
1103 for (n = 0; n < MAX_GAMEFILES; n++) {
1104 if (Gamefiles[n].used && (!stricmp(Gamefiles[n].name, tempbuffer))) {
1105 break;
1106 }
1107 }
1108
1109 if (n == MAX_GAMEFILES)
1110 return false;
1111
1112 // Make sure we own this gamefile
1113 strcpy(temp_pl.name, Gamefiles[n].name);
1114 temp_pl.pagetype = PAGETYPE_GAMEFILE;
1115
1116 r = mng_CheckIfPageOwned(&temp_pl, TableUser);
1117 if (r < 0)
1118 OutrageMessageBox(ErrorString);
1119 else if (r == 0)
1120 OutrageMessageBox(InfoString);
1121 else {
1122 // Change the pagelock state to UNLOCKED
1123 strcpy(temp_pl.holder, "UNLOCKED");
1124 if (!mng_ReplacePagelock(temp_pl.name, &temp_pl)) {
1125 AfxMessageBox(ErrorString, MB_OK);
1126 return false;
1127 } else {
1128 // Now actually replace the copy on the net with our local one
1129 if (!mng_ReplacePage(Gamefiles[n].name, Gamefiles[n].name, n, PAGETYPE_GAMEFILE, 0))
1130 OutrageMessageBox(ErrorString);
1131 else {
1132 // Save this gamefile file to the network for all
1133
1134 char destname[100], srcname[100];
1135
1136 ddio_MakePath(srcname, LocalD3Dir, "data", Gamefiles[n].dir_name, Gamefiles[n].name, NULL);
1137 ddio_MakePath(destname, NetD3Dir, "data", Gamefiles[n].dir_name, Gamefiles[n].name, NULL);
1138
1139 cf_CopyFile(destname, srcname);
1140
1141 // Delete it from local pagefile if its there
1142 int dret = mng_DeletePage(Gamefiles[n].name, PAGETYPE_GAMEFILE, 1);
1143 ASSERT(dret == 1);
1144
1145 // Free the tracklock
1146 int p = mng_FindTrackLock(Gamefiles[n].name, PAGETYPE_GAMEFILE);
1147 ASSERT(p != -1);
1148 mng_FreeTrackLock(p);
1149
1150 if (show_ok_confirmation)
1151 OutrageMessageBox("%s checked in.", tempbuffer);
1152
1153 // Make sure its checked in
1154 if (cf_Diff(destname, srcname)) {
1155 ASSERT(1); // Get Jason! File didn't check in correctly!
1156 cf_CopyFile(destname, srcname); // Do this so we can trace whats happening
1157 }
1158 }
1159 }
1160 }
1161 return true;
1162 }
1163
1164 bool CheckOutGamefile(char *tempbuffer, bool show_ok_confirmation, bool report_who_has_locked) {
1165 int n;
1166 mngs_Pagelock temp_pl;
1167 mngs_gamefile_page gamefilepage;
1168 int r;
1169
1170 for (n = 0; n < MAX_GAMEFILES; n++) {
1171 if (Gamefiles[n].used && (!stricmp(Gamefiles[n].name, tempbuffer))) {
1172 break;
1173 }
1174 }
1175
1176 if (n == MAX_GAMEFILES)
1177 return false;
1178
1179 // Make sure it can be locked
1180 strcpy(temp_pl.name, Gamefiles[n].name);
1181 temp_pl.pagetype = PAGETYPE_GAMEFILE;
1182
1183 r = mng_CheckIfPageLocked(&temp_pl);
1184 if (r == 2) {
1185 int answer;
1186 answer = OutrageMessageBox(MBOX_YESNO, "This page is not even in the table file, or the database maybe corrupt. "
1187 "Override to 'Unlocked'? (Select NO if you don't know what you're doing)");
1188 if (answer == IDYES) {
1189 strcpy(temp_pl.holder, "UNLOCKED");
1190 if (!mng_ReplacePagelock(temp_pl.name, &temp_pl))
1191 AfxMessageBox(ErrorString, MB_OK);
1192 }
1193 } else if (r < 0)
1194 OutrageMessageBox(ErrorString);
1195 else if (r == 1) {
1196 if (report_who_has_locked)
1197 OutrageMessageBox(InfoString);
1198 } else {
1199
1200 // Everything is ok. Tell the network we're locking it and get a copy to
1201 // our local drive
1202 strcpy(temp_pl.holder, TableUser);
1203
1204 // Search thru the net pagefile and get a new copy in RAM in case anyone
1205 // changed it since we started the editor
1206 if (mng_FindSpecificGamefilePage(temp_pl.name, &gamefilepage, 0)) {
1207 if (mng_AssignGamefilePageToGamefile(&gamefilepage, n)) {
1208 if (!mng_ReplacePage(Gamefiles[n].name, Gamefiles[n].name, n, PAGETYPE_GAMEFILE, 1)) {
1209 OutrageMessageBox("There was problem writing that page(%s) locally!", tempbuffer);
1210 return false;
1211 } else {
1212
1213 if (!mng_ReplacePagelock(temp_pl.name, &temp_pl)) {
1214 AfxMessageBox(ErrorString, MB_OK);
1215 return false;
1216 }
1217 }
1218
1219 if (show_ok_confirmation)
1220 OutrageMessageBox("%s locked.", tempbuffer);
1221 } else
1222 OutrageMessageBox("There was a problem loading this gamefile(%s). You might encounter problems in dealing "
1223 "with it. Good luck!",
1224 tempbuffer);
1225
1226 mng_AllocTrackLock(Gamefiles[n].name, PAGETYPE_GAMEFILE);
1227 } else
1228 OutrageMessageBox("Couldn't find that gamefile(%s) in the table file!", tempbuffer);
1229 }
1230
1231 return true;
1232 }
1233
1234 bool UndoCheckOutGamefile(char *tempbuffer) {
1235 int tl, n;
1236 mngs_Pagelock pl;
1237 mngs_gamefile_page gamefilepage;
1238
1239 for (n = 0; n < MAX_GAMEFILES; n++) {
1240 if (Gamefiles[n].used && (!stricmp(Gamefiles[n].name, tempbuffer))) {
1241 break;
1242 }
1243 }
1244
1245 if (n == MAX_GAMEFILES)
1246 return false;
1247
1248 // Should have this item locked
1249 if ((tl = mng_FindTrackLock(Gamefiles[n].name, PAGETYPE_GAMEFILE)) == -1)
1250 return false;
1251
1252 // Make sure its to be deleted
1253 if (OutrageMessageBox(MBOX_YESNO,
1254 "Are you sure you want to undo your lock on %s and lose any changes you may have made?",
1255 tempbuffer) != IDYES)
1256 return false;
1257
1258 strcpy(pl.name, Gamefiles[n].name);
1259 pl.pagetype = PAGETYPE_GAMEFILE;
1260
1261 mng_FreeTrackLock(tl);
1262
1263 // Delete local page
1264 if (!mng_DeletePage(Gamefiles[n].name, PAGETYPE_GAMEFILE, 1)) {
1265 mprintf(0, ErrorString);
1266 Int3();
1267 }
1268
1269 // Get old data from net
1270 if (!mng_FindSpecificGamefilePage(pl.name, &gamefilepage, 0)) {
1271 Int3();
1272 return false;
1273 }
1274
1275 if (!mng_AssignGamefilePageToGamefile(&gamefilepage, n)) {
1276 Int3();
1277 return false;
1278 }
1279
1280 return true;
1281 }
1282
1283 bool CScriptLevelInterface::DeleteLevel() {
1284 CCheckListBox *list = (CCheckListBox *)GetDlgItem(IDC_LIST_CHECKEDOUT);
1285 int listbox_size = list->GetCount();
1286 int list_size = 0;
1287 int i;
1288 for (i = 0; i < listbox_size; i++) {
1289 if (list->GetCheck(i)) {
1290 list_size++;
1291 }
1292 }
1293
1294 if (list_size == 0)
1295 return false;
1296 int *index_map = (int *)mem_malloc(list_size * sizeof(int));
1297 if (!index_map)
1298 return false;
1299
1300 int index = 0;
1301 for (i = 0; i < listbox_size; i++) {
1302 if (list->GetCheck(i)) {
1303 index_map[index] = i;
1304 index++;
1305 }
1306 }
1307
1308 if (!mng_MakeLocker()) {
1309 mem_free(index_map);
1310 return false;
1311 }
1312
1313 int j;
1314 bool changed = false;
1315 char buffer[_MAX_PATH + 200];
1316 char tempbuffer[_MAX_PATH];
1317 char savename[_MAX_PATH];
1318
1319 for (i = 0; i < list_size; i++) {
1320 index = index_map[i];
1321
1322 list->GetText(index, tempbuffer);
1323 strcpy(savename, tempbuffer);
1324 strcat(tempbuffer, ".d3l");
1325
1326 // this item is checked...we wish to delete
1327 sprintf(buffer, "Are you sure you want to delete the level\n%s?", tempbuffer);
1328 if (MessageBox(buffer, "Friendly Warning", MB_YESNO) == IDYES) {
1329 // go ahead and delete the sucker!
1330 char t[256];
1331 sprintf(t, "Deleting: %s", tempbuffer);
1332 SetStatus(t);
1333 if (DeleteGamefile(tempbuffer))
1334 changed = true;
1335 }
1336
1337 bool script_also;
1338 script_also = false;
1339
1340 // ok the level has been deleted, see if there is a corresponding .cpp file
1341 strcpy(tempbuffer, savename);
1342 strcat(tempbuffer, ".cpp");
1343 for (j = 0; j < MAX_TRACKLOCKS; j++) {
1344 if ((GlobalTrackLocks[j].used) && (GlobalTrackLocks[j].pagetype == PAGETYPE_GAMEFILE) &&
1345 (!stricmp(GlobalTrackLocks[j].name, tempbuffer))) {
1346 // ok, we found a possibly matching script...ask if they want that
1347 // removed also...
1348 sprintf(buffer, "A possible level script (%s) was found, do you want\nto remove this also?", tempbuffer);
1349 if (m_AutoCheckScripts || MessageBox(buffer, "Friendly Warning", MB_YESNO) == IDYES) {
1350 // go ahead and delete the sucker!
1351 char t[256];
1352 sprintf(t, "Deleting: %s", tempbuffer);
1353 SetStatus(t);
1354
1355 if (DeleteGamefile(tempbuffer)) {
1356 changed = true;
1357 script_also = true;
1358 }
1359 }
1360 break;
1361 }
1362 }
1363
1364 // ok, now see if there was a DLL too
1365 if (script_also) {
1366 strcpy(tempbuffer, savename);
1367 strcat(tempbuffer, ".dll");
1368 for (j = 0; j < MAX_TRACKLOCKS; j++) {
1369 if ((GlobalTrackLocks[j].used) && (GlobalTrackLocks[j].pagetype == PAGETYPE_GAMEFILE) &&
1370 (!stricmp(GlobalTrackLocks[j].name, tempbuffer))) {
1371 // ok, we found a possibly matching script...ask if they want that
1372 // removed also...
1373 // go ahead and delete the sucker!
1374 char t[256];
1375 sprintf(t, "Deleting: %s", tempbuffer);
1376 SetStatus(t);
1377
1378 if (DeleteGamefile(tempbuffer))
1379 changed = true;
1380 break;
1381 }
1382 }
1383
1384 strcpy(tempbuffer, savename);
1385 strcat(tempbuffer, ".msg");
1386 for (j = 0; j < MAX_TRACKLOCKS; j++) {
1387 if ((GlobalTrackLocks[j].used) && (GlobalTrackLocks[j].pagetype == PAGETYPE_GAMEFILE) &&
1388 (!stricmp(GlobalTrackLocks[j].name, tempbuffer))) {
1389 // ok, we found a possibly matching script...ask if they want that
1390 // removed also...
1391 // go ahead and delete the sucker!
1392 char t[256];
1393 sprintf(t, "Deleting: %s", tempbuffer);
1394 SetStatus(t);
1395
1396 if (DeleteGamefile(tempbuffer))
1397 changed = true;
1398 break;
1399 }
1400 }
1401
1402 strcpy(tempbuffer, savename);
1403 strcat(tempbuffer, ".str");
1404 for (j = 0; j < MAX_TRACKLOCKS; j++) {
1405 if ((GlobalTrackLocks[j].used) && (GlobalTrackLocks[j].pagetype == PAGETYPE_GAMEFILE) &&
1406 (!stricmp(GlobalTrackLocks[j].name, tempbuffer))) {
1407 // ok, we found a possibly matching script...ask if they want that
1408 // removed also...
1409 // go ahead and delete the sucker!
1410 char t[256];
1411 sprintf(t, "Deleting: %s", tempbuffer);
1412 SetStatus(t);
1413
1414 if (DeleteGamefile(tempbuffer))
1415 changed = true;
1416 break;
1417 }
1418 }
1419 }
1420 }
1421
1422 mng_EraseLocker();
1423 mem_free(index_map);
1424
1425 return changed;
1426 }
1427
1428 bool CScriptLevelInterface::DeleteScript() {
1429 CCheckListBox *list = (CCheckListBox *)GetDlgItem(IDC_LIST_CHECKEDOUT);
1430 int listbox_size = list->GetCount();
1431 int list_size = 0;
1432 int i;
1433 for (i = 0; i < listbox_size; i++) {
1434 if (list->GetCheck(i)) {
1435 list_size++;
1436 }
1437 }
1438
1439 if (list_size == 0)
1440 return false;
1441 int *index_map = (int *)mem_malloc(list_size * sizeof(int));
1442 if (!index_map)
1443 return false;
1444
1445 int index = 0;
1446 for (i = 0; i < listbox_size; i++) {
1447 if (list->GetCheck(i)) {
1448 index_map[index] = i;
1449 index++;
1450 }
1451 }
1452
1453 if (!mng_MakeLocker()) {
1454 mem_free(index_map);
1455 return false;
1456 }
1457
1458 int j;
1459 bool changed = false;
1460 char buffer[_MAX_PATH + 200];
1461 char tempbuffer[_MAX_PATH];
1462 char savename[_MAX_PATH];
1463
1464 for (i = 0; i < list_size; i++) {
1465 index = index_map[i];
1466
1467 list->GetText(index, tempbuffer);
1468 strcpy(savename, tempbuffer);
1469 strcat(tempbuffer, ".cpp");
1470
1471 // this item is checked...we wish to delete
1472 sprintf(buffer, "Are you sure you want to delete script source file\n%s?", tempbuffer);
1473 if (MessageBox(buffer, "Friendly Warning", MB_YESNO) == IDYES) {
1474 // go ahead and delete the sucker!
1475 char t[256];
1476 sprintf(t, "Deleting: %s", tempbuffer);
1477 SetStatus(t);
1478
1479 if (DeleteGamefile(tempbuffer))
1480 changed = true;
1481 }
1482
1483 // ok, now see if there was a DLL too
1484 strcpy(tempbuffer, savename);
1485 strcat(tempbuffer, ".dll");
1486 for (j = 0; j < MAX_TRACKLOCKS; j++) {
1487 if ((GlobalTrackLocks[j].used) && (GlobalTrackLocks[j].pagetype == PAGETYPE_GAMEFILE) &&
1488 (!stricmp(GlobalTrackLocks[j].name, tempbuffer))) {
1489 // ok, we found a possibly matching script...ask if they want that
1490 // removed also...
1491 // go ahead and delete the sucker!
1492 char t[256];
1493 sprintf(t, "Deleting: %s", tempbuffer);
1494 SetStatus(t);
1495
1496 if (DeleteGamefile(tempbuffer))
1497 changed = true;
1498 break;
1499 }
1500 }
1501
1502 strcpy(tempbuffer, savename);
1503 strcat(tempbuffer, ".msg");
1504 for (j = 0; j < MAX_TRACKLOCKS; j++) {
1505 if ((GlobalTrackLocks[j].used) && (GlobalTrackLocks[j].pagetype == PAGETYPE_GAMEFILE) &&
1506 (!stricmp(GlobalTrackLocks[j].name, tempbuffer))) {
1507 // ok, we found a possibly matching script...ask if they want that
1508 // removed also...
1509 // go ahead and delete the sucker!
1510 char t[256];
1511 sprintf(t, "Deleting: %s", tempbuffer);
1512 SetStatus(t);
1513
1514 if (DeleteGamefile(tempbuffer))
1515 changed = true;
1516 break;
1517 }
1518 }
1519
1520 strcpy(tempbuffer, savename);
1521 strcat(tempbuffer, ".str");
1522 for (j = 0; j < MAX_TRACKLOCKS; j++) {
1523 if ((GlobalTrackLocks[j].used) && (GlobalTrackLocks[j].pagetype == PAGETYPE_GAMEFILE) &&
1524 (!stricmp(GlobalTrackLocks[j].name, tempbuffer))) {
1525 // ok, we found a possibly matching script...ask if they want that
1526 // removed also...
1527 // go ahead and delete the sucker!
1528 char t[256];
1529 sprintf(t, "Deleting: %s", tempbuffer);
1530 SetStatus(t);
1531
1532 if (DeleteGamefile(tempbuffer))
1533 changed = true;
1534 break;
1535 }
1536 }
1537 }
1538
1539 mng_EraseLocker();
1540 mem_free(index_map);
1541
1542 return changed;
1543 }
1544
1545 bool CScriptLevelInterface::CheckInScripts() {
1546 CCheckListBox *list = (CCheckListBox *)GetDlgItem(IDC_LIST_CHECKEDOUT);
1547 int listbox_size = list->GetCount();
1548 int list_size = 0;
1549 int i;
1550 for (i = 0; i < listbox_size; i++) {
1551 if (list->GetCheck(i)) {
1552 list_size++;
1553 }
1554 }
1555
1556 if (list_size == 0)
1557 return false;
1558 int *index_map = (int *)mem_malloc(list_size * sizeof(int));
1559 if (!index_map)
1560 return false;
1561
1562 int index = 0;
1563 for (i = 0; i < listbox_size; i++) {
1564 if (list->GetCheck(i)) {
1565 index_map[index] = i;
1566 index++;
1567 }
1568 }
1569
1570 if (!mng_MakeLocker()) {
1571 mem_free(index_map);
1572 return false;
1573 }
1574
1575 int j;
1576 bool changed = false;
1577 char tempbuffer[_MAX_PATH];
1578 char savename[_MAX_PATH];
1579
1580 for (i = 0; i < list_size; i++) {
1581 index = index_map[i];
1582
1583 list->GetText(index, tempbuffer);
1584 strcpy(savename, tempbuffer);
1585 strcat(tempbuffer, ".cpp");
1586
1587 char t[256];
1588 sprintf(t, "Checking In: %s", tempbuffer);
1589 SetStatus(t);
1590
1591 // this item is checked...we wish to checkin
1592 if (CheckInGamefile(tempbuffer, false))
1593 changed = true;
1594
1595 // ok, now see if there was a DLL too
1596 strcpy(tempbuffer, savename);
1597 strcat(tempbuffer, ".dll");
1598 for (j = 0; j < MAX_TRACKLOCKS; j++) {
1599 if ((GlobalTrackLocks[j].used) && (GlobalTrackLocks[j].pagetype == PAGETYPE_GAMEFILE) &&
1600 (!stricmp(GlobalTrackLocks[j].name, tempbuffer))) {
1601 // ok, we found a possibly matching script...ask if they want that
1602 // checked in also...
1603 char t[256];
1604 sprintf(t, "Checking In: %s", tempbuffer);
1605 SetStatus(t);
1606
1607 if (CheckInGamefile(tempbuffer, false))
1608 changed = true;
1609 break;
1610 }
1611 }
1612
1613 strcpy(tempbuffer, savename);
1614 strcat(tempbuffer, ".msg");
1615 for (j = 0; j < MAX_TRACKLOCKS; j++) {
1616 if ((GlobalTrackLocks[j].used) && (GlobalTrackLocks[j].pagetype == PAGETYPE_GAMEFILE) &&
1617 (!stricmp(GlobalTrackLocks[j].name, tempbuffer))) {
1618 // ok, we found a possibly matching script...ask if they want that
1619 // checked in also...
1620 char t[256];
1621 sprintf(t, "Checking In: %s", tempbuffer);
1622 SetStatus(t);
1623
1624 if (CheckInGamefile(tempbuffer, false))
1625 changed = true;
1626 break;
1627 }
1628 }
1629
1630 strcpy(tempbuffer, savename);
1631 strcat(tempbuffer, ".str");
1632 for (j = 0; j < MAX_TRACKLOCKS; j++) {
1633 if ((GlobalTrackLocks[j].used) && (GlobalTrackLocks[j].pagetype == PAGETYPE_GAMEFILE) &&
1634 (!stricmp(GlobalTrackLocks[j].name, tempbuffer))) {
1635 // ok, we found a possibly matching script...ask if they want that
1636 // checked in also...
1637 char t[256];
1638 sprintf(t, "Checking In: %s", tempbuffer);
1639 SetStatus(t);
1640
1641 if (CheckInGamefile(tempbuffer, false))
1642 changed = true;
1643 break;
1644 }
1645 }
1646 }
1647
1648 mng_EraseLocker();
1649
1650 return changed;
1651 }
1652
1653 bool CScriptLevelInterface::CheckInLevels() {
1654 CCheckListBox *list = (CCheckListBox *)GetDlgItem(IDC_LIST_CHECKEDOUT);
1655 int listbox_size = list->GetCount();
1656 int list_size = 0;
1657 int i;
1658 for (i = 0; i < listbox_size; i++) {
1659 if (list->GetCheck(i)) {
1660 list_size++;
1661 }
1662 }
1663
1664 if (list_size == 0)
1665 return false;
1666 int *index_map = (int *)mem_malloc(list_size * sizeof(int));
1667 if (!index_map)
1668 return false;
1669
1670 int index = 0;
1671 for (i = 0; i < listbox_size; i++) {
1672 if (list->GetCheck(i)) {
1673 index_map[index] = i;
1674 index++;
1675 }
1676 }
1677
1678 if (!mng_MakeLocker()) {
1679 mem_free(index_map);
1680 return false;
1681 }
1682
1683 int j;
1684 bool changed = false;
1685 char buffer[_MAX_PATH + 200];
1686 char tempbuffer[_MAX_PATH];
1687 char savename[_MAX_PATH];
1688
1689 for (i = 0; i < list_size; i++) {
1690 index = index_map[i];
1691
1692 list->GetText(index, tempbuffer);
1693 strcpy(savename, tempbuffer);
1694 strcat(tempbuffer, ".d3l");
1695
1696 char t[256];
1697 sprintf(t, "Checking In: %s", tempbuffer);
1698 SetStatus(t);
1699
1700 // go ahead and check in
1701 if (CheckInGamefile(tempbuffer, false))
1702 changed = true;
1703
1704 bool script_also;
1705 script_also = false;
1706
1707 // ok the level has been checked in, see if there is a corresponding .cpp file
1708 strcpy(tempbuffer, savename);
1709 strcat(tempbuffer, ".cpp");
1710 for (j = 0; j < MAX_TRACKLOCKS; j++) {
1711 if ((GlobalTrackLocks[j].used) && (GlobalTrackLocks[j].pagetype == PAGETYPE_GAMEFILE) &&
1712 (!stricmp(GlobalTrackLocks[j].name, tempbuffer))) {
1713 // ok, we found a possibly matching script...ask if they want that
1714 // checked in also...
1715 sprintf(buffer,
1716 "A possible level script (%s) was found, do you want\nto check this in also? (HIGHLY recommended)",
1717 tempbuffer);
1718 if (m_AutoCheckScripts || MessageBox(buffer, "Friendly Warning", MB_YESNO) == IDYES) {
1719 char t[256];
1720 sprintf(t, "Checking In: %s", tempbuffer);
1721 SetStatus(t);
1722
1723 if (CheckInGamefile(tempbuffer, false)) {
1724 changed = true;
1725 script_also = true;
1726 }
1727 }
1728 break;
1729 }
1730 }
1731
1732 // ok, now see if there was a DLL too
1733 if (script_also) {
1734 strcpy(tempbuffer, savename);
1735 strcat(tempbuffer, ".dll");
1736 for (j = 0; j < MAX_TRACKLOCKS; j++) {
1737 if ((GlobalTrackLocks[j].used) && (GlobalTrackLocks[j].pagetype == PAGETYPE_GAMEFILE) &&
1738 (!stricmp(GlobalTrackLocks[j].name, tempbuffer))) {
1739 // ok, we found a possibly matching script...ask if they want that
1740 // checked in also...
1741 char t[256];
1742 sprintf(t, "Checking In: %s", tempbuffer);
1743 SetStatus(t);
1744
1745 if (CheckInGamefile(tempbuffer, false))
1746 changed = true;
1747 break;
1748 }
1749 }
1750
1751 strcpy(tempbuffer, savename);
1752 strcat(tempbuffer, ".msg");
1753 for (j = 0; j < MAX_TRACKLOCKS; j++) {
1754 if ((GlobalTrackLocks[j].used) && (GlobalTrackLocks[j].pagetype == PAGETYPE_GAMEFILE) &&
1755 (!stricmp(GlobalTrackLocks[j].name, tempbuffer))) {
1756 // ok, we found a possibly matching script...ask if they want that
1757 // checked in also...
1758 char t[256];
1759 sprintf(t, "Checking In: %s", tempbuffer);
1760 SetStatus(t);
1761
1762 if (CheckInGamefile(tempbuffer, false))
1763 changed = true;
1764 break;
1765 }
1766 }
1767
1768 strcpy(tempbuffer, savename);
1769 strcat(tempbuffer, ".str");
1770 for (j = 0; j < MAX_TRACKLOCKS; j++) {
1771 if ((GlobalTrackLocks[j].used) && (GlobalTrackLocks[j].pagetype == PAGETYPE_GAMEFILE) &&
1772 (!stricmp(GlobalTrackLocks[j].name, tempbuffer))) {
1773 // ok, we found a possibly matching script...ask if they want that
1774 // checked in also...
1775 char t[256];
1776 sprintf(t, "Checking In: %s", tempbuffer);
1777 SetStatus(t);
1778
1779 if (CheckInGamefile(tempbuffer, false))
1780 changed = true;
1781 break;
1782 }
1783 }
1784 }
1785 }
1786
1787 mng_EraseLocker();
1788 mem_free(index_map);
1789
1790 return changed;
1791 }
1792
1793 bool CScriptLevelInterface::CheckOutScripts() {
1794 CCheckListBox *list = (CCheckListBox *)GetDlgItem(IDC_LIST_AVAILABLE);
1795 int listbox_size = list->GetCount();
1796 int list_size = 0;
1797 int i;
1798 for (i = 0; i < listbox_size; i++) {
1799 if (list->GetCheck(i)) {
1800 list_size++;
1801 }
1802 }
1803
1804 if (list_size == 0)
1805 return false;
1806 int *index_map = (int *)mem_malloc(list_size * sizeof(int));
1807 if (!index_map)
1808 return false;
1809
1810 int index = 0;
1811 for (i = 0; i < listbox_size; i++) {
1812 if (list->GetCheck(i)) {
1813 index_map[index] = i;
1814 index++;
1815 }
1816 }
1817
1818 if (!mng_MakeLocker()) {
1819 mem_free(index_map);
1820 return false;
1821 }
1822
1823 int j;
1824 bool changed = false;
1825 char tempbuffer[_MAX_PATH];
1826 char savename[_MAX_PATH];
1827
1828 for (i = 0; i < list_size; i++) {
1829 index = index_map[i];
1830
1831 list->GetText(index, tempbuffer);
1832 strcpy(savename, tempbuffer);
1833 strcat(tempbuffer, ".cpp");
1834
1835 char t[256];
1836 sprintf(t, "Checking Out: %s", tempbuffer);
1837 SetStatus(t);
1838
1839 // this item is checked...we wish to checkin
1840 if (CheckOutGamefile(tempbuffer, false))
1841 changed = true;
1842
1843 // ok, now see if there was a DLL too
1844 strcpy(tempbuffer, savename);
1845 strcat(tempbuffer, ".dll");
1846 for (j = 0; j < MAX_GAMEFILES; j++) {
1847 if ((Gamefiles[j].used) && (!stricmp(Gamefiles[j].name, tempbuffer)) &&
1848 (mng_FindTrackLock(tempbuffer, PAGETYPE_GAMEFILE) == -1)) {
1849 // ok, we found a possibly matching script...ask if they want that
1850 // checked out also...
1851 // go ahead and delete the sucker!
1852 char t[256];
1853 sprintf(t, "Checking Out: %s", tempbuffer);
1854 SetStatus(t);
1855
1856 if (CheckOutGamefile(tempbuffer, false))
1857 changed = true;
1858 break;
1859 }
1860 }
1861
1862 strcpy(tempbuffer, savename);
1863 strcat(tempbuffer, ".msg");
1864 for (j = 0; j < MAX_GAMEFILES; j++) {
1865 if ((Gamefiles[j].used) && (!stricmp(Gamefiles[j].name, tempbuffer)) &&
1866 (mng_FindTrackLock(tempbuffer, PAGETYPE_GAMEFILE) == -1)) {
1867 // ok, we found a possibly matching script...ask if they want that
1868 // checked out also...
1869 // go ahead and delete the sucker!
1870 char t[256];
1871 sprintf(t, "Checking Out: %s", tempbuffer);
1872 SetStatus(t);
1873
1874 if (CheckOutGamefile(tempbuffer, false))
1875 changed = true;
1876 break;
1877 }
1878 }
1879
1880 strcpy(tempbuffer, savename);
1881 strcat(tempbuffer, ".str");
1882 for (j = 0; j < MAX_GAMEFILES; j++) {
1883 if ((Gamefiles[j].used) && (!stricmp(Gamefiles[j].name, tempbuffer)) &&
1884 (mng_FindTrackLock(tempbuffer, PAGETYPE_GAMEFILE) == -1)) {
1885 // ok, we found a possibly matching script...ask if they want that
1886 // checked out also...
1887 // go ahead and delete the sucker!
1888 char t[256];
1889 sprintf(t, "Checking Out: %s", tempbuffer);
1890 SetStatus(t);
1891
1892 if (CheckOutGamefile(tempbuffer, false))
1893 changed = true;
1894 break;
1895 }
1896 }
1897 }
1898
1899 mng_EraseLocker();
1900 mem_free(index_map);
1901
1902 return changed;
1903 }
1904
1905 bool CScriptLevelInterface::CheckOutLevels() {
1906 CCheckListBox *list = (CCheckListBox *)GetDlgItem(IDC_LIST_AVAILABLE);
1907 int listbox_size = list->GetCount();
1908 int list_size = 0;
1909 int i;
1910 for (i = 0; i < listbox_size; i++) {
1911 if (list->GetCheck(i)) {
1912 list_size++;
1913 }
1914 }
1915
1916 if (list_size == 0)
1917 return false;
1918 int *index_map = (int *)mem_malloc(list_size * sizeof(int));
1919 if (!index_map)
1920 return false;
1921
1922 int index = 0;
1923 for (i = 0; i < listbox_size; i++) {
1924 if (list->GetCheck(i)) {
1925 index_map[index] = i;
1926 index++;
1927 }
1928 }
1929
1930 if (!mng_MakeLocker()) {
1931 mem_free(index_map);
1932 return false;
1933 }
1934
1935 int j;
1936 bool changed = false;
1937 char buffer[_MAX_PATH + 200];
1938 char tempbuffer[_MAX_PATH];
1939 char savename[_MAX_PATH];
1940
1941 for (i = 0; i < list_size; i++) {
1942 index = index_map[i];
1943
1944 list->GetText(index, tempbuffer);
1945 strcpy(savename, tempbuffer);
1946 strcat(tempbuffer, ".d3l");
1947
1948 char t[256];
1949 sprintf(t, "Checking Out: %s", tempbuffer);
1950 SetStatus(t);
1951
1952 // this item is checked...we wish to checkin
1953 if (CheckOutGamefile(tempbuffer, false))
1954 changed = true;
1955
1956 bool script_also;
1957 script_also = false;
1958
1959 // ok the level has been checked in, see if there is a corresponding .cpp file
1960 strcpy(tempbuffer, savename);
1961 strcat(tempbuffer, ".cpp");
1962 for (j = 0; j < MAX_GAMEFILES; j++) {
1963 if ((Gamefiles[j].used) && (!stricmp(Gamefiles[j].name, tempbuffer)) &&
1964 (mng_FindTrackLock(tempbuffer, PAGETYPE_GAMEFILE) == -1)) {
1965 // ok, we found a possibly matching script...ask if they want that
1966 // checked out also...
1967 sprintf(buffer,
1968 "A possible level script (%s) was found, do you want\nto check this out also? (HIGHLY recommended)",
1969 tempbuffer);
1970 if (m_AutoCheckScripts || MessageBox(buffer, "Friendly Warning", MB_YESNO) == IDYES) {
1971 // go ahead and delete the sucker!
1972 char t[256];
1973 sprintf(t, "Checking Out: %s", tempbuffer);
1974 SetStatus(t);
1975
1976 if (CheckOutGamefile(tempbuffer, false)) {
1977 changed = true;
1978 script_also = true;
1979 }
1980 }
1981 break;
1982 }
1983 }
1984
1985 // ok, now see if there was a DLL too
1986 if (script_also) {
1987 strcpy(tempbuffer, savename);
1988 strcat(tempbuffer, ".dll");
1989 for (j = 0; j < MAX_GAMEFILES; j++) {
1990 if ((Gamefiles[j].used) && (!stricmp(Gamefiles[j].name, tempbuffer)) &&
1991 (mng_FindTrackLock(tempbuffer, PAGETYPE_GAMEFILE) == -1)) {
1992 // ok, we found a possibly matching script...ask if they want that
1993 // checked out also...
1994 // go ahead and delete the sucker!
1995 char t[256];
1996 sprintf(t, "Checking Out: %s", tempbuffer);
1997 SetStatus(t);
1998
1999 if (CheckOutGamefile(tempbuffer, false))
2000 changed = true;
2001 break;
2002 }
2003 }
2004
2005 strcpy(tempbuffer, savename);
2006 strcat(tempbuffer, ".msg");
2007 for (j = 0; j < MAX_GAMEFILES; j++) {
2008 if ((Gamefiles[j].used) && (!stricmp(Gamefiles[j].name, tempbuffer)) &&
2009 (mng_FindTrackLock(tempbuffer, PAGETYPE_GAMEFILE) == -1)) {
2010 // ok, we found a possibly matching script...ask if they want that
2011 // checked out also...
2012 // go ahead and delete the sucker!
2013 char t[256];
2014 sprintf(t, "Checking Out: %s", tempbuffer);
2015 SetStatus(t);
2016
2017 if (CheckOutGamefile(tempbuffer, false))
2018 changed = true;
2019 break;
2020 }
2021 }
2022
2023 strcpy(tempbuffer, savename);
2024 strcat(tempbuffer, ".str");
2025 for (j = 0; j < MAX_GAMEFILES; j++) {
2026 if ((Gamefiles[j].used) && (!stricmp(Gamefiles[j].name, tempbuffer)) &&
2027 (mng_FindTrackLock(tempbuffer, PAGETYPE_GAMEFILE) == -1)) {
2028 // ok, we found a possibly matching script...ask if they want that
2029 // checked out also...
2030 // go ahead and delete the sucker!
2031 char t[256];
2032 sprintf(t, "Checking Out: %s", tempbuffer);
2033 SetStatus(t);
2034
2035 if (CheckOutGamefile(tempbuffer, false))
2036 changed = true;
2037 break;
2038 }
2039 }
2040 }
2041 }
2042
2043 mng_EraseLocker();
2044 mem_free(index_map);
2045
2046 return changed;
2047 }
2048
2049 bool CScriptLevelInterface::UndoCheckOutScripts() {
2050 CCheckListBox *list = (CCheckListBox *)GetDlgItem(IDC_LIST_CHECKEDOUT);
2051 int listbox_size = list->GetCount();
2052 int list_size = 0;
2053 int i;
2054 for (i = 0; i < listbox_size; i++) {
2055 if (list->GetCheck(i)) {
2056 list_size++;
2057 }
2058 }
2059
2060 if (list_size == 0)
2061 return false;
2062 int *index_map = (int *)mem_malloc(list_size * sizeof(int));
2063 if (!index_map)
2064 return false;
2065
2066 int index = 0;
2067 for (i = 0; i < listbox_size; i++) {
2068 if (list->GetCheck(i)) {
2069 index_map[index] = i;
2070 index++;
2071 }
2072 }
2073
2074 if (!mng_MakeLocker()) {
2075 mem_free(index_map);
2076 return false;
2077 }
2078
2079 int j;
2080 bool changed = false;
2081 char tempbuffer[_MAX_PATH];
2082 char savename[_MAX_PATH];
2083
2084 for (i = 0; i < list_size; i++) {
2085 index = index_map[i];
2086
2087 list->GetText(index, tempbuffer);
2088 strcpy(savename, tempbuffer);
2089 strcat(tempbuffer, ".cpp");
2090
2091 char t[256];
2092 sprintf(t, "UndoCheck Out: %s", tempbuffer);
2093 SetStatus(t);
2094
2095 // this item is checked...we wish to checkin
2096 if (UndoCheckOutGamefile(tempbuffer))
2097 changed = true;
2098
2099 // ok, now see if there was a DLL too
2100 strcpy(tempbuffer, savename);
2101 strcat(tempbuffer, ".dll");
2102 for (j = 0; j < MAX_TRACKLOCKS; j++) {
2103 if ((GlobalTrackLocks[j].used) && (GlobalTrackLocks[j].pagetype == PAGETYPE_GAMEFILE) &&
2104 (!stricmp(GlobalTrackLocks[j].name, tempbuffer))) {
2105 // ok, we found a possibly matching script...ask if they want that
2106 // undone also...
2107 // go ahead and delete the sucker!
2108 char t[256];
2109 sprintf(t, "UndoCheck Out: %s", tempbuffer);
2110 SetStatus(t);
2111
2112 if (UndoCheckOutGamefile(tempbuffer))
2113 changed = true;
2114 break;
2115 }
2116 }
2117
2118 strcpy(tempbuffer, savename);
2119 strcat(tempbuffer, ".msg");
2120 for (j = 0; j < MAX_TRACKLOCKS; j++) {
2121 if ((GlobalTrackLocks[j].used) && (GlobalTrackLocks[j].pagetype == PAGETYPE_GAMEFILE) &&
2122 (!stricmp(GlobalTrackLocks[j].name, tempbuffer))) {
2123 // ok, we found a possibly matching script...ask if they want that
2124 // undone also...
2125 // go ahead and delete the sucker!
2126 char t[256];
2127 sprintf(t, "UndoCheck Out: %s", tempbuffer);
2128 SetStatus(t);
2129
2130 if (UndoCheckOutGamefile(tempbuffer))
2131 changed = true;
2132 break;
2133 }
2134 }
2135
2136 strcpy(tempbuffer, savename);
2137 strcat(tempbuffer, ".str");
2138 for (j = 0; j < MAX_TRACKLOCKS; j++) {
2139 if ((GlobalTrackLocks[j].used) && (GlobalTrackLocks[j].pagetype == PAGETYPE_GAMEFILE) &&
2140 (!stricmp(GlobalTrackLocks[j].name, tempbuffer))) {
2141 // ok, we found a possibly matching script...ask if they want that
2142 // undone also...
2143 // go ahead and delete the sucker!
2144 char t[256];
2145 sprintf(t, "UndoCheck Out: %s", tempbuffer);
2146 SetStatus(t);
2147
2148 if (UndoCheckOutGamefile(tempbuffer))
2149 changed = true;
2150 break;
2151 }
2152 }
2153 }
2154
2155 mng_EraseLocker();
2156
2157 return changed;
2158 }
2159
2160 bool CScriptLevelInterface::UndoCheckOutLevels() {
2161 CCheckListBox *list = (CCheckListBox *)GetDlgItem(IDC_LIST_CHECKEDOUT);
2162 int listbox_size = list->GetCount();
2163 int list_size = 0;
2164 int i;
2165 for (i = 0; i < listbox_size; i++) {
2166 if (list->GetCheck(i)) {
2167 list_size++;
2168 }
2169 }
2170
2171 if (list_size == 0)
2172 return false;
2173 int *index_map = (int *)mem_malloc(list_size * sizeof(int));
2174 if (!index_map)
2175 return false;
2176
2177 int index = 0;
2178 for (i = 0; i < listbox_size; i++) {
2179 if (list->GetCheck(i)) {
2180 index_map[index] = i;
2181 index++;
2182 }
2183 }
2184
2185 if (!mng_MakeLocker()) {
2186 mem_free(index_map);
2187 return false;
2188 }
2189
2190 int j;
2191 bool changed = false;
2192 char buffer[_MAX_PATH + 200];
2193 char tempbuffer[_MAX_PATH];
2194 char savename[_MAX_PATH];
2195
2196 for (i = 0; i < list_size; i++) {
2197 index = index_map[i];
2198
2199 list->GetText(index, tempbuffer);
2200 strcpy(savename, tempbuffer);
2201 strcat(tempbuffer, ".d3l");
2202
2203 char t[256];
2204 sprintf(t, "UndoCheck Out: %s", tempbuffer);
2205 SetStatus(t);
2206
2207 // go ahead and check in
2208 if (UndoCheckOutGamefile(tempbuffer))
2209 changed = true;
2210
2211 bool script_also;
2212 script_also = false;
2213
2214 // ok the level has been checked in, see if there is a corresponding .cpp file
2215 strcpy(tempbuffer, savename);
2216 strcat(tempbuffer, ".cpp");
2217 for (j = 0; j < MAX_TRACKLOCKS; j++) {
2218 if ((GlobalTrackLocks[j].used) && (GlobalTrackLocks[j].pagetype == PAGETYPE_GAMEFILE) &&
2219 (!stricmp(GlobalTrackLocks[j].name, tempbuffer))) {
2220 // ok, we found a possibly matching script...ask if they want that
2221 // checked in also...
2222 sprintf(
2223 buffer,
2224 "A possible level script (%s) was found, do you want\nto undo this check out also? (HIGHLY recommended)",
2225 tempbuffer);
2226 if (m_AutoCheckScripts || MessageBox(buffer, "Friendly Warning", MB_YESNO) == IDYES) {
2227 // go ahead and delete the sucker!
2228 char t[256];
2229 sprintf(t, "UndoCheck Out: %s", tempbuffer);
2230 SetStatus(t);
2231
2232 if (UndoCheckOutGamefile(tempbuffer)) {
2233 changed = true;
2234 script_also = true;
2235 }
2236 }
2237 break;
2238 }
2239 }
2240
2241 // ok, now see if there was a DLL too
2242 if (script_also) {
2243 strcpy(tempbuffer, savename);
2244 strcat(tempbuffer, ".dll");
2245 for (j = 0; j < MAX_TRACKLOCKS; j++) {
2246 if ((GlobalTrackLocks[j].used) && (GlobalTrackLocks[j].pagetype == PAGETYPE_GAMEFILE) &&
2247 (!stricmp(GlobalTrackLocks[j].name, tempbuffer))) {
2248 // ok, we found a possibly matching script...ask if they want that
2249 // undone also...
2250 // go ahead and undo the sucker!
2251 char t[256];
2252 sprintf(t, "UndoCheck Out: %s", tempbuffer);
2253 SetStatus(t);
2254
2255 if (UndoCheckOutGamefile(tempbuffer))
2256 changed = true;
2257 break;
2258 }
2259 }
2260
2261 strcpy(tempbuffer, savename);
2262 strcat(tempbuffer, ".msg");
2263 for (j = 0; j < MAX_TRACKLOCKS; j++) {
2264 if ((GlobalTrackLocks[j].used) && (GlobalTrackLocks[j].pagetype == PAGETYPE_GAMEFILE) &&
2265 (!stricmp(GlobalTrackLocks[j].name, tempbuffer))) {
2266 // ok, we found a possibly matching script...ask if they want that
2267 // undone also...
2268 // go ahead and undo the sucker!
2269 char t[256];
2270 sprintf(t, "UndoCheck Out: %s", tempbuffer);
2271 SetStatus(t);
2272
2273 if (UndoCheckOutGamefile(tempbuffer))
2274 changed = true;
2275 break;
2276 }
2277 }
2278
2279 strcpy(tempbuffer, savename);
2280 strcat(tempbuffer, ".str");
2281 for (j = 0; j < MAX_TRACKLOCKS; j++) {
2282 if ((GlobalTrackLocks[j].used) && (GlobalTrackLocks[j].pagetype == PAGETYPE_GAMEFILE) &&
2283 (!stricmp(GlobalTrackLocks[j].name, tempbuffer))) {
2284 // ok, we found a possibly matching script...ask if they want that
2285 // undone also...
2286 // go ahead and undo the sucker!
2287 char t[256];
2288 sprintf(t, "UndoCheck Out: %s", tempbuffer);
2289 SetStatus(t);
2290
2291 if (UndoCheckOutGamefile(tempbuffer))
2292 changed = true;
2293 break;
2294 }
2295 }
2296 }
2297 }
2298
2299 mng_EraseLocker();
2300 mem_free(index_map);
2301
2302 return changed;
2303 }
2304 // returns true if the given .cpp file is has an out of date dll (or non-existant). Working
2305 // dir MUST be set to data\scripts before calling this function
2306 bool IsScriptOutofDate(char *name) {
2307 bool out_of_date = false;
2308
2309 HANDLE hFindFilecpp = INVALID_HANDLE_VALUE, hFindFiledll = INVALID_HANDLE_VALUE;
2310 WIN32_FIND_DATA FindFileDatacpp, FindFileDatadll;
2311 char fname[_MAX_PATH], ext[_MAX_EXT];
2312
2313 hFindFilecpp = FindFirstFile(name, &FindFileDatacpp);
2314 if (hFindFilecpp != INVALID_HANDLE_VALUE) {
2315 ddio_SplitPath(FindFileDatacpp.cFileName, NULL, fname, ext);
2316 strcat(fname, ".dll");
2317
2318 hFindFiledll = FindFirstFile(fname, &FindFileDatadll);
2319 if (hFindFiledll == INVALID_HANDLE_VALUE ||
2320 CompareFileTime(&FindFileDatadll.ftLastWriteTime, &FindFileDatacpp.ftLastWriteTime) < 0) {
2321 // out of date
2322 out_of_date = true;
2323 }
2324 if (hFindFiledll != INVALID_HANDLE_VALUE)
2325 FindClose(hFindFiledll);
2326 hFindFiledll = INVALID_HANDLE_VALUE;
2327 } else {
2328 char error[_MAX_PATH];
2329 sprintf(error, "'%s' not found", name);
2330 AfxMessageBox(error);
2331 out_of_date = true;
2332 }
2333 if (hFindFilecpp != INVALID_HANDLE_VALUE)
2334 FindClose(hFindFilecpp);
2335 hFindFilecpp = INVALID_HANDLE_VALUE;
2336
2337 return out_of_date;
2338 }
2339
2340 #include "module.h"
2341 #include "osiris_share.h"
2342 extern tOSIRISModuleInit Osiris_module_init;
2343 typedef char(DLLFUNCCALL *InitializeDLL_fp)(tOSIRISModuleInit *function_list);
2344 typedef void(DLLFUNCCALL *ShutdownDLL_fp)(void);
2345
2346 // returns true if the given .cpp/.dll file is out of sync (or non-existant). Working directory
2347 // doesn't necessarily have to be set to data\scripts.
2348 bool IsScriptOutofSync(char *name) {
2349 bool out_of_sync = false;
2350 InitializeDLL_fp initdll;
2351 ShutdownDLL_fp shutdowndll;
2352 module mod;
2353
2354 char filename[_MAX_PATH], ext[_MAX_EXT];
2355 char path[_MAX_PATH];
2356
2357 ddio_SplitPath(name, NULL, filename, ext);
2358
2359 Osiris_module_init.string_count = 0;
2360 Osiris_module_init.string_table = NULL;
2361 Osiris_module_init.module_is_static = false;
2362 Osiris_module_init.module_identifier = 0;
2363 Osiris_module_init.script_identifier = filename;
2364
2365 strcat(filename, ".dll");
2366 ddio_MakePath(path, LocalScriptDir, filename, NULL);
2367 mprintf(0, " Checking %s...", filename);
2368
2369 if (mod_LoadModule(&mod, path)) {
2370 initdll = (InitializeDLL_fp)mod_GetSymbol(&mod, "InitializeDLL", 4);
2371 if (initdll) {
2372 if (!initdll(&Osiris_module_init)) {
2373 // dll does not initialize...out of synce
2374 out_of_sync = true;
2375 mprintf(0, "OUT OF SYNC!\n");
2376 } else {
2377 mprintf(0, "Not Out of Sync\n");
2378 shutdowndll = (ShutdownDLL_fp)mod_GetSymbol(&mod, "ShutdownDLL", 0);
2379 if (shutdowndll) {
2380 shutdowndll();
2381 }
2382 }
2383 } else {
2384 // unable to load
2385 mprintf(0, "UNABLE TO GET INITIALIZEDLL\n");
2386 }
2387
2388 mod_FreeModule(&mod);
2389 } else {
2390 mprintf(0, "MODULE NOT FOUND\n");
2391 }
2392
2393 return out_of_sync;
2394 }
2395
2396 // Returns true if there are out of date script files (only checks those in manage system)
2397 int AreScriptsOutofDate(void) {
2398 if (Scripts_need_sync) {
2399 CScriptSyncDialog dlg;
2400 dlg.DoModal();
2401 Scripts_need_sync = false;
2402 return dlg.m_ErrorCount;
2403 }
2404 return 0;
2405
2406 /*
2407 int count = 0;
2408 char old_dir[_MAX_PATH];
2409
2410 ddio_GetWorkingDir(old_dir,_MAX_PATH);
2411
2412 // First check for out-of-sync scripts (attempt load aigame and generic)
2413 mprintf(0,"Checking for out of sync scripts...\n");
2414 if(IsScriptOutofSync("aigame.dll")||IsScriptOutofSync("generic.dll"))
2415 {
2416 OutrageMessageBox(MBOX_OK,"WARNING! You have out of sync scripts...you MUST recompile your scripts!!!!!");
2417 }
2418
2419
2420 mprintf(0,"Checking for out of date scripts...");
2421 ddio_SetWorkingDir(LocalScriptDir);
2422
2423 for (int i=0;i<MAX_GAMEFILES;i++){
2424 if (Gamefiles[i].used){
2425 //we're only adding .d3l's to this list
2426 int length = strlen(Gamefiles[i].name);
2427 if(!stricmp(&Gamefiles[i].name[length-4],".cpp") && IsScriptOutofDate(Gamefiles[i].name)){
2428 count++;
2429 }
2430 }
2431 }
2432
2433 ddio_SetWorkingDir(old_dir);
2434
2435 mprintf(0,"Found %d OOD scripts\n",count);
2436 return count;
2437 */
2438 }
2439
2440 /*
2441 #include "psglob.h"
2442 class tFindInManage
2443 {
2444 public:
2445 tFindInManage() {searching = false;}
2446
2447 bool searching;
2448 bool in_Gamefiles;
2449 int curr_index;
2450 char glob_string[PAGENAME_LEN];
2451 };
2452 tFindInManage FindInManageData;
2453
2454 bool FindManageFirst(char *buffer,char *wildcard);
2455 bool FindManageNext(char *buffer);
2456 void FindManageClose(void);
2457
2458
2459 bool FindManageFirst(char *buffer,char *wildcard)
2460 {
2461 if(FindInManageData.searching)
2462 FindManageClose();
2463
2464 FindInManageData.searching = true;
2465 strcpy(FindInManageData.glob_string,wildcard);
2466 FindInManageData.curr_index = 0;
2467 FindInManageData.in_Gamefiles = true;
2468
2469 return FindManageNext(buffer);
2470 }
2471
2472 bool FindManageNext(char *buffer)
2473 {
2474 if(!FindInManageData.searching)
2475 return false;
2476
2477 if(FindInManageData.in_Gamefiles)
2478 {
2479
2480 for(;FindInManageData.curr_index<MAX_GAMEFILES;FindInManageData.curr_index++)
2481 {
2482 if(Gamefiles[FindInManageData.curr_index].used &&
2483 PSGlobMatch(FindInManageData.glob_string,Gamefiles[FindInManageData.curr_index].name,false,false))
2484 {
2485 //match
2486 strcpy(buffer,Gamefiles[FindInManageData.curr_index].name);
2487 FindInManageData.curr_index++;
2488 return true;
2489 }
2490 }
2491
2492 FindInManageData.curr_index = 0;
2493 FindInManageData.in_Gamefiles = false;
2494 }
2495
2496 for(;FindInManageData.curr_index<MAX_TRACKLOCKS;FindInManageData.curr_index++)
2497 {
2498 if(GlobalTrackLocks[FindInManageData.curr_index].used &&
2499 GlobalTrackLocks[FindInManageData.curr_index].pagetype==PAGETYPE_GAMEFILE &&
2500 PSGlobMatch(FindInManageData.glob_string,GlobalTrackLocks[FindInManageData.curr_index].name,false,false))
2501 {
2502 //match
2503 strcpy(buffer,GlobalTrackLocks[FindInManageData.curr_index].name);
2504 FindInManageData.curr_index++;
2505 return true;
2506 }
2507 }
2508
2509 return false;
2510 }
2511
2512 void FindManageClose(void)
2513 {
2514 FindInManageData.searching = false;
2515 }
2516 */