Config
Config
IO;
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
namespace DeathSounds.code
{
public class Config
{
public bool firstEverEnter = true;
public bool doneFirstTimeSetup = false;
public bool doSecondReload = false;
private Config()
{
addedFiles = new HashSet<string>();
firstEverEnter = true;
doneFirstTimeSetup = false;
doSecondReload = false;
}
private static Config instance;
public static Config Instance
{
get
{
if (instance == null)
instance = new Config();
return instance;
}
private set { instance = value; }
}
public string Save(string path = "")
{
if (String.IsNullOrEmpty(path))
path = PATH.CONFIG_FILE;
string json = JsonConvert.SerializeObject(Instance,
Formatting.Indented);
File.WriteAllText(path, json);
return json;
}
public string Load(string path = "")
{
if (String.IsNullOrEmpty(path))
path = PATH.CONFIG_FILE;
string json = "";
try
{
json = File.ReadAllText(path);
JsonConvert.PopulateObject(json, Config.Instance);
}
catch
{
Config.Instance = null;
json = JsonConvert.SerializeObject(Config.Instance);
Directory.CreateDirectory(Directory.GetParent(path).FullName);
File.WriteAllText(path, json);
}
return json;
}
}
}