| 2306 | } |
| 2307 | |
| 2308 | static bool installIso(JNIEnv *env, fs::file &&file, jlong progressId) { |
| 2309 | auto optIso = iso_dev::open(std::make_unique<file_view_block_dev>(file)); |
| 2310 | Progress progress(env, progressId); |
| 2311 | |
| 2312 | if (!optIso) { |
| 2313 | progress.failure("Failed to read ISO"); |
| 2314 | return false; |
| 2315 | } |
| 2316 | |
| 2317 | auto iso = std::move(*optIso); |
| 2318 | auto sfo_raw_file = iso.open("PS3_GAME/PARAM.SFO", fs::read); |
| 2319 | |
| 2320 | if (!sfo_raw_file) { |
| 2321 | progress.failure("Failed to locate PARAM.SFO in ISO"); |
| 2322 | return false; |
| 2323 | } |
| 2324 | |
| 2325 | fs::file sfo_file; |
| 2326 | sfo_file.reset(std::move(sfo_raw_file)); |
| 2327 | |
| 2328 | auto sfo = psf::load_object(sfo_file, "iso://PS3_GAME/PARAM.SFO"); |
| 2329 | auto title_id = psf::get_string(sfo, "TITLE_ID"); |
| 2330 | |
| 2331 | if (title_id.empty()) { |
| 2332 | progress.failure("Failed to fetch TITLE_ID from PARAM.SFO in ISO"); |
| 2333 | return false; |
| 2334 | } |
| 2335 | |
| 2336 | if (auto gameInfo = fetchGameInfo(sfo)) { |
| 2337 | sendGameInfo(env, progressId, {{*gameInfo}}); |
| 2338 | } |
| 2339 | |
| 2340 | std::filesystem::path destinationPath = |
| 2341 | fs::get_config_dir() + "games/" + std::string(title_id); |
| 2342 | std::size_t filesCount = 0; |
| 2343 | |
| 2344 | auto roots = [&] { |
| 2345 | std::vector<std::filesystem::path> result; |
| 2346 | std::vector<std::filesystem::path> workList; |
| 2347 | workList.push_back({}); |
| 2348 | result.push_back({}); |
| 2349 | |
| 2350 | while (!workList.empty()) { |
| 2351 | auto path = std::move(workList.back()); |
| 2352 | workList.pop_back(); |
| 2353 | |
| 2354 | fs::dir dir; |
| 2355 | dir.reset(iso.open_dir(path)); |
| 2356 | |
| 2357 | for (auto &entry : dir) { |
| 2358 | if (entry.name == "." || entry.name == "..") { |
| 2359 | continue; |
| 2360 | } |
| 2361 | if (entry.name == "PS3_UPDATE" && path.empty()) { |
| 2362 | continue; |
| 2363 | } |
| 2364 | |
| 2365 | if (entry.is_directory) { |
no test coverage detected