2021-06-11 19:24:52 +02:00
|
|
|
// MassBuilderSaveTool
|
2022-01-30 11:36:56 +01:00
|
|
|
// Copyright (C) 2021-2022 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-03-27 22:09:56 +02:00
|
|
|
#ifndef SAVETOOL_DEBUG_BUILD
|
2021-06-20 13:39:43 +02:00
|
|
|
#include <fstream>
|
2022-03-27 22:09:56 +02:00
|
|
|
#endif
|
2021-06-20 13:39:43 +02:00
|
|
|
|
2021-07-28 15:17:46 +02:00
|
|
|
#include <errhandlingapi.h>
|
|
|
|
#include <synchapi.h>
|
|
|
|
#include <winerror.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 09:50:43 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-11-21 09:30:13 +01:00
|
|
|
#ifndef SAVETOOL_DEBUG_BUILD
|
2022-03-30 14:18:23 +02:00
|
|
|
std::ofstream output{"SaveToolLog.txt", std::ios::trunc|std::ios::out};
|
|
|
|
|
|
|
|
Utility::Debug d{&output};
|
|
|
|
Utility::Warning w{&output};
|
|
|
|
Utility::Error e{&output};
|
2022-11-21 09:30:13 +01:00
|
|
|
#else
|
2022-03-30 14:18:23 +02:00
|
|
|
Utility::Warning w{Utility::Debug::defaultOutput()};
|
|
|
|
Utility::Error e{Utility::Debug::defaultOutput()};
|
2022-11-21 09:30:13 +01:00
|
|
|
#endif
|
2022-03-30 14:18:23 +02:00
|
|
|
|
2022-11-21 09:30:38 +01:00
|
|
|
Utility::Debug{} << "M.A.S.S. Builder Save Tool version " SAVETOOL_VERSION;
|
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 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 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-03-30 14:18:23 +02:00
|
|
|
Utility::Debug{} << "===Initialising OpenGL renderer===";
|
2021-06-20 13:39:43 +02:00
|
|
|
SaveTool app({argc, argv});
|
2021-07-28 15:17:46 +02:00
|
|
|
Int result = app.exec();
|
|
|
|
|
|
|
|
ReleaseMutex(mutex_handle);
|
|
|
|
|
|
|
|
return result;
|
2021-06-20 13:39:43 +02:00
|
|
|
}
|