Example #1
0
        /// <summary>
        /// Save settings to .json file
        /// </summary>
        /// <param name="glob">settings object</param>
        public static void SaveDat(globalsettings glob)
        {
            var xm = new jsonsettings
            {
                globalsettings = glob,
            };

            string json = JsonConvert.SerializeObject(xm, Formatting.Indented);


            if (!Directory.Exists(SubDataFolder))
            {
                Directory.CreateDirectory(SubDataFolder);
            }
            File.WriteAllText(Path.Combine(SubDataFolder, "settings.json"), json);
        }
Example #2
0
 /// <summary>
 /// Load settings from .json file
 /// </summary>
 public static jsonsettings LoadDat()
 {
     if (File.Exists(Path.Combine(SubDataFolder, "settings.json")))
     {
         try
         {
             jsonsettings xm = JsonConvert.DeserializeObject <jsonsettings>(File.ReadAllText(Path.Combine(SubDataFolder, "settings.json")));
             return(xm);
         }
         catch (Exception)
         {
             MessageBox.Show("Error on serializing settings.json");
             Application.Exit();
             return(null);
         }
     }
     else
     {
         var jm   = new jsonsettings();
         var glob = new globalsettings();
         SaveDat(glob);
         return(null);
     }
 }