| 273 | } |
| 274 | |
| 275 | bool InstallLayout::StartInstall(const std::string &path, const std::string &pres_path, fs::Explorer *exp, const NcmStorageId storage_id, const bool omit_confirmation, const bool skip_if_already_installed) { |
| 276 | g_MainApplication->LoadCommonIconMenuData(true, cfg::Strings.GetString(77), CommonIconKind::Storage, cfg::Strings.GetString(145) + " " + pres_path); |
| 277 | ScopeGuard on_exit([&]() { |
| 278 | // Just in case |
| 279 | cnt::NotifyApplicationsChanged(); |
| 280 | g_MainApplication->GetApplicationListLayout()->NotifyApplicationsChanged(); |
| 281 | g_MainApplication->ReturnToParentLayout(); |
| 282 | }); |
| 283 | |
| 284 | nsp::Installer nsp_installer(path, exp, storage_id); |
| 285 | |
| 286 | auto rc = nsp_installer.PrepareInstallation(); |
| 287 | if(R_FAILED(rc)) { |
| 288 | if(rc == rc::goldleaf::ResultContentAlreadyInstalled) { |
| 289 | if(skip_if_already_installed) { |
| 290 | return false; |
| 291 | } |
| 292 | |
| 293 | const auto option = g_MainApplication->DisplayDialog(cfg::Strings.GetString(77), cfg::Strings.GetString(272) + "\n" + cfg::Strings.GetString(273) + "\n" + cfg::Strings.GetString(274), { cfg::Strings.GetString(111), cfg::Strings.GetString(18) }, true); |
| 294 | if(option == 0) { |
| 295 | for(const auto &program: nsp_installer.GetInstallablePrograms()) { |
| 296 | const auto program_id = program.meta_key.id; |
| 297 | GLEAF_WARN_FMT("Checking program %016lX...", program_id); |
| 298 | const auto program_app = cnt::ExistsApplicationContent(program_id, static_cast<NcmContentMetaType>(program.meta_key.type)); |
| 299 | if(program_app.has_value()) { |
| 300 | GLEAF_WARN_FMT("Removing program %016lX...", program_id); |
| 301 | const auto &cnt_status = program_app.value().get().meta_status_list; |
| 302 | const auto cnt_it = std::find_if(cnt_status.begin(), cnt_status.end(), [&](const NsApplicationContentMetaStatus &cnt_status) -> bool { |
| 303 | return cnt_status.application_id == program_id; |
| 304 | }); |
| 305 | if(cnt_it != cnt_status.end()) { |
| 306 | GLEAF_WARN_FMT("Removing program %016lX actually...", program_id); |
| 307 | const auto cnt_idx = std::distance(cnt_status.begin(), cnt_it); |
| 308 | cnt::RemoveApplicationContentById(program_app.value().get(), cnt_idx); |
| 309 | } |
| 310 | } |
| 311 | } |
| 312 | nsp_installer.FinalizeInstallation(); |
| 313 | rc = nsp_installer.PrepareInstallation(); |
| 314 | if(R_FAILED(rc)) { |
| 315 | HandleResult(rc, cfg::Strings.GetString(251)); |
| 316 | return false; |
| 317 | } |
| 318 | } |
| 319 | else { |
| 320 | return false; |
| 321 | } |
| 322 | } |
| 323 | else { |
| 324 | HandleResult(rc, cfg::Strings.GetString(251)); |
| 325 | return false; |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | auto do_install = false; |
| 330 | if(omit_confirmation) { |
| 331 | do_install = true; |
| 332 | } |
no test coverage detected