2021-06-11 19:24:52 +02:00
|
|
|
// MassBuilderSaveTool
|
2023-09-02 18:30:29 +02:00
|
|
|
// Copyright (C) 2021-2023 Guillaume Jacquemin
|
2021-06-11 19:24:52 +02:00
|
|
|
//
|
|
|
|
// 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/>.
|
|
|
|
|
2022-11-21 09:51:21 +01:00
|
|
|
#include <SDL_messagebox.h>
|
|
|
|
|
|
|
|
#include <cpuid.h>
|
|
|
|
|
2021-07-28 15:17:46 +02:00
|
|
|
#include <errhandlingapi.h>
|
|
|
|
#include <synchapi.h>
|
|
|
|
#include <winerror.h>
|
|
|
|
|
2023-08-31 12:34:34 +02:00
|
|
|
#include "Configuration/Configuration.h"
|
2022-11-21 10:17:13 +01:00
|
|
|
#include "Logger/MagnumLogBuffer.h"
|
2022-11-21 09:48:33 +01:00
|
|
|
#include "SaveTool/SaveTool.h"
|
|
|
|
|
2021-06-20 13:39:43 +02:00
|
|
|
int main(int argc, char** argv) {
|
2022-11-21 10:17:13 +01:00
|
|
|
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};
|
|
|
|
|
2022-11-25 17:10:26 +01:00
|
|
|
logger().initialise();
|
|
|
|
|
2023-10-29 10:40:02 +01:00
|
|
|
LOG_INFO("Initialising M.A.S.S. Builder Save Tool version " SAVETOOL_VERSION_STRING ".");
|
2022-11-21 10:17:13 +01:00
|
|
|
|
2022-11-26 11:30:48 +01:00
|
|
|
auto str = setlocale(LC_ALL, ".utf-8");
|
2022-11-21 10:17:13 +01:00
|
|
|
if(str) {
|
|
|
|
Containers::StringView locale{str};
|
|
|
|
LOG_INFO_FORMAT("Current locale: {}", locale);
|
|
|
|
|
2023-08-28 13:51:32 +02:00
|
|
|
if(!locale.hasSuffix(".utf8") && !locale.hasSuffix(".65001")) {
|
2022-11-21 10:17:13 +01:00
|
|
|
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error",
|
|
|
|
"Your system doesn't support UTF-8.", nullptr);
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2023-08-31 12:34:34 +02:00
|
|
|
|
|
|
|
if(locale.hasSuffix(".65001")) {
|
|
|
|
LOG_INFO("Wine detected.");
|
|
|
|
conf().setRunningInWine(true);
|
|
|
|
}
|
2022-11-21 09:50:43 +01:00
|
|
|
}
|
|
|
|
|
2022-03-30 14:18:23 +02:00
|
|
|
auto mutex_handle = CreateMutexW(nullptr, 0, L"MassBuilderSaveTool");
|
2021-07-28 15:17:46 +02:00
|
|
|
|
|
|
|
if(!mutex_handle) {
|
2022-11-21 10:17:13 +01:00
|
|
|
LOG_ERROR_FORMAT("Error initialising the instance checker. GetLastError() returned {}.", GetLastError());
|
2022-11-21 09:47:21 +01:00
|
|
|
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error",
|
|
|
|
"There was an error initialising the single-instance checker.",nullptr);
|
2021-07-28 15:17:46 +02:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(GetLastError() == ERROR_ALREADY_EXISTS) {
|
2022-11-21 10:17:13 +01:00
|
|
|
LOG_ERROR("Another instance of the application was detected.");
|
2022-11-21 09:47:21 +01:00
|
|
|
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error",
|
2021-07-28 15:17:46 +02:00
|
|
|
"There can be only one running instance of the application.",nullptr);
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2022-11-21 09:51:21 +01:00
|
|
|
std::uint32_t brand[12];
|
|
|
|
|
|
|
|
if (!__get_cpuid_max(0x80000004, nullptr)) {
|
2022-11-21 10:17:13 +01:00
|
|
|
LOG_WARNING("CPUID features not supported. Can't get the current processor's model.");
|
2022-11-21 09:51:21 +01:00
|
|
|
}
|
|
|
|
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);
|
2022-11-21 10:17:13 +01:00
|
|
|
LOG_INFO_FORMAT("Processor: {}", Containers::arrayCast<const char>(brand).data());
|
2022-11-21 09:51:21 +01:00
|
|
|
}
|
|
|
|
|
2021-06-20 13:39:43 +02:00
|
|
|
SaveTool app({argc, argv});
|
2022-12-05 11:32:18 +01:00
|
|
|
int result = app.exec();
|
2021-07-28 15:17:46 +02:00
|
|
|
|
|
|
|
ReleaseMutex(mutex_handle);
|
|
|
|
|
|
|
|
return result;
|
2021-06-20 13:39:43 +02:00
|
|
|
}
|