| 1339 | } |
| 1340 | |
| 1341 | VMBootResult VMManager::Initialize(const VMBootParameters& boot_params, Error* error) |
| 1342 | { |
| 1343 | const Common::Timer init_timer; |
| 1344 | if (s_state.load(std::memory_order_acquire) != VMState::Shutdown) |
| 1345 | { |
| 1346 | Error::SetString(error, TRANSLATE_STR("VMManager", "The virtual machine is already running.")); |
| 1347 | return VMBootResult::StartupFailure; |
| 1348 | } |
| 1349 | |
| 1350 | // cancel any game list scanning, we need to use CDVD! |
| 1351 | // TODO: we can get rid of this once, we make CDVD not use globals... |
| 1352 | // (or make it thread-local, but that seems silly.) |
| 1353 | Host::CancelGameListRefresh(); |
| 1354 | |
| 1355 | s_state.store(VMState::Initializing, std::memory_order_release); |
| 1356 | s_vm_thread_handle = Threading::ThreadHandle::GetForCallingThread(); |
| 1357 | Host::OnVMStarting(); |
| 1358 | VMManager::Internal::ResetVMHotkeyState(); |
| 1359 | |
| 1360 | ScopedGuard close_state = [] { |
| 1361 | if (GSDumpReplayer::IsReplayingDump()) |
| 1362 | GSDumpReplayer::Shutdown(); |
| 1363 | |
| 1364 | s_elf_override = {}; |
| 1365 | ClearELFInfo(); |
| 1366 | ClearDiscDetails(); |
| 1367 | |
| 1368 | Achievements::GameChanged(0, 0); |
| 1369 | FullscreenUI::GameChanged(s_title, std::string(), s_disc_serial, 0, 0); |
| 1370 | UpdateDiscordPresence(true); |
| 1371 | Host::OnGameChanged(s_title, std::string(), std::string(), s_disc_serial, 0, 0); |
| 1372 | |
| 1373 | UpdateGameSettingsLayer(); |
| 1374 | s_state.store(VMState::Shutdown, std::memory_order_release); |
| 1375 | Host::OnVMDestroyed(); |
| 1376 | ApplySettings(); |
| 1377 | }; |
| 1378 | |
| 1379 | std::string state_to_load; |
| 1380 | |
| 1381 | s_elf_override = boot_params.elf_override; |
| 1382 | if (!boot_params.save_state.empty()) |
| 1383 | state_to_load = boot_params.save_state; |
| 1384 | |
| 1385 | // if we're loading an indexed save state, we need to get the serial/crc from the disc. |
| 1386 | if (boot_params.state_index.has_value()) |
| 1387 | { |
| 1388 | if (boot_params.filename.empty()) |
| 1389 | { |
| 1390 | Error::SetString(error, |
| 1391 | TRANSLATE_STR("VMManager", "Cannot load an indexed save state without a boot filename.")); |
| 1392 | return VMBootResult::StartupFailure; |
| 1393 | } |
| 1394 | |
| 1395 | state_to_load = GetSaveStateFileName(boot_params.filename.c_str(), boot_params.state_index.value()); |
| 1396 | if (state_to_load.empty()) |
| 1397 | { |
| 1398 | Error::SetString(error, |
nothing calls this directly
no test coverage detected