tracy/server/TracyFileselector.cpp
2022-10-05 22:50:17 +02:00

55 lines
964 B
C++

#include "TracyFileselector.hpp"
#ifndef TRACY_NO_FILESELECTOR
# include "../nfd/nfd.h"
#endif
namespace tracy::Fileselector
{
void Init()
{
#ifndef TRACY_NO_FILESELECTOR
NFD_Init();
#endif
}
void Shutdown()
{
#ifndef TRACY_NO_FILESELECTOR
NFD_Quit();
#endif
}
std::string OpenFile( const char* ext, const char* desc )
{
std::string ret;
#ifndef TRACY_NO_FILESELECTOR
nfdu8filteritem_t filter = { desc, ext };
nfdu8char_t* fn;
if( NFD_OpenDialogU8( &fn, &filter, 1, nullptr ) == NFD_OKAY )
{
ret.assign( fn );
NFD_FreePathU8( fn );
}
#endif
return ret;
}
std::string SaveFile( const char* ext, const char* desc )
{
std::string ret;
#ifndef TRACY_NO_FILESELECTOR
nfdu8filteritem_t filter = { desc, ext };
nfdu8char_t* fn;
if( NFD_SaveDialogU8( &fn, &filter, 1, nullptr, nullptr ) == NFD_OKAY )
{
ret.assign( fn );
NFD_FreePathU8( fn );
}
#endif
return ret;
}
}