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