Compare commits

...

4 commits

Author SHA1 Message Date
71d38f4a91 SaveTool,MassManager: improve staged file updates.
No need to redo the whole staged list when only one file gets updated.
Considering the call to refreshStagedMasses() is blocking (I might look
into threading stuff), its time complexity is O(n) at worst, which can
be bad on slower systems.
2022-04-04 10:37:09 +02:00
869ca07b20 SaveTool: remove an extraneous call to data().
Corrade arrays implicitly decay to their T* form (wchar_t here), after
all.
2022-04-04 09:58:12 +02:00
c1ae793800 SaveTool: add a help marker for the melee effect colour picker. 2022-04-04 09:22:12 +02:00
70ddb0ce39 UESaveFile: don't create a backup if the file is already temporary.
Also improve error handling.
2022-04-04 09:21:31 +02:00
6 changed files with 43 additions and 15 deletions

View file

@ -200,6 +200,26 @@ 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 {
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;

View file

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

View file

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

View file

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

View file

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

View file

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