From 688e61b9ae96a5e6e1fa4a3be20ca24b77516b8f Mon Sep 17 00:00:00 2001 From: William JCM Date: Wed, 21 Jul 2021 20:57:39 +0200 Subject: [PATCH] MassManager: move some fields to SaveTool. --- src/MassManager/MassManager.cpp | 12 ++---------- src/MassManager/MassManager.h | 11 ++++------- src/SaveTool/SaveTool.cpp | 10 ++++++++-- src/SaveTool/SaveTool.h | 1 + src/SaveTool/SaveTool_MainManager.cpp | 3 ++- src/SaveTool/SaveTool_drawMainMenu.cpp | 8 ++++---- 6 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/MassManager/MassManager.cpp b/src/MassManager/MassManager.cpp index a7c16ea..e0c4910 100644 --- a/src/MassManager/MassManager.cpp +++ b/src/MassManager/MassManager.cpp @@ -24,11 +24,11 @@ static const std::string empty_string = ""; -MassManager::MassManager(const std::string& save_path, const std::string& steam_id, bool demo): +MassManager::MassManager(const std::string& save_path, const std::string& steam_id, bool demo, const std::string& staging_dir): _saveDirectory{save_path}, _steamId{steam_id}, _demo{demo}, - _stagingAreaDirectory{Utility::Directory::join(Utility::Directory::path(Utility::Directory::executableLocation()), "staging")} + _stagingAreaDirectory{staging_dir} { Containers::arrayReserve(_hangars, 32); @@ -45,14 +45,6 @@ MassManager::MassManager(const std::string& save_path, const std::string& steam_ refreshStagedMasses(); } -auto MassManager::saveDirectory() -> std::string const& { - return _saveDirectory; -} - -auto MassManager::stagingAreaDirectory() -> std::string const& { - return _stagingAreaDirectory; -} - auto MassManager::lastError() -> std::string const& { return _lastError; } diff --git a/src/MassManager/MassManager.h b/src/MassManager/MassManager.h index 6a642f2..2b0d0f7 100644 --- a/src/MassManager/MassManager.h +++ b/src/MassManager/MassManager.h @@ -27,10 +27,7 @@ using namespace Corrade; class MassManager { public: - MassManager(const std::string& save_path, const std::string& steam_id, bool demo); - - auto saveDirectory() -> std::string const&; - auto stagingAreaDirectory() -> std::string const&; + MassManager(const std::string& save_path, const std::string& steam_id, bool demo, const std::string& staging_dir); auto lastError() -> std::string const&; @@ -50,15 +47,15 @@ class MassManager { auto deleteStagedMass(const std::string& filename) -> bool; private: - std::string _saveDirectory; - std::string _steamId; + const std::string& _saveDirectory; + const std::string& _steamId; bool _demo; std::string _lastError; Containers::Array _hangars; - const std::string _stagingAreaDirectory; + const std::string& _stagingAreaDirectory; std::map _stagedMasses; }; diff --git a/src/SaveTool/SaveTool.cpp b/src/SaveTool/SaveTool.cpp index a24548f..6b864e8 100644 --- a/src/SaveTool/SaveTool.cpp +++ b/src/SaveTool/SaveTool.cpp @@ -88,11 +88,16 @@ SaveTool::SaveTool(const Arguments& arguments): } _backupsDir = Utility::Directory::join(Utility::Directory::path(Utility::Directory::executableLocation()), "backups"); + _stagingDir = Utility::Directory::join(Utility::Directory::path(Utility::Directory::executableLocation()), "staging"); if(!Utility::Directory::exists(_backupsDir)) { Utility::Directory::mkpath(_backupsDir); } + if(!Utility::Directory::exists(_stagingDir)) { + Utility::Directory::mkpath(_stagingDir); + } + if(!findGameDataDirectory()) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app", _lastError.c_str(), window()); exit(EXIT_FAILURE); @@ -345,7 +350,8 @@ void SaveTool::initialiseMassManager() { _massManager.emplace(_saveDir, _currentProfile->steamId(), - _currentProfile->type() == ProfileType::Demo); + _currentProfile->type() == ProfileType::Demo, + _stagingDir); initialiseFileWatcher(); } @@ -353,7 +359,7 @@ void SaveTool::initialiseMassManager() { void SaveTool::initialiseFileWatcher() { _fileWatcher.emplace(); _watchIDs[SaveDir] = _fileWatcher->addWatch(_saveDir, this, false); - _watchIDs[StagingDir] = _fileWatcher->addWatch(_massManager->stagingAreaDirectory(), this, false); + _watchIDs[StagingDir] = _fileWatcher->addWatch(_stagingDir, this, false); _fileWatcher->watch(); } diff --git a/src/SaveTool/SaveTool.h b/src/SaveTool/SaveTool.h index 858d1c2..cc56934 100644 --- a/src/SaveTool/SaveTool.h +++ b/src/SaveTool/SaveTool.h @@ -166,6 +166,7 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener std::string _screenshotsDir; std::string _backupsDir; + std::string _stagingDir; enum class GameState : UnsignedByte { Unknown, NotRunning, Running diff --git a/src/SaveTool/SaveTool_MainManager.cpp b/src/SaveTool/SaveTool_MainManager.cpp index 22f1f9b..2c44f93 100644 --- a/src/SaveTool/SaveTool_MainManager.cpp +++ b/src/SaveTool/SaveTool_MainManager.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -528,7 +529,7 @@ void SaveTool::drawMassManager() { ImGui::TextUnformatted("Staging area"); ImGui::SameLine(); if(ImGui::SmallButton(ICON_FA_FOLDER_OPEN " Open staging folder")) { - openUri(_massManager->stagingAreaDirectory()); + openUri(Utility::Directory::toNativeSeparators(_stagingDir)); } for(const auto& pair : _massManager->stagedMasses()) { diff --git a/src/SaveTool/SaveTool_drawMainMenu.cpp b/src/SaveTool/SaveTool_drawMainMenu.cpp index af1f1c3..6112b95 100644 --- a/src/SaveTool/SaveTool_drawMainMenu.cpp +++ b/src/SaveTool/SaveTool_drawMainMenu.cpp @@ -41,14 +41,14 @@ void SaveTool::drawMainMenu() { } if(ImGui::BeginMenu(ICON_FA_FOLDER_OPEN " Open manager directory")) { - if(ImGui::MenuItem(ICON_FA_EXCHANGE_ALT " Staging area", nullptr, false, _massManager != nullptr)) { - openUri(Utility::Directory::toNativeSeparators(_massManager->stagingAreaDirectory())); - } - if(ImGui::MenuItem(ICON_FA_FILE_ARCHIVE " Profile backups", nullptr, false, _profileManager != nullptr)) { openUri(Utility::Directory::toNativeSeparators(_backupsDir)); } + if(ImGui::MenuItem(ICON_FA_EXCHANGE_ALT " Staging area", nullptr, false, _massManager != nullptr)) { + openUri(Utility::Directory::toNativeSeparators(_stagingDir)); + } + ImGui::EndMenu(); }