diff --git a/components/openmw-mp/Log.cpp b/components/openmw-mp/Log.cpp index 4a22355cb..624080c25 100644 --- a/components/openmw-mp/Log.cpp +++ b/components/openmw-mp/Log.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include "Log.hpp" using namespace std; @@ -104,3 +105,21 @@ void Log::print(int level, bool hasPrefix, const char *file, int line, const cha va_end(args); cout << buf.data() << flush; } + +string Log::copyOldLog(boost::filesystem::path path, string name, string extension) +{ + namespace fs = boost::filesystem; + fs::directory_iterator end_iter; + + std::string fullname = name + "." + extension; + + if (fs::exists(path / fullname)) + { + std::string newname; + for (int i = 1; fs::exists(path / (newname = name + boost::lexical_cast(i++) + "." + extension));); + + fs::rename(path / fullname, path / newname); + return newname; + } + return fullname; +} \ No newline at end of file diff --git a/components/openmw-mp/Log.hpp b/components/openmw-mp/Log.hpp index ae32ca40c..bd9bed0d7 100644 --- a/components/openmw-mp/Log.hpp +++ b/components/openmw-mp/Log.hpp @@ -5,6 +5,8 @@ #ifndef OPENMW_LOG_HPP #define OPENMW_LOG_HPP +#include + #ifdef __GNUC__ #pragma GCC system_header #endif @@ -44,6 +46,8 @@ public: static const Log &Get(); static void SetLevel(int level); void print(int level, bool hasPrefix, const char *file, int line, const char *message, ...) const; + + static std::string copyOldLog(boost::filesystem::path path, std::string name, std::string extension); private: Log(int logLevel); /// Not implemented