MassBuilderSaveTool/src/main.cpp
William JCM 9c074c24bd Update coding style.
Magnum's type names are fine, but I'd rather limit what depends on
Magnum as much as possible. Vector types are still allowed, though. No
way I'll write my own.
2023-01-13 10:02:29 +01:00

89 lines
3.3 KiB
C++

// 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 <SDL_messagebox.h>
#include <cpuid.h>
#include <errhandlingapi.h>
#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};
logger().initialise();
LOG_INFO("Initialising M.A.S.S. Builder Save Tool version " SAVETOOL_VERSION ".");
auto str = setlocale(LC_ALL, ".utf-8");
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;
}
}
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;
}
std::uint32_t brand[12];
if (!__get_cpuid_max(0x80000004, nullptr)) {
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);
LOG_INFO_FORMAT("Processor: {}", Containers::arrayCast<const char>(brand).data());
}
SaveTool app({argc, argv});
int result = app.exec();
ReleaseMutex(mutex_handle);
return result;
}