Quake-III-Arena

Quake III Arena GPL Source Release
Log | Files | Refs

Radiant.cpp (7719B)


      1 /*
      2 ===========================================================================
      3 Copyright (C) 1999-2005 Id Software, Inc.
      4 
      5 This file is part of Quake III Arena source code.
      6 
      7 Quake III Arena source code is free software; you can redistribute it
      8 and/or modify it under the terms of the GNU General Public License as
      9 published by the Free Software Foundation; either version 2 of the License,
     10 or (at your option) any later version.
     11 
     12 Quake III Arena source code is distributed in the hope that it will be
     13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 GNU General Public License for more details.
     16 
     17 You should have received a copy of the GNU General Public License
     18 along with Foobar; if not, write to the Free Software
     19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     20 ===========================================================================
     21 */
     22 // Radiant.cpp : Defines the class behaviors for the application.
     23 //
     24 
     25 #include "stdafx.h"
     26 #include "Radiant.h"
     27 
     28 #include "MainFrm.h"
     29 #include "ChildFrm.h"
     30 #include "RadiantDoc.h"
     31 #include "RadiantView.h"
     32 #include "PrefsDlg.h"
     33 
     34 #ifdef _DEBUG
     35 #define new DEBUG_NEW
     36 #undef THIS_FILE
     37 static char THIS_FILE[] = __FILE__;
     38 #endif
     39 
     40 /////////////////////////////////////////////////////////////////////////////
     41 // CRadiantApp
     42 
     43 BEGIN_MESSAGE_MAP(CRadiantApp, CWinApp)
     44 	//{{AFX_MSG_MAP(CRadiantApp)
     45 	ON_COMMAND(ID_HELP, OnHelp)
     46 	//}}AFX_MSG_MAP
     47 	// Standard file based document commands
     48 	ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
     49 	ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
     50 	// Standard print setup command
     51 	ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
     52 END_MESSAGE_MAP()
     53 
     54 /////////////////////////////////////////////////////////////////////////////
     55 // CRadiantApp construction
     56 
     57 CRadiantApp::CRadiantApp()
     58 {
     59 	// TODO: add construction code here,
     60 	// Place all significant initialization in InitInstance
     61 }
     62 
     63 /////////////////////////////////////////////////////////////////////////////
     64 // The one and only CRadiantApp object
     65 
     66 CRadiantApp theApp;
     67 
     68 /////////////////////////////////////////////////////////////////////////////
     69 // CRadiantApp initialization
     70 
     71 HINSTANCE g_hOpenGL32 = NULL;
     72 HINSTANCE g_hOpenGL = NULL;
     73 bool g_bBuildList = false;
     74 
     75 BOOL CRadiantApp::InitInstance()
     76 {
     77   //g_hOpenGL32 = ::LoadLibrary("opengl32.dll");
     78 	// AfxEnableControlContainer();
     79 
     80 	// Standard initialization
     81 	// If you are not using these features and wish to reduce the size
     82 	//  of your final executable, you should remove from the following
     83 	//  the specific initialization routines you do not need.
     84   //AfxEnableMemoryTracking(FALSE);
     85 
     86 	// VC7 says deprecated and no longer necessary
     87 #if 0
     88 
     89 #ifdef _AFXDLL
     90 	Enable3dControls();			// Call this when using MFC in a shared DLL
     91 #else
     92 	Enable3dControlsStatic();	// Call this when linking to MFC statically
     93 #endif
     94 
     95 #endif
     96 
     97 	// If there's a .INI file in the directory use it instead of registry
     98 	char RadiantPath[_MAX_PATH];
     99 	GetModuleFileName( NULL, RadiantPath, _MAX_PATH );
    100 
    101 	// search for exe
    102 	CFileFind Finder;
    103 	Finder.FindFile( RadiantPath );
    104 	Finder.FindNextFile();
    105 	// extract root
    106 	CString Root = Finder.GetRoot();
    107 	// build root\*.ini
    108 	CString IniPath = Root + "\\REGISTRY.INI";
    109 	// search for ini file
    110 	Finder.FindNextFile();
    111 	if (Finder.FindFile( IniPath ))
    112 	{
    113 		Finder.FindNextFile();
    114 		// use the .ini file instead of the registry
    115 		free((void*)m_pszProfileName);
    116 		m_pszProfileName=_tcsdup(_T(Finder.GetFilePath()));
    117 		// look for the registry key for void* buffers storage ( these can't go into .INI files )
    118 		int i=0;
    119 		CString key;
    120 		HKEY hkResult;
    121 		DWORD dwDisp;
    122 		DWORD type;
    123 		char iBuf[3];
    124 		do
    125 		{
    126 			sprintf( iBuf, "%d", i );
    127 			key = "Software\\Q3Radiant\\IniPrefs" + CString(iBuf);
    128 			// does this key exists ?
    129 			if ( RegOpenKeyEx( HKEY_CURRENT_USER, key, 0, KEY_ALL_ACCESS, &hkResult ) != ERROR_SUCCESS )
    130 			{
    131 				// this key doesn't exist, so it's the one we'll use
    132 				strcpy( g_qeglobals.use_ini_registry, key.GetBuffer(0) );
    133 				RegCreateKeyEx( HKEY_CURRENT_USER, key, 0, NULL, 
    134 					REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkResult, &dwDisp );
    135 				RegSetValueEx( hkResult, "RadiantName", 0, REG_SZ, reinterpret_cast<CONST BYTE *>(RadiantPath), strlen( RadiantPath )+1 );
    136 				RegCloseKey( hkResult );
    137 				break;
    138 			}
    139 			else
    140 			{
    141 				char RadiantAux[ _MAX_PATH ];
    142 				unsigned long size = _MAX_PATH;
    143 				// the key exists, is it the one we are looking for ?
    144 				RegQueryValueEx( hkResult, "RadiantName", 0, &type, reinterpret_cast<BYTE *>(RadiantAux), &size );
    145 				RegCloseKey( hkResult );
    146 				if ( !strcmp( RadiantAux, RadiantPath ) )
    147 				{
    148 					// got it !
    149 					strcpy( g_qeglobals.use_ini_registry, key.GetBuffer(0) );
    150 					break;
    151 				}
    152 			}
    153 			i++;
    154 		} while (1);
    155 		g_qeglobals.use_ini = true;
    156 	}
    157 	else
    158 	{
    159 		// Change the registry key under which our settings are stored.
    160 		// You should modify this string to be something appropriate
    161 		// such as the name of your company or organization.
    162 		SetRegistryKey("Q3Radiant");
    163 		g_qeglobals.use_ini = false;
    164 	}
    165 
    166 	LoadStdProfileSettings();  // Load standard INI file options (including MRU)
    167 
    168 
    169 	// Register the application's document templates.  Document templates
    170 	//  serve as the connection between documents, frame windows and views.
    171 
    172 //	CMultiDocTemplate* pDocTemplate;
    173 //	pDocTemplate = new CMultiDocTemplate(
    174 //		IDR_RADIANTYPE,
    175 //		RUNTIME_CLASS(CRadiantDoc),
    176 //		RUNTIME_CLASS(CMainFrame), // custom MDI child frame
    177 //		RUNTIME_CLASS(CRadiantView));
    178 //	AddDocTemplate(pDocTemplate);
    179 
    180 	// create main MDI Frame window
    181 
    182   g_PrefsDlg.LoadPrefs();
    183 
    184   int nMenu = IDR_MENU1;
    185 
    186   CString strOpenGL = (g_PrefsDlg.m_bSGIOpenGL) ? "opengl.dll" : "opengl32.dll";
    187   CString strGLU = (g_PrefsDlg.m_bSGIOpenGL) ? "glu.dll" : "glu32.dll";
    188   
    189   if (!QGL_Init(strOpenGL, strGLU))
    190   {
    191     g_PrefsDlg.m_bSGIOpenGL ^= 1;
    192     strOpenGL = (g_PrefsDlg.m_bSGIOpenGL) ? "opengl.dll" : "opengl32.dll";
    193     strGLU = (g_PrefsDlg.m_bSGIOpenGL) ? "glu.dll" : "glu32.dll";
    194     if (!QGL_Init(strOpenGL, strGLU))
    195     {
    196       AfxMessageBox("Failed to load OpenGL libraries. \"OPENGL32.DLL\" and \"OPENGL.DLL\" were tried");
    197       return FALSE;
    198     }
    199     g_PrefsDlg.SavePrefs();
    200   }
    201 
    202 	CString strTemp = m_lpCmdLine;
    203   strTemp.MakeLower();
    204   if (strTemp.Find("builddefs") >= 0)
    205     g_bBuildList = true;
    206 
    207 	CMainFrame* pMainFrame = new CMainFrame;
    208 	if (!pMainFrame->LoadFrame(nMenu))
    209 		return FALSE;
    210 
    211   if (pMainFrame->m_hAccelTable)
    212     ::DestroyAcceleratorTable(pMainFrame->m_hAccelTable);
    213   
    214   pMainFrame->LoadAccelTable(MAKEINTRESOURCE(IDR_MINIACCEL));
    215 
    216 	m_pMainWnd = pMainFrame;
    217 
    218   // Parse command line for standard shell commands, DDE, file open
    219 	CCommandLineInfo cmdInfo;
    220 	ParseCommandLine(cmdInfo);
    221 
    222 	// Dispatch commands specified on the command line
    223 	//if (!ProcessShellCommand(cmdInfo))
    224 	//	return FALSE;
    225 
    226 	// The main window has been initialized, so show and update it.
    227 	pMainFrame->ShowWindow(m_nCmdShow);
    228 	pMainFrame->UpdateWindow();
    229 
    230   free((void*)m_pszHelpFilePath);
    231   CString strHelp = g_strAppPath;
    232   AddSlash(strHelp);
    233   strHelp += "Q3RManual.chm";
    234   m_pszHelpFilePath= _tcsdup(strHelp);
    235 
    236 
    237 	return TRUE;
    238 }
    239 
    240 /////////////////////////////////////////////////////////////////////////////
    241 // CRadiantApp commands
    242 
    243 int CRadiantApp::ExitInstance() 
    244 {
    245 	// TODO: Add your specialized code here and/or call the base class
    246   //::FreeLibrary(g_hOpenGL32);
    247 	QGL_Shutdown();
    248 	return CWinApp::ExitInstance();
    249 }
    250 
    251 BOOL CRadiantApp::OnIdle(LONG lCount) 
    252 {
    253 	if (g_pParentWnd)
    254     g_pParentWnd->RoutineProcessing();
    255 	return CWinApp::OnIdle(lCount);
    256 }
    257 
    258 void CRadiantApp::OnHelp() 
    259 {
    260   ShellExecute(m_pMainWnd->GetSafeHwnd(), "open", m_pszHelpFilePath, NULL, NULL, SW_SHOW);
    261 }