FromFile() public static méthode

Obtain configuration from a file. If the file name is not supplied the the default path of Constants.Data_DIR\eddi.json is used
public static FromFile ( string filename = null ) : EDDIConfiguration
filename string
Résultat EDDIConfiguration
Exemple #1
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
            }
        }
Exemple #2
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();
                }
            }
        }
Exemple #3
0
        private void betaProgrammeDisabled(object sender, RoutedEventArgs e)
        {
            EDDIConfiguration eddiConfiguration = EDDIConfiguration.FromFile();

            eddiConfiguration.Beta = eddiBetaProgramme.IsChecked.Value;
            eddiConfiguration.ToFile();
            if (runBetaCheck)
            {
                // Because we have changed to not wanting beta upgrades we need to re-check upgrade information
                EDDI.Instance.CheckUpgrade();
                setStatusInfo();
            }
            else
            {
                runBetaCheck = true;
            }
        }
Exemple #4
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));
            }
        }
Exemple #5
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);
        }
Exemple #6
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"));
            }
        }
Exemple #7
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);
        }
Exemple #8
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;
            }
        }
Exemple #9
0
        private void squadronFactionDropDownUpdated(object sender, SelectionChangedEventArgs e)
        {
            EDDIConfiguration eddiConfiguration = EDDIConfiguration.FromFile();
            string            squadronFaction   = squadronFactionDropDown.SelectedItem?.ToString();

            if (eddiConfiguration.SquadronFaction != squadronFaction)
            {
                eddiConfiguration.SquadronFaction  = squadronFaction == "None" ? null : squadronFaction;
                EDDI.Instance.Cmdr.squadronfaction = eddiConfiguration.SquadronFaction;

                if (squadronFaction != "None")
                {
                    StarSystem system  = StarSystemSqLiteRepository.Instance.GetOrCreateStarSystem(eddiConfiguration.SquadronSystem, true);
                    Faction    faction = system.factions.Find(f => f.name == squadronFaction);

                    if (eddiConfiguration.SquadronAllegiance != faction.Allegiance)
                    {
                        eddiConfiguration.SquadronAllegiance = faction.Allegiance;
                        eddiConfiguration.ToFile();

                        EDDI.Instance.Cmdr.squadronallegiance = faction.Allegiance;

                        squadronPowerDropDown.SelectedItem = Power.None.localizedName;
                        ConfigureSquadronPowerOptions(eddiConfiguration);
                    }
                }
                else
                {
                    eddiConfiguration.SquadronAllegiance = Superpower.None;
                    eddiConfiguration.ToFile();

                    EDDI.Instance.Cmdr.squadronallegiance = Superpower.None;

                    squadronPowerDropDown.SelectedItem = Power.None.localizedName;
                    ConfigureSquadronPowerOptions(eddiConfiguration);
                }
                eddiConfiguration.ToFile();
            }
        }
Exemple #10
0
        public static void Main()
        {
            if (!FromVA && AlreadyRunning())
            {
                return;
            }

            App app = new App();

            app.Exit += OnExit;

            // Prepare to start the application
            Logging.incrementLogs(); // Increment to a new log file.
            EDDIConfiguration configuration = EDDIConfiguration.FromFile();

            StartRollbar(configuration.DisableTelemetry); // do immediately to initialize error reporting
            ApplyAnyOverrideCulture(configuration);       // this must be done before any UI is generated

            // Start by fetching information from the update server, and handling appropriately
            EddiUpgrader.CheckUpgrade();
            if (EddiUpgrader.UpgradeRequired)
            {
                // We are too old to continue; initialize in a "safe mode".
                EDDI.Init(true);
            }

            if (FromVA)
            {
                // Start with the MainWindow hidden
                app.MainWindow = new MainWindow();
                app.Run();
            }
            else
            {
                // Start by displaying the MainWindow
                app.Run(new MainWindow());
            }
        }
Exemple #11
0
        private EDDI()
        {
            try
            {
                Logging.Info(Constants.EDDI_NAME + " " + Constants.EDDI_VERSION + " starting");

                // Start by ensuring that our primary data structures have something in them.  This allows them to be updated
                // from any source
                Cmdr     = new Commander();
                Ship     = new Ship();
                Shipyard = new List <Ship>();

                // Set up the EDDI configuration
                EDDIConfiguration configuration = EDDIConfiguration.FromFile();
                Logging.Verbose = configuration.Debug;
                if (configuration.HomeSystem != null && configuration.HomeSystem.Trim().Length > 0)
                {
                    HomeStarSystem = StarSystemSqLiteRepository.Instance.GetOrCreateStarSystem(configuration.HomeSystem.Trim());
                    if (HomeStarSystem != null)
                    {
                        Logging.Debug("Home star system is " + HomeStarSystem.name);
                        if (configuration.HomeStation != null && configuration.HomeStation.Trim().Length > 0)
                        {
                            string homeStationName = configuration.HomeStation.Trim();
                            foreach (Station station in HomeStarSystem.stations)
                            {
                                if (station.name == homeStationName)
                                {
                                    HomeStation = station;
                                    Logging.Debug("Home station is " + HomeStation.name);
                                    break;
                                }
                            }
                        }
                    }
                }

                // Set up the app service
                if (CompanionAppService.Instance.CurrentState == CompanionAppService.State.READY)
                {
                    // Carry out initial population of profile
                    try
                    {
                        refreshProfile();
                    }
                    catch (Exception ex)
                    {
                        Logging.Debug("Failed to obtain profile: " + ex);
                    }
                }

                Cmdr.insurance = configuration.Insurance;
                if (Cmdr.name != null)
                {
                    Logging.Info("EDDI access to the companion app is enabled");
                }
                else
                {
                    // If InvokeUpdatePlugin failed then it will have have left an error message, but this once we ignore it
                    Logging.Info("EDDI access to the companion app is disabled");
                }

                // Set up the star map service
                StarMapConfiguration starMapCredentials = StarMapConfiguration.FromFile();
                if (starMapCredentials != null && starMapCredentials.apiKey != null)
                {
                    // Commander name might come from star map credentials or the companion app's profile
                    string commanderName = null;
                    if (starMapCredentials.commanderName != null)
                    {
                        commanderName = starMapCredentials.commanderName;
                    }
                    else if (Cmdr != null && Cmdr.name != null)
                    {
                        commanderName = Cmdr.name;
                    }
                    if (commanderName != null)
                    {
                        starMapService = new StarMapService(starMapCredentials.apiKey, commanderName);
                        Logging.Info("EDDI access to EDSM is enabled");
                    }
                }
                if (starMapService == null)
                {
                    Logging.Info("EDDI access to EDSM is disabled");
                }

                // We always start in normal space
                Environment = Constants.ENVIRONMENT_NORMAL_SPACE;

                // Set up monitors and responders
                monitors   = findMonitors();
                responders = findResponders();

                // Check for an update
                string response;
                try
                {
                    if (Constants.EDDI_VERSION.Contains("b"))
                    {
                        response = Net.DownloadString("http://api.eddp.co/betaversion");
                    }
                    else
                    {
                        response = Net.DownloadString("http://api.eddp.co/version");
                    }
                    if (Versioning.Compare(response, Constants.EDDI_VERSION) == 1)
                    {
                        SpeechService.Instance.Say(null, "EDDI version " + response.Replace(".", " point ") + " is now available.", false);
                    }
                }
                catch
                {
                    SpeechService.Instance.Say(null, "There was a problem connecting to external data services; some features may not work fully", false);
                }

                Logging.Info(Constants.EDDI_NAME + " " + Constants.EDDI_VERSION + " initialised");
            }
            catch (Exception ex)
            {
                Logging.Error("Failed to initialise: " + ex.ToString());
            }
        }
Exemple #12
0
        public MainWindow(bool fromVA = false)
        {
            InitializeComponent();

            this.fromVA = fromVA;

            // Start the EDDI instance
            EDDI.Instance.Start();

            // Configure the EDDI tab
            versionText.Text = Constants.EDDI_VERSION;

            //// Need to set up the correct information in the hero text depending on from where we were started
            if (fromVA)
            {
                heroText.Text = "Any changes made here will take effect automatically in VoiceAttack.  You can close this window when you have finished.";
            }
            else
            {
                heroText.Text = "If you are using VoiceAttack then please close this window before you start VoiceAttack for your changes to take effect.  You can access this window from VoiceAttack with the \"Configure EDDI\" command.";
            }

            EDDIConfiguration eddiConfiguration = EDDIConfiguration.FromFile();

            eddiHomeSystemText.Text      = eddiConfiguration.HomeSystem;
            eddiHomeStationText.Text     = eddiConfiguration.HomeStation;
            eddiInsuranceDecimal.Text    = eddiConfiguration.Insurance.ToString(CultureInfo.InvariantCulture);
            eddiVerboseLogging.IsChecked = eddiConfiguration.Debug;

            Logging.Verbose = eddiConfiguration.Debug;

            // Configure the Companion App tab
            CompanionAppCredentials companionAppCredentials = CompanionAppCredentials.FromFile();

            companionAppEmailText.Text = companionAppCredentials.email;
            // See if the credentials work
            try
            {
                profile = CompanionAppService.Instance.Profile();
                if (profile == null)
                {
                    setUpCompanionAppComplete("Your connection to the companion app is good but experiencing temporary issues.  Your information should be available soon");
                }
                else
                {
                    setUpCompanionAppComplete("Your connection to the companion app is operational, Commander " + profile.Cmdr.name);
                }
            }
            catch (Exception)
            {
                if (CompanionAppService.Instance.CurrentState == CompanionAppService.State.NEEDS_LOGIN)
                {
                    // Fall back to stage 1
                    setUpCompanionAppStage1();
                }
                else if (CompanionAppService.Instance.CurrentState == CompanionAppService.State.NEEDS_CONFIRMATION)
                {
                    // Fall back to stage 2
                    setUpCompanionAppStage2();
                }
            }

            if (profile != null)
            {
                setShipyardFromConfiguration();
            }

            // Configure the Text-to-speech tab
            SpeechServiceConfiguration speechServiceConfiguration = SpeechServiceConfiguration.FromFile();
            List <string> speechOptions = new List <string>();

            speechOptions.Add("Windows TTS default");
            try
            {
                using (SpeechSynthesizer synth = new SpeechSynthesizer())
                {
                    foreach (InstalledVoice voice in synth.GetInstalledVoices())
                    {
                        if (voice.Enabled && (!voice.VoiceInfo.Name.Contains("Microsoft Server Speech Text to Speech Voice")))
                        {
                            speechOptions.Add(voice.VoiceInfo.Name);
                        }
                    }
                }

                ttsVoiceDropDown.ItemsSource = speechOptions;
                ttsVoiceDropDown.Text        = speechServiceConfiguration.StandardVoice == null ? "Windows TTS default" : speechServiceConfiguration.StandardVoice;
            }
            catch (Exception e)
            {
                Logging.Warn("" + Thread.CurrentThread.ManagedThreadId + ": Caught exception " + e);
            }
            ttsVolumeSlider.Value         = speechServiceConfiguration.Volume;
            ttsRateSlider.Value           = speechServiceConfiguration.Rate;
            ttsEffectsLevelSlider.Value   = speechServiceConfiguration.EffectsLevel;
            ttsDistortCheckbox.IsChecked  = speechServiceConfiguration.DistortOnDamage;
            disableSsmlCheckbox.IsChecked = speechServiceConfiguration.DisableSsml;

            ttsTestShipDropDown.ItemsSource = ShipDefinitions.ShipModels;
            ttsTestShipDropDown.Text        = "Adder";

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

                PluginSkeleton skeleton = new PluginSkeleton(monitor.MonitorName());
                skeleton.plugindescription.Text = monitor.MonitorDescription();

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

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

                TabItem item = new TabItem {
                    Header = monitor.MonitorName()
                };
                item.Content = skeleton;
                tabControl.Items.Add(item);
            }

            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();

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

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

                TabItem item = new TabItem {
                    Header = responder.ResponderName()
                };
                item.Content = skeleton;
                tabControl.Items.Add(item);
            }

            EDDI.Instance.Start();
        }
Exemple #13
0
        public MainWindow(bool fromVA = false)
        {
            InitializeComponent();

            this.fromVA = fromVA;

            // Start the EDDI instance
            EDDI.FromVA = fromVA;
            EDDI.Instance.Start();

            // Configure the EDDI tab
            setStatusInfo();

            // Need to set up the correct information in the hero text depending on from where we were started
            if (fromVA)
            {
                // Allow the EDDI VA plugin to change window state
                VaWindowStateChange = new vaWindowStateChangeDelegate(OnVaWindowStateChange);
                heroText.Text       = Properties.EddiResources.change_affect_va;
            }
            else
            {
                heroText.Text = Properties.EddiResources.if_using_va;
            }

            EDDIConfiguration eddiConfiguration = EDDIConfiguration.FromFile();

            eddiHomeSystemText.Text      = eddiConfiguration.validSystem == true ? eddiConfiguration.HomeSystem : string.Empty;
            eddiHomeStationText.Text     = eddiConfiguration.validStation == true ? eddiConfiguration.HomeStation : string.Empty;
            eddiVerboseLogging.IsChecked = eddiConfiguration.Debug;
            eddiBetaProgramme.IsChecked  = eddiConfiguration.Beta;
            if (eddiConfiguration.Gender == "Female")
            {
                eddiGenderFemale.IsChecked = true;
            }
            else if (eddiConfiguration.Gender == "Male")
            {
                eddiGenderMale.IsChecked = true;
            }
            else
            {
                eddiGenderNeither.IsChecked = true;
            }

            List <LanguageDef> langs = GetAvailableLangs();

            chooseLanguageDropDown.ItemsSource       = langs;
            chooseLanguageDropDown.DisplayMemberPath = "displayName";
            chooseLanguageDropDown.SelectedItem      = langs.Find(l => l.ci.Name == Eddi.Properties.Settings.Default.OverrideCulture);
            chooseLanguageDropDown.SelectionChanged += (sender, e) =>
            {
                LanguageDef cultureDef = (LanguageDef)chooseLanguageDropDown.SelectedValue;
                Eddi.Properties.Settings.Default.OverrideCulture = cultureDef.ci.Name;
            };

            // Configure the Frontier API tab
            CompanionAppCredentials companionAppCredentials = CompanionAppCredentials.FromFile();

            companionAppEmailText.Text = companionAppCredentials.email;
            // See if the credentials work
            try
            {
                profile = CompanionAppService.Instance.Profile();
                if (profile == null)
                {
                    setUpCompanionAppComplete(Properties.EddiResources.frontier_api_temp_nok);
                }
                else
                {
                    setUpCompanionAppComplete(String.Format(Properties.EddiResources.frontier_api_ok, profile.Cmdr.name));
                }
            }
            catch (Exception)
            {
                if (CompanionAppService.Instance.CurrentState == CompanionAppService.State.NEEDS_LOGIN)
                {
                    // Fall back to stage 1
                    setUpCompanionAppStage1();
                }
                else if (CompanionAppService.Instance.CurrentState == CompanionAppService.State.NEEDS_CONFIRMATION)
                {
                    // Fall back to stage 2
                    setUpCompanionAppStage2();
                }
            }

            // Configure the Text-to-speech tab
            ConfigureTTS();

            LoadMonitors(eddiConfiguration);

            LoadResponders(eddiConfiguration);

            RestoreWindowState();
            EDDI.Instance.Start();
        }
Exemple #14
0
        private void SquadronSystemDropDown_LostFocus(object sender, RoutedEventArgs e)
        {
            EDDIConfiguration eddiConfiguration = EDDIConfiguration.FromFile();

            squadronSystemDropDown.DidLoseFocus(oldValue: eddiConfiguration.SquadronSystem);
        }
Exemple #15
0
        public MainWindow(bool fromVA = false)
        {
            InitializeComponent();

            this.fromVA = fromVA;

            // Start the EDDI instance
            EDDI.FromVA = fromVA;
            EDDI.Instance.Start();

            // Configure the EDDI tab
            setStatusInfo();

            // Need to set up the correct information in the hero text depending on from where we were started
            if (fromVA)
            {
                // Allow the EDDI VA plugin to change window state
                VaWindowStateChange = new vaWindowStateChangeDelegate(OnVaWindowStateChange);
                heroText.Text       = Properties.EddiResources.change_affect_va;
            }
            else
            {
                heroText.Text = Properties.EddiResources.if_using_va;
            }

            EDDIConfiguration eddiConfiguration = EDDIConfiguration.FromFile();

            // Setup home system & station from config file
            homeSystemDropDown.ItemsSource = new List <string> {
                eddiConfiguration.HomeSystem ?? string.Empty
            };
            homeSystemDropDown.SelectedItem = eddiConfiguration.HomeSystem ?? string.Empty;
            ConfigureHomeStationOptions(eddiConfiguration.HomeSystem);
            homeStationDropDown.SelectedItem = eddiConfiguration.HomeStation ?? Properties.MainWindow.no_station;

            eddiVerboseLogging.IsChecked = eddiConfiguration.Debug;
            eddiBetaProgramme.IsChecked  = eddiConfiguration.Beta;
            if (eddiConfiguration.Gender == "Female")
            {
                eddiGenderFemale.IsChecked = true;
            }
            else if (eddiConfiguration.Gender == "Male")
            {
                eddiGenderMale.IsChecked = true;
            }
            else
            {
                eddiGenderNeither.IsChecked = true;
            }
            eddiSquadronNameText.Text         = eddiConfiguration.SquadronName ?? string.Empty;
            eddiSquadronIDText.Text           = eddiConfiguration.SquadronID ?? string.Empty;
            squadronRankDropDown.SelectedItem = (eddiConfiguration.SquadronRank ?? SquadronRank.None).localizedName;
            ConfigureSquadronRankOptions(eddiConfiguration);

            // Setup squadron home system from config file
            squadronSystemDropDown.ItemsSource = new List <string> {
                eddiConfiguration.SquadronSystem ?? string.Empty
            };
            squadronSystemDropDown.SelectedItem = eddiConfiguration.SquadronSystem ?? string.Empty;

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

            List <LanguageDef> langs = GetAvailableLangs(); // already correctly sorted

            chooseLanguageDropDown.ItemsSource       = langs;
            chooseLanguageDropDown.DisplayMemberPath = "displayName";
            chooseLanguageDropDown.SelectedItem      = langs.Find(l => l.ci.Name == Eddi.Properties.Settings.Default.OverrideCulture);
            chooseLanguageDropDown.SelectionChanged += (sender, e) =>
            {
                LanguageDef cultureDef = (LanguageDef)chooseLanguageDropDown.SelectedItem;
                Eddi.Properties.Settings.Default.OverrideCulture = cultureDef.ci.Name;
            };

            // Configure the Frontier API tab
            CompanionAppCredentials companionAppCredentials = CompanionAppCredentials.Load();

            CompanionAppService.Instance.StateChanged += companionApiStatusChanged;

            // Configure the Text-to-speech tab
            ConfigureTTS();

            LoadAndSortTabs(eddiConfiguration);

            RestoreWindowState();
            EDDI.Instance.MainWindow = this;
            EDDI.Instance.Start();
        }
Exemple #16
0
        /// <summary>
        /// Check to see if an upgrade is available and populate relevant variables
        /// </summary>
        public static void CheckUpgrade()
        {
            // Clear the old values
            UpgradeRequired  = false;
            UpgradeAvailable = false;
            UpgradeLocation  = null;
            UpgradeVersion   = null;
            Motd             = null;

            try
            {
                ServerInfo updateServerInfo = ServerInfo.FromServer(Constants.EDDI_SERVER_URL);
                if (updateServerInfo == null)
                {
                    throw new Exception("Failed to contact update server");
                }
                else
                {
                    EDDIConfiguration configuration = EDDIConfiguration.FromFile();
                    InstanceInfo      info          = configuration.Beta ? updateServerInfo.beta : updateServerInfo.production;
                    string            spokenVersion = info.version.Replace(".", $" {Eddi.Properties.EddiResources.point} ");
                    Motd = info.motd;
                    if (updateServerInfo.productionbuilds != null)
                    {
                        ProductionBuilds = updateServerInfo.productionbuilds;
                    }
                    Utilities.Version minVersion = new Utilities.Version(info.minversion);
                    if (minVersion > Constants.EDDI_VERSION)
                    {
                        // There is a mandatory update available
                        if (!App.FromVA)
                        {
                            string message = String.Format(Eddi.Properties.EddiResources.mandatory_upgrade, spokenVersion);
                            SpeechService.Instance.Say(null, message, 0);
                        }
                        UpgradeRequired = true;
                        UpgradeLocation = info.url;
                        UpgradeVersion  = info.version;
                        return;
                    }

                    Utilities.Version latestVersion = new Utilities.Version(info.version);
                    if (latestVersion > Constants.EDDI_VERSION)
                    {
                        // There is an update available
                        if (!App.FromVA)
                        {
                            string message = String.Format(Eddi.Properties.EddiResources.update_available, spokenVersion);
                            SpeechService.Instance.Say(null, message, 0);
                        }
                        UpgradeAvailable = true;
                        UpgradeLocation  = info.url;
                        UpgradeVersion   = info.version;
                    }
                }
            }
            catch (Exception ex)
            {
                SpeechService.Instance.Say(null, Eddi.Properties.EddiResources.update_server_unreachable, 0);
                Logging.Warn("Failed to access " + Constants.EDDI_SERVER_URL, ex);
            }
        }