| 1311 | } |
| 1312 | |
| 1313 | void EventManagerMain(void*) { |
| 1314 | UL_LOG_INFO("[EventManager] alive!"); |
| 1315 | |
| 1316 | Event record_ev; |
| 1317 | UL_RC_ASSERT(nsGetApplicationRecordUpdateSystemEvent(&record_ev)); |
| 1318 | UL_LOG_INFO("[EventManager] registered ApplicationRecordUpdateSystemEvent"); |
| 1319 | |
| 1320 | Event gc_mount_fail_event; |
| 1321 | if(hosversionAtLeast(3,0,0)) { |
| 1322 | UL_RC_ASSERT(nsGetGameCardMountFailureEvent(&gc_mount_fail_event)); |
| 1323 | UL_LOG_INFO("[EventManager] registered GameCardMountFailureEvent"); |
| 1324 | } |
| 1325 | else { |
| 1326 | UL_LOG_INFO("[EventManager] cannot register GameCardMountFailureEvent, unsuported by firmware!"); |
| 1327 | } |
| 1328 | |
| 1329 | s32 ev_idx; |
| 1330 | while(true) { |
| 1331 | auto wait_rc = ul::ResultSuccess; |
| 1332 | if(hosversionAtLeast(3,0,0)) { |
| 1333 | wait_rc = waitMulti(&ev_idx, UINT64_MAX, waiterForEvent(&record_ev), waiterForEvent(&gc_mount_fail_event)); |
| 1334 | } |
| 1335 | else { |
| 1336 | wait_rc = waitMulti(&ev_idx, UINT64_MAX, waiterForEvent(&record_ev)); |
| 1337 | } |
| 1338 | |
| 1339 | if(R_SUCCEEDED(wait_rc)) { |
| 1340 | if(ev_idx == 0) { |
| 1341 | ul::ScopedLock lock(g_CurrentRecordsLock); |
| 1342 | ul::ScopedLock lock2(g_LastDeletedApplicationsLock); |
| 1343 | ul::ScopedLock lock3(g_LastAddedApplicationsLock); |
| 1344 | g_LastAddedApplications.clear(); |
| 1345 | g_LastDeletedApplications.clear(); |
| 1346 | UL_LOG_INFO("[EventManager] Application records changed!"); |
| 1347 | |
| 1348 | std::vector<AccountUid> uids; |
| 1349 | UL_RC_ASSERT(accountInitialize(AccountServiceType_System)); |
| 1350 | UL_RC_ASSERT(ul::acc::ListAccounts(uids)); |
| 1351 | accountExit(); |
| 1352 | |
| 1353 | const auto old_records = std::move(g_CurrentRecords); |
| 1354 | g_CurrentRecords = ul::os::ListApplicationRecords(); |
| 1355 | |
| 1356 | const auto added_records = ListAddedRecords(old_records, g_CurrentRecords); |
| 1357 | for(const auto &record: added_records) { |
| 1358 | UL_LOG_INFO("[EventManager] > Added application 0x%016lX, caching it...", record.id); |
| 1359 | g_LastAddedApplications.push_back(record.id); |
| 1360 | ul::system::app::RequestCacheApplication(record.id); |
| 1361 | |
| 1362 | for(const auto &uid: uids) { |
| 1363 | const auto menu_path = ul::menu::MakeMenuPath(g_AmsIsEmuMMC, uid); |
| 1364 | UL_LOG_INFO("[EventManager] > Ensuring application ID 0x%016lX entry in user menu (%s)", record.id, menu_path.c_str()); |
| 1365 | ul::menu::EnsureApplicationEntry(record, menu_path); |
| 1366 | } |
| 1367 | } |
| 1368 | |
| 1369 | const auto removed_records = ListRemovedRecords(old_records, g_CurrentRecords); |
| 1370 | for(const auto &record: removed_records) { |
nothing calls this directly
no test coverage detected