Compare commits

..

6 commits

9 changed files with 47 additions and 43 deletions

View file

@ -30,12 +30,12 @@ cmake_dependent_option(SAVETOOL_USE_SYSTEM_LIBZIP "Use a system-wide version of
cmake_dependent_option(SAVETOOL_USE_SYSTEM_EFSW "Use a system-wide version of EFSW." ON "SAVETOOL_USE_SYSTEM_LIBS" OFF) cmake_dependent_option(SAVETOOL_USE_SYSTEM_EFSW "Use a system-wide version of EFSW." ON "SAVETOOL_USE_SYSTEM_LIBS" OFF)
cmake_dependent_option(SAVETOOL_USE_SYSTEM_LIBCURL "Use a system-wide version of libcurl." ON "SAVETOOL_USE_SYSTEM_LIBS" OFF) cmake_dependent_option(SAVETOOL_USE_SYSTEM_LIBCURL "Use a system-wide version of libcurl." ON "SAVETOOL_USE_SYSTEM_LIBS" OFF)
if(NOT SAVETOOL_USE_SYSTEM_LIBS) if(NOT SAVETOOL_USE_SYSTEM_LIBS OR NOT (SAVETOOL_USE_SYSTEM_CORRADE_MAGNUM AND SAVETOOL_USE_SYSTEM_SDL2 AND SAVETOOL_USE_SYSTEM_LIBZIP AND SAVETOOL_USE_SYSTEM_EFSW AND SAVETOOL_USE_SYSTEM_LIBCURL))
# Generic variables shared by multiple libs that don't provide their own. # Generic variables shared by multiple libs that don't provide their own.
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set(BUILD_STATIC_LIBS ON CACHE BOOL "" FORCE) set(BUILD_STATIC_LIBS ON CACHE BOOL "" FORCE)
set(BUILD_TESTING OFF CACHE BOOL "" FORCE) set(BUILD_TESTING OFF CACHE BOOL "" FORCE)
endif(NOT SAVETOOL_USE_SYSTEM_LIBS) endif()
if(NOT SAVETOOL_USE_SYSTEM_SDL2) if(NOT SAVETOOL_USE_SYSTEM_SDL2)
set(DIRECTX OFF CACHE BOOL "" FORCE) # We use OpenGL. set(DIRECTX OFF CACHE BOOL "" FORCE) # We use OpenGL.

View file

@ -130,7 +130,7 @@ Application::Application(const Arguments& arguments):
} }
if(conf().skipDisclaimer()) { if(conf().skipDisclaimer()) {
_uiState = UiState::Initialising; _uiState = UiState::Initialising;
_initThread = std::thread{[this]{ initialiseManager(); }}; _initThread = std::thread{[this]{ initialiseManager(); }};
} }
@ -174,7 +174,7 @@ void
Application::viewportEvent(ViewportEvent& event) { Application::viewportEvent(ViewportEvent& event) {
GL::defaultFramebuffer.setViewport({{}, event.framebufferSize()}); GL::defaultFramebuffer.setViewport({{}, event.framebufferSize()});
const Vector2 size = Vector2{windowSize()}/dpiScaling(); const auto size = Vector2{windowSize()}/dpiScaling();
_imgui.relayout(size, windowSize(), framebufferSize()); _imgui.relayout(size, windowSize(), framebufferSize());
} }
@ -347,7 +347,7 @@ Application::drawDisclaimer() {
ImGui::TableSetColumnIndex(1); ImGui::TableSetColumnIndex(1);
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {24.0f, 12.0f}); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {24.0f, 12.0f});
if(ImGui::Button("I understand the risks")) { if(ImGui::Button("I understand the risks")) {
_uiState = UiState::Initialising; _uiState = UiState::Initialising;
_initThread = std::thread{[this]{ initialiseManager(); }}; _initThread = std::thread{[this]{ initialiseManager(); }};
} }
ImGui::PopStyleVar(); ImGui::PopStyleVar();

View file

@ -29,11 +29,8 @@
namespace mbst { namespace mbst {
void void
Application::handleFileAction(efsw::WatchID watch_id, Application::handleFileAction(efsw::WatchID watch_id, const std::string&, const std::string& filename,
const std::string&, efsw::Action action, std::string old_filename)
const std::string& filename,
efsw::Action action,
std::string old_filename)
{ {
SDL_Event event; SDL_Event event;
SDL_zero(event); SDL_zero(event);

View file

@ -58,8 +58,7 @@ Application::initialiseGui() {
LOG_INFO("Initialising Dear ImGui."); LOG_INFO("Initialising Dear ImGui.");
auto ctx = ImGui::CreateContext(); auto ctx = ImGui::CreateContext();
auto& io = ImGui::GetIO();
ImGuiIO& io = ImGui::GetIO();
const auto size = Vector2{windowSize()}/dpiScaling(); const auto size = Vector2{windowSize()}/dpiScaling();
@ -94,10 +93,10 @@ Application::initialiseGui() {
io.IniFilename = nullptr; io.IniFilename = nullptr;
ImGuiStyle& style = ImGui::GetStyle(); auto& style = ImGui::GetStyle();
style.WindowTitleAlign = {0.5f, 0.5f}; style.WindowTitleAlign = {0.5f, 0.5f};
style.FrameRounding = 3.2f; style.FrameRounding = 3.2f;
style.Colors[ImGuiCol_WindowBg] = ImColor(0xff1f1f1f); style.Colors[ImGuiCol_WindowBg] = ImColor(0xff1f1f1f);
} }
@ -125,8 +124,7 @@ Application::initialiseManager() {
void void
Application::initialiseMassManager() { Application::initialiseMassManager() {
LOG_INFO("Initialising the M.A.S.S. manager."); LOG_INFO("Initialising the M.A.S.S. manager.");
_massManager.emplace(conf().directories().gameSaves, _currentProfile->account(), _currentProfile->isDemo(), _massManager.emplace(_currentProfile->account(), _currentProfile->isDemo());
conf().directories().staging);
} }
void void

View file

@ -521,6 +521,7 @@ Application::drawMassManager() {
drawDeleteMassPopup(mass_to_delete); drawDeleteMassPopup(mass_to_delete);
// TODO: fix this shit, like with the profile manager.
static ImGuiID staged_mass_deletion_popup_ID = drawDeleteStagedMassPopup(""); static ImGuiID staged_mass_deletion_popup_ID = drawDeleteStagedMassPopup("");
static Containers::StringView staged_mass_to_delete; static Containers::StringView staged_mass_to_delete;

View file

@ -333,6 +333,18 @@ Application::drawCustomStyle(GameObjects::CustomStyle& style) {
style.name = name_buf.data(); style.name = name_buf.data();
} }
if(ImGui::SmallButton(ICON_FA_FILE_EXPORT " Export")) {
if(!ImportExport::exportStyle(_currentMass->name(), style)) {
_queue.addToast(Toast::Type::Error, ImportExport::lastExportError());
}
else {
_queue.addToast(Toast::Type::Success, "Style exported successfully.");
}
}
if(drawUnsafeWidget(ImGui::SmallButton, ICON_FA_FILE_IMPORT " Import")) {
// TODO: implement once the style manager is ready.
}
ImGui::EndMenuBar(); ImGui::EndMenuBar();
} }

View file

@ -19,6 +19,7 @@
#include <Corrade/Utility/Format.h> #include <Corrade/Utility/Format.h>
#include <Corrade/Utility/Path.h> #include <Corrade/Utility/Path.h>
#include "../Configuration/Configuration.h"
#include "../Logger/Logger.h" #include "../Logger/Logger.h"
#include "MassManager.h" #include "MassManager.h"
@ -27,13 +28,12 @@ using namespace Containers::Literals;
namespace mbst { namespace Managers { namespace mbst { namespace Managers {
MassManager::MassManager(Containers::StringView save_path, Containers::StringView account, bool demo, MassManager::MassManager(Containers::StringView account, bool demo):
Containers::StringView staging_dir): _account{account}, _demo{demo}
_saveDirectory{save_path}, _account{account}, _demo{demo}, _stagingAreaDirectory{staging_dir}
{ {
Containers::String mass_filename = ""; Containers::String mass_filename = "";
for(std::uint32_t i = 0; i < _hangars.size(); i++) { for(std::uint32_t i = 0; i < _hangars.size(); i++) {
mass_filename = Utility::Path::join(_saveDirectory, mass_filename = Utility::Path::join(conf().directories().gameSaves,
Utility::format("{}Unit{:.2d}{}.sav", demo ? "Demo"_s : ""_s, i, _account)); Utility::format("{}Unit{:.2d}{}.sav", demo ? "Demo"_s : ""_s, i, _account));
new(&_hangars[i]) GameObjects::Mass{mass_filename}; new(&_hangars[i]) GameObjects::Mass{mass_filename};
} }
@ -60,7 +60,7 @@ MassManager::refreshHangar(std::int32_t hangar) {
} }
Containers::String mass_filename = Containers::String mass_filename =
Utility::Path::join(_saveDirectory, Utility::Path::join(conf().directories().gameSaves,
Utility::format("{}Unit{:.2d}{}.sav", _demo ? "Demo" : "", hangar, _account)); Utility::format("{}Unit{:.2d}{}.sav", _demo ? "Demo" : "", hangar, _account));
_hangars[hangar] = GameObjects::Mass{mass_filename}; _hangars[hangar] = GameObjects::Mass{mass_filename};
} }
@ -81,7 +81,7 @@ MassManager::importMass(Containers::StringView staged_fn, std::int32_t hangar) {
return false; return false;
} }
Containers::String source = Utility::Path::join(_stagingAreaDirectory, staged_fn); Containers::String source = Utility::Path::join(conf().directories().staging, staged_fn);
Utility::Path::copy(source, source + ".tmp"_s); Utility::Path::copy(source, source + ".tmp"_s);
{ {
@ -93,7 +93,7 @@ MassManager::importMass(Containers::StringView staged_fn, std::int32_t hangar) {
} }
} }
Containers::String dest = Utility::Path::join(_saveDirectory, _hangars[hangar].filename()); Containers::String dest = Utility::Path::join(conf().directories().gameSaves, _hangars[hangar].filename());
if(Utility::Path::exists(dest)) { if(Utility::Path::exists(dest)) {
Utility::Path::remove(dest); Utility::Path::remove(dest);
@ -122,8 +122,8 @@ MassManager::exportMass(std::int32_t hangar) {
return false; return false;
} }
Containers::String source = Utility::Path::join(_saveDirectory, _hangars[hangar].filename()); Containers::String source = Utility::Path::join(conf().directories().gameSaves, _hangars[hangar].filename());
Containers::String dest = Utility::Path::join(_stagingAreaDirectory, Containers::String dest = Utility::Path::join(conf().directories().staging,
Utility::format("{}_{}.sav", _hangars[hangar].name(), _account)); Utility::format("{}_{}.sav", _hangars[hangar].name(), _account));
if(!Utility::Path::copy(source, dest)) { if(!Utility::Path::copy(source, dest)) {
@ -149,8 +149,10 @@ MassManager::moveMass(std::int32_t source, std::int32_t destination) {
return false; return false;
} }
Containers::String source_file = Utility::Path::join(_saveDirectory, _hangars[source].filename()); Containers::String source_file = Utility::Path::join(conf().directories().gameSaves,
Containers::String dest_file = Utility::Path::join(_saveDirectory, _hangars[destination].filename()); _hangars[source].filename());
Containers::String dest_file = Utility::Path::join(conf().directories().gameSaves,
_hangars[destination].filename());
GameObjects::Mass::State dest_state = _hangars[destination].state(); GameObjects::Mass::State dest_state = _hangars[destination].state();
switch(dest_state) { switch(dest_state) {
@ -181,7 +183,7 @@ MassManager::deleteMass(std::int32_t hangar) {
return false; return false;
} }
if(!Utility::Path::remove(Utility::Path::join(_saveDirectory, _hangars[hangar].filename()))) { if(!Utility::Path::remove(Utility::Path::join(conf().directories().gameSaves, _hangars[hangar].filename()))) {
_lastError = Utility::format("Deletion failed: {}", std::strerror(errno)); _lastError = Utility::format("Deletion failed: {}", std::strerror(errno));
LOG_ERROR(_lastError); LOG_ERROR(_lastError);
return false; return false;
@ -200,11 +202,11 @@ MassManager::refreshStagedMasses() {
_stagedMasses.clear(); _stagedMasses.clear();
using Utility::Path::ListFlag; using Utility::Path::ListFlag;
auto file_list = Utility::Path::list(_stagingAreaDirectory, auto file_list = Utility::Path::list(conf().directories().staging,
ListFlag::SkipSpecial|ListFlag::SkipDirectories|ListFlag::SkipDotAndDotDot); ListFlag::SkipSpecial|ListFlag::SkipDirectories|ListFlag::SkipDotAndDotDot);
if(!file_list) { if(!file_list) {
LOG_ERROR_FORMAT("{} couldn't be opened.", _stagingAreaDirectory); LOG_ERROR_FORMAT("{} couldn't be opened.", conf().directories().staging);
return; return;
} }
@ -216,7 +218,7 @@ MassManager::refreshStagedMasses() {
LOG_INFO("Scanning for staged M.A.S.S.es..."); LOG_INFO("Scanning for staged M.A.S.S.es...");
for(Containers::StringView file : list_view) { for(Containers::StringView file : list_view) {
auto name = GameObjects::Mass::getNameFromFile(Utility::Path::join(_stagingAreaDirectory, file)); auto name = GameObjects::Mass::getNameFromFile(Utility::Path::join(conf().directories().staging, file));
if(name) { if(name) {
LOG_INFO_FORMAT("Found staged M.A.S.S.: {}", *name); LOG_INFO_FORMAT("Found staged M.A.S.S.: {}", *name);
@ -232,11 +234,11 @@ void
MassManager::refreshStagedMass(Containers::StringView filename) { MassManager::refreshStagedMass(Containers::StringView filename) {
LOG_INFO_FORMAT("Refreshing staged unit with filename {}.", filename); LOG_INFO_FORMAT("Refreshing staged unit with filename {}.", filename);
bool file_exists = Utility::Path::exists(Utility::Path::join(_stagingAreaDirectory, filename)); bool file_exists = Utility::Path::exists(Utility::Path::join(conf().directories().staging, filename));
auto it = _stagedMasses.find(filename); auto it = _stagedMasses.find(filename);
if(file_exists) { if(file_exists) {
auto name = GameObjects::Mass::getNameFromFile(Utility::Path::join(_stagingAreaDirectory, filename)); auto name = GameObjects::Mass::getNameFromFile(Utility::Path::join(conf().directories().staging, filename));
if(name) { if(name) {
_stagedMasses[filename] = *name; _stagedMasses[filename] = *name;
} }
@ -257,7 +259,7 @@ MassManager::deleteStagedMass(Containers::StringView filename) {
return false; return false;
} }
if(!Utility::Path::remove(Utility::Path::join(_stagingAreaDirectory, filename))) { if(!Utility::Path::remove(Utility::Path::join(conf().directories().staging, filename))) {
_lastError = filename + " couldn't be deleted: " + std::strerror(errno); _lastError = filename + " couldn't be deleted: " + std::strerror(errno);
LOG_ERROR(_lastError); LOG_ERROR(_lastError);
return false; return false;

View file

@ -30,7 +30,7 @@ namespace mbst { namespace Managers {
class MassManager { class MassManager {
public: public:
MassManager(Containers::StringView save_path, Containers::StringView account, bool demo, Containers::StringView staging_dir); MassManager(Containers::StringView account, bool demo);
auto lastError() -> Containers::StringView; auto lastError() -> Containers::StringView;
@ -50,7 +50,6 @@ class MassManager {
bool deleteStagedMass(Containers::StringView filename); bool deleteStagedMass(Containers::StringView filename);
private: private:
Containers::StringView _saveDirectory;
Containers::StringView _account; Containers::StringView _account;
bool _demo; bool _demo;
@ -58,8 +57,6 @@ class MassManager {
Containers::StaticArray<32, GameObjects::Mass> _hangars{NoInit}; Containers::StaticArray<32, GameObjects::Mass> _hangars{NoInit};
Containers::StringView _stagingAreaDirectory;
std::map<Containers::String, Containers::String> _stagedMasses; std::map<Containers::String, Containers::String> _stagedMasses;
}; };

View file

@ -14,10 +14,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cstdio>
#include <algorithm> #include <algorithm>
#include <chrono>
#include <Corrade/Containers/ScopeGuard.h> #include <Corrade/Containers/ScopeGuard.h>
#include <Corrade/Containers/StaticArray.h> #include <Corrade/Containers/StaticArray.h>
@ -25,8 +22,6 @@
#include <Corrade/Utility/Path.h> #include <Corrade/Utility/Path.h>
#include <Corrade/Utility/String.h> #include <Corrade/Utility/String.h>
#include <zip.h>
#include "../Configuration/Configuration.h" #include "../Configuration/Configuration.h"
#include "../Logger/Logger.h" #include "../Logger/Logger.h"
@ -103,6 +98,8 @@ ProfileManager::getProfile(std::size_t index) {
bool bool
ProfileManager::deleteProfile(std::size_t index, bool delete_builds) { ProfileManager::deleteProfile(std::size_t index, bool delete_builds) {
CORRADE_INTERNAL_ASSERT(index < _profiles.size());
if(!Utility::Path::remove(Utility::Path::join(conf().directories().gameSaves, _profiles[index].filename()))) { if(!Utility::Path::remove(Utility::Path::join(conf().directories().gameSaves, _profiles[index].filename()))) {
_lastError = Utility::format("Couldn't delete {} (filename: {}).", _lastError = Utility::format("Couldn't delete {} (filename: {}).",
_profiles[index].companyName(), _profiles[index].companyName(),