| 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/QuickCompile.cpp $ |
| 21 | * $Revision: 1.1.1.1 $ |
| 22 | * $Date: 2003-08-26 03:57:38 $ |
| 23 | * $Author: kevinb $ |
| 24 | * |
| 25 | * Does a quick compile of a script |
| 26 | * |
| 27 | * $Log: not supported by cvs2svn $ |
| 28 | * |
| 29 | * 2 12/30/98 4:38p Jeff |
| 30 | * initial creation |
| 31 | * |
| 32 | * $NoKeywords: $ |
| 33 | */ |
| 34 | |
| 35 | // QuickCompile.cpp : implementation file |
| 36 | // |
| 37 | |
| 38 | #include "stdafx.h" |
| 39 | #include "editor.h" |
| 40 | #include "QuickCompile.h" |
| 41 | #include "scriptcompilerapi.h" |
| 42 | #include "ScriptMassCompile.h" |
| 43 | #include "ddio.h" |
| 44 | #include "cfile.h" |
| 45 | #include "manage.h" |
| 46 | |
| 47 | #ifdef _DEBUG |
| 48 | #define new DEBUG_NEW |
| 49 | #undef THIS_FILE |
| 50 | static char THIS_FILE[] = __FILE__; |
| 51 | #endif |
| 52 | |
| 53 | ///////////////////////////////////////////////////////////////////////////// |
| 54 | // CQuickCompile dialog |
| 55 | |
| 56 | CQuickCompile::CQuickCompile(char *scriptname, CWnd *pParent /*=NULL*/) : CDialog(CQuickCompile::IDD, pParent) { |
| 57 | //{{AFX_DATA_INIT(CQuickCompile) |
| 58 | // NOTE: the ClassWizard will add member initialization here |
| 59 | //}}AFX_DATA_INIT |
| 60 | |
| 61 | strcpy(m_scriptname, scriptname); |
| 62 | ret_value = 0; |
| 63 | } |
| 64 | |
| 65 | void CQuickCompile::DoDataExchange(CDataExchange *pDX) { |
| 66 | CDialog::DoDataExchange(pDX); |
| 67 | //{{AFX_DATA_MAP(CQuickCompile) |
| 68 | // NOTE: the ClassWizard will add DDX and DDV calls here |
| 69 | //}}AFX_DATA_MAP |
| 70 | } |
| 71 | |
| 72 | BEGIN_MESSAGE_MAP(CQuickCompile, CDialog) |
| 73 | //{{AFX_MSG_MAP(CQuickCompile) |
| 74 | ON_WM_DESTROY() |
| 75 | //}}AFX_MSG_MAP |
| 76 | END_MESSAGE_MAP() |
| 77 | |
| 78 | ///////////////////////////////////////////////////////////////////////////// |
| 79 | // CQuickCompile message handlers |
| 80 | |
| 81 | CEdit *quick_compile_edit; |
| 82 | CString quick_compile_string; |
| 83 | |
| 84 | void quickcompilercallback(char *str) { |
| 85 | quick_compile_string += str; |
| 86 | quick_compile_edit->SetWindowText(quick_compile_string); |
| 87 | } |
| 88 | |
| 89 | BOOL CQuickCompile::OnInitDialog() { |
| 90 | CDialog::OnInitDialog(); |
| 91 | |
| 92 | quick_compile_string = ""; |
| 93 | quick_compile_edit = (CEdit *)GetDlgItem(IDC_TEXT); |
| 94 | ret_value = 0; |
| 95 | |
| 96 | char filename[_MAX_PATH]; |
| 97 | char compiled_filename[_MAX_PATH]; |
| 98 | bool isours = false; |
| 99 | |
| 100 | ddio_SplitPath(m_scriptname, NULL, filename, NULL); |
| 101 | strcpy(compiled_filename, filename); |
| 102 | strcat(filename, ".cpp"); |
| 103 | strcat(compiled_filename, ".dll"); |
| 104 | |
| 105 | if (mng_FindTrackLock(filename, PAGETYPE_GAMEFILE) != -1) |
| 106 | isours = true; |
| 107 | |
| 108 | // grey out the OK button |
| 109 | CWnd *wnd = (CWnd *)GetDlgItem(IDOK); |
| 110 | wnd->EnableWindow(false); |
| 111 | |
| 112 | if (cfexist(filename)) { |
| 113 | char full_path[_MAX_PATH]; |
| 114 | ddio_MakePath(full_path, LocalScriptDir, compiled_filename, NULL); |
| 115 | if (cfexist(full_path)) { |
| 116 | ddio_DeleteFile(full_path); |
| 117 | } |
| 118 | |
| 119 | if (!isours) { |
| 120 | quick_compile_string += "====================================================\r\n"; |
| 121 | quick_compile_string += "=== SCRIPT IS NOT CHECKED OUT BY YOU!!!!!\r\n"; |
| 122 | quick_compile_string += "====================================================\r\n"; |
| 123 | quick_compile_edit->SetWindowText(quick_compile_string); |
| 124 | } |
| 125 | |
| 126 | tCompilerInfo ci; |
| 127 | ci.callback = quickcompilercallback; |
| 128 | ci.script_type = DetermineScriptType(filename); |
| 129 | strcpy(ci.source_filename, filename); |
| 130 | ScriptCompile(&ci); |
| 131 | |
| 132 | if (cfexist(compiled_filename)) { |
| 133 | ret_value = 1; |
| 134 | } |
| 135 | |
| 136 | } else { |
| 137 | ret_value = -1; |
| 138 | char buffer[256]; |
| 139 | sprintf(buffer, "'%s' does not exist", filename); |
| 140 | quick_compile_edit->SetWindowText(buffer); |
| 141 | } |
| 142 | |
| 143 | wnd->EnableWindow(true); |
| 144 | |
| 145 | return TRUE; // return TRUE unless you set the focus to a control |
| 146 | // EXCEPTION: OCX Property Pages should return FALSE |
| 147 | } |
| 148 | |
| 149 | void CQuickCompile::OnDestroy() { |
| 150 | CDialog::OnDestroy(); |
| 151 | |
| 152 | quick_compile_string = ""; |
| 153 | } |
| 154 | |
| 155 | INT_PTR CQuickCompile::DoModal() { return CDialog::DoModal(); } |