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) +
|
||||
(filename[_currentProfile->isDemo() ? 9 : 5] - 0x30);
|
||||
}
|
||||
static bool is_moved_after_save = false;
|
||||
|
||||
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_index = ((old_filename[_currentProfile->isDemo() ? 8 : 4] - 0x30) * 10) +
|
||||
|
@ -429,8 +429,15 @@ void SaveTool::fileUpdateEvent(SDL_Event& event) {
|
|||
_massManager->refreshHangar(index);
|
||||
}
|
||||
else {
|
||||
if(!is_moved_after_save) {
|
||||
is_moved_after_save = false;
|
||||
if(_modifiedBySaveTool && _currentMass->filename() == filename) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -438,10 +445,6 @@ void SaveTool::fileUpdateEvent(SDL_Event& event) {
|
|||
break;
|
||||
case FileMoved:
|
||||
if(is_unit) {
|
||||
if(old_filename.hasSuffix(".tmp"_s)) {
|
||||
is_moved_after_save = true;
|
||||
return;
|
||||
}
|
||||
if(old_filename.hasSuffix(".sav"_s)) {
|
||||
_massManager->refreshHangar(index);
|
||||
_massManager->refreshHangar(old_index);
|
||||
|
|
|
@ -277,6 +277,7 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener
|
|||
Containers::String _releaseLink;
|
||||
Containers::String _downloadLink;
|
||||
|
||||
bool _modifiedBySaveTool{false};
|
||||
bool _jointsDirty{false};
|
||||
bool _stylesDirty{false};
|
||||
bool _eyeFlareDirty{false};
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include <Magnum/ImGuiIntegration/Integration.h>
|
||||
|
||||
#include "../Maps/Accessories.h"
|
||||
|
||||
#define STYLENAMES_DEFINITION
|
||||
#include "../Maps/StyleNames.h"
|
||||
|
||||
|
@ -175,7 +174,9 @@ void SaveTool::drawGlobalStyles() {
|
|||
_currentMass->getGlobalStyles();
|
||||
break;
|
||||
case DCS_Save:
|
||||
_modifiedBySaveTool = true;
|
||||
if(!_currentMass->writeGlobalStyle(i)) {
|
||||
_modifiedBySaveTool = false;
|
||||
_queue.addToast(Toast::Type::Error, _currentMass->lastError());
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -152,7 +152,9 @@ void SaveTool::drawArmour() {
|
|||
ImGui::Separator();
|
||||
|
||||
if(drawUnsafeWidget([]{ return ImGui::Button(ICON_FA_SAVE " Save"); })) {
|
||||
_modifiedBySaveTool = true;
|
||||
if(!_currentMass->writeArmourPart(part.slot)) {
|
||||
_modifiedBySaveTool = false;
|
||||
_queue.addToast(Toast::Type::Error, _currentMass->lastError());
|
||||
}
|
||||
}
|
||||
|
@ -274,9 +276,11 @@ void SaveTool::drawArmour() {
|
|||
ImGui::EndGroup();
|
||||
}
|
||||
|
||||
_modifiedBySaveTool = true;
|
||||
if(drawUnsafeWidget([]{ return ImGui::Button(ICON_FA_SAVE " Save"); }) &&
|
||||
!_currentMass->writeBulletLauncherAttachments())
|
||||
{
|
||||
_modifiedBySaveTool = false;
|
||||
_queue.addToast(Toast::Type::Error, _currentMass->lastError());
|
||||
}
|
||||
}
|
||||
|
@ -305,7 +309,9 @@ void SaveTool::drawCustomArmourStyles() {
|
|||
_currentMass->getArmourCustomStyles();
|
||||
break;
|
||||
case DCS_Save:
|
||||
_modifiedBySaveTool = true;
|
||||
if(_currentMass->writeArmourCustomStyle(i)) {
|
||||
_modifiedBySaveTool = false;
|
||||
_queue.addToast(Toast::Type::Error, _currentMass->lastError());
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -180,7 +180,9 @@ void SaveTool::drawJointSliders() {
|
|||
}
|
||||
else {
|
||||
if(drawUnsafeWidget([]{ return ImGui::Button(ICON_FA_SAVE " Save"); })) {
|
||||
_modifiedBySaveTool = true;
|
||||
if(!_currentMass->writeJointSliders()) {
|
||||
_modifiedBySaveTool = false;
|
||||
_queue.addToast(Toast::Type::Error, _currentMass->lastError());
|
||||
}
|
||||
_jointsDirty = false;
|
||||
|
@ -228,7 +230,9 @@ void SaveTool::drawFrameStyles() {
|
|||
}
|
||||
else {
|
||||
if(drawUnsafeWidget([]{ return ImGui::Button(ICON_FA_SAVE " Save"); })) {
|
||||
_modifiedBySaveTool = true;
|
||||
if(!_currentMass->writeFrameStyles()) {
|
||||
_modifiedBySaveTool = false;
|
||||
_queue.addToast(Toast::Type::Error, _currentMass->lastError());
|
||||
}
|
||||
_stylesDirty = false;
|
||||
|
@ -259,7 +263,9 @@ void SaveTool::drawEyeColourPicker() {
|
|||
}
|
||||
else {
|
||||
if(drawUnsafeWidget([]{ return ImGui::Button(ICON_FA_SAVE " Save"); })) {
|
||||
_modifiedBySaveTool = true;
|
||||
if(!_currentMass->writeEyeFlareColour()) {
|
||||
_modifiedBySaveTool = false;
|
||||
_queue.addToast(Toast::Type::Error, _currentMass->lastError());
|
||||
}
|
||||
_eyeFlareDirty = false;
|
||||
|
@ -293,7 +299,9 @@ void SaveTool::drawCustomFrameStyles() {
|
|||
_currentMass->getFrameCustomStyles();
|
||||
break;
|
||||
case DCS_Save:
|
||||
_modifiedBySaveTool = true;
|
||||
if(!_currentMass->writeFrameCustomStyle(i)) {
|
||||
_modifiedBySaveTool = false;
|
||||
_queue.addToast(Toast::Type::Error, _currentMass->lastError());
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -57,7 +57,9 @@ void SaveTool::drawWeapons() {
|
|||
|
||||
if(drawUnsafeWidget([]{ return ImGui::Button(ICON_FA_SAVE " Save"); })) {
|
||||
if(_meleeDirty) {
|
||||
_modifiedBySaveTool = true;
|
||||
if(!_currentMass->writeMeleeWeapons()) {
|
||||
_modifiedBySaveTool = false;
|
||||
_queue.addToast(Toast::Type::Error, _currentMass->lastError());
|
||||
}
|
||||
else {
|
||||
|
@ -66,7 +68,9 @@ void SaveTool::drawWeapons() {
|
|||
}
|
||||
|
||||
if(_shieldsDirty) {
|
||||
_modifiedBySaveTool = true;
|
||||
if(!_currentMass->writeShields()) {
|
||||
_modifiedBySaveTool = false;
|
||||
_queue.addToast(Toast::Type::Error, _currentMass->lastError());
|
||||
}
|
||||
else {
|
||||
|
@ -75,7 +79,9 @@ void SaveTool::drawWeapons() {
|
|||
}
|
||||
|
||||
if(_bShootersDirty) {
|
||||
_modifiedBySaveTool = true;
|
||||
if(!_currentMass->writeBulletShooters()) {
|
||||
_modifiedBySaveTool = false;
|
||||
_queue.addToast(Toast::Type::Error, _currentMass->lastError());
|
||||
}
|
||||
else {
|
||||
|
@ -84,7 +90,9 @@ void SaveTool::drawWeapons() {
|
|||
}
|
||||
|
||||
if(_eShootersDirty) {
|
||||
_modifiedBySaveTool = true;
|
||||
if(_currentMass->writeEnergyShooters()) {
|
||||
_modifiedBySaveTool = false;
|
||||
_queue.addToast(Toast::Type::Error, _currentMass->lastError());
|
||||
}
|
||||
else {
|
||||
|
@ -93,7 +101,9 @@ void SaveTool::drawWeapons() {
|
|||
}
|
||||
|
||||
if(_bLaunchersDirty) {
|
||||
_modifiedBySaveTool = true;
|
||||
if(_currentMass->writeBulletLaunchers()) {
|
||||
_modifiedBySaveTool = false;
|
||||
_queue.addToast(Toast::Type::Error, _currentMass->lastError());
|
||||
}
|
||||
else {
|
||||
|
@ -102,7 +112,9 @@ void SaveTool::drawWeapons() {
|
|||
}
|
||||
|
||||
if(_eLaunchersDirty) {
|
||||
_modifiedBySaveTool = true;
|
||||
if(_currentMass->writeEnergyLaunchers()) {
|
||||
_modifiedBySaveTool = false;
|
||||
_queue.addToast(Toast::Type::Error, _currentMass->lastError());
|
||||
}
|
||||
else {
|
||||
|
@ -167,40 +179,47 @@ void SaveTool::drawWeapons() {
|
|||
ImGui::Separator();
|
||||
|
||||
if(drawUnsafeWidget([](){ return ImGui::Button(ICON_FA_SAVE " Save changes to weapon category"); })) {
|
||||
_modifiedBySaveTool = true;
|
||||
switch(_currentWeapon->type) {
|
||||
case WeaponType::Melee:
|
||||
if(!_currentMass->writeMeleeWeapons()) {
|
||||
_modifiedBySaveTool = false;
|
||||
_queue.addToast(Toast::Type::Error, _currentMass->lastError());
|
||||
}
|
||||
break;
|
||||
case WeaponType::Shield:
|
||||
if(!_currentMass->writeShields()) {
|
||||
_modifiedBySaveTool = false;
|
||||
_queue.addToast(Toast::Type::Error, _currentMass->lastError());
|
||||
}
|
||||
break;
|
||||
case WeaponType::BulletShooter:
|
||||
if(!_currentMass->writeBulletShooters()) {
|
||||
_modifiedBySaveTool = false;
|
||||
_queue.addToast(Toast::Type::Error, _currentMass->lastError());
|
||||
}
|
||||
break;
|
||||
case WeaponType::EnergyShooter:
|
||||
if(!_currentMass->writeEnergyShooters()) {
|
||||
_modifiedBySaveTool = false;
|
||||
_queue.addToast(Toast::Type::Error, _currentMass->lastError());
|
||||
}
|
||||
break;
|
||||
case WeaponType::BulletLauncher:
|
||||
if(!_currentMass->writeBulletLaunchers()) {
|
||||
_modifiedBySaveTool = false;
|
||||
_queue.addToast(Toast::Type::Error, _currentMass->lastError());
|
||||
}
|
||||
break;
|
||||
case WeaponType::EnergyLauncher:
|
||||
if(!_currentMass->writeEnergyLaunchers()) {
|
||||
_modifiedBySaveTool = false;
|
||||
_queue.addToast(Toast::Type::Error, _currentMass->lastError());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
_modifiedBySaveTool = false;
|
||||
_queue.addToast(Toast::Type::Error, "Unknown weapon type");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue