Exemplo n.º 1
0
 private void CreateConfig()
 {
     string filepath = Path.Combine(TShock.SavePath, "EnglishPlsConfig.json");
     try
     {
         using (var stream = new FileStream(filepath, FileMode.Create, FileAccess.Write, FileShare.Write))
         {
             using (var sr = new StreamWriter(stream))
             {
                 cfg = new Config();
                 var configString = JsonConvert.SerializeObject(cfg, Formatting.Indented);
                 sr.Write(configString);
             }
             stream.Close();
         }
     }
     catch (Exception ex)
     {
         TShock.Log.ConsoleError(ex.Message);
         cfg = new Config();
     }
 }
Exemplo n.º 2
0
 private bool ReadConfig()
 {
     string filepath = Path.Combine(TShock.SavePath, "EnglishPlsConfig.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();
                     cfg = JsonConvert.DeserializeObject<Config>(configString);
                 }
                 stream.Close();
             }
             return true;
         }
         else
         {
             TShock.Log.ConsoleError("EnglishPls config not found. Creating new one...");
             CreateConfig();
             return true;
         }
     }
     catch (Exception ex)
     {
         TShock.Log.ConsoleError(ex.Message);
     }
     return false;
 }