/Branches/krishmav/MediaScout/MainWindow.xaml.cs
C# | 5939 lines | 5253 code | 460 blank | 226 comment | 723 complexity | f5983b6aaa26ea44d3b0deab5e254252 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Shapes;
- using System.Windows.Interop;
- using System.IO;
- using System.Collections;
- using System.Collections.ObjectModel;
- using System.Data;
- using System.Threading;
- using System.Windows.Threading;
- using System.Text.RegularExpressions;
- using System.Xml;
- using System.Xml.Serialization;
- using System.Diagnostics;
- using System.Windows.Shell;
- using MediaScoutGUI.GUITypes;
- using MediaScout.Providers;
-
- namespace MediaScoutGUI
- {
- /// <summary>
- /// Interaction logic for Window1.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- //Delegates
-
- public MediaScout.MediaScoutMessage.Message Message;
-
- public delegate void MetadataCompletedHandler(Thread th, String reason, bool Reset);
- public event MetadataCompletedHandler MetadataCompleted;
-
- public delegate void TVShowChangedHandler(TVShow ts, bool IsRemoved);
- public event TVShowChangedHandler TVShowChanged;
- public delegate void SeasonChangedHandler(TVShow ts, Season s, bool IsRemoved);
- public event SeasonChangedHandler SeasonChanged;
- public delegate void EpisodeChangedHandler(TVShow ts, Season s, Episode e, bool IsRemoved);
- public event EpisodeChangedHandler EpisodeChanged;
- public delegate void MovieChangedHandler(Movie m, bool IsRemoved);
- public event MovieChangedHandler MovieChanged;
- public delegate void MovieFileChangedHandler(Movie m, MovieFile mf, bool IsRemoved);
- public event MovieFileChangedHandler MovieFileChanged;
- public delegate void ActorThumbChangedHandler(Person p);
- public event ActorThumbChangedHandler ActorThumbChanged;
-
- public delegate void FocusChangedHandler();
-
- public delegate void TaskbarProgressValueChangeHandler(int value);
- public delegate void TaskbarProgressStatusChangeHandler(TaskbarItemProgressState state);
-
- public delegate void TVShowImageChangedHandler(TVShow ts, TVShowPosterType type, bool IsLoading);
- public delegate void SeasonImageChangedHandler(Season s, TVShowPosterType type, bool IsLoading);
- public delegate void EpisodeImageChangedHandler(Episode e, String filename, bool IsLoading);
- public delegate void MovieImageChangedHandler(Movie m, MoviePosterType type, bool IsLoading);
- public delegate void MovieFileImageChangedHandler(MovieFile mf, MoviePosterType type, bool IsLoading);
-
- public delegate void PosterChangedHandler(Object obj, String id, bool IsMovie, Season s, String file);
- public delegate void BackdropChangedHandler(Object obj, String id, bool IsMovie, Season s, String file, String file1);
-
- //Collections
- private ObservableCollection<TVShow> tvshows = new ObservableCollection<TVShow>();
- private ObservableCollection<Movie> movies = new ObservableCollection<Movie>();
- private DispatchingCollection<ObservableCollection<TVShow>, TVShow> dispatchtvshows;
- private DispatchingCollection<ObservableCollection<Movie>, Movie> dispatchmovies;
-
- //Settings
- private List<String> ignoredFiles = new List<String>();
- private List<String> AllowedFileTypes;
- private List<String> AllowedSubtitleTypes;
-
- MediaScoutApp app;
- private bool WindowLoaded;
- //private System.Windows.Forms.NotifyIcon notifyIcon;
- //private System.Windows.Forms.ToolStripMenuItem mnuCancel;
- private JumpList jumplist;
- private JumpTask jumpCancel;
- private JumpTask jumpCancelAll;
- private JumpTask jumpOperationsSeparator;
-
- //Objects
- private MediaScout.TVScout TVScout = null;
- private MediaScout.MovieScout MovieScout = null;
- private FileSystemWatcher TVFSWatcher = null;
- private FileSystemWatcher MovieFSWatcher = null;
- private TheTVDBProvider tvdb = null;
- private TheMovieDBProvider tmdb = null;
- private Collection<Thread> tvThreads = new Collection<Thread>();
- private bool resetTVfolder = false;
- private bool resetMoviefolder = false;
-
- int currentvalue = 0;
- int maxvalue = 0;
-
- private TVShow SelectedTVShow;
- private int SelectedTVShowIndex = 0;
- private TVShow UnsortedEpisodes;
- private Season SelectedSeason;
- private int SelectedSeasonIndex = 0;
- private Episode SelectedEpisode;
- private int SelectedEpisodeIndex = 0;
- private Movie SelectedMovie;
- private int SelectedMovieIndex = 0;
- private Movie UnsortedFiles;
- private MovieFile SelectedMovieFile;
- private int SelectedMovieFileIndex = 0;
- private Person SelectedPerson;
- //private int SelectedPersonIndex = 0;
-
- private int LogTabIndex = 1;
-
- private int SelectedTabIndex = 0;
-
- #region To Enable/Disable for the Aero glass effect
-
- public Rect GetBoundsForGlassFrame()
- {
- return VisualTreeHelper.GetContentBounds(tcTabs);
- }
- public bool SetGlassFrame(bool ExtendGlass)
- {
- bool success = false;
- if (ExtendGlass)
- {
- // Extend glass
- Rect bounds = GetBoundsForGlassFrame();
- success = GlassHelper.ExtendGlassFrame(this, new Thickness(bounds.Left, bounds.Top, bounds.Right, bounds.Bottom));
- }
- else
- {
- // turn off glass...
- GlassHelper.DisableGlassFrame(this);
- success = true;
- }
- return success;
- }
- public IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
- {
- int WM_DWMCOMPOSITIONCHANGED = 0x031E; // for glass (when DWM / glass setting is changed)
- // handle the message for DWM when the aero glass is turned on or off
- if (msg == WM_DWMCOMPOSITIONCHANGED)
- {
- SetGlassFrame(GlassHelper.IsGlassEnabled);
- handled = true;
- }
-
- return IntPtr.Zero;
- }
-
- #endregion
-
-
- #region Window Routines
-
- public MainWindow(int SelectedTabIndex)
- {
- try
- {
- this.InitializeComponent();
- app = ((MediaScoutApp)Application.Current);
- //notifyIcon = app.notifyIcon;
- jumplist = app.jumplist;
-
- this.SelectedTabIndex = SelectedTabIndex;
- this.Message = new MediaScout.MediaScoutMessage.Message(TVScout_Message);
- tvdb = new TheTVDBProvider(Message);
- tmdb = new TheMovieDBProvider(Message);
-
- this.MetadataCompleted += new MetadataCompletedHandler(ResetUI);
- this.TVShowChanged += new TVShowChangedHandler(ResetTVShow);
- this.SeasonChanged += new SeasonChangedHandler(ResetSeason);
- this.EpisodeChanged += new EpisodeChangedHandler(ResetEpisode);
- this.MovieChanged += new MovieChangedHandler(ResetMovie);
- this.MovieFileChanged += new MovieFileChangedHandler(ResetMovieFile);
- this.ActorThumbChanged += new ActorThumbChangedHandler(ResetActorThumb);
-
- //creating directories
- String CacheDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\MediaScout\Cache";
- String TVCacheDir = CacheDir + @"\TVCache";
- String MovieCacheDir = CacheDir + @"\MovieCache";
- if (!Directory.Exists(CacheDir))
- Directory.CreateDirectory(CacheDir);
- if (!Directory.Exists(TVCacheDir))
- Directory.CreateDirectory(TVCacheDir);
- if (!Directory.Exists(MovieCacheDir))
- Directory.CreateDirectory(MovieCacheDir);
-
- SetCancelButtons();
-
- dispatchtvshows = new DispatchingCollection<ObservableCollection<TVShow>, TVShow>(tvshows, Dispatcher);
- dispatchmovies = new DispatchingCollection<ObservableCollection<Movie>, Movie>(movies, Dispatcher);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- //Debug.Write(ex.Message);
- }
- }
- private void Window_Loaded(object sender, RoutedEventArgs e)
- {
- Rect bounds = GetBoundsForGlassFrame();
- HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
- source.AddHook(new HwndSourceHook(WndProc));
-
- WindowLoaded = true;
- tcTabs.SelectedIndex = SelectedTabIndex;
- LoadOptions();
-
- //Dispatcher.Hooks.OperationPosted += new DispatcherHookEventHandler(Hooks_OperationPosted);
- }
- private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
- {
- Properties.Settings.Default.Zoom = zoomslider.Value.ToString();
- Properties.Settings.Default.Save();
-
- //When the application is closed, check wether the application is
- //exiting from menu or forms close button
- //if (!isAppExiting)
- //{
- // //if the forms close button is triggered, cancel the event and hide the form
- // //then show the notification ballon tip
-
- // e.Cancel = true;
- //}
- }
- private void Window_StateChanged(object sender, EventArgs e)
- {
-
- // if (this.WindowState == WindowState.Minimized)
- // {
- // //Hide();
- // if (app.showballoontip)
- // {
- // notifyIcon.BalloonTipIcon = System.Windows.Forms.ToolTipIcon.Info;
- // notifyIcon.BalloonTipTitle = "Media Scout";
- // notifyIcon.BalloonTipText = "Application minimized to the system tray. To open the application, double-click the icon in the system tray.";
- // notifyIcon.ShowBalloonTip(400);
- // }
- // }
- }
- private void Window_Closed(object sender, EventArgs e)
- {
- AbortAllThreads();
- app.Shutdown();
- }
-
- #endregion
-
-
- #region Loads all the options from the user configuration file
- private void LoadOptions()
- {
- //TV Options
- txtTVDropBox.Text = Properties.Settings.Default.TVDropBoxLocation;
- ChangeMonitorTVFolder();
- if(chkTVFSWatcher.IsEnabled)
- chkTVFSWatcher.IsChecked = Properties.Settings.Default.TVFSWatcher;
-
- chkSeriesPosters.IsChecked = Properties.Settings.Default.getSeriesPosters;
- chkSeasonPosters.IsChecked = Properties.Settings.Default.getSeasonPosters;
- chkEpPosters.IsChecked = Properties.Settings.Default.getEpisodePosters;
- chkMoveTVFiles.IsChecked = Properties.Settings.Default.moveTVFiles;
- chkSaveTVActors.IsChecked = Properties.Settings.Default.SaveTVActors;
-
- txtSeasonFolderName.Text = Properties.Settings.Default.SeasonFolderName;
- txtSpecialsFolderName.Text = Properties.Settings.Default.SpecialsFolderName;
-
- chkdownloadAllTVImages.IsChecked = Properties.Settings.Default.downloadAllTVImages;
- chkdownloadAllTVPosters.IsChecked = Properties.Settings.Default.downloadAllTVPosters;
- chkdownloadAllTVBackdrops.IsChecked = Properties.Settings.Default.downloadAllTVBackdrops;
- chkdownloadAllTVBanners.IsChecked = Properties.Settings.Default.downloadAllTVBanners;
- chkdownloadAllTVSeasonPosters.IsChecked = Properties.Settings.Default.downloadAllTVSeasonPosters;
- chkdownloadAllTVSeasonBackdrops.IsChecked = Properties.Settings.Default.downloadAllTVSeasonBackdrops;
-
- chkRenameTVFiles.IsChecked = Properties.Settings.Default.renameTVFiles;
- txtTVRenameFormat.Text = Properties.Settings.Default.TVfileformat;
- txtSeasonNumZeroPadding.Text = Properties.Settings.Default.SeasonNumZeroPadding;
- txtEpisodeNumZeroPadding.Text = Properties.Settings.Default.EpisodeNumZeroPadding;
-
- //Movie Options
- txtMovieDropBox.Text = Properties.Settings.Default.MovieDropBoxLocation;
- ChangeMonitorMovieFolder();
- if(chkMovieFSWatcher.IsEnabled)
- chkMovieFSWatcher.IsChecked = Properties.Settings.Default.MovieFSWatcher;
-
- chkMoviePosters.IsChecked = Properties.Settings.Default.getMoviePosters;
- chkMovieFilePosters.IsChecked = Properties.Settings.Default.getMovieFilePosters;
- chkMoveMovieFiles.IsChecked = Properties.Settings.Default.moveMovieFiles;
-
- chkdownloadAllMovieImages.IsChecked = Properties.Settings.Default.downloadAllMovieImages;
- chkdownloadAllMoviePosters.IsChecked = Properties.Settings.Default.downloadAllMoviePosters;
- chkdownloadAllMovieBackdrops.IsChecked = Properties.Settings.Default.downloadAllMovieBackdrops;
-
- chkSaveMovieActors.IsChecked = Properties.Settings.Default.SaveMovieActors;
-
- chkRenameMovieFiles.IsChecked = Properties.Settings.Default.renameMovieFiles;
- txtMovieFileRenameFormat.Text = Properties.Settings.Default.Moviefileformat;
- txtMovieDirRenameFormat.Text = Properties.Settings.Default.MovieDirformat;
-
- //File Options
- txtAllowedFiletypes.Text = Properties.Settings.Default.allowedFileTypes;
- txtAllowedSubtitles.Text = Properties.Settings.Default.allowedSubtitles;
-
- chkForceUpdate.IsChecked = Properties.Settings.Default.forceUpdate;
- chkOverwrite.IsChecked = Properties.Settings.Default.overwriteFiles;
- chkSilentMode.IsChecked = Properties.Settings.Default.SilentMode;
- chkAutoSelectMovieTitle.IsChecked = Properties.Settings.Default.AutoSelectMovieTitle;
- chkforceEnterSearchTerm.IsChecked = Properties.Settings.Default.forceEnterSearchTerm;
-
- chkFullBackdrop.IsChecked = Properties.Settings.Default.FullBackdropView;
- chkEnableGlassFrame.IsChecked = Properties.Settings.Default.EnableGlassFrame;
-
- chkSaveXBMCMeta.IsChecked = Properties.Settings.Default.SaveXBMCMeta;
- chkSaveMMMeta.IsChecked = Properties.Settings.Default.SaveMyMoviesMeta;
-
- txtImagesByName.Text = Properties.Settings.Default.ImagesByNameLocation;
-
- /* Load Variables */
- AllowedFileTypes = new List<string>(Properties.Settings.Default.allowedFileTypes.Split(';'));
- AllowedSubtitleTypes = new List<string>(Properties.Settings.Default.allowedSubtitles.Split(';'));
-
- zoomslider.Value = Double.Parse(Properties.Settings.Default.Zoom);
- }
- #endregion
-
-
- #region Thread Completeion Handlers
-
- public void AbortAllThreads()
- {
- if (tvThreads.Count > 0)
- {
- foreach (Thread th in tvThreads)
- th.Abort();
- tvThreads.Clear();
- MetadataCompleted(null, "All Operations aborted", true);
- }
- }
- private void ResetUI(Thread th, String reason, bool Reset)
- {
- if (!Dispatcher.CheckAccess())
- {
- Dispatcher.Invoke(DispatcherPriority.Normal, new MetadataCompletedHandler(ResetUI), th, reason, Reset);
- return;
- }
-
- if (th != null)
- {
- th.Abort();
- tvThreads.Remove(th);
- if (th.Name == "Loading TV Shows")
- {
- lbShowTitle.Visibility = Visibility.Visible;
- btnSaveTVShow.Visibility = Visibility.Visible;
- lbShowDesc.Visibility = Visibility.Visible;
- lstTVActors.Visibility = Visibility.Visible;
- SetFocusOnTVShow();
- gridSeriesView.ContextMenu.Visibility = Visibility.Visible;
- }
- if (th.Name == "Loading Movies")
- {
- lbMovieTitle.Visibility = Visibility.Visible;
- btnSaveMovie.Visibility = Visibility.Visible;
- lbMovieDesc.Visibility = Visibility.Visible;
- lstMovieActors.Visibility = Visibility.Visible;
- SetFocusOnMovie();
- gridMovie.ContextMenu.Visibility = Visibility.Visible;
- }
- }
-
- if (Reset && tvThreads.Count == 0)
- {
- HideCancelButtons();
- maxvalue = 0;
- currentvalue = 0;
- TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None;
- }
- if (reason != null)
- Message(((th != null && th.Name != null) ? th.Name + " : " : "") + reason, MediaScout.MediaScoutMessage.MessageType.Task, 0);
- }
- private void ResetTVShow(TVShow ts, bool IsRemoved)
- {
- if (!Dispatcher.CheckAccess())
- {
- Dispatcher.Invoke(DispatcherPriority.Normal, new TVShowChangedHandler(ResetTVShow), ts, IsRemoved);
- return;
- }
- tvTVShows.SelectedIndex = -1;
- int tsindex = tvshows.IndexOf(ts);
- tvshows.RemoveAt(tsindex);
- if (!IsRemoved)
- {
- ts = new TVShow(ts.Folderpath, ts.Name, ts.IsUnsortedEpisodeCollection);
- tvshows.Insert(tsindex, ts);
-
- }
- tvTVShows.SelectedIndex = SelectedTVShowIndex;
- }
- private void ResetSeason(TVShow ts, Season s, bool IsRemoved)
- {
- if (!Dispatcher.CheckAccess())
- {
- Dispatcher.Invoke(DispatcherPriority.Normal, new SeasonChangedHandler(ResetSeason), ts, s, IsRemoved);
- return;
- }
- tvSeasons.SelectedIndex = -1;
- int tsindex = tvshows.IndexOf(ts);
- int sindex = tvshows[tsindex].Seasons.IndexOf(s);
- tvshows[tsindex].Seasons.RemoveAt(sindex);
- if (!IsRemoved)
- {
- s = new Season(s.Folderpath, s.Name, ts);
- tvshows[tsindex].Seasons.Insert(sindex, s);
- }
- tvSeasons.SelectedIndex = SelectedSeasonIndex;
- }
- private void ResetEpisode(TVShow ts, Season s, Episode e, bool IsRemoved)
- {
- if (!Dispatcher.CheckAccess())
- {
- Dispatcher.Invoke(DispatcherPriority.Normal, new EpisodeChangedHandler(ResetEpisode), ts, s, e, IsRemoved);
- return;
- }
-
- tvEpisodes.SelectedIndex = -1;
- int tsindex = tvshows.IndexOf(ts);
- int sindex = tvshows[tsindex].Seasons.IndexOf(s);
- int eindex = tvshows[tsindex].Seasons[sindex].Episodes.IndexOf(e);
- tvshows[tsindex].Seasons[sindex].Episodes.RemoveAt(eindex);
- if (!IsRemoved)
- {
- e = new Episode(e.Filepath, e.Name, s);
- tvshows[tsindex].Seasons[sindex].Episodes.Insert(eindex, e);
- }
- tvEpisodes.SelectedIndex = SelectedEpisodeIndex;
- }
- private void ResetMovie(Movie m, bool IsRemoved)
- {
- if (!Dispatcher.CheckAccess())
- {
- Dispatcher.Invoke(DispatcherPriority.Normal, new MovieChangedHandler(ResetMovie), m, IsRemoved);
- return;
- }
-
- lbMovies.SelectedIndex = -1;
- int mindex = movies.IndexOf(m);
- movies.RemoveAt(mindex);
- if (!IsRemoved)
- {
- m = new Movie(m.Folderpath, m.Name, m.IsUnsortedFileCollection);
- movies.Insert(mindex, m);
- }
- lbMovies.SelectedIndex = SelectedMovieIndex;
- }
- private void ResetMovieFile(Movie m, MovieFile mf, bool IsRemoved)
- {
- if (!Dispatcher.CheckAccess())
- {
- Dispatcher.Invoke(DispatcherPriority.Normal, new MovieFileChangedHandler(ResetMovieFile), m, mf, IsRemoved);
- return;
- }
-
- lbMovieFiles.SelectedIndex = -1;
- int mindex = movies.IndexOf(m);
- int mfindex = movies[mindex].Files.IndexOf(mf);
- movies[mindex].Files.RemoveAt(mfindex);
- if (!IsRemoved)
- {
- mf = new MovieFile(mf.Filepath, mf.Name, m);
- movies[mindex].Files.Insert(mfindex, mf);
- }
- lbMovieFiles.SelectedIndex = SelectedMovieFileIndex;
- }
- private void ResetActorThumb(Person p)
- {
- if (!Dispatcher.CheckAccess())
- {
- Dispatcher.Invoke(DispatcherPriority.Normal, new ActorThumbChangedHandler(ResetActorThumb), p);
- return;
- }
-
- p.Thumb = p.GetImage(p.XBMCFolderPath);
-
- }
-
- #endregion
-
-
- #region Reload TV and Movie Button Click Routines
-
- private void btnReloadSelectedTV_Click(object sender, RoutedEventArgs e)
- {
- TVShow ts = SelectedTVShow;
- TVShowChanged(ts, false);
- }
-
- private void btnReloadSelectedMovie_Click(object sender, RoutedEventArgs e)
- {
- Movie m = SelectedMovie;
- MovieChanged(m, false);
- }
-
- private void btnReloadAllTV_Click(object sender, RoutedEventArgs e)
- {
- loadTVShows();
- }
-
- private void btnReloadAllMovie_Click(object sender, RoutedEventArgs e)
- {
- loadMovies();
- }
-
- #endregion
-
-
- #region Cancel Button Routines
-
- #region Set/Show/Hide Cancel Button Routines
-
- private void SetCancelButtons()
- {
- ////Set the NotifyIcon Cancel Button
- //mnuCancel = new System.Windows.Forms.ToolStripMenuItem();
- //mnuCancel.Text = "Cancel";
- //mnuCancel.Click += new EventHandler(mnuCancel_Click);
- //mnuCancel.Visible = false;
- //notifyIcon.ContextMenuStrip.Items.Add(mnuCancel);
-
- //Set the Jumplist Cancel item
- jumpCancel = new JumpTask();
- jumpCancel.ApplicationPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
- jumpCancel.Arguments = "/Cancel:";
- jumpCancel.IconResourcePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
- jumpCancel.IconResourceIndex = 4;
- jumpCancel.Title = "Cancel";
- jumpCancel.Description = "Cancels Last Operation";
-
- jumpCancelAll = new JumpTask();
- jumpCancelAll.ApplicationPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
- jumpCancelAll.Arguments = "/CancelAll:";
- jumpCancelAll.IconResourcePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
- jumpCancelAll.IconResourceIndex = 4;
- jumpCancelAll.Title = "Cancel All";
- jumpCancelAll.Description = "Cancels All Operation";
-
- jumpOperationsSeparator = new JumpTask();
- }
- private void ShowCancelButtons()
- {
- btnCancelAll.Visibility = Visibility.Visible;
- btnCancel.Visibility = Visibility.Visible;
- //mnuCancel.Visible = true;
-
- TaskbarItemInfo.Overlay = (BitmapSource)this.FindResource("imgoverlay");
- if (!jumplist.JumpItems.Contains(jumpOperationsSeparator))
- {
- List<JumpItem> jumplistitems = new List<JumpItem>();
- jumplistitems.Add(jumpCancel);
- jumplistitems.Add(jumpCancelAll);
- jumplistitems.Add(jumpOperationsSeparator);
-
- jumplist.JumpItems.InsertRange(0, jumplistitems);
- jumplist.Apply();
-
- }
- }
- private void HideCancelButtons()
- {
- btnCancelAll.Visibility = Visibility.Collapsed;
- btnCancel.Visibility = Visibility.Collapsed;
-
- //mnuCancel.Visible = false;
-
- TaskbarItemInfo.Overlay = null;
-
- if (jumplist.JumpItems.Contains(jumpOperationsSeparator))
- {
- jumplist.JumpItems.Remove(jumpOperationsSeparator);
- jumplist.JumpItems.Remove(jumpCancel);
- jumplist.JumpItems.Remove(jumpCancelAll);
- jumplist.Apply();
- }
- }
-
- #endregion
-
- private void btnCancelAll_Click(object sender, RoutedEventArgs e)
- {
- AbortAllThreads();
- }
- private void _tbCancelAllButton_Click(object sender, EventArgs e)
- {
- AbortAllThreads();
- }
-
- public void CancelOperation(Thread th)
- {
- if (th == null)
- th = tvThreads[tvThreads.Count - 1];
- MetadataCompleted(th, "Operation Aborted", true);
- }
- private void btnCancel_Click(object sender, RoutedEventArgs e)
- {
- CancelOperation(null);
- }
- private void _tbCancelButton_Click(object sender, EventArgs e)
- {
- CancelOperation(null);
- }
-
- private void _tbPauseButton_Click(object sender, EventArgs e)
- {
- if (_tbPauseButton.Description == "Pause")
- {
- _tbPauseButton.Description = "Play";
- _tbPauseButton.ImageSource = (BitmapImage)Resources["PlayImage"];
- tvThreads[tvThreads.Count - 1].Suspend();
- }
- else
- {
- _tbPauseButton.Description = "Pause";
- _tbPauseButton.ImageSource = (BitmapImage)Resources["PauseImage"];
- tvThreads[tvThreads.Count - 1].Resume();
- }
- }
-
- #endregion
-
-
- #region Focus Set Routines
-
- private void SetFocusOnTVShow()
- {
- //if (!Dispatcher.CheckAccess())
- //{
- // Dispatcher.Invoke(DispatcherPriority.Normal, new FocusChangedHandler(SetFocusOnTVShow));
- // return;
- //}
-
- if (tvTVShows.SelectedIndex == -1)
- tvTVShows.SelectedIndex = 0;
-
- if (tvTVShows.Items.Count > 0)
- {
- if (tvTVShows.ItemContainerGenerator.Status == System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated)
- {
- ListBoxItem lbi = tvTVShows.ItemContainerGenerator.ContainerFromIndex(SelectedTVShowIndex) as ListBoxItem;
- if (lbi != null)
- {
- lbi.IsSelected = true;
- lbi.Focus();
- }
- }
- }
- }
- private void SetFocusOnSeason()
- {
- //if (!Dispatcher.CheckAccess())
- //{
- // Dispatcher.Invoke(DispatcherPriority.Normal, new FocusChangedHandler(SetFocusOnSeason));
- // return;
- //}
-
- if (tvSeasons.SelectedIndex == -1)
- tvSeasons.SelectedIndex = 0;
-
- if (tvSeasons.Items.Count > 0)
- {
- if (tvSeasons.ItemContainerGenerator.Status == System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated)
- {
- ListBoxItem lbi = tvSeasons.ItemContainerGenerator.ContainerFromIndex(SelectedSeasonIndex) as ListBoxItem;
- if (lbi != null)
- {
- lbi.IsSelected = true;
- lbi.Focus();
- }
- }
- }
- }
- private void SetFocusOnEpisode()
- {
- //if (!Dispatcher.CheckAccess())
- //{
- // Dispatcher.Invoke(DispatcherPriority.Normal, new FocusChangedHandler(SetFocusOnEpisode));
- // return;
- //}
-
- if (tvEpisodes.SelectedIndex == -1)
- tvEpisodes.SelectedIndex = 0;
-
- if (tvEpisodes.Items.Count > 0)
- {
- if (tvEpisodes.ItemContainerGenerator.Status == System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated)
- {
- ListBoxItem lbi = tvEpisodes.ItemContainerGenerator.ContainerFromIndex(SelectedEpisodeIndex) as ListBoxItem;
- if (lbi != null)
- {
- lbi.IsSelected = true;
- lbi.Focus();
- }
- }
- }
- }
- private void SetFocusOnMovie()
- {
- //if (!Dispatcher.CheckAccess())
- //{
- // Dispatcher.Invoke(DispatcherPriority.Normal, new FocusChangedHandler(SetFocusOnMovie));
- // return;
- //}
-
- if (lbMovies.SelectedIndex == -1)
- lbMovies.SelectedIndex = 0;
-
- if (lbMovies.Items.Count > 0)
- {
- if (lbMovies.ItemContainerGenerator.Status == System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated)
- {
- ListBoxItem lbi = lbMovies.ItemContainerGenerator.ContainerFromIndex(SelectedMovieIndex) as ListBoxItem;
- if (lbi != null)
- {
- lbi.IsSelected = true;
- lbi.Focus();
- }
- }
- }
-
- }
- private void SetFocusOnMovieFile()
- {
- //if (!Dispatcher.CheckAccess())
- //{
- // Dispatcher.Invoke(DispatcherPriority.Normal, new FocusChangedHandler(SetFocusOnMovieFile));
- // return;
- //}
-
- if (lbMovieFiles.SelectedIndex == -1)
- lbMovieFiles.SelectedIndex = 0;
-
- if (lbMovieFiles.Items.Count > 0)
- {
- if (lbMovieFiles.ItemContainerGenerator.Status == System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated)
- {
- ListBoxItem lbi = lbMovieFiles.ItemContainerGenerator.ContainerFromIndex(SelectedMovieFileIndex) as ListBoxItem;
- if (lbi != null)
- {
- lbi.IsSelected = true;
- lbi.Focus();
- }
- }
- }
- }
-
- private void SetTVTabFocus()
- {
- if (gridSeriesView.Visibility == Visibility.Visible)
- SetFocusOnTVShow();
- else if (gridSeasonsView.Visibility == Visibility.Visible)
- SetFocusOnSeason();
- else if (gridEpisodesView.Visibility == Visibility.Visible)
- SetFocusOnEpisode();
- }
- private void SetMovieTabFocus()
- {
- if (gridMovie.Visibility == Visibility.Visible)
- SetFocusOnMovie();
- else if (gridMovieFile.Visibility == Visibility.Visible)
- SetFocusOnMovieFile();
- }
-
- #endregion
-
-
- #region Tab Selection and Keyboard Routines
-
- private void tabTVSeries_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.Key == Key.Enter)
- {
- if (gridSeriesView.Visibility == Visibility.Visible)
- {
- if (SelectedTVShow != null)
- ShowSeasons();
- }
- else if (gridSeasonsView.Visibility == Visibility.Visible)
- {
- if (SelectedSeason != null)
- ShowEpisodeList();
- }
- }
- if (e.Key == Key.Delete)
- {
- if (gridSeriesView.Visibility == Visibility.Visible)
- {
- if (tvTVShows.SelectedItem != null)
- btnStripSelectedTV_Click(null, null);
- }
- else if (gridSeasonsView.Visibility == Visibility.Visible)
- {
- if (tvSeasons.SelectedItem != null)
- btnStripSelectedSeason_Click(null, null);
- }
- }
- if (e.Key == Key.Back)
- {
- if (gridSeasonsView.Visibility == Visibility.Visible)
- ShowTVShowList();
- else if (gridEpisodesView.Visibility == Visibility.Visible)
- ShowSeasons();
- }
- }
- private void tabMovies_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.Key == Key.Enter)
- {
- if (gridMovie.Visibility == Visibility.Visible)
- {
- if (SelectedMovie != null)
- ShowMovieFileList();
- }
- }
- if (e.Key == Key.Delete)
- {
- if (gridMovie.Visibility == Visibility.Visible)
- {
- if (SelectedMovie != null)
- btnStripSelectedMovie_Click(null, null);
- }
- else if (gridMovieFile.Visibility == Visibility.Visible)
- {
- if (SelectedMovie != null)
- btnStripSelectedMovieFile_Click(null, null);
- }
- }
- if (e.Key == Key.Back)
- {
- if (gridMovieFile.Visibility == Visibility.Visible)
- ShowMovieList();
- }
- }
-
- private void tcTabs_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (WindowLoaded)
- {
- //Find out what tab is selected. If the program is just loading up, then the
- // tab control might not be generated or have a selected tab yet, so we have
- // to take into account a "null" scenario.
- TabItem CurrentTab = tcTabs.SelectedItem as TabItem;
- String CurrentTabName = "";
- if (CurrentTab != null)
- CurrentTabName = CurrentTab.Name;
-
- //switch (tcTabs.SelectedIndex)
- switch (CurrentTabName)
- {
- case "tabTVSeries":
- //Make sure the TVFolder is set before attempting to load in all the TV show data.
- System.Collections.Specialized.StringCollection TVFolders = Properties.Settings.Default.TVFolders;
-
- if (TVFolders == null || TVFolders.Count == 0)
- {
- if (tvshows.Count > 0)
- {
- tvshows.Clear();
- lbShowTitle.Visibility = Visibility.Collapsed;
- btnSaveTVShow.Visibility = Visibility.Collapsed;
- lbShowDesc.Visibility = Visibility.Collapsed;
- lstTVActors.Visibility = Visibility.Collapsed;
- gridSeriesView.ContextMenu.Visibility = Visibility.Collapsed;
- UpdateTVPoster(null, TVShowPosterType.Poster, false);
- UpdateTVPoster(null, TVShowPosterType.Backdrop, false);
- }
- break;
- }
-
- if (tvshows == null || tvshows.Count == 0 || resetTVfolder)
- {
- resetTVfolder = false;
- loadTVShows();
- gridTVSeries.DataContext = dispatchtvshows;
- }
-
- break;
-
- case "tabMovies":
-
- //Make sure the MovieFolder is set before attempting to load in all the movies data.
- System.Collections.Specialized.StringCollection MovieFolders = Properties.Settings.Default.MovieFolders;
-
- if (MovieFolders == null || MovieFolders.Count == 0)
- {
- if (movies.Count > 0)
- {
- movies.Clear();
- lbMovieTitle.Visibility = Visibility.Collapsed;
- btnSaveMovie.Visibility = Visibility.Collapsed;
- lbMovieDesc.Visibility = Visibility.Collapsed;
- lstMovieActors.Visibility = Visibility.Collapsed;
- gridMovie.ContextMenu.Visibility = Visibility.Collapsed;
- UpdateMoviePoster(null, MoviePosterType.Poster, false);
- UpdateMoviePoster(null, MoviePosterType.Backdrop, false);
- }
- break;
- }
-
- if (movies == null || movies.Count == 0 || resetMoviefolder)
- {
- resetMoviefolder = false;
- loadMovies();
- gridMovies.DataContext = dispatchmovies;
- }
-
- break;
-
- default:
- break;
- }
- }
- }
-
- #endregion
-
-
- #region Taskbar Progress Status Routines
-
- private void SetTasbkBarProgressStatus(TaskbarItemProgressState state)
- {
- if (!Dispatcher.CheckAccess())
- {
- Dispatcher.Invoke(DispatcherPriority.Normal, new TaskbarProgressStatusChangeHandler(SetTasbkBarProgressStatus), state);
- return;
- }
-
- TaskbarItemInfo.ProgressState = state;
- }
- private void SetTasbkBarProgressValue(int value)
- {
- if (!Dispatcher.CheckAccess())
- {
- Dispatcher.Invoke(DispatcherPriority.Send, new TaskbarProgressValueChangeHandler(SetTasbkBarProgressValue), value);
- return;
- }
- if (value != maxvalue)
- {
- if (TaskbarItemInfo.ProgressState != TaskbarItemProgressState.Normal)
- TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Normal;
- TaskbarItemInfo.ProgressValue = ((double)value/maxvalue);
- }
- else
- TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None;
- }
-
- #endregion
-
-
- #region Loading TV and Movie Routines
-
- private void loadTVShows()
- {
- tvTVShows.SelectedIndex = -1;
- tvshows.Clear();
- //Load it on a seperate thread (hence the use of the DispatchingCollection) so as not to lag UI
- ShowCancelButtons();
- Thread th = null;
- th = new Thread(delegate()
- {
- foreach (String dir in Properties.Settings.Default.TVFolders)
- {
- DirectoryInfo TVShows = new DirectoryInfo(dir);
- maxvalue += TVShows.GetDirectories().Length;
- try
- {
- foreach (DirectoryInfo di in TVShows.GetDirectories())
- {
- TVShow t = new TVShow(di.FullName, di.Name, false);
- tvshows.Add(t);
- SetTasbkBarProgressValue(++currentvalue);
- }
- bool containsUnsortedFiles = false;
- foreach (FileInfo fi in TVShows.GetFiles())
- {
- if (AllowedFileTypes.Contains(fi.Extension))
- containsUnsortedFiles = true;
- }
- if (containsUnsortedFiles)
- {
- TVShow t = new TVShow(TVShows.FullName, "Unsorted Episodes", true);
- UnsortedEpisodes = t;
- tvshows.Add(t);
- }
- }
- catch (Exception ex)
- {
- if (th.ThreadState != System.Threading.ThreadState.AbortRequested)
- {
- SetTasbkBarProgressStatus(TaskbarItemProgressState.Error);
- MessageBox.Show(ex.Message);
- }
- }
- }
- MetadataCompleted(th, tvshows.Count.ToString(), true);
- });
-
- th.Name = "Loading TV Shows";
- th.SetApartmentState(ApartmentState.STA);
- th.Start();
- tvThreads.Add(th);
- }
-
- private void loadMovies()
- {
- lbMovies.SelectedIndex = -1;
- movies.Clear();
- ShowCancelButtons();
- Thread th = null;
- th = new Thread(delegate()
- {
- foreach (String dir in Properties.Settings.Default.MovieFolders)
- {
- DirectoryInfo Movies = new DirectoryInfo(dir);
- maxvalue += Movies.GetDirectories().Length;
- try
- {
- foreach (DirectoryInfo di in Movies.GetDirectories())
- {
- Movie m = new Movie(di.FullName, di.Name, false);
- movies.Add(m);
- SetTasbkBarProgressValue(++currentvalue);
- }
- bool containsUnsortedFiles = false;
- foreach (FileInfo fi in Movies.GetFiles())
- {
- if (AllowedFileTypes.Contains(fi.Extension))
- containsUnsortedFiles = true;
- }
- if (containsUnsortedFiles)
- {
- Movie m = new Movie(Movies.FullName, "Unsorted Files", true);
- UnsortedFiles = m;
- movies.Add(m);
- }
- }
- catch (Exception ex)
- {
- if (th.ThreadState != System.Threading.ThreadState.AbortRequested)
- {
- SetTasbkBarProgressStatus(TaskbarItemProgressState.Error);
- MessageBox.Show(ex.Message);
- }
- }
- }
- MetadataCompleted(th, movies.Count.ToString(), true);
- });
-
- th.Name = "Loading Movies";
- th.SetApartmentState(ApartmentState.STA);
- th.Start();
-
- tvThreads.Add(th);
- }
-
- #endregion
-
-
- #region Open In Explorer Routines
-
- private void btnOpenTVShow_Click(object sender, RoutedEventArgs e)
- {
- System.Diagnostics.Process.Start("explorer.exe", "/select," + SelectedTVShow.Folderpath);
- }
-
- private void btnOpenSeason_Click(object sender, RoutedEventArgs e)
- {
- System.Diagnostics.Process.Start("explorer.exe", "/select," + SelectedSeason.Folderpath);
- }
- private void btnOpenSeasonMetadata_Click(object sender, RoutedEventArgs e)
- {
- String dir = SelectedSeason.MetadataFolderPath;
- if(Directory.Exists(dir))
- System.Diagnostics.Process.Start("explorer.exe", dir);
- else
- MessageBox.Show("Directory doesn't Exist");
- }
-
- private void btnOpenEpisode_Click(object sender, RoutedEventArgs e)
- {
- String file = SelectedEpisode.Filepath;
- if (File.Exists(file))
- System.Diagnostics.Process.Start("explorer.exe", "/select," + file);
- else
- MessageBox.Show("File doesn't Exist");
- }
- private void btnOpenEpisodeXMLMetadata_Click(object sender, RoutedEventArgs e)
- {
- String file = SelectedEpisode.XMLFile;
- if(File.Exists(file))
- System.Diagnostics.Process.Start("explorer.exe", "/select," + file);
- else
- MessageBox.Show("File doesn't Exist");
- }
-
- private void btnOpenMovie_Click(object sender, RoutedEventArgs e)
- {
- System.Diagnostics.Process.Start("explorer.exe", "/select," + SelectedMovie.Folderpath);
- }
- private void btnOpenMovieFile_Click(object sender, RoutedEventArgs e)
- {
- String file = SelectedMovieFile.Filepath;
- if (File.Exists(file))
- System.Diagnostics.Process.Start("explorer.exe", "/select," + file);
- else
- MessageBox.Show("File doesn't Exist");
- }
-
- private void btnOpenActorThumb_Click(object sender, RoutedEventArgs e)
- {
- String file;
- if (Properties.Settings.Default.SaveXBMCMeta)
- {
- file = SelectedPerson.XBMCFolderPath + "\\" + SelectedPerson.Name.Replace(" ", "_") + ".jpg";
- if (File.Exists(file))
- System.Diagnostics.Process.Start("explorer.exe", "/select," + file);
- else
- MessageBox.Show("File doesn't Exist");
- }
- if (Properties.Settings.Default.SaveMyMoviesMeta)
- {
- file = SelectedPerson.MyMoviesFolderPath + "\\" + SelectedPerson.Name.Replace(" ", "_") + @"\folder.jpg";
- if (File.Exists(file))
- System.Diagnostics.Process.Start("explorer.exe", "/select," + file);
- else
- MessageBox.Show("File doesn't Exist");
- }
-
- }
-
- #endregion
-
-
- #region TV Series, Season, Episode And Movie Listbox Routines
-
- #region TV Shows ListBox Routines
-
- private void tvTVShows_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (tvTVShows.SelectedIndex != -1)
- {
- SelectedTVShow = (TVShow)tvTVShows.SelectedItem;
- SelectedTVShowIndex = tvTVShows.SelectedIndex;
- SelectedTVShow.Load();
- UpdateTVPoster(SelectedTVShow, TVShowPosterType.Poster, false);
- UpdateTVPoster(SelectedTVShow, TVShowPosterType.Backdrop, false);
- UpdateTVPoster(SelectedTVShow, TVShowPosterType.Banner, false);
- }
- }
- private void ShowTVShowList()
- {
- gridEpisodesView.Visibility = Visibility.Hidden;
- gridSeasonsView.Visibility = Visibility.Hidden;
- gridSeriesView.Visibility = Visibility.Visible;
- SetFocusOnTVShow();
- }
- private void TVShowItem_DoubleClick(object sender, MouseButtonEventArgs e)
- {
- if (e.ClickCount == 2)
- ShowSeasons();
- }
- private void ShowSeasons()
- {
- TVShow ts = SelectedTVShow;
- if (ts.IsUnsortedEpisodeCollection)
- {
- if (gridEpisodesView.Visibility == Visibility.Visible)
- ShowTVShowList();
- else
- {
- SelectedSeason = ts.UnsortedEpisodes[0].Season;
- ShowEpisodeList();
- }
- }
- else
- ShowSeasonList();
- }
- private void ShowSeasonList()
- {
- gridSeriesView.Visibility = Visibility.Hidden;
- gridEpisodesView.Visibility = Visibility.Hidden;
- gridSeasonsView.Visibility = Visibility.Visible;
- gridSeasonsView.DataContext = Select…
Large files files are truncated, but you can click here to view the full file