Radiant.cpp 7.5 KB

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