示例#1
0
 public static void SaveKeybinds()
 {
     using (var sw = new StreamWriter(BESettings.GetPath("BEMainKeybinds")))
     {
         var s = new XmlSerializer(typeof(List <BEKeybind>));
         s.Serialize(sw, keybinds);
     }
 }
示例#2
0
 public static void LoadKeybinds()
 {
     using (var sr = new StreamReader(BESettings.GetPath("BEMainKeybinds")))
     {
         var s = new XmlSerializer(typeof(List <BEKeybind>));
         keybinds = (List <BEKeybind>)(s.Deserialize(sr) ?? new List <BEKeybind>());
     }
 }
示例#3
0
        public static void Save(BESettings stgObject, Type stgType)
        {
            string filePath = GetPath(stgType.Name);

            try
            {
                using (var sw = new StreamWriter(filePath))
                {
                    var s = new XmlSerializer(stgType);
                    s.Serialize(sw, stgObject);
                }
            }
            catch (Exception e)
            {
                BetterEditor.Logger.Log($"Settings saving failed for the type '{stgType.Name}'.");
                BetterEditor.Logger.LogException(e);
            }
        }
示例#4
0
        public static void Setup()
        {
            SettingsStorage.Clear();
            IEnumerable <Type> stgSubclasses = Assembly.GetExecutingAssembly().GetTypes().Where(
                t => t.IsSubclassOf(typeof(BESettings)));

            StringBuilder nullSb = new StringBuilder("Those types returned null while loading types: ");

            foreach (Type stgType in stgSubclasses)
            {
                BESettings stgInstance = Load(stgType);
                if (stgInstance == null)
                {
                    nullSb.Append($"{stgType.Name} ");
                    stgInstance = (BESettings)stgType.GetConstructors().First().Invoke(null, null);
                }

                SettingsStorage.Add(stgType, stgInstance);
            }

            BetterEditor.Logger.Log(nullSb.ToString());
        }