Compare commits
No commits in common. "028d991b74fb75547ea3f37ebdd7c5423c786724" and "fbfcce1d86252b66c44e9ac3cdff9a431ac1e61d" have entirely different histories.
028d991b74
...
fbfcce1d86
9 changed files with 43 additions and 47 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 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))
|
||||
if(NOT SAVETOOL_USE_SYSTEM_LIBS)
|
||||
# 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()
|
||||
endif(NOT SAVETOOL_USE_SYSTEM_LIBS)
|
||||
|
||||
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 auto size = Vector2{windowSize()}/dpiScaling();
|
||||
const Vector2 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,8 +29,11 @@
|
|||
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,7 +58,8 @@ Application::initialiseGui() {
|
|||
LOG_INFO("Initialising Dear ImGui.");
|
||||
|
||||
auto ctx = ImGui::CreateContext();
|
||||
auto& io = ImGui::GetIO();
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
const auto size = Vector2{windowSize()}/dpiScaling();
|
||||
|
||||
|
@ -93,10 +94,10 @@ Application::initialiseGui() {
|
|||
|
||||
io.IniFilename = nullptr;
|
||||
|
||||
auto& style = ImGui::GetStyle();
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
|
||||
style.WindowTitleAlign = {0.5f, 0.5f};
|
||||
style.FrameRounding = 3.2f;
|
||||
style.FrameRounding = 3.2f;
|
||||
style.Colors[ImGuiCol_WindowBg] = ImColor(0xff1f1f1f);
|
||||
}
|
||||
|
||||
|
@ -124,7 +125,8 @@ Application::initialiseManager() {
|
|||
void
|
||||
Application::initialiseMassManager() {
|
||||
LOG_INFO("Initialising the M.A.S.S. manager.");
|
||||
_massManager.emplace(_currentProfile->account(), _currentProfile->isDemo());
|
||||
_massManager.emplace(conf().directories().gameSaves, _currentProfile->account(), _currentProfile->isDemo(),
|
||||
conf().directories().staging);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -521,7 +521,6 @@ 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,18 +333,6 @@ 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,7 +19,6 @@
|
|||
#include <Corrade/Utility/Format.h>
|
||||
#include <Corrade/Utility/Path.h>
|
||||
|
||||
#include "../Configuration/Configuration.h"
|
||||
#include "../Logger/Logger.h"
|
||||
|
||||
#include "MassManager.h"
|
||||
|
@ -28,12 +27,13 @@ using namespace Containers::Literals;
|
|||
|
||||
namespace mbst { namespace Managers {
|
||||
|
||||
MassManager::MassManager(Containers::StringView account, bool demo):
|
||||
_account{account}, _demo{demo}
|
||||
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}
|
||||
{
|
||||
Containers::String mass_filename = "";
|
||||
for(std::uint32_t i = 0; i < _hangars.size(); i++) {
|
||||
mass_filename = Utility::Path::join(conf().directories().gameSaves,
|
||||
mass_filename = Utility::Path::join(_saveDirectory,
|
||||
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(conf().directories().gameSaves,
|
||||
Utility::Path::join(_saveDirectory,
|
||||
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(conf().directories().staging, staged_fn);
|
||||
Containers::String source = Utility::Path::join(_stagingAreaDirectory, 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(conf().directories().gameSaves, _hangars[hangar].filename());
|
||||
Containers::String dest = Utility::Path::join(_saveDirectory, _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(conf().directories().gameSaves, _hangars[hangar].filename());
|
||||
Containers::String dest = Utility::Path::join(conf().directories().staging,
|
||||
Containers::String source = Utility::Path::join(_saveDirectory, _hangars[hangar].filename());
|
||||
Containers::String dest = Utility::Path::join(_stagingAreaDirectory,
|
||||
Utility::format("{}_{}.sav", _hangars[hangar].name(), _account));
|
||||
|
||||
if(!Utility::Path::copy(source, dest)) {
|
||||
|
@ -149,10 +149,8 @@ MassManager::moveMass(std::int32_t source, std::int32_t destination) {
|
|||
return false;
|
||||
}
|
||||
|
||||
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());
|
||||
Containers::String source_file = Utility::Path::join(_saveDirectory, _hangars[source].filename());
|
||||
Containers::String dest_file = Utility::Path::join(_saveDirectory, _hangars[destination].filename());
|
||||
GameObjects::Mass::State dest_state = _hangars[destination].state();
|
||||
|
||||
switch(dest_state) {
|
||||
|
@ -183,7 +181,7 @@ MassManager::deleteMass(std::int32_t hangar) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if(!Utility::Path::remove(Utility::Path::join(conf().directories().gameSaves, _hangars[hangar].filename()))) {
|
||||
if(!Utility::Path::remove(Utility::Path::join(_saveDirectory, _hangars[hangar].filename()))) {
|
||||
_lastError = Utility::format("Deletion failed: {}", std::strerror(errno));
|
||||
LOG_ERROR(_lastError);
|
||||
return false;
|
||||
|
@ -202,11 +200,11 @@ MassManager::refreshStagedMasses() {
|
|||
_stagedMasses.clear();
|
||||
|
||||
using Utility::Path::ListFlag;
|
||||
auto file_list = Utility::Path::list(conf().directories().staging,
|
||||
auto file_list = Utility::Path::list(_stagingAreaDirectory,
|
||||
ListFlag::SkipSpecial|ListFlag::SkipDirectories|ListFlag::SkipDotAndDotDot);
|
||||
|
||||
if(!file_list) {
|
||||
LOG_ERROR_FORMAT("{} couldn't be opened.", conf().directories().staging);
|
||||
LOG_ERROR_FORMAT("{} couldn't be opened.", _stagingAreaDirectory);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -218,7 +216,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(conf().directories().staging, file));
|
||||
auto name = GameObjects::Mass::getNameFromFile(Utility::Path::join(_stagingAreaDirectory, file));
|
||||
|
||||
if(name) {
|
||||
LOG_INFO_FORMAT("Found staged M.A.S.S.: {}", *name);
|
||||
|
@ -234,11 +232,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(conf().directories().staging, filename));
|
||||
bool file_exists = Utility::Path::exists(Utility::Path::join(_stagingAreaDirectory, filename));
|
||||
auto it = _stagedMasses.find(filename);
|
||||
|
||||
if(file_exists) {
|
||||
auto name = GameObjects::Mass::getNameFromFile(Utility::Path::join(conf().directories().staging, filename));
|
||||
auto name = GameObjects::Mass::getNameFromFile(Utility::Path::join(_stagingAreaDirectory, filename));
|
||||
if(name) {
|
||||
_stagedMasses[filename] = *name;
|
||||
}
|
||||
|
@ -259,7 +257,7 @@ MassManager::deleteStagedMass(Containers::StringView filename) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if(!Utility::Path::remove(Utility::Path::join(conf().directories().staging, filename))) {
|
||||
if(!Utility::Path::remove(Utility::Path::join(_stagingAreaDirectory, 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 account, bool demo);
|
||||
MassManager(Containers::StringView save_path, Containers::StringView account, bool demo, Containers::StringView staging_dir);
|
||||
|
||||
auto lastError() -> Containers::StringView;
|
||||
|
||||
|
@ -50,6 +50,7 @@ class MassManager {
|
|||
bool deleteStagedMass(Containers::StringView filename);
|
||||
|
||||
private:
|
||||
Containers::StringView _saveDirectory;
|
||||
Containers::StringView _account;
|
||||
bool _demo;
|
||||
|
||||
|
@ -57,6 +58,8 @@ class MassManager {
|
|||
|
||||
Containers::StaticArray<32, GameObjects::Mass> _hangars{NoInit};
|
||||
|
||||
Containers::StringView _stagingAreaDirectory;
|
||||
|
||||
std::map<Containers::String, Containers::String> _stagedMasses;
|
||||
};
|
||||
|
||||
|
|
|
@ -14,7 +14,10 @@
|
|||
// 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>
|
||||
|
@ -22,6 +25,8 @@
|
|||
#include <Corrade/Utility/Path.h>
|
||||
#include <Corrade/Utility/String.h>
|
||||
|
||||
#include <zip.h>
|
||||
|
||||
#include "../Configuration/Configuration.h"
|
||||
#include "../Logger/Logger.h"
|
||||
|
||||
|
@ -98,8 +103,6 @@ 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