t7x/src/client/component/updater.cpp

71 lines
974 B
C++
Raw Normal View History

2022-06-16 08:15:14 -04:00
#include <std_include.hpp>
#include "loader/component_loader.hpp"
2023-01-31 12:13:54 -05:00
#include "updater.hpp"
2023-02-18 13:15:47 -05:00
#include "game/game.hpp"
2022-06-16 08:15:14 -04:00
2023-03-28 13:06:48 -04:00
#include <utils/flags.hpp>
2023-02-18 13:15:47 -05:00
#include <updater/updater.hpp>
2022-06-16 08:15:14 -04:00
namespace updater
{
2023-02-18 13:15:47 -05:00
void update()
2022-06-16 08:15:14 -04:00
{
2023-03-28 13:06:48 -04:00
if (utils::flags::has_flag("noupdate"))
{
return;
}
2023-02-18 13:15:47 -05:00
try
2022-06-16 08:15:14 -04:00
{
2023-02-18 13:15:47 -05:00
run(game::get_appdata_path());
2022-06-16 08:15:14 -04:00
}
2023-02-18 13:15:47 -05:00
catch (update_cancelled&)
2022-06-16 08:15:14 -04:00
{
TerminateProcess(GetCurrentProcess(), 0);
}
2023-01-31 12:13:54 -05:00
catch (...)
{
}
}
2023-01-01 15:51:04 -05:00
class component final : public generic_component
2022-06-16 08:15:14 -04:00
{
public:
2022-11-11 11:00:34 -05:00
component()
2022-06-16 08:15:14 -04:00
{
this->update_thread_ = std::thread([this]
{
2023-01-31 12:13:54 -05:00
update();
2022-06-16 08:15:14 -04:00
});
}
void pre_destroy() override
{
join();
}
void post_unpack() override
{
join();
}
2022-11-11 11:00:34 -05:00
component_priority priority() const override
2022-06-16 08:15:14 -04:00
{
2022-11-11 11:00:34 -05:00
return component_priority::updater;
2022-06-16 08:15:14 -04:00
}
private:
std::thread update_thread_{};
void join()
{
if (this->update_thread_.joinable())
{
this->update_thread_.join();
}
}
};
}
REGISTER_COMPONENT(updater::component)