SaveTool: fix "external changes detected" on saving in the tool.
I hope.
This commit is contained in:
parent
fd3306b175
commit
ac1276761e
6 changed files with 47 additions and 9 deletions
|
@ -390,7 +390,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 +429,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 +445,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);
|
||||||
|
|
|
@ -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};
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue