[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,33 +1138,35 @@ 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);
}); });
for (auto& zarchive_file_path : zarchive_files) { auto run = [this, extract_dir, zarchive_files]() -> void {
// Normalize the path and make absolute. std::string summary = "";
auto abs_path = std::filesystem::absolute(zarchive_file_path);
std::filesystem::path abs_extract_dir;
if (zarchive_files.size() > 1) { for (auto& zarchive_file_path : zarchive_files) {
abs_extract_dir = // Normalize the path and make absolute.
std::filesystem::absolute((extract_dir / abs_path.stem())); auto abs_path = std::filesystem::absolute(zarchive_file_path);
} else { std::filesystem::path abs_extract_dir;
abs_extract_dir = std::filesystem::absolute(extract_dir);
}
XELOGI("Extracting zar package: {}\n", if (zarchive_files.size() > 1) {
zarchive_file_path.filename().string()); abs_extract_dir =
std::filesystem::absolute((extract_dir / abs_path.stem()));
} else {
abs_extract_dir = std::filesystem::absolute(extract_dir);
}
XELOGI("Extracting zar package: {}\n",
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);
summary +=
fmt::format("\nFailed: {}", path_to_utf8(zarchive_file_path));
XELOGE("Failed to extract Zarchive package.", result); XELOGE("Failed to extract Zarchive package.", result);
} else {
xe::ui::ImGuiDialog::ShowMessageBox( summary += fmt::format("\nSuccess: {}", path_to_utf8(abs_extract_dir));
imgui_drawer_.get(), "Failed to extract Zarchive package.",
"Failed to extract Zarchive package.");
} }
}; }
auto thd = std::thread(run); new xe::ui::HostNotificationWindow(imgui_drawer(), "Zar Extraction Summary",
thd.detach(); string_util::trim(summary), 0);
} };
auto zarThread = std::thread(run);
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);
}); });
for (auto const& [content_path, zarchive_file] : zarchive_files) { auto run = [this, zarchive_files]() -> void {
// Normalize the path and make absolute. std::string summary = "";
auto abs_content_dir = std::filesystem::absolute(content_path);
XELOGI("Creating zar package: {}\n", zarchive_file.filename().string()); for (auto const& [content_path, zarchive_file] : zarchive_files) {
// Normalize the path and make absolute.
auto abs_content_dir = std::filesystem::absolute(content_path);
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);
summary += fmt::format("\nFailed: {}", path_to_utf8(abs_content_dir));
XELOGE("Failed to create Zarchive package.", result); XELOGE("Failed to create Zarchive package.", result);
} else {
xe::ui::ImGuiDialog::ShowMessageBox( summary += fmt::format("\nSuccess: {}", path_to_utf8(zarchive_file));
imgui_drawer_.get(), "Failed to create Zarchive package.",
"Failed to create Zarchive package.");
} }
}; }
auto thd = std::thread(run); new xe::ui::HostNotificationWindow(imgui_drawer(), "Zar Creation Summary",
thd.detach(); string_util::trim(summary), 0);
} };
auto zarThread = std::thread(run);
zarThread.detach();
} }
void EmulatorWindow::ShowContentDirectory() { void EmulatorWindow::ShowContentDirectory() {