wdeview.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. // WDView.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "wdump.h"
  22. #include "WDEView.h"
  23. #include "wdumpdoc.h"
  24. #include "chunk_d.h"
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CWDumpEditView
  32. IMPLEMENT_DYNCREATE(CWDumpEditView, CEditView)
  33. CWDumpEditView::CWDumpEditView()
  34. {
  35. }
  36. CWDumpEditView::~CWDumpEditView()
  37. {
  38. }
  39. BEGIN_MESSAGE_MAP(CWDumpEditView, CEditView)
  40. //{{AFX_MSG_MAP(CWDumpEditView)
  41. // NOTE - the ClassWizard will add and remove mapping macros here.
  42. //}}AFX_MSG_MAP
  43. END_MESSAGE_MAP()
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CWDumpEditView drawing
  46. void CWDumpEditView::OnDraw(CDC* pDC)
  47. {
  48. CDocument* pDoc = GetDocument();
  49. // TODO: add draw code here
  50. }
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CWDumpEditView diagnostics
  53. #ifdef _DEBUG
  54. void CWDumpEditView::AssertValid() const
  55. {
  56. CEditView::AssertValid();
  57. }
  58. void CWDumpEditView::Dump(CDumpContext& dc) const
  59. {
  60. CEditView::Dump(dc);
  61. }
  62. #endif //_DEBUG
  63. /////////////////////////////////////////////////////////////////////////////
  64. // CWDumpEditView message handlers
  65. void CWDumpEditView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
  66. {
  67. // TODO: Add your specialized code here and/or call the base class
  68. CEdit &edit = GetEditCtrl();
  69. edit.SetReadOnly(TRUE);
  70. CWdumpDoc *doc= (CWdumpDoc *) GetDocument();
  71. ChunkItem *item = doc->m_ChunkItem;
  72. if(item == 0) {
  73. edit.SetWindowText("Load a chunk file and select the chunk in the tree view to see it's hex data here.");
  74. return; // no selected chunk item, leave a clear screen.
  75. }
  76. char *text = Build_Hex_Text((unsigned char *) item->Data, item->Length);
  77. edit.SetWindowText(text);
  78. delete text;
  79. }
  80. char * CWDumpEditView::Build_Hex_Text(unsigned char * Source, int Length)
  81. {
  82. if(Source == 0) {
  83. char *c = new char[256];
  84. sprintf(c, "This chunk is a wrapper chunk for other chunks. It's total length is %d", Length);
  85. return c;
  86. }
  87. int per_line = 16;
  88. int lines = Length / per_line;
  89. int buf_size = Length * 5 + per_line * 5;
  90. char *buffer = new char[buf_size];
  91. char *dest = buffer;
  92. while(lines--) {
  93. if(lines == 0) {
  94. per_line = Length % per_line;
  95. }
  96. int counter = 0;
  97. do {
  98. sprintf(dest, "%02x ", Source[counter]);
  99. dest += 3;
  100. } while(++counter < per_line);
  101. *dest++ = ' ';
  102. *dest++ = ' ';
  103. counter = 0;
  104. do {
  105. char c = Source[counter];
  106. if(c >= 32 && c <= 192)
  107. *dest++ = c;
  108. else
  109. *dest++ = '.';
  110. } while(++counter < per_line);
  111. *dest++ = '\r';
  112. *dest++ = '\n';
  113. Source += per_line;
  114. }
  115. *dest = 0;
  116. return buffer;
  117. }