source: binary-improvements/7dtd-server-fixes/src/PersistentData/PersistentContainer.cs@ 145

Last change on this file since 145 was 144, checked in by alloc, 10 years ago

Fixes

File size: 1.3 KB
Line 
1using System;
2using System.IO;
3using System.Runtime.Serialization;
4using System.Runtime.Serialization.Formatters.Binary;
5
6namespace AllocsFixes.PersistentData
7{
8 [Serializable]
9 public class PersistentContainer
10 {
11 private Players players;
12
13 public Players Players {
14 get {
15 if (players == null)
16 players = new Players ();
17 return players;
18 }
19 }
20
21 private static PersistentContainer instance;
22
23 public static PersistentContainer Instance {
24 get {
25 if (instance == null) {
26 instance = new PersistentContainer ();
27 }
28 return instance;
29 }
30 }
31
32 private PersistentContainer ()
33 {
34 }
35
36 public void Save ()
37 {
38 Stream stream = File.Open (StaticDirectories.GetSaveGameDir () + "/AllocsPeristentData.bin", FileMode.Create);
39 BinaryFormatter bFormatter = new BinaryFormatter ();
40 bFormatter.Serialize (stream, this);
41 stream.Close ();
42 }
43
44 public static bool Load ()
45 {
46 if (File.Exists (StaticDirectories.GetSaveGameDir () + "/AllocsPeristentData.bin")) {
47 PersistentContainer obj;
48 Stream stream = File.Open (StaticDirectories.GetSaveGameDir () + "/AllocsPeristentData.bin", FileMode.Open);
49 BinaryFormatter bFormatter = new BinaryFormatter ();
50 obj = (PersistentContainer)bFormatter.Deserialize (stream);
51 stream.Close ();
52 instance = obj;
53 return true;
54 } else
55 return false;
56 }
57
58 }
59}
60
Note: See TracBrowser for help on using the repository browser.