public static YamlConfig Load(string filePath)
 {
     try
     {
         if (File.Exists(filePath))
         {
             using (StreamReader r = new StreamReader(filePath, Encoding.UTF8, false))
             {
                 Deserializer s = new DeserializerBuilder()
                                  .Build();
                 YamlConfig conv = new YamlConfig();
                 conv.Root     = s.Deserialize <Dictionary <string, object> >(r);
                 conv.FilePath = filePath;
                 return((YamlConfig)Convert.ChangeType(conv, typeof(YamlConfig)));
             }
         }
         else
         {
             YamlConfig conv = new YamlConfig();
             conv.FilePath = filePath;
             conv.Save();
             return(conv);
         }
     }
     catch (YamlException e)
     {
         Logger.Error(e);
         Logger.Error("%config_error");
         Logger.Notice("%config_error2");
         throw new ServerException();
     }
 }
Example #2
0
 public static YamlConfig Load(string filePath)
 {
     try
     {
         if (File.Exists(filePath))
         {
             using (StreamReader r = new StreamReader(filePath, Encoding.UTF8, false))
             {
                 Deserializer s = (Deserializer) new DeserializerBuilder()
                                  .Build();
                 YamlConfig conv = new YamlConfig();
                 conv.Root     = s.Deserialize <Dictionary <string, object> >(r);
                 conv.FilePath = filePath;
                 return((YamlConfig)Convert.ChangeType(conv, typeof(YamlConfig)));
             }
         }
         else
         {
             YamlConfig conv = new YamlConfig();
             conv.FilePath = filePath;
             conv.Save();
             return(conv);
         }
     }
     catch (SerializationException)
     {
         File.Move(filePath, filePath + ".old");
         return(YamlConfig.Load(filePath));
     }
     catch (YamlException)
     {
         File.Move(filePath, filePath + ".old");
         return(YamlConfig.Load(filePath));
     }
     catch (Exception e)
     {
         throw e;
     }
 }