mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-10 10:41:50 +00:00
Add helper function for opening files.
This commit is contained in:
parent
2a0d6ce4ad
commit
38bfae13dd
@ -1,6 +1,5 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "TracyStorage.hpp"
|
#include "TracyStorage.hpp"
|
||||||
#include "TracyUserData.hpp"
|
#include "TracyUserData.hpp"
|
||||||
@ -18,10 +17,7 @@ UserData::UserData( const char* program, uint64_t time )
|
|||||||
: m_program( program )
|
: m_program( program )
|
||||||
, m_time( time )
|
, m_time( time )
|
||||||
{
|
{
|
||||||
const auto descpath = GetSavePath( m_program.c_str(), m_time, FileDescription, false );
|
FILE* f = OpenFile( FileDescription, false );
|
||||||
if( descpath )
|
|
||||||
{
|
|
||||||
FILE* f = fopen( descpath, "rb" );
|
|
||||||
if( f )
|
if( f )
|
||||||
{
|
{
|
||||||
fseek( f, 0, SEEK_END );
|
fseek( f, 0, SEEK_END );
|
||||||
@ -33,7 +29,6 @@ UserData::UserData( const char* program, uint64_t time )
|
|||||||
m_description.assign( buf.get(), buf.get() + sz );
|
m_description.assign( buf.get(), buf.get() + sz );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void UserData::Init( const char* program, uint64_t time )
|
void UserData::Init( const char* program, uint64_t time )
|
||||||
{
|
{
|
||||||
@ -49,10 +44,7 @@ bool UserData::SetDescription( const char* description )
|
|||||||
m_description = description;
|
m_description = description;
|
||||||
const auto sz = m_description.size();
|
const auto sz = m_description.size();
|
||||||
|
|
||||||
const auto path = GetSavePath( m_program.c_str(), m_time, FileDescription, true );
|
FILE* f = OpenFile( FileDescription, true );
|
||||||
if( !path ) return false;
|
|
||||||
|
|
||||||
FILE* f = fopen( path, "wb" );
|
|
||||||
if( !f ) return false;
|
if( !f ) return false;
|
||||||
|
|
||||||
fwrite( description, 1, sz, f );
|
fwrite( description, 1, sz, f );
|
||||||
@ -60,4 +52,12 @@ bool UserData::SetDescription( const char* description )
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FILE* UserData::OpenFile( const char* filename, bool write )
|
||||||
|
{
|
||||||
|
const auto path = GetSavePath( m_program.c_str(), m_time, filename, write );
|
||||||
|
if( !path ) return nullptr;
|
||||||
|
FILE* f = fopen( path, write ? "wb" : "rb" );
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define __TRACYUSERDATA_HPP__
|
#define __TRACYUSERDATA_HPP__
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace tracy
|
namespace tracy
|
||||||
@ -20,6 +21,8 @@ public:
|
|||||||
bool SetDescription( const char* description );
|
bool SetDescription( const char* description );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
FILE* OpenFile( const char* filename, bool write );
|
||||||
|
|
||||||
std::string m_program;
|
std::string m_program;
|
||||||
uint64_t m_time;
|
uint64_t m_time;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user