| 2197 | } |
| 2198 | |
| 2199 | static bool installEdat(JNIEnv *env, fs::file &&file, jlong progressId, |
| 2200 | std::string_view rootPath = {}) { |
| 2201 | Progress progress(env, progressId); |
| 2202 | |
| 2203 | NPD_HEADER npdHeader; |
| 2204 | if (!file.read(npdHeader)) { |
| 2205 | progress.failure("Invalid EDAT file"); |
| 2206 | return false; |
| 2207 | } |
| 2208 | |
| 2209 | if (!rootPath.empty()) { |
| 2210 | auto ebootPath = locateEbootPath(rootPath); |
| 2211 | auto sfoPath = locateParamSfoPath(rootPath); |
| 2212 | |
| 2213 | if (sfoPath.empty()) { |
| 2214 | progress.failure("Game is broken: PARAM.SFO not found"); |
| 2215 | return false; |
| 2216 | } |
| 2217 | |
| 2218 | auto psf = psf::load_object(sfoPath); |
| 2219 | auto contentId = psf::get_string(psf, "CONTENT_ID"); |
| 2220 | |
| 2221 | if (contentId != npdHeader.content_id) { |
| 2222 | progress.failure(fmt::format("File cannot be used for this game. EDAT " |
| 2223 | "content ID missmatch %s vs %s", |
| 2224 | contentId, npdHeader.content_id)); |
| 2225 | return false; |
| 2226 | } |
| 2227 | } |
| 2228 | |
| 2229 | const auto licenseFile = |
| 2230 | fmt::format("%shome/%s/exdata/%s.edat", rpcs3::utils::get_hdd0_dir(), |
| 2231 | Emu.GetUsr(), npdHeader.content_id); |
| 2232 | |
| 2233 | file.seek(0); |
| 2234 | |
| 2235 | std::vector<std::uint8_t> bytes(file.size()); |
| 2236 | if (!file.read(bytes)) { |
| 2237 | progress.failure("Failed to read key"); |
| 2238 | return false; |
| 2239 | } |
| 2240 | |
| 2241 | if (!fs::write_file(licenseFile, fs::open_mode::create + fs::open_mode::trunc, |
| 2242 | bytes)) { |
| 2243 | progress.failure(fmt::format("Failed to write EDAT to %s", licenseFile)); |
| 2244 | return false; |
| 2245 | } |
| 2246 | |
| 2247 | auto root = std::string(rootPath); |
| 2248 | |
| 2249 | if (root.empty()) { |
| 2250 | root = rpcs3::utils::get_hdd0_dir() + "game"; |
| 2251 | } |
| 2252 | |
| 2253 | collectGameInfo(env, progressId, {std::move(root)}); |
| 2254 | return true; |
| 2255 | } |
| 2256 |
no test coverage detected