#include "filesystem.h" #include #include #include #include #include #include #include #include #include #include // ===================================================================================================================== // time for waiting between file stats static const std::chrono::milliseconds sk_waitTime = std::chrono::milliseconds(100); // Check if a file exists bool FileExists( const std::string& name ) { struct stat buffer; return (stat (name.c_str(), &buffer) == 0); } // Wait for a file to exist void WaitForFile( const std::string& name, const std::chrono::milliseconds& time ) { while( !FileExists(name) ) std::this_thread::sleep_for(time); } bool OutputGameStateFile(CTTRTSGame &game) { char turnFileName[128]; snprintf(turnFileName,128,"%s%s/Turn_%i.txt", getGamesDir().c_str(),game.GetName().c_str(),game.GetTurn()); std::ofstream turnFile(turnFileName, std::ios_base::trunc); // truncate to overwrite if a file exists if ( turnFile.bad() ) { return false; } // Output the turn description std::string turnDescriptor = GetStringFromGame(game); turnFile<(file)),std::istreambuf_iterator()); if( gameDescriptor.size() == 0 ) { std::cerr<<"Error: failed to read in any information from "<(turnFile)), std::istreambuf_iterator()); return orders; } int CreateAndCleanGameDir(const std::string& gameName) { std::string gameDir = getGamesDir()+gameName; struct stat info; int ret = stat( gameDir.c_str(), &info ); if( ret == 0 && info.st_mode & S_IFDIR ) { std::cout<< gameDir << " game directory already exists"<>input; if( !input.size() || std::tolower(input[0]) != 'y' ) { std::cerr<<"Aborting..."<