Beispiel #1
0
        public static PartyManagerSettings LoadSettings()
        {
            if (!File.Exists(filePath))
            {
                return(CreateUpdateFile());
            }
            else
            {
                PartyManagerSettings settings;

                using (FileStream fs = new FileStream(filePath, FileMode.Open))
                {
                    try
                    {
                        settings = Serializer.Deserialize(fs) as PartyManagerSettings;
                    }
                    catch (Exception ex)
                    {
                        GenericHelpers.LogException("LoadSettings", ex);
                        settings = new PartyManagerSettings();
                    }
                }

                if (settings.Version != version)
                {
                    settings = CreateUpdateFile(settings);
                }
                return(settings);
            }
        }
Beispiel #2
0
        private static PartyManagerSettings CreateUpdateFile(PartyManagerSettings settings = null)
        {
            try
            {
                var newFileGenerated = false;
                if (settings == null)
                {
                    settings         = new PartyManagerSettings();
                    newFileGenerated = true;
                }
                else
                {
                    for (int i = settings.Version.Value; i < version; i++)
                    {
                        switch (i)
                        {
                        case 1:
                            settings.EnableHotkey   = true;
                            settings.EnableAutoSort = true;
                            break;

                        case 2:
                            settings.EnableSortTypeCycleHotkey      = true;
                            settings.EnableRecruitUpgradeSortHotkey = true;
                            break;

                        case 3:
                            settings.CavalryAboveFootmen = true;
                            settings.MeleeAboveArchers   = true;
                            break;
                        }
                    }

                    settings.Version = version;
                }


                var saveDirectory = Path.GetDirectoryName(filePath);
                if (!Directory.Exists(saveDirectory))
                {
                    Directory.CreateDirectory(saveDirectory);
                }


                using (var fs = new FileStream(filePath, FileMode.Create))
                {
                    Serializer.Serialize(fs, settings);
                }

                if (newFileGenerated)
                {
                    var fullPath = Path.GetFullPath(filePath);
                    settings.NewFileMessage = $"PartyManager config generated at {fullPath}";
                }
            }
            catch (Exception ex)
            {
                GenericHelpers.LogException("PartyManagerSettings.CreateUpdateFile", ex);
            }

            return(settings);
        }
Beispiel #3
0
 public static void ReloadSettings()
 {
     _settings = LoadSettings();
     GenericHelpers.LogMessage("Settings Reloaded");
 }