Handle fastfiles in updater

This commit is contained in:
Federico Cecchetto 2022-08-22 04:38:53 +02:00
parent 8c0a891180
commit c0013157b2
3 changed files with 46 additions and 1 deletions

View File

@ -22,6 +22,7 @@ namespace database
{
std::unique_ptr<std::ifstream> stream;
uint64_t offset{};
std::string path;
};
std::unordered_map<game::DB_IFileSysFile*, bnet_file_handle_t> 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:

View File

@ -0,0 +1,6 @@
#pragma once
namespace database
{
void close_fastfile_handles();
}

View File

@ -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
@ -444,9 +455,16 @@ namespace updater
});
for (const auto& file : garbage_files)
{
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);