diff --git a/src/client/component/database.cpp b/src/client/component/database.cpp index b7c5f97e..3a41546e 100644 --- a/src/client/component/database.cpp +++ b/src/client/component/database.cpp @@ -22,6 +22,7 @@ namespace database { std::unique_ptr stream; uint64_t offset{}; + std::string path; }; std::unordered_map bnet_file_handles{}; @@ -159,6 +160,7 @@ namespace database bnet_file_handle_t bnet_handle{}; bnet_handle.stream = std::move(stream); + bnet_handle.path = path; bnet_file_handles[handle] = std::move(bnet_handle); return handle; } @@ -376,6 +378,17 @@ namespace database } } + void close_fastfile_handles() + { + for (const auto& handle : bnet_file_handles) + { + if (handle.second.path.ends_with(".ff")) + { + handle.second.stream->close(); + } + } + } + class component final : public component_interface { public: diff --git a/src/client/component/database.hpp b/src/client/component/database.hpp new file mode 100644 index 00000000..12c5af6a --- /dev/null +++ b/src/client/component/database.hpp @@ -0,0 +1,6 @@ +#pragma once + +namespace database +{ + void close_fastfile_handles(); +} diff --git a/src/client/component/updater.cpp b/src/client/component/updater.cpp index 78b81eab..ed4cdf75 100644 --- a/src/client/component/updater.cpp +++ b/src/client/component/updater.cpp @@ -5,6 +5,8 @@ #include "updater.hpp" #include "game/ui_scripting/execution.hpp" #include "console.hpp" +#include "command.hpp" +#include "database.hpp" #include "version.h" @@ -403,6 +405,15 @@ namespace updater }); } + std::string name_ = name; + if (name_.ends_with(".ff")) + { + update_data.access([](update_data_t& data_) + { + data_.restart_required = true;// + }); + } + #ifdef DEBUG console::info("[Updater] need file %s\n", name); #endif @@ -445,7 +456,14 @@ namespace updater for (const auto& file : garbage_files) { - std::filesystem::remove_all(file); + try + { + std::filesystem::remove_all(file); + } + catch (...) + { + console::error("Failed to delete %s\n", file.data()); + } } scheduler::once([]() @@ -487,6 +505,14 @@ namespace updater for (const auto& download : downloads) { + update_data.access([](update_data_t& data_) + { + if (data_.restart_required) + { + database::close_fastfile_handles(); + } + }); + if (!write_file(download.name, download.data)) { set_update_download_status(true, false, ERR_WRITE_FAIL + download.name);