Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
on very small (<10^{-300}) probabilities.
- The new subgame root computation fixes a bug which failed to detect subgames where the subgame
root node is a member of an absent-minded infoset. (#584)
- Removed spurious warning in graphical interface when loading file as a command-line argument
(or also by clicking on a file in MSW, as that uses the command-line mechanism). (#801)

## [16.5.1] - unreleased

Expand Down
37 changes: 15 additions & 22 deletions src/gui/app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ wxBEGIN_EVENT_TABLE(Application, wxApp) EVT_TIMER(wxID_ANY, Application::OnSplas

bool Application::OnInit()
{
wxApp::OnInit();

const wxBitmap bitmap(gambitbig_xpm);
m_splashTimer.Start();
m_splash = new wxSplashScreen(MakeScaledSplashBitmap(bitmap, 0.45),
Expand All @@ -84,26 +82,19 @@ wxBEGIN_EVENT_TABLE(Application, wxApp) EVT_TIMER(wxID_ANY, Application::OnSplas
wxConfigBase::Get()->Read(_T("/General/CurrentDirectory"), &m_currentDir, _T(""));

// Process command line arguments, if any.
for (int i = 1; i < wxApp::argc; i++) {
const AppLoadResult result = LoadFile(wxApp::argv[i]);
for (int i = 1; i < argc; i++) {
const AppLoadResult result = LoadFile(argv[i], nullptr);
if (result == GBT_APP_OPEN_FAILED) {
wxMessageDialog dialog(
nullptr, wxT("Gambit could not open file '") + wxApp::argv[i] + wxT("' for reading."),
wxT("Unable to open file"), wxOK | wxICON_ERROR);
dialog.ShowModal();
wxMessageBox(wxString::Format(_("Gambit could not open file for reading:\n%s"), argv[i]),
_("Unable to open file"), wxOK | wxICON_ERROR, nullptr);
}
else if (result == GBT_APP_PARSE_FAILED) {
wxMessageDialog dialog(
nullptr, wxT("File '") + wxApp::argv[i] + wxT("' is not in a format Gambit recognizes."),
wxT("Unable to read file"), wxOK | wxICON_ERROR);
dialog.ShowModal();
wxMessageBox(wxString::Format(_("File is not in a format Gambit recognizes:\n%s"), argv[i]),
_("Unable to read file"), wxOK | wxICON_ERROR, nullptr);
}
}

if (m_documents.size() == 0) {
// If we don't have any game files -- whether because none were
// specified on the command line, or because those specified couldn't
// be read -- create a default document.
if (m_documents.empty()) {
const Game efg = NewTree();
efg->NewPlayer()->SetLabel("Player 1");
efg->NewPlayer()->SetLabel("Player 2");
Expand Down Expand Up @@ -140,10 +131,12 @@ void Application::DismissSplash()
m_splash = nullptr;
}

AppLoadResult Application::LoadFile(const wxString &p_filename)
AppLoadResult Application::LoadFile(const wxString &p_filename, wxWindow *p_parent)
{
std::ifstream infile((const char *)p_filename.mb_str());
std::ifstream infile(p_filename.mb_str());
if (!infile.good()) {
wxMessageBox(_("Gambit could not open file for reading:\n") + p_filename,
_("Unable to open file"), wxOK | wxICON_ERROR, p_parent);
return GBT_APP_OPEN_FAILED;
}

Expand All @@ -155,21 +148,21 @@ AppLoadResult Application::LoadFile(const wxString &p_filename)
(void)new GameFrame(nullptr, doc);
return GBT_APP_FILE_OK;
}
else {
delete doc;
}
delete doc;

try {
const Game nfg = ReadGame(infile);

m_fileHistory.AddFileToHistory(p_filename);
m_fileHistory.Save(*wxConfigBase::Get());
doc = new GameDocument(nfg);
doc->SetFilename(wxT(""));
doc->SetFilename("");
(void)new GameFrame(nullptr, doc);
return GBT_APP_FILE_OK;
}
catch (InvalidFileException &) {
wxMessageBox(_("File is not in a format Gambit recognizes:\n") + p_filename,
_("Unable to read file"), wxOK | wxICON_ERROR, p_parent);
return GBT_APP_PARSE_FAILED;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/gui/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ class Application final : public wxApp {
}
void RemoveMenu(wxMenu *p_menu) { m_fileHistory.RemoveMenu(p_menu); }

AppLoadResult LoadFile(const wxString &);
AppLoadResult LoadFile(const wxString &, wxWindow *);
;
#ifdef __WXMAC__
void MacOpenFile(const wxString &filename) override { LoadFile(filename); }
void MacOpenFile(const wxString &filename) override { LoadFile(filename, nullptr); }
#endif // __WXMAC__

//!
Expand Down
30 changes: 2 additions & 28 deletions src/gui/gameframe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -649,20 +649,7 @@ void GameFrame::OnFileOpen(wxCommandEvent &)
if (dialog.ShowModal() == wxID_OK) {
const wxString filename = dialog.GetPath();
wxGetApp().SetCurrentDir(wxPathOnly(filename));

const AppLoadResult result = wxGetApp().LoadFile(filename);
if (result == GBT_APP_OPEN_FAILED) {
wxMessageDialog msgdialog(
this, wxT("Gambit could not open file '") + filename + wxT("' for reading."),
wxT("Unable to open file"), wxOK | wxICON_ERROR);
msgdialog.ShowModal();
}
else if (result == GBT_APP_PARSE_FAILED) {
wxMessageDialog msgdialog(
this, wxT("File '") + filename + wxT("' is not in a format Gambit recognizes."),
wxT("Unable to read file"), wxOK | wxICON_ERROR);
msgdialog.ShowModal();
}
wxGetApp().LoadFile(filename, this);
}
}

Expand Down Expand Up @@ -903,20 +890,7 @@ void GameFrame::OnFileExit(wxCommandEvent &p_event)
void GameFrame::OnFileMRUFile(wxCommandEvent &p_event)
{
const wxString filename = wxGetApp().GetHistoryFile(p_event.GetId() - wxID_FILE1);
const AppLoadResult result = wxGetApp().LoadFile(filename);

if (result == GBT_APP_OPEN_FAILED) {
wxMessageDialog dialog(this,
wxT("Gambit could not open file '") + filename + wxT("' for reading."),
wxT("Unable to open file"), wxOK | wxICON_ERROR);
dialog.ShowModal();
}
else if (result == GBT_APP_PARSE_FAILED) {
wxMessageDialog dialog(
this, wxT("File '") + filename + wxT("' is not in a format Gambit recognizes."),
wxT("Unable to read file"), wxOK | wxICON_ERROR);
dialog.ShowModal();
}
wxGetApp().LoadFile(filename, this);
}

//----------------------------------------------------------------------
Expand Down
Loading