extraction: detect task crashing (#6386)
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
#include "ResourceManagerHelpers.h"
|
#include "ResourceManagerHelpers.h"
|
||||||
#include <fast/Fast3dWindow.h>
|
#include <fast/Fast3dWindow.h>
|
||||||
@@ -408,7 +409,6 @@ void OTRGlobals::RunExtract(int argc, char* argv[]) {
|
|||||||
Extractor extract;
|
Extractor extract;
|
||||||
PromptSteps promptStep = PS_FILE_CHECK;
|
PromptSteps promptStep = PS_FILE_CHECK;
|
||||||
bool generatedIsMQ = false;
|
bool generatedIsMQ = false;
|
||||||
std::atomic<bool> extracting = false;
|
|
||||||
std::atomic<size_t> extractCount = 0, totalExtract = 0;
|
std::atomic<size_t> extractCount = 0, totalExtract = 0;
|
||||||
|
|
||||||
std::string installPath = Ship::Context::GetAppBundlePath();
|
std::string installPath = Ship::Context::GetAppBundlePath();
|
||||||
@@ -444,8 +444,9 @@ void OTRGlobals::RunExtract(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<BS::thread_pool> threadPool = std::make_shared<BS::thread_pool>(1);
|
std::shared_ptr<BS::thread_pool> threadPool = std::make_shared<BS::thread_pool>(1);
|
||||||
|
std::optional<std::future<void>> extractionTask;
|
||||||
while (!extractDone) {
|
while (!extractDone) {
|
||||||
if (SohGui::PopupsQueued() > 0 || extracting) {
|
if (SohGui::PopupsQueued() > 0 || extractionTask.has_value()) {
|
||||||
goto render;
|
goto render;
|
||||||
}
|
}
|
||||||
switch (extractStep) {
|
switch (extractStep) {
|
||||||
@@ -582,20 +583,16 @@ void OTRGlobals::RunExtract(int argc, char* argv[]) {
|
|||||||
if (std::filesystem::exists(Ship::Context::GetAppDirectoryPath(appShortName) + "/" + archive)) {
|
if (std::filesystem::exists(Ship::Context::GetAppDirectoryPath(appShortName) + "/" + archive)) {
|
||||||
std::string msg = "Archive for current ROM, " + archive + ", already exists.\nExtract again?";
|
std::string msg = "Archive for current ROM, " + archive + ", already exists.\nExtract again?";
|
||||||
SohGui::RegisterPopup("Confirm Re-extract", msg.c_str(), "Yes", "No", [&]() {
|
SohGui::RegisterPopup("Confirm Re-extract", msg.c_str(), "Yes", "No", [&]() {
|
||||||
extracting = true;
|
extractionTask = threadPool->submit_task([&]() -> void {
|
||||||
threadPool->submit_task([&]() -> void {
|
|
||||||
extract.CallZapd(installPath, Ship::Context::GetAppDirectoryPath(appShortName),
|
extract.CallZapd(installPath, Ship::Context::GetAppDirectoryPath(appShortName),
|
||||||
&extractCount, &totalExtract);
|
&extractCount, &totalExtract);
|
||||||
extracting = false;
|
|
||||||
extractCount = totalExtract = 0;
|
extractCount = totalExtract = 0;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
extracting = true;
|
extractionTask = threadPool->submit_task([&]() -> void {
|
||||||
threadPool->submit_task([&]() -> void {
|
|
||||||
extract.CallZapd(installPath, Ship::Context::GetAppDirectoryPath(appShortName),
|
extract.CallZapd(installPath, Ship::Context::GetAppDirectoryPath(appShortName),
|
||||||
&extractCount, &totalExtract);
|
&extractCount, &totalExtract);
|
||||||
extracting = false;
|
|
||||||
extractCount = totalExtract = 0;
|
extractCount = totalExtract = 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -648,12 +645,10 @@ void OTRGlobals::RunExtract(int argc, char* argv[]) {
|
|||||||
promptStep = PS_FILE_CHECK;
|
promptStep = PS_FILE_CHECK;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
extracting = true;
|
extractionTask = threadPool->submit_task([&]() -> void {
|
||||||
threadPool->submit_task([&]() -> void {
|
|
||||||
extract.CallZapd(installPath, Ship::Context::GetAppDirectoryPath(appShortName),
|
extract.CallZapd(installPath, Ship::Context::GetAppDirectoryPath(appShortName),
|
||||||
&extractCount, &totalExtract);
|
&extractCount, &totalExtract);
|
||||||
generatedIsMQ = extract.IsMasterQuest();
|
generatedIsMQ = extract.IsMasterQuest();
|
||||||
extracting = false;
|
|
||||||
promptStep = PS_SECOND;
|
promptStep = PS_SECOND;
|
||||||
extractCount = 0;
|
extractCount = 0;
|
||||||
totalExtract = 0;
|
totalExtract = 0;
|
||||||
@@ -668,11 +663,9 @@ void OTRGlobals::RunExtract(int argc, char* argv[]) {
|
|||||||
: RomSearchMode::MQ)) {
|
: RomSearchMode::MQ)) {
|
||||||
extractStep = ES_VERIFY;
|
extractStep = ES_VERIFY;
|
||||||
} else {
|
} else {
|
||||||
extracting = true;
|
extractionTask = threadPool->submit_task([&]() -> void {
|
||||||
threadPool->submit_task([&]() -> void {
|
|
||||||
extract.CallZapd(installPath, Ship::Context::GetAppDirectoryPath(appShortName),
|
extract.CallZapd(installPath, Ship::Context::GetAppDirectoryPath(appShortName),
|
||||||
&extractCount, &totalExtract);
|
&extractCount, &totalExtract);
|
||||||
extracting = false;
|
|
||||||
extractStep = ES_VERIFY;
|
extractStep = ES_VERIFY;
|
||||||
extractCount = 0;
|
extractCount = 0;
|
||||||
totalExtract = 0;
|
totalExtract = 0;
|
||||||
@@ -722,30 +715,40 @@ void OTRGlobals::RunExtract(int argc, char* argv[]) {
|
|||||||
gui->StartDraw();
|
gui->StartDraw();
|
||||||
sohFast3dWindow->StartFrame();
|
sohFast3dWindow->StartFrame();
|
||||||
sohFast3dWindow->RunGuiOnly();
|
sohFast3dWindow->RunGuiOnly();
|
||||||
if (extracting && !ImGui::IsPopupOpen("ROM Extraction")) {
|
if (extractionTask.has_value()) {
|
||||||
ImGui::OpenPopup("ROM Extraction");
|
auto status = extractionTask->wait_for(std::chrono::milliseconds(0));
|
||||||
}
|
if (status == std::future_status::ready) {
|
||||||
if (extracting) {
|
try {
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
extractionTask->get();
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10.0f, 8.0f));
|
} catch (const std::exception& e) {
|
||||||
auto color = UIWidgets::ColorValues.at(THEME_COLOR);
|
SohGui::RegisterPopup("Extraction Crashed", e.what(), "Close", "", []() { exit(1); });
|
||||||
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(color.x, color.y, color.z, 0.6f));
|
}
|
||||||
ImGui::PushStyleColor(ImGuiCol_PlotHistogram, ImVec4(color.x, color.y, color.z, 1.0f));
|
extractionTask.reset();
|
||||||
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0.0f, 0.0f, 0.0f, 0.3f));
|
} else {
|
||||||
if (ImGui::BeginPopupModal("ROM Extraction", NULL,
|
if (!ImGui::IsPopupOpen("ROM Extraction")) {
|
||||||
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize |
|
ImGui::OpenPopup("ROM Extraction");
|
||||||
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar |
|
}
|
||||||
ImGuiWindowFlags_NoSavedSettings)) {
|
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
||||||
float progress = (totalExtract > 0.0f ? (float)extractCount / (float)totalExtract : 0) * 100.0f;
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10.0f, 8.0f));
|
||||||
auto filename = std::filesystem::path(file).filename().string();
|
auto color = UIWidgets::ColorValues.at(THEME_COLOR);
|
||||||
ImGui::Text("Extracting %s...%s", filename.c_str(),
|
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(color.x, color.y, color.z, 0.6f));
|
||||||
roundf(progress) == 100.0f ? " Done. Finishing up." : "");
|
ImGui::PushStyleColor(ImGuiCol_PlotHistogram, ImVec4(color.x, color.y, color.z, 1.0f));
|
||||||
std::string overlay = extractCount > 0 ? fmt::format("{:.0f}%", progress) : "Starting Up";
|
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0.0f, 0.0f, 0.0f, 0.3f));
|
||||||
ImGui::ProgressBar(progress / 100.0f, ImVec2(600.0f, 50.0f), overlay.c_str());
|
if (ImGui::BeginPopupModal("ROM Extraction", NULL,
|
||||||
ImGui::EndPopup();
|
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize |
|
||||||
|
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar |
|
||||||
|
ImGuiWindowFlags_NoSavedSettings)) {
|
||||||
|
float progress = (totalExtract > 0.0f ? (float)extractCount / (float)totalExtract : 0) * 100.0f;
|
||||||
|
auto filename = std::filesystem::path(file).filename().string();
|
||||||
|
ImGui::Text("Extracting %s...%s", filename.c_str(),
|
||||||
|
roundf(progress) == 100.0f ? " Done. Finishing up." : "");
|
||||||
|
std::string overlay = extractCount > 0 ? fmt::format("{:.0f}%", progress) : "Starting Up";
|
||||||
|
ImGui::ProgressBar(progress / 100.0f, ImVec2(600.0f, 50.0f), overlay.c_str());
|
||||||
|
ImGui::EndPopup();
|
||||||
|
}
|
||||||
|
ImGui::PopStyleColor(3);
|
||||||
|
ImGui::PopStyleVar(2);
|
||||||
}
|
}
|
||||||
ImGui::PopStyleColor(3);
|
|
||||||
ImGui::PopStyleVar(2);
|
|
||||||
}
|
}
|
||||||
gui->EndDraw();
|
gui->EndDraw();
|
||||||
sohFast3dWindow->EndFrame();
|
sohFast3dWindow->EndFrame();
|
||||||
|
|||||||
Reference in New Issue
Block a user