CopyLockedDlg.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. // CopyLockedDlg.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "CopyLocked.h"
  22. #include "CopyLockedDlg.h"
  23. #ifdef _DEBUG
  24. #define new DEBUG_NEW
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CCopyLockedDlg dialog
  30. CCopyLockedDlg::CCopyLockedDlg(CWnd* pParent /*=NULL*/)
  31. : CDialog(CCopyLockedDlg::IDD, pParent)
  32. {
  33. //{{AFX_DATA_INIT(CCopyLockedDlg)
  34. // NOTE: the ClassWizard will add member initialization here
  35. //}}AFX_DATA_INIT
  36. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  37. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  38. }
  39. void CCopyLockedDlg::DoDataExchange(CDataExchange* pDX)
  40. {
  41. CDialog::DoDataExchange(pDX);
  42. //{{AFX_DATA_MAP(CCopyLockedDlg)
  43. // NOTE: the ClassWizard will add DDX and DDV calls here
  44. //}}AFX_DATA_MAP
  45. }
  46. BEGIN_MESSAGE_MAP(CCopyLockedDlg, CDialog)
  47. //{{AFX_MSG_MAP(CCopyLockedDlg)
  48. ON_WM_PAINT()
  49. ON_WM_QUERYDRAGICON()
  50. //}}AFX_MSG_MAP
  51. END_MESSAGE_MAP()
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CCopyLockedDlg message handlers
  54. BOOL CCopyLockedDlg::OnInitDialog()
  55. {
  56. CDialog::OnInitDialog();
  57. // Set the icon for this dialog. The framework does this automatically
  58. // when the application's main window is not a dialog
  59. SetIcon(m_hIcon, TRUE); // Set big icon
  60. SetIcon(m_hIcon, FALSE); // Set small icon
  61. // TODO: Add extra initialization here
  62. return TRUE; // return TRUE unless you set the focus to a control
  63. }
  64. // If you add a minimize button to your dialog, you will need the code below
  65. // to draw the icon. For MFC applications using the document/view model,
  66. // this is automatically done for you by the framework.
  67. void CCopyLockedDlg::OnPaint()
  68. {
  69. if (IsIconic())
  70. {
  71. CPaintDC dc(this); // device context for painting
  72. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  73. // Center icon in client rectangle
  74. int cxIcon = GetSystemMetrics(SM_CXICON);
  75. int cyIcon = GetSystemMetrics(SM_CYICON);
  76. CRect rect;
  77. GetClientRect(&rect);
  78. int x = (rect.Width() - cxIcon + 1) / 2;
  79. int y = (rect.Height() - cyIcon + 1) / 2;
  80. // Draw the icon
  81. dc.DrawIcon(x, y, m_hIcon);
  82. }
  83. else
  84. {
  85. CDialog::OnPaint();
  86. }
  87. }
  88. // The system calls this to obtain the cursor to display while the user drags
  89. // the minimized window.
  90. HCURSOR CCopyLockedDlg::OnQueryDragIcon()
  91. {
  92. return (HCURSOR) m_hIcon;
  93. }
  94. LPCTSTR _filenames[] = {
  95. "Msvcrtd.dll",
  96. "Mfc42d.dll",
  97. "Msvcp50.dll",
  98. "Msvcp50d.dll",
  99. "Msvcp60.dll",
  100. "Msvcp60d.dll",
  101. "Msvcrt.dll",
  102. "Mfc42.dll" };
  103. void
  104. CCopyLockedDlg::OnOK()
  105. {
  106. // TODO: Add extra validation here
  107. CWaitCursor wait_cursor;
  108. TCHAR temp_path[MAX_PATH];
  109. ::GetTempPath (sizeof (temp_path), temp_path);
  110. for (int index = 0; index < sizeof (_filenames)/sizeof (LPCTSTR); index ++) {
  111. HRSRC hresource = ::FindResource (::AfxGetInstanceHandle (), _filenames[index], "FILE");
  112. HGLOBAL hglobal = ::LoadResource (::AfxGetInstanceHandle (), hresource);
  113. LPVOID pbuffer = ::LockResource (hglobal);
  114. if(pbuffer != NULL) {
  115. CString full_path = CString (temp_path);
  116. if (temp_path[::lstrlen (temp_path)-1] != '\\') {
  117. full_path += "\\";
  118. }
  119. full_path += CString (_filenames[index]);
  120. HANDLE hfile = ::CreateFile (full_path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
  121. if (hfile != INVALID_HANDLE_VALUE) {
  122. DWORD dwbyteswritten = 0L;
  123. DWORD dwsizeofres = ::SizeofResource (::AfxGetInstanceHandle (), hresource);
  124. ::WriteFile (hfile, pbuffer, dwsizeofres, &dwbyteswritten, NULL);
  125. ::CloseHandle (hfile);
  126. if (dwbyteswritten == dwsizeofres) {
  127. TCHAR system_path[MAX_PATH];
  128. ::GetSystemDirectory (system_path, sizeof (system_path));
  129. CString new_path = CString (system_path);
  130. if (new_path[::lstrlen (new_path)-1] != '\\') {
  131. new_path += "\\";
  132. }
  133. new_path += CString (_filenames[index]);
  134. ::MoveFileEx (full_path, new_path, MOVEFILE_DELAY_UNTIL_REBOOT | MOVEFILE_REPLACE_EXISTING);
  135. ::MoveFileEx (full_path, NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
  136. }
  137. }
  138. }
  139. }
  140. ::MessageBox (m_hWnd, "In order to complete the install, you need to reboot your machine.", "Reboot", MB_OK | MB_ICONEXCLAMATION);
  141. //::ExitWindowsEx (EWX_REBOOT, 0);
  142. CDialog::OnOK();
  143. return ;
  144. }