1
0
mirror of synced 2025-01-25 15:53:43 +01:00

impr: Force update all installed content store items after an update

This commit is contained in:
WerWolv 2024-12-25 14:29:41 +01:00
parent 99b90f90ac
commit 9c1a673047
2 changed files with 42 additions and 22 deletions

View File

@ -71,6 +71,7 @@ namespace hex::plugin::builtin {
bool download(const paths::impl::DefaultPath *pathType, const std::string &fileName, const std::string &url);
bool remove(const paths::impl::DefaultPath *pathType, const std::string &fileName);
void updateAll();
private:
HttpRequest m_httpRequest = HttpRequest("GET", "");

View File

@ -52,6 +52,16 @@ namespace hex::plugin::builtin {
ThemeManager::addTheme(themeFile.readString());
});
addCategory("hex.builtin.view.store.tab.yara", "yara", &paths::Yara);
TaskManager::doLater([this] {
// Force update all installed items after an update so that there's no old and incompatible versions around anymore
{
const auto prevUpdateVersion = ContentRegistry::Settings::read<std::string>("hex.builtin.setting.general", "hex.builtin.setting.general.prev_launch_version", "");
if (prevUpdateVersion != ImHexApi::System::getImHexVersion()) {
updateAll();
}
}
});
}
@ -197,28 +207,7 @@ namespace hex::plugin::builtin {
ImGui::SameLine(ImGui::GetWindowWidth() - ImGui::GetCursorPosX() - 25_scaled);
ImGui::BeginDisabled(m_updateAllTask.isRunning() || m_updateCount == 0);
if (ImGuiExt::IconButton(ICON_VS_CLOUD_DOWNLOAD, ImGui::GetStyleColorVec4(ImGuiCol_Text))) {
m_updateAllTask = TaskManager::createTask("hex.builtin.task.updating_store"_lang, m_updateCount, [this](auto &task) {
for (auto &category : m_categories) {
for (auto &entry : category.entries) {
if (entry.hasUpdate) {
entry.downloading = this->download(category.path, entry.fileName, entry.link);
if (!m_download.valid())
continue;
m_download.wait();
while (m_download.valid() && m_download.wait_for(100ms) != std::future_status::ready) {
task.update();
}
entry.hasUpdate = false;
entry.downloading = false;
task.increment();
}
}
}
});
this->updateAll();
}
ImGuiExt::InfoTooltip(hex::format("hex.builtin.view.store.update_count"_lang, m_updateCount.load()).c_str());
@ -346,6 +335,36 @@ namespace hex::plugin::builtin {
return removed;
}
void ViewStore::updateAll() {
m_updateAllTask = TaskManager::createTask("hex.builtin.task.updating_store"_lang, m_updateCount, [this](auto &task) {
for (auto &category : m_categories) {
for (auto &entry : category.entries) {
if (entry.hasUpdate) {
entry.downloading = this->download(category.path, entry.fileName, entry.link);
if (!m_download.valid())
continue;
m_download.wait();
while (m_download.valid() && m_download.wait_for(100ms) != std::future_status::ready) {
task.update();
}
entry.hasUpdate = false;
entry.downloading = false;
task.increment();
}
}
}
TaskManager::doLater([] {
ContentRegistry::Settings::write<std::string>("hex.builtin.setting.general", "hex.builtin.setting.general.prev_launch_version", ImHexApi::System::getImHexVersion());
});
});
}
void ViewStore::addCategory(const UnlocalizedString &unlocalizedName, const std::string &requestName, const paths::impl::DefaultPath *path, std::function<void()> downloadCallback) {
m_categories.push_back({ unlocalizedName, requestName, path, { }, std::move(downloadCallback) });
}