@@ -726,10 +726,40 @@ void RecorderClass::stopRecording() {
726726 if (m_file != NULL ) {
727727 m_file->close ();
728728 m_file = NULL ;
729+
730+ if (TheGlobalData->m_archiveReplays )
731+ archiveReplay (m_fileName);
729732 }
730733 m_fileName.clear ();
731734}
732735
736+ /* *
737+ * Copy the replay file to the archive directory and rename it using the current timestamp.
738+ */
739+ void RecorderClass::archiveReplay (AsciiString fileName)
740+ {
741+ SYSTEMTIME st;
742+ GetLocalTime (&st);
743+
744+ AsciiString archiveFileName;
745+ // Use a standard YYYYMMDD_HHMMSS format for simplicity and to avoid conflicts.
746+ archiveFileName.format (" %04d%02d%02d_%02d%02d%02d" , st.wYear , st.wMonth , st.wDay , st.wHour , st.wMinute , st.wSecond );
747+
748+ AsciiString sourcePath = getReplayDir ();
749+ sourcePath.concat (fileName);
750+
751+ if (!sourcePath.endsWith (getReplayExtention ()))
752+ sourcePath.concat (getReplayExtention ());
753+
754+ AsciiString destPath = getReplayArchiveDir ();
755+ destPath.concat (archiveFileName);
756+ destPath.concat (getReplayExtention ());
757+
758+ TheFileSystem->createDirectory (getReplayArchiveDir ().str ());
759+ if (!CopyFile (sourcePath.str (), destPath.str (), FALSE ))
760+ DEBUG_LOG ((" RecorderClass::archiveReplay: Failed to copy %s to %s" , sourcePath.str (), destPath.str ()));
761+ }
762+
733763/* *
734764 * Write this game message to the record file. This also writes the game message's execution frame.
735765 */
@@ -1602,6 +1632,18 @@ AsciiString RecorderClass::getReplayDir()
16021632 return tmp;
16031633}
16041634
1635+ /* *
1636+ * returns the directory that holds the archived replay files.
1637+ */
1638+ AsciiString RecorderClass::getReplayArchiveDir ()
1639+ {
1640+ const char * replayDir = " ArchivedReplays\\ " ;
1641+
1642+ AsciiString tmp = TheGlobalData->getPath_UserData ();
1643+ tmp.concat (replayDir);
1644+ return tmp;
1645+ }
1646+
16051647/* *
16061648 * returns the file extention for the replay files.
16071649 */
0 commit comments