Close fastfiles handles during update + fixes

This commit is contained in:
Federico Cecchetto 2022-09-11 02:21:38 +02:00
parent 74cab5fb8c
commit 5dc75c505e
5 changed files with 29 additions and 6 deletions

View File

@ -1,5 +1 @@
require("loading") require("loading")
if (Engine.InFrontend()) then
require("download")
end

View File

@ -3,7 +3,7 @@ if (game:issingleplayer()) then
end end
if (Engine.InFrontend()) then if (Engine.InFrontend()) then
require("shaderdialog") require("shader_dialog")
require("gamemodes") require("gamemodes")
require("no_mode_switch") require("no_mode_switch")
require("disable_useless_things") require("disable_useless_things")

View File

@ -23,6 +23,8 @@ namespace fastfiles
utils::hook::detour db_find_xasset_header_hook; utils::hook::detour db_find_xasset_header_hook;
game::dvar_t* g_dump_scripts; game::dvar_t* g_dump_scripts;
std::vector<HANDLE> fastfile_handles;
void db_try_load_x_file_internal(const char* zone_name, const int flags) void db_try_load_x_file_internal(const char* zone_name, const int flags)
{ {
console::info("Loading fastfile %s\n", zone_name); console::info("Loading fastfile %s\n", zone_name);
@ -189,7 +191,13 @@ namespace fastfiles
} }
} }
return CreateFileA(path.data(), 0x80000000, 1u, 0, 3u, 0x60000000u, 0); const auto handle = CreateFileA(path.data(), 0x80000000, 1u, 0, 3u, 0x60000000u, 0);
if (handle != reinterpret_cast<HANDLE>(-1))
{
fastfile_handles.push_back(handle);
}
return handle;
} }
utils::hook::detour sys_createfile_hook; utils::hook::detour sys_createfile_hook;
@ -321,6 +329,14 @@ namespace fastfiles
}), &callback, includeOverride); }), &callback, includeOverride);
} }
void close_fastfile_handles()
{
for (const auto& handle : fastfile_handles)
{
CloseHandle(handle);
}
}
class component final : public component_interface class component final : public component_interface
{ {
public: public:

View File

@ -10,4 +10,6 @@ namespace fastfiles
void enum_assets(const game::XAssetType type, void enum_assets(const game::XAssetType type,
const std::function<void(game::XAssetHeader)>& callback, const bool includeOverride); const std::function<void(game::XAssetHeader)>& callback, const bool includeOverride);
void close_fastfile_handles();
} }

View File

@ -5,6 +5,7 @@
#include "scheduler.hpp" #include "scheduler.hpp"
#include "dvars.hpp" #include "dvars.hpp"
#include "updater.hpp" #include "updater.hpp"
#include "fastfiles.hpp"
#include "game/ui_scripting/execution.hpp" #include "game/ui_scripting/execution.hpp"
#include "version.h" #include "version.h"
@ -508,6 +509,14 @@ namespace updater
return data_.garbage_files; return data_.garbage_files;
}); });
update_data.access([](update_data_t& data_)
{
if (data_.restart_required)
{
fastfiles::close_fastfile_handles();
}
});
for (const auto& file : garbage_files) for (const auto& file : garbage_files)
{ {
try try