Compare commits
6 commits
fbfcce1d86
...
028d991b74
Author | SHA1 | Date | |
---|---|---|---|
028d991b74 | |||
fd367619e2 | |||
555cfcaadd | |||
2f70aa7672 | |||
e10e457ad8 | |||
661f6acd12 |
9 changed files with 47 additions and 43 deletions
|
@ -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_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.
|
||||
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
|
||||
set(BUILD_STATIC_LIBS ON CACHE BOOL "" FORCE)
|
||||
set(BUILD_TESTING OFF CACHE BOOL "" FORCE)
|
||||
endif(NOT SAVETOOL_USE_SYSTEM_LIBS)
|
||||
endif()
|
||||
|
||||
if(NOT SAVETOOL_USE_SYSTEM_SDL2)
|
||||
set(DIRECTX OFF CACHE BOOL "" FORCE) # We use OpenGL.
|
||||
|
|
|
@ -130,7 +130,7 @@ Application::Application(const Arguments& arguments):
|
|||
}
|
||||
|
||||
if(conf().skipDisclaimer()) {
|
||||
_uiState = UiState::Initialising;
|
||||
_uiState = UiState::Initialising;
|
||||
_initThread = std::thread{[this]{ initialiseManager(); }};
|
||||
}
|
||||
|
||||
|
@ -174,7 +174,7 @@ void
|
|||
Application::viewportEvent(ViewportEvent& event) {
|
||||
GL::defaultFramebuffer.setViewport({{}, event.framebufferSize()});
|
||||
|
||||
const Vector2 size = Vector2{windowSize()}/dpiScaling();
|
||||
const auto size = Vector2{windowSize()}/dpiScaling();
|
||||
_imgui.relayout(size, windowSize(), framebufferSize());
|
||||
}
|
||||
|
||||
|
@ -347,7 +347,7 @@ Application::drawDisclaimer() {
|
|||
ImGui::TableSetColumnIndex(1);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {24.0f, 12.0f});
|
||||
if(ImGui::Button("I understand the risks")) {
|
||||
_uiState = UiState::Initialising;
|
||||
_uiState = UiState::Initialising;
|
||||
_initThread = std::thread{[this]{ initialiseManager(); }};
|
||||
}
|
||||
ImGui::PopStyleVar();
|
||||
|
|
|
@ -29,11 +29,8 @@
|
|||
namespace mbst {
|
||||
|
||||
void
|
||||
Application::handleFileAction(efsw::WatchID watch_id,
|
||||
const std::string&,
|
||||
const std::string& filename,
|
||||
efsw::Action action,
|
||||
std::string old_filename)
|
||||
Application::handleFileAction(efsw::WatchID watch_id, const std::string&, const std::string& filename,
|
||||
efsw::Action action, std::string old_filename)
|
||||
{
|
||||
SDL_Event event;
|
||||
SDL_zero(event);
|
||||
|
|
|
@ -58,8 +58,7 @@ Application::initialiseGui() {
|
|||
LOG_INFO("Initialising Dear ImGui.");
|
||||
|
||||
auto ctx = ImGui::CreateContext();
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
auto& io = ImGui::GetIO();
|
||||
|
||||
const auto size = Vector2{windowSize()}/dpiScaling();
|
||||
|
||||
|
@ -94,10 +93,10 @@ Application::initialiseGui() {
|
|||
|
||||
io.IniFilename = nullptr;
|
||||
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
auto& style = ImGui::GetStyle();
|
||||
|
||||
style.WindowTitleAlign = {0.5f, 0.5f};
|
||||
style.FrameRounding = 3.2f;
|
||||
style.FrameRounding = 3.2f;
|
||||
style.Colors[ImGuiCol_WindowBg] = ImColor(0xff1f1f1f);
|
||||
}
|
||||
|
||||
|
@ -125,8 +124,7 @@ Application::initialiseManager() {
|
|||
void
|
||||
Application::initialiseMassManager() {
|
||||
LOG_INFO("Initialising the M.A.S.S. manager.");
|
||||
_massManager.emplace(conf().directories().gameSaves, _currentProfile->account(), _currentProfile->isDemo(),
|
||||
conf().directories().staging);
|
||||
_massManager.emplace(_currentProfile->account(), _currentProfile->isDemo());
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -521,6 +521,7 @@ Application::drawMassManager() {
|
|||
|
||||
drawDeleteMassPopup(mass_to_delete);
|
||||
|
||||
// TODO: fix this shit, like with the profile manager.
|
||||
static ImGuiID staged_mass_deletion_popup_ID = drawDeleteStagedMassPopup("");
|
||||
static Containers::StringView staged_mass_to_delete;
|
||||
|
||||
|
|
|
@ -333,6 +333,18 @@ Application::drawCustomStyle(GameObjects::CustomStyle& style) {
|
|||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <Corrade/Utility/Format.h>
|
||||
#include <Corrade/Utility/Path.h>
|
||||
|
||||
#include "../Configuration/Configuration.h"
|
||||
#include "../Logger/Logger.h"
|
||||
|
||||
#include "MassManager.h"
|
||||
|
@ -27,13 +28,12 @@ using namespace Containers::Literals;
|
|||
|
||||
namespace mbst { namespace Managers {
|
||||
|
||||
MassManager::MassManager(Containers::StringView save_path, Containers::StringView account, bool demo,
|
||||
Containers::StringView staging_dir):
|
||||
_saveDirectory{save_path}, _account{account}, _demo{demo}, _stagingAreaDirectory{staging_dir}
|
||||
MassManager::MassManager(Containers::StringView account, bool demo):
|
||||
_account{account}, _demo{demo}
|
||||
{
|
||||
Containers::String mass_filename = "";
|
||||
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));
|
||||
new(&_hangars[i]) GameObjects::Mass{mass_filename};
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ MassManager::refreshHangar(std::int32_t hangar) {
|
|||
}
|
||||
|
||||
Containers::String mass_filename =
|
||||
Utility::Path::join(_saveDirectory,
|
||||
Utility::Path::join(conf().directories().gameSaves,
|
||||
Utility::format("{}Unit{:.2d}{}.sav", _demo ? "Demo" : "", hangar, _account));
|
||||
_hangars[hangar] = GameObjects::Mass{mass_filename};
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ MassManager::importMass(Containers::StringView staged_fn, std::int32_t hangar) {
|
|||
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);
|
||||
|
||||
{
|
||||
|
@ -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)) {
|
||||
Utility::Path::remove(dest);
|
||||
|
@ -122,8 +122,8 @@ MassManager::exportMass(std::int32_t hangar) {
|
|||
return false;
|
||||
}
|
||||
|
||||
Containers::String source = Utility::Path::join(_saveDirectory, _hangars[hangar].filename());
|
||||
Containers::String dest = Utility::Path::join(_stagingAreaDirectory,
|
||||
Containers::String source = Utility::Path::join(conf().directories().gameSaves, _hangars[hangar].filename());
|
||||
Containers::String dest = Utility::Path::join(conf().directories().staging,
|
||||
Utility::format("{}_{}.sav", _hangars[hangar].name(), _account));
|
||||
|
||||
if(!Utility::Path::copy(source, dest)) {
|
||||
|
@ -149,8 +149,10 @@ MassManager::moveMass(std::int32_t source, std::int32_t destination) {
|
|||
return false;
|
||||
}
|
||||
|
||||
Containers::String source_file = Utility::Path::join(_saveDirectory, _hangars[source].filename());
|
||||
Containers::String dest_file = Utility::Path::join(_saveDirectory, _hangars[destination].filename());
|
||||
Containers::String source_file = Utility::Path::join(conf().directories().gameSaves,
|
||||
_hangars[source].filename());
|
||||
Containers::String dest_file = Utility::Path::join(conf().directories().gameSaves,
|
||||
_hangars[destination].filename());
|
||||
GameObjects::Mass::State dest_state = _hangars[destination].state();
|
||||
|
||||
switch(dest_state) {
|
||||
|
@ -181,7 +183,7 @@ MassManager::deleteMass(std::int32_t hangar) {
|
|||
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));
|
||||
LOG_ERROR(_lastError);
|
||||
return false;
|
||||
|
@ -200,11 +202,11 @@ MassManager::refreshStagedMasses() {
|
|||
_stagedMasses.clear();
|
||||
|
||||
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);
|
||||
|
||||
if(!file_list) {
|
||||
LOG_ERROR_FORMAT("{} couldn't be opened.", _stagingAreaDirectory);
|
||||
LOG_ERROR_FORMAT("{} couldn't be opened.", conf().directories().staging);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -216,7 +218,7 @@ MassManager::refreshStagedMasses() {
|
|||
|
||||
LOG_INFO("Scanning for staged M.A.S.S.es...");
|
||||
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) {
|
||||
LOG_INFO_FORMAT("Found staged M.A.S.S.: {}", *name);
|
||||
|
@ -232,11 +234,11 @@ void
|
|||
MassManager::refreshStagedMass(Containers::StringView 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);
|
||||
|
||||
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) {
|
||||
_stagedMasses[filename] = *name;
|
||||
}
|
||||
|
@ -257,7 +259,7 @@ MassManager::deleteStagedMass(Containers::StringView filename) {
|
|||
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);
|
||||
LOG_ERROR(_lastError);
|
||||
return false;
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace mbst { namespace Managers {
|
|||
|
||||
class MassManager {
|
||||
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;
|
||||
|
||||
|
@ -50,7 +50,6 @@ class MassManager {
|
|||
bool deleteStagedMass(Containers::StringView filename);
|
||||
|
||||
private:
|
||||
Containers::StringView _saveDirectory;
|
||||
Containers::StringView _account;
|
||||
bool _demo;
|
||||
|
||||
|
@ -58,8 +57,6 @@ class MassManager {
|
|||
|
||||
Containers::StaticArray<32, GameObjects::Mass> _hangars{NoInit};
|
||||
|
||||
Containers::StringView _stagingAreaDirectory;
|
||||
|
||||
std::map<Containers::String, Containers::String> _stagedMasses;
|
||||
};
|
||||
|
||||
|
|
|
@ -14,10 +14,7 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
|
||||
#include <Corrade/Containers/ScopeGuard.h>
|
||||
#include <Corrade/Containers/StaticArray.h>
|
||||
|
@ -25,8 +22,6 @@
|
|||
#include <Corrade/Utility/Path.h>
|
||||
#include <Corrade/Utility/String.h>
|
||||
|
||||
#include <zip.h>
|
||||
|
||||
#include "../Configuration/Configuration.h"
|
||||
#include "../Logger/Logger.h"
|
||||
|
||||
|
@ -103,6 +98,8 @@ ProfileManager::getProfile(std::size_t index) {
|
|||
|
||||
bool
|
||||
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()))) {
|
||||
_lastError = Utility::format("Couldn't delete {} (filename: {}).",
|
||||
_profiles[index].companyName(),
|
||||
|
|
Loading…
Reference in a new issue