From 6a30c7d037f03d4dded92d86ac8027c03e9d738d Mon Sep 17 00:00:00 2001 From: William JCM Date: Mon, 29 Jun 2020 16:38:43 +0200 Subject: [PATCH] Fail gracefully if the screenshots folder doesn't exist. --- GUI/EvtMainFrame.cpp | 11 +++++++++-- GUI/MainFrame.cpp | 2 +- GUI/MainFrame.fbp | 4 ++-- GUI/MainFrame.h | 2 +- MassManager/MassManager.cpp | 4 +--- MassManager/MassManager.h | 2 +- 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/GUI/EvtMainFrame.cpp b/GUI/EvtMainFrame.cpp index d9cfa48..48ca4c8 100644 --- a/GUI/EvtMainFrame.cpp +++ b/GUI/EvtMainFrame.cpp @@ -56,8 +56,6 @@ EvtMainFrame::EvtMainFrame(wxWindow* parent): MainFrame(parent) { wxFSW_EVENT_CREATE|wxFSW_EVENT_DELETE|wxFSW_EVENT_MODIFY|wxFSW_EVENT_RENAME, wxString::Format("*%s.sav", _manager.steamId())); _watcher.AddTree(wxFileName(Utility::Directory::toNativeSeparators(_manager.stagingAreaDirectory()), wxPATH_WIN), wxFSW_EVENT_CREATE|wxFSW_EVENT_DELETE|wxFSW_EVENT_MODIFY|wxFSW_EVENT_RENAME, "*.sav"); - _watcher.AddTree(wxFileName(Utility::Directory::toNativeSeparators(_manager.screenshotDirectory()), wxPATH_WIN), - wxFSW_EVENT_CREATE|wxFSW_EVENT_DELETE, "*.png"); // Not monitoring wxFSW_EVENT_{MODIFY,RENAME}, because they're a massive pain to handle. Ugh. std::vector v = _manager.initialiseStagingArea(); for(const std::string& s : v) { @@ -66,6 +64,15 @@ EvtMainFrame::EvtMainFrame(wxWindow* parent): MainFrame(parent) { _gameCheckTimer.Start(3000); + if(!_manager.findScreenshotDirectory()) { + warningMessage("Screenshot manager not ready:\n\n" + _manager.lastError()); + _screenshotsPanel->Disable(); + return; + } + + _watcher.AddTree(wxFileName(Utility::Directory::toNativeSeparators(_manager.screenshotDirectory()), wxPATH_WIN), + wxFSW_EVENT_CREATE|wxFSW_EVENT_DELETE, "*.png"); // Not monitoring wxFSW_EVENT_{MODIFY,RENAME}, because they're a massive pain to handle. Ugh. + _screenshotsList->SetImageList(&_screenshotThumbs, wxIMAGE_LIST_NORMAL); updateScreenshotList(); diff --git a/GUI/MainFrame.cpp b/GUI/MainFrame.cpp index b7d484c..66c7e18 100644 --- a/GUI/MainFrame.cpp +++ b/GUI/MainFrame.cpp @@ -186,7 +186,7 @@ MainFrame::MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, co bSizerMainPanel->Add( bSizerGameStatus, 0, wxALIGN_CENTER_HORIZONTAL, 5 ); - _aboutText = new wxStaticText( _mainPanel, wxID_ANY, wxT("This version of the application was tested on M.A.S.S. Builder early access version 0.4.1.\nIt may or may not work with other versions of the game.\nMade for the M.A.S.S. Builder community by Guillaume Jacquemin."), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER_HORIZONTAL ); + _aboutText = new wxStaticText( _mainPanel, wxID_ANY, wxT("This version of the application was tested on M.A.S.S. Builder early access version 0.4.5.\nIt may or may not work with other versions of the game.\nMade for the M.A.S.S. Builder community by Guillaume Jacquemin."), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER_HORIZONTAL ); _aboutText->Wrap( -1 ); bSizerMainPanel->Add( _aboutText, 0, wxEXPAND|wxRIGHT|wxLEFT|wxALIGN_CENTER_HORIZONTAL, 5 ); diff --git a/GUI/MainFrame.fbp b/GUI/MainFrame.fbp index 2946cae..a98cfa2 100644 --- a/GUI/MainFrame.fbp +++ b/GUI/MainFrame.fbp @@ -48,7 +48,7 @@ -1,-1 wxCAPTION|wxCLOSE_BOX|wxMINIMIZE_BOX|wxSYSTEM_MENU ; ; forward_declare - M.A.S.S. Manager 1.1.1 + M.A.S.S. Manager 1.1.2 @@ -1968,7 +1968,7 @@ 0 0 wxID_ANY - This version of the application was tested on M.A.S.S. Builder early access version 0.4.1. It may or may not work with other versions of the game. Made for the M.A.S.S. Builder community by Guillaume Jacquemin. + This version of the application was tested on M.A.S.S. Builder early access version 0.4.5. It may or may not work with other versions of the game. Made for the M.A.S.S. Builder community by Guillaume Jacquemin. 0 0 diff --git a/GUI/MainFrame.h b/GUI/MainFrame.h index 61916f2..3281a60 100644 --- a/GUI/MainFrame.h +++ b/GUI/MainFrame.h @@ -96,7 +96,7 @@ class MainFrame : public wxFrame public: - MainFrame( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("M.A.S.S. Manager 1.1.1"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxCAPTION|wxCLOSE_BOX|wxMINIMIZE_BOX|wxSYSTEM_MENU|wxCLIP_CHILDREN|wxTAB_TRAVERSAL ); + MainFrame( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("M.A.S.S. Manager 1.1.2"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxCAPTION|wxCLOSE_BOX|wxMINIMIZE_BOX|wxSYSTEM_MENU|wxCLIP_CHILDREN|wxTAB_TRAVERSAL ); ~MainFrame(); diff --git a/MassManager/MassManager.cpp b/MassManager/MassManager.cpp index 9109281..dea0e4d 100644 --- a/MassManager/MassManager.cpp +++ b/MassManager/MassManager.cpp @@ -43,7 +43,7 @@ constexpr unsigned char active_slot_locator[] = { 'A', 'c', 't', 'i', 'v', 'e', constexpr unsigned char credits_locator[] = { 'C', 'r', 'e', 'd', 'i', 't', '\0', 0x0C, '\0', '\0', '\0', 'I', 'n', 't', 'P', 'r', 'o', 'p', 'e', 'r', 't', 'y', '\0' }; MassManager::MassManager() { - _ready = findSaveDirectory() && findSteamId() && findScreenshotDirectory(); + _ready = findSaveDirectory() && findSteamId(); if(!_ready) { return; @@ -59,8 +59,6 @@ MassManager::MassManager() { _hangars[i]._filename = Utility::formatString("Unit{:.2d}{}.sav", i, _steamId); refreshHangar(i); } - - loadScreenshots(); } auto MassManager::ready() -> bool { diff --git a/MassManager/MassManager.h b/MassManager/MassManager.h index 41d6ed4..e1b3b34 100644 --- a/MassManager/MassManager.h +++ b/MassManager/MassManager.h @@ -94,6 +94,7 @@ class MassManager { auto stagedMassName(int index) -> std::string; auto stagedMassName(const std::string& filename) -> std::string; + auto findScreenshotDirectory() -> bool; void loadScreenshots(); auto screenshots() -> std::vector const&; void sortScreenshots(SortType type); @@ -107,7 +108,6 @@ class MassManager { auto findSaveDirectory() -> bool; auto findSteamId() -> bool; - auto findScreenshotDirectory() -> bool; void addScreenshot(const std::string& filename); bool _ready = false;