public static bool loadSave(string name) { //update current game... try { currentGame = CurrentGame.load(Path.Combine(saveDirectory.ToString(), name + ".sav")); return true; } catch (Exception e) { currentGame = new CurrentGame(); return false; } }
public static CurrentGame load(string path) { if (File.Exists(path)) { FileStream fs = File.OpenRead(path); BinaryFormatter bf = new BinaryFormatter(); Dictionary<string, Dictionary<string, object>> variables = (Dictionary<string, Dictionary<string, object>>)bf.Deserialize(fs); CurrentGame cg = new CurrentGame(); cg.Variables = variables; return cg; } else { throw new FileNotFoundException(); } }