Compare commits

..

No commits in common. "83e9169dae95a97c9b81955116ecf23fcb2d8873" and "1421257c4f49b81bc4fdd9c9a4a99635a1c07b9b" have entirely different histories.

5 changed files with 53 additions and 69 deletions

View File

@ -203,22 +203,22 @@ void MassManager::refreshStagedMasses() {
auto list_view = file_list->exceptSuffix(file_list->end() - iter);
LOG_INFO("Scanning for staged M.A.S.S.es...");
Utility::Debug{} << "Scanning for staged M.A.S.S.es...";
for(Containers::StringView file : list_view) {
auto name = Mass::getNameFromFile(Utility::Path::join(_stagingAreaDirectory, file));
if(name) {
LOG_INFO_FORMAT("Found staged M.A.S.S.: {}", *name);
Utility::Debug{} << "Found staged M.A.S.S.:" << *name;
_stagedMasses[file] = *name;
}
else {
LOG_WARNING_FORMAT("Skipped {}.", file);
Utility::Warning{} << "Skipped:" << file;
}
}
}
void MassManager::refreshStagedMass(Containers::StringView filename) {
LOG_INFO_FORMAT("Refreshing staged unit with filename {}.", filename);
Utility::Debug{} << "Refreshing staged unit with filename" << filename;
bool file_exists = Utility::Path::exists(Utility::Path::join(_stagingAreaDirectory, filename));
auto it = _stagedMasses.find(filename);

View File

@ -35,7 +35,6 @@
#include <wtsapi32.h>
#include "../FontAwesome/IconsFontAwesome5.h"
#include "../Logger/Logger.h"
using namespace Containers::Literals;
@ -54,7 +53,6 @@ SaveTool::SaveTool(const Arguments& arguments):
tweak.enable(""_s, "../../"_s);
#endif
LOG_INFO("Configuring OpenGL renderer.");
GL::Renderer::enable(GL::Renderer::Feature::Blending);
GL::Renderer::enable(GL::Renderer::Feature::ScissorTest);
GL::Renderer::disable(GL::Renderer::Feature::FaceCulling);
@ -64,21 +62,25 @@ SaveTool::SaveTool(const Arguments& arguments):
GL::Renderer::setBlendEquation(GL::Renderer::BlendEquation::Add,
GL::Renderer::BlendEquation::Add);
LOG_INFO("Configuring SDL2.");
if(SDL_VERSION_ATLEAST(2, 0, 5)) {
if(SDL_SetHintWithPriority(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1", SDL_HINT_OVERRIDE) == SDL_TRUE) {
LOG_INFO("Clickthrough is enabled.");
Utility::Debug{} << "Renderer initialisation successful.";
Utility::Debug{} << "===Configuring SDL2===";
{
Utility::Debug d{};
d << "Enabling clickthrough...";
if(SDL_VERSION_ATLEAST(2, 0, 5)) {
if(SDL_SetHintWithPriority(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1", SDL_HINT_OVERRIDE) == SDL_TRUE) {
d << "success!"_s;
} else {
d << "error: hint couldn't be set."_s;
}
} else {
d << "error: SDL2 is too old (version < 2.0.5)."_s;
}
else {
LOG_WARNING("Clickthrough is disabled.");
}
}
else {
LOG_WARNING_FORMAT("Clickthrough is disabled: SDL2 version is too old ({}.{}.{})",
SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL);
}
LOG_INFO("Registering custom events.");
if((_initEventId = SDL_RegisterEvents(3)) == UnsignedInt(-1)) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error",
"SDL_RegisterEvents() failed in SaveTool::SaveTool(). Exiting...", window());
@ -89,27 +91,26 @@ SaveTool::SaveTool(const Arguments& arguments):
_updateEventId = _initEventId + 1;
_fileEventId = _initEventId + 2;
LOG_INFO("Initialising the timer subsystem.");
if(SDL_InitSubSystem(SDL_INIT_TIMER) != 0) {
LOG_ERROR(SDL_GetError());
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app",
SDL_GetError(), window());
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app", SDL_GetError(), window());
exit(EXIT_FAILURE);
return;
}
Utility::Debug{} << "SDL2 configuration successful.";
Utility::Debug{} << "===Initialising the Save Tool===";
initialiseGui();
if(!initialiseToolDirectories()) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app",
_lastError.data(), window());
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app", _lastError.data(), window());
exit(EXIT_FAILURE);
return;
}
if(!findGameDataDirectory()) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app",
_lastError.data(), window());
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error initialising the app", _lastError.data(), window());
exit(EXIT_FAILURE);
return;
}
@ -121,7 +122,6 @@ SaveTool::SaveTool(const Arguments& arguments):
return interval;
}, this);
if(_gameCheckTimerId == 0) {
LOG_ERROR(SDL_GetError());
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", SDL_GetError(), window());
exit(EXIT_FAILURE);
return;
@ -138,7 +138,6 @@ SaveTool::SaveTool(const Arguments& arguments):
break;
}
LOG_INFO("Initialising update checker.");
curl_global_init(CURL_GLOBAL_DEFAULT);
if(_checkUpdatesOnStartup) {
_queue.addToast(Toast::Type::Default, "Checking for updates..."_s);
@ -151,6 +150,9 @@ SaveTool::SaveTool(const Arguments& arguments):
GL::DebugOutput::setEnabled(GL::DebugOutput::Source::Api, GL::DebugOutput::Type::Other, {131185}, false);
}
Utility::Debug{} << "Initialisation successful.";
Utility::Debug{} << "===Running main loop===";
if(_skipDisclaimer) {
_uiState = UiState::Initialising;
_initThread = std::thread{[this]{ initialiseManager(); }};
@ -158,14 +160,14 @@ SaveTool::SaveTool(const Arguments& arguments):
}
SaveTool::~SaveTool() {
LOG_INFO("Cleaning up.");
Utility::Debug{} << "===Perfoming cleanup===";
LOG_INFO("Shutting libcurl down.");
Utility::Debug{} << "Shutting libcurl down...";
curl_global_cleanup();
SDL_RemoveTimer(_gameCheckTimerId);
LOG_INFO("Saving the configuration.");
Utility::Debug{} << "Saving the configuration...";
_conf.setValue("cheat_mode"_s, _cheatMode);
_conf.setValue("startup_update_check"_s, _checkUpdatesOnStartup);
@ -184,7 +186,7 @@ SaveTool::~SaveTool() {
_conf.save();
LOG_INFO("Exiting.");
Utility::Debug{} << "Exiting...";
}
void SaveTool::drawEvent() {

View File

@ -26,7 +26,6 @@
#include "../FontAwesome/IconsFontAwesome5.h"
#include "../FontAwesome/IconsFontAwesome5Brands.h"
#include "../Logger/Logger.h"
#include "SaveTool.h"
@ -49,7 +48,7 @@ void SaveTool::initEvent(SDL_Event& event) {
}
void SaveTool::initialiseConfiguration() {
LOG_INFO("Reading configuration file.");
Utility::Debug{} << "Reading configuration file...";
if(_conf.hasValue("cheat_mode"_s)) {
_cheatMode = _conf.value<bool>("cheat_mode"_s);
@ -89,7 +88,7 @@ void SaveTool::initialiseConfiguration() {
}
void SaveTool::initialiseGui() {
LOG_INFO("Initialising Dear ImGui.");
Utility::Debug{} << "Initialising ImGui...";
ImGui::CreateContext();
@ -139,8 +138,6 @@ void SaveTool::initialiseGui() {
}
void SaveTool::initialiseManager() {
LOG_INFO("Initialising the profile manager.");
SDL_Event event;
SDL_zero(event);
event.type = _initEventId;
@ -157,7 +154,7 @@ void SaveTool::initialiseManager() {
}
auto SaveTool::initialiseToolDirectories() -> bool {
LOG_INFO("Initialising Save Tool directories.");
Utility::Debug{} << "Initialising Save Tool directories...";
_backupsDir = Utility::Path::join(Utility::Path::split(*Utility::Path::executableLocation()).first(), "backups");
_stagingDir = Utility::Path::join(Utility::Path::split(*Utility::Path::executableLocation()).first(), "staging");
@ -167,17 +164,17 @@ auto SaveTool::initialiseToolDirectories() -> bool {
//_stylesDir = Utility::Directory::join(_armouryDir, "styles");
if(!Utility::Path::exists(_backupsDir)) {
LOG_WARNING("Backups directory not found, creating...");
Utility::Debug{} << "Backups directory not found, creating...";
if(!Utility::Path::make(_backupsDir)) {
LOG_ERROR(_lastError = "Couldn't create the backups directory.");
Utility::Error{} << (_lastError = "Couldn't create the backups directory.");
return false;
}
}
if(!Utility::Path::exists(_stagingDir)) {
LOG_WARNING("Staging directory not found, creating...");
Utility::Debug{} << "Staging directory not found, creating...";
if(!Utility::Path::make(_stagingDir)) {
LOG_ERROR(_lastError = "Couldn't create the staging directory.");
Utility::Error{} << (_lastError = "Couldn't create the backups directory.");
return false;
}
}
@ -218,21 +215,20 @@ auto SaveTool::initialiseToolDirectories() -> bool {
}
auto SaveTool::findGameDataDirectory() -> bool {
LOG_INFO("Searching for the game's save directory.");
Utility::Debug{} << "Searching for the game's save directory...";
wchar_t* localappdata_path = nullptr;
Containers::ScopeGuard guard{localappdata_path, CoTaskMemFree};
if(SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_NO_APPCONTAINER_REDIRECTION, nullptr, &localappdata_path) != S_OK)
{
_lastError = Utility::format("SHGetKnownFolderPath() failed with error code {}.", GetLastError());
LOG_ERROR(_lastError);
Utility::Error{} << (_lastError = "SHGetKnownFolderPath() failed in SaveTool::findGameDataDirectory()"_s);
return false;
}
_gameDataDir = Utility::Path::join(Utility::Path::fromNativeSeparators(Utility::Unicode::narrow(localappdata_path)), "MASS_Builder"_s);
if(!Utility::Path::exists(_gameDataDir)) {
LOG_ERROR(_lastError = _gameDataDir + " wasn't found. Make sure to play the game at least once."_s);
Utility::Error{} << (_lastError = _gameDataDir + " wasn't found. Make sure to play the game at least once."_s);
return false;
}
@ -244,12 +240,10 @@ auto SaveTool::findGameDataDirectory() -> bool {
}
void SaveTool::initialiseMassManager() {
LOG_INFO("Initialising the M.A.S.S. manager.");
_massManager.emplace(_saveDir, _currentProfile->account(), _currentProfile->isDemo(), _stagingDir);
}
void SaveTool::initialiseFileWatcher() {
LOG_INFO("Initialising the file watcher.");
_fileWatcher.emplace();
_watchIDs[SaveDir] = _fileWatcher->addWatch(_saveDir, this, false);
_watchIDs[StagingDir] = _fileWatcher->addWatch(_stagingDir, this, false);

View File

@ -20,8 +20,6 @@
#include <curl/curl.h>
#include "../Logger/Logger.h"
#include "SaveTool.h"
void SaveTool::updateCheckEvent(SDL_Event& event) {
@ -29,26 +27,20 @@ void SaveTool::updateCheckEvent(SDL_Event& event) {
if(event.user.code == CurlInitFailed) {
_queue.addToast(Toast::Type::Error, "Couldn't initialise libcurl. Update check aborted."_s);
LOG_ERROR("Couldn't initialise libcurl. Update check aborted.");
return;
}
else if(event.user.code == CurlError) {
Containers::String error{static_cast<char*>(event.user.data2), CURL_ERROR_SIZE, nullptr};
_queue.addToast(Toast::Type::Error, error, std::chrono::milliseconds{5000});
_queue.addToast(Toast::Type::Error, static_cast<char*>(event.user.data1),
std::chrono::milliseconds{5000});
LOG_ERROR_FORMAT("{}: {}", static_cast<char*>(event.user.data1), static_cast<char*>(event.user.data2));
_queue.addToast(Toast::Type::Error, static_cast<char*>(event.user.data1), std::chrono::milliseconds{5000});
return;
}
else if(event.user.code == CurlTimeout) {
_queue.addToast(Toast::Type::Error, "The request timed out."_s);
LOG_ERROR("The request timed out.");
return;
}
else if(event.user.code != 200) {
_queue.addToast(Toast::Type::Error,
Utility::format("The request failed with error code {}.", event.user.code));
LOG_ERROR_FORMAT("The request failed with error code {}.", event.user.code);
_queue.addToast(Toast::Type::Error, Utility::format("The request failed with error code {}", event.user.code));
return;
}
@ -79,7 +71,7 @@ void SaveTool::updateCheckEvent(SDL_Event& event) {
bool prerelease = false;
bool operator==(const Version& other) const {
return fullVersion == other.fullVersion && prerelease == other.prerelease;
return fullVersion == other.fullVersion;
}
bool operator>(const Version& other) const {
if((fullVersion > other.fullVersion) ||
@ -98,28 +90,24 @@ void SaveTool::updateCheckEvent(SDL_Event& event) {
static const Version current_ver{SAVETOOL_VERSION};
auto str = static_cast<char*>(event.user.data1);
Containers::String response{str, strlen(str), nullptr};
Containers::String response{static_cast<char*>(event.user.data1), strlen(static_cast<char*>(event.user.data1)), nullptr};
auto components = response.split('\n');
Version latest_ver{components.front()};
if(latest_ver > current_ver) {
_queue.addToast(Toast::Type::Warning,
"Your version is out of date.\nCheck the settings for more information."_s,
_queue.addToast(Toast::Type::Warning, "Your version is out of date.\nCheck the settings for more information."_s,
std::chrono::milliseconds{5000});
_updateAvailable = true;
_latestVersion = Containers::String{latest_ver};
_releaseLink = Utility::format("https://williamjcm.ovh/git/williamjcm/MassBuilderSaveTool/releases/tag/v{}",
components.front());
_releaseLink = Utility::format("https://williamjcm.ovh/git/williamjcm/MassBuilderSaveTool/releases/tag/v{}", components.front());
_downloadLink = components.back();
}
else if(latest_ver == current_ver || (current_ver > latest_ver && current_ver.prerelease)) {
_queue.addToast(Toast::Type::Success, "The application is already up to date."_s);
}
else if(current_ver > latest_ver && !current_ver.prerelease) {
_queue.addToast(Toast::Type::Warning,
"Your version is more recent than the latest one in the repo. How???"_s);
_queue.addToast(Toast::Type::Warning, "Your version is more recent than the latest one in the repo. How???"_s);
}
}
@ -149,7 +137,7 @@ void SaveTool::checkForUpdates() {
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeData);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response_body);
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error_buffer.data());
curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 0L);
curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 10000L);
auto code = curl_easy_perform(curl);

View File

@ -62,7 +62,7 @@ class Toast {
private:
Type _type{Type::Default};
Containers::String _message;
Containers::StringView _message;
std::chrono::milliseconds _timeout;
std::chrono::steady_clock::time_point _creationTime;
Animation::Track<UnsignedInt, Phase> _phaseTrack;