Beispiel #1
0
        public static FriendlyTroopBannerHotkeysModSettings LoadSettings()
        {
            if (!File.Exists(setttingsPathName))
            {
                return(InitializeFile());
            }
            else
            {
                FriendlyTroopBannerHotkeysModSettings settings;
                bool needToSaveFile = false;

                using (FileStream fs = new FileStream(setttingsPathName, FileMode.Open))
                {
                    try
                    {
                        settings = Serializer.Deserialize(fs) as FriendlyTroopBannerHotkeysModSettings;
                    }
                    catch (Exception ex)
                    {
                        Utility.Log("LoadSettings", ex);
                        settings       = new FriendlyTroopBannerHotkeysModSettings();
                        needToSaveFile = true;
                    }
                }

                if (settings.HotkeyInstructions != hotkeyInstructions)
                {
                    settings.HotkeyInstructions = hotkeyInstructions;
                }
                if (settings.BannerScalingInstructions != bannerScalingInstructions)
                {
                    settings.BannerScalingInstructions = bannerScalingInstructions;
                }

                // Check for valid option ranges and adjust if necessary
                if (settings.BannerScaleFactor < 0.1f)
                {
                    settings.BannerScaleFactor = 0.1f; needToSaveFile = true;
                }
                if (settings.BannerScaleFactor > 1f)
                {
                    settings.BannerScaleFactor = 1f; needToSaveFile = true;
                }
                if (settings.SelectedBannerScaleFactor < 1f)
                {
                    settings.SelectedBannerScaleFactor = 1f; needToSaveFile = true;
                }
                if (settings.SelectedBannerScaleFactor > 60f)
                {
                    settings.SelectedBannerScaleFactor = 60f; needToSaveFile = true;
                }

                if (needToSaveFile || settings.SettingsVersion != settingsVersion)
                {
                    settings = InitializeFile(settings);
                }

                return(settings);
            }
        }
Beispiel #2
0
        private static FriendlyTroopBannerHotkeysModSettings InitializeFile(FriendlyTroopBannerHotkeysModSettings settings = null)
        {
            try
            {
                var fileCreated = false;
                if (settings == null)
                {
                    settings    = new FriendlyTroopBannerHotkeysModSettings();
                    fileCreated = true;
                }
                else
                {
                    if (settings.SettingsVersion != settingsVersion || settings.HotkeyInstructions != hotkeyInstructions)
                    {
                        settings.HotkeyInstructions = hotkeyInstructions;
                        settings.SettingsVersion    = settingsVersion;
                    }
                }

                var settingsPath = Path.GetDirectoryName(setttingsPathName);
                if (!Directory.Exists(settingsPath))
                {
                    Directory.CreateDirectory(settingsPath);
                }

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

                if (fileCreated)
                {
                    var fullPath = Path.GetFullPath(setttingsPathName);
                    settings.NewFileMessage = FriendlyTroopBannerHotkeys.ModName + $" config generated at {fullPath}";
                }
            }
            catch (Exception ex)
            {
                Utility.Log("FriendlyTroopBannerHotkeysModSettings.InitializeFile", ex);
            }

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