Example #1
0
 /// <summary>
 /// Saves the game to disk in the background.
 /// </summary>
 /// <param name="data">The uncompressed save data.</param>
 private void DoSave(BackgroundSaveData data)
 {
     try {
         var stream = data.Stream;
         PUtil.LogDebug("Background save to: " + data.FileName);
         stream.Seek(0L, SeekOrigin.Begin);
         CleanAutosaves();
         // Write the file header
         using (var writer = new BinaryWriter(File.Open(data.FileName, FileMode.
                                                        Create))) {
             var saveHeader = SaveGame.Instance.GetSaveHeader(true, data.Compress,
                                                              out SaveGame.Header header);
             writer.Write(header.buildVersion);
             writer.Write(header.headerSize);
             writer.Write(header.headerVersion);
             writer.Write(header.compression);
             writer.Write(saveHeader);
             if (FastSaveOptions.Instance.DelegateSave)
             {
                 FastSerializationManager.SerializeDirectory(writer);
             }
             else
             {
                 KSerialization.Manager.SerializeDirectory(writer);
             }
             writer.Flush();
             if (data.Compress)
             {
                 COMPRESS_CONTENTS.Invoke(writer, stream.GetBuffer(), (int)stream.
                                          Length);
             }
             else
             {
                 stream.CopyTo(writer.BaseStream);
             }
         }
         stream.Dispose();
         status = SaveStatus.Done;
         PUtil.LogDebug("Background save complete");
     } catch (IOException e) {
         // Autosave error!
         PUtil.LogExcWarn(e);
         status = SaveStatus.IOError;
     } catch (Exception e) {
         // Allowing it to continue here will crash with a simdll error
         PUtil.LogException(e);
         status = SaveStatus.Failed;
     } finally {
         try {
             // Cannot throw during a finally, or it will discard the original exception
             data.Dispose();
         } catch { }
     }
 }
Example #2
0
 /// <summary>
 /// Applied before SerializeDirectory runs.
 /// </summary>
 internal static bool Prefix(BinaryWriter writer)
 {
     FastSerializationManager.SerializeDirectory(writer);
     return(false);
 }