Add cache dir support.

This commit is contained in:
Bartosz Taudul
2025-05-28 23:45:27 +02:00
parent 5f9491264b
commit f6f602da32
2 changed files with 63 additions and 0 deletions

View File

@@ -88,6 +88,40 @@ static void GetConfigDirectory( char* buf, size_t& sz )
#endif
}
static void GetCacheDirectory( char* buf, size_t& sz )
{
#ifdef _WIN32
auto path = getenv( "LOCALAPPDATA" );
sz = strlen( path );
memcpy( buf, path, sz );
for( size_t i=0; i<sz; i++ )
{
if( buf[i] == '\\' )
{
buf[i] = '/';
}
}
#else
auto path = getenv( "XDG_CACHE_HOME" );
if( path && *path )
{
sz = strlen( path );
memcpy( buf, path, sz );
}
else
{
path = getenv( "HOME" );
assert( path && *path );
sz = strlen( path );
memcpy( buf, path, sz );
memcpy( buf+sz, "/.cache", 7 );
sz += 7;
}
#endif
}
const char* GetSavePath( const char* file )
{
assert( file && *file );
@@ -208,4 +242,31 @@ const char* GetSavePath( const char* program, uint64_t time, const char* file, b
return buf;
}
const char* GetCachePath( const char* file )
{
assert( file && *file );
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;
GetCacheDirectory( buf, sz );
memcpy( buf+sz, "/tracy/", 8 );
sz += 7;
auto status = CreateDirStruct( buf );
assert( status );
const auto fsz = strlen( file );
assert( sz + fsz < MaxPath );
memcpy( buf+sz, file, fsz+1 );
return buf;
}
}

View File

@@ -9,6 +9,8 @@ namespace tracy
const char* GetSavePath( const char* file );
const char* GetSavePath( const char* program, uint64_t time, const char* file, bool create );
const char* GetCachePath( const char* file );
}
#endif