Compare commits

..

No commits in common. "63a8cf70754faa2542a4b04120cb01ec9dba1b03" and "fd3306b175bff5b8d73a1f6b39ce919a9b3ad6e1" have entirely different histories.

7 changed files with 13 additions and 52 deletions

View file

@ -20,6 +20,7 @@
#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>
@ -209,7 +210,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{Containers::AllocatedInit, old_filename.c_str()}.release(); event.user.data2 = Containers::String{old_filename}.release();
} }
SDL_PushEvent(&event); SDL_PushEvent(&event);
@ -358,8 +359,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 = release["html_url"].get<std::string>().c_str(); _releaseLink = to_string(release["html_url"]);
_downloadLink = release["assets"][0]["browser_download_url"].get<std::string>().c_str(); _downloadLink = to_string(release["assets"][0]["browser_download_url"]);
} }
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);
@ -389,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) +
@ -428,15 +429,8 @@ void SaveTool::fileUpdateEvent(SDL_Event& event) {
_massManager->refreshHangar(index); _massManager->refreshHangar(index);
} }
else { else {
if(_modifiedBySaveTool && _currentMass->filename() == filename) { if(!is_moved_after_save) {
auto handle = CreateFileW(Utility::Unicode::widen(Containers::StringView{filename}).data(), GENERIC_READ, 0, is_moved_after_save = false;
nullptr, OPEN_EXISTING, 0, nullptr);
if(handle && handle != INVALID_HANDLE_VALUE) {
CloseHandle(handle);
_modifiedBySaveTool = false;
}
}
else {
_currentMass->setDirty(); _currentMass->setDirty();
} }
} }
@ -444,6 +438,10 @@ 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,7 +277,6 @@ 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,6 +19,7 @@
#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"
@ -174,9 +175,7 @@ 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,9 +152,7 @@ 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());
} }
} }
@ -276,11 +274,9 @@ 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());
} }
} }
@ -309,9 +305,7 @@ 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,9 +180,7 @@ 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;
@ -230,9 +228,7 @@ 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;
@ -263,9 +259,7 @@ 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;
@ -299,9 +293,7 @@ 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,9 +57,7 @@ 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 {
@ -68,9 +66,7 @@ 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 {
@ -79,9 +75,7 @@ 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 {
@ -90,9 +84,7 @@ 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 {
@ -101,9 +93,7 @@ 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 {
@ -112,9 +102,7 @@ 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 {
@ -179,47 +167,40 @@ 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,9 +16,7 @@
#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>