ReplayMenu.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: ReplayMenu.cpp /////////////////////////////////////////////////////////////////////
  24. // Author: Chris The masta Huybregts, December 2001
  25. // Description: Replay Menus
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #include "Lib/BaseType.h"
  30. #include "Common/FileSystem.h"
  31. #include "Common/GameEngine.h"
  32. #include "Common/GameState.h"
  33. #include "Common/Recorder.h"
  34. #include "Common/Version.h"
  35. #include "GameClient/WindowLayout.h"
  36. #include "GameClient/Gadget.h"
  37. #include "GameClient/GadgetListbox.h"
  38. #include "GameClient/Shell.h"
  39. #include "GameClient/KeyDefs.h"
  40. #include "GameClient/GameWindowManager.h"
  41. #include "GameClient/MessageBox.h"
  42. #include "GameClient/MapUtil.h"
  43. #include "GameClient/GameText.h"
  44. #include "GameClient/GameWindowTransitions.h"
  45. #ifdef _INTERNAL
  46. // for occasional debugging...
  47. //#pragma optimize("", off)
  48. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  49. #endif
  50. // window ids -------------------------------------------------------------------------------------
  51. static NameKeyType parentReplayMenuID = NAMEKEY_INVALID;
  52. static NameKeyType buttonLoadID = NAMEKEY_INVALID;
  53. static NameKeyType buttonBackID = NAMEKEY_INVALID;
  54. static NameKeyType listboxReplayFilesID = NAMEKEY_INVALID;
  55. static NameKeyType buttonDeleteID = NAMEKEY_INVALID;
  56. static NameKeyType buttonCopyID = NAMEKEY_INVALID;
  57. static Bool isShuttingDown = false;
  58. // window pointers --------------------------------------------------------------------------------
  59. static GameWindow *parentReplayMenu = NULL;
  60. static GameWindow *buttonLoad = NULL;
  61. static GameWindow *buttonBack = NULL;
  62. static GameWindow *listboxReplayFiles = NULL;
  63. static GameWindow *buttonDelete = NULL;
  64. static GameWindow *buttonCopy = NULL;
  65. static Int initialGadgetDelay = 2;
  66. static Bool justEntered = FALSE;
  67. #if defined _DEBUG || defined _INTERNAL
  68. static GameWindow *buttonAnalyzeReplay = NULL;
  69. #endif
  70. void deleteReplay( void );
  71. void copyReplay( void );
  72. static Bool callCopy = FALSE;
  73. static Bool callDelete = FALSE;
  74. void deleteReplayFlag( void ) { callDelete = TRUE;}
  75. void copyReplayFlag( void ) { callCopy = TRUE;}
  76. UnicodeString GetReplayFilenameFromListbox(GameWindow *listbox, Int index)
  77. {
  78. UnicodeString fname = GadgetListBoxGetText(listbox, index);
  79. if (fname == TheGameText->fetch("GUI:LastReplay"))
  80. {
  81. fname.translate(TheRecorder->getLastReplayFileName());
  82. }
  83. UnicodeString ext;
  84. ext.translate(TheRecorder->getReplayExtention());
  85. fname.concat(ext);
  86. return fname;
  87. }
  88. //-------------------------------------------------------------------------------------------------
  89. /** Populate the listbox with the names of the available replay files */
  90. //-------------------------------------------------------------------------------------------------
  91. void PopulateReplayFileListbox(GameWindow *listbox)
  92. {
  93. if (!TheMapCache)
  94. return;
  95. GadgetListBoxReset(listbox);
  96. enum {
  97. COLOR_SP = 0,
  98. COLOR_SP_CRC_MISMATCH,
  99. COLOR_MP,
  100. COLOR_MP_CRC_MISMATCH,
  101. COLOR_MAX
  102. };
  103. Color colors[COLOR_MAX] = {
  104. GameMakeColor( 255, 255, 255, 255 ),
  105. GameMakeColor( 128, 128, 128, 255 ),
  106. GameMakeColor( 255, 255, 255, 255 ),
  107. GameMakeColor( 128, 128, 128, 255 )
  108. };
  109. AsciiString asciistr;
  110. AsciiString asciisearch;
  111. asciisearch = "*";
  112. asciisearch.concat(TheRecorder->getReplayExtention());
  113. FilenameList replayFilenames;
  114. FilenameListIter it;
  115. TheFileSystem->getFileListInDirectory(TheRecorder->getReplayDir(), asciisearch, replayFilenames, TRUE);
  116. TheMapCache->updateCache();
  117. for (it = replayFilenames.begin(); it != replayFilenames.end(); ++it)
  118. {
  119. // just want the filename
  120. asciistr.set((*it).reverseFind('\\') + 1);
  121. // lets get some info about the replay
  122. RecorderClass::ReplayHeader header;
  123. header.forPlayback = FALSE;
  124. header.filename = asciistr;
  125. Bool success = TheRecorder && TheMapCache && TheRecorder->readReplayHeader( header );
  126. if (success)
  127. {
  128. ReplayGameInfo info;
  129. if (ParseAsciiStringToGameInfo( &info, header.gameOptions ))
  130. {
  131. // columns are: name, date, version, map, extra
  132. // name
  133. header.replayName.translate(asciistr);
  134. for (Int tmp=0; tmp < TheRecorder->getReplayExtention().getLength(); ++tmp)
  135. header.replayName.removeLastChar();
  136. UnicodeString replayNameToShow = header.replayName;
  137. AsciiString lastReplayFName = TheRecorder->getLastReplayFileName();
  138. lastReplayFName.concat(TheRecorder->getReplayExtention());
  139. if (lastReplayFName.compareNoCase(asciistr) == 0)
  140. replayNameToShow = TheGameText->fetch("GUI:LastReplay");
  141. UnicodeString displayTimeBuffer = getUnicodeTimeBuffer(header.timeVal);
  142. //displayTimeBuffer.format( L"%ls", timeBuffer);
  143. // version (no-op)
  144. // map
  145. UnicodeString mapStr;
  146. const MapMetaData *md = TheMapCache->findMap(info.getMap());
  147. if (!md)
  148. {
  149. mapStr.translate(info.getMap());
  150. }
  151. else
  152. {
  153. mapStr = md->m_displayName;
  154. }
  155. // // extra
  156. // UnicodeString extraStr;
  157. // if (header.localPlayerIndex >= 0)
  158. // {
  159. // // MP game
  160. // time_t totalSeconds = header.endTime - header.startTime;
  161. // Int mins = totalSeconds/60;
  162. // Int secs = totalSeconds%60;
  163. // Real fps = header.frameDuration/totalSeconds;
  164. // extraStr.format(L"%d:%d (%g fps) %hs", mins, secs, fps, header.desyncGame?"OOS ":"");
  165. //
  166. // for (Int i=0; i<MAX_SLOTS; ++i)
  167. // {
  168. // const GameSlot *slot = info.getConstSlot(i);
  169. // if (slot && slot->isHuman())
  170. // {
  171. // if (i)
  172. // extraStr.concat(L", ");
  173. // if (header.playerDiscons[i])
  174. // extraStr.concat(L'*');
  175. // extraStr.concat(info.getConstSlot(i)->getName());
  176. // }
  177. // }
  178. // }
  179. // else
  180. // {
  181. // // solo game
  182. // time_t totalSeconds = header.endTime - header.startTime;
  183. // Int mins = totalSeconds/60;
  184. // Int secs = totalSeconds%60;
  185. // Real fps = header.frameDuration/totalSeconds;
  186. // extraStr.format(L"%d:%d (%g fps)", mins, secs, fps);
  187. // }
  188. // pick a color
  189. Color color;
  190. if (header.versionString == TheVersion->getUnicodeVersion() && header.versionNumber == TheVersion->getVersionNumber() &&
  191. header.exeCRC == TheGlobalData->m_exeCRC && header.iniCRC == TheGlobalData->m_iniCRC)
  192. {
  193. // good version
  194. if (header.localPlayerIndex >= 0)
  195. {
  196. // MP
  197. color = colors[COLOR_MP];
  198. }
  199. else
  200. {
  201. // SP
  202. color = colors[COLOR_SP];
  203. }
  204. }
  205. else
  206. {
  207. // bad version
  208. if (header.localPlayerIndex >= 0)
  209. {
  210. // MP
  211. color = colors[COLOR_MP_CRC_MISMATCH];
  212. }
  213. else
  214. {
  215. // SP
  216. color = colors[COLOR_SP_CRC_MISMATCH];
  217. }
  218. }
  219. Int insertionIndex = GadgetListBoxAddEntryText(listbox, replayNameToShow, color, -1, 0);
  220. GadgetListBoxAddEntryText(listbox, displayTimeBuffer, color, insertionIndex, 1);
  221. GadgetListBoxAddEntryText(listbox, header.versionString, color, insertionIndex, 2);
  222. GadgetListBoxAddEntryText(listbox, mapStr, color, insertionIndex, 3);
  223. //GadgetListBoxAddEntryText(listbox, extraStr, color, insertionIndex, 4);
  224. }
  225. }
  226. }
  227. GadgetListBoxSetSelected(listbox, 0);
  228. }
  229. //-------------------------------------------------------------------------------------------------
  230. /** Initialize the single player menu */
  231. //-------------------------------------------------------------------------------------------------
  232. void ReplayMenuInit( WindowLayout *layout, void *userData )
  233. {
  234. TheShell->showShellMap(TRUE);
  235. // get ids for our children controls
  236. parentReplayMenuID = TheNameKeyGenerator->nameToKey( AsciiString("ReplayMenu.wnd:ParentReplayMenu") );
  237. buttonLoadID = TheNameKeyGenerator->nameToKey( AsciiString("ReplayMenu.wnd:ButtonLoadReplay") );
  238. buttonBackID = TheNameKeyGenerator->nameToKey( AsciiString("ReplayMenu.wnd:ButtonBack") );
  239. listboxReplayFilesID = TheNameKeyGenerator->nameToKey( AsciiString("ReplayMenu.wnd:ListboxReplayFiles") );
  240. buttonDeleteID = TheNameKeyGenerator->nameToKey( AsciiString("ReplayMenu.wnd:ButtonDeleteReplay") );
  241. buttonCopyID = TheNameKeyGenerator->nameToKey( AsciiString("ReplayMenu.wnd:ButtonCopyReplay") );
  242. parentReplayMenu = TheWindowManager->winGetWindowFromId( NULL, parentReplayMenuID );
  243. buttonLoad = TheWindowManager->winGetWindowFromId( parentReplayMenu, buttonLoadID );
  244. buttonBack = TheWindowManager->winGetWindowFromId( parentReplayMenu, buttonBackID );
  245. listboxReplayFiles = TheWindowManager->winGetWindowFromId( parentReplayMenu, listboxReplayFilesID );
  246. buttonDelete = TheWindowManager->winGetWindowFromId( parentReplayMenu, buttonDeleteID );
  247. buttonCopy = TheWindowManager->winGetWindowFromId( parentReplayMenu, buttonCopyID );
  248. //Load the listbox shiznit
  249. GadgetListBoxReset(listboxReplayFiles);
  250. PopulateReplayFileListbox(listboxReplayFiles);
  251. #if defined _DEBUG || defined _INTERNAL
  252. WinInstanceData instData;
  253. instData.init();
  254. BitSet( instData.m_style, GWS_PUSH_BUTTON | GWS_MOUSE_TRACK );
  255. instData.m_textLabelString = "Debug: Analyze Replay";
  256. instData.setTooltipText(UnicodeString(L"Only Used in Debug and Internal!"));
  257. buttonAnalyzeReplay = TheWindowManager->gogoGadgetPushButton( parentReplayMenu,
  258. WIN_STATUS_ENABLED | WIN_STATUS_IMAGE,
  259. 4, 4,
  260. 180, 26,
  261. &instData, NULL, TRUE );
  262. #endif
  263. // show menu
  264. layout->hide( FALSE );
  265. // set keyboard focus to main parent
  266. TheWindowManager->winSetFocus( parentReplayMenu );
  267. justEntered = TRUE;
  268. initialGadgetDelay = 2;
  269. GameWindow *win = TheWindowManager->winGetWindowFromId(NULL, TheNameKeyGenerator->nameToKey("ReplayMenu.wnd:GadgetParent"));
  270. if(win)
  271. win->winHide(TRUE);
  272. isShuttingDown = FALSE;
  273. } // end ReplayMenuInit
  274. //-------------------------------------------------------------------------------------------------
  275. /** single player menu shutdown method */
  276. //-------------------------------------------------------------------------------------------------
  277. void ReplayMenuShutdown( WindowLayout *layout, void *userData )
  278. {
  279. Bool popImmediate = *(Bool *)userData;
  280. if( popImmediate )
  281. {
  282. layout->hide( TRUE );
  283. TheShell->shutdownComplete( layout );
  284. return;
  285. } //end if
  286. // our shutdown is complete
  287. TheTransitionHandler->reverse("ReplayMenuFade");
  288. isShuttingDown = TRUE;
  289. } // end ReplayMenuShutdown
  290. //-------------------------------------------------------------------------------------------------
  291. /** single player menu update method */
  292. //-------------------------------------------------------------------------------------------------
  293. void ReplayMenuUpdate( WindowLayout *layout, void *userData )
  294. {
  295. if(justEntered)
  296. {
  297. if(initialGadgetDelay == 1)
  298. {
  299. TheTransitionHandler->remove("MainMenuDefaultMenuLogoFade");
  300. TheTransitionHandler->setGroup("ReplayMenuFade");
  301. initialGadgetDelay = 2;
  302. justEntered = FALSE;
  303. }
  304. else
  305. initialGadgetDelay--;
  306. }
  307. if(callCopy)
  308. copyReplay();
  309. if(callDelete)
  310. deleteReplay();
  311. // We'll only be successful if we've requested to
  312. if(isShuttingDown && TheShell->isAnimFinished()&& TheTransitionHandler->isFinished())
  313. TheShell->shutdownComplete( layout );
  314. } // end ReplayMenuUpdate
  315. //-------------------------------------------------------------------------------------------------
  316. /** Replay menu input callback */
  317. //-------------------------------------------------------------------------------------------------
  318. WindowMsgHandledType ReplayMenuInput( GameWindow *window, UnsignedInt msg,
  319. WindowMsgData mData1, WindowMsgData mData2 )
  320. {
  321. switch( msg )
  322. {
  323. // --------------------------------------------------------------------------------------------
  324. case GWM_CHAR:
  325. {
  326. UnsignedByte key = mData1;
  327. UnsignedByte state = mData2;
  328. switch( key )
  329. {
  330. // ----------------------------------------------------------------------------------------
  331. case KEY_ESC:
  332. {
  333. //
  334. // send a simulated selected event to the parent window of the
  335. // back/exit button
  336. //
  337. if( BitTest( state, KEY_STATE_UP ) )
  338. {
  339. TheWindowManager->winSendSystemMsg( window, GBM_SELECTED,
  340. (WindowMsgData)buttonBack, buttonBackID );
  341. } // end if
  342. // don't let key fall through anywhere else
  343. return MSG_HANDLED;
  344. } // end escape
  345. } // end switch( key )
  346. } // end char
  347. } // end switch( msg )
  348. return MSG_IGNORED;
  349. } // end ReplayMenuInput
  350. void reallyLoadReplay(void)
  351. {
  352. UnicodeString filename;
  353. Int selected;
  354. GadgetListBoxGetSelected( listboxReplayFiles, &selected );
  355. if(selected < 0)
  356. {
  357. MessageBoxOk(TheGameText->fetch("GUI:NoFileSelected"),TheGameText->fetch("GUI:PleaseSelectAFile"), NULL);
  358. return;
  359. }
  360. filename = GetReplayFilenameFromListbox(listboxReplayFiles, selected);
  361. AsciiString asciiFilename;
  362. asciiFilename.translate(filename);
  363. TheRecorder->playbackFile(asciiFilename);
  364. if(parentReplayMenu != NULL)
  365. {
  366. parentReplayMenu->winHide(TRUE);
  367. }
  368. }
  369. //-------------------------------------------------------------------------------------------------
  370. /** single player menu window system callback */
  371. //-------------------------------------------------------------------------------------------------
  372. WindowMsgHandledType ReplayMenuSystem( GameWindow *window, UnsignedInt msg,
  373. WindowMsgData mData1, WindowMsgData mData2 )
  374. {
  375. switch( msg )
  376. {
  377. // --------------------------------------------------------------------------------------------
  378. case GWM_CREATE:
  379. {
  380. break;
  381. } // end create
  382. //---------------------------------------------------------------------------------------------
  383. case GWM_DESTROY:
  384. {
  385. break;
  386. } // end case
  387. // --------------------------------------------------------------------------------------------
  388. case GWM_INPUT_FOCUS:
  389. {
  390. // if we're givin the opportunity to take the keyboard focus we must say we want it
  391. if( mData1 == TRUE )
  392. *(Bool *)mData2 = TRUE;
  393. return MSG_HANDLED;
  394. } // end input
  395. //---------------------------------------------------------------------------------------------
  396. case GLM_DOUBLE_CLICKED:
  397. {
  398. GameWindow *control = (GameWindow *)mData1;
  399. Int controlID = control->winGetWindowId();
  400. if( controlID == listboxReplayFilesID )
  401. {
  402. int rowSelected = mData2;
  403. if (rowSelected >= 0)
  404. {
  405. UnicodeString filename;
  406. filename = GetReplayFilenameFromListbox(listboxReplayFiles, rowSelected);
  407. AsciiString asciiFilename;
  408. asciiFilename.translate(filename);
  409. TheRecorder->playbackFile(asciiFilename);
  410. if(parentReplayMenu != NULL)
  411. {
  412. parentReplayMenu->winHide(TRUE);
  413. }
  414. }
  415. }
  416. break;
  417. }
  418. //---------------------------------------------------------------------------------------------
  419. case GBM_SELECTED:
  420. {
  421. UnicodeString filename;
  422. GameWindow *control = (GameWindow *)mData1;
  423. Int controlID = control->winGetWindowId();
  424. #if defined _DEBUG || defined _INTERNAL
  425. if( controlID == buttonAnalyzeReplay->winGetWindowId() )
  426. {
  427. if(listboxReplayFiles)
  428. {
  429. Int selected;
  430. GadgetListBoxGetSelected( listboxReplayFiles, &selected );
  431. if(selected < 0)
  432. {
  433. MessageBoxOk(UnicodeString(L"Blah Blah"),UnicodeString(L"Please select something munkee boy"), NULL);
  434. break;
  435. }
  436. filename = GetReplayFilenameFromListbox(listboxReplayFiles, selected);
  437. AsciiString asciiFilename;
  438. asciiFilename.translate(filename);
  439. if (TheRecorder->analyzeReplay(asciiFilename))
  440. {
  441. do
  442. {
  443. TheRecorder->update();
  444. } while (TheRecorder->isAnalysisInProgress());
  445. }
  446. }
  447. }
  448. else
  449. #endif
  450. if( controlID == buttonLoadID )
  451. {
  452. if(listboxReplayFiles)
  453. {
  454. Int selected;
  455. GadgetListBoxGetSelected( listboxReplayFiles, &selected );
  456. if(selected < 0)
  457. {
  458. MessageBoxOk(TheGameText->fetch("GUI:NoFileSelected"),TheGameText->fetch("GUI:PleaseSelectAFile"), NULL);
  459. break;
  460. }
  461. filename = GetReplayFilenameFromListbox(listboxReplayFiles, selected);
  462. AsciiString asciiFilename;
  463. asciiFilename.translate(filename);
  464. if(TheRecorder->testVersionPlayback(asciiFilename))
  465. {
  466. MessageBoxOkCancel(TheGameText->fetch("GUI:OlderReplayVersionTitle"), TheGameText->fetch("GUI:OlderReplayVersion"),reallyLoadReplay ,NULL);
  467. }
  468. else
  469. {
  470. TheRecorder->playbackFile(asciiFilename);
  471. if(parentReplayMenu != NULL)
  472. {
  473. parentReplayMenu->winHide(TRUE);
  474. }
  475. }
  476. }
  477. } // end else if
  478. else if( controlID == buttonBackID )
  479. {
  480. // thou art directed to return to thy known solar system immediately!
  481. TheShell->pop();
  482. } // end else if
  483. else if( controlID == buttonDeleteID )
  484. {
  485. Int selected;
  486. GadgetListBoxGetSelected( listboxReplayFiles, &selected );
  487. if(selected < 0)
  488. {
  489. MessageBoxOk(TheGameText->fetch("GUI:NoFileSelected"),TheGameText->fetch("GUI:PleaseSelectAFile"), NULL);
  490. break;
  491. }
  492. filename = GetReplayFilenameFromListbox(listboxReplayFiles, selected);
  493. MessageBoxYesNo(TheGameText->fetch("GUI:DeleteFile"), TheGameText->fetch("GUI:AreYouSureDelete"), deleteReplayFlag, NULL);
  494. }
  495. else if( controlID == buttonCopyID )
  496. {
  497. Int selected;
  498. GadgetListBoxGetSelected( listboxReplayFiles, &selected );
  499. if(selected < 0)
  500. {
  501. MessageBoxOk(TheGameText->fetch("GUI:NoFileSelected"),TheGameText->fetch("GUI:PleaseSelectAFile"), NULL);
  502. break;
  503. }
  504. filename = GetReplayFilenameFromListbox(listboxReplayFiles, selected);
  505. MessageBoxYesNo(TheGameText->fetch("GUI:CopyReplay"), TheGameText->fetch("GUI:AreYouSureCopy"), copyReplayFlag, NULL);
  506. }
  507. break;
  508. } // end selected
  509. default:
  510. return MSG_IGNORED;
  511. } // end switch
  512. return MSG_HANDLED;
  513. } // end ReplayMenuSystem
  514. void deleteReplay( void )
  515. {
  516. callDelete = FALSE;
  517. Int selected;
  518. GadgetListBoxGetSelected( listboxReplayFiles, &selected );
  519. if(selected < 0)
  520. {
  521. MessageBoxOk(TheGameText->fetch("GUI:NoFileSelected"),TheGameText->fetch("GUI:PleaseSelectAFile"), NULL);
  522. return;
  523. }
  524. AsciiString filename, translate;
  525. filename = TheRecorder->getReplayDir();
  526. translate.translate(GetReplayFilenameFromListbox(listboxReplayFiles, selected));
  527. filename.concat(translate);
  528. if(DeleteFile(filename.str()) == 0)
  529. {
  530. char buffer[1024];
  531. FormatMessage ( FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, buffer, sizeof(buffer), NULL);
  532. UnicodeString errorStr;
  533. translate.set(buffer);
  534. errorStr.translate(translate);
  535. MessageBoxOk(TheGameText->fetch("GUI:Error"),errorStr, NULL);
  536. }
  537. //Load the listbox shiznit
  538. GadgetListBoxReset(listboxReplayFiles);
  539. PopulateReplayFileListbox(listboxReplayFiles);
  540. }
  541. void copyReplay( void )
  542. {
  543. callCopy = FALSE;
  544. Int selected;
  545. GadgetListBoxGetSelected( listboxReplayFiles, &selected );
  546. if(selected < 0)
  547. {
  548. MessageBoxOk(TheGameText->fetch("GUI:NoFileSelected"),TheGameText->fetch("GUI:PleaseSelectAFile"), NULL);
  549. return;
  550. }
  551. AsciiString filename, translate;
  552. filename = TheRecorder->getReplayDir();
  553. translate.translate(GetReplayFilenameFromListbox(listboxReplayFiles, selected));
  554. filename.concat(translate);
  555. char path[1024];
  556. LPITEMIDLIST pidl;
  557. SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOPDIRECTORY, &pidl);
  558. SHGetPathFromIDList(pidl,path);
  559. AsciiString newFilename;
  560. newFilename.set(path);
  561. newFilename.concat("\\");
  562. newFilename.concat(translate);
  563. if(CopyFile(filename.str(),newFilename.str(), FALSE) == 0)
  564. {
  565. wchar_t buffer[1024];
  566. FormatMessageW( FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, buffer, sizeof(buffer), NULL);
  567. UnicodeString errorStr;
  568. errorStr.set(buffer);
  569. errorStr.trim();
  570. MessageBoxOk(TheGameText->fetch("GUI:Error"),errorStr, NULL);
  571. }
  572. }