| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | // VirtualCompilerConfig.cpp : implementation file |
| 20 | // |
| 21 | |
| 22 | #include "stdafx.h" |
| 23 | #include "editor.h" |
| 24 | #include "AppDatabase.h" |
| 25 | #include "VirtualCompilerConfig.h" |
| 26 | #include "Descent.h" |
| 27 | |
| 28 | #ifdef _DEBUG |
| 29 | #define new DEBUG_NEW |
| 30 | #undef THIS_FILE |
| 31 | static char THIS_FILE[] = __FILE__; |
| 32 | #endif |
| 33 | |
| 34 | ///////////////////////////////////////////////////////////////////////////// |
| 35 | // CVirtualCompilerConfig dialog |
| 36 | |
| 37 | CVirtualCompilerConfig::CVirtualCompilerConfig(CWnd *pParent /*=NULL*/) |
| 38 | : CDialog(CVirtualCompilerConfig::IDD, pParent) { |
| 39 | //{{AFX_DATA_INIT(CVirtualCompilerConfig) |
| 40 | m_Compiler = _T(""); |
| 41 | m_DebugType = 0; |
| 42 | m_WarningLevel = 0; |
| 43 | //}}AFX_DATA_INIT |
| 44 | } |
| 45 | |
| 46 | void CVirtualCompilerConfig::DoDataExchange(CDataExchange *pDX) { |
| 47 | CDialog::DoDataExchange(pDX); |
| 48 | //{{AFX_DATA_MAP(CVirtualCompilerConfig) |
| 49 | DDX_Text(pDX, IDC_COMPILER, m_Compiler); |
| 50 | DDX_Radio(pDX, IDC_OPTIMIZE, m_DebugType); |
| 51 | DDX_Radio(pDX, IDC_WARN_NONE, m_WarningLevel); |
| 52 | //}}AFX_DATA_MAP |
| 53 | } |
| 54 | |
| 55 | BEGIN_MESSAGE_MAP(CVirtualCompilerConfig, CDialog) |
| 56 | //{{AFX_MSG_MAP(CVirtualCompilerConfig) |
| 57 | ON_BN_CLICKED(IDC_BROWSE, OnBrowse) |
| 58 | //}}AFX_MSG_MAP |
| 59 | END_MESSAGE_MAP() |
| 60 | |
| 61 | ///////////////////////////////////////////////////////////////////////////// |
| 62 | // CVirtualCompilerConfig message handlers |
| 63 | |
| 64 | void CVirtualCompilerConfig::OnBrowse() { |
| 65 | UpdateData(true); |
| 66 | |
| 67 | char filename[255]; |
| 68 | |
| 69 | // Get the filename of the representing image |
| 70 | CString filter = "Descent III Virtual Compiler (*.exe)|*.exe||"; |
| 71 | |
| 72 | if (!OpenFileDialog(this, (LPCTSTR)filter, filename, Current_files_dir, sizeof(Current_files_dir))) |
| 73 | return; |
| 74 | |
| 75 | m_Compiler = filename; |
| 76 | |
| 77 | UpdateData(false); |
| 78 | } |
| 79 | |
| 80 | BOOL CVirtualCompilerConfig::OnInitDialog() { |
| 81 | CDialog::OnInitDialog(); |
| 82 | char buffer[_MAX_PATH]; |
| 83 | int len = _MAX_PATH; |
| 84 | |
| 85 | if (Database->read("EditorCompiler", buffer, &len)) { |
| 86 | m_Compiler = buffer; |
| 87 | } else { |
| 88 | m_Compiler = ""; |
| 89 | } |
| 90 | |
| 91 | if (Database->read_int("EditorVCWarningLevel", &len)) { |
| 92 | m_WarningLevel = len; |
| 93 | } else { |
| 94 | m_WarningLevel = 0; |
| 95 | } |
| 96 | |
| 97 | if (Database->read_int("EditorVCDebugLevel", &len)) { |
| 98 | m_DebugType = len; |
| 99 | } else { |
| 100 | m_DebugType = 0; |
| 101 | } |
| 102 | |
| 103 | UpdateData(false); |
| 104 | |
| 105 | return TRUE; |
| 106 | } |
| 107 | |
| 108 | void CVirtualCompilerConfig::OnOK() { |
| 109 | char buffer[_MAX_PATH]; |
| 110 | UpdateData(true); |
| 111 | |
| 112 | strcpy(buffer, m_Compiler.GetBuffer(0)); |
| 113 | Database->write("EditorCompiler", buffer, strlen(buffer) + 1); |
| 114 | |
| 115 | Database->write("EditorVCWarningLevel", m_WarningLevel); |
| 116 | Database->write("EditorVCDebugLevel", m_DebugType); |
| 117 | CDialog::OnOK(); |
| 118 | } |