public void UpdateEpisodenNamesFromStorage() { FileInfo[] files = Folder.Files; List <EpisodeName> oldNames = episodesNames.ToList(); ObservableCollection <EpisodeName> names = new ObservableCollection <EpisodeName>(); foreach (FileInfo datei in files) { try { EpisodeName episodeName = new EpisodeName(datei.FullName); EpisodeName oldName = oldNames.FirstOrDefault(x => x.FullPath == episodeName.FullPath); if (oldName != null) { episodeName.Name = oldName.Name; } int insertIndex = GetInsertIndexWhenOrderedBySeasonAndEpisode(episodeName, names); names.Insert(insertIndex, episodeName); } catch { } } EpisodesNames = names; MaxEpisodeNumberText = names.Any() ? names.Max(x => x.EpisodeNumber).ToString() : "0"; }
public EpisodenNameWindow(EpisodeName episodeName) { InitializeComponent(); this.episodeName = episodeName; tblEpisodeFilename.Text = episodeName.FileNameWithoutExtension + ":"; tbxEpisodeName.Text = episodeName.Name; }
private int GetInsertIndexWhenOrderedBySeasonAndEpisode(EpisodeName episodeName, ObservableCollection <EpisodeName> list) { int index = 0; while (index < list.Count && list[index].SeasonNumber < episodeName.SeasonNumber) { index++; } while (index < list.Count && list[index].EpisodeNumber < episodeName.EpisodeNumber) { index++; } return(index); }