diff --git a/server/TracyStorage.cpp b/server/TracyStorage.cpp index 41a0d3d1..082ab570 100644 --- a/server/TracyStorage.cpp +++ b/server/TracyStorage.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -109,4 +110,32 @@ const char* GetSavePath( const char* file ) return buf; } +const char* GetSavePath( const char* program, uint64_t time, const char* file, bool create ) +{ + enum { Pool = 8 }; + enum { MaxPath = 512 }; + static char bufpool[Pool][MaxPath]; + static int bufsel = 0; + char* buf = bufpool[bufsel]; + bufsel = ( bufsel + 1 ) % Pool; + + size_t sz; + GetConfigDirectory( buf, sz ); + + // 604800 = 7 days + sz += sprintf( buf+sz, "/tracy/user/%c/%s/%" PRIu64 "/%" PRIu64 "/", program[0], program, uint64_t( time / 604800 ), time ); + + if( create ) + { + auto status = CreateDirStruct( buf ); + assert( status ); + } + + const auto fsz = strlen( file ); + assert( sz + fsz < MaxPath ); + memcpy( buf+sz, file, fsz+1 ); + + return buf; +} + } diff --git a/server/TracyStorage.hpp b/server/TracyStorage.hpp index aa70eb9c..8eac7b69 100644 --- a/server/TracyStorage.hpp +++ b/server/TracyStorage.hpp @@ -1,10 +1,13 @@ #ifndef __TRACYSTORAGE_HPP__ #define __TRACYSTORAGE_HPP__ +#include + namespace tracy { const char* GetSavePath( const char* file ); +const char* GetSavePath( const char* program, uint64_t time, const char* file, bool create ); }