| 2011 | } |
| 2012 | |
| 2013 | static bool installPup(JNIEnv *env, fs::file &&pup_f, jlong progressId) { |
| 2014 | Progress progress(env, progressId); |
| 2015 | |
| 2016 | pup_object pup(std::move(pup_f)); |
| 2017 | AtExit atExit{[&] { pup.file().release_handle(); }}; |
| 2018 | |
| 2019 | if (static_cast<pup_error>(pup) == pup_error::hash_mismatch) { |
| 2020 | rpcsx_android.fatal("installFw: invalid PUP"); |
| 2021 | progress.failure("Selected file is not firmware update file"); |
| 2022 | return false; |
| 2023 | } |
| 2024 | |
| 2025 | if (static_cast<pup_error>(pup) != pup_error::ok) { |
| 2026 | rpcsx_android.fatal("installFw: invalid PUP"); |
| 2027 | progress.failure("Firmware update file is broken"); |
| 2028 | return false; |
| 2029 | } |
| 2030 | |
| 2031 | fs::file update_files_f = pup.get_file(0x300); |
| 2032 | |
| 2033 | const usz update_files_size = update_files_f ? update_files_f.size() : 0; |
| 2034 | |
| 2035 | if (!update_files_size) { |
| 2036 | rpcsx_android.fatal("installFw: invalid PUP"); |
| 2037 | progress.failure("Firmware update file is broken"); |
| 2038 | return false; |
| 2039 | } |
| 2040 | |
| 2041 | tar_object update_files(update_files_f); |
| 2042 | |
| 2043 | auto update_filenames = update_files.get_filenames(); |
| 2044 | update_filenames.erase(std::remove_if(update_filenames.begin(), |
| 2045 | update_filenames.end(), |
| 2046 | [](const std::string &s) { |
| 2047 | return !s.starts_with("dev_flash_"); |
| 2048 | }), |
| 2049 | update_filenames.end()); |
| 2050 | |
| 2051 | if (update_filenames.empty()) { |
| 2052 | rpcsx_android.fatal("installFw: invalid PUP"); |
| 2053 | progress.failure("Firmware update file is broken"); |
| 2054 | return false; |
| 2055 | } |
| 2056 | |
| 2057 | std::string version_string; |
| 2058 | |
| 2059 | if (fs::file version = pup.get_file(0x100)) { |
| 2060 | version_string = version.to_string(); |
| 2061 | } |
| 2062 | |
| 2063 | if (const usz version_pos = version_string.find('\n'); |
| 2064 | version_pos != std::string::npos) { |
| 2065 | version_string.erase(version_pos); |
| 2066 | } |
| 2067 | |
| 2068 | if (version_string.empty()) { |
| 2069 | rpcsx_android.fatal("installFw: invalid PUP"); |
| 2070 | progress.failure("Firmware update file is broken"); |
no test coverage detected