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,10 +715,19 @@ 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()) {
|
||||||
|
auto status = extractionTask->wait_for(std::chrono::milliseconds(0));
|
||||||
|
if (status == std::future_status::ready) {
|
||||||
|
try {
|
||||||
|
extractionTask->get();
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
SohGui::RegisterPopup("Extraction Crashed", e.what(), "Close", "", []() { exit(1); });
|
||||||
|
}
|
||||||
|
extractionTask.reset();
|
||||||
|
} else {
|
||||||
|
if (!ImGui::IsPopupOpen("ROM Extraction")) {
|
||||||
ImGui::OpenPopup("ROM Extraction");
|
ImGui::OpenPopup("ROM Extraction");
|
||||||
}
|
}
|
||||||
if (extracting) {
|
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10.0f, 8.0f));
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10.0f, 8.0f));
|
||||||
auto color = UIWidgets::ColorValues.at(THEME_COLOR);
|
auto color = UIWidgets::ColorValues.at(THEME_COLOR);
|
||||||
@@ -747,6 +749,7 @@ void OTRGlobals::RunExtract(int argc, char* argv[]) {
|
|||||||
ImGui::PopStyleColor(3);
|
ImGui::PopStyleColor(3);
|
||||||
ImGui::PopStyleVar(2);
|
ImGui::PopStyleVar(2);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
gui->EndDraw();
|
gui->EndDraw();
|
||||||
sohFast3dWindow->EndFrame();
|
sohFast3dWindow->EndFrame();
|
||||||
ImGui::PopStyleColor(2);
|
ImGui::PopStyleColor(2);
|
||||||
|
|||||||
Reference in New Issue
Block a user