From 3b6b67b7ee32f3c3024a47d4446b1efb6cfd5436 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 21 Apr 2018 15:00:54 +0200 Subject: [PATCH] Display a dialog when user tries to open invalid file. --- standalone/src/main.cpp | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/standalone/src/main.cpp b/standalone/src/main.cpp index 7d49993a..18c555a0 100644 --- a/standalone/src/main.cpp +++ b/standalone/src/main.cpp @@ -101,22 +101,36 @@ int main( int argc, char** argv ) auto res = NFD_OpenDialog( "tracy", nullptr, &fn ); if( res == NFD_OKAY ) { - auto f = std::unique_ptr( tracy::FileRead::Open( fn ) ); - if( f ) + try { - try + auto f = std::unique_ptr( tracy::FileRead::Open( fn ) ); + if( f ) { view = std::make_unique( *f ); } - catch( const tracy::UnsupportedVersion& e ) - { - badVer = e.version; - } + } + catch( const tracy::UnsupportedVersion& e ) + { + badVer = e.version; + } + catch( const tracy::NotTracyDump& e ) + { + badVer = -1; } } } - if( badVer != 0 ) ImGui::OpenPopup( "Unsupported file version" ); + if( badVer != 0 ) + { + if( badVer > 0 ) + { + ImGui::OpenPopup( "Unsupported file version" ); + } + else + { + ImGui::OpenPopup( "Bad file" ); + } + } if( ImGui::BeginPopupModal( "Unsupported file version", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) ) { ImGui::Text( "The file you are trying to open is unsupported.\nYou should update to tracy %i.%i.%i or newer and try again.", badVer >> 16, ( badVer >> 8 ) & 0xFF, badVer & 0xFF ); @@ -128,6 +142,17 @@ int main( int argc, char** argv ) } ImGui::EndPopup(); } + if( ImGui::BeginPopupModal( "Bad file", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) ) + { + ImGui::Text( "The file you are trying to open is not a tracy dump." ); + ImGui::Separator(); + if( ImGui::Button( "Oops" ) ) + { + ImGui::CloseCurrentPopup(); + badVer = 0; + } + ImGui::EndPopup(); + } ImGui::End(); }