public static GameConfig Create(bool loadFile = true, Func <string> filePath = null) { if (!loadFile) { return(new GameConfig((filePath ?? DefaultConfigPath))); } var cfgpath = (filePath ?? DefaultConfigPath)(); if (File.Exists(cfgpath)) { var xml = new XmlSerializer(typeof(GameConfig)); using (var reader = new StreamReader(cfgpath)) { var loaded = (GameConfig)xml.Deserialize(reader); loaded.filePath = (filePath ?? DefaultConfigPath); if (loaded.UUID == null) { loaded.UUID = Guid.NewGuid(); } return(loaded); } } else { var cfg = new GameConfig((filePath ?? DefaultConfigPath)); if (cfg.UUID == null) { cfg.UUID = Guid.NewGuid(); } cfg.Save(); return(cfg); } }
public static GameConfig Create(bool loadFile = true, Func <string> filePath = null) { if (!loadFile) { return(new GameConfig((filePath ?? DefaultConfigPath))); } var cfgpath = (filePath ?? DefaultConfigPath)(); if (File.Exists(cfgpath)) { var cfg = new GameConfig((filePath ?? DefaultConfigPath)); cfg.ParseAndFill(cfgpath, null); if (cfg.UUID == null) { cfg.UUID = Guid.NewGuid(); } return(cfg); } else { var cfg = new GameConfig((filePath ?? DefaultConfigPath)); if (cfg.UUID == null) { cfg.UUID = Guid.NewGuid(); } cfg.Save(); return(cfg); } }