Ejemplo n.º 1
0
        public static void ApplyAnyOverrideCulture()
        {
            string overrideCultureName = null;

            try
            {
                // Use Eddi.Properties.Settings if an override culture isn't set in our configuration
                EDDIConfiguration configuration = EDDIConfiguration.FromFile();
                if (configuration.OverrideCulture is null && !string.IsNullOrEmpty(Eddi.Properties.Settings.Default.OverrideCulture))
                {
                    configuration.OverrideCulture = Eddi.Properties.Settings.Default.OverrideCulture;
                    configuration.ToFile();
                }

                overrideCultureName = configuration.OverrideCulture;

                // we are using the InvariantCulture name "" to mean user's culture
                CultureInfo overrideCulture = string.IsNullOrEmpty(overrideCultureName) ? null : new CultureInfo(overrideCultureName);
                ApplyCulture(overrideCulture);
            }
            catch
            {
                ApplyCulture(null);
                Debug.WriteLine("Culture [{0}] not available", overrideCultureName);
            }
        }
Ejemplo n.º 2
0
        public void Start()
        {
            if (!started)
            {
                EDDIConfiguration configuration = EDDIConfiguration.FromFile();

                foreach (EDDIMonitor monitor in monitors)
                {
                    bool enabled;
                    if (!configuration.Plugins.TryGetValue(monitor.MonitorName(), out enabled))
                    {
                        // No information; default to enabled
                        enabled = true;
                    }

                    if (!enabled)
                    {
                        Logging.Debug(monitor.MonitorName() + " is disabled; not starting");
                    }
                    else
                    {
                        Thread monitorThread = new Thread(() => monitor.Start());
                        monitorThread.Name         = monitor.MonitorName();
                        monitorThread.IsBackground = true;
                        Logging.Info("Starting " + monitor.MonitorName());
                        monitorThread.Start();
                    }
                }

                foreach (EDDIResponder responder in responders)
                {
                    bool enabled;
                    if (!configuration.Plugins.TryGetValue(responder.ResponderName(), out enabled))
                    {
                        // No information; default to enabled
                        enabled = true;
                    }

                    if (!enabled)
                    {
                        Logging.Debug(responder.ResponderName() + " is disabled; not starting");
                    }
                    else
                    {
                        bool responderStarted = responder.Start();
                        if (responderStarted)
                        {
                            activeResponders.Add(responder);
                            //EventHandler += new OnEventHandler(responder.Handle);
                            Logging.Info("Started " + responder.ResponderName());
                        }
                        else
                        {
                            Logging.Warn("Failed to start " + responder.ResponderName());
                        }
                    }
                }
                started = true;
            }
        }
Ejemplo n.º 3
0
        private void homeStationChanged(object sender, TextChangedEventArgs e)
        {
            EDDIConfiguration eddiConfiguration = EDDIConfiguration.FromFile();

            eddiConfiguration.HomeStation = string.IsNullOrWhiteSpace(eddiHomeStationText.Text) ? null : eddiHomeStationText.Text.Trim();
            eddiConfiguration.ToFile();
        }
Ejemplo n.º 4
0
        // Handle changes to the editable squadron system combo box
        private void SquadronSystemText_TextChanged(object sender, TextChangedEventArgs e)
        {
            EDDIConfiguration eddiConfiguration = EDDIConfiguration.FromFile();
            string            oldValue          = eddiConfiguration.SquadronSystem;

            void changeHandler()
            {
                // Reset the squadron data due to selecting new squadron system
                if (eddiConfiguration.SquadronFaction != null)
                {
                    eddiConfiguration.SquadronFaction = null;

                    eddiConfiguration.SquadronAllegiance = Superpower.None;
                    eddiConfiguration.SquadronPower      = Power.None;
                    eddiConfiguration.ToFile();

                    squadronFactionDropDown.SelectedItem = Power.None.localizedName;
                    ConfigureSquadronFactionOptions(eddiConfiguration);
                    squadronPowerDropDown.SelectedItem = eddiConfiguration.SquadronPower.localizedName;
                    ConfigureSquadronPowerOptions(eddiConfiguration);

                    EDDI.Instance.Cmdr.squadronallegiance = Superpower.None;
                    EDDI.Instance.Cmdr.squadronpower      = Power.None;
                    eddiConfiguration.ToFile();
                }
            }

            squadronSystemDropDown.TextDidChange(sender, e, oldValue, changeHandler);
        }
        /// <summary>
        /// Obtain configuration from a file.  If the file name is not supplied the the default
        /// path of Constants.Data_DIR\eddi.json is used
        /// </summary>
        public static EDDIConfiguration FromFile(string filename = null)
        {
            if (filename == null)
            {
                filename = Constants.DATA_DIR + @"\eddi.json";
            }

            EDDIConfiguration configuration = new EDDIConfiguration();

            try
            {
                configuration = JsonConvert.DeserializeObject <EDDIConfiguration>(File.ReadAllText(filename));
            }
            catch (Exception ex)
            {
                Logging.Debug("Failed to read EDDI configuration", ex);
            }
            configuration.dataPath = filename;
            if (configuration.Plugins == null)
            {
                configuration.Plugins = new Dictionary <string, bool>();
            }

            return(configuration);
        }
Ejemplo n.º 6
0
        private void verboseLoggingDisabled(object sender, RoutedEventArgs e)
        {
            EDDIConfiguration eddiConfiguration = EDDIConfiguration.FromFile();

            eddiConfiguration.Debug = eddiVerboseLogging.IsChecked.Value;
            eddiConfiguration.ToFile();
        }
Ejemplo n.º 7
0
        private void pluginenabled_Unchecked(object sender, RoutedEventArgs e)
        {
            EDDIConfiguration configuration = EDDIConfiguration.FromFile();

            configuration.Plugins[pluginName] = false;
            configuration.ToFile();
        }
Ejemplo n.º 8
0
        private void LoadResponders(EDDIConfiguration eddiConfiguration)
        {
            foreach (EDDIResponder responder in EDDI.Instance.responders)
            {
                Logging.Debug("Adding configuration tab for " + responder.ResponderName());

                PluginSkeleton skeleton = new PluginSkeleton(responder.ResponderName());
                skeleton.plugindescription.Text = responder.ResponderDescription();

                if (eddiConfiguration.Plugins.TryGetValue(responder.ResponderName(), out bool enabled))
                {
                    skeleton.pluginenabled.IsChecked = enabled;
                }
                else
                {
                    // Default to enabled
                    skeleton.pluginenabled.IsChecked = true;
                    eddiConfiguration.ToFile();
                }

                // Add responder-specific configuration items
                System.Windows.Controls.UserControl monitorConfiguration = responder.ConfigurationTabItem();
                if (monitorConfiguration != null)
                {
                    monitorConfiguration.Margin = new Thickness(10);
                    skeleton.panel.Children.Add(monitorConfiguration);
                }

                TabItem item = new TabItem {
                    Header = responder.LocalizedResponderName()
                };
                item.Content = skeleton;
                tabControl.Items.Add(item);
            }
        }
Ejemplo n.º 9
0
        private void LoadAndSortTabs(EDDIConfiguration eddiConfiguration)
        {
            // Sort all but the first TabItem by name, ignoring case
            ItemCollection items       = tabControl.Items;
            List <TabItem> sortedItems = new List <TabItem>();

            foreach (var item in items)
            {
                sortedItems.Add(item as TabItem);
            }

            List <TabItem> monitors = LoadMonitors(eddiConfiguration);

            sortedItems.AddRange(monitors);
            List <TabItem> responders = LoadResponders(eddiConfiguration);

            sortedItems.AddRange(responders);

            TabItemComparer comparer = new TabItemComparer(StringComparer.CurrentCultureIgnoreCase);

            sortedItems.Sort(1, sortedItems.Count - 1, comparer);

            items.Clear();
            foreach (var item in sortedItems)
            {
                items.Add(item);
            }
        }
Ejemplo n.º 10
0
        private void isNeitherGender_Checked(object sender, RoutedEventArgs e)
        {
            EDDIConfiguration eddiConfiguration = EDDIConfiguration.FromFile();

            eddiConfiguration.Gender = "Neither";
            eddiConfiguration.ToFile();
            EDDI.Instance.Cmdr.gender = "Neither";
        }
Ejemplo n.º 11
0
        private void pluginenabled_Unchecked(object sender, RoutedEventArgs e)
        {
            EDDIConfiguration configuration = EDDIConfiguration.FromFile();

            configuration.Plugins[pluginName] = false;
            configuration.ToFile();
            EDDI.Instance.DisableResponder(pluginName);
            EDDI.Instance.DisableMonitor(pluginName);
        }
        private void betaProgrammeDisabled(object sender, RoutedEventArgs e)
        {
            EDDIConfiguration eddiConfiguration = EDDIConfiguration.FromFile();

            eddiConfiguration.Beta = eddiBetaProgramme.IsChecked.Value;
            eddiConfiguration.ToFile();
            // Because we have chaned to not wanting beta upgrades we need to re-check upgrade information
            EDDI.Instance.CheckUpgrade();
            setStatusInfo();
        }
Ejemplo n.º 13
0
 private void eddiSquadronNameText_LostFocus(object sender, RoutedEventArgs e)
 {
     // Discard invalid results
     if (eddiSquadronNameText.Text == string.Empty)
     {
         EDDIConfiguration eddiConfiguration = EDDIConfiguration.FromFile();
         eddiConfiguration.SquadronName = null;
         eddiConfiguration.ToFile();
         EDDI.Instance.Cmdr.squadronname = string.Empty;
     }
 }
Ejemplo n.º 14
0
        public EDDIConfiguration resetSquadronRank(EDDIConfiguration configuration)
        {
            if (configuration.SquadronName == null)
            {
                configuration.SquadronRank        = SquadronRank.None;
                squadronRankDropDown.SelectedItem = configuration.SquadronRank.localizedName;
            }
            ConfigureSquadronRankOptions(configuration);

            return(configuration);
        }
Ejemplo n.º 15
0
        private void homeStationChanged(object sender, TextChangedEventArgs e)
        {
            EDDIConfiguration eddiConfiguration = EDDIConfiguration.FromFile();

            eddiConfiguration.HomeStation = string.IsNullOrWhiteSpace(eddiHomeStationText.Text) ? null : eddiHomeStationText.Text.Trim();
            eddiConfiguration             = EDDI.Instance.updateHomeStation(eddiConfiguration);
            eddiConfiguration.ToFile();

            // Update the UI for invalid results
            runValidation(eddiHomeStationText);
        }
Ejemplo n.º 16
0
        private void squadronIDChanged(object sender, TextChangedEventArgs e)
        {
            EDDIConfiguration eddiConfiguration = EDDIConfiguration.FromFile();

            if (eddiConfiguration.SquadronID != eddiSquadronIDText.Text)
            {
                eddiConfiguration.SquadronID = string.IsNullOrWhiteSpace(eddiSquadronIDText.Text) ? null : eddiSquadronIDText.Text.Trim();
                eddiConfiguration.ToFile();

                EDDI.Instance.Cmdr.squadronid = eddiConfiguration.SquadronID;
            }
        }
Ejemplo n.º 17
0
        private void homeStationDropDownUpdated(object sender, SelectionChangedEventArgs e)
        {
            EDDIConfiguration eddiConfiguration = EDDIConfiguration.FromFile();
            string            homeStationName   = homeStationDropDown.SelectedItem?.ToString();

            if (eddiConfiguration.HomeStation != homeStationName)
            {
                eddiConfiguration.HomeStation = homeStationName == Properties.MainWindow.no_station ? null : homeStationName;
                eddiConfiguration             = EDDI.Instance.updateHomeStation(eddiConfiguration);
                eddiConfiguration.ToFile();
            }
        }
Ejemplo n.º 18
0
        private void eddiHomeSystemText_LostFocus(object sender, RoutedEventArgs e)
        {
            // Discard invalid results
            EDDIConfiguration eddiConfiguration = EDDIConfiguration.FromFile();

            if (!eddiConfiguration.validSystem)
            {
                eddiConfiguration.HomeSystem = null;
                eddiHomeSystemText.Text      = string.Empty;
                eddiConfiguration.ToFile();
            }
        }
Ejemplo n.º 19
0
        private void squadronPowerDropDownUpdated(object sender, SelectionChangedEventArgs e)
        {
            EDDIConfiguration eddiConfiguration = EDDIConfiguration.FromFile();
            string            squadronPower     = squadronPowerDropDown.SelectedItem?.ToString();

            if ((eddiConfiguration.SquadronPower?.localizedName ?? "") != squadronPower)
            {
                eddiConfiguration.SquadronPower = Power.FromName(squadronPower);
                eddiConfiguration.ToFile();

                EDDI.Instance.Cmdr.squadronpower = eddiConfiguration.SquadronPower;
            }
        }
Ejemplo n.º 20
0
        private void squadronRankDropDownUpdated(object sender, SelectionChangedEventArgs e)
        {
            EDDIConfiguration eddiConfiguration = EDDIConfiguration.FromFile();
            string            squadronRank      = squadronRankDropDown.SelectedItem.ToString();

            if (eddiConfiguration.SquadronRank.edname != squadronRank)
            {
                eddiConfiguration.SquadronRank = SquadronRank.FromName(squadronRank);
                eddiConfiguration.ToFile();

                EDDI.Instance.Cmdr.squadronrank = eddiConfiguration.SquadronRank;
            }
        }
Ejemplo n.º 21
0
 public static void ApplyAnyOverrideCulture(EDDIConfiguration configuration)
 {
     try
     {
         // we are using the InvariantCulture name "" to mean user's culture
         CultureInfo overrideCulture = string.IsNullOrEmpty(configuration.OverrideCulture) ? null : new CultureInfo(configuration.OverrideCulture);
         ApplyCulture(overrideCulture);
     }
     catch
     {
         ApplyCulture(null);
         Debug.WriteLine("Culture [{0}] not available", configuration.OverrideCulture);
     }
 }
Ejemplo n.º 22
0
        private void insuranceChanged(object sender, TextChangedEventArgs e)
        {
            EDDIConfiguration eddiConfiguration = EDDIConfiguration.FromFile();

            try
            {
                eddiConfiguration.Insurance = string.IsNullOrWhiteSpace(eddiInsuranceDecimal.Text) ? 5 : Convert.ToDecimal(eddiInsuranceDecimal.Text);
                eddiConfiguration.ToFile();
            }
            catch
            {
                // Bad user input; ignore it
            }
        }
Ejemplo n.º 23
0
        private void eddiSquadronIDText_LostFocus(object sender, RoutedEventArgs e)
        {
            // Discard invalid results
            EDDIConfiguration eddiConfiguration = EDDIConfiguration.FromFile();

            if (eddiConfiguration.SquadronID != null)
            {
                if (eddiConfiguration.SquadronID.Contains(" ") || eddiConfiguration.SquadronID.Length > 4)
                {
                    eddiConfiguration.SquadronID = null;
                    squadronSystemDropDown.Text  = string.Empty;
                    eddiConfiguration.ToFile();
                }
            }
        }
Ejemplo n.º 24
0
        private void ConfigureSquadronRankOptions(EDDIConfiguration configuration)
        {
            List <string> SquadronRankOptions = new List <string>();

            foreach (SquadronRank squadronrank in SquadronRank.AllOfThem)
            {
                if (configuration.SquadronName == null && squadronrank != SquadronRank.None)
                {
                    break;
                }
                SquadronRankOptions.Add(squadronrank.localizedName);
            }
            // Don't sort
            squadronRankDropDown.ItemsSource = SquadronRankOptions;
        }
Ejemplo n.º 25
0
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            EDDIConfiguration eddiConfiguration = EDDIConfiguration.FromFile();

            if (value == null)
            {
                return(ValidationResult.ValidResult);
            }
            if (eddiConfiguration.validSystem)
            {
                return(ValidationResult.ValidResult);
            }
            else
            {
                return(new ValidationResult(false, "Invalid System"));
            }
        }
Ejemplo n.º 26
0
        private void SquadronSystemDropDown_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            void changeHandler(string newValue)
            {
                // Update configuration to new squadron system
                EDDIConfiguration eddiConfiguration = EDDIConfiguration.FromFile();

                eddiConfiguration.SquadronSystem = newValue;
                eddiConfiguration = EDDI.Instance.updateSquadronSystem(eddiConfiguration);
                eddiConfiguration.ToFile();

                // Update squadron faction options for new system
                ConfigureSquadronFactionOptions(eddiConfiguration);
            }

            squadronSystemDropDown.SelectionDidChange(changeHandler);
        }
Ejemplo n.º 27
0
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            EDDIConfiguration eddiConfiguration = EDDIConfiguration.FromFile();

            if (value == null)
            {
                return(ValidationResult.ValidResult);
            }
            if (eddiConfiguration.validStation)
            {
                return(ValidationResult.ValidResult);
            }
            else
            {
                return(new ValidationResult(false, Properties.EddiResources.invalid_station));
            }
        }
Ejemplo n.º 28
0
        // Handle changes to the editable home system combo box
        private void HomeSystemText_TextChanged(object sender, TextChangedEventArgs e)
        {
            EDDIConfiguration eddiConfiguration = EDDIConfiguration.FromFile();

            void changeHandler()
            {
                // Reset the home station due to selecting new home system
                if (eddiConfiguration.HomeStation != null)
                {
                    eddiConfiguration.HomeStation    = null;
                    homeStationDropDown.SelectedItem = Properties.MainWindow.no_station;
                    ConfigureHomeStationOptions(null);
                    eddiConfiguration.ToFile();
                }
            }

            homeSystemDropDown.TextDidChange(sender, e, eddiConfiguration.HomeSystem, changeHandler);
        }
Ejemplo n.º 29
0
        private void squadronNameChanged(object sender, TextChangedEventArgs e)
        {
            EDDIConfiguration eddiConfiguration = EDDIConfiguration.FromFile();

            if (eddiConfiguration.SquadronName != eddiSquadronNameText.Text)
            {
                eddiConfiguration.SquadronName = string.IsNullOrWhiteSpace(eddiSquadronNameText.Text) ? null : eddiSquadronNameText.Text.Trim();
                if (eddiConfiguration.SquadronName == null)
                {
                    eddiConfiguration.SquadronID = null;
                    eddiSquadronIDText.Text      = string.Empty;

                    squadronSystemDropDown.Text = string.Empty;
                }
                eddiConfiguration = resetSquadronRank(eddiConfiguration);
                eddiConfiguration.ToFile();

                EDDI.Instance.Cmdr.squadronname = eddiConfiguration.SquadronName;
            }
        }
Ejemplo n.º 30
0
        private List <TabItem> LoadMonitors(EDDIConfiguration eddiConfiguration)
        {
            List <TabItem> result = new List <TabItem>();

            foreach (EDDIMonitor monitor in EDDI.Instance.monitors)
            {
                Logging.Debug("Adding configuration tab for " + monitor.MonitorName());

                System.Windows.Controls.UserControl monitorConfiguration = monitor.ConfigurationTabItem();
                // Only show a tab if this can be turned off or has configuration elements
                if (monitorConfiguration != null || !monitor.IsRequired())
                {
                    PluginSkeleton skeleton = new PluginSkeleton(monitor.MonitorName());
                    skeleton.plugindescription.Text = monitor.MonitorDescription();

                    if (eddiConfiguration.Plugins.TryGetValue(monitor.MonitorName(), out bool enabled))
                    {
                        skeleton.pluginenabled.IsChecked = enabled;
                    }
                    else
                    {
                        // Default to enabled
                        skeleton.pluginenabled.IsChecked = true;
                        eddiConfiguration.ToFile();
                    }

                    // Add monitor-specific configuration items
                    if (monitorConfiguration != null)
                    {
                        skeleton.panel.Children.Add(monitorConfiguration);
                    }

                    TabItem item = new TabItem {
                        Header = monitor.LocalizedMonitorName()
                    };
                    item.Content = skeleton;
                    result.Add(item);
                }
            }
            return(result);
        }
        /// <summary>
        /// Obtain configuration from a file.  If the file name is not supplied the the default
        /// path of Constants.Data_DIR\eddi.json is used
        /// </summary>
        public static EDDIConfiguration FromFile(string filename=null)
        {
            if (filename == null)
            {
                filename = Constants.DATA_DIR + @"\eddi.json";
            }

            EDDIConfiguration configuration = new EDDIConfiguration();
            try
            {
                configuration = JsonConvert.DeserializeObject<EDDIConfiguration>(File.ReadAllText(filename));
            }
            catch {}
            configuration.dataPath = filename;
            if (configuration.Plugins == null)
            {
                configuration.Plugins = new Dictionary<string, bool>();
            }

            return configuration;
        }