wdump.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. // wdump.cpp : Defines the class behaviors for the application.
  19. //
  20. #include "stdafx.h"
  21. #include "wdump.h"
  22. #include "MainFrm.h"
  23. #include "wdumpDoc.h"
  24. #include "wdView.h"
  25. #include "FCNTL.H"
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CWdumpApp
  33. BEGIN_MESSAGE_MAP(CWdumpApp, CWinApp)
  34. //{{AFX_MSG_MAP(CWdumpApp)
  35. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  36. // NOTE - the ClassWizard will add and remove mapping macros here.
  37. // DO NOT EDIT what you see in these blocks of generated code!
  38. //}}AFX_MSG_MAP
  39. // Standard file based document commands
  40. ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  41. ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  42. END_MESSAGE_MAP()
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CWdumpApp construction
  45. CWdumpApp::CWdumpApp()
  46. : DumpTextures(false), NoWindow(false), TextureDumpFile(0)
  47. {
  48. // TODO: add construction code here,
  49. // Place all significant initialization in InitInstance
  50. }
  51. /////////////////////////////////////////////////////////////////////////////
  52. // The one and only CWdumpApp object
  53. CWdumpApp theApp;
  54. // private class declaration of a CCommandLineInfo class that knows about our special options
  55. class CWDumpCommandLineInfo : public CCommandLineInfo
  56. {
  57. virtual void ParseParam(const TCHAR* pszParam,BOOL bFlag,BOOL bLast)
  58. {
  59. if (bFlag)
  60. {
  61. if(pszParam[0] == 't') {
  62. theApp.DumpTextures = true;
  63. ParseLast(bLast);
  64. return;
  65. }
  66. if(pszParam[0] == 'q') {
  67. theApp.NoWindow = true;
  68. ParseLast(bLast);
  69. return;
  70. }
  71. }
  72. CCommandLineInfo::ParseParam(pszParam, bFlag, bLast);
  73. }
  74. };
  75. /////////////////////////////////////////////////////////////////////////////
  76. // CWdumpApp initialization
  77. BOOL CWdumpApp::InitInstance()
  78. {
  79. // Standard initialization
  80. // If you are not using these features and wish to reduce the size
  81. // of your final executable, you should remove from the following
  82. // the specific initialization routines you do not need.
  83. #ifdef _AFXDLL
  84. Enable3dControls(); // Call this when using MFC in a shared DLL
  85. #else
  86. Enable3dControlsStatic(); // Call this when linking to MFC statically
  87. #endif
  88. // Change the registry key under which our settings are stored.
  89. // You should modify this string to be something appropriate
  90. // such as the name of your company or organization.
  91. SetRegistryKey(_T("Westwood Studios"));
  92. LoadStdProfileSettings(); // Load standard INI file options (including MRU)
  93. // Register the application's document templates. Document templates
  94. // serve as the connection between documents, frame windows and views.
  95. CSingleDocTemplate* pDocTemplate;
  96. pDocTemplate = new CSingleDocTemplate(
  97. IDR_MAINFRAME,
  98. RUNTIME_CLASS(CWdumpDoc),
  99. RUNTIME_CLASS(CMainFrame), // main SDI frame window
  100. RUNTIME_CLASS(CWdumpView));
  101. AddDocTemplate(pDocTemplate);
  102. // Parse command line for standard shell commands, DDE, file open
  103. CWDumpCommandLineInfo cmdInfo;
  104. ParseCommandLine(cmdInfo);
  105. // note: if any other dump types are enabled, they should probably open different files.
  106. if(DumpTextures) {
  107. TextureDumpFile = fopen("textures.txt", "a");
  108. }
  109. if(NoWindow) {
  110. if(cmdInfo.m_nShellCommand == CWDumpCommandLineInfo::FileOpen) {
  111. const char *c = strrchr(cmdInfo.m_strFileName, '\\');
  112. if(c == 0)
  113. c = (LPCTSTR) cmdInfo.m_strFileName;
  114. if(*c == '\\')
  115. c++;
  116. Filename = c;
  117. /* STARTUPINFO info;
  118. GetStartupInfo(&info);
  119. if(info.hStdOutput == NULL) {
  120. AllocConsole(); // Allocate console window
  121. freopen("CONOUT$", "a", stdout);
  122. freopen("CONIN$", "r", stdin);
  123. } else {
  124. int CrtInput;
  125. int CrtOutput;
  126. if ( (CrtInput =_open_osfhandle((long) info.hStdInput, _O_RDONLY)) != -1) {
  127. if ( (CrtOutput = _open_osfhandle((long) info.hStdOutput, _O_APPEND)) != -1) {
  128. _dup2( CrtInput, 0);
  129. _dup2( CrtOutput, 1);
  130. }
  131. }
  132. // stdin = (struct _iobuf * ) info.hStdInput;
  133. // stdout = (struct _iobuf * ) info.hStdOutput;
  134. }
  135. */
  136. CWdumpDoc *doc = (CWdumpDoc *) pDocTemplate->OpenDocumentFile(cmdInfo.m_strFileName, FALSE);
  137. /* if(info.hStdOutput == NULL) {
  138. printf("Press return to close this window..");
  139. getchar();
  140. FreeConsole();
  141. }
  142. */
  143. CloseAllDocuments(TRUE);
  144. PostQuitMessage(0);
  145. return TRUE;
  146. }
  147. }
  148. // Dispatch commands specified on the command line
  149. if (!ProcessShellCommand(cmdInfo))
  150. return FALSE;
  151. m_pMainWnd->ShowWindow(SW_SHOW);
  152. m_pMainWnd->UpdateWindow();
  153. POSITION p = pDocTemplate->GetFirstDocPosition();
  154. CWdumpDoc *doc = (CWdumpDoc *) pDocTemplate->GetNextDoc(p);
  155. doc->UpdateAllViews(0);
  156. return TRUE;
  157. }
  158. /////////////////////////////////////////////////////////////////////////////
  159. // CAboutDlg dialog used for App About
  160. class CAboutDlg : public CDialog
  161. {
  162. public:
  163. CAboutDlg();
  164. // Dialog Data
  165. //{{AFX_DATA(CAboutDlg)
  166. enum { IDD = IDD_ABOUTBOX };
  167. //}}AFX_DATA
  168. // ClassWizard generated virtual function overrides
  169. //{{AFX_VIRTUAL(CAboutDlg)
  170. protected:
  171. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  172. //}}AFX_VIRTUAL
  173. // Implementation
  174. protected:
  175. //{{AFX_MSG(CAboutDlg)
  176. // No message handlers
  177. //}}AFX_MSG
  178. DECLARE_MESSAGE_MAP()
  179. };
  180. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  181. {
  182. //{{AFX_DATA_INIT(CAboutDlg)
  183. //}}AFX_DATA_INIT
  184. }
  185. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  186. {
  187. CDialog::DoDataExchange(pDX);
  188. //{{AFX_DATA_MAP(CAboutDlg)
  189. //}}AFX_DATA_MAP
  190. }
  191. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  192. //{{AFX_MSG_MAP(CAboutDlg)
  193. // No message handlers
  194. //}}AFX_MSG_MAP
  195. END_MESSAGE_MAP()
  196. // App command to run the dialog
  197. void CWdumpApp::OnAppAbout()
  198. {
  199. CAboutDlg aboutDlg;
  200. aboutDlg.DoModal();
  201. }
  202. /////////////////////////////////////////////////////////////////////////////
  203. // CWdumpApp commands