| 1917 | } |
| 1918 | |
| 1919 | void 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 | |
| 1968 | void VMManager::ZipSaveState(std::unique_ptr<ArchiveEntryList> elist, |
| 1969 | std::unique_ptr<SaveStateScreenshotData> screenshot, const char* filename, |
nothing calls this directly
no test coverage detected