Пример #1
0
        void LoadLibrary()
        {
            FileHelper.CreatePath(LibraryPath);
            List <string> files = new List <string>();

            foreach (FileInfo f in new DirectoryInfo(LibraryPath).GetFiles())
            {
                files.Add(f.Name);
            }
            if (files.Count == 0)
            {
                try
                {
                    IList <Preset> collection = EngineeringHelper.LoadPresetFile(ArtemisTarget);

                    EngineeringHelper.WritePresetFile(System.IO.Path.Combine(LibraryPath, "Artemis.dat"), collection);
                    files.Add("Artemis.dat");
                }
                catch (InvalidPresetFileException)
                {
                    //Can be ignored--handling this issue is already part of elsewhere.
                }
            }
            Library = new ObservableCollection <string>(files);
        }
Пример #2
0
        void Import()
        {
            OpenFileDialog diag = new OpenFileDialog();

            diag.Filter     = "Data files (*.dat)|*.dat|All Files (*.*)|*.*";
            diag.DefaultExt = ".dat";
            diag.Title      = "Select file to import";
            if (diag.ShowDialog() == true)
            {
                try
                {
                    PresetItems = new ObservableCollection <Preset>(EngineeringHelper.LoadPresetFile(diag.FileName));
                }
                catch (InvalidPresetFileException)
                {
                    Locations.MessageBoxShow("Engineering preset file is invalid.  Cannot import.", MessageBoxButton.OK, MessageBoxImage.Hand);
                }
                string file = new FileInfo(diag.FileName).Name;

                if (IsAlreadyInLibrary(file))
                {
                    PromptDialog diagP = new PromptDialog();
                    diagP.Title = "Engineering Preset";
                    diagP.Label = "The name already exists.   Provide a new name for the imported preset:";
                    if (diagP.ShowDialog() == true)
                    {
                        string f = null;
                        if (diagP.Text.EndsWith(".dat", StringComparison.OrdinalIgnoreCase))
                        {
                            file = diagP.Text;
                        }
                        else
                        {
                            file = diagP.Text + ".dat";
                        }

                        if (IsAlreadyInLibrary(f))
                        {
                            if (Locations.MessageBoxShow("File is already in library.\r\n\r\nOverwrite?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
                            {
                                return;
                            }
                        }
                        f = System.IO.Path.Combine(LibraryPath, file);
                        EngineeringHelper.WritePresetFile(f, PresetItems);
                    }
                    else
                    {
                        CurrentFile = null;
                        return;
                    }
                }
                Library.Add(file);
                CurrentFile = file;
            }
        }
Пример #3
0
 void LoadData()
 {
     if (!EngineeringHelper.IsSupportedVersion)
     {
         if (Locations.MessageBoxShow("The current Artemis version is not known to be compatible with this process.\r\n\r\nProceeding risks corrupting data.\r\n\r\nDo you wish to proceed?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
         {
             Okay = false;
             return;
         }
     }
     CurrentFile = null;
     try
     {
         PresetItems = new ObservableCollection <Preset>(EngineeringHelper.LoadPresetFile(ArtemisTarget));
     }
     catch (InvalidPresetFileException)
     {
         ProcessInvalidFile(ArtemisTarget, false);
     }
 }
Пример #4
0
        private void LoadStored_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;

            if (btn != null)
            {
                string dat = btn.CommandParameter as string;
                if (!string.IsNullOrEmpty(dat))
                {
                    string f = System.IO.Path.Combine(LibraryPath, dat);
                    try
                    {
                        PresetItems = new ObservableCollection <Preset>(EngineeringHelper.LoadPresetFile(f));
                    }
                    catch (InvalidPresetFileException)
                    {
                        ProcessInvalidFile(f, true);
                    }
                }
            }
        }