Display a dialog when user tries to open invalid file.

This commit is contained in:
Bartosz Taudul 2018-04-21 15:00:54 +02:00
parent 764792d8db
commit 3b6b67b7ee

View File

@ -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>( tracy::FileRead::Open( fn ) );
if( f )
try
{
try
auto f = std::unique_ptr<tracy::FileRead>( tracy::FileRead::Open( fn ) );
if( f )
{
view = std::make_unique<tracy::View>( *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();
}