MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / DoSaveState

Method DoSaveState

pcsx2/VMManager.cpp:1919–1966  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1917}
1918
1919void VMManager::DoSaveState(const char* filename, s32 slot_for_message, bool zip_on_thread, bool backup_old_state, std::function<void(const std::string&)> error_callback)
1920{
1921 if (GSDumpReplayer::IsReplayingDump())
1922 {
1923 error_callback(TRANSLATE_STR("VMManager", "Cannot save state while replaying a GS dump."));
1924 return;
1925 }
1926
1927 Error error;
1928 std::unique_ptr<ArchiveEntryList> elist = SaveState_DownloadState(&error);
1929 if (!elist)
1930 {
1931 error_callback(error.GetDescription());
1932 return;
1933 }
1934
1935 std::unique_ptr<SaveStateScreenshotData> screenshot = SaveState_SaveScreenshot();
1936
1937 if (FileSystem::FileExists(filename) && backup_old_state)
1938 {
1939 const std::string backup_filename(fmt::format("{}.backup", filename));
1940 Console.WriteLn(fmt::format("Creating save state backup {}...", backup_filename));
1941 if (!FileSystem::RenamePath(filename, backup_filename.c_str()))
1942 {
1943 error_callback(fmt::format(
1944 TRANSLATE_FS("VMManager", "Cannot back up old save state '{}'."),
1945 Path::GetFileName(filename)));
1946 return;
1947 }
1948 }
1949
1950 if (zip_on_thread)
1951 {
1952 // lock order here is important; the thread could exit before we resume here.
1953 std::unique_lock lock(s_save_state_threads_mutex);
1954 s_save_state_threads.emplace_back(&VMManager::ZipSaveStateOnThread, std::move(elist), std::move(screenshot),
1955 std::string(filename), slot_for_message, std::move(error_callback));
1956 }
1957 else
1958 {
1959 ZipSaveState(
1960 std::move(elist), std::move(screenshot), filename, slot_for_message, std::move(error_callback));
1961 }
1962
1963 Host::OnSaveStateSaved(filename);
1964 MemcardBusy::CheckSaveStateDependency();
1965 return;
1966}
1967
1968void VMManager::ZipSaveState(std::unique_ptr<ArchiveEntryList> elist,
1969 std::unique_ptr<SaveStateScreenshotData> screenshot, const char* filename,

Callers

nothing calls this directly

Calls 8

error_callbackFunction · 0.85
SaveState_DownloadStateFunction · 0.85
SaveState_SaveScreenshotFunction · 0.85
GetDescriptionMethod · 0.80
formatFunction · 0.50
stringClass · 0.50
WriteLnMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected