Changeset 448 for binary-improvements/7dtd-server-fixes/src/PersistentData
- Timestamp:
- Jun 16, 2023, 3:31:26 PM (19 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/PersistentData/PersistentContainer.cs
r369 r448 7 7 [Serializable] 8 8 public class PersistentContainer { 9 private const string persistentDataFileName = "/AllocsPersistentData.bin"; 10 9 11 private Players players; 10 12 [OptionalField] private Attributes attributes; … … 44 46 private PersistentContainer () { 45 47 } 46 48 47 49 public void Save () { 48 Stream stream = File.Open (GameIO.GetSaveGameDir () + "/AllocsPeristentData.bin", FileMode.Create); 49 BinaryFormatter bFormatter = new BinaryFormatter (); 50 bFormatter.Serialize (stream, this); 51 stream.Close (); 50 lock (fileLockObject) { 51 using Stream stream = File.Open (GameIO.GetSaveGameDir () + persistentDataFileName, FileMode.Create); 52 BinaryFormatter bFormatter = new BinaryFormatter (); 53 bFormatter.Serialize (stream, this); 54 } 52 55 } 53 56 54 57 public static bool Load () { 55 if (!File.Exists (GameIO.GetSaveGameDir () + "/AllocsPeristentData.bin")) {58 if (!File.Exists (GameIO.GetSaveGameDir () + persistentDataFileName)) { 56 59 return false; 57 60 } … … 59 62 try { 60 63 PersistentContainer obj; 61 Stream stream = File.Open (GameIO.GetSaveGameDir () + "/AllocsPeristentData.bin", FileMode.Open); 62 BinaryFormatter bFormatter = new BinaryFormatter (); 63 obj = (PersistentContainer) bFormatter.Deserialize (stream); 64 stream.Close (); 64 lock (fileLockObject) { 65 using Stream stream = File.Open (GameIO.GetSaveGameDir () + persistentDataFileName, FileMode.Open); 66 BinaryFormatter bFormatter = new BinaryFormatter (); 67 obj = (PersistentContainer)bFormatter.Deserialize (stream); 68 } 69 65 70 instance = obj; 66 71 return true; … … 72 77 return false; 73 78 } 79 80 private static readonly object fileLockObject = new(); 74 81 } 75 82 }
Note:
See TracChangeset
for help on using the changeset viewer.