Compare commits

...

4 commits

7 changed files with 52 additions and 13 deletions

View file

@ -20,7 +20,6 @@
#include <Corrade/Containers/Pair.h> #include <Corrade/Containers/Pair.h>
#include <Corrade/Containers/ScopeGuard.h> #include <Corrade/Containers/ScopeGuard.h>
#include <Corrade/Containers/StringStl.h>
#include <Corrade/Utility/Format.h> #include <Corrade/Utility/Format.h>
#include <Corrade/Utility/Path.h> #include <Corrade/Utility/Path.h>
#include <Corrade/Utility/String.h> #include <Corrade/Utility/String.h>
@ -210,7 +209,7 @@ void SaveTool::handleFileAction(efsw::WatchID watch_id,
event.user.code = action; event.user.code = action;
event.user.data1 = Containers::String{Containers::AllocatedInit, filename.c_str()}.release(); event.user.data1 = Containers::String{Containers::AllocatedInit, filename.c_str()}.release();
if(action == efsw::Actions::Moved) { if(action == efsw::Actions::Moved) {
event.user.data2 = Containers::String{old_filename}.release(); event.user.data2 = Containers::String{Containers::AllocatedInit, old_filename.c_str()}.release();
} }
SDL_PushEvent(&event); SDL_PushEvent(&event);
@ -359,8 +358,8 @@ void SaveTool::updateCheckEvent(SDL_Event& event) {
std::chrono::milliseconds{5000}); std::chrono::milliseconds{5000});
_updateAvailable = true; _updateAvailable = true;
_latestVersion = latest_ver; _latestVersion = latest_ver;
_releaseLink = to_string(release["html_url"]); _releaseLink = release["html_url"].get<std::string>().c_str();
_downloadLink = to_string(release["assets"][0]["browser_download_url"]); _downloadLink = release["assets"][0]["browser_download_url"].get<std::string>().c_str();
} }
else if(latest_ver == current_ver || (current_ver > latest_ver && Utility::String::endsWith(SAVETOOL_VERSION, "-pre"))) { else if(latest_ver == current_ver || (current_ver > latest_ver && Utility::String::endsWith(SAVETOOL_VERSION, "-pre"))) {
_queue.addToast(Toast::Type::Success, "The application is already up to date."_s); _queue.addToast(Toast::Type::Success, "The application is already up to date."_s);
@ -390,7 +389,7 @@ void SaveTool::fileUpdateEvent(SDL_Event& event) {
index = ((filename[_currentProfile->isDemo() ? 8 : 4] - 0x30) * 10) + index = ((filename[_currentProfile->isDemo() ? 8 : 4] - 0x30) * 10) +
(filename[_currentProfile->isDemo() ? 9 : 5] - 0x30); (filename[_currentProfile->isDemo() ? 9 : 5] - 0x30);
} }
static bool is_moved_after_save = false;
if(event.user.code == FileMoved) { if(event.user.code == FileMoved) {
old_filename = Containers::String{static_cast<char*>(event.user.data2), std::strlen(static_cast<char*>(event.user.data2)), nullptr}; old_filename = Containers::String{static_cast<char*>(event.user.data2), std::strlen(static_cast<char*>(event.user.data2)), nullptr};
old_index = ((old_filename[_currentProfile->isDemo() ? 8 : 4] - 0x30) * 10) + old_index = ((old_filename[_currentProfile->isDemo() ? 8 : 4] - 0x30) * 10) +
@ -429,8 +428,15 @@ void SaveTool::fileUpdateEvent(SDL_Event& event) {
_massManager->refreshHangar(index); _massManager->refreshHangar(index);
} }
else { else {
if(!is_moved_after_save) { if(_modifiedBySaveTool && _currentMass->filename() == filename) {
is_moved_after_save = false; auto handle = CreateFileW(Utility::Unicode::widen(Containers::StringView{filename}).data(), GENERIC_READ, 0,
nullptr, OPEN_EXISTING, 0, nullptr);
if(handle && handle != INVALID_HANDLE_VALUE) {
CloseHandle(handle);
_modifiedBySaveTool = false;
}
}
else {
_currentMass->setDirty(); _currentMass->setDirty();
} }
} }
@ -438,10 +444,6 @@ void SaveTool::fileUpdateEvent(SDL_Event& event) {
break; break;
case FileMoved: case FileMoved:
if(is_unit) { if(is_unit) {
if(old_filename.hasSuffix(".tmp"_s)) {
is_moved_after_save = true;
return;
}
if(old_filename.hasSuffix(".sav"_s)) { if(old_filename.hasSuffix(".sav"_s)) {
_massManager->refreshHangar(index); _massManager->refreshHangar(index);
_massManager->refreshHangar(old_index); _massManager->refreshHangar(old_index);

View file

@ -277,6 +277,7 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener
Containers::String _releaseLink; Containers::String _releaseLink;
Containers::String _downloadLink; Containers::String _downloadLink;
bool _modifiedBySaveTool{false};
bool _jointsDirty{false}; bool _jointsDirty{false};
bool _stylesDirty{false}; bool _stylesDirty{false};
bool _eyeFlareDirty{false}; bool _eyeFlareDirty{false};

View file

@ -19,7 +19,6 @@
#include <Magnum/ImGuiIntegration/Integration.h> #include <Magnum/ImGuiIntegration/Integration.h>
#include "../Maps/Accessories.h" #include "../Maps/Accessories.h"
#define STYLENAMES_DEFINITION #define STYLENAMES_DEFINITION
#include "../Maps/StyleNames.h" #include "../Maps/StyleNames.h"
@ -175,7 +174,9 @@ void SaveTool::drawGlobalStyles() {
_currentMass->getGlobalStyles(); _currentMass->getGlobalStyles();
break; break;
case DCS_Save: case DCS_Save:
_modifiedBySaveTool = true;
if(!_currentMass->writeGlobalStyle(i)) { if(!_currentMass->writeGlobalStyle(i)) {
_modifiedBySaveTool = false;
_queue.addToast(Toast::Type::Error, _currentMass->lastError()); _queue.addToast(Toast::Type::Error, _currentMass->lastError());
} }
break; break;

View file

@ -152,7 +152,9 @@ void SaveTool::drawArmour() {
ImGui::Separator(); ImGui::Separator();
if(drawUnsafeWidget([]{ return ImGui::Button(ICON_FA_SAVE " Save"); })) { if(drawUnsafeWidget([]{ return ImGui::Button(ICON_FA_SAVE " Save"); })) {
_modifiedBySaveTool = true;
if(!_currentMass->writeArmourPart(part.slot)) { if(!_currentMass->writeArmourPart(part.slot)) {
_modifiedBySaveTool = false;
_queue.addToast(Toast::Type::Error, _currentMass->lastError()); _queue.addToast(Toast::Type::Error, _currentMass->lastError());
} }
} }
@ -274,9 +276,11 @@ void SaveTool::drawArmour() {
ImGui::EndGroup(); ImGui::EndGroup();
} }
_modifiedBySaveTool = true;
if(drawUnsafeWidget([]{ return ImGui::Button(ICON_FA_SAVE " Save"); }) && if(drawUnsafeWidget([]{ return ImGui::Button(ICON_FA_SAVE " Save"); }) &&
!_currentMass->writeBulletLauncherAttachments()) !_currentMass->writeBulletLauncherAttachments())
{ {
_modifiedBySaveTool = false;
_queue.addToast(Toast::Type::Error, _currentMass->lastError()); _queue.addToast(Toast::Type::Error, _currentMass->lastError());
} }
} }
@ -305,7 +309,9 @@ void SaveTool::drawCustomArmourStyles() {
_currentMass->getArmourCustomStyles(); _currentMass->getArmourCustomStyles();
break; break;
case DCS_Save: case DCS_Save:
_modifiedBySaveTool = true;
if(_currentMass->writeArmourCustomStyle(i)) { if(_currentMass->writeArmourCustomStyle(i)) {
_modifiedBySaveTool = false;
_queue.addToast(Toast::Type::Error, _currentMass->lastError()); _queue.addToast(Toast::Type::Error, _currentMass->lastError());
} }
break; break;

View file

@ -180,7 +180,9 @@ void SaveTool::drawJointSliders() {
} }
else { else {
if(drawUnsafeWidget([]{ return ImGui::Button(ICON_FA_SAVE " Save"); })) { if(drawUnsafeWidget([]{ return ImGui::Button(ICON_FA_SAVE " Save"); })) {
_modifiedBySaveTool = true;
if(!_currentMass->writeJointSliders()) { if(!_currentMass->writeJointSliders()) {
_modifiedBySaveTool = false;
_queue.addToast(Toast::Type::Error, _currentMass->lastError()); _queue.addToast(Toast::Type::Error, _currentMass->lastError());
} }
_jointsDirty = false; _jointsDirty = false;
@ -228,7 +230,9 @@ void SaveTool::drawFrameStyles() {
} }
else { else {
if(drawUnsafeWidget([]{ return ImGui::Button(ICON_FA_SAVE " Save"); })) { if(drawUnsafeWidget([]{ return ImGui::Button(ICON_FA_SAVE " Save"); })) {
_modifiedBySaveTool = true;
if(!_currentMass->writeFrameStyles()) { if(!_currentMass->writeFrameStyles()) {
_modifiedBySaveTool = false;
_queue.addToast(Toast::Type::Error, _currentMass->lastError()); _queue.addToast(Toast::Type::Error, _currentMass->lastError());
} }
_stylesDirty = false; _stylesDirty = false;
@ -259,7 +263,9 @@ void SaveTool::drawEyeColourPicker() {
} }
else { else {
if(drawUnsafeWidget([]{ return ImGui::Button(ICON_FA_SAVE " Save"); })) { if(drawUnsafeWidget([]{ return ImGui::Button(ICON_FA_SAVE " Save"); })) {
_modifiedBySaveTool = true;
if(!_currentMass->writeEyeFlareColour()) { if(!_currentMass->writeEyeFlareColour()) {
_modifiedBySaveTool = false;
_queue.addToast(Toast::Type::Error, _currentMass->lastError()); _queue.addToast(Toast::Type::Error, _currentMass->lastError());
} }
_eyeFlareDirty = false; _eyeFlareDirty = false;
@ -293,7 +299,9 @@ void SaveTool::drawCustomFrameStyles() {
_currentMass->getFrameCustomStyles(); _currentMass->getFrameCustomStyles();
break; break;
case DCS_Save: case DCS_Save:
_modifiedBySaveTool = true;
if(!_currentMass->writeFrameCustomStyle(i)) { if(!_currentMass->writeFrameCustomStyle(i)) {
_modifiedBySaveTool = false;
_queue.addToast(Toast::Type::Error, _currentMass->lastError()); _queue.addToast(Toast::Type::Error, _currentMass->lastError());
} }
break; break;

View file

@ -57,7 +57,9 @@ void SaveTool::drawWeapons() {
if(drawUnsafeWidget([]{ return ImGui::Button(ICON_FA_SAVE " Save"); })) { if(drawUnsafeWidget([]{ return ImGui::Button(ICON_FA_SAVE " Save"); })) {
if(_meleeDirty) { if(_meleeDirty) {
_modifiedBySaveTool = true;
if(!_currentMass->writeMeleeWeapons()) { if(!_currentMass->writeMeleeWeapons()) {
_modifiedBySaveTool = false;
_queue.addToast(Toast::Type::Error, _currentMass->lastError()); _queue.addToast(Toast::Type::Error, _currentMass->lastError());
} }
else { else {
@ -66,7 +68,9 @@ void SaveTool::drawWeapons() {
} }
if(_shieldsDirty) { if(_shieldsDirty) {
_modifiedBySaveTool = true;
if(!_currentMass->writeShields()) { if(!_currentMass->writeShields()) {
_modifiedBySaveTool = false;
_queue.addToast(Toast::Type::Error, _currentMass->lastError()); _queue.addToast(Toast::Type::Error, _currentMass->lastError());
} }
else { else {
@ -75,7 +79,9 @@ void SaveTool::drawWeapons() {
} }
if(_bShootersDirty) { if(_bShootersDirty) {
_modifiedBySaveTool = true;
if(!_currentMass->writeBulletShooters()) { if(!_currentMass->writeBulletShooters()) {
_modifiedBySaveTool = false;
_queue.addToast(Toast::Type::Error, _currentMass->lastError()); _queue.addToast(Toast::Type::Error, _currentMass->lastError());
} }
else { else {
@ -84,7 +90,9 @@ void SaveTool::drawWeapons() {
} }
if(_eShootersDirty) { if(_eShootersDirty) {
_modifiedBySaveTool = true;
if(_currentMass->writeEnergyShooters()) { if(_currentMass->writeEnergyShooters()) {
_modifiedBySaveTool = false;
_queue.addToast(Toast::Type::Error, _currentMass->lastError()); _queue.addToast(Toast::Type::Error, _currentMass->lastError());
} }
else { else {
@ -93,7 +101,9 @@ void SaveTool::drawWeapons() {
} }
if(_bLaunchersDirty) { if(_bLaunchersDirty) {
_modifiedBySaveTool = true;
if(_currentMass->writeBulletLaunchers()) { if(_currentMass->writeBulletLaunchers()) {
_modifiedBySaveTool = false;
_queue.addToast(Toast::Type::Error, _currentMass->lastError()); _queue.addToast(Toast::Type::Error, _currentMass->lastError());
} }
else { else {
@ -102,7 +112,9 @@ void SaveTool::drawWeapons() {
} }
if(_eLaunchersDirty) { if(_eLaunchersDirty) {
_modifiedBySaveTool = true;
if(_currentMass->writeEnergyLaunchers()) { if(_currentMass->writeEnergyLaunchers()) {
_modifiedBySaveTool = false;
_queue.addToast(Toast::Type::Error, _currentMass->lastError()); _queue.addToast(Toast::Type::Error, _currentMass->lastError());
} }
else { else {
@ -167,40 +179,47 @@ void SaveTool::drawWeapons() {
ImGui::Separator(); ImGui::Separator();
if(drawUnsafeWidget([](){ return ImGui::Button(ICON_FA_SAVE " Save changes to weapon category"); })) { if(drawUnsafeWidget([](){ return ImGui::Button(ICON_FA_SAVE " Save changes to weapon category"); })) {
_modifiedBySaveTool = true;
switch(_currentWeapon->type) { switch(_currentWeapon->type) {
case WeaponType::Melee: case WeaponType::Melee:
if(!_currentMass->writeMeleeWeapons()) { if(!_currentMass->writeMeleeWeapons()) {
_modifiedBySaveTool = false;
_queue.addToast(Toast::Type::Error, _currentMass->lastError()); _queue.addToast(Toast::Type::Error, _currentMass->lastError());
} }
break; break;
case WeaponType::Shield: case WeaponType::Shield:
if(!_currentMass->writeShields()) { if(!_currentMass->writeShields()) {
_modifiedBySaveTool = false;
_queue.addToast(Toast::Type::Error, _currentMass->lastError()); _queue.addToast(Toast::Type::Error, _currentMass->lastError());
} }
break; break;
case WeaponType::BulletShooter: case WeaponType::BulletShooter:
if(!_currentMass->writeBulletShooters()) { if(!_currentMass->writeBulletShooters()) {
_modifiedBySaveTool = false;
_queue.addToast(Toast::Type::Error, _currentMass->lastError()); _queue.addToast(Toast::Type::Error, _currentMass->lastError());
} }
break; break;
case WeaponType::EnergyShooter: case WeaponType::EnergyShooter:
if(!_currentMass->writeEnergyShooters()) { if(!_currentMass->writeEnergyShooters()) {
_modifiedBySaveTool = false;
_queue.addToast(Toast::Type::Error, _currentMass->lastError()); _queue.addToast(Toast::Type::Error, _currentMass->lastError());
} }
break; break;
case WeaponType::BulletLauncher: case WeaponType::BulletLauncher:
if(!_currentMass->writeBulletLaunchers()) { if(!_currentMass->writeBulletLaunchers()) {
_modifiedBySaveTool = false;
_queue.addToast(Toast::Type::Error, _currentMass->lastError()); _queue.addToast(Toast::Type::Error, _currentMass->lastError());
} }
break; break;
case WeaponType::EnergyLauncher: case WeaponType::EnergyLauncher:
if(!_currentMass->writeEnergyLaunchers()) { if(!_currentMass->writeEnergyLaunchers()) {
_modifiedBySaveTool = false;
_queue.addToast(Toast::Type::Error, _currentMass->lastError()); _queue.addToast(Toast::Type::Error, _currentMass->lastError());
} }
break; break;
default: default:
_modifiedBySaveTool = false;
_queue.addToast(Toast::Type::Error, "Unknown weapon type"); _queue.addToast(Toast::Type::Error, "Unknown weapon type");
} }
} }

View file

@ -16,7 +16,9 @@
#include "SaveTool/SaveTool.h" #include "SaveTool/SaveTool.h"
#ifndef SAVETOOL_DEBUG_BUILD
#include <fstream> #include <fstream>
#endif
#include <errhandlingapi.h> #include <errhandlingapi.h>
#include <synchapi.h> #include <synchapi.h>