[App] Added host notification for Zar creation and extraction on completion

This commit is contained in:
Adrian 2024-08-25 11:20:59 +01:00 committed by Radosław Gliński
parent f01317591a
commit ee210db096
1 changed files with 51 additions and 40 deletions

View File

@ -1138,17 +1138,20 @@ void EmulatorWindow::ExtractZarchive() {
return; return;
} }
std::string overview = ""; std::string extract_overview = "";
for (auto& zarchive_file_path : zarchive_files) { for (auto& zarchive_file_path : zarchive_files) {
overview += "\n" + path_to_utf8(zarchive_file_path); extract_overview += "\n" + path_to_utf8(zarchive_file_path);
} }
app_context_.CallInUIThread([&]() { app_context_.CallInUIThread([&]() {
new xe::ui::HostNotificationWindow(imgui_drawer(), "Extracting...", new xe::ui::HostNotificationWindow(imgui_drawer(), "Extracting...",
string_util::trim(overview), 0); string_util::trim(extract_overview), 0);
}); });
auto run = [this, extract_dir, zarchive_files]() -> void {
std::string summary = "";
for (auto& zarchive_file_path : zarchive_files) { for (auto& zarchive_file_path : zarchive_files) {
// Normalize the path and make absolute. // Normalize the path and make absolute.
auto abs_path = std::filesystem::absolute(zarchive_file_path); auto abs_path = std::filesystem::absolute(zarchive_file_path);
@ -1164,7 +1167,6 @@ void EmulatorWindow::ExtractZarchive() {
XELOGI("Extracting zar package: {}\n", XELOGI("Extracting zar package: {}\n",
zarchive_file_path.filename().string()); zarchive_file_path.filename().string());
auto run = [this, abs_path, abs_extract_dir]() -> void {
auto result = auto result =
emulator_->ExtractZarchivePackage(abs_path, abs_extract_dir); emulator_->ExtractZarchivePackage(abs_path, abs_extract_dir);
@ -1174,17 +1176,21 @@ void EmulatorWindow::ExtractZarchive() {
// delete incomplete output file // delete incomplete output file
std::filesystem::remove(abs_extract_dir, ec); std::filesystem::remove(abs_extract_dir, ec);
XELOGE("Failed to extract Zarchive package.", result); summary +=
fmt::format("\nFailed: {}", path_to_utf8(zarchive_file_path));
xe::ui::ImGuiDialog::ShowMessageBox( XELOGE("Failed to extract Zarchive package.", result);
imgui_drawer_.get(), "Failed to extract Zarchive package.", } else {
"Failed to extract Zarchive package."); summary += fmt::format("\nSuccess: {}", path_to_utf8(abs_extract_dir));
} }
}
new xe::ui::HostNotificationWindow(imgui_drawer(), "Zar Extraction Summary",
string_util::trim(summary), 0);
}; };
auto thd = std::thread(run); auto zarThread = std::thread(run);
thd.detach(); zarThread.detach();
}
} }
void EmulatorWindow::CreateZarchive() { void EmulatorWindow::CreateZarchive() {
@ -1227,7 +1233,7 @@ void EmulatorWindow::CreateZarchive() {
return; return;
} }
std::string overview = ""; std::string create_overview = "";
std::map<std::filesystem::path, std::filesystem::path> zarchive_files{}; std::map<std::filesystem::path, std::filesystem::path> zarchive_files{};
@ -1245,21 +1251,23 @@ void EmulatorWindow::CreateZarchive() {
zarchive_files[content_path] = abs_zarchive_file; zarchive_files[content_path] = abs_zarchive_file;
overview += "\n" + path_to_utf8(abs_zarchive_file); create_overview += "\n" + path_to_utf8(abs_zarchive_file);
} }
app_context_.CallInUIThread([&]() { app_context_.CallInUIThread([&]() {
new xe::ui::HostNotificationWindow(imgui_drawer(), "Creating...", new xe::ui::HostNotificationWindow(imgui_drawer(), "Creating...",
string_util::trim(overview), 0); string_util::trim(create_overview), 0);
}); });
auto run = [this, zarchive_files]() -> void {
std::string summary = "";
for (auto const& [content_path, zarchive_file] : zarchive_files) { for (auto const& [content_path, zarchive_file] : zarchive_files) {
// Normalize the path and make absolute. // Normalize the path and make absolute.
auto abs_content_dir = std::filesystem::absolute(content_path); auto abs_content_dir = std::filesystem::absolute(content_path);
XELOGI("Creating zar package: {}\n", zarchive_file.filename().string()); XELOGI("Creating zar package: {}\n", zarchive_file.filename().string());
auto run = [this, abs_content_dir, zarchive_file]() -> void {
auto result = auto result =
emulator_->CreateZarchivePackage(abs_content_dir, zarchive_file); emulator_->CreateZarchivePackage(abs_content_dir, zarchive_file);
@ -1269,17 +1277,20 @@ void EmulatorWindow::CreateZarchive() {
// delete incomplete output file // delete incomplete output file
std::filesystem::remove(zarchive_file, ec); std::filesystem::remove(zarchive_file, ec);
XELOGE("Failed to create Zarchive package.", result); summary += fmt::format("\nFailed: {}", path_to_utf8(abs_content_dir));
xe::ui::ImGuiDialog::ShowMessageBox( XELOGE("Failed to create Zarchive package.", result);
imgui_drawer_.get(), "Failed to create Zarchive package.", } else {
"Failed to create Zarchive package."); summary += fmt::format("\nSuccess: {}", path_to_utf8(zarchive_file));
} }
}
new xe::ui::HostNotificationWindow(imgui_drawer(), "Zar Creation Summary",
string_util::trim(summary), 0);
}; };
auto thd = std::thread(run); auto zarThread = std::thread(run);
thd.detach(); zarThread.detach();
}
} }
void EmulatorWindow::ShowContentDirectory() { void EmulatorWindow::ShowContentDirectory() {