示例#1
0
 private bool ReadConfig()
 {
     string filepath = Path.Combine(TShock.SavePath, "ReplenisherConfig.json");
     try
     {
         if (File.Exists(filepath))
         {
             using (var stream = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.Read))
             {
                 using (var sr = new StreamReader(stream))
                 {
                     var configString = sr.ReadToEnd();
                     config = JsonConvert.DeserializeObject<Config>(configString);
                 }
                 stream.Close();
             }
             return true;
         }
         else
         {
             TShock.Log.ConsoleError("Replenisher config not found. Creating new one...");
             CreateConfig();
             return true;
         }
     }
     catch (JsonSerializationException ex)
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine("Error in Replenisher config file. Please try to let the config file be generated automatically and manually import your settings. If that doesn't work, feel free to post about it.");
         Console.WriteLine(ex.Message);
         Console.ForegroundColor = ConsoleColor.White;
     }
     catch (Exception ex)
     {
         TShock.Log.ConsoleError(ex.Message);
     }
     return false;
 }
示例#2
0
 private void CreateConfig()
 {
     string filepath = Path.Combine(TShock.SavePath, "ReplenisherConfig.json");
     try
     {
         using (var stream = new FileStream(filepath, FileMode.Create, FileAccess.Write, FileShare.Write))
         {
             using (var sr = new StreamWriter(stream))
             {
                 config = new Config();
                 var configString = JsonConvert.SerializeObject(config, Formatting.Indented);
                 sr.Write(configString);
             }
             stream.Close();
         }
     }
     catch (Exception ex)
     {
         TShock.Log.ConsoleError(ex.Message);
         config = new Config();
     }
 }