Compare commits

...

3 Commits

8 changed files with 334 additions and 28 deletions

View File

@ -28,6 +28,19 @@ set_directory_properties(PROPERTIES CORRADE_USE_PEDANTIC_FLAGS ON)
corrade_add_resource(Assets assets.conf)
add_library(Logger STATIC EXCLUDE_FROM_ALL
Logger/Logger.h
Logger/Logger.cpp
Logger/EntryType.h
Logger/MagnumLogBuffer.h
Logger/MagnumLogBuffer.cpp
)
target_link_libraries(Logger PRIVATE
Corrade::Utility
Magnum::Magnum
)
add_library(UESaveFile STATIC EXCLUDE_FROM_ALL
UESaveFile/Serialisers/AbstractUnrealCollectionPropertySerialiser.h
UESaveFile/Serialisers/AbstractUnrealPropertySerialiser.h
@ -108,6 +121,7 @@ target_link_libraries(UESaveFile PRIVATE
Corrade::Containers
Corrade::Utility
Magnum::Magnum
Logger
)
add_executable(MassBuilderSaveTool WIN32
@ -196,6 +210,7 @@ target_link_libraries(MassBuilderSaveTool PRIVATE
Magnum::GL
Magnum::Sdl2Application
MagnumIntegration::ImGui
Logger
UESaveFile
efsw
zip

23
src/Logger/EntryType.h Normal file
View File

@ -0,0 +1,23 @@
#pragma once
// MassBuilderSaveTool
// Copyright (C) 2021-2022 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/>.
enum class EntryType {
Info,
Warning,
Error,
};

118
src/Logger/Logger.cpp Normal file
View File

@ -0,0 +1,118 @@
// MassBuilderSaveTool
// Copyright (C) 2021-2022 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/>.
#ifdef SAVETOOL_DEBUG_BUILD
#include <iostream>
#endif
#include <mutex>
#include <Corrade/Containers/GrowableArray.h>
#include <Corrade/Utility/Debug.h>
#include <Magnum/Types.h>
#include "Logger.h"
using Containers::Array;
using Utility::Debug;
using Utility::Warning;
using Utility::Error;
using namespace Magnum;
Logger&
Logger::instance() {
static Logger logger;
return logger;
}
void
Logger::initialise() {
#ifndef SAVETOOL_DEBUG_BUILD
_logFile.open("SaveToolLog.txt", std::ios::trunc);
_logFile << "In case you encounter a bug:\n" <<
"1. Do not run the Save Tool again, as this log will be cleared.\n" <<
"2. Go to either the official Sekai Project Discord guild, or the community M.A.S.S. Builder one.\n" <<
"3. Mention me (William JCM#2301) to get my attention, with a description of the bug.\n"
" Please include as many details as possible, I don't want to play \"20 questions\", and neither do you.\n" <<
"4. Send me this file _when I ask for it_, preferably in DMs.\n" <<
std::endl;
#endif
}
void
Logger::indent() {
_indentLevel++;
}
void
Logger::unindent() {
if(_indentLevel > 0) {
_indentLevel--;
}
}
void
Logger::log(EntryType type, StringView location, StringView message) {
Debug d{
#ifndef SAVETOOL_DEBUG_BUILD
&_logFile
#else
&std::cout
#endif
};
#ifdef SAVETOOL_DEBUG_BUILD
#define COLOURED_TEXT(colour, text) Debug::color(Debug::Color::colour) << (text) << Debug::resetColor
#else
#define COLOURED_TEXT(colour, text) (text)
#endif
switch(type) {
case EntryType::Info:
d << COLOURED_TEXT(Default, "[ INFO]"_s);
break;
case EntryType::Warning:
d << COLOURED_TEXT(Yellow, "[WARNING]"_s);
break;
case EntryType::Error:
d << COLOURED_TEXT(Red, "[ ERROR]"_s);
break;
}
#undef COLOURED_TEXT
d << "["_s << Debug::nospace << location << Debug::nospace << "]";
for(UnsignedInt i = 0; i < _indentLevel; i++) {
d << Debug::nospace << " "_s << Debug::nospace;
}
d << ((message.back() == '\n') ? message.exceptSuffix(1) : message);
}
void
Logger::lockMutex() {
_logMutex.lock();
}
void
Logger::unlockMutex() {
_logMutex.unlock();
}
Logger&
logger() {
return Logger::instance();
}

88
src/Logger/Logger.h Normal file
View File

@ -0,0 +1,88 @@
#pragma once
// MassBuilderSaveTool
// Copyright (C) 2021-2022 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 <ctime>
#include <mutex>
#include <fstream>
#include <Corrade/Containers/String.h>
#include <Corrade/Containers/ArrayView.h>
#include <Corrade/Utility/Format.h>
#include <Magnum/Types.h>
#include "EntryType.h"
using namespace Corrade;
using Containers::ArrayView;
using Containers::String;
using Containers::StringView;
using namespace Magnum;
using namespace Containers::Literals;
class Logger {
public:
Logger(const Logger&) = delete;
Logger& operator=(const Logger&) = delete;
Logger(Logger&&) = delete;
Logger& operator=(Logger&&) = delete;
static auto instance() -> Logger&;
void initialise();
void indent();
void unindent();
void log(EntryType type, StringView location, StringView message);
void lockMutex();
void unlockMutex();
private:
Logger() = default;
#ifndef SAVETOOL_DEBUG_BUILD
std::ofstream _logFile;
#endif
UnsignedInt _indentLevel = 0;
std::mutex _logMutex{};
};
auto logger() -> Logger&;
#define LOG(entry_type, message) logger().lockMutex(); \
logger().log(EntryType::entry_type, \
Utility::format("{}:{}", StringView{__builtin_FILE()}.find("src"_s).data() + 4, __builtin_LINE()), \
message); \
logger().unlockMutex()
#define LOG_INFO(message) LOG(Info, message)
#define LOG_WARNING(message) LOG(Warning, message)
#define LOG_ERROR(message) LOG(Error, message)
#define LOG_INFO_FORMAT(message, ...) LOG_INFO(Utility::format(message, __VA_ARGS__))
#define LOG_WARNING_FORMAT(message, ...) LOG_WARNING(Utility::format(message, __VA_ARGS__))
#define LOG_ERROR_FORMAT(message, ...) LOG_ERROR(Utility::format(message, __VA_ARGS__))

View File

@ -0,0 +1,30 @@
// MassBuilderSaveTool
// Copyright (C) 2021-2022 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 "MagnumLogBuffer.h"
MagnumLogBuffer::MagnumLogBuffer(EntryType type): std::stringbuf(std::ios_base::out), _type{type} {}
MagnumLogBuffer::~MagnumLogBuffer() = default;
int
MagnumLogBuffer::sync() {
logger().lockMutex();
logger().log(_type, "Corrade/Magnum"_s, str().c_str());
logger().unlockMutex();
str({});
return 0;
}

View File

@ -0,0 +1,34 @@
#pragma once
// MassBuilderSaveTool
// Copyright (C) 2021-2022 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 <sstream>
#include "Logger.h"
#include "EntryType.h"
class MagnumLogBuffer : public std::stringbuf {
public:
explicit MagnumLogBuffer(EntryType type);
~MagnumLogBuffer();
private:
int sync() override;
EntryType _type;
};

View File

@ -23,15 +23,10 @@
#include "../UESaveFile/Types/ArrayProperty.h"
#include "../UESaveFile/Types/BoolProperty.h"
#include "../UESaveFile/Types/ByteProperty.h"
#include "../UESaveFile/Types/ColourStructProperty.h"
#include "../UESaveFile/Types/FloatProperty.h"
#include "../UESaveFile/Types/GenericStructProperty.h"
#include "../UESaveFile/Types/IntProperty.h"
#include "../UESaveFile/Types/RotatorStructProperty.h"
#include "../UESaveFile/Types/StringProperty.h"
#include "../UESaveFile/Types/VectorStructProperty.h"
#include "../UESaveFile/Types/Vector2DStructProperty.h"
#include "Mass.h"

View File

@ -14,10 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef SAVETOOL_DEBUG_BUILD
#include <fstream>
#endif
#include <SDL_messagebox.h>
#include <cpuid.h>
@ -26,38 +22,45 @@
#include <synchapi.h>
#include <winerror.h>
#include "Logger/MagnumLogBuffer.h"
#include "SaveTool/SaveTool.h"
int main(int argc, char** argv) {
MagnumLogBuffer debug_intercept_buffer{EntryType::Info};
MagnumLogBuffer warning_intercept_buffer{EntryType::Warning};
MagnumLogBuffer error_intercept_buffer{EntryType::Error};
std::ostream debug_intercept_stream{&debug_intercept_buffer};
std::ostream warning_intercept_stream{&warning_intercept_buffer};
std::ostream error_intercept_stream{&error_intercept_buffer};
Debug debug_intercept{&debug_intercept_stream};
Warning warning_intercept{&warning_intercept_stream};
Error error_intercept{&error_intercept_stream};
LOG_INFO("M.A.S.S. Builder Save Tool version " SAVETOOL_VERSION);
auto str = std::setlocale(LC_ALL, ".utf-8");
if(str && !Containers::StringView{str}.hasSuffix(".utf8")) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error",
"Your system doesn't support UTF-8.", nullptr);
return EXIT_FAILURE;
if(str) {
Containers::StringView locale{str};
LOG_INFO_FORMAT("Current locale: {}", locale);
if(!locale.hasSuffix(".utf8")) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error",
"Your system doesn't support UTF-8.", nullptr);
return EXIT_FAILURE;
}
}
#ifndef SAVETOOL_DEBUG_BUILD
std::ofstream output{"SaveToolLog.txt", std::ios::trunc|std::ios::out};
Utility::Debug d{&output};
Utility::Warning w{&output};
Utility::Error e{&output};
#else
Utility::Warning w{Utility::Debug::defaultOutput()};
Utility::Error e{Utility::Debug::defaultOutput()};
#endif
Utility::Debug{} << "M.A.S.S. Builder Save Tool version " SAVETOOL_VERSION;
auto mutex_handle = CreateMutexW(nullptr, 0, L"MassBuilderSaveTool");
if(!mutex_handle) {
LOG_ERROR_FORMAT("Error initialising the instance checker. GetLastError() returned {}.", GetLastError());
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error",
"There was an error initialising the single-instance checker.",nullptr);
return EXIT_FAILURE;
}
if(GetLastError() == ERROR_ALREADY_EXISTS) {
LOG_ERROR("Another instance of the application was detected.");
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error",
"There can be only one running instance of the application.",nullptr);
return EXIT_FAILURE;
@ -66,13 +69,13 @@ int main(int argc, char** argv) {
std::uint32_t brand[12];
if (!__get_cpuid_max(0x80000004, nullptr)) {
Utility::Warning{} << "Warning: CPUID features not supported. Can't get the current processor's model.";
LOG_WARNING("CPUID features not supported. Can't get the current processor's model.");
}
else {
__get_cpuid(0x80000002, brand+0x0, brand+0x1, brand+0x2, brand+0x3);
__get_cpuid(0x80000003, brand+0x4, brand+0x5, brand+0x6, brand+0x7);
__get_cpuid(0x80000004, brand+0x8, brand+0x9, brand+0xa, brand+0xb);
Utility::Debug{} << "Processor:" << Containers::arrayCast<const char>(brand).data();
LOG_INFO_FORMAT("Processor: {}", Containers::arrayCast<const char>(brand).data());
}
SaveTool app({argc, argv});