Compare commits

..

No commits in common. "71d38f4a91bffe69be7066bf0832eae8e4a36607" and "704f6e2f492e0ef6d1f310a2e30fe6e95c9bd0b5" have entirely different histories.

6 changed files with 15 additions and 43 deletions

View file

@ -105,8 +105,8 @@ auto MassManager::exportMass(Int hangar) -> bool {
} }
Containers::String source = Utility::Path::join(_saveDirectory, _hangars[hangar].filename()); Containers::String source = Utility::Path::join(_saveDirectory, _hangars[hangar].filename());
Containers::String dest = Utility::Path::join(_stagingAreaDirectory, Containers::String dest = Utility::Path::join(_stagingAreaDirectory,
Utility::format("{}_{}.sav", _hangars[hangar].name(), _account)); Utility::format("{}_{}.sav", _hangars[hangar].name(), _account));
if(!Utility::Path::copy(source, dest)) { if(!Utility::Path::copy(source, dest)) {
_lastError = Utility::format("Couldn't export data from hangar {:.2d} to {}", hangar, dest); _lastError = Utility::format("Couldn't export data from hangar {:.2d} to {}", hangar, dest);
@ -200,26 +200,6 @@ void MassManager::refreshStagedMasses() {
} }
} }
void MassManager::refreshStagedMass(Containers::StringView 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);
if(file_exists) {
auto name = Mass::getNameFromFile(Utility::Path::join(_stagingAreaDirectory, filename));
if(name) {
_stagedMasses[filename] = *name;
}
else if(it != _stagedMasses.cend()) {
_stagedMasses.erase(it);
}
}
else if(it != _stagedMasses.cend()) {
_stagedMasses.erase(it);
}
}
auto MassManager::deleteStagedMass(Containers::StringView filename) -> bool { auto MassManager::deleteStagedMass(Containers::StringView filename) -> bool {
if(_stagedMasses.find(filename) == _stagedMasses.cend()) { if(_stagedMasses.find(filename) == _stagedMasses.cend()) {
_lastError = "The file "_s + filename + " couldn't be found in the list of staged M.A.S.S.es."_s; _lastError = "The file "_s + filename + " couldn't be found in the list of staged M.A.S.S.es."_s;

View file

@ -44,7 +44,6 @@ class MassManager {
auto stagedMasses() -> std::map<Containers::String, Containers::String> const&; auto stagedMasses() -> std::map<Containers::String, Containers::String> const&;
void refreshStagedMasses(); void refreshStagedMasses();
void refreshStagedMass(Containers::StringView filename);
auto deleteStagedMass(Containers::StringView filename) -> bool; auto deleteStagedMass(Containers::StringView filename) -> bool;
private: private:

View file

@ -94,7 +94,7 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener
FileDeleted = efsw::Action::Delete, FileDeleted = efsw::Action::Delete,
FileModified = efsw::Action::Modified, FileModified = efsw::Action::Modified,
FileMoved = efsw::Action::Moved, FileMoved = efsw::Action::Moved,
StagedUpdate = 1 << 3 StagedUpdate
}; };
void fileUpdateEvent(SDL_Event& event); void fileUpdateEvent(SDL_Event& event);

View file

@ -32,10 +32,8 @@ void SaveTool::handleFileAction(efsw::WatchID watch_id,
SDL_zero(event); SDL_zero(event);
event.type = _fileEventId; event.type = _fileEventId;
event.user.data1 = Containers::String{Containers::AllocatedInit, filename.c_str()}.release();
if(watch_id == _watchIDs[StagingDir] && Utility::String::endsWith(filename, ".sav")) { if(watch_id == _watchIDs[StagingDir] && Utility::String::endsWith(filename, ".sav")) {
event.user.code = StagedUpdate | action; event.user.code = StagedUpdate;
SDL_PushEvent(&event); SDL_PushEvent(&event);
return; return;
} }
@ -49,6 +47,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();
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{Containers::AllocatedInit, old_filename.c_str()}.release();
} }
@ -57,13 +56,12 @@ void SaveTool::handleFileAction(efsw::WatchID watch_id,
} }
void SaveTool::fileUpdateEvent(SDL_Event& event) { void SaveTool::fileUpdateEvent(SDL_Event& event) {
Containers::String filename{static_cast<char*>(event.user.data1), std::strlen(static_cast<char*>(event.user.data1)), nullptr}; if(event.user.code == StagedUpdate) {
_massManager->refreshStagedMasses();
if((event.user.code & StagedUpdate) == StagedUpdate) {
_massManager->refreshStagedMass(filename);
return; return;
} }
Containers::String filename{static_cast<char*>(event.user.data1), std::strlen(static_cast<char*>(event.user.data1)), nullptr};
Containers::String old_filename; Containers::String old_filename;
Int index = 0; Int index = 0;
@ -114,7 +112,7 @@ void SaveTool::fileUpdateEvent(SDL_Event& event) {
} }
else { else {
if(_modifiedBySaveTool && _currentMass->filename() == filename) { if(_modifiedBySaveTool && _currentMass->filename() == filename) {
auto handle = CreateFileW(Utility::Unicode::widen(Containers::StringView{filename}), GENERIC_READ, 0, auto handle = CreateFileW(Utility::Unicode::widen(Containers::StringView{filename}).data(), GENERIC_READ, 0,
nullptr, OPEN_EXISTING, 0, nullptr); nullptr, OPEN_EXISTING, 0, nullptr);
if(handle && handle != INVALID_HANDLE_VALUE) { if(handle && handle != INVALID_HANDLE_VALUE) {
CloseHandle(handle); CloseHandle(handle);

View file

@ -411,8 +411,6 @@ void SaveTool::drawWeaponEditor(Weapon& weapon) {
} }
ImGui::ColorEdit3("##CustomEffectColourPicker", &weapon.effectColour.x(), ImGuiColorEditFlags_HDR|ImGuiColorEditFlags_Float); ImGui::ColorEdit3("##CustomEffectColourPicker", &weapon.effectColour.x(), ImGuiColorEditFlags_HDR|ImGuiColorEditFlags_Float);
ImGui::SameLine();
drawHelpMarker("Click the coloured square for the full picker.");
if(!custom_effect) { if(!custom_effect) {
ImGui::EndDisabled(); ImGui::EndDisabled();

View file

@ -67,13 +67,6 @@ auto UESaveFile::props() -> Containers::ArrayView<UnrealPropertyBase::ptr> {
} }
auto UESaveFile::saveToFile() -> bool { auto UESaveFile::saveToFile() -> bool {
bool temp_file = _filepath.hasSuffix(".tmp");
if(!temp_file && !Utility::Path::copy(_filepath, _filepath + ".bak"_s)) {
_lastError = "Couldn't create a backup for " + _filepath;
return false;
}
BinaryWriter writer{_filepath + ".tmp"_s}; BinaryWriter writer{_filepath + ".tmp"_s};
if(!writer.open()) { if(!writer.open()) {
@ -132,8 +125,12 @@ auto UESaveFile::saveToFile() -> bool {
writer.closeFile(); writer.closeFile();
if(!temp_file && !Utility::Path::copy(_filepath + ".tmp"_s, _filepath)) { if(!Utility::Path::copy(_filepath, _filepath + ".bak"_s)) {
_lastError = "Couldn't save the file properly."; return false;
}
if(!Utility::Path::copy(_filepath + ".tmp"_s, _filepath)) {
Utility::Path::copy(_filepath + ".bak"_s, _filepath);
return false; return false;
} }
else { else {