From a852cf390a4164f050b18b0a6deae1f76b260bb0 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Wed, 20 Apr 2022 18:24:00 +0200 Subject: [PATCH] Adapt code to new NFD. --- profiler/build/win32/Tracy.vcxproj | 3 --- profiler/build/win32/Tracy.vcxproj.filters | 21 ++++++--------------- profiler/src/main.cpp | 15 +++++++++++++-- server/TracySourceView.cpp | 6 ++++-- server/TracyView.cpp | 14 ++++++++++---- 5 files changed, 33 insertions(+), 26 deletions(-) diff --git a/profiler/build/win32/Tracy.vcxproj b/profiler/build/win32/Tracy.vcxproj index 8215cc7a..ceeaee4d 100644 --- a/profiler/build/win32/Tracy.vcxproj +++ b/profiler/build/win32/Tracy.vcxproj @@ -114,7 +114,6 @@ - @@ -196,9 +195,7 @@ - - diff --git a/profiler/build/win32/Tracy.vcxproj.filters b/profiler/build/win32/Tracy.vcxproj.filters index 32f70fdd..ffae1985 100644 --- a/profiler/build/win32/Tracy.vcxproj.filters +++ b/profiler/build/win32/Tracy.vcxproj.filters @@ -60,12 +60,6 @@ server - - nfd - - - nfd - server @@ -246,6 +240,9 @@ server + + nfd + @@ -281,15 +278,6 @@ server - - nfd - - - nfd - - - nfd - server @@ -584,6 +572,9 @@ zstd\compress + + nfd + diff --git a/profiler/src/main.cpp b/profiler/src/main.cpp index bd4e4943..00823917 100644 --- a/profiler/src/main.cpp +++ b/profiler/src/main.cpp @@ -393,6 +393,10 @@ int main( int argc, char** argv ) view = std::make_unique( RunOnMainThread, connectTo, port, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative, SetupScaleCallback ); } +#ifndef TRACY_NO_FILESELECTOR + NFD_Init(); +#endif + glfwShowWindow( window ); // Main loop @@ -450,6 +454,11 @@ int main( int argc, char** argv ) ImGui::DestroyContext(); glfwDestroyWindow(window); + +#ifndef TRACY_NO_FILESELECTOR + NFD_Quit(); +#endif + glfwTerminate(); { @@ -773,8 +782,9 @@ static void DrawContents() #ifndef TRACY_NO_FILESELECTOR if( ImGui::Button( ICON_FA_FOLDER_OPEN " Open saved trace" ) && !loadThread.joinable() ) { - nfdchar_t* fn; - auto res = NFD_OpenDialog( "tracy", nullptr, &fn, GetMainWindowNative() ); + nfdu8filteritem_t filter = { "Tracy Profiler trace file", "tracy" }; + nfdu8char_t* fn; + auto res = NFD_OpenDialogU8( &fn, &filter, 1, nullptr ); if( res == NFD_OKAY ) { try @@ -808,6 +818,7 @@ static void DrawContents() { badVer.state = tracy::BadVersionState::ReadError; } + NFD_FreePathU8( fn ); } } diff --git a/server/TracySourceView.cpp b/server/TracySourceView.cpp index 72caccd6..483979d2 100644 --- a/server/TracySourceView.cpp +++ b/server/TracySourceView.cpp @@ -5062,8 +5062,9 @@ void SourceView::Save( const Worker& worker, size_t start, size_t stop ) assert( start < m_asm.size() ); assert( start < stop ); - nfdchar_t* fn; - auto res = NFD_SaveDialog( "asm", nullptr, &fn, m_gwcb ? m_gwcb() : nullptr ); + nfdu8filteritem_t filter = { "Assembly file", "asm" }; + nfdu8char_t* fn; + auto res = NFD_SaveDialogU8( &fn, &filter, 1, nullptr, nullptr ); if( res == NFD_OKAY ) { FILE* f = nullptr; @@ -5137,6 +5138,7 @@ void SourceView::Save( const Worker& worker, size_t start, size_t stop ) } fclose( f ); } + NFD_FreePathU8( fn ); } } #endif diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 11dfb22e..dc8befd1 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -1617,8 +1617,9 @@ bool View::DrawConnection() if( ImGui::Button( ICON_FA_SAVE " Save trace" ) && m_saveThreadState.load( std::memory_order_relaxed ) == SaveThreadState::Inert ) { #ifndef TRACY_NO_FILESELECTOR - nfdchar_t* fn; - auto res = NFD_SaveDialog( "tracy", nullptr, &fn, m_gwcb ? m_gwcb() : nullptr ); + nfdu8filteritem_t filter = { "Tracy Profiler trace file", "tracy" }; + nfdu8char_t* fn; + auto res = NFD_SaveDialogU8( &fn, &filter, 1, nullptr, nullptr ); if( res == NFD_OKAY ) #else const char* fn = "trace.tracy"; @@ -1635,6 +1636,9 @@ bool View::DrawConnection() { m_filenameStaging = fn; } +#ifndef TRACY_NO_FILESELECTOR + NFD_FreePathU8( fn ); +#endif } } @@ -11781,8 +11785,9 @@ void View::DrawCompare() ImGui::TextWrapped( "Please load a second trace to compare results." ); if( ImGui::Button( ICON_FA_FOLDER_OPEN " Open second trace" ) && !m_compare.loadThread.joinable() ) { - nfdchar_t* fn; - auto res = NFD_OpenDialog( "tracy", nullptr, &fn, m_gwcb ? m_gwcb() : nullptr ); + nfdu8filteritem_t filter = { "Tracy Profiler trace file", "tracy" }; + nfdu8char_t* fn; + auto res = NFD_OpenDialogU8( &fn, &filter, 1, nullptr ); if( res == NFD_OKAY ) { try @@ -11813,6 +11818,7 @@ void View::DrawCompare() m_compare.badVer.state = BadVersionState::ReadError; } } + NFD_FreePathU8( fn ); } tracy::BadVersion( m_compare.badVer, m_bigFont ); ImGui::End();