private void AddToDeletedDefaultAc(string path, string reg)
 {
     if (Paths.PathsAreSame(Path.GetDirectoryName(path), ConfigLoader.DefaultFolderPath))
     {
         var deleted = new DeletedDefaultAc();
         var succeed = deleted.Add(reg);
         if (!succeed)
         {
             ParentControl.ShowError(deleted.ErrorMessage);
         }
     }
 }
 private bool TryDeleteConfig(string path)
 {
     try
     {
         File.Delete(path);
         return(true);
     }
     catch
     {
         ParentControl.ShowError("Failed to delete the selected config.");
         return(false);
     }
 }
 private string TryGetFileName()
 {
     try
     {
         return(GetFileName());
     }
     catch (NoFileNameAvailException)
     {
         // FileNameGenerator cannot generate a file name.
         ParentControl.ShowError("Failed to save config file.");
         return(null);
     }
 }
        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.");
            }
        }