public void SaveNameList(IList <Effect> effects) { SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.Title = "Save Name List"; saveDialog.Filter = "XML file | *.xml"; saveDialog.InitialDirectory = Path.GetFullPath(NameListDir); saveDialog.AddExtension = true; saveDialog.ShowDialog(); if (!String.IsNullOrWhiteSpace(saveDialog.FileName)) { string selectedDir = Path.GetDirectoryName(saveDialog.FileName); //Create the Name List NameList nameList = new NameList(); nameList.Names = new List <NameListEntry>(); foreach (var effect in effects) { if (effect.NameList != null) { nameList.Names.Add(new NameListEntry() { EffectID = effect.IndexNum, Description = effect.NameList }); } } //Save Name List nameList.Save(saveDialog.FileName); //Add Name List to current list if (selectedDir == Path.GetFullPath(NameListDir)) { NameListFile nameListFile = new NameListFile(); nameListFile.Name = Path.GetFileNameWithoutExtension(saveDialog.FileName); nameListFile.path = saveDialog.FileName; nameListFile.File = nameList; LoadedNameLists.Add(nameListFile); } MessageBox.Show("The name list was saved.", "Save Name List", MessageBoxButton.OK, MessageBoxImage.Information); } else { MessageBox.Show("The entered path was invalid.", "Save Name List", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void LoadNameLists() { if (Directory.Exists(NameListDir)) { string[] files = Directory.GetFiles(NameListDir); foreach (var file in files) { try { LoadedNameLists.Add(new NameListFile() { Name = Path.GetFileNameWithoutExtension(file), path = file }); } catch { } } } }