Example #1
0
 private AircraftConfigItem TryValidate()
 {
     try
     {
         return(new AcConfigValidator(elem).Validate());
     }
     catch (InvalidUserInputException ex)
     {
         ParentControl.ShowWarning(ex.Message);
         return(null);
     }
 }
Example #2
0
        private void DeleteCurrentConfigFile()
        {
            var file = currentConfig.FilePath;

            try
            {
                File.Delete(file);
            }
            catch (Exception e)
            {
                LoggerInstance.Log(e);
                ParentControl.ShowWarning("The config was saved but the old config cannot" +
                                          $"be deleted. Please manually delete {Path.GetFullPath(file)}.");
            }
        }
Example #3
0
        public void SaveConfig(object sender, EventArgs e)
        {
            var config = TryValidate();

            if (config == null)
            {
                return;
            }

            // New profile must have a unique registration.
            if (!InEditMode && profiles.AcConfigs.Find(config.Registration) != null)
            {
                ParentControl.ShowWarning("Registration already exists. Please use another one.");
                return;
            }

            var fn = TryGetFileName();

            if (fn == null)
            {
                return;
            }

            if (TrySaveConfig(config, fn))
            {
                if (InEditMode)
                {
                    if (fn != currentConfig.FilePath)
                    {
                        DeleteCurrentConfigFile();
                    }
                    AddToDeletedDefaultAc(currentConfig.FilePath, currentConfig.Config.Registration);
                }

                RemoveOldConfig();
                profiles.AcConfigs.Add(new AircraftConfig(config, fn));
                ShowSelectionGroupBox();
                AircraftsChanged?.Invoke(this, EventArgs.Empty);
            }
            else
            {
                ParentControl.ShowError("Failed to save config file.");
            }
        }