Esempio n. 1
0
 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);
         }
     }
 }
Esempio n. 2
0
 private bool TryDeleteConfig(string path)
 {
     try
     {
         File.Delete(path);
         return(true);
     }
     catch
     {
         ParentControl.ShowError("Failed to delete the selected config.");
         return(false);
     }
 }
Esempio n. 3
0
 private string TryGetFileName()
 {
     try
     {
         return(GetFileName());
     }
     catch (NoFileNameAvailException)
     {
         // FileNameGenerator cannot generate a file name.
         ParentControl.ShowError("Failed to save config file.");
         return(null);
     }
 }
Esempio n. 4
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.");
            }
        }