private static void OnSnapshotDone(bool snapshotSuccess, MySessionSnapshot snapshot) { if (snapshotSuccess) { if (!MySandboxGame.IsDedicated) { var thumbPath = MySession.Static.ThumbPath; try { if (File.Exists(thumbPath)) File.Delete(thumbPath); MyGuiSandbox.TakeScreenshot(1200, 672, saveToPath: thumbPath, ignoreSprites: true, showNotification: false); } catch (Exception ex) { MySandboxGame.Log.WriteLine("Could not take session thumb screenshot. Exception:"); MySandboxGame.Log.WriteLine(ex); } } snapshot.SaveParallel(completionCallback: () => { if (!MySandboxGame.IsDedicated) { MyHud.PopRotatingWheelVisible(); if (MySession.Static != null) { if (snapshot.SavingSuccess) { var notification = new MyHudNotification(MyCommonTexts.WorldSaved, 2500); notification.SetTextFormatArguments(MySession.Static.Name); MyHud.Notifications.Add(notification); } else { MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( messageText: new StringBuilder().AppendFormat(MyTexts.GetString(MyCommonTexts.WorldNotSaved), MySession.Static.Name), messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError))); } } } PopInProgress(); }); } else { if (!MySandboxGame.IsDedicated) { MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( messageText: new StringBuilder().AppendFormat(MyTexts.GetString(MyCommonTexts.WorldNotSaved), MySession.Static.Name), messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError))); } PopInProgress(); } if (m_callbackOnFinished != null) m_callbackOnFinished(); m_callbackOnFinished = null; MyAudio.Static.Mute = false; }
public bool Save(out MySessionSnapshot snapshot, string customSaveName = null) { if (Sync.IsServer) { MyMultiplayer.RaiseStaticEvent(x => OnServerSaving, true); } snapshot = new MySessionSnapshot(); MySandboxGame.Log.WriteLine("Saving world - START"); using (var indent = MySandboxGame.Log.IndentUsing(LoggingOptions.NONE)) { string saveName = customSaveName ?? Name; // Custom save name is used for "Save As" functionality. if (customSaveName != null) CurrentPath = MyLocalCache.GetSessionSavesPath(customSaveName, false); snapshot.TargetDir = CurrentPath; snapshot.SavingDir = GetTempSavingFolder(); try { MySandboxGame.Log.WriteLine("Making world state snapshot."); LogMemoryUsage("Before snapshot."); snapshot.CheckpointSnapshot = GetCheckpoint(saveName); snapshot.SectorSnapshot = GetSector(); snapshot.CompressedVoxelSnapshots = Static.GetVoxelMapsArray(true); LogMemoryUsage("After snapshot."); SaveDataComponents(); } catch (Exception ex) { MySandboxGame.Log.WriteLine(ex); return false; } finally { SaveEnded(); } LogMemoryUsage("Directory cleanup"); } MySandboxGame.Log.WriteLine("Saving world - END"); return true; }