From 11cafbff1d47b6ff0717f909183fc7129c3b03b0 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 30 Oct 2022 00:36:07 +0200 Subject: [PATCH] Expose internal file selector failure state. --- server/TracyFileselector.cpp | 29 +++++++++++++++++++++++++++-- server/TracyFileselector.hpp | 6 +++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/server/TracyFileselector.cpp b/server/TracyFileselector.cpp index d4783568..be98f897 100644 --- a/server/TracyFileselector.cpp +++ b/server/TracyFileselector.cpp @@ -11,6 +11,8 @@ namespace tracy::Fileselector { +static bool s_hasFailed = false; + void Init() { #if !defined TRACY_NO_FILESELECTOR && !defined __EMSCRIPTEN__ @@ -25,6 +27,19 @@ void Shutdown() #endif } +bool HasFailed() +{ + if( s_hasFailed ) + { + s_hasFailed = false; + return true; + } + else + { + return false; + } +} + #ifdef __EMSCRIPTEN__ static std::function s_openFileCallback; @@ -35,7 +50,7 @@ extern "C" int nativeOpenFile() } #endif -bool OpenFile( const char* ext, const char* desc, std::function callback ) +static bool OpenFileImpl( const char* ext, const char* desc, std::function callback ) { #ifndef TRACY_NO_FILESELECTOR # ifdef __EMSCRIPTEN__ @@ -73,7 +88,7 @@ bool OpenFile( const char* ext, const char* desc, std::function callback ) +static bool SaveFileImpl( const char* ext, const char* desc, std::function callback ) { #if !defined TRACY_NO_FILESELECTOR && !defined __EMSCRIPTEN__ nfdu8filteritem_t filter = { desc, ext }; @@ -88,4 +103,14 @@ bool SaveFile( const char* ext, const char* desc, std::function callback ) +{ + if( !OpenFileImpl( ext, desc, callback ) ) s_hasFailed = true; +} + +void SaveFile( const char* ext, const char* desc, std::function callback ) +{ + if( !SaveFileImpl( ext, desc, callback ) ) s_hasFailed = true; +} + } diff --git a/server/TracyFileselector.hpp b/server/TracyFileselector.hpp index 5844aa1e..cd22d7a8 100644 --- a/server/TracyFileselector.hpp +++ b/server/TracyFileselector.hpp @@ -8,10 +8,10 @@ namespace tracy::Fileselector void Init(); void Shutdown(); +bool HasFailed(); -// Will return false if file selector cannot be presented to the user. -bool OpenFile( const char* ext, const char* desc, std::function callback ); -bool SaveFile( const char* ext, const char* desc, std::function callback ); +void OpenFile( const char* ext, const char* desc, std::function callback ); +void SaveFile( const char* ext, const char* desc, std::function callback ); }