- Timestamp:
- Jul 31, 2023, 4:06:13 PM (16 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/PersistentData/PersistentContainer.cs
r448 r455 12 12 [OptionalField] private Attributes attributes; 13 13 14 public Players Players { 15 get { 16 if (players == null) { 17 players = new Players (); 18 } 14 public Players Players => players ??= new Players (); 19 15 20 return players; 21 } 22 } 23 24 public Attributes Attributes { 25 get { 26 if (attributes == null) { 27 attributes = new Attributes (); 28 } 29 30 return attributes; 31 } 32 } 16 public Attributes Attributes => attributes ??= new Attributes (); 33 17 34 18 private static PersistentContainer instance; 35 19 36 public static PersistentContainer Instance { 37 get { 38 if (instance == null) { 39 instance = new PersistentContainer (); 40 } 41 42 return instance; 43 } 44 } 20 public static PersistentContainer Instance => instance ??= new PersistentContainer (); 45 21 46 22 private PersistentContainer () { … … 49 25 public void Save () { 50 26 lock (fileLockObject) { 51 using Stream stream = File.Open ( GameIO.GetSaveGameDir () + persistentDataFileName, FileMode.Create);27 using Stream stream = File.Open ($"{GameIO.GetSaveGameDir ()}{persistentDataFileName}", FileMode.Create); 52 28 BinaryFormatter bFormatter = new BinaryFormatter (); 53 29 bFormatter.Serialize (stream, this); … … 56 32 57 33 public static bool Load () { 58 if (!File.Exists (GameIO.GetSaveGameDir () + persistentDataFileName)) { 34 var filePath = $"{GameIO.GetSaveGameDir ()}{persistentDataFileName}"; 35 36 if (!File.Exists (filePath)) { 59 37 return false; 60 38 } … … 63 41 PersistentContainer obj; 64 42 lock (fileLockObject) { 65 using Stream stream = File.Open ( GameIO.GetSaveGameDir () + persistentDataFileName, FileMode.Open);43 using Stream stream = File.Open (filePath, FileMode.Open); 66 44 BinaryFormatter bFormatter = new BinaryFormatter (); 67 45 obj = (PersistentContainer)bFormatter.Deserialize (stream);
Note:
See TracChangeset
for help on using the changeset viewer.