From 1f6ce2fc67d9262bb4d3c896f243eb9bb704a23b Mon Sep 17 00:00:00 2001 From: nishinji <107111782+nishinji@users.noreply.github.com> Date: Fri, 4 Oct 2024 03:57:50 +0900 Subject: [PATCH] gui/pkg_install_dialog: Allow license files to be automatically selected if it is already exist (#3370) Co-authored-by: bookmist --- vita3k/gui/src/pkg_install_dialog.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/vita3k/gui/src/pkg_install_dialog.cpp b/vita3k/gui/src/pkg_install_dialog.cpp index 048c0a61d1..3d32843ed6 100644 --- a/vita3k/gui/src/pkg_install_dialog.cpp +++ b/vita3k/gui/src/pkg_install_dialog.cpp @@ -48,9 +48,23 @@ void draw_pkg_install_dialog(GuiState &gui, EmuEnvState &emuenv) { if (draw_file_dialog) { result = host::dialog::filesystem::open_file(pkg_path, { { "PlayStation Store Downloaded Package", { "pkg" } } }); draw_file_dialog = false; - if (result == host::dialog::filesystem::Result::SUCCESS) - ImGui::OpenPopup("install"); - else if (result == host::dialog::filesystem::Result::CANCEL) { + if (result == host::dialog::filesystem::Result::SUCCESS) { + fs::ifstream infile(pkg_path.native(), std::ios::binary); + PkgHeader pkg_header{}; + infile.read(reinterpret_cast(&pkg_header), sizeof(PkgHeader)); + std::string title_id_str(pkg_header.content_id); + std::string title_id = title_id_str.substr(7, 9); + const auto work_path{ emuenv.pref_path / fmt::format("ux0/license/{}/{}.rif", title_id, pkg_header.content_id) }; + if (fs::exists(work_path)) { + LOG_INFO("Found license file: {}", work_path); + fs::ifstream binfile(work_path, std::ios::in | std::ios::binary | std::ios::ate); + zRIF = rif2zrif(binfile); + ImGui::OpenPopup("install"); + gui::state = "install"; + } else { + ImGui::OpenPopup("install"); + } + } else if (result == host::dialog::filesystem::Result::CANCEL) { gui.file_menu.pkg_install_dialog = false; draw_file_dialog = true; } else {