LightMap.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  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. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : LightMap *
  23. * *
  24. * $Archive:: /Commando/Code/Tool $*
  25. * *
  26. * $Author:: Ian_l $*
  27. * *
  28. * $Modtime:: 7/19/01 8:13p $*
  29. * *
  30. * $Revision:: 11 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. // Includes.
  36. #include "StdAfx.h"
  37. #include "LightMap.h"
  38. #include "LightMapView.h"
  39. #include "MainFrm.h"
  40. #include "verchk.h"
  41. #include <stdlib.h>
  42. #include <direct.h>
  43. // Static functions.
  44. BOOL CALLBACK TopLevelWindowSearch (HWND hwnd, LPARAM lParam);
  45. // The following is maintained by MFC tools.
  46. #ifdef _DEBUG
  47. #define new DEBUG_NEW
  48. #undef THIS_FILE
  49. static char THIS_FILE[] = __FILE__;
  50. #endif
  51. BEGIN_MESSAGE_MAP(LightMapApp, CWinApp)
  52. //{{AFX_MSG_MAP(LightMapApp)
  53. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  54. ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
  55. //}}AFX_MSG_MAP
  56. // Standard file based document commands
  57. ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  58. ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  59. END_MESSAGE_MAP()
  60. // The one and only LightMapApp object
  61. LightMapApp theApp;
  62. class CAboutDlg : public CDialog
  63. {
  64. public:
  65. CAboutDlg();
  66. // Dialog Data
  67. //{{AFX_DATA(CAboutDlg)
  68. enum { IDD = IDD_ABOUTBOX };
  69. //}}AFX_DATA
  70. // ClassWizard generated virtual function overrides
  71. //{{AFX_VIRTUAL(CAboutDlg)
  72. protected:
  73. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  74. //}}AFX_VIRTUAL
  75. // Implementation
  76. protected:
  77. //{{AFX_MSG(CAboutDlg)
  78. virtual BOOL OnInitDialog();
  79. //}}AFX_MSG
  80. DECLARE_MESSAGE_MAP()
  81. };
  82. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  83. {
  84. //{{AFX_DATA_INIT(CAboutDlg)
  85. //}}AFX_DATA_INIT
  86. }
  87. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  88. {
  89. CDialog::DoDataExchange(pDX);
  90. //{{AFX_DATA_MAP(CAboutDlg)
  91. //}}AFX_DATA_MAP
  92. }
  93. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  94. //{{AFX_MSG_MAP(CAboutDlg)
  95. //}}AFX_MSG_MAP
  96. END_MESSAGE_MAP()
  97. /***********************************************************************************************
  98. * LightMapApp:: -- *
  99. * *
  100. * INPUT: *
  101. * *
  102. * OUTPUT: *
  103. * *
  104. * WARNINGS: *
  105. * *
  106. * HISTORY: *
  107. * 6/1/99 IML : Created. *
  108. *=============================================================================================*/
  109. LightMapApp::LightMapApp()
  110. {
  111. // NOTE: Place all significant initialization in InitInstance
  112. }
  113. /***********************************************************************************************
  114. * LightMapApp:: -- *
  115. * *
  116. * INPUT: *
  117. * *
  118. * OUTPUT: *
  119. * *
  120. * WARNINGS: *
  121. * *
  122. * HISTORY: *
  123. * 6/1/99 IML : Created. *
  124. *=============================================================================================*/
  125. BOOL LightMapApp::InitInstance()
  126. {
  127. char computername [MAX_COMPUTERNAME_LENGTH + 1];
  128. char processidname [33];
  129. DWORD computernamesize;
  130. // Standard initialization
  131. // If you are not using these features and wish to reduce the size
  132. // of your final executable, you should remove from the following
  133. // specific initialization routines you do not need.
  134. #ifdef _AFXDLL
  135. Enable3dControls(); // Call this when using MFC in a shared DLL
  136. #else
  137. Enable3dControlsStatic(); // Call this when linking to MFC statically
  138. #endif
  139. Do_Version_Check();
  140. // Set the working path.
  141. _getdcwd (0, WorkingPath, sizeof (WorkingPath));
  142. strcat (WorkingPath, "\\");
  143. // Set the instance name.
  144. computernamesize = sizeof (computername);
  145. GetComputerName (computername, &computernamesize);
  146. itoa (GetCurrentProcessId(), processidname, 16);
  147. strcpy (InstanceName, computername);
  148. strcat (InstanceName, processidname);
  149. // Version 0.1 by default.
  150. ApplicationVersion = 1;
  151. // Get the name and path of the currently executing application.
  152. TCHAR filename [MAX_PATH];
  153. ::GetModuleFileName (NULL, filename, sizeof (filename));
  154. // Get the version information for this application.
  155. DWORD dummy_var = 0;
  156. DWORD version_size = ::GetFileVersionInfoSize (filename, &dummy_var);
  157. if (version_size > 0) {
  158. // Get the file version block
  159. LPBYTE pblock = new BYTE [version_size];
  160. if (::GetFileVersionInfo (filename, 0L, version_size, pblock)) {
  161. // Query the block for the file version information.
  162. UINT version_len = 0;
  163. VS_FIXEDFILEINFO *pversion_info = NULL;
  164. if (::VerQueryValue (pblock, "\\", (LPVOID*) &pversion_info, &version_len)) {
  165. ApplicationVersion = pversion_info->dwFileVersionMS;
  166. }
  167. }
  168. delete [] pblock;
  169. }
  170. SetRegistryKey ("Westwood Studios");
  171. LoadStdProfileSettings(); // Load standard INI file options (including MRU)
  172. // Register the application's document templates. Document templates
  173. // serve as the connection between documents, frame windows and views.
  174. CSingleDocTemplate* pDocTemplate;
  175. pDocTemplate = new CSingleDocTemplate(
  176. IDR_MAINFRAME,
  177. RUNTIME_CLASS(LightMapDoc),
  178. RUNTIME_CLASS(CMainFrame),
  179. RUNTIME_CLASS(LightMapView));
  180. AddDocTemplate(pDocTemplate);
  181. // Parse command line for standard shell commands, DDE, file open.
  182. CCommandLineInfo cmdInfo;
  183. ParseCommandLine (cmdInfo);
  184. EnableShellOpen();
  185. RegisterShellFileTypes (TRUE);
  186. // Dispatch commands specified on the command line.
  187. if (!ProcessShellCommand (cmdInfo)) return (FALSE);
  188. m_pMainWnd->DragAcceptFiles();
  189. return (TRUE);
  190. }
  191. /***********************************************************************************************
  192. * LightMapApp::Do_Version_Check -- Check if this version of lightmap is newer or older than *
  193. * a version at a designated location on the network and if *
  194. * older then report this fact to user. *
  195. * *
  196. * INPUT: *
  197. * *
  198. * OUTPUT: *
  199. * *
  200. * WARNINGS: *
  201. * *
  202. * HISTORY: *
  203. * 05/15/00 IML : Created. *
  204. *=============================================================================================*/
  205. void LightMapApp::Do_Version_Check()
  206. {
  207. const char *networkpath = "\\\\Mobius\\Project7\\Projects\\Renegade\\Programming\\Tools\\Lightmap";
  208. const char *newversiontext = "There is a newer version of the Lightmap tool. Please run 'Renegade Update' to update your local copy.";
  209. char pathname [_MAX_PATH];
  210. char filename [_MAX_FNAME];
  211. char extension [_MAX_EXT];
  212. ::GetModuleFileName (NULL, pathname, MAX_PATH);
  213. _splitpath (pathname, NULL, NULL, filename, extension);
  214. strcpy (pathname, "\\\\Mobius\\Project7\\Projects\\Renegade\\Programming\\Tools\\Lightmap\\");
  215. strcat (pathname, filename);
  216. strcat (pathname, extension);
  217. if (Compare_EXE_Version ((int)::AfxGetInstanceHandle(), pathname) < 0) {
  218. ::MessageBox (NULL, newversiontext, "Version Information", MB_ICONEXCLAMATION | MB_OK | MB_SETFOREGROUND | MB_SYSTEMMODAL);
  219. }
  220. }
  221. /***********************************************************************************************
  222. * LightMapApp::TopLevelWindowSearch -- *
  223. * *
  224. * INPUT: *
  225. * *
  226. * OUTPUT: *
  227. * *
  228. * WARNINGS: *
  229. * *
  230. * HISTORY: *
  231. * 05/15/00 IML : Created. *
  232. *=============================================================================================*/
  233. BOOL CALLBACK TopLevelWindowSearch (HWND hwnd, LPARAM lParam)
  234. {
  235. BOOL bcontinue = TRUE;
  236. // Is this a viewer window?
  237. if (::GetProp (hwnd, "LIGHTMAP") != 0) {
  238. bcontinue = FALSE;
  239. (*((HWND*)lParam)) = hwnd;
  240. }
  241. return (bcontinue);
  242. }
  243. /***********************************************************************************************
  244. * LightMapApp:: -- *
  245. * *
  246. * INPUT: *
  247. * *
  248. * OUTPUT: *
  249. * *
  250. * WARNINGS: *
  251. * *
  252. * HISTORY: *
  253. * 6/1/99 IML : Created. *
  254. *=============================================================================================*/
  255. LightMapDoc* LightMapApp::GetDoc()
  256. {
  257. POSITION pos = GetFirstDocTemplatePosition();
  258. CDocTemplate *pDocTemplate = GetNextDocTemplate (pos);
  259. pos = pDocTemplate->GetFirstDocPosition();
  260. LightMapDoc* pDoc = (LightMapDoc*)pDocTemplate->GetNextDoc (pos);
  261. ASSERT (pDoc->IsKindOf(RUNTIME_CLASS(LightMapDoc)));
  262. return (pDoc);
  263. }
  264. /***********************************************************************************************
  265. * LightMapApp:: -- *
  266. * *
  267. * INPUT: *
  268. * *
  269. * OUTPUT: *
  270. * *
  271. * WARNINGS: *
  272. * *
  273. * HISTORY: *
  274. * 6/1/99 IML : Created. *
  275. *=============================================================================================*/
  276. void LightMapApp::OnAppAbout()
  277. {
  278. CAboutDlg aboutDlg;
  279. aboutDlg.DoModal();
  280. }
  281. /***********************************************************************************************
  282. * LightMapApp::OnFileOpen -- *
  283. * *
  284. * INPUT: *
  285. * *
  286. * OUTPUT: *
  287. * *
  288. * WARNINGS: *
  289. * *
  290. * HISTORY: *
  291. * 6/1/99 IML : Created. *
  292. *=============================================================================================*/
  293. void LightMapApp::OnFileOpen()
  294. {
  295. CFileDialog dialog (TRUE, NULL, NULL, File_Dialog_Flags(), File_Dialog_Filter());
  296. if (dialog.DoModal() == IDOK) {
  297. if (GetDoc()->OnOpenDocument (dialog.GetPathName())) {
  298. GetDoc()->SetPathName (dialog.GetPathName());
  299. GetDoc()->UpdateAllViews (NULL);
  300. }
  301. }
  302. }
  303. /***********************************************************************************************
  304. * LightMapApp::Explorer_Style -- *
  305. * *
  306. * INPUT: *
  307. * *
  308. * OUTPUT: *
  309. * *
  310. * WARNINGS: *
  311. * *
  312. * HISTORY: *
  313. * 6/1/99 IML : Created. *
  314. *=============================================================================================*/
  315. bool LightMapApp::Explorer_Style()
  316. {
  317. OSVERSIONINFO info;
  318. info.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
  319. ::GetVersionEx (&info);
  320. return ((info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) || ((info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion >= 4)));
  321. }
  322. /***********************************************************************************************
  323. * LightMapApp::File_Dialog_Flags -- *
  324. * *
  325. * INPUT: *
  326. * *
  327. * OUTPUT: *
  328. * *
  329. * WARNINGS: *
  330. * *
  331. * HISTORY: *
  332. * 6/1/99 IML : Created. *
  333. *=============================================================================================*/
  334. DWORD LightMapApp::File_Dialog_Flags()
  335. {
  336. DWORD flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT;
  337. if (Explorer_Style()) flags |= OFN_EXPLORER;
  338. return (flags);
  339. }
  340. /***********************************************************************************************
  341. * CAboutDlg::OnInitDialog -- *
  342. * *
  343. * INPUT: *
  344. * *
  345. * OUTPUT: *
  346. * *
  347. * WARNINGS: *
  348. * *
  349. * HISTORY: *
  350. * 6/1/99 IML : Created. *
  351. *=============================================================================================*/
  352. BOOL CAboutDlg::OnInitDialog()
  353. {
  354. // Allow the base class to process this message.
  355. CDialog::OnInitDialog();
  356. // Put the version string into the dialog.
  357. CString version_string;
  358. version_string.Format ("Version %d.%d", (theApp.Application_Version() >> 16), (theApp.Application_Version() & 0xffff));
  359. GetDlgItem (IDC_VERSION_TEXT)->SetWindowText (version_string);
  360. return TRUE; // return TRUE unless you set the focus to a control
  361. // EXCEPTION: OCX Property Pages should return FALSE
  362. }