Compare commits

..

6 commits

Author SHA1 Message Date
bd360b9268
CMakeLists: reorganise how system deps are handled.
Allowing each dependency to be system-wide or not is gonna be an
improvement, especially when it comes to IDE memory usage.
2024-04-07 15:40:45 +02:00
35c96af509
CMakeLists: reorder lines for consistency. 2024-04-07 15:20:47 +02:00
3ffac15c26
CMakeLists: add new common variable for dependencies. 2024-04-07 15:20:03 +02:00
c48165614a
CMakeLists: remove an unnecessary option.
Logger doesn't output coloured text to the console anymore. As a
result, we don't need to tell Corrade to use ANSI colour codes on
Windows anymore.
2024-04-07 15:11:33 +02:00
1db00ba892
Logger: add a missing string view operator. 2024-04-07 15:10:52 +02:00
8ecd1922f1
Utilities: add temp file management functions. 2024-03-30 23:47:04 +01:00
7 changed files with 188 additions and 20 deletions

View file

@ -23,23 +23,21 @@ set(ZLIB_USE_STATIC_LIBS ON CACHE BOOL "" FORCE) # Required on setups where zlib
option(SAVETOOL_USE_SYSTEM_LIBS "Use system-wide versions of the dependencies instead of the versions provided by submodules." OFF)
include(CMakeDependentOption)
cmake_dependent_option(SAVETOOL_USE_SYSTEM_CORRADE_MAGNUM "Use system-wide versions of Corrade and Magnum." ON "SAVETOOL_USE_SYSTEM_LIBS" OFF)
cmake_dependent_option(SAVETOOL_USE_SYSTEM_SDL2 "Use a system-wide version of SDL2." ON "SAVETOOL_USE_SYSTEM_LIBS" OFF)
cmake_dependent_option(SAVETOOL_USE_SYSTEM_LIBZIP "Use a system-wide version of libzip." 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)
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(NOT SAVETOOL_USE_SYSTEM_LIBS)
set(CORRADE_BUILD_DEPRECATED OFF CACHE BOOL "" FORCE)
set(CORRADE_BUILD_STATIC ON CACHE BOOL "" FORCE)
set(CORRADE_BUILD_STATIC_PIC ON CACHE BOOL "" FORCE)
set(CORRADE_BUILD_STATIC_UNIQUE_GLOBALS OFF CACHE BOOL "" FORCE)
set(CORRADE_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(CORRADE_WITH_INTERCONNECT OFF CACHE BOOL "" FORCE)
set(CORRADE_WITH_PLUGINMANAGER OFF CACHE BOOL "" FORCE)
set(CORRADE_WITH_TESTSUITE OFF CACHE BOOL "" FORCE)
set(CORRADE_WITH_MAIN ON CACHE BOOL "" FORCE)
set(CORRADE_UTILITY_USE_ANSI_COLORS ON CACHE BOOL "" FORCE)
add_subdirectory(third-party/corrade EXCLUDE_FROM_ALL)
if(NOT SAVETOOL_USE_SYSTEM_SDL2)
set(DIRECTX OFF CACHE BOOL "" FORCE) # We use OpenGL.
set(SDL_ATOMIC OFF CACHE BOOL "" FORCE)
set(SDL_CPUINFO OFF CACHE BOOL "" FORCE)
@ -55,6 +53,19 @@ if(NOT SAVETOOL_USE_SYSTEM_LIBS)
set(SDL_TIMERS ON CACHE BOOL "" FORCE)
set(SDL_SHARED OFF CACHE BOOL "" FORCE)
add_subdirectory(third-party/SDL EXCLUDE_FROM_ALL)
endif(NOT SAVETOOL_USE_SYSTEM_SDL2)
if(NOT SAVETOOL_USE_SYSTEM_CORRADE_MAGNUM)
set(CORRADE_BUILD_DEPRECATED OFF CACHE BOOL "" FORCE)
set(CORRADE_BUILD_STATIC ON CACHE BOOL "" FORCE)
set(CORRADE_BUILD_STATIC_PIC ON CACHE BOOL "" FORCE)
set(CORRADE_BUILD_STATIC_UNIQUE_GLOBALS OFF CACHE BOOL "" FORCE)
set(CORRADE_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(CORRADE_WITH_INTERCONNECT OFF CACHE BOOL "" FORCE)
set(CORRADE_WITH_PLUGINMANAGER OFF CACHE BOOL "" FORCE)
set(CORRADE_WITH_TESTSUITE OFF CACHE BOOL "" FORCE)
set(CORRADE_WITH_MAIN ON CACHE BOOL "" FORCE)
add_subdirectory(third-party/corrade EXCLUDE_FROM_ALL)
set(MAGNUM_BUILD_STATIC ON CACHE BOOL "" FORCE)
set(MAGNUM_BUILD_STATIC_PIC ON CACHE BOOL "" FORCE)
@ -85,7 +96,9 @@ if(NOT SAVETOOL_USE_SYSTEM_LIBS)
set(IMGUI_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third-party/imgui)
set(MAGNUM_WITH_IMGUI ON CACHE BOOL "" FORCE)
add_subdirectory(third-party/magnum-integration EXCLUDE_FROM_ALL)
endif(NOT SAVETOOL_USE_SYSTEM_CORRADE_MAGNUM)
if(NOT SAVETOOL_USE_SYSTEM_LIBZIP)
set(ENABLE_COMMONCRYPTO OFF CACHE BOOL "" FORCE)
set(ENABLE_GNUTLS OFF CACHE BOOL "" FORCE)
set(ENABLE_MBEDTLS OFF CACHE BOOL "" FORCE)
@ -99,12 +112,16 @@ if(NOT SAVETOOL_USE_SYSTEM_LIBS)
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(BUILD_DOC OFF CACHE BOOL "" FORCE)
add_subdirectory(third-party/libzip EXCLUDE_FROM_ALL)
endif(NOT SAVETOOL_USE_SYSTEM_LIBZIP)
if(NOT SAVETOOL_USE_SYSTEM_EFSW)
set(VERBOSE OFF CACHE BOOL "" FORCE)
set(BUILD_TEST_APP OFF CACHE BOOL "" FORCE)
set(EFSW_INSTALL OFF CACHE BOOL "" FORCE)
add_subdirectory(third-party/efsw EXCLUDE_FROM_ALL)
endif(NOT SAVETOOL_USE_SYSTEM_EFSW)
if(NOT SAVETOOL_USE_SYSTEM_LIBCURL)
set(BUILD_CURL_EXE OFF CACHE BOOL "" FORCE)
set(ENABLE_UNICODE ON CACHE BOOL "" FORCE)
set(ENABLE_INET_PTON OFF CACHE BOOL "" FORCE)
@ -118,6 +135,6 @@ if(NOT SAVETOOL_USE_SYSTEM_LIBS)
set(CURL_USE_SCHANNEL ON CACHE BOOL "" FORCE)
set(CURL_USE_LIBSSH2 OFF CACHE BOOL "" FORCE) # For some reason, even when HTTP_ONLY is set to ON, libcurl will try to link to libssh2.
add_subdirectory(third-party/curl EXCLUDE_FROM_ALL)
endif(NOT SAVETOOL_USE_SYSTEM_LIBS)
endif(NOT SAVETOOL_USE_SYSTEM_LIBCURL)
add_subdirectory(src)

View file

@ -26,11 +26,18 @@ if(CORRADE_TARGET_WINDOWS)
endif()
find_package(Magnum REQUIRED GL Sdl2Application)
find_package(MagnumIntegration REQUIRED ImGui)
if(SAVETOOL_USE_SYSTEM_LIBS)
find_package(CURL REQUIRED HTTPS)
if(SAVETOOL_USE_SYSTEM_LIBZIP)
find_package(libzip REQUIRED)
endif(SAVETOOL_USE_SYSTEM_LIBZIP)
if(SAVETOOL_USE_SYSTEM_EFSW)
find_package(efsw REQUIRED)
endif()
endif(SAVETOOL_USE_SYSTEM_EFSW)
if(SAVETOOL_USE_SYSTEM_LIBCURL)
find_package(CURL REQUIRED HTTPS)
endif(SAVETOOL_USE_SYSTEM_LIBCURL)
set_directory_properties(PROPERTIES CORRADE_USE_PEDANTIC_FLAGS ON)
@ -201,6 +208,8 @@ add_executable(MassBuilderSaveTool
UpdateChecker/UpdateChecker.cpp
Utilities/Crc32.h
Utilities/Crc32.cpp
Utilities/Temp.h
Utilities/Temp.cpp
Version/Version.h
Version/Version.cpp
${Logger_SOURCES}
@ -245,10 +254,16 @@ target_link_libraries(MassBuilderSaveTool PRIVATE
CURL::libcurl_static
)
if(SAVETOOL_USE_SYSTEM_LIBS)
target_link_libraries(MassBuilderSaveTool PRIVATE libzip::zip efsw::efsw)
if(SAVETOOL_USE_SYSTEM_LIBZIP)
target_link_libraries(MassBuilderSaveTool PRIVATE libzip::zip)
else()
target_link_libraries(MassBuilderSaveTool PRIVATE zip efsw)
target_link_libraries(MassBuilderSaveTool PRIVATE zip)
endif()
if(SAVETOOL_USE_SYSTEM_EFSW)
target_link_libraries(MassBuilderSaveTool PRIVATE efsw::efsw)
else()
target_link_libraries(MassBuilderSaveTool PRIVATE efsw)
endif()
if(CORRADE_TARGET_WINDOWS)

View file

@ -25,6 +25,7 @@
#include <shlobj.h>
#include "../Logger/Logger.h"
#include "../Utilities/Temp.h"
#include "Configuration.h"
@ -123,6 +124,7 @@ Configuration::Configuration() {
_directories.armours = Utility::Path::join(armoury_dir, "armours");
_directories.weapons = Utility::Path::join(armoury_dir, "weapons");
_directories.styles = Utility::Path::join(armoury_dir, "styles");
_directories.temp = Utility::Path::join(executable_location, "temp");
if(!Utility::Path::exists(_directories.backups)) {
LOG_WARNING("Backups directory not found, creating...");
@ -160,6 +162,17 @@ Configuration::Configuration() {
}
}
if(!Utility::Path::exists(_directories.temp)) {
LOG_WARNING("Temporary directory not found, creating...");
if(!Utility::Path::make(_directories.temp)) {
LOG_ERROR(_lastError = "Couldn't create the temporary directory.");
return;
}
}
else {
Utilities::emptyTempDir();
}
_valid = true;
}

View file

@ -64,6 +64,7 @@ class Configuration {
Containers::String armours;
Containers::String weapons;
Containers::String styles;
Containers::String temp;
};
auto directories() const -> Directories const&;

View file

@ -85,7 +85,7 @@ Logger::log(EntryType type, StringView location, StringView message) {
break;
}
d << "["_s << Debug::nospace << location << Debug::nospace << "]";
d << "["_s << Debug::nospace << location << Debug::nospace << "]"_s;
for(auto i = 0u; i < _indentLevel; i++) {
d << Debug::nospace << " "_s << Debug::nospace;

88
src/Utilities/Temp.cpp Normal file
View file

@ -0,0 +1,88 @@
// MassBuilderSaveTool
// Copyright (C) 2021-2024 Guillaume Jacquemin
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// 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 <Corrade/Containers/Array.h>
#include <Corrade/Containers/Pair.h>
#include <Corrade/Utility/Path.h>
#include "../Configuration/Configuration.h"
#include "../Logger/Logger.h"
#include "Temp.h"
namespace mbst { namespace Utilities {
Containers::String
getTempPath(Containers::StringView filename) {
return Utility::Path::join(conf().directories().temp, filename);
}
Containers::Optional<Containers::String>
copyToTemp(Containers::StringView path) {
auto filename = Utility::Path::split(path).first();
auto dest = Utility::Path::join(conf().directories().temp, filename);
if(!Utility::Path::copy(path, dest)) {
LOG_ERROR_FORMAT("Couldn't copy {} to {}.", path, conf().directories().temp);
return Containers::NullOpt;
}
return Utility::move(dest);
}
Containers::Optional<Containers::String>
moveToTemp(Containers::StringView path) {
auto filename = Utility::Path::split(path).first();
auto dest = Utility::Path::join(conf().directories().temp, filename);
if(!Utility::Path::move(path, dest)) {
LOG_ERROR_FORMAT("Couldn't move {} to {}.", path, conf().directories().temp);
return Containers::NullOpt;
}
return Utility::move(dest);
}
bool
moveFromTemp(Containers::StringView filename, Containers::StringView destination) {
auto source = Utility::Path::join(conf().directories().temp, filename);
auto dest = Utility::Path::join(destination, filename);
if(!Utility::Path::move(source, dest)) {
LOG_ERROR_FORMAT("Couldn't move {} to {}.", filename, destination);
return false;
}
return true;
}
bool
deleteTempFile(Containers::StringView filename) {
return Utility::Path::remove(Utility::Path::join(conf().directories().temp, filename));
}
void
emptyTempDir() {
using Flag = Utility::Path::ListFlag;
auto files = Utility::Path::list(conf().directories().temp, Flag::SkipDirectories|Flag::SkipSpecial);
CORRADE_INTERNAL_ASSERT(files);
for(auto& filename : *files) {
deleteTempFile(filename);
}
}
}}

34
src/Utilities/Temp.h Normal file
View file

@ -0,0 +1,34 @@
#pragma once
// MassBuilderSaveTool
// Copyright (C) 2021-2024 Guillaume Jacquemin
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// 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 <Corrade/Containers/Optional.h>
#include <Corrade/Containers/String.h>
#include <Corrade/Containers/StringView.h>
using namespace Corrade;
namespace mbst { namespace Utilities {
auto getTempPath(Containers::StringView filename) -> Containers::String;
auto copyToTemp(Containers::StringView path) -> Containers::Optional<Containers::String>;
auto moveToTemp(Containers::StringView path) -> Containers::Optional<Containers::String>;
bool moveFromTemp(Containers::StringView filename, Containers::StringView destination);
bool deleteTempFile(Containers::StringView filename);
void emptyTempDir();
}}