diff --git a/src/fileio/fileio.cpp b/src/fileio/fileio.cpp index 69a2c149..7558cc5a 100644 --- a/src/fileio/fileio.cpp +++ b/src/fileio/fileio.cpp @@ -33,7 +33,7 @@ bool mac_is_intel(){ } return _mac_is_intel; } -fs::path progDir, tempDir, scenDir; +fs::path progDir, tempDir, scenDir, replayDir; // This is here to avoid unnecessarily duplicating it in platform-specific files. cursor_type Cursor::current = sword_curs; @@ -77,6 +77,10 @@ void init_directories(const char* exec_path) { #endif scenDir = tempDir/"Scenarios"; fs::create_directories(scenDir); + + replayDir = tempDir/"Replays"; + fs::create_directories(replayDir); + add_resmgr_paths(tempDir/"data"); tempDir /= "Temporary Files"; @@ -100,6 +104,7 @@ void init_directories(const char* exec_path) { std::cout << "Program directory: " << progDir << std::endl; std::cout << "Scenario directory: " << scenDir << std::endl; std::cout << "Temporary directory: " << tempDir << std::endl; + std::cout << "Replay directory: " << replayDir << std::endl; } #if !defined(_WIN32) && !defined(_WIN64) && !defined(__APPLE__) diff --git a/src/tools/replay.cpp b/src/tools/replay.cpp index d912ed79..28508fa2 100644 --- a/src/tools/replay.cpp +++ b/src/tools/replay.cpp @@ -40,12 +40,12 @@ const std::string replay_error = "Replay system internal error! "; using namespace ticpp; Document log_document; -std::string log_file; +fs::path log_file; Element* next_action; boost::optional replay_fps_limit; static void save_log() { - if(!log_file.empty()) log_document.SaveFile(log_file); + if(!log_file.empty()) log_document.SaveFile(log_file.string()); } void start_log_file(std::string file) { @@ -54,6 +54,8 @@ void start_log_file(std::string file) { save_log(); } +extern fs::path replayDir; + bool init_action_log(std::string command, std::string file) { if(command == "record-unique") { // If a filename is given, use it as a base, but insert a timestamp for uniqueness. @@ -73,6 +75,9 @@ bool init_action_log(std::string command, std::string file) { } if(command == "record") { log_file = file; + if(!log_file.empty() && log_file == log_file.filename()){ + log_file = replayDir / log_file; + } try { Element root_element("actions"); #ifndef MSBUILD_GITREV @@ -86,7 +91,7 @@ bool init_action_log(std::string command, std::string file) { if(log_file.empty()){ std::cout << "Recording this session in memory." << std::endl; }else{ - start_log_file(log_file); + start_log_file(log_file.string()); } } catch(...) { std::cout << "Failed to write to file " << log_file << std::endl; @@ -95,7 +100,11 @@ bool init_action_log(std::string command, std::string file) { } else if (command == "replay") { try { - log_document.LoadFile(file); + fs::path file_path = file; + if(file_path == file_path.filename() && !fs::exists(file_path)){ + file_path = replayDir / file_path; + } + log_document.LoadFile(file_path.string()); Element* root = log_document.FirstChildElement(); next_action = root->FirstChildElement();