Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TracyUserData.cpp « server - github.com/wolfpld/tracy.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ae187c050c6e5c90da870c94f11800484de1ab68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <assert.h>
#include <memory>
#include <stdio.h>

#include "TracyStorage.hpp"
#include "TracyUserData.hpp"

namespace tracy
{

constexpr auto FileDescription = "description";

UserData::UserData()
{
}

UserData::UserData( const char* program, uint64_t time )
    : m_program( program )
    , m_time( time )
{
    const auto descpath = GetSavePath( m_program.c_str(), m_time, FileDescription, false );
    if( descpath )
    {
        FILE* f = fopen( descpath, "rb" );
        if( f )
        {
            fseek( f, 0, SEEK_END );
            const auto sz = ftell( f );
            fseek( f, 0, SEEK_SET );
            auto buf = std::make_unique<char[]>( sz );
            fread( buf.get(), 1, sz, f );
            fclose( f );
            m_description.assign( buf.get(), buf.get() + sz );
        }
    }
}

void UserData::Init( const char* program, uint64_t time )
{
    assert( !Valid() );
    m_program = program;
    m_time = time;
}

bool UserData::SetDescription( const char* description )
{
    assert( Valid() );

    m_description = description;
    const auto sz = m_description.size();

    const auto path = GetSavePath( m_program.c_str(), m_time, FileDescription, true );
    if( !path ) return false;

    FILE* f = fopen( path, "wb" );
    if( !f ) return false;

    fwrite( description, 1, sz, f );
    fclose( f );
    return true;
}

}