OutputForm.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. // OutputFormClass.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "outputform.h"
  23. #include "utils.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. /////////////////////////////////////////////////////////////////////////////
  30. // OutputFormClass
  31. //IMPLEMENT_DYNCREATE(OutputFormClass, DockableFormClass)
  32. /////////////////////////////////////////////////////////////////////////////
  33. //
  34. // OutputFormClass
  35. //
  36. /////////////////////////////////////////////////////////////////////////////
  37. OutputFormClass::OutputFormClass()
  38. : DockableFormClass(OutputFormClass::IDD)
  39. {
  40. //{{AFX_DATA_INIT(OutputFormClass)
  41. // NOTE: the ClassWizard will add member initialization here
  42. //}}AFX_DATA_INIT
  43. //
  44. // Create the log file
  45. //
  46. char filename[MAX_PATH];
  47. ::GetModuleFileName (NULL, filename, sizeof (filename));
  48. CString directory = ::Strip_Filename_From_Path (filename);
  49. CString full_path = Make_Path (directory, "_editorlog.txt");
  50. //
  51. // Try to open the log file
  52. //
  53. HANDLE file = ::CreateFile ( full_path,
  54. GENERIC_WRITE,
  55. FILE_SHARE_READ,
  56. NULL,
  57. OPEN_ALWAYS,
  58. 0L,
  59. NULL);
  60. //
  61. // If we succeeded then pass the handle onto our file object
  62. //
  63. if (file != INVALID_HANDLE_VALUE) {
  64. LogFile.Attach (file);
  65. }
  66. return ;
  67. }
  68. /////////////////////////////////////////////////////////////////////////////
  69. //
  70. // ~OutputFormClass
  71. //
  72. /////////////////////////////////////////////////////////////////////////////
  73. OutputFormClass::~OutputFormClass (void)
  74. {
  75. LogFile.Close ();
  76. return ;
  77. }
  78. /////////////////////////////////////////////////////////////////////////////
  79. //
  80. // DoDataExchange
  81. //
  82. void
  83. OutputFormClass::DoDataExchange(CDataExchange* pDX)
  84. {
  85. DockableFormClass::DoDataExchange(pDX);
  86. //{{AFX_DATA_MAP(OutputFormClass)
  87. DDX_Control(pDX, IDC_OUTPUT_EDIT, m_OutputEdit);
  88. //}}AFX_DATA_MAP
  89. return ;
  90. }
  91. BEGIN_MESSAGE_MAP(OutputFormClass, DockableFormClass)
  92. //{{AFX_MSG_MAP(OutputFormClass)
  93. ON_WM_CREATE()
  94. ON_WM_SIZE()
  95. //}}AFX_MSG_MAP
  96. END_MESSAGE_MAP()
  97. /////////////////////////////////////////////////////////////////////////////
  98. // OutputFormClass diagnostics
  99. #ifdef _DEBUG
  100. void OutputFormClass::AssertValid() const
  101. {
  102. DockableFormClass::AssertValid();
  103. }
  104. void OutputFormClass::Dump(CDumpContext& dc) const
  105. {
  106. DockableFormClass::Dump(dc);
  107. }
  108. #endif //_DEBUG
  109. /////////////////////////////////////////////////////////////////////////////
  110. // OutputFormClass message handlers
  111. /////////////////////////////////////////////////////////////////////////////
  112. //
  113. // OnCreate
  114. //
  115. int
  116. OutputFormClass::OnCreate (LPCREATESTRUCT lpCreateStruct)
  117. {
  118. // Allow the base class to process this message
  119. if (DockableFormClass::OnCreate(lpCreateStruct) == -1) {
  120. return -1;
  121. }
  122. return 0;
  123. }
  124. /////////////////////////////////////////////////////////////////////////////
  125. //
  126. // HandleInitDialog
  127. //
  128. void
  129. OutputFormClass::HandleInitDialog (void)
  130. {
  131. //
  132. // TODO - Any initialization
  133. //
  134. m_OutputEdit.SetTabStops (10);
  135. return ;
  136. }
  137. /////////////////////////////////////////////////////////////////////////////
  138. //
  139. // OnSize
  140. //
  141. void
  142. OutputFormClass::OnSize
  143. (
  144. UINT nType,
  145. int cx,
  146. int cy
  147. )
  148. {
  149. // Allow the base class to process this message
  150. DockableFormClass::OnSize (nType, cx, cy);
  151. if (::IsWindow (m_OutputEdit) && (cx > 0) && (cy > 0)) {
  152. // Resize the tab control to fill the entire contents of the client area
  153. m_OutputEdit.SetWindowPos (NULL, 0, 0, cx, cy, SWP_NOZORDER | SWP_NOMOVE);
  154. }
  155. return ;
  156. }
  157. /////////////////////////////////////////////////////////////////////////////
  158. //
  159. // Output_Message
  160. //
  161. void
  162. OutputFormClass::Output_Message (LPCTSTR new_message)
  163. {
  164. //
  165. // Turn off repainting
  166. //
  167. m_OutputEdit.SetRedraw (FALSE);
  168. // Get the text currently displayed in the window
  169. TCHAR window_text[32768] = { 0 };
  170. int curr_text_len = m_OutputEdit.GetWindowText (window_text, sizeof (window_text)) + 1;
  171. // Get the new text length
  172. int new_text_len = ::lstrlen (new_message);
  173. // Do we need to scroll text out of the buffer?
  174. if (curr_text_len + new_text_len > (32768 - 16)) {
  175. // Move the first 4K out of the buffer
  176. ::memmove (window_text, &window_text[4096], curr_text_len-4096);
  177. }
  178. // Concat the new message onto the current window text.
  179. ::lstrcat (window_text, new_message);
  180. // Make sure the message has a line feed
  181. if ( new_message[new_text_len-2] != '\r' &&
  182. new_message[new_text_len-1] == '\n')
  183. {
  184. int text_len = ::lstrlen (window_text);
  185. window_text[text_len-1] = '\r';
  186. window_text[text_len] = '\n';
  187. window_text[text_len+1] = 0;
  188. }
  189. // Put the text back into the edit control
  190. m_OutputEdit.SetWindowText (window_text);
  191. int line_count = m_OutputEdit.GetLineCount ();
  192. m_OutputEdit.LineScroll (line_count-4);
  193. //
  194. // Turn painting back on
  195. //
  196. m_OutputEdit.SetRedraw (TRUE);
  197. if (LogFile.Is_Open ()) {
  198. LogFile.Write ((const char *)new_message, ::lstrlen (new_message));
  199. }
  200. return ;
  201. }