Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

Radiant.cpp

Go to the documentation of this file.
00001 /*
00002 ===========================================================================
00003 Copyright (C) 1999-2005 Id Software, Inc.
00004 
00005 This file is part of Quake III Arena source code.
00006 
00007 Quake III Arena source code is free software; you can redistribute it
00008 and/or modify it under the terms of the GNU General Public License as
00009 published by the Free Software Foundation; either version 2 of the License,
00010 or (at your option) any later version.
00011 
00012 Quake III Arena source code is distributed in the hope that it will be
00013 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Foobar; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 ===========================================================================
00021 */
00022 // Radiant.cpp : Defines the class behaviors for the application.
00023 //
00024 
00025 #include "stdafx.h"
00026 #include "Radiant.h"
00027 
00028 #include "MainFrm.h"
00029 #include "ChildFrm.h"
00030 #include "RadiantDoc.h"
00031 #include "RadiantView.h"
00032 #include "PrefsDlg.h"
00033 
00034 #ifdef _DEBUG
00035 #define new DEBUG_NEW
00036 #undef THIS_FILE
00037 static char THIS_FILE[] = __FILE__;
00038 #endif
00039 
00041 // CRadiantApp
00042 
00043 BEGIN_MESSAGE_MAP(CRadiantApp, CWinApp)
00044     //{{AFX_MSG_MAP(CRadiantApp)
00045     ON_COMMAND(ID_HELP, OnHelp)
00046     //}}AFX_MSG_MAP
00047     // Standard file based document commands
00048     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
00049     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
00050     // Standard print setup command
00051     ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
00052 END_MESSAGE_MAP()
00053 
00055 // CRadiantApp construction
00056 
00057 CRadiantApp::CRadiantApp()
00058 {
00059     // TODO: add construction code here,
00060     // Place all significant initialization in InitInstance
00061 }
00062 
00064 // The one and only CRadiantApp object
00065 
00066 CRadiantApp theApp;
00067 
00069 // CRadiantApp initialization
00070 
00071 HINSTANCE g_hOpenGL32 = NULL;
00072 HINSTANCE g_hOpenGL = NULL;
00073 bool g_bBuildList = false;
00074 
00075 BOOL CRadiantApp::InitInstance()
00076 {
00077   //g_hOpenGL32 = ::LoadLibrary("opengl32.dll");
00078     // AfxEnableControlContainer();
00079 
00080     // Standard initialization
00081     // If you are not using these features and wish to reduce the size
00082     //  of your final executable, you should remove from the following
00083     //  the specific initialization routines you do not need.
00084   //AfxEnableMemoryTracking(FALSE);
00085 
00086     // VC7 says deprecated and no longer necessary
00087 #if 0
00088 
00089 #ifdef _AFXDLL
00090     Enable3dControls();         // Call this when using MFC in a shared DLL
00091 #else
00092     Enable3dControlsStatic();   // Call this when linking to MFC statically
00093 #endif
00094 
00095 #endif
00096 
00097     // If there's a .INI file in the directory use it instead of registry
00098     char RadiantPath[_MAX_PATH];
00099     GetModuleFileName( NULL, RadiantPath, _MAX_PATH );
00100 
00101     // search for exe
00102     CFileFind Finder;
00103     Finder.FindFile( RadiantPath );
00104     Finder.FindNextFile();
00105     // extract root
00106     CString Root = Finder.GetRoot();
00107     // build root\*.ini
00108     CString IniPath = Root + "\\REGISTRY.INI";
00109     // search for ini file
00110     Finder.FindNextFile();
00111     if (Finder.FindFile( IniPath ))
00112     {
00113         Finder.FindNextFile();
00114         // use the .ini file instead of the registry
00115         free((void*)m_pszProfileName);
00116         m_pszProfileName=_tcsdup(_T(Finder.GetFilePath()));
00117         // look for the registry key for void* buffers storage ( these can't go into .INI files )
00118         int i=0;
00119         CString key;
00120         HKEY hkResult;
00121         DWORD dwDisp;
00122         DWORD type;
00123         char iBuf[3];
00124         do
00125         {
00126             sprintf( iBuf, "%d", i );
00127             key = "Software\\Q3Radiant\\IniPrefs" + CString(iBuf);
00128             // does this key exists ?
00129             if ( RegOpenKeyEx( HKEY_CURRENT_USER, key, 0, KEY_ALL_ACCESS, &hkResult ) != ERROR_SUCCESS )
00130             {
00131                 // this key doesn't exist, so it's the one we'll use
00132                 strcpy( g_qeglobals.use_ini_registry, key.GetBuffer(0) );
00133                 RegCreateKeyEx( HKEY_CURRENT_USER, key, 0, NULL, 
00134                     REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkResult, &dwDisp );
00135                 RegSetValueEx( hkResult, "RadiantName", 0, REG_SZ, reinterpret_cast<CONST BYTE *>(RadiantPath), strlen( RadiantPath )+1 );
00136                 RegCloseKey( hkResult );
00137                 break;
00138             }
00139             else
00140             {
00141                 char RadiantAux[ _MAX_PATH ];
00142                 unsigned long size = _MAX_PATH;
00143                 // the key exists, is it the one we are looking for ?
00144                 RegQueryValueEx( hkResult, "RadiantName", 0, &type, reinterpret_cast<BYTE *>(RadiantAux), &size );
00145                 RegCloseKey( hkResult );
00146                 if ( !strcmp( RadiantAux, RadiantPath ) )
00147                 {
00148                     // got it !
00149                     strcpy( g_qeglobals.use_ini_registry, key.GetBuffer(0) );
00150                     break;
00151                 }
00152             }
00153             i++;
00154         } while (1);
00155         g_qeglobals.use_ini = true;
00156     }
00157     else
00158     {
00159         // Change the registry key under which our settings are stored.
00160         // You should modify this string to be something appropriate
00161         // such as the name of your company or organization.
00162         SetRegistryKey("Q3Radiant");
00163         g_qeglobals.use_ini = false;
00164     }
00165 
00166     LoadStdProfileSettings();  // Load standard INI file options (including MRU)
00167 
00168 
00169     // Register the application's document templates.  Document templates
00170     //  serve as the connection between documents, frame windows and views.
00171 
00172 //  CMultiDocTemplate* pDocTemplate;
00173 //  pDocTemplate = new CMultiDocTemplate(
00174 //      IDR_RADIANTYPE,
00175 //      RUNTIME_CLASS(CRadiantDoc),
00176 //      RUNTIME_CLASS(CMainFrame), // custom MDI child frame
00177 //      RUNTIME_CLASS(CRadiantView));
00178 //  AddDocTemplate(pDocTemplate);
00179 
00180     // create main MDI Frame window
00181 
00182   g_PrefsDlg.LoadPrefs();
00183 
00184   int nMenu = IDR_MENU1;
00185 
00186   CString strOpenGL = (g_PrefsDlg.m_bSGIOpenGL) ? "opengl.dll" : "opengl32.dll";
00187   CString strGLU = (g_PrefsDlg.m_bSGIOpenGL) ? "glu.dll" : "glu32.dll";
00188   
00189   if (!QGL_Init(strOpenGL, strGLU))
00190   {
00191     g_PrefsDlg.m_bSGIOpenGL ^= 1;
00192     strOpenGL = (g_PrefsDlg.m_bSGIOpenGL) ? "opengl.dll" : "opengl32.dll";
00193     strGLU = (g_PrefsDlg.m_bSGIOpenGL) ? "glu.dll" : "glu32.dll";
00194     if (!QGL_Init(strOpenGL, strGLU))
00195     {
00196       AfxMessageBox("Failed to load OpenGL libraries. \"OPENGL32.DLL\" and \"OPENGL.DLL\" were tried");
00197       return FALSE;
00198     }
00199     g_PrefsDlg.SavePrefs();
00200   }
00201 
00202     CString strTemp = m_lpCmdLine;
00203   strTemp.MakeLower();
00204   if (strTemp.Find("builddefs") >= 0)
00205     g_bBuildList = true;
00206 
00207     CMainFrame* pMainFrame = new CMainFrame;
00208     if (!pMainFrame->LoadFrame(nMenu))
00209         return FALSE;
00210 
00211   if (pMainFrame->m_hAccelTable)
00212     ::DestroyAcceleratorTable(pMainFrame->m_hAccelTable);
00213   
00214   pMainFrame->LoadAccelTable(MAKEINTRESOURCE(IDR_MINIACCEL));
00215 
00216     m_pMainWnd = pMainFrame;
00217 
00218   // Parse command line for standard shell commands, DDE, file open
00219     CCommandLineInfo cmdInfo;
00220     ParseCommandLine(cmdInfo);
00221 
00222     // Dispatch commands specified on the command line
00223     //if (!ProcessShellCommand(cmdInfo))
00224     //  return FALSE;
00225 
00226     // The main window has been initialized, so show and update it.
00227     pMainFrame->ShowWindow(m_nCmdShow);
00228     pMainFrame->UpdateWindow();
00229 
00230   free((void*)m_pszHelpFilePath);
00231   CString strHelp = g_strAppPath;
00232   AddSlash(strHelp);
00233   strHelp += "Q3RManual.chm";
00234   m_pszHelpFilePath= _tcsdup(strHelp);
00235 
00236 
00237     return TRUE;
00238 }
00239 
00241 // CRadiantApp commands
00242 
00243 int CRadiantApp::ExitInstance() 
00244 {
00245     // TODO: Add your specialized code here and/or call the base class
00246   //::FreeLibrary(g_hOpenGL32);
00247     QGL_Shutdown();
00248     return CWinApp::ExitInstance();
00249 }
00250 
00251 BOOL CRadiantApp::OnIdle(LONG lCount) 
00252 {
00253     if (g_pParentWnd)
00254     g_pParentWnd->RoutineProcessing();
00255     return CWinApp::OnIdle(lCount);
00256 }
00257 
00258 void CRadiantApp::OnHelp() 
00259 {
00260   ShellExecute(m_pMainWnd->GetSafeHwnd(), "open", m_pszHelpFilePath, NULL, NULL, SW_SHOW);
00261 }

Generated on Thu Aug 25 12:38:38 2005 for Quake III Arena by  doxygen 1.3.9.1