PageRenderTime 44ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 1ms

/Branches/seufert/MediaScout/MainWindow.xaml.cs

#
C# | 6494 lines | 5691 code | 519 blank | 284 comment | 778 complexity | 22e5bce88000d27abf43f367c27f5dca MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. using System.Windows.Data;
  7. using System.Windows.Documents;
  8. using System.Windows.Input;
  9. using System.Windows.Media;
  10. using System.Windows.Media.Imaging;
  11. using System.Windows.Shapes;
  12. using System.Windows.Interop;
  13. using System.IO;
  14. using System.Collections;
  15. using System.Collections.ObjectModel;
  16. using System.Data;
  17. using System.Threading;
  18. using System.Windows.Threading;
  19. using System.Text.RegularExpressions;
  20. using System.Xml;
  21. using System.Xml.Serialization;
  22. using System.Diagnostics;
  23. using System.Windows.Shell;
  24. using MediaScoutGUI.GUITypes;
  25. using MediaScout.Providers;
  26. namespace MediaScoutGUI
  27. {
  28. /// <summary>
  29. /// Interaction logic for Window1.xaml
  30. /// </summary>
  31. public partial class MainWindow : Window
  32. {
  33. //Delegates
  34. public MediaScout.MediaScoutMessage.Message Message;
  35. public delegate void MetadataCompletedHandler(Thread th, String reason, bool Reset);
  36. public event MetadataCompletedHandler MetadataCompleted;
  37. public delegate void TVShowChangedHandler(TVShow ts, bool IsRemoved);
  38. public event TVShowChangedHandler TVShowChanged;
  39. public delegate void SeasonChangedHandler(Season s, bool IsRemoved);
  40. public event SeasonChangedHandler SeasonChanged;
  41. public delegate void EpisodeChangedHandler(Episode e, bool IsRemoved);
  42. public event EpisodeChangedHandler EpisodeChanged;
  43. public delegate void MovieChangedHandler(Movie m, bool IsRemoved);
  44. public event MovieChangedHandler MovieChanged;
  45. public delegate void MovieFileChangedHandler(MovieFile mf, bool IsRemoved);
  46. public event MovieFileChangedHandler MovieFileChanged;
  47. public delegate void ActorThumbChangedHandler(Person p);
  48. public event ActorThumbChangedHandler ActorThumbChanged;
  49. public delegate void FocusChangedHandler();
  50. public delegate void TaskbarProgressValueChangeHandler(int value);
  51. public delegate void TaskbarProgressStatusChangeHandler(TaskbarItemProgressState state);
  52. public delegate void TVShowImageChangedHandler(TVShow ts, TVShowPosterType type, bool IsLoading);
  53. public delegate void SeasonImageChangedHandler(Season s, TVShowPosterType type, bool IsLoading);
  54. public delegate void EpisodeImageChangedHandler(Episode e, String filename, bool IsLoading);
  55. public delegate void MovieImageChangedHandler(Movie m, MoviePosterType type, bool IsLoading);
  56. public delegate void MovieFileImageChangedHandler(MovieFile mf, MoviePosterType type, bool IsLoading);
  57. public delegate void PosterChangedHandler(Object obj, String id, bool IsMovie, Season s, String file);
  58. public delegate void BackdropChangedHandler(Object obj, String id, bool IsMovie, Season s, String file, String file1);
  59. //Collections
  60. private ObservableCollection<TVShow> tvshows = new ObservableCollection<TVShow>();
  61. private ObservableCollection<Movie> movies = new ObservableCollection<Movie>();
  62. private DispatchingCollection<ObservableCollection<TVShow>, TVShow> dispatchtvshows;
  63. private DispatchingCollection<ObservableCollection<Movie>, Movie> dispatchmovies;
  64. //Settings
  65. private List<String> ignoredFiles = new List<String>();
  66. private List<String> AllowedFileTypes;
  67. private List<String> AllowedSubtitleTypes;
  68. MediaScoutApp app;
  69. private bool WindowLoaded = false;
  70. private bool WindowRendered = false;
  71. //private System.Windows.Forms.NotifyIcon notifyIcon;
  72. //private System.Windows.Forms.ToolStripMenuItem mnuCancel;
  73. private JumpList jumplist;
  74. private JumpTask jumpCancel;
  75. private JumpTask jumpCancelAll;
  76. private JumpTask jumpOperationsSeparator;
  77. //Objects
  78. private MediaScout.TVScout TVScout = null;
  79. private MediaScout.MovieScout MovieScout = null;
  80. private FileSystemWatcher TVFSWatcher = null;
  81. private FileSystemWatcher MovieFSWatcher = null;
  82. private TheTVDBProvider tvdb = null;
  83. private TheMovieDBProvider tmdb = null;
  84. private Collection<Thread> tvThreads = new Collection<Thread>();
  85. private bool resetTVfolder = false;
  86. private bool resetMoviefolder = false;
  87. int currentvalue = 0;
  88. int maxvalue = 0;
  89. private TVShow SelectedTVShow;
  90. private int SelectedTVShowIndex = 0;
  91. private TVShow UnsortedEpisodes;
  92. private Season SelectedSeason;
  93. private int SelectedSeasonIndex = 0;
  94. private Episode SelectedEpisode;
  95. private int SelectedEpisodeIndex = 0;
  96. private Movie SelectedMovie;
  97. private int SelectedMovieIndex = 0;
  98. private Movie UnsortedFiles;
  99. private MovieFile SelectedMovieFile;
  100. private int SelectedMovieFileIndex = 0;
  101. private Person SelectedPerson;
  102. //private int SelectedPersonIndex = 0;
  103. private int LogTabIndex = 1;
  104. private int SelectedTabIndex = 0;
  105. #region To Enable/Disable for the Aero glass effect
  106. public Rect GetBoundsForGlassFrame()
  107. {
  108. return VisualTreeHelper.GetContentBounds(tcTabs);
  109. }
  110. public bool SetGlassFrame(bool ExtendGlass)
  111. {
  112. bool success = false;
  113. if (ExtendGlass)
  114. {
  115. // Extend glass
  116. Rect bounds = GetBoundsForGlassFrame();
  117. success = GlassHelper.ExtendGlassFrame(this, new Thickness(bounds.Left, bounds.Top, bounds.Right, bounds.Bottom));
  118. }
  119. else
  120. {
  121. // turn off glass...
  122. GlassHelper.DisableGlassFrame(this);
  123. success = true;
  124. }
  125. return success;
  126. }
  127. public IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
  128. {
  129. int WM_DWMCOMPOSITIONCHANGED = 0x031E; // for glass (when DWM / glass setting is changed)
  130. // handle the message for DWM when the aero glass is turned on or off
  131. if (msg == WM_DWMCOMPOSITIONCHANGED)
  132. {
  133. SetGlassFrame(GlassHelper.IsGlassEnabled);
  134. handled = true;
  135. }
  136. return IntPtr.Zero;
  137. }
  138. #endregion
  139. #region Window Routines
  140. public MainWindow(int SelectedTabIndex)
  141. {
  142. try
  143. {
  144. this.InitializeComponent();
  145. app = ((MediaScoutApp)Application.Current);
  146. //notifyIcon = app.notifyIcon;
  147. jumplist = app.jumplist;
  148. this.SelectedTabIndex = SelectedTabIndex;
  149. this.Message = new MediaScout.MediaScoutMessage.Message(TVScout_Message);
  150. tvdb = new TheTVDBProvider(Message);
  151. tmdb = new TheMovieDBProvider(Message);
  152. this.MetadataCompleted += new MetadataCompletedHandler(ResetUI);
  153. this.TVShowChanged += new TVShowChangedHandler(ResetTVShow);
  154. this.SeasonChanged += new SeasonChangedHandler(ResetSeason);
  155. this.EpisodeChanged += new EpisodeChangedHandler(ResetEpisode);
  156. this.MovieChanged += new MovieChangedHandler(ResetMovie);
  157. this.MovieFileChanged += new MovieFileChangedHandler(ResetMovieFile);
  158. this.ActorThumbChanged += new ActorThumbChangedHandler(ResetActorThumb);
  159. //creating directories
  160. String CacheDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\MediaScout\Cache";
  161. String TVCacheDir = CacheDir + @"\TVCache";
  162. String MovieCacheDir = CacheDir + @"\MovieCache";
  163. if (!Directory.Exists(CacheDir))
  164. Directory.CreateDirectory(CacheDir);
  165. if (!Directory.Exists(TVCacheDir))
  166. Directory.CreateDirectory(TVCacheDir);
  167. if (!Directory.Exists(MovieCacheDir))
  168. Directory.CreateDirectory(MovieCacheDir);
  169. SetCancelButtons();
  170. dispatchtvshows = new DispatchingCollection<ObservableCollection<TVShow>, TVShow>(tvshows, Dispatcher);
  171. dispatchmovies = new DispatchingCollection<ObservableCollection<Movie>, Movie>(movies, Dispatcher);
  172. }
  173. catch (Exception ex)
  174. {
  175. MessageBox.Show(ex.Message);
  176. }
  177. }
  178. private void Window_Loaded(object sender, RoutedEventArgs e)
  179. {
  180. Rect bounds = GetBoundsForGlassFrame();
  181. HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
  182. source.AddHook(new HwndSourceHook(WndProc));
  183. WindowLoaded = true;
  184. LoadOptions();
  185. tcTabs.SelectedIndex = SelectedTabIndex;
  186. //Dispatcher.Hooks.OperationPosted += new DispatcherHookEventHandler(Hooks_OperationPosted);
  187. }
  188. private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  189. {
  190. //Properties.Settings.Default.Zoom = zoomslider.Value.ToString();
  191. //Properties.Settings.Default.Save();
  192. //When the application is closed, check wether the application is
  193. //exiting from menu or forms close button
  194. //if (!isAppExiting)
  195. //{
  196. // //if the forms close button is triggered, cancel the event and hide the form
  197. // //then show the notification ballon tip
  198. // e.Cancel = true;
  199. //}
  200. }
  201. private void Window_StateChanged(object sender, EventArgs e)
  202. {
  203. // if (this.WindowState == WindowState.Minimized)
  204. // {
  205. // //Hide();
  206. // if (app.showballoontip)
  207. // {
  208. // notifyIcon.BalloonTipIcon = System.Windows.Forms.ToolTipIcon.Info;
  209. // notifyIcon.BalloonTipTitle = "Media Scout";
  210. // notifyIcon.BalloonTipText = "Application minimized to the system tray. To open the application, double-click the icon in the system tray.";
  211. // notifyIcon.ShowBalloonTip(400);
  212. // }
  213. // }
  214. }
  215. private void Window_Closed(object sender, EventArgs e)
  216. {
  217. AbortAllThreads();
  218. app.Shutdown();
  219. }
  220. private void Window_ContentRendered(object sender, EventArgs e)
  221. {
  222. WindowRendered = true;
  223. StartLoadingItems();
  224. }
  225. #endregion
  226. #region Loads all the options from the user configuration file
  227. private void LoadOptions()
  228. {
  229. //TV Options
  230. txtTVDropBox.Text = Properties.Settings.Default.TVDropBoxLocation;
  231. ChangeMonitorTVFolder();
  232. if(chkTVFSWatcher.IsEnabled)
  233. chkTVFSWatcher.IsChecked = Properties.Settings.Default.TVFSWatcher;
  234. chkSeriesPosters.IsChecked = Properties.Settings.Default.getSeriesPosters;
  235. chkSeasonPosters.IsChecked = Properties.Settings.Default.getSeasonPosters;
  236. chkEpPosters.IsChecked = Properties.Settings.Default.getEpisodePosters;
  237. chkMoveTVFiles.IsChecked = Properties.Settings.Default.moveTVFiles;
  238. chkSaveTVActors.IsChecked = Properties.Settings.Default.SaveTVActors;
  239. txtSeasonFolderName.Text = Properties.Settings.Default.SeasonFolderName;
  240. txtSpecialsFolderName.Text = Properties.Settings.Default.SpecialsFolderName;
  241. chkdownloadAllTVImages.IsChecked = Properties.Settings.Default.downloadAllTVImages;
  242. chkdownloadAllTVPosters.IsChecked = Properties.Settings.Default.downloadAllTVPosters;
  243. chkdownloadAllTVBackdrops.IsChecked = Properties.Settings.Default.downloadAllTVBackdrops;
  244. chkdownloadAllTVBanners.IsChecked = Properties.Settings.Default.downloadAllTVBanners;
  245. chkdownloadAllTVSeasonPosters.IsChecked = Properties.Settings.Default.downloadAllTVSeasonPosters;
  246. chkdownloadAllTVSeasonBackdrops.IsChecked = Properties.Settings.Default.downloadAllTVSeasonBackdrops;
  247. chkRenameTVFiles.IsChecked = Properties.Settings.Default.renameTVFiles;
  248. txtTVRenameFormat.Text = Properties.Settings.Default.TVfileformat;
  249. txtSeasonNumZeroPadding.Text = Properties.Settings.Default.SeasonNumZeroPadding;
  250. txtEpisodeNumZeroPadding.Text = Properties.Settings.Default.EpisodeNumZeroPadding;
  251. //Movie Options
  252. txtMovieDropBox.Text = Properties.Settings.Default.MovieDropBoxLocation;
  253. ChangeMonitorMovieFolder();
  254. if(chkMovieFSWatcher.IsEnabled)
  255. chkMovieFSWatcher.IsChecked = Properties.Settings.Default.MovieFSWatcher;
  256. chkMoviePosters.IsChecked = Properties.Settings.Default.getMoviePosters;
  257. chkMovieFilePosters.IsChecked = Properties.Settings.Default.getMovieFilePosters;
  258. chkMoveMovieFiles.IsChecked = Properties.Settings.Default.moveMovieFiles;
  259. chkdownloadAllMovieImages.IsChecked = Properties.Settings.Default.downloadAllMovieImages;
  260. chkdownloadAllMoviePosters.IsChecked = Properties.Settings.Default.downloadAllMoviePosters;
  261. chkdownloadAllMovieBackdrops.IsChecked = Properties.Settings.Default.downloadAllMovieBackdrops;
  262. chkSaveMovieActors.IsChecked = Properties.Settings.Default.SaveMovieActors;
  263. chkRenameMovieFiles.IsChecked = Properties.Settings.Default.renameMovieFiles;
  264. txtMovieFileRenameFormat.Text = Properties.Settings.Default.Moviefileformat;
  265. txtMovieDirRenameFormat.Text = Properties.Settings.Default.MovieDirformat;
  266. //File Options
  267. txtAllowedFiletypes.Text = Properties.Settings.Default.allowedFileTypes;
  268. txtAllowedSubtitles.Text = Properties.Settings.Default.allowedSubtitles;
  269. txtSearchTermFilters.Text = Properties.Settings.Default.SearchTermFilters;
  270. chkForceUpdate.IsChecked = Properties.Settings.Default.forceUpdate;
  271. chkOverwrite.IsChecked = Properties.Settings.Default.overwriteFiles;
  272. chkSilentMode.IsChecked = Properties.Settings.Default.SilentMode;
  273. chkAutoSelectMovieTitle.IsChecked = Properties.Settings.Default.AutoSelectMovieTitle;
  274. chkforceEnterSearchTerm.IsChecked = Properties.Settings.Default.forceEnterSearchTerm;
  275. chkEnableGlassFrame.IsChecked = Properties.Settings.Default.EnableGlassFrame;
  276. chkSaveXBMCMeta.IsChecked = Properties.Settings.Default.SaveXBMCMeta;
  277. chkSaveMMMeta.IsChecked = Properties.Settings.Default.SaveMyMoviesMeta;
  278. txtImagesByName.Text = Properties.Settings.Default.ImagesByNameLocation;
  279. /* Load Variables */
  280. AllowedFileTypes = new List<string>(Properties.Settings.Default.allowedFileTypes.Split(';'));
  281. AllowedSubtitleTypes = new List<string>(Properties.Settings.Default.allowedSubtitles.Split(';'));
  282. //zoomslider.Value = Double.Parse(Properties.Settings.Default.Zoom);
  283. }
  284. #endregion
  285. #region Thread Completeion Handlers
  286. private void SetTVShowTabItemsVisibility(Visibility v)
  287. {
  288. //lbShowTitle.Visibility = v;
  289. //btnSaveTVShow.Visibility = v;
  290. //lbShowDesc.Visibility = v;
  291. //tcTVShowCategories.Visibility = v;
  292. //tcTVShowPersons.Visibility = v;
  293. //lbTVShowFirstAired.Visibility = v;
  294. //dtTVShowFirstAired.Visibility = v;
  295. //lbShowRating.Visibility = v;
  296. //ratingTVShow.Visibility = v;
  297. //tvTVShows.ContextMenu.Visibility = v;
  298. gridSeriesView.Visibility = v;
  299. gridSeasonsView.Visibility = v;
  300. gridEpisodesView.Visibility = v;
  301. gridSeriesView.ContextMenu.Visibility = v;
  302. }
  303. private void SetMovieTabItemsVisibility(Visibility v)
  304. {
  305. //lbMovieTitle.Visibility = v;
  306. //btnSaveMovie.Visibility = v;
  307. //lbMovieDesc.Visibility = v;
  308. //tcMovieCategories.Visibility = v;
  309. //tcMoviePersons.Visibility = v;
  310. //lbMovieYear.Visibility = v;
  311. //lbMovieRating.Visibility = v;
  312. //ratingMovie.Visibility = v;
  313. //lbMovies.ContextMenu.Visibility = v;
  314. gridMovie.Visibility = v;
  315. gridMovieFile.Visibility = v;
  316. gridMovie.ContextMenu.Visibility = v;
  317. }
  318. public void AbortAllThreads()
  319. {
  320. if (tvThreads.Count > 0)
  321. {
  322. foreach (Thread th in tvThreads)
  323. th.Abort();
  324. tvThreads.Clear();
  325. MetadataCompleted(null, "All Operations aborted", true);
  326. }
  327. }
  328. private void ResetUI(Thread th, String reason, bool Reset)
  329. {
  330. if (!Dispatcher.CheckAccess())
  331. {
  332. Dispatcher.Invoke(DispatcherPriority.Normal, new MetadataCompletedHandler(ResetUI), th, reason, Reset);
  333. return;
  334. }
  335. if (th != null)
  336. {
  337. th.Abort();
  338. tvThreads.Remove(th);
  339. if (th.Name == "Loading TV Shows")
  340. {
  341. LoadingTVShows = false;
  342. if (tvshows.Count > 0)
  343. {
  344. gridSeriesView.ContextMenu.Visibility = Visibility.Visible;
  345. //SetFocusOnTVShow();
  346. txtSearchTVShow.Focus();
  347. //tvTVShows.SelectedIndex = 0;
  348. }
  349. }
  350. if (th.Name == "Loading Movies")
  351. {
  352. LoadingMovies = false;
  353. if (movies.Count > 0)
  354. {
  355. gridMovie.ContextMenu.Visibility = Visibility.Visible;
  356. //SetFocusOnMovie();
  357. txtSearchMovie.Focus();
  358. //lbMovies.SelectedIndex = 0;
  359. }
  360. }
  361. }
  362. if (Reset && tvThreads.Count == 0)
  363. {
  364. HideCancelButtons();
  365. maxvalue = 0;
  366. currentvalue = 0;
  367. TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None;
  368. }
  369. if (reason != null)
  370. Message(((th != null && th.Name != null) ? th.Name + " : " : "") + reason, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  371. }
  372. private void ResetTVShow(TVShow ts, bool IsRemoved)
  373. {
  374. if (!Dispatcher.CheckAccess())
  375. {
  376. Dispatcher.Invoke(DispatcherPriority.Normal, new TVShowChangedHandler(ResetTVShow), ts, IsRemoved);
  377. return;
  378. }
  379. tvTVShows.SelectedIndex = -1;
  380. int tsindex = tvshows.IndexOf(ts);
  381. tvshows.RemoveAt(tsindex);
  382. if (!IsRemoved)
  383. {
  384. ts = new TVShow(ts.Folderpath, ts.Foldername, ts.IsUnsortedEpisodeCollection);
  385. tvshows.Insert(tsindex, ts);
  386. }
  387. tvTVShows.SelectedIndex = SelectedTVShowIndex;
  388. }
  389. private void ResetSeason(Season s, bool IsRemoved)
  390. {
  391. if (!Dispatcher.CheckAccess())
  392. {
  393. Dispatcher.Invoke(DispatcherPriority.Normal, new SeasonChangedHandler(ResetSeason), s, IsRemoved);
  394. return;
  395. }
  396. TVShow ts = s.TVShow;
  397. tvSeasons.SelectedIndex = -1;
  398. int tsindex = tvshows.IndexOf(ts);
  399. int sindex = tvshows[tsindex].Seasons.IndexOf(s);
  400. tvshows[tsindex].Seasons.RemoveAt(sindex);
  401. if (!IsRemoved)
  402. {
  403. s = new Season(s.Folderpath, s.Name, ts);
  404. tvshows[tsindex].Seasons.Insert(sindex, s);
  405. }
  406. tvSeasons.SelectedIndex = SelectedSeasonIndex;
  407. }
  408. private void ResetEpisode(Episode e, bool IsRemoved)
  409. {
  410. if (!Dispatcher.CheckAccess())
  411. {
  412. Dispatcher.Invoke(DispatcherPriority.Normal, new EpisodeChangedHandler(ResetEpisode), e, IsRemoved);
  413. return;
  414. }
  415. Season s = e.Season;
  416. //TVShow ts = s.TVShow;
  417. tvEpisodes.SelectedIndex = -1;
  418. //int tsindex = tvshows.IndexOf(ts);
  419. //int sindex = tvshows[tsindex].Seasons.IndexOf(s);
  420. //int eindex = tvshows[tsindex].Seasons[sindex].Episodes.IndexOf(e);
  421. //tvshows[tsindex].Seasons[sindex].Episodes.RemoveAt(eindex);
  422. int eindex = e.Season.Episodes.IndexOf(e);
  423. e.Season.Episodes.RemoveAt(eindex);
  424. if (!IsRemoved)
  425. {
  426. e = new Episode(e.Filepath, e.Name, s);
  427. //tvshows[tsindex].Seasons[sindex].Episodes.Insert(eindex, e);
  428. s.Episodes.Insert(eindex, e);
  429. }
  430. tvEpisodes.SelectedIndex = SelectedEpisodeIndex;
  431. }
  432. private void ResetMovie(Movie m, bool IsRemoved)
  433. {
  434. if (!Dispatcher.CheckAccess())
  435. {
  436. Dispatcher.Invoke(DispatcherPriority.Normal, new MovieChangedHandler(ResetMovie), m, IsRemoved);
  437. return;
  438. }
  439. lbMovies.SelectedIndex = -1;
  440. int mindex = movies.IndexOf(m);
  441. movies.RemoveAt(mindex);
  442. if (!IsRemoved)
  443. {
  444. m = new Movie(m.Folderpath, m.Foldername, m.IsUnsortedFileCollection);
  445. movies.Insert(mindex, m);
  446. }
  447. lbMovies.SelectedIndex = SelectedMovieIndex;
  448. }
  449. private void ResetMovieFile(MovieFile mf, bool IsRemoved)
  450. {
  451. if (!Dispatcher.CheckAccess())
  452. {
  453. Dispatcher.Invoke(DispatcherPriority.Normal, new MovieFileChangedHandler(ResetMovieFile), mf, IsRemoved);
  454. return;
  455. }
  456. Movie m = mf.Movie;
  457. lbMovieFiles.SelectedIndex = -1;
  458. int mindex = movies.IndexOf(m);
  459. int mfindex = movies[mindex].Files.IndexOf(mf);
  460. movies[mindex].Files.RemoveAt(mfindex);
  461. if (!IsRemoved)
  462. {
  463. mf = new MovieFile(mf.Filepath, mf.Name, m);
  464. movies[mindex].Files.Insert(mfindex, mf);
  465. }
  466. lbMovieFiles.SelectedIndex = SelectedMovieFileIndex;
  467. }
  468. private void ResetActorThumb(Person p)
  469. {
  470. if (!Dispatcher.CheckAccess())
  471. {
  472. Dispatcher.Invoke(DispatcherPriority.Normal, new ActorThumbChangedHandler(ResetActorThumb), p);
  473. return;
  474. }
  475. p.Thumb = p.GetImage(p.XBMCFolderPath);
  476. }
  477. #endregion
  478. #region Reload TV and Movie Button Click Routines
  479. private void btnReloadSelectedTV_Click(object sender, RoutedEventArgs e)
  480. {
  481. TVShow ts = SelectedTVShow;
  482. TVShowChanged(ts, false);
  483. }
  484. private void btnReloadSelectedTVs_Click(object sender, RoutedEventArgs e)
  485. {
  486. foreach(TVShow ts in tvshows)
  487. TVShowChanged(ts, false);
  488. }
  489. private void btnReloadAllTV_Click(object sender, RoutedEventArgs e)
  490. {
  491. loadTVShows();
  492. }
  493. private void btnReloadSelectedMovie_Click(object sender, RoutedEventArgs e)
  494. {
  495. Movie m = SelectedMovie;
  496. MovieChanged(m, false);
  497. }
  498. private void btnReloadSelectedMovies_Click(object sender, RoutedEventArgs e)
  499. {
  500. foreach(Movie m in movies)
  501. MovieChanged(m, false);
  502. }
  503. private void btnReloadAllMovie_Click(object sender, RoutedEventArgs e)
  504. {
  505. loadMovies();
  506. }
  507. #endregion
  508. #region Cancel Button Routines
  509. #region Set/Show/Hide Cancel Button Routines
  510. private void SetCancelButtons()
  511. {
  512. ////Set the NotifyIcon Cancel Button
  513. //mnuCancel = new System.Windows.Forms.ToolStripMenuItem();
  514. //mnuCancel.Text = "Cancel";
  515. //mnuCancel.Click += new EventHandler(mnuCancel_Click);
  516. //mnuCancel.Visible = false;
  517. //notifyIcon.ContextMenuStrip.Items.Add(mnuCancel);
  518. //Set the Jumplist Cancel item
  519. jumpCancel = new JumpTask();
  520. jumpCancel.ApplicationPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
  521. jumpCancel.Arguments = "/Cancel:";
  522. jumpCancel.IconResourcePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
  523. jumpCancel.IconResourceIndex = 4;
  524. jumpCancel.Title = "Cancel";
  525. jumpCancel.Description = "Cancels Last Operation";
  526. jumpCancelAll = new JumpTask();
  527. jumpCancelAll.ApplicationPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
  528. jumpCancelAll.Arguments = "/CancelAll:";
  529. jumpCancelAll.IconResourcePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
  530. jumpCancelAll.IconResourceIndex = 4;
  531. jumpCancelAll.Title = "Cancel All";
  532. jumpCancelAll.Description = "Cancels All Operation";
  533. jumpOperationsSeparator = new JumpTask();
  534. }
  535. private void ShowCancelButtons()
  536. {
  537. btnCancelAll.Visibility = Visibility.Visible;
  538. btnCancel.Visibility = Visibility.Visible;
  539. //mnuCancel.Visible = true;
  540. TaskbarItemInfo.Overlay = (BitmapSource)this.FindResource("imgoverlay");
  541. if (!jumplist.JumpItems.Contains(jumpOperationsSeparator))
  542. {
  543. List<JumpItem> jumplistitems = new List<JumpItem>();
  544. jumplistitems.Add(jumpCancel);
  545. jumplistitems.Add(jumpCancelAll);
  546. jumplistitems.Add(jumpOperationsSeparator);
  547. jumplist.JumpItems.InsertRange(0, jumplistitems);
  548. jumplist.Apply();
  549. }
  550. }
  551. private void HideCancelButtons()
  552. {
  553. btnCancelAll.Visibility = Visibility.Collapsed;
  554. btnCancel.Visibility = Visibility.Collapsed;
  555. //mnuCancel.Visible = false;
  556. TaskbarItemInfo.Overlay = null;
  557. if (jumplist.JumpItems.Contains(jumpOperationsSeparator))
  558. {
  559. jumplist.JumpItems.Remove(jumpOperationsSeparator);
  560. jumplist.JumpItems.Remove(jumpCancel);
  561. jumplist.JumpItems.Remove(jumpCancelAll);
  562. jumplist.Apply();
  563. }
  564. }
  565. #endregion
  566. private void btnCancelAll_Click(object sender, RoutedEventArgs e)
  567. {
  568. AbortAllThreads();
  569. }
  570. private void _tbCancelAllButton_Click(object sender, EventArgs e)
  571. {
  572. AbortAllThreads();
  573. }
  574. public void CancelOperation(Thread th)
  575. {
  576. if (th == null)
  577. th = tvThreads[tvThreads.Count - 1];
  578. MetadataCompleted(th, "Operation Aborted", true);
  579. }
  580. private void btnCancel_Click(object sender, RoutedEventArgs e)
  581. {
  582. CancelOperation(null);
  583. }
  584. private void _tbCancelButton_Click(object sender, EventArgs e)
  585. {
  586. CancelOperation(null);
  587. }
  588. private void _tbPauseButton_Click(object sender, EventArgs e)
  589. {
  590. if (_tbPauseButton.Description == "Pause")
  591. {
  592. _tbPauseButton.Description = "Play";
  593. _tbPauseButton.ImageSource = (BitmapImage)Resources["PlayImage"];
  594. tvThreads[tvThreads.Count - 1].Suspend();
  595. SetTasbkBarProgressStatus(TaskbarItemProgressState.Paused);
  596. }
  597. else
  598. {
  599. _tbPauseButton.Description = "Pause";
  600. _tbPauseButton.ImageSource = (BitmapImage)Resources["PauseImage"];
  601. tvThreads[tvThreads.Count - 1].Resume();
  602. SetTasbkBarProgressStatus(TaskbarItemProgressState.Normal);
  603. }
  604. }
  605. #endregion
  606. #region Focus Set Routines
  607. private void SetFocusOnTVShow()
  608. {
  609. //if (!Dispatcher.CheckAccess())
  610. //{
  611. // Dispatcher.Invoke(DispatcherPriority.Normal, new FocusChangedHandler(SetFocusOnTVShow));
  612. // return;
  613. //}
  614. if (tvTVShows.SelectedIndex == -1)
  615. tvTVShows.SelectedIndex = 0;
  616. if (tvTVShows.Items.Count > 0)
  617. {
  618. if (tvTVShows.ItemContainerGenerator.Status == System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated)
  619. {
  620. ListBoxItem lbi = tvTVShows.ItemContainerGenerator.ContainerFromIndex(SelectedTVShowIndex) as ListBoxItem;
  621. if (lbi != null)
  622. {
  623. lbi.IsSelected = true;
  624. lbi.Focus();
  625. }
  626. }
  627. }
  628. }
  629. private void SetFocusOnSeason()
  630. {
  631. //if (!Dispatcher.CheckAccess())
  632. //{
  633. // Dispatcher.Invoke(DispatcherPriority.Normal, new FocusChangedHandler(SetFocusOnSeason));
  634. // return;
  635. //}
  636. if (tvSeasons.SelectedIndex == -1)
  637. tvSeasons.SelectedIndex = 0;
  638. if (tvSeasons.Items.Count > 0)
  639. {
  640. if (tvSeasons.ItemContainerGenerator.Status == System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated)
  641. {
  642. ListBoxItem lbi = tvSeasons.ItemContainerGenerator.ContainerFromIndex(SelectedSeasonIndex) as ListBoxItem;
  643. if (lbi != null)
  644. {
  645. lbi.IsSelected = true;
  646. lbi.Focus();
  647. }
  648. }
  649. }
  650. }
  651. private void SetFocusOnEpisode()
  652. {
  653. //if (!Dispatcher.CheckAccess())
  654. //{
  655. // Dispatcher.Invoke(DispatcherPriority.Normal, new FocusChangedHandler(SetFocusOnEpisode));
  656. // return;
  657. //}
  658. if (tvEpisodes.SelectedIndex == -1)
  659. tvEpisodes.SelectedIndex = 0;
  660. if (tvEpisodes.Items.Count > 0)
  661. {
  662. if (tvEpisodes.ItemContainerGenerator.Status == System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated)
  663. {
  664. ListBoxItem lbi = tvEpisodes.ItemContainerGenerator.ContainerFromIndex(SelectedEpisodeIndex) as ListBoxItem;
  665. if (lbi != null)
  666. {
  667. lbi.IsSelected = true;
  668. lbi.Focus();
  669. }
  670. }
  671. }
  672. }
  673. private void SetFocusOnMovie()
  674. {
  675. //if (!Dispatcher.CheckAccess())
  676. //{
  677. // Dispatcher.Invoke(DispatcherPriority.Normal, new FocusChangedHandler(SetFocusOnMovie));
  678. // return;
  679. //}
  680. if (lbMovies.SelectedIndex == -1)
  681. lbMovies.SelectedIndex = 0;
  682. if (lbMovies.Items.Count > 0)
  683. {
  684. if (lbMovies.ItemContainerGenerator.Status == System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated)
  685. {
  686. ListBoxItem lbi = lbMovies.ItemContainerGenerator.ContainerFromIndex(SelectedMovieIndex) as ListBoxItem;
  687. if (lbi != null)
  688. {
  689. lbi.IsSelected = true;
  690. lbi.Focus();
  691. }
  692. }
  693. }
  694. }
  695. private void SetFocusOnMovieFile()
  696. {
  697. //if (!Dispatcher.CheckAccess())
  698. //{
  699. // Dispatcher.Invoke(DispatcherPriority.Normal, new FocusChangedHandler(SetFocusOnMovieFile));
  700. // return;
  701. //}
  702. if (lbMovieFiles.SelectedIndex == -1)
  703. lbMovieFiles.SelectedIndex = 0;
  704. if (lbMovieFiles.Items.Count > 0)
  705. {
  706. if (lbMovieFiles.ItemContainerGenerator.Status == System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated)
  707. {
  708. ListBoxItem lbi = lbMovieFiles.ItemContainerGenerator.ContainerFromIndex(SelectedMovieFileIndex) as ListBoxItem;
  709. if (lbi != null)
  710. {
  711. lbi.IsSelected = true;
  712. lbi.Focus();
  713. }
  714. }
  715. }
  716. }
  717. private void SetTVTabFocus()
  718. {
  719. if (gridSeriesView.Visibility == Visibility.Visible)
  720. SetFocusOnTVShow();
  721. else if (gridSeasonsView.Visibility == Visibility.Visible)
  722. SetFocusOnSeason();
  723. else if (gridEpisodesView.Visibility == Visibility.Visible)
  724. SetFocusOnEpisode();
  725. }
  726. private void SetMovieTabFocus()
  727. {
  728. if (gridMovie.Visibility == Visibility.Visible)
  729. SetFocusOnMovie();
  730. else if (gridMovieFile.Visibility == Visibility.Visible)
  731. SetFocusOnMovieFile();
  732. }
  733. #endregion
  734. #region Tab Selection and Keyboard Routines
  735. private void tabTVSeries_KeyDown(object sender, KeyEventArgs e)
  736. {
  737. if (e.Key == Key.E && Keyboard.Modifiers == ModifierKeys.Control)
  738. txtSearchTVShow.Focus();
  739. else if (e.Key == Key.Enter)
  740. {
  741. if (gridSeriesView.Visibility == Visibility.Visible)
  742. {
  743. if (SelectedTVShow != null)
  744. ShowSeasons();
  745. }
  746. else if (gridSeasonsView.Visibility == Visibility.Visible)
  747. {
  748. if (SelectedSeason != null)
  749. ShowEpisodeList();
  750. }
  751. }
  752. else if (e.Key == Key.Delete)
  753. {
  754. if (gridSeriesView.Visibility == Visibility.Visible)
  755. {
  756. if (tvTVShows.SelectedItem != null)
  757. btnStripSelectedTV_Click(null, null);
  758. }
  759. else if (gridSeasonsView.Visibility == Visibility.Visible)
  760. {
  761. if (tvSeasons.SelectedItem != null)
  762. btnStripSelectedSeason_Click(null, null);
  763. }
  764. }
  765. else if (e.Key == Key.Back)
  766. {
  767. if (gridSeasonsView.Visibility == Visibility.Visible)
  768. ShowTVShowList();
  769. else if (gridEpisodesView.Visibility == Visibility.Visible)
  770. ShowSeasons();
  771. }
  772. }
  773. private void tabMovies_KeyDown(object sender, KeyEventArgs e)
  774. {
  775. if (e.Key == Key.E && Keyboard.Modifiers == ModifierKeys.Control)
  776. txtSearchMovie.Focus();
  777. else if (e.Key == Key.Enter)
  778. {
  779. if (gridMovie.Visibility == Visibility.Visible)
  780. {
  781. if (SelectedMovie != null)
  782. ShowMovieFileList();
  783. }
  784. }
  785. else if (e.Key == Key.Delete)
  786. {
  787. if (gridMovie.Visibility == Visibility.Visible)
  788. {
  789. if (SelectedMovie != null)
  790. btnStripSelectedMovie_Click(null, null);
  791. }
  792. else if (gridMovieFile.Visibility == Visibility.Visible)
  793. {
  794. if (SelectedMovie != null)
  795. btnStripSelectedMovieFile_Click(null, null);
  796. }
  797. }
  798. else if (e.Key == Key.Back)
  799. {
  800. if (gridMovieFile.Visibility == Visibility.Visible)
  801. ShowMovieList();
  802. }
  803. }
  804. private void tcTabs_SelectionChanged(object sender, SelectionChangedEventArgs e)
  805. {
  806. if (WindowRendered)
  807. StartLoadingItems();
  808. }
  809. private void StartLoadingItems()
  810. {
  811. //Find out what tab is selected. If the program is just loading up, then the
  812. // tab control might not be generated or have a selected tab yet, so we have
  813. // to take into account a "null" scenario.
  814. TabItem CurrentTab = tcTabs.SelectedItem as TabItem;
  815. String CurrentTabName = "";
  816. if (CurrentTab != null)
  817. CurrentTabName = CurrentTab.Name;
  818. //switch (tcTabs.SelectedIndex)
  819. switch (CurrentTabName)
  820. {
  821. case "tabTVSeries":
  822. StartLoadingTVShows();
  823. break;
  824. case "tabMovies":
  825. StartLoadingMovies();
  826. break;
  827. default:
  828. break;
  829. }
  830. }
  831. #endregion
  832. #region Taskbar Progress Status Routines
  833. private void SetTasbkBarProgressStatus(TaskbarItemProgressState state)
  834. {
  835. if (!Dispatcher.CheckAccess())
  836. {
  837. Dispatcher.Invoke(DispatcherPriority.Normal, new TaskbarProgressStatusChangeHandler(SetTasbkBarProgressStatus), state);
  838. return;
  839. }
  840. TaskbarItemInfo.ProgressState = state;
  841. }
  842. private void SetTasbkBarProgressValue(int value)
  843. {
  844. if (!Dispatcher.CheckAccess())
  845. {
  846. Dispatcher.Invoke(DispatcherPriority.Send, new TaskbarProgressValueChangeHandler(SetTasbkBarProgressValue), value);
  847. return;
  848. }
  849. if (value != maxvalue)
  850. {
  851. if (TaskbarItemInfo.ProgressState != TaskbarItemProgressState.Normal)
  852. TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Normal;
  853. TaskbarItemInfo.ProgressValue = ((double)value/maxvalue);
  854. }
  855. else
  856. TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None;
  857. }
  858. #endregion
  859. #region Loading TV and Movie Routines
  860. private void StartLoadingTVShows()
  861. {
  862. //Make sure the TVFolder is set before attempting to load in all the TV show data.
  863. System.Collections.Specialized.StringCollection TVFolders = Properties.Settings.Default.TVFolders;
  864. if (TVFolders == null || TVFolders.Count == 0)
  865. {
  866. if (tvshows.Count > 0)
  867. {
  868. tvshows.Clear();
  869. SetTVShowTabItemsVisibility(Visibility.Hidden);
  870. UpdateTVPoster(null, TVShowPosterType.Banner, false);
  871. UpdateTVPoster(null, TVShowPosterType.Poster, false);
  872. UpdateTVPoster(null, TVShowPosterType.Backdrop, false);
  873. }
  874. return;
  875. }
  876. if ((tvshows == null || tvshows.Count == 0 || resetTVfolder) && WindowRendered)
  877. {
  878. resetTVfolder = false;
  879. loadTVShows();
  880. gridTVSeries.DataContext = dispatchtvshows;
  881. }
  882. }
  883. bool LoadingTVShows = false;
  884. private void loadTVShows()
  885. {
  886. if (!LoadingTVShows)
  887. {
  888. LoadingTVShows = true;
  889. tvTVShows.SelectedIndex = -1;
  890. tvshows.Clear();
  891. //Load it on a seperate thread (hence the use of the DispatchingCollection) so as not to lag UI
  892. ShowCancelButtons();
  893. Thread th = null;
  894. th = new Thread(delegate()
  895. {
  896. foreach (String dir in Properties.Settings.Default.TVFolders)
  897. {
  898. if (Directory.Exists(dir))
  899. {
  900. DirectoryInfo TVShows = new DirectoryInfo(dir);
  901. maxvalue += TVShows.GetDirectories().Length;
  902. try
  903. {
  904. int UnsortedFilesLength = 0;
  905. bool containsUnsortedFiles = false;
  906. foreach (FileInfo fi in TVShows.GetFiles())
  907. {
  908. if (AllowedFileTypes.Contains(fi.Extension))
  909. {
  910. containsUnsortedFiles = true;
  911. UnsortedFilesLength++;
  912. }
  913. }
  914. if (containsUnsortedFiles)
  915. {
  916. maxvalue += UnsortedFilesLength;
  917. TVShow t = new TVShow(TVShows.FullName, "Unsorted Episodes", true);
  918. UnsortedEpisodes = t;
  919. tvshows.Add(t);
  920. }
  921. foreach (DirectoryInfo di in TVShows.GetDirectories())
  922. {
  923. TVShow t = new TVShow(di.FullName, di.Name, false);
  924. tvshows.Add(t);
  925. SetTasbkBarProgressValue(++currentvalue);
  926. }
  927. }
  928. catch (Exception ex)
  929. {
  930. if (th.ThreadState != System.Threading.ThreadState.AbortRequested)
  931. {
  932. SetTasbkBarProgressStatus(TaskbarItemProgressState.Error);
  933. MessageBox.Show(ex.Message);
  934. }
  935. }
  936. }
  937. }
  938. MetadataCompleted(th, tvshows.Count.ToString(), true);
  939. });
  940. th.Name = "Loading TV Shows";
  941. th.SetApartmentState(ApartmentState.STA);
  942. th.Start();
  943. tvThreads.Add(th);
  944. }
  945. }
  946. private void StartLoadingMovies()
  947. {
  948. //Make sure the MovieFolder is set before attempting to load in all the movies data.
  949. System.Collections.Specialized.StringCollection MovieFolders = Properties.Settings.Default.MovieFolders;
  950. if (MovieFolders == null || MovieFolders.Count == 0)
  951. {
  952. if (movies.Count > 0)
  953. {
  954. movies.Clear();
  955. SetMovieTabItemsVisibility(Visibility.Hidden);
  956. UpdateMoviePoster(null, MoviePosterType.Poster, false);
  957. UpdateMoviePoster(null, MoviePosterType.Backdrop, false);
  958. }
  959. return;
  960. }
  961. if (movies == null || movies.Count == 0 || resetMoviefolder)
  962. {
  963. resetMoviefolder = false;
  964. loadMovies();
  965. gridMovies.DataContext = dispatchmovies;
  966. }
  967. }
  968. bool LoadingMovies = false;
  969. private void loadMovies()
  970. {
  971. if (!LoadingMovies)
  972. {
  973. LoadingMovies = true;
  974. lbMovies.SelectedIndex = -1;
  975. movies.Clear();
  976. ShowCancelButtons();
  977. Thread th = null;
  978. th = new Thread(delegate()
  979. {
  980. foreach (String dir in Properties.Settings.Default.MovieFolders)
  981. {
  982. if (Directory.Exists(dir))
  983. {
  984. DirectoryInfo Movies = new DirectoryInfo(dir);
  985. maxvalue += Movies.GetDirectories().Length;
  986. try
  987. {
  988. int UnsortedFilesLength = 0;
  989. bool containsUnsortedFiles = false;
  990. foreach (FileInfo fi in Movies.GetFiles())
  991. {
  992. if (AllowedFileTypes.Contains(fi.Extension))
  993. {
  994. containsUnsortedFiles = true;
  995. UnsortedFilesLength++;
  996. }
  997. }
  998. maxvalue += UnsortedFilesLength;
  999. if (containsUnsortedFiles)
  1000. {
  1001. Movie m = new Movie(Movies.FullName, "Unsorted Files", true);
  1002. UnsortedFiles = m;
  1003. movies.Add(m);
  1004. }
  1005. foreach (DirectoryInfo di in Movies.GetDirectories())
  1006. {
  1007. Movie m = new Movie(di.FullName, di.Name, false);
  1008. movies.Add(m);
  1009. SetTasbkBarProgressValue(++currentvalue);
  1010. }
  1011. }
  1012. catch (Exception ex)
  1013. {
  1014. if (th.ThreadState != System.Threading.ThreadState.AbortRequested)
  1015. {
  1016. SetTasbkBarProgressStatus(TaskbarItemProgressState.Error);
  1017. MessageBox.Show(ex.Message);
  1018. }
  1019. }
  1020. }
  1021. }
  1022. MetadataCompleted(th, movies.Count.ToString(), true);
  1023. });
  1024. th.Name = "Loading Movies";
  1025. th.SetApartmentState(ApartmentState.STA);
  1026. th.Start();
  1027. tvThreads.Add(th);
  1028. }
  1029. }
  1030. #endregion
  1031. #region Open In Explorer Routines
  1032. private void btnOpenTVShow_Click(object sender, RoutedEventArgs e)
  1033. {
  1034. System.Diagnostics.Process.Start("explorer.exe", "/select," + SelectedTVShow.Folderpath);
  1035. }
  1036. private void btnOpenSeason_Click(object sender, RoutedEventArgs e)
  1037. {
  1038. System.Diagnostics.Process.Start("explorer.exe", "/select," + SelectedSeason.Folderpath);
  1039. }
  1040. private void btnOpenSeasonMetadata_Click(object sender, RoutedEventArgs e)
  1041. {
  1042. String dir = SelectedSeason.MetadataFolderPath;
  1043. if(Directory.Exists(dir))
  1044. System.Diagnostics.Process.Start("explorer.exe", dir);
  1045. else
  1046. MessageBox.Show("Directory doesn't Exist");
  1047. }
  1048. private void btnOpenEpisode_Click(object sender, RoutedEventArgs e)
  1049. {
  1050. String file = SelectedEpisode.Filepath;
  1051. if (File.Exists(file))
  1052. System.Diagnostics.Process.Start("explorer.exe", "/select," + file);
  1053. else
  1054. MessageBox.Show("File doesn't Exist");
  1055. }
  1056. private void btnOpenEpisodeXMLMetadata_Click(object sender, RoutedEventArgs e)
  1057. {
  1058. String file = SelectedEpisode.XMLFile;
  1059. if(File.Exists(file))
  1060. System.Diagnostics.Process.Start("explorer.exe", "/select," + file);
  1061. else
  1062. MessageBox.Show("File doesn't Exist");
  1063. }
  1064. private void btnOpenMovie_Click(object sender, RoutedEventArgs e)
  1065. {
  1066. System.Diagnostics.Process.Start("explorer.exe", "/select," + SelectedMovie.Folderpath);
  1067. }
  1068. private void btnOpenMovieFile_Click(object sender, RoutedEventArgs e)
  1069. {
  1070. String file = SelectedMovieFile.Filepath;
  1071. if (File.Exists(file))
  1072. System.Diagnostics.Process.Start("explorer.exe", "/select," + file);
  1073. else
  1074. MessageBox.Show("File doesn't Exist");
  1075. }
  1076. private void btnOpenActorThumb_Click(object sender, RoutedEventArgs e)
  1077. {
  1078. String file;
  1079. if (Properties.Settings.Default.SaveXBMCMeta)
  1080. {
  1081. file = SelectedPerson.XBMCFolderPath + "\\" + SelectedPerson.Name.Replace(" ", "_") + ".jpg";
  1082. if (File.Exists(file))
  1083. System.Diagnostics.Process.Start("explorer.exe", "/select," + file);
  1084. else
  1085. MessageBox.Show("File doesn't Exist");
  1086. }
  1087. if (Properties.Settings.Default.SaveMyMoviesMeta)
  1088. {
  1089. file = SelectedPerson.MyMoviesFolderPath + "\\" + SelectedPerson.Name.Replace(" ", "_") + @"\folder.jpg";
  1090. if (File.Exists(file))
  1091. System.Diagnostics.Process.Start("explorer.exe", "/select," + file);
  1092. else
  1093. MessageBox.Show("File doesn't Exist");
  1094. }
  1095. }
  1096. #endregion
  1097. #region TV Series, Season, Episode And Movie Listbox Routines
  1098. #region TV Shows ListBox Routines
  1099. private void tvTVShows_SelectionChanged(object sender, SelectionChangedEventArgs e)
  1100. {
  1101. if (tvTVShows.SelectedItems.Count > 1)
  1102. tvTVShows.ItemTemplate = FindResource("dtMultipleTVShows") as DataTemplate;
  1103. else
  1104. {
  1105. if (tvTVShows.SelectedIndex != -1)
  1106. {
  1107. SelectedTVShow = (TVShow)tvTVShows.SelectedItem;
  1108. SelectedTVShowIndex = tvTVShows.SelectedIndex;
  1109. if (!SelectedTVShow.IsUnsortedEpisodeCollection)
  1110. {
  1111. tvTVShows.ItemTemplate = FindResource("dtTVShows") as DataTemplate;
  1112. ShowTVShowList();
  1113. SelectedTVShow.Load();
  1114. UpdateTVPoster(SelectedTVShow, TVShowPosterType.Poster, SelectedTVShow.isPosterLoading);
  1115. UpdateTVPoster(SelectedTVShow, TVShowPosterType.Backdrop, SelectedTVShow.isBackDropLoading);
  1116. UpdateTVPoster(SelectedTVShow, TVShowPosterType.Banner, SelectedTVShow.isBannerLoading);
  1117. }
  1118. else
  1119. {
  1120. tvTVShows.ItemTemplate = FindResource("dtUnsortedEpisodesCollection") as DataTemplate;
  1121. ShowUnsortedEpisodeCollection();
  1122. }
  1123. }
  1124. }
  1125. }
  1126. private void ShowTVShowList()
  1127. {
  1128. gridEpisodesView.Visibility = Visibility.Hidden;
  1129. gridSeasonsView.Visibility = Visibility.Hidden;
  1130. gridSeriesView.Visibility = Visibility.Visible;
  1131. SetFocusOnTVShow();
  1132. }
  1133. private void TVShowItem_DoubleClick(object sender, MouseButtonEventArgs e)
  1134. {
  1135. if (e.ClickCount == 2)
  1136. ShowSeasons();
  1137. }
  1138. private void ShowUnsortedEpisodeCollection()
  1139. {
  1140. SelectedSeason = SelectedTVShow.UnsortedEpisodes[0].Season;
  1141. ShowEpisodeList();
  1142. }
  1143. private void ShowSeasons()
  1144. {
  1145. TVShow ts = SelectedTVShow;
  1146. if (ts.IsUnsortedEpisodeCollection)
  1147. {
  1148. if (gridEpisodesView.Visibility == Visibility.Visible)
  1149. ShowTVShowList();
  1150. else
  1151. ShowUnsortedEpisodeCollection();
  1152. }
  1153. else
  1154. ShowSeasonList();
  1155. }
  1156. private void ShowSeasonList()
  1157. {
  1158. gridSeriesView.Visibility = Visibility.Hidden;
  1159. gridEpisodesView.Visibility = Visibility.Hidden;
  1160. gridSeasonsView.Visibility = Visibility.Visible;
  1161. gridSeasonsView.DataContext = SelectedTVShow;
  1162. //tvSeasons.ItemsSource = SelectedTVShow.Seasons;
  1163. SetFocusOnSeason();
  1164. }
  1165. #endregion
  1166. #region Seasons ListBox Routines
  1167. private void tvSeasons_SelectionChanged(object sender, SelectionChangedEventArgs e)
  1168. {
  1169. if (tvSeasons.SelectedItems.Count > 1)
  1170. tvSeasons.ItemTemplate = FindResource("dtMultipleSeasons") as DataTemplate;
  1171. else
  1172. {
  1173. tvSeasons.ItemTemplate = FindResource("dtSeasons") as DataTemplate;
  1174. if (tvSeasons.SelectedIndex != -1)
  1175. {
  1176. SelectedSeason = (Season)tvSeasons.SelectedItem;
  1177. SelectedSeasonIndex = tvSeasons.SelectedIndex;
  1178. UpdateSeasonPoster(SelectedSeason, TVShowPosterType.Season_Poster, SelectedSeason.isPosterLoading);
  1179. UpdateSeasonPoster(SelectedSeason, TVShowPosterType.Season_Backdrop, SelectedSeason.isBackDropLoading);
  1180. }
  1181. }
  1182. }
  1183. private void SeasonItem_DoubleClick(object sender, MouseButtonEventArgs e)
  1184. {
  1185. if (e.ClickCount == 2)
  1186. ShowEpisodeList();
  1187. }
  1188. private void ShowEpisodeList()
  1189. {
  1190. if(SelectedSeason.TVShow.IsUnsortedEpisodeCollection)
  1191. btnEpisodesBack.Visibility = Visibility.Collapsed;
  1192. else
  1193. btnEpisodesBack.Visibility = Visibility.Visible;
  1194. gridSeriesView.Visibility = Visibility.Hidden;
  1195. gridSeasonsView.Visibility = Visibility.Hidden;
  1196. gridEpisodesView.Visibility = Visibility.Visible;
  1197. gridEpisodesView.DataContext = SelectedSeason;
  1198. //tvEpisodes.ItemsSource = SelectedSeason.Episodes;
  1199. SetFocusOnEpisode();
  1200. }
  1201. private void btnSeasonBack_Click(object sender, RoutedEventArgs e)
  1202. {
  1203. ShowTVShowList();
  1204. }
  1205. #endregion
  1206. #region Episodes ListBox Routines
  1207. private void tvEpisodes_SelectionChanged(object sender, SelectionChangedEventArgs e)
  1208. {
  1209. if (tvEpisodes.SelectedItems.Count > 1)
  1210. tvEpisodes.ItemTemplate = FindResource("dtMultipleEpisodes") as DataTemplate;
  1211. else
  1212. {
  1213. tvEpisodes.ItemTemplate = FindResource("dtEpisodes") as DataTemplate;
  1214. if (tvEpisodes.SelectedIndex != -1)
  1215. {
  1216. SelectedEpisode = tvEpisodes.SelectedItem as Episode;
  1217. SelectedEpisodeIndex = tvEpisodes.SelectedIndex;
  1218. SelectedEpisode.Load();
  1219. UpdateEpisodePoster(SelectedEpisode, SelectedEpisode.PosterFilename, false);
  1220. }
  1221. }
  1222. }
  1223. private void btnEpisodesBack_Click(object sender, RoutedEventArgs e)
  1224. {
  1225. ShowSeasons();
  1226. }
  1227. #endregion
  1228. #region Movies ListBox Routines
  1229. private void lbMovies_SelectionChanged(object sender, SelectionChangedEventArgs e)
  1230. {
  1231. if (lbMovies.SelectedItems.Count > 1)
  1232. lbMovies.ItemTemplate = FindResource("dtMultipleMovies") as DataTemplate;
  1233. else
  1234. {
  1235. lbMovies.ItemTemplate = FindResource("dtMovies") as DataTemplate;
  1236. if (lbMovies.SelectedIndex != -1)
  1237. {
  1238. SelectedMovie = (Movie)lbMovies.SelectedItem;
  1239. SelectedMovieIndex = lbMovies.SelectedIndex;
  1240. if (!SelectedMovie.IsUnsortedFileCollection)
  1241. {
  1242. ShowMovieList();
  1243. SelectedMovie.Load();
  1244. UpdateMoviePoster(SelectedMovie, MoviePosterType.Poster, SelectedMovie.isPosterLoading);
  1245. UpdateMoviePoster(SelectedMovie, MoviePosterType.Backdrop, SelectedMovie.isBackDropLoading);
  1246. }
  1247. else
  1248. {
  1249. lbMovies.ItemTemplate = FindResource("dtUnsortedFilesCollection") as DataTemplate;
  1250. ShowMovieFileList();
  1251. }
  1252. }
  1253. }
  1254. }
  1255. private void ShowMovieList()
  1256. {
  1257. gridMovieFile.Visibility = Visibility.Hidden;
  1258. gridMovie.Visibility = Visibility.Visible;
  1259. SetFocusOnMovie();
  1260. }
  1261. private void MovieItem_DoubleClick(object sender, MouseButtonEventArgs e)
  1262. {
  1263. if (e.ClickCount == 2)
  1264. ShowMovieFileList();
  1265. }
  1266. private void ShowMovieFileList()
  1267. {
  1268. if (SelectedMovie.IsUnsortedFileCollection)
  1269. btnMovieFileBack.Visibility = Visibility.Collapsed;
  1270. else
  1271. btnMovieFileBack.Visibility = Visibility.Visible;
  1272. gridMovie.Visibility = Visibility.Hidden;
  1273. gridMovieFile.Visibility = Visibility.Visible;
  1274. SetFocusOnMovieFile();
  1275. }
  1276. #endregion
  1277. #region Movie File ListBox Routines
  1278. private void lbMovieFiles_SelectionChanged(object sender, SelectionChangedEventArgs e)
  1279. {
  1280. if (lbMovieFiles.SelectedItems.Count > 1)
  1281. lbMovieFiles.ItemTemplate = FindResource("dtMultipleMovieFiles") as DataTemplate;
  1282. else
  1283. {
  1284. lbMovieFiles.ItemTemplate = FindResource("dtMovieFiles") as DataTemplate;
  1285. if (lbMovieFiles.SelectedIndex != -1)
  1286. {
  1287. SelectedMovieFile = (MovieFile)lbMovieFiles.SelectedItem;
  1288. SelectedMovieFileIndex = lbMovieFiles.SelectedIndex;
  1289. UpdateMovieFilePoster(SelectedMovieFile, MoviePosterType.File_Poster, SelectedMovieFile.isPosterLoading);
  1290. UpdateMovieFilePoster(SelectedMovieFile, MoviePosterType.File_Backdrop, SelectedMovieFile.isBackDropLoading);
  1291. }
  1292. }
  1293. }
  1294. private void btnMovieFileBack_Click(object sender, RoutedEventArgs e)
  1295. {
  1296. ShowMovieList();
  1297. }
  1298. #endregion
  1299. #region Actor Listbox Routines
  1300. private void lstMovieActors_SelectionChanged(object sender, SelectionChangedEventArgs e)
  1301. {
  1302. if (lstMovieActors.SelectedIndex != -1)
  1303. {
  1304. SelectedPerson = lstMovieActors.SelectedItem as Person;
  1305. }
  1306. }
  1307. private void lstTVActors_SelectionChanged(object sender, SelectionChangedEventArgs e)
  1308. {
  1309. if (lstTVActors.SelectedIndex != -1)
  1310. {
  1311. SelectedPerson = lstTVActors.SelectedItem as Person;
  1312. }
  1313. }
  1314. #endregion
  1315. #endregion
  1316. #region Search For IDs From Providers
  1317. private class SearchResultsDecision
  1318. {
  1319. //public String SearchObjectName = null;
  1320. public String SelectedID = null;
  1321. public String SelectedName = null;
  1322. public bool SelectedHasMultipleTitles = false;
  1323. public String SearchTerm = null;
  1324. public object[] results = null;
  1325. public DecisionType Decision = DecisionType.Continue;
  1326. };
  1327. private void SetBestMatchOnTopInMovieResults(object[] results, Movie movie, String SearchTerm)
  1328. {
  1329. int i = 0;
  1330. bool found = false;
  1331. int foundindex = 0;
  1332. if (movie.ID != null)
  1333. {
  1334. foreach (MediaScout.MovieXML m in results)
  1335. {
  1336. if (movie.ID == m.ID)
  1337. {
  1338. foundindex = i;
  1339. found = true;
  1340. break;
  1341. }
  1342. i++;
  1343. }
  1344. }
  1345. else
  1346. {
  1347. if (movie.Year != null)
  1348. {
  1349. List<int> SortedByYear = new List<int>();
  1350. foreach (MediaScout.MovieXML m in results)
  1351. {
  1352. if (m.Year != null)
  1353. {
  1354. if (m.Year == movie.Year)
  1355. {
  1356. if (m.Title == SearchTerm)
  1357. {
  1358. foundindex = i;
  1359. found = true;
  1360. break;
  1361. }
  1362. }
  1363. }
  1364. if (m.Title == SearchTerm)
  1365. {
  1366. foundindex = i;
  1367. found = true;
  1368. }
  1369. //year not defined or no year and title match items
  1370. SortedByYear.Add(i);
  1371. i++;
  1372. }
  1373. if (!found)
  1374. {
  1375. foreach (int index in SortedByYear)
  1376. {
  1377. if ((results[index] as MediaScout.MovieXML).Title.Contains(SearchTerm) && (results[index] as MediaScout.MovieXML).Year != null)
  1378. {
  1379. foundindex = index;
  1380. found = true;
  1381. break;
  1382. }
  1383. if ((results[index] as MediaScout.MovieXML).Title.Contains(SearchTerm))
  1384. {
  1385. foundindex = index;
  1386. found = true;
  1387. }
  1388. }
  1389. if (!found && SortedByYear.Count > 0)
  1390. {
  1391. foundindex = SortedByYear[0];
  1392. found = true;
  1393. }
  1394. }
  1395. }
  1396. else
  1397. {
  1398. foreach (MediaScout.MovieXML m in results)
  1399. {
  1400. if (m.Title == SearchTerm)
  1401. {
  1402. foundindex = i;
  1403. found = true;
  1404. break;
  1405. }
  1406. else if (m.Title.Contains(SearchTerm))
  1407. {
  1408. foundindex = i;
  1409. found = true;
  1410. }
  1411. }
  1412. }
  1413. }
  1414. if (found)
  1415. {
  1416. object temp;
  1417. temp = results[0];
  1418. results[0] = results[foundindex];
  1419. results[foundindex] = temp;
  1420. }
  1421. }
  1422. private void SetBestMatchOnTopInTVShowResults(object[] results, TVShow tvshow, String SearchTerm)
  1423. {
  1424. int i = 0;
  1425. bool found = false;
  1426. int foundindex = 0;
  1427. if (tvshow.ID != null)
  1428. {
  1429. foreach (MediaScout.TVShowXML m in results)
  1430. {
  1431. if (tvshow.ID == m.ID)
  1432. {
  1433. foundindex = i;
  1434. found = true;
  1435. break;
  1436. }
  1437. i++;
  1438. }
  1439. }
  1440. else
  1441. {
  1442. if (tvshow.Year != null)
  1443. {
  1444. List<int> SortedByYear = new List<int>();
  1445. foreach (MediaScout.TVShowXML m in results)
  1446. {
  1447. if (m.Year != null)
  1448. {
  1449. if (m.Year == tvshow.Year)
  1450. {
  1451. if (m.Title == SearchTerm)
  1452. {
  1453. foundindex = i;
  1454. found = true;
  1455. break;
  1456. }
  1457. }
  1458. }
  1459. if (m.Title == SearchTerm)
  1460. {
  1461. foundindex = i;
  1462. found = true;
  1463. }
  1464. //year not defined or no year and title match items
  1465. SortedByYear.Add(i);
  1466. i++;
  1467. }
  1468. if (!found)
  1469. {
  1470. foreach (int index in SortedByYear)
  1471. {
  1472. if ((results[index] as MediaScout.TVShowXML).Title.Contains(SearchTerm) && (results[index] as MediaScout.TVShowXML).Year != null)
  1473. {
  1474. foundindex = index;
  1475. found = true;
  1476. break;
  1477. }
  1478. if ((results[index] as MediaScout.TVShowXML).Title.Contains(SearchTerm))
  1479. {
  1480. foundindex = index;
  1481. found = true;
  1482. }
  1483. }
  1484. if (!found && SortedByYear.Count > 0)
  1485. {
  1486. foundindex = SortedByYear[0];
  1487. found = true;
  1488. }
  1489. }
  1490. }
  1491. else
  1492. {
  1493. foreach (MediaScout.TVShowXML m in results)
  1494. {
  1495. if (m.Title == SearchTerm)
  1496. {
  1497. foundindex = i;
  1498. found = true;
  1499. break;
  1500. }
  1501. else if (m.Title.Contains(SearchTerm))
  1502. {
  1503. foundindex = i;
  1504. found = true;
  1505. }
  1506. }
  1507. }
  1508. }
  1509. if (found)
  1510. {
  1511. object temp;
  1512. temp = results[0];
  1513. results[0] = results[foundindex];
  1514. results[foundindex] = temp;
  1515. }
  1516. }
  1517. private SearchResultsDecision PromptForSearchTerm(String SearchObjectName, String SearchTerm, bool IsMovie, bool forced, bool CanUserSkip)
  1518. {
  1519. SearchResultsDecision SearchDecision = new SearchResultsDecision();
  1520. Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
  1521. new Action(
  1522. delegate()
  1523. {
  1524. while ((SearchDecision.results == null || SearchDecision.results.Length == 0) && (SearchDecision.Decision == DecisionType.Continue))
  1525. {
  1526. NoResultsDialog nrd = new NoResultsDialog(SearchObjectName, SearchTerm, forced, CanUserSkip, IsMovie);
  1527. nrd.Owner = this;
  1528. nrd.ShowDialog();
  1529. SearchTerm = nrd.Term;
  1530. SearchDecision.Decision = nrd.Decision;
  1531. if (SearchDecision.Decision == DecisionType.Continue)
  1532. {
  1533. if (IsMovie)
  1534. SearchDecision.results = tmdb.Search(SearchTerm);
  1535. else
  1536. SearchDecision.results = tvdb.Search(SearchTerm);
  1537. }
  1538. }
  1539. }
  1540. ));
  1541. SearchDecision.SearchTerm = SearchTerm;
  1542. return SearchDecision;
  1543. }
  1544. private SearchResultsDecision PromptForSelection(String SearchObjectName, SearchResultsDecision SearchDecision, object item, bool IsMovie, bool Skip)
  1545. {
  1546. Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
  1547. new Action(
  1548. delegate()
  1549. {
  1550. SelectResultDialog rsd = new SelectResultDialog(SearchObjectName, SearchDecision.results, IsMovie, Skip);
  1551. rsd.Owner = this;
  1552. rsd.ShowDialog();
  1553. SearchDecision.Decision = rsd.Decision;
  1554. if (SearchDecision.Decision == DecisionType.SearchAgain)
  1555. {
  1556. SearchDecision = PromptForSearchTerm(SearchObjectName, SearchDecision.SearchTerm, IsMovie, true, Skip);
  1557. if (SearchDecision.results != null)
  1558. {
  1559. if (SearchDecision.results.Length == 0)
  1560. SearchDecision = PromptForSearchTerm(SearchObjectName, SearchDecision.SearchTerm, IsMovie, false, Skip);
  1561. if (SearchDecision.Decision == DecisionType.Continue)
  1562. {
  1563. //if (SearchDecision.results.Length == 1)
  1564. // SearchDecision = GetSelectedIDAndName(SearchDecision, IsMovie, 0);
  1565. //else
  1566. if (Properties.Settings.Default.SilentMode)
  1567. {
  1568. if (IsMovie)
  1569. SetBestMatchOnTopInMovieResults(SearchDecision.results, item as Movie, SearchDecision.SearchTerm);
  1570. else
  1571. SetBestMatchOnTopInTVShowResults(SearchDecision.results, item as TVShow, SearchDecision.SearchTerm);
  1572. SearchDecision = GetSelectedIDAndName(SearchDecision, IsMovie, 0);
  1573. }
  1574. else // if (SearchDecision.results.Length > 1)
  1575. {
  1576. if (IsMovie)
  1577. SetBestMatchOnTopInMovieResults(SearchDecision.results, item as Movie, SearchDecision.SearchTerm);
  1578. else
  1579. SetBestMatchOnTopInTVShowResults(SearchDecision.results, item as TVShow, SearchDecision.SearchTerm);
  1580. SearchDecision = PromptForSelection(SearchObjectName, SearchDecision, item, IsMovie, Skip);
  1581. }
  1582. }
  1583. }
  1584. }
  1585. if (rsd.Decision == DecisionType.Continue)
  1586. {
  1587. MediaScout.MovieXML m;
  1588. MediaScout.TVShowXML ts;
  1589. if (IsMovie)
  1590. {
  1591. m = rsd.Selected as MediaScout.MovieXML;
  1592. SearchDecision.SelectedName = m.Title;
  1593. SearchDecision.SelectedID = m.ID;
  1594. }
  1595. else
  1596. {
  1597. ts = rsd.Selected as MediaScout.TVShowXML;
  1598. SearchDecision.SelectedName = ts.Title;
  1599. SearchDecision.SelectedID = ts.ID;
  1600. }
  1601. }
  1602. }
  1603. ));
  1604. return SearchDecision;
  1605. }
  1606. private SearchResultsDecision SearchForID(object item, bool IsMovie, String SearchObjectName, String SearchTerm, bool CanUserSkip, bool forceEnterSearchTerm)
  1607. {
  1608. SearchResultsDecision SearchDecision = new SearchResultsDecision();
  1609. Movie m = null;
  1610. TVShow ts = null;
  1611. if (IsMovie)
  1612. m = item as Movie;
  1613. else
  1614. ts = item as TVShow;
  1615. //try to load ID from the metadata file if it exist
  1616. if (!forceEnterSearchTerm)
  1617. {
  1618. if (IsMovie)
  1619. {
  1620. if (m.ID == null)
  1621. m.Load();
  1622. if (m.HasMetadata || m.ID != null)
  1623. {
  1624. SearchDecision.SelectedName = m.Name;
  1625. SearchDecision.SelectedID = m.ID;
  1626. }
  1627. }
  1628. else
  1629. {
  1630. if (ts.ID == null)
  1631. ts.Load();
  1632. if (ts.HasMetadata || ts.ID != null)
  1633. {
  1634. SearchDecision.SelectedName = ts.Name;
  1635. SearchDecision.SelectedID = ts.ID;
  1636. }
  1637. }
  1638. }
  1639. //else, the GUIType doesn't have an ID (ie, if the metadata hasn't been fetched before)
  1640. if (SearchDecision.SelectedID == null)
  1641. {
  1642. if (SearchTerm == null)
  1643. if (IsMovie)
  1644. SearchTerm = m.HasMetadata ? m.SearchTerm : m.GetSearchTerm();
  1645. else
  1646. SearchTerm = ts.HasMetadata ? ts.SearchTerm : ts.GetSearchTerm();
  1647. SearchDecision.SearchTerm = SearchTerm;
  1648. if (forceEnterSearchTerm)
  1649. SearchDecision = PromptForSearchTerm(SearchObjectName, SearchDecision.SearchTerm, IsMovie, true, CanUserSkip);
  1650. else
  1651. {
  1652. if (IsMovie)
  1653. SearchDecision.results = tmdb.Search(SearchDecision.SearchTerm);
  1654. else
  1655. SearchDecision.results = tvdb.Search(SearchDecision.SearchTerm);
  1656. }
  1657. if (SearchDecision.Decision == DecisionType.Continue)
  1658. {
  1659. if (SearchDecision.results == null)
  1660. SearchDecision = PromptForSearchTerm(SearchObjectName, SearchDecision.SearchTerm, IsMovie, false, CanUserSkip);
  1661. if (SearchDecision.Decision == DecisionType.Continue)
  1662. {
  1663. //if (SearchDecision.results.Length == 1)
  1664. // SearchDecision = GetSelectedIDAndName(SearchDecision, IsMovie, 0);
  1665. //else
  1666. if (Properties.Settings.Default.SilentMode)
  1667. {
  1668. if (IsMovie)
  1669. SetBestMatchOnTopInMovieResults(SearchDecision.results, m, SearchDecision.SearchTerm);
  1670. else
  1671. SetBestMatchOnTopInTVShowResults(SearchDecision.results, ts, SearchDecision.SearchTerm);
  1672. SearchDecision = GetSelectedIDAndName(SearchDecision, IsMovie, 0);
  1673. }
  1674. else // if (SearchDecision.results.Length > 1)
  1675. {
  1676. if (IsMovie)
  1677. SetBestMatchOnTopInMovieResults(SearchDecision.results, m, SearchDecision.SearchTerm);
  1678. else
  1679. SetBestMatchOnTopInTVShowResults(SearchDecision.results, ts, SearchDecision.SearchTerm);
  1680. SearchDecision = PromptForSelection(SearchObjectName, SearchDecision, item, IsMovie, CanUserSkip);
  1681. }
  1682. }
  1683. //m.SearchTerm = SearchDecision.SearchTerm;
  1684. if(SearchDecision.SelectedName != null)
  1685. Message("Selected " + SearchDecision.SelectedName, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  1686. }
  1687. }
  1688. return SearchDecision;
  1689. }
  1690. private SearchResultsDecision GetSelectedIDAndName(SearchResultsDecision SearchDecision, bool IsMovie, int index)
  1691. {
  1692. MediaScout.MovieXML m;
  1693. MediaScout.TVShowXML ts;
  1694. if (IsMovie)
  1695. {
  1696. m = SearchDecision.results[index] as MediaScout.MovieXML;
  1697. SearchDecision.SelectedName = m.Title;
  1698. SearchDecision.SelectedID = m.ID;
  1699. }
  1700. else
  1701. {
  1702. ts = SearchDecision.results[index] as MediaScout.TVShowXML;
  1703. SearchDecision.SelectedName = ts.Title;
  1704. SearchDecision.SelectedID = ts.ID;
  1705. }
  1706. return SearchDecision;
  1707. }
  1708. #endregion
  1709. #region Build Selected Items List
  1710. private ObservableCollection<TVShow> BuildSelectedShowList()
  1711. {
  1712. ObservableCollection<TVShow> tvshows = null;
  1713. if (tvTVShows.SelectedItems.Count > 0)
  1714. {
  1715. tvshows = new ObservableCollection<TVShow>();
  1716. foreach (TVShow ts in tvTVShows.SelectedItems)
  1717. tvshows.Add(ts);
  1718. }
  1719. return tvshows;
  1720. }
  1721. private ObservableCollection<Season> BuildSelectedSeasonList()
  1722. {
  1723. ObservableCollection<Season> seasons = null;
  1724. if (tvSeasons.SelectedItems.Count > 0)
  1725. {
  1726. seasons = new ObservableCollection<Season>();
  1727. foreach (Season s in tvSeasons.SelectedItems)
  1728. seasons.Add(s);
  1729. }
  1730. return seasons;
  1731. }
  1732. private ObservableCollection<Episode> BuildSelectedEpisodeList()
  1733. {
  1734. ObservableCollection<Episode> episodes = null;
  1735. if (tvEpisodes.SelectedItems.Count > 0)
  1736. {
  1737. episodes = new ObservableCollection<Episode>();
  1738. foreach (Episode e in tvEpisodes.SelectedItems)
  1739. episodes.Add(e);
  1740. }
  1741. return episodes;
  1742. }
  1743. private ObservableCollection<Movie> BuildSelectedMovieList()
  1744. {
  1745. ObservableCollection<Movie> movies = null;
  1746. if (lbMovies.SelectedItems.Count > 0)
  1747. {
  1748. movies = new ObservableCollection<Movie>();
  1749. foreach (Movie m in lbMovies.SelectedItems)
  1750. movies.Add(m);
  1751. }
  1752. return movies;
  1753. }
  1754. private ObservableCollection<MovieFile> BuildSelectedMovieFileList()
  1755. {
  1756. ObservableCollection<MovieFile> moviefiles = null;
  1757. if (lbMovieFiles.SelectedItems.Count > 0)
  1758. {
  1759. moviefiles = new ObservableCollection<MovieFile>();
  1760. foreach (MovieFile m in lbMovieFiles.SelectedItems)
  1761. moviefiles.Add(m);
  1762. }
  1763. return moviefiles;
  1764. }
  1765. #endregion
  1766. #region Fetch List Items(TV Series, Movie And Episode) Routines
  1767. #region Fetch TV
  1768. private void btnFetchSelectedTV_Click(object sender, RoutedEventArgs e)
  1769. {
  1770. ShowCancelButtons();
  1771. TVShow ts = SelectedTVShow;
  1772. Thread th = null;
  1773. th = new Thread(delegate()
  1774. {
  1775. if (ts.IsUnsortedEpisodeCollection)
  1776. FetchUnsortedEpisodeCollection(th, ts);
  1777. else
  1778. {
  1779. DecisionType Decison = FetchSelectedTV(ts, false);
  1780. if (Decison == DecisionType.Cancel)
  1781. MetadataCompleted(th, "Canceled.", true);
  1782. else
  1783. TVShowChanged(ts, false);
  1784. }
  1785. MetadataCompleted(th, "Done.", true);
  1786. });
  1787. th.Name = "Fetching " + ts.Name;
  1788. th.SetApartmentState(ApartmentState.STA);
  1789. th.Start();
  1790. tvThreads.Add(th);
  1791. }
  1792. private DecisionType FetchSelectedTV(TVShow ts, bool CanUserSkip)
  1793. {
  1794. SearchResultsDecision SearchDecision = SearchForID(ts, false, ts.Name, null, CanUserSkip, Properties.Settings.Default.forceEnterSearchTerm);
  1795. if (SearchDecision.Decision == DecisionType.Continue)
  1796. {
  1797. MediaScout.TVShowXML selected = tvdb.GetTVShow(SearchDecision.SelectedID);
  1798. if (Properties.Settings.Default.SaveXBMCMeta)
  1799. {
  1800. Message("Saving Metadata as " + selected.GetNFOFile(ts.Folderpath), MediaScout.MediaScoutMessage.MessageType.Task, 0);
  1801. try
  1802. {
  1803. selected.SaveNFO(ts.Folderpath);
  1804. }
  1805. catch (Exception ex)
  1806. {
  1807. Message(ex.Message, MediaScout.MediaScoutMessage.MessageType.Error, 0);
  1808. }
  1809. Message("Done", MediaScout.MediaScoutMessage.MessageType.TaskResult, 0);
  1810. }
  1811. if (Properties.Settings.Default.SaveMyMoviesMeta)
  1812. {
  1813. Message("Saving Metadata as " + selected.GetXMLFile(ts.Folderpath), MediaScout.MediaScoutMessage.MessageType.Task, 0);
  1814. try
  1815. {
  1816. selected.SaveXML(ts.Folderpath);
  1817. }
  1818. catch (Exception ex)
  1819. {
  1820. Message(ex.Message, MediaScout.MediaScoutMessage.MessageType.Error, 0);
  1821. }
  1822. Message("Done", MediaScout.MediaScoutMessage.MessageType.TaskResult, 0);
  1823. }
  1824. ////Fetch the images too
  1825. //if (Properties.Settings.Default.getSeriesPosters)
  1826. //{
  1827. // ChangeSelectedTVorSeasonPoster(ts, null, selected.id, true);
  1828. // ChangeSelectedTVBanner(ts, selected.id, true);
  1829. // ChangeSelectedTVorSeasonBackdrop(ts, null, selected.id, true);
  1830. //}
  1831. }
  1832. return SearchDecision.Decision;
  1833. }
  1834. private void btnFetchSelectedTVs_Click(object sender, RoutedEventArgs e)
  1835. {
  1836. tcTabs.SelectedIndex = LogTabIndex;
  1837. ShowCancelButtons();
  1838. ObservableCollection<TVShow> selectedtvshows = BuildSelectedShowList();
  1839. Thread th = null;
  1840. th = new Thread(delegate()
  1841. {
  1842. foreach(TVShow ts in selectedtvshows)
  1843. {
  1844. if (ts.IsUnsortedEpisodeCollection)
  1845. FetchUnsortedEpisodeCollection(th, ts);
  1846. else
  1847. {
  1848. DecisionType Decision = FetchSelectedTV(ts, true);
  1849. if (Decision == DecisionType.Skip)
  1850. Message("Skipped " + ts.Name, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  1851. else if (Decision == DecisionType.Cancel)
  1852. MetadataCompleted(th, "Canceled.", true);
  1853. else
  1854. TVShowChanged(ts, false);
  1855. }
  1856. }
  1857. MetadataCompleted(th, "Done.", true);
  1858. });
  1859. th.Name = "Fetching Selected TVShows";
  1860. th.SetApartmentState(ApartmentState.STA);
  1861. th.Start();
  1862. tvThreads.Add(th);
  1863. }
  1864. #endregion
  1865. #region Fetch Movie
  1866. private void btnFetchSelectedMovie_Click(object sender, RoutedEventArgs e)
  1867. {
  1868. ShowCancelButtons();
  1869. Movie m = SelectedMovie;
  1870. Thread th = null;
  1871. th = new Thread(delegate()
  1872. {
  1873. DecisionType Decision = FetchSelectedMovie(m, false);
  1874. if (Decision == DecisionType.Cancel)
  1875. MetadataCompleted(th, "Canceled.", true);
  1876. else
  1877. {
  1878. MovieChanged(m, false);
  1879. MetadataCompleted(th, "Done.", true);
  1880. }
  1881. });
  1882. th.Name = "Fetching " + m.Name;
  1883. th.SetApartmentState(ApartmentState.STA);
  1884. th.Start();
  1885. tvThreads.Add(th);
  1886. }
  1887. private DecisionType FetchSelectedMovie(Movie m, bool CanUserSkip)
  1888. {
  1889. if (m.IsUnsortedFileCollection)
  1890. return DecisionType.Skip;
  1891. SearchResultsDecision SearchDecision = SearchForID(m, true, m.Name, null, CanUserSkip, Properties.Settings.Default.forceEnterSearchTerm);
  1892. if (SearchDecision.Decision == DecisionType.Continue)
  1893. {
  1894. //Fetch all the information
  1895. MediaScout.MovieXML selected = tmdb.Get(SearchDecision.SelectedID);
  1896. if (Properties.Settings.Default.SaveXBMCMeta)
  1897. {
  1898. Message("Saving Metadata as " + selected.GetNFOFile(m.Folderpath), MediaScout.MediaScoutMessage.MessageType.Task, 0);
  1899. try
  1900. {
  1901. selected.SaveNFO(m.Folderpath);
  1902. }
  1903. catch (Exception ex)
  1904. {
  1905. Message(ex.Message, MediaScout.MediaScoutMessage.MessageType.Error, 0);
  1906. }
  1907. Message("Done", MediaScout.MediaScoutMessage.MessageType.TaskResult, 0);
  1908. }
  1909. if (Properties.Settings.Default.SaveMyMoviesMeta)
  1910. {
  1911. Message("Saving Metadata as " + selected.GetXMLFile(m.Folderpath), MediaScout.MediaScoutMessage.MessageType.Task, 0);
  1912. try
  1913. {
  1914. selected.SaveXML(m.Folderpath);
  1915. }
  1916. catch (Exception ex)
  1917. {
  1918. Message(ex.Message, MediaScout.MediaScoutMessage.MessageType.Error, 0);
  1919. }
  1920. Message("Done", MediaScout.MediaScoutMessage.MessageType.TaskResult, 0);
  1921. }
  1922. //if (Properties.Settings.Default.getMoviePosters)
  1923. // ChangeSelectedMoviePoster(m, selected.ID, true);
  1924. //if (Properties.Settings.Default.getMovieBackdrops)
  1925. // ChangeSelectedMovieBackdrop(m, selected.ID, true);
  1926. }
  1927. return SearchDecision.Decision;
  1928. }
  1929. private void btnFetchSelectedMovies_Click(object sender, RoutedEventArgs e)
  1930. {
  1931. tcTabs.SelectedIndex = LogTabIndex;
  1932. ShowCancelButtons();
  1933. ObservableCollection<Movie> selectedmovies = BuildSelectedMovieList();
  1934. Thread th = null;
  1935. th = new Thread(delegate()
  1936. {
  1937. foreach (Movie m in selectedmovies)
  1938. {
  1939. DecisionType Decision = FetchSelectedMovie(m, true);
  1940. if (Decision == DecisionType.Skip)
  1941. Message("Skipped " + m.Name, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  1942. else if (Decision == DecisionType.Cancel)
  1943. MetadataCompleted(th, "Canceled.", true);
  1944. else
  1945. MovieChanged(m, false);
  1946. }
  1947. MetadataCompleted(th, "Done.", true);
  1948. });
  1949. th.Name = "Fetching Selected Movies";
  1950. th.SetApartmentState(ApartmentState.STA);
  1951. th.Start();
  1952. tvThreads.Add(th);
  1953. }
  1954. #endregion
  1955. #region Fetch Episode
  1956. private void FetchUnsortedEpisodeCollection(Thread th, TVShow ts)
  1957. {
  1958. foreach (Episode episode in ts.UnsortedEpisodes)
  1959. {
  1960. DecisionType Decision = FetchSelectedEpisode(episode, true);
  1961. if (Decision == DecisionType.Skip)
  1962. Message("Skipped " + episode.Name, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  1963. else if (Decision == DecisionType.Cancel)
  1964. MetadataCompleted(th, "Canceled.", true);
  1965. else
  1966. EpisodeChanged(episode, false);
  1967. }
  1968. }
  1969. private void btnFetchSelectedEpisode_Click(object sender, RoutedEventArgs e)
  1970. {
  1971. ShowCancelButtons();
  1972. Episode episode = SelectedEpisode;
  1973. Thread th = null;
  1974. th = new Thread(delegate()
  1975. {
  1976. DecisionType Decision = FetchSelectedEpisode(episode, false);
  1977. if (Decision == DecisionType.Cancel)
  1978. MetadataCompleted(th, "Canceled.", true);
  1979. else
  1980. {
  1981. EpisodeChanged(episode, false);
  1982. MetadataCompleted(th, "Done.", true);
  1983. }
  1984. });
  1985. th.Name = "Fetcing " + episode.Name;
  1986. th.SetApartmentState(ApartmentState.STA);
  1987. th.Start();
  1988. tvThreads.Add(th);
  1989. }
  1990. private DecisionType FetchSelectedEpisode(Episode e, bool CanUserSkip)
  1991. {
  1992. Season s = e.Season;
  1993. TVShow ts = s.TVShow;
  1994. int eid = MediaScout.GetID.GetSeasonAndEpisodeIDFromFile(e.StrippedFileName).EpisodeID;
  1995. int sid = (ts.IsUnsortedEpisodeCollection) ? MediaScout.GetID.GetSeasonAndEpisodeIDFromFile(e.StrippedFileName).SeasonID : s.GetNum();
  1996. if (eid == -1 || sid == -1)
  1997. {
  1998. // Should prompt for Dialog box asking episode/season number instead of Messagebox
  1999. MessageBox.Show("Unable to Get Episode/Season Number from File");
  2000. return DecisionType.Skip;
  2001. }
  2002. String SearchTerm = ts.IsUnsortedEpisodeCollection ? ts.GetSearchTerm(e.StrippedFileName) : null;
  2003. String SearchObjectName = ts.IsUnsortedEpisodeCollection ? e.Name : ts.Name;
  2004. SearchResultsDecision SearchDecision = SearchForID(ts, false, SearchObjectName, SearchTerm, false, Properties.Settings.Default.forceEnterSearchTerm);
  2005. if (SearchDecision.Decision == DecisionType.Continue)
  2006. {
  2007. String id = SearchDecision.SelectedID;
  2008. if (!String.IsNullOrEmpty(id))
  2009. {
  2010. MediaScout.EpisodeXML selected = tvdb.GetEpisode(id, sid.ToString(), eid.ToString());
  2011. #region Save Metadata
  2012. if (Properties.Settings.Default.SaveXBMCMeta)
  2013. {
  2014. Message("Saving Metadata as " + selected.GetNFOFile(s.Folderpath, e.StrippedFileName), MediaScout.MediaScoutMessage.MessageType.Task, 0);
  2015. try
  2016. {
  2017. selected.SaveNFO(s.Folderpath, e.StrippedFileName);
  2018. }
  2019. catch (Exception ex)
  2020. {
  2021. Message(ex.Message, MediaScout.MediaScoutMessage.MessageType.Error, 0);
  2022. }
  2023. Message("Done", MediaScout.MediaScoutMessage.MessageType.TaskResult, 0);
  2024. }
  2025. if (Properties.Settings.Default.SaveMyMoviesMeta)
  2026. {
  2027. if(!Directory.Exists(s.MetadataFolderPath))
  2028. MediaScout.IOFunctions.CreateHiddenFolder(s.MetadataFolderPath);
  2029. Message("Saving Metadata as " + selected.GetXMLFile(s.Folderpath, e.StrippedFileName), MediaScout.MediaScoutMessage.MessageType.Task, 0);
  2030. try
  2031. {
  2032. selected.SaveXML(s.Folderpath, e.StrippedFileName);
  2033. }
  2034. catch (Exception ex)
  2035. {
  2036. Message(ex.Message, MediaScout.MediaScoutMessage.MessageType.Error, 0);
  2037. }
  2038. Message("Done", MediaScout.MediaScoutMessage.MessageType.TaskResult, 0);
  2039. }
  2040. #endregion
  2041. #region Save Image
  2042. if (!String.IsNullOrEmpty(selected.PosterUrl))
  2043. {
  2044. MediaScout.Posters p = new MediaScout.Posters();
  2045. p.Poster = selected.PosterUrl;
  2046. try
  2047. {
  2048. if (Properties.Settings.Default.SaveXBMCMeta)
  2049. {
  2050. Message("Saving Episode Poster as " + selected.GetXBMCThumbFilename(e.StrippedFileName), MediaScout.MediaScoutMessage.MessageType.Task, 0);
  2051. String filename = selected.GetXBMCThumbFile(e.Season.Folderpath, e.StrippedFileName);
  2052. p.SavePoster(filename);
  2053. Message("Done", MediaScout.MediaScoutMessage.MessageType.TaskResult, 0);
  2054. }
  2055. if (Properties.Settings.Default.SaveMyMoviesMeta)
  2056. {
  2057. Message("Saving Episode Poster as " + selected.GetMyMoviesThumbFilename(), MediaScout.MediaScoutMessage.MessageType.Task, 0);
  2058. String filename = selected.GetMyMoviesThumbFile(e.Season.Folderpath);
  2059. p.SavePoster(filename);
  2060. Message("Done", MediaScout.MediaScoutMessage.MessageType.TaskResult, 0);
  2061. }
  2062. }
  2063. catch (Exception ex)
  2064. {
  2065. Message(ex.Message, MediaScout.MediaScoutMessage.MessageType.TaskError, 0);
  2066. }
  2067. }
  2068. #endregion
  2069. }
  2070. }
  2071. return SearchDecision.Decision;
  2072. }
  2073. private void btnFetchSelectedEpisodes_Click(object sender, RoutedEventArgs e)
  2074. {
  2075. tcTabs.SelectedIndex = LogTabIndex;
  2076. ShowCancelButtons();
  2077. ObservableCollection<Episode> selectedepisodes = BuildSelectedEpisodeList();
  2078. Thread th = null;
  2079. th = new Thread(delegate()
  2080. {
  2081. foreach (Episode episode in selectedepisodes)
  2082. {
  2083. DecisionType Decision = FetchSelectedEpisode(episode, true);
  2084. if (Decision == DecisionType.Skip)
  2085. Message("Skipped " + episode.Name, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  2086. else if (Decision == DecisionType.Cancel)
  2087. MetadataCompleted(th, "Canceled.", true);
  2088. else
  2089. EpisodeChanged(episode, false);
  2090. }
  2091. MetadataCompleted(th, "Done.", true);
  2092. });
  2093. th.Name = "Fetcing Selected Episodes";
  2094. th.SetApartmentState(ApartmentState.STA);
  2095. th.Start();
  2096. tvThreads.Add(th);
  2097. }
  2098. #endregion
  2099. #region Fetch Actor
  2100. private void btnFetchSelectedActorThumb_Click(object sender, RoutedEventArgs e)
  2101. {
  2102. List<MediaScout.Person> Persons = null;
  2103. try
  2104. {
  2105. Persons = (SelectedPerson.IsMovieActor) ? tmdb.GetActors(SelectedMovie.ID) : tvdb.GetActors(SelectedTVShow.ID);
  2106. }
  2107. catch (Exception ex)
  2108. {
  2109. MessageBox.Show(ex.Message);
  2110. }
  2111. if (Persons != null & Persons.Count != 0)
  2112. {
  2113. foreach (MediaScout.Person p in Persons)
  2114. {
  2115. if (SelectedPerson.Name == p.Name)
  2116. {
  2117. //SelectedPerson.Role = p.Role;
  2118. #region Save Actors Thumb
  2119. if (Properties.Settings.Default.SaveXBMCMeta)
  2120. {
  2121. Message("Saving " + p.Name + " Image in \\" + p.GetXBMCDirectory(), MediaScout.MediaScoutMessage.MessageType.Task, 0);
  2122. String ActorsDir = SelectedPerson.XBMCFolderPath;
  2123. if (!Directory.Exists(ActorsDir))
  2124. MediaScout.IOFunctions.CreateHiddenFolder(ActorsDir);
  2125. if (!String.IsNullOrEmpty(p.Thumb))
  2126. {
  2127. String Filename = p.GetXBMCFilename();
  2128. String Filepath = ActorsDir + "\\" + Filename;
  2129. p.SaveThumb(Filepath);
  2130. Message("Done", MediaScout.MediaScoutMessage.MessageType.TaskResult, 0);
  2131. }
  2132. else
  2133. Message("Image Not Found", MediaScout.MediaScoutMessage.MessageType.TaskError, 0);
  2134. }
  2135. if (Properties.Settings.Default.SaveMyMoviesMeta)
  2136. {
  2137. Message("Saving" + p.Name + " Image in \\ImagesByName\\" + p.GetMyMoviesDirectory(), MediaScout.MediaScoutMessage.MessageType.Task, 0);
  2138. if (Directory.Exists(Properties.Settings.Default.ImagesByNameLocation))
  2139. {
  2140. if (!String.IsNullOrEmpty(p.Thumb))
  2141. {
  2142. String ActorsDir = SelectedPerson.MyMoviesFolderPath + "\\" + p.GetMyMoviesDirectory();
  2143. String Filepath = ActorsDir + "\\" + p.GetMyMoviesFilename();
  2144. if (!Directory.Exists(ActorsDir))
  2145. Directory.CreateDirectory(ActorsDir);
  2146. p.SaveThumb(Filepath);
  2147. Message("Done", MediaScout.MediaScoutMessage.MessageType.TaskResult, 0);
  2148. }
  2149. else
  2150. Message("Image Not Found", MediaScout.MediaScoutMessage.MessageType.TaskError, 0);
  2151. }
  2152. else
  2153. Message("ImagesByName Location Not Defined", MediaScout.MediaScoutMessage.MessageType.TaskError, 0);
  2154. }
  2155. #endregion
  2156. if (SelectedPerson.IsMovieActor)
  2157. SelectedMovie.LoadActorsThumb(SelectedPerson);
  2158. else
  2159. SelectedTVShow.LoadActorsThumb(SelectedPerson);
  2160. break;
  2161. }
  2162. }
  2163. }
  2164. }
  2165. #endregion
  2166. #endregion
  2167. #region Strip (TV, Sesaons, And Episode) Routines
  2168. #region Strip Routines
  2169. private void StripFile(String name, String path, int level)
  2170. {
  2171. if (File.Exists(path))
  2172. {
  2173. Message("Deleting " + name, MediaScout.MediaScoutMessage.MessageType.Task, level);
  2174. try
  2175. {
  2176. Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(path, Microsoft.VisualBasic.FileIO.UIOption.OnlyErrorDialogs, Microsoft.VisualBasic.FileIO.RecycleOption.SendToRecycleBin);
  2177. //File.Delete(path);
  2178. }
  2179. catch (Exception ex)
  2180. {
  2181. Message(ex.Message, MediaScout.MediaScoutMessage.MessageType.TaskError, level);
  2182. }
  2183. Message("Done", MediaScout.MediaScoutMessage.MessageType.TaskResult, level);
  2184. }
  2185. }
  2186. private void StripDir(String name, String path, int level)
  2187. {
  2188. if (Directory.Exists(path))
  2189. {
  2190. Message("Deleting " + name, MediaScout.MediaScoutMessage.MessageType.Task, level);
  2191. try
  2192. {
  2193. Microsoft.VisualBasic.FileIO.FileSystem.DeleteDirectory(path, Microsoft.VisualBasic.FileIO.UIOption.OnlyErrorDialogs, Microsoft.VisualBasic.FileIO.RecycleOption.SendToRecycleBin);
  2194. //Directory.Move(path, true);
  2195. }
  2196. catch (Exception ex)
  2197. {
  2198. Message(ex.Message, MediaScout.MediaScoutMessage.MessageType.TaskError, level);
  2199. }
  2200. Message("Done", MediaScout.MediaScoutMessage.MessageType.TaskResult, level);
  2201. }
  2202. }
  2203. #endregion
  2204. #region Strip TV Routines
  2205. private void btnStripSelectedTV_Click(object sender, RoutedEventArgs e)
  2206. {
  2207. TVShow ts = SelectedTVShow;
  2208. String msg = "Are you sure you want to delete all Metadata and images for this series?";
  2209. if (MessageBox.Show(msg, ts.Name, MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
  2210. {
  2211. StripSelectedTV(ts);
  2212. Message("Done.", MediaScout.MediaScoutMessage.MessageType.Task, 0);
  2213. }
  2214. }
  2215. private void StripSelectedTV(TVShow ts)
  2216. {
  2217. if (ts.IsUnsortedEpisodeCollection)
  2218. {
  2219. btnStripAllEpisodes_Click(null, null);
  2220. return;
  2221. }
  2222. Message("Delete all of the Metadata for series " + ts.Name, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  2223. String path, name;
  2224. name = "folder.jpg";
  2225. path = ts.Folderpath + "\\" + name;
  2226. StripFile(name, path, 1);
  2227. name = "banner.jpg";
  2228. path = ts.Folderpath + "\\" + name;
  2229. StripFile(name, path, 1);
  2230. if (Properties.Settings.Default.SaveMyMoviesMeta)
  2231. {
  2232. name = "backdrop.jpg";
  2233. path = ts.Folderpath + "\\" + name;
  2234. StripFile(name, path, 1);
  2235. name = "series.xml";
  2236. path = ts.Folderpath + "\\" + name;
  2237. StripFile(name, path, 1);
  2238. }
  2239. if (Properties.Settings.Default.SaveXBMCMeta)
  2240. {
  2241. name = "fanart.jpg";
  2242. path = ts.Folderpath + "\\" + name;
  2243. StripFile(name, path, 1);
  2244. name = "tvshow.nfo";
  2245. path = ts.Folderpath + "\\" + name;
  2246. StripFile(name, path, 1);
  2247. name = ".actors";
  2248. path = System.IO.Path.Combine(ts.Folderpath, name);
  2249. StripDir(name, path, 1);
  2250. }
  2251. if (ts.Actors != null)
  2252. for (int i = 0; i < ts.Actors.Count; i++)
  2253. StripSelectedActorThumb(ts.Actors[i]);
  2254. if (ts.Seasons != null)
  2255. for (int i = 0; i < ts.Seasons.Count; i++)
  2256. StripSelectedSeason(ts.Seasons[i]);
  2257. TVShowChanged(ts, false);
  2258. }
  2259. private void btnStripSelectedTVs_Click(object sender, RoutedEventArgs e)
  2260. {
  2261. String msg = "Are you sure you want to delete all Metadata and images for selected TV Shows?";
  2262. if (MessageBox.Show(msg, "TV Shows", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
  2263. StripMultipleTV(BuildSelectedShowList());
  2264. }
  2265. private void StripMultipleTV(ObservableCollection<TVShow> tvshows)
  2266. {
  2267. tcTabs.SelectedIndex = LogTabIndex;
  2268. Thread th = null;
  2269. th = new Thread(delegate()
  2270. {
  2271. maxvalue += tvshows.Count;
  2272. for (int i = 0; i < tvshows.Count; i++)
  2273. {
  2274. StripSelectedTV(tvshows[i]);
  2275. SetTasbkBarProgressValue(++currentvalue);
  2276. }
  2277. //ReloadTVShows();
  2278. MetadataCompleted(th, "Done.", true);
  2279. });
  2280. th.Name = "Stripping TV Shows";
  2281. th.SetApartmentState(ApartmentState.STA);
  2282. th.Start();
  2283. tvThreads.Add(th);
  2284. }
  2285. private void btnStripAllTV_Click(object sender, RoutedEventArgs e)
  2286. {
  2287. String msg = "Are you sure you want to delete all Metadata and images for all TV Shows?";
  2288. if (MessageBox.Show(msg, "TV Shows", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
  2289. StripMultipleTV(tvshows);
  2290. }
  2291. #endregion
  2292. #region Strip Season Routines
  2293. private void btnStripSelectedSeason_Click(object sender, RoutedEventArgs e)
  2294. {
  2295. Season s = SelectedSeason;
  2296. String msg = "Are you sure you want to delete all Metadata and images for this season?";
  2297. if (MessageBox.Show(msg, s.Name, MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
  2298. {
  2299. StripSelectedSeason(s);
  2300. Message("Done.", MediaScout.MediaScoutMessage.MessageType.Task, 1);
  2301. }
  2302. }
  2303. private void StripSelectedSeason(Season s)
  2304. {
  2305. Message("Deleting Metadata for " + s.Name, MediaScout.MediaScoutMessage.MessageType.Task, 1);
  2306. String path, name;
  2307. name = "folder.jpg";
  2308. path = s.Folderpath + "\\" + name;
  2309. StripFile(name, path, 2);
  2310. if (Properties.Settings.Default.SaveMyMoviesMeta)
  2311. {
  2312. name = "backdrop.jpg";
  2313. path = s.Folderpath + "\\" + name;
  2314. StripFile(name, path, 2);
  2315. name = "metadata";
  2316. path = System.IO.Path.Combine(s.Folderpath, name);
  2317. StripDir(name, path, 2);
  2318. }
  2319. if (Properties.Settings.Default.SaveXBMCMeta)
  2320. {
  2321. name = "fanart.jpg";
  2322. path = s.Folderpath + "\\" + name;
  2323. StripFile(name, path, 2);
  2324. name = ".actors";
  2325. path = System.IO.Path.Combine(s.Folderpath, name);
  2326. StripDir(name, path, 2);
  2327. }
  2328. if (s.Episodes != null)
  2329. for (int i = 0; i < s.Episodes.Count; i++)
  2330. StripSelectedEpisode(s.Episodes[i]);
  2331. SeasonChanged(s, false);
  2332. }
  2333. private void btnStripSelectedSeasons_Click(object sender, RoutedEventArgs e)
  2334. {
  2335. TVShow ts = SelectedTVShow;
  2336. String msg = "Are you sure you want to delete all Metadata and images fo selected seasons?";
  2337. if (MessageBox.Show(msg, ts.Name, MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
  2338. StripMultipleSeason(BuildSelectedSeasonList());
  2339. }
  2340. private void StripMultipleSeason(ObservableCollection<Season> seasons)
  2341. {
  2342. tcTabs.SelectedIndex = LogTabIndex;
  2343. ShowCancelButtons();
  2344. Thread th = null;
  2345. th = new Thread(delegate()
  2346. {
  2347. maxvalue += seasons.Count;
  2348. for (int i = 0; i < seasons.Count; i++)
  2349. {
  2350. StripSelectedSeason(seasons[i]);
  2351. SetTasbkBarProgressValue(++currentvalue);
  2352. }
  2353. MetadataCompleted(th, "Done.", true);
  2354. });
  2355. th.Name = "Stripping Seasons";
  2356. th.SetApartmentState(ApartmentState.STA);
  2357. th.Start();
  2358. tvThreads.Add(th);
  2359. }
  2360. private void btnStripAllSeasons_Click(object sender, RoutedEventArgs e)
  2361. {
  2362. TVShow ts = SelectedTVShow;
  2363. String msg = "Are you sure you want to delete all Metadata and images fo all seasons?";
  2364. if (MessageBox.Show(msg, ts.Name, MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
  2365. StripMultipleSeason(ts.Seasons);
  2366. }
  2367. #endregion
  2368. #region Strip Episode Routines
  2369. private void btnStripSelectedEpisode_Click(object sender, RoutedEventArgs e)
  2370. {
  2371. Episode Episode = SelectedEpisode;
  2372. String msg = "Are you sure you want to delete all Metadata and images for this episode?";
  2373. if (MessageBox.Show(msg, Episode.Name, MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
  2374. {
  2375. StripSelectedEpisode(Episode);
  2376. Message("Done.", MediaScout.MediaScoutMessage.MessageType.Task, 2);
  2377. }
  2378. }
  2379. private void StripSelectedEpisode(Episode e)
  2380. {
  2381. String path, name;
  2382. Message("Stripping Metadata for " + e.Name, MediaScout.MediaScoutMessage.MessageType.Task, 2);
  2383. if (Properties.Settings.Default.SaveMyMoviesMeta)
  2384. {
  2385. name = e.StrippedFileName + ".xml";
  2386. path = e.Season.MetadataFolderPath + "\\" + name;
  2387. StripFile(name, path, 3);
  2388. name = e.PosterFilename;
  2389. path = e.Season.MetadataFolderPath + "\\" + name;
  2390. StripFile(name, path, 3);
  2391. }
  2392. if (Properties.Settings.Default.SaveXBMCMeta)
  2393. {
  2394. name = e.StrippedFileName + ".nfo";
  2395. path = e.Season.Folderpath + "\\" + name;
  2396. StripFile(name, path, 3);
  2397. name = e.StrippedFileName + ".tbn";
  2398. path = e.Season.Folderpath + "\\" + name;
  2399. StripFile(name, path, 3);
  2400. }
  2401. EpisodeChanged(e, false);
  2402. }
  2403. private void btnStripSelectedEpisodes_Click(object sender, RoutedEventArgs e)
  2404. {
  2405. Season s = SelectedSeason;
  2406. String msg = "Are you sure you want to delete all Metadata and images for all episode?";
  2407. if (MessageBox.Show(msg, s.Name, MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
  2408. StripMultipleEpisodes(BuildSelectedEpisodeList());
  2409. }
  2410. private void StripMultipleEpisodes(ObservableCollection<Episode> episodes)
  2411. {
  2412. tcTabs.SelectedIndex = LogTabIndex;
  2413. ShowCancelButtons();
  2414. Thread th = null;
  2415. th = new Thread(delegate()
  2416. {
  2417. maxvalue += episodes.Count;
  2418. for (int i = 0; i < episodes.Count; i++)
  2419. {
  2420. StripSelectedEpisode(episodes[i]);
  2421. SetTasbkBarProgressValue(++currentvalue);
  2422. }
  2423. MetadataCompleted(th, "Done.", true);
  2424. });
  2425. th.Name = "Stripping Episodes";
  2426. th.SetApartmentState(ApartmentState.STA);
  2427. th.Start();
  2428. tvThreads.Add(th);
  2429. }
  2430. private void btnStripAllEpisodes_Click(object sender, RoutedEventArgs e)
  2431. {
  2432. Season s = SelectedSeason;
  2433. String msg = "Are you sure you want to delete all Metadata and images for all episode?";
  2434. if (MessageBox.Show(msg, s.Name, MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
  2435. StripMultipleEpisodes(s.Episodes);
  2436. }
  2437. #endregion
  2438. #region Strip Movie Routines
  2439. private void btnStripSelectedMovie_Click(object sender, RoutedEventArgs e)
  2440. {
  2441. Movie m = SelectedMovie;
  2442. String msg = "Are you sure you want to delete all Metadata and images for this Movie?";
  2443. if (MessageBox.Show(msg, m.Name, MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
  2444. {
  2445. StripSelectedMovie(m);
  2446. Message("Done.", MediaScout.MediaScoutMessage.MessageType.Task, 0);
  2447. }
  2448. else
  2449. Debug.WriteLine("Leaving Metadata alone.");
  2450. }
  2451. private void StripSelectedMovie(Movie m)
  2452. {
  2453. if (m.IsUnsortedFileCollection)
  2454. {
  2455. btnStripAllMovieFiles_Click(null, null);
  2456. return;
  2457. }
  2458. Message("Deleting all of the Metadata for movie " + m.Name, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  2459. String path, name;
  2460. name = "folder.jpg";
  2461. path = m.Folderpath + "\\" + name;
  2462. StripFile(name, path, 1);
  2463. if (Properties.Settings.Default.SaveMyMoviesMeta)
  2464. {
  2465. name = "backdrop.jpg";
  2466. path = m.Folderpath + "\\" + name;
  2467. StripFile(name, path, 1);
  2468. name = "mymovies.xml";
  2469. path = m.Folderpath + "\\" + name;
  2470. StripFile(name, path, 1);
  2471. }
  2472. if (Properties.Settings.Default.SaveXBMCMeta)
  2473. {
  2474. name = "fanart.jpg";
  2475. path = m.Folderpath + "\\" + name;
  2476. StripFile(name, path, 1);
  2477. name = "movie.nfo";
  2478. path = m.Folderpath + "\\" + name;
  2479. StripFile(name, path, 1);
  2480. name = ".actors";
  2481. path = System.IO.Path.Combine(m.Folderpath, name);
  2482. StripDir(name, path, 1);
  2483. }
  2484. if (m.Actors != null)
  2485. for (int i = 0; i < m.Actors.Count; i++)
  2486. StripSelectedActorThumb(m.Actors[i]);
  2487. if (m.Files != null)
  2488. for (int i = 0; i < m.Files.Count; i++)
  2489. StripSelectedMovieFile(m.Files[i]);
  2490. MovieChanged(m, false);
  2491. }
  2492. private void btnStripSelectedMovies_Click(object sender, RoutedEventArgs e)
  2493. {
  2494. String msg = "Are you sure you want to delete all Metadata and images for selected Movies?";
  2495. if (MessageBox.Show(msg, "Movies", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
  2496. StripMultipleMovies(BuildSelectedMovieList());
  2497. }
  2498. private void StripMultipleMovies(ObservableCollection<Movie> movies)
  2499. {
  2500. tcTabs.SelectedIndex = LogTabIndex;
  2501. ShowCancelButtons();
  2502. Thread th = null;
  2503. th = new Thread(delegate()
  2504. {
  2505. maxvalue += movies.Count;
  2506. for (int i = 0; i < movies.Count; i++)
  2507. {
  2508. StripSelectedMovie(movies[i]);
  2509. SetTasbkBarProgressValue(++currentvalue);
  2510. }
  2511. //ReloadMovies();
  2512. MetadataCompleted(th, "Done.", true);
  2513. });
  2514. th.Name = "Stripping Movies";
  2515. th.SetApartmentState(ApartmentState.STA);
  2516. th.Start();
  2517. tvThreads.Add(th);
  2518. }
  2519. private void btnStripAllMovie_Click(object sender, RoutedEventArgs e)
  2520. {
  2521. String msg = "Are you sure you want to delete all Metadata and images for all Movies?";
  2522. if (MessageBox.Show(msg, "Movies", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
  2523. StripMultipleMovies(movies);
  2524. }
  2525. #endregion
  2526. #region Strip Movie File Routines
  2527. private void btnStripSelectedMovieFile_Click(object sender, RoutedEventArgs e)
  2528. {
  2529. MovieFile mf = SelectedMovieFile;
  2530. String msg = "Are you sure you want to delete all Metadata and images for this Movie File?";
  2531. if (MessageBox.Show(msg, mf.Name, MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
  2532. {
  2533. StripSelectedMovieFile(mf);
  2534. Message("Done.", MediaScout.MediaScoutMessage.MessageType.Task, 0);
  2535. }
  2536. }
  2537. private void StripSelectedMovieFile(MovieFile mf)
  2538. {
  2539. String path, name;
  2540. if (Properties.Settings.Default.SaveXBMCMeta)
  2541. {
  2542. name = mf.StrippedFileName + ".nfo";
  2543. path = mf.Movie.Folderpath + "\\" + name;
  2544. StripFile(name, path, 2);
  2545. name = mf.StrippedFileName + ".tbn";
  2546. path = mf.Movie.Folderpath + "\\" + name;
  2547. StripFile(name, path, 2);
  2548. }
  2549. MovieFileChanged(mf, false);
  2550. }
  2551. private void btnStripSelectedMovieFiles_Click(object sender, RoutedEventArgs e)
  2552. {
  2553. Movie m = SelectedMovie;
  2554. String msg = "Are you sure you want to delete all Metadata and images for selected Movie Files?";
  2555. if (MessageBox.Show(msg, m.Name, MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
  2556. StripMultipleMovieFiles(BuildSelectedMovieFileList());
  2557. }
  2558. private void StripMultipleMovieFiles(ObservableCollection<MovieFile> files)
  2559. {
  2560. tcTabs.SelectedIndex = LogTabIndex;
  2561. ShowCancelButtons();
  2562. Thread th = null;
  2563. th = new Thread(delegate()
  2564. {
  2565. maxvalue += movies.Count;
  2566. for (int i = 0; i < files.Count; i++)
  2567. {
  2568. StripSelectedMovieFile(files[i]);
  2569. SetTasbkBarProgressValue(++currentvalue);
  2570. }
  2571. MetadataCompleted(th, "Done.", true);
  2572. });
  2573. th.Name = "Stripping Movie Files";
  2574. th.SetApartmentState(ApartmentState.STA);
  2575. th.Start();
  2576. tvThreads.Add(th);
  2577. }
  2578. private void btnStripAllMovieFiles_Click(object sender, RoutedEventArgs e)
  2579. {
  2580. Movie m = SelectedMovie;
  2581. String msg = "Are you sure you want to delete all Metadata and images for all Movie Files?";
  2582. if (MessageBox.Show(msg, m.Name, MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
  2583. StripMultipleMovieFiles(m.Files);
  2584. }
  2585. #endregion
  2586. #region Strip Actor Routines
  2587. private void btnStripSelectedActorThumb_Click(object sender, RoutedEventArgs e)
  2588. {
  2589. Person p = SelectedPerson;
  2590. String msg = "Are you sure you want to delete images for this actor?";
  2591. if (MessageBox.Show(msg, p.Name, MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
  2592. {
  2593. StripSelectedActorThumb(p);
  2594. Message("Done.", MediaScout.MediaScoutMessage.MessageType.Task, 0);
  2595. }
  2596. }
  2597. private void StripSelectedActorThumb(Person p)
  2598. {
  2599. String path, name;
  2600. if (Properties.Settings.Default.SaveMyMoviesMeta)
  2601. {
  2602. name = p.Name + "\\folder.jpg";
  2603. path = p.MyMoviesFolderPath + "\\" + name;
  2604. StripFile(name, path, 2);
  2605. name = p.Name;
  2606. path = System.IO.Path.Combine(p.MyMoviesFolderPath, name);
  2607. StripDir(name, path, 2);
  2608. }
  2609. if (Properties.Settings.Default.SaveXBMCMeta)
  2610. {
  2611. name = p.Name.Replace(" ", "_") + ".jpg";
  2612. path = p.XBMCFolderPath + "\\" + name;
  2613. StripFile(name, path, 2);
  2614. }
  2615. ActorThumbChanged(p);
  2616. }
  2617. #endregion
  2618. #endregion
  2619. #region Processing (TV, Seasons, Episode, Movie and Movie File) Routines
  2620. #region MediaScout Routines
  2621. private MediaScout.TVScout SetTVScout()
  2622. {
  2623. MediaScout.TVScoutOptions Options = new MediaScout.TVScoutOptions()
  2624. {
  2625. GetSeriesPosters = Properties.Settings.Default.getSeriesPosters,
  2626. GetSeasonPosters = Properties.Settings.Default.getSeasonPosters,
  2627. GetEpisodePosters = Properties.Settings.Default.getEpisodePosters,
  2628. MoveFiles = Properties.Settings.Default.moveTVFiles,
  2629. SeasonFolderName = Properties.Settings.Default.SeasonFolderName,
  2630. SpecialsFolderName = Properties.Settings.Default.SpecialsFolderName,
  2631. DownloadAllPosters = Properties.Settings.Default.downloadAllTVPosters,
  2632. DownloadAllBackdrops = Properties.Settings.Default.downloadAllTVBackdrops,
  2633. DownloadAllBanners = Properties.Settings.Default.downloadAllTVBanners,
  2634. DownloadAllSeasonPosters = Properties.Settings.Default.downloadAllTVSeasonPosters,
  2635. DownloadAllSeasonBackdrops = Properties.Settings.Default.downloadAllTVSeasonBackdrops,
  2636. SaveActors = Properties.Settings.Default.SaveTVActors,
  2637. RenameFiles = Properties.Settings.Default.renameTVFiles,
  2638. RenameFormat = Properties.Settings.Default.TVfileformat,
  2639. SeasonNumZeroPadding = int.Parse(Properties.Settings.Default.SeasonNumZeroPadding),
  2640. EpisodeNumZeroPadding = int.Parse(Properties.Settings.Default.EpisodeNumZeroPadding),
  2641. AllowedFileTypes = AllowedFileTypes.ToArray(),
  2642. AllowedSubtitles = AllowedSubtitleTypes.ToArray(),
  2643. ForceUpdate = Properties.Settings.Default.forceUpdate,
  2644. overwrite = Properties.Settings.Default.overwriteFiles,
  2645. SaveXBMCMeta = Properties.Settings.Default.SaveXBMCMeta,
  2646. SaveMyMoviesMeta = Properties.Settings.Default.SaveMyMoviesMeta,
  2647. FilenameReplaceChar = Properties.Settings.Default.FilenameReplaceChar
  2648. };
  2649. TVScout = new MediaScout.TVScout(Options, Message, Properties.Settings.Default.ImagesByNameLocation);
  2650. return TVScout;
  2651. }
  2652. private MediaScout.MovieScout SetMovieScout()
  2653. {
  2654. MediaScout.MovieScoutOptions Options = new MediaScout.MovieScoutOptions()
  2655. {
  2656. GetMoviePosters = Properties.Settings.Default.getMoviePosters,
  2657. GetMovieFilePosters = Properties.Settings.Default.getMovieFilePosters,
  2658. MoveFiles = Properties.Settings.Default.moveMovieFiles,
  2659. DownloadAllPosters = Properties.Settings.Default.downloadAllMoviePosters,
  2660. DownloadAllBackdrops = Properties.Settings.Default.downloadAllMovieBackdrops,
  2661. SaveActors = Properties.Settings.Default.SaveMovieActors,
  2662. RenameFiles = Properties.Settings.Default.renameMovieFiles,
  2663. FileRenameFormat = Properties.Settings.Default.Moviefileformat,
  2664. DirRenameFormat = Properties.Settings.Default.MovieDirformat,
  2665. AllowedFileTypes = AllowedFileTypes.ToArray(),
  2666. AllowedSubtitles = AllowedSubtitleTypes.ToArray(),
  2667. ForceUpdate = Properties.Settings.Default.forceUpdate,
  2668. overwrite = Properties.Settings.Default.overwriteFiles,
  2669. SaveXBMCMeta = Properties.Settings.Default.SaveXBMCMeta,
  2670. SaveMyMoviesMeta = Properties.Settings.Default.SaveMyMoviesMeta,
  2671. FilenameReplaceChar = Properties.Settings.Default.FilenameReplaceChar
  2672. };
  2673. MovieScout = new MediaScout.MovieScout(Options, Message, Properties.Settings.Default.ImagesByNameLocation);
  2674. return MovieScout;
  2675. }
  2676. #endregion
  2677. #region Process TV Routines
  2678. private void btnProcessSelectedTV_Click(object sender, RoutedEventArgs e)
  2679. {
  2680. TVShow ts = SelectedTVShow;
  2681. tcTabs.SelectedIndex = LogTabIndex;
  2682. ShowCancelButtons();
  2683. TVScout = SetTVScout();
  2684. if (ts.IsUnsortedEpisodeCollection)
  2685. //ProcessUnsortedEpisodeCollection(th, ts);
  2686. ProcessMultipleEpisodes(ts.Seasons[0].Episodes);
  2687. else
  2688. {
  2689. Thread th = null;
  2690. th = new Thread(delegate()
  2691. {
  2692. DecisionType Decision = ProcessingSelectedTV(ts, false);
  2693. if (Decision == DecisionType.Cancel)
  2694. MetadataCompleted(th, "Canceled.", true);
  2695. else
  2696. TVShowChanged(ts, ts.IsDeleted);
  2697. MetadataCompleted(th, "Done.", true);
  2698. });
  2699. th.Name = "Processing " + ts.Name;
  2700. th.SetApartmentState(ApartmentState.STA);
  2701. th.Start();
  2702. tvThreads.Add(th);
  2703. }
  2704. }
  2705. private DecisionType ProcessingSelectedTV(TVShow ts, bool CanUserSkip)
  2706. {
  2707. Message("Scanning folder " + ts.Name, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  2708. SearchResultsDecision SearchDecision = SearchForID(ts, false, ts.Name, null, CanUserSkip, Properties.Settings.Default.forceEnterSearchTerm);
  2709. if (SearchDecision.Decision == DecisionType.Continue)
  2710. {
  2711. MediaScout.TVShowXML selected = null;
  2712. try
  2713. {
  2714. selected = tvdb.GetTVShow(SearchDecision.SelectedID);
  2715. }
  2716. catch (Exception ex)
  2717. {
  2718. Message(ex.Message, MediaScout.MediaScoutMessage.MessageType.Error, 0);
  2719. }
  2720. if (selected != null)
  2721. {
  2722. TVScout.series = selected;
  2723. String name = TVScout.ProcessDirectory(ts.Folderpath);
  2724. if (name != null)
  2725. {
  2726. if (name.Substring(0, 2) != "d:")
  2727. {
  2728. ts.Name = name;
  2729. ts.Folderpath = new DirectoryInfo(ts.Folderpath).Parent.FullName + "\\" + name;
  2730. }
  2731. else
  2732. ts.IsDeleted = true;
  2733. }
  2734. }
  2735. }
  2736. return SearchDecision.Decision;
  2737. }
  2738. private void btnProcessSelectedTVs_Click(object sender, RoutedEventArgs e)
  2739. {
  2740. ProcessMultipleTVs(BuildSelectedShowList());
  2741. }
  2742. private void ProcessMultipleTVs(ObservableCollection<TVShow> tvshows)
  2743. {
  2744. tcTabs.SelectedIndex = LogTabIndex;
  2745. ShowCancelButtons();
  2746. TVScout = SetTVScout();
  2747. Thread th = null;
  2748. th = new Thread(delegate()
  2749. {
  2750. maxvalue += tvshows.Count;
  2751. foreach(TVShow ts in tvshows)
  2752. {
  2753. if (ts.IsUnsortedEpisodeCollection)
  2754. //ProcessUnsortedEpisodeCollection(th, ts);
  2755. ProcessMultipleEpisodes(ts.Seasons[0].Episodes);
  2756. else
  2757. {
  2758. DecisionType Decision = ProcessingSelectedTV(ts, true);
  2759. if (Decision == DecisionType.Skip)
  2760. Message("Skipped " + ts.Name, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  2761. else if (Decision == DecisionType.Cancel)
  2762. MetadataCompleted(th, "Canceled.", true);
  2763. else
  2764. TVShowChanged(ts, false);
  2765. }
  2766. SetTasbkBarProgressValue(++currentvalue);
  2767. }
  2768. for (int i = 0; i < tvshows.Count; i++)
  2769. {
  2770. if (tvshows[i].IsDeleted)
  2771. {
  2772. TVShowChanged(tvshows[i], true);
  2773. i--;
  2774. }
  2775. }
  2776. MetadataCompleted(th, "Done.", true);
  2777. });
  2778. th.Name = "Processing TVShows";
  2779. th.SetApartmentState(ApartmentState.STA);
  2780. th.Start();
  2781. tvThreads.Add(th);
  2782. }
  2783. private void btnProcessAllTV_Click(object sender, RoutedEventArgs e)
  2784. {
  2785. ProcessMultipleTVs(tvshows);
  2786. }
  2787. #endregion
  2788. #region Process Season Routines
  2789. private void btnProcessSelectedSeason_Click(object sender, RoutedEventArgs e)
  2790. {
  2791. tcTabs.SelectedIndex = LogTabIndex;
  2792. ShowCancelButtons();
  2793. TVScout = SetTVScout();
  2794. Season s = SelectedSeason;
  2795. Thread th = null;
  2796. th = new Thread(delegate()
  2797. {
  2798. DecisionType Decision = ProcessingSelectedSeason(s, false);
  2799. if(Decision == DecisionType.Cancel)
  2800. MetadataCompleted(th, "Canceled.", true);
  2801. else
  2802. SeasonChanged(s, s.IsDeleted);
  2803. MetadataCompleted(th, "Done.", true);
  2804. });
  2805. th.Name = "Processing " + s.Name;
  2806. th.SetApartmentState(ApartmentState.STA);
  2807. th.Start();
  2808. tvThreads.Add(th);
  2809. }
  2810. private DecisionType ProcessingSelectedSeason(Season s, bool CanUserSkip)
  2811. {
  2812. TVShow ts = s.TVShow;
  2813. Message("Scanning folder " + s.Name, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  2814. SearchResultsDecision SearchDecision = SearchForID(ts, false, ts.Name, null, CanUserSkip, Properties.Settings.Default.forceEnterSearchTerm);
  2815. if (SearchDecision.Decision == DecisionType.Continue)
  2816. {
  2817. MediaScout.TVShowXML selected = null;
  2818. try
  2819. {
  2820. selected = tvdb.GetTVShow(SearchDecision.SelectedID);
  2821. }
  2822. catch (Exception ex)
  2823. {
  2824. Message(ex.Message, MediaScout.MediaScoutMessage.MessageType.Error, 0);
  2825. }
  2826. if (selected != null)
  2827. {
  2828. TVScout.series = selected;
  2829. String name = TVScout.ProcessSeasonDirectory(ts.Folderpath, new DirectoryInfo(s.Folderpath), -1);
  2830. if (name != null)
  2831. {
  2832. if (name.Substring(0, 2) != "d:")
  2833. {
  2834. s.Name = name;
  2835. s.Folderpath = ts.Folderpath + "\\" + name;
  2836. }
  2837. else
  2838. s.IsDeleted = true;
  2839. }
  2840. }
  2841. }
  2842. return SearchDecision.Decision;
  2843. }
  2844. private void btnProcessSelectedSeasons_Click(object sender, RoutedEventArgs e)
  2845. {
  2846. ProcessMultipleSeasons(BuildSelectedSeasonList());
  2847. }
  2848. private void ProcessMultipleSeasons(ObservableCollection<Season> seasons)
  2849. {
  2850. tcTabs.SelectedIndex = LogTabIndex;
  2851. ShowCancelButtons();
  2852. TVScout = SetTVScout();
  2853. Thread th = null;
  2854. th = new Thread(delegate()
  2855. {
  2856. maxvalue += seasons.Count;
  2857. foreach (Season s in seasons)
  2858. {
  2859. DecisionType Decision = ProcessingSelectedSeason(s, true);
  2860. if (Decision == DecisionType.Skip)
  2861. Message("Skipped " + s.Name, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  2862. else if (Decision == DecisionType.Cancel)
  2863. MetadataCompleted(th, "Canceled.", true);
  2864. else
  2865. SeasonChanged(s, false);
  2866. SetTasbkBarProgressValue(++currentvalue);
  2867. }
  2868. for (int i = 0; i < seasons.Count; i++)
  2869. {
  2870. if (seasons[i].IsDeleted)
  2871. SeasonChanged(seasons[i], true);
  2872. }
  2873. MetadataCompleted(th, "Done.", true);
  2874. });
  2875. th.Name = "Processing Seasons";
  2876. th.SetApartmentState(ApartmentState.STA);
  2877. th.Start();
  2878. tvThreads.Add(th);
  2879. }
  2880. private void btnProcessAllSeasons_Click(object sender, RoutedEventArgs e)
  2881. {
  2882. TVShow ts = SelectedTVShow;
  2883. ProcessMultipleSeasons(ts.Seasons);
  2884. }
  2885. #endregion
  2886. #region Process Episode Routines
  2887. //private void ProcessUnsortedEpisodeCollection(Thread th, TVShow ts)
  2888. //{
  2889. // foreach (Episode episode in ts.UnsortedEpisodes)
  2890. // {
  2891. // DecisionType Decision = ProcessingSelectedEpisode(episode, true);
  2892. // if (Decision == DecisionType.Skip)
  2893. // Message("Skipped " + episode.Name, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  2894. // else if (Decision == DecisionType.Cancel)
  2895. // MetadataCompleted(th, "Canceled.", true);
  2896. // //else
  2897. // // EpisodeChanged(episode, false);
  2898. // }
  2899. // for (int i = 0; i < ts.UnsortedEpisodes.Count; i++)
  2900. // {
  2901. // if (ts.UnsortedEpisodes[i].IsDeleted)
  2902. // EpisodeChanged(ts.UnsortedEpisodes[i].Season.Episodes[i], true);
  2903. // }
  2904. //}
  2905. private void btnProcessSelectedEpisode_Click(object sender, RoutedEventArgs e)
  2906. {
  2907. tcTabs.SelectedIndex = LogTabIndex;
  2908. ShowCancelButtons();
  2909. TVScout = SetTVScout();
  2910. Episode Episode = SelectedEpisode;
  2911. Thread th = null;
  2912. th = new Thread(delegate()
  2913. {
  2914. DecisionType Decision = ProcessingSelectedEpisode(Episode, false);
  2915. if (Decision == DecisionType.Cancel)
  2916. MetadataCompleted(th, "Canceled.", true);
  2917. else
  2918. EpisodeChanged(Episode, Episode.IsDeleted);
  2919. MetadataCompleted(th, "Done.", true);
  2920. });
  2921. th.Name = "Processing " + Episode.Name;
  2922. th.SetApartmentState(ApartmentState.STA);
  2923. th.Start();
  2924. tvThreads.Add(th);
  2925. }
  2926. private DecisionType ProcessingSelectedEpisode(Episode e, bool CanUserSkip)
  2927. {
  2928. Message("Scanning file " + e.Name, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  2929. Season s = e.Season;
  2930. TVShow ts = s.TVShow;
  2931. //int sid = (ts.IsUnsortedEpisodeCollection) ? MediaScout.GetID.GetSeasonAndEpisodeIDFromFile(e.StrippedFileName).SeasonID : s.GetNum();
  2932. int sid = (ts.IsUnsortedEpisodeCollection) ? -1 : s.GetNum();
  2933. //if (sid == -1)
  2934. //{
  2935. // // Should prompt for Dialog box asking season number instead of Messagebox
  2936. // MessageBox.Show("Unable to Get Season Number from File");
  2937. // return DecisionType.Skip;
  2938. //}
  2939. String SearchTerm = ts.IsUnsortedEpisodeCollection ? ts.GetSearchTerm(e.StrippedFileName) : null;
  2940. String SearchObjectName = ts.IsUnsortedEpisodeCollection ? e.Name : ts.Name;
  2941. SearchResultsDecision SearchDecision = SearchForID(ts, false, SearchObjectName, SearchTerm, CanUserSkip, Properties.Settings.Default.forceEnterSearchTerm);
  2942. if (SearchDecision.Decision == DecisionType.Continue)
  2943. {
  2944. String TVShowID = SearchDecision.SelectedID;
  2945. if (!String.IsNullOrEmpty(TVShowID))
  2946. {
  2947. MediaScout.TVShowXML selected = null;
  2948. try
  2949. {
  2950. selected = tvdb.GetTVShow(TVShowID);
  2951. }
  2952. catch (Exception ex)
  2953. {
  2954. Debug.WriteLine(ex.Message);
  2955. Message(ex.Message, MediaScout.MediaScoutMessage.MessageType.Error, 0);
  2956. }
  2957. if (selected != null)
  2958. {
  2959. TVScout.series = selected;
  2960. String name = TVScout.ProcessEpisode(ts.Folderpath, new FileInfo(e.Filepath), sid, !ts.IsUnsortedEpisodeCollection, -1);
  2961. if (name != null)
  2962. {
  2963. if (ts.IsUnsortedEpisodeCollection)
  2964. e.IsDeleted = true;
  2965. else
  2966. {
  2967. e.Name = name;
  2968. e.Filepath = e.Season.Folderpath + "\\" + e.Name;
  2969. }
  2970. }
  2971. }
  2972. }
  2973. }
  2974. return SearchDecision.Decision;
  2975. }
  2976. private void btnProcessSelectedEpisodes_Click(object sender, RoutedEventArgs e)
  2977. {
  2978. ProcessMultipleEpisodes(BuildSelectedEpisodeList());
  2979. }
  2980. private void ProcessMultipleEpisodes(ObservableCollection<Episode> episodes)
  2981. {
  2982. tcTabs.SelectedIndex = LogTabIndex;
  2983. ShowCancelButtons();
  2984. TVScout = SetTVScout();
  2985. TVShow ts = episodes[0].Season.TVShow;
  2986. Thread th = null;
  2987. th = new Thread(delegate()
  2988. {
  2989. maxvalue += episodes.Count;
  2990. foreach(Episode e in episodes)
  2991. {
  2992. DecisionType Decision = ProcessingSelectedEpisode(e, true);
  2993. if (Decision == DecisionType.Skip)
  2994. Message("Skipped " + e.Name, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  2995. else if (Decision == DecisionType.Cancel)
  2996. MetadataCompleted(th, "Canceled.", true);
  2997. SetTasbkBarProgressValue(++currentvalue);
  2998. }
  2999. for (int i = 0; i < episodes.Count; i++)
  3000. {
  3001. if (episodes[i].IsDeleted)
  3002. {
  3003. EpisodeChanged(episodes[i], true);
  3004. i--;
  3005. }
  3006. }
  3007. if (ts.IsUnsortedEpisodeCollection)
  3008. if (episodes.Count == 0)
  3009. TVShowChanged(ts, true);
  3010. MetadataCompleted(th, "Done.", true);
  3011. });
  3012. th.Name = "Processing Episodes";
  3013. th.SetApartmentState(ApartmentState.STA);
  3014. th.Start();
  3015. tvThreads.Add(th);
  3016. }
  3017. private void btnProcessAllEpisodes_Click(object sender, RoutedEventArgs e)
  3018. {
  3019. Season s = SelectedSeason;
  3020. ProcessMultipleEpisodes(s.Episodes);
  3021. }
  3022. #endregion
  3023. #region Process Movie Routines
  3024. private String PromptForTitleSelectionDialog(MediaScout.MovieXML selected)
  3025. {
  3026. String Title = null;
  3027. Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
  3028. new Action(
  3029. delegate()
  3030. {
  3031. TitleSelectionDialog tsd = new TitleSelectionDialog(selected);
  3032. tsd.Owner = this;
  3033. tsd.ShowDialog();
  3034. Title = tsd.SelectedTitle;
  3035. }
  3036. ));
  3037. return Title;
  3038. }
  3039. private void btnProcessSelectedMovie_Click(object sender, RoutedEventArgs e)
  3040. {
  3041. tcTabs.SelectedIndex = LogTabIndex;
  3042. ShowCancelButtons();
  3043. MovieScout = SetMovieScout();
  3044. Movie m = SelectedMovie;
  3045. if (m.IsUnsortedFileCollection)
  3046. //ProcessUnsortedFileCollection(th, m);
  3047. ProcessMultipleMovieFiles(m.Files);
  3048. else
  3049. {
  3050. Thread th = null;
  3051. th = new Thread(delegate()
  3052. {
  3053. DecisionType Decision = ProcessingSelectedMovie(m, null, null, false);
  3054. if (Decision == DecisionType.Cancel)
  3055. MetadataCompleted(th, "Canceled.", true);
  3056. else
  3057. MovieChanged(m, m.IsDeleted);
  3058. MetadataCompleted(th, "Done.", true);
  3059. });
  3060. th.Name = "Processing " + m.Name;
  3061. th.SetApartmentState(ApartmentState.STA);
  3062. th.Start();
  3063. tvThreads.Add(th);
  3064. }
  3065. }
  3066. private DecisionType ProcessingSelectedMovie(Movie m, String Title, String Year, bool CanUserSkip)
  3067. {
  3068. Message("Processing Movie " + m.Name, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  3069. SearchResultsDecision SearchDecision = SearchForID(m, true, m.Name, null, CanUserSkip, Properties.Settings.Default.forceEnterSearchTerm);
  3070. if (SearchDecision.Decision == DecisionType.Continue)
  3071. {
  3072. MediaScout.MovieXML selected = null;
  3073. try
  3074. {
  3075. selected = tmdb.Get(SearchDecision.SelectedID);
  3076. }
  3077. catch (Exception ex)
  3078. {
  3079. Message(ex.Message, MediaScout.MediaScoutMessage.MessageType.Error, 0);
  3080. }
  3081. if (selected != null)
  3082. {
  3083. if (!String.IsNullOrEmpty(selected.LocalTitle) && selected.LocalTitle != selected.Title)
  3084. SearchDecision.SelectedHasMultipleTitles = true;
  3085. if (!Properties.Settings.Default.AutoSelectMovieTitle && Title == null && SearchDecision.SelectedHasMultipleTitles)
  3086. Title = PromptForTitleSelectionDialog(selected);
  3087. if (Title != null)
  3088. selected.Title = Title;
  3089. if (Year != null)
  3090. selected.Year = Year;
  3091. MovieScout.m = selected;
  3092. String name = MovieScout.ProcessDirectory(m.Folderpath);
  3093. if (name != null)
  3094. {
  3095. if (name.Substring(0, 2) != "d:")
  3096. {
  3097. m.Name = name;
  3098. m.Folderpath = new DirectoryInfo(m.Folderpath).Parent.FullName + "\\" + name;
  3099. }
  3100. else
  3101. m.IsDeleted = true;
  3102. }
  3103. }
  3104. }
  3105. return SearchDecision.Decision;
  3106. }
  3107. private void btnProcessSelectedMovies_Click(object sender, RoutedEventArgs e)
  3108. {
  3109. ProcessMultipleMovies(BuildSelectedMovieList());
  3110. }
  3111. private void ProcessMultipleMovies(ObservableCollection<Movie> movies)
  3112. {
  3113. tcTabs.SelectedIndex = LogTabIndex;
  3114. ShowCancelButtons();
  3115. MovieScout = SetMovieScout();
  3116. Thread th = null;
  3117. th = new Thread(delegate()
  3118. {
  3119. maxvalue += movies.Count;
  3120. foreach (Movie m in movies)
  3121. {
  3122. if (m.IsUnsortedFileCollection)
  3123. //ProcessUnsortedFileCollection(th, m);
  3124. ProcessMultipleMovieFiles(m.Files);
  3125. else
  3126. {
  3127. DecisionType Decision = ProcessingSelectedMovie(m, null, null, true);
  3128. if (Decision == DecisionType.Skip)
  3129. Message("Skipped " + m.Name, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  3130. else if (Decision == DecisionType.Cancel)
  3131. MetadataCompleted(th, "Canceled.", true);
  3132. else
  3133. MovieChanged(m, false);
  3134. }
  3135. SetTasbkBarProgressValue(++currentvalue);
  3136. }
  3137. for (int i = 0; i < movies.Count; i++)
  3138. {
  3139. if (movies[i].IsDeleted)
  3140. {
  3141. MovieChanged(movies[i], true);
  3142. i--;
  3143. }
  3144. }
  3145. MetadataCompleted(th, "Done.", true);
  3146. });
  3147. th.Name = "Processing Movies";
  3148. th.SetApartmentState(ApartmentState.STA);
  3149. th.Start();
  3150. tvThreads.Add(th);
  3151. }
  3152. private void btnProcessAllMovie_Click(object sender, RoutedEventArgs e)
  3153. {
  3154. ProcessAllMoviesDialog pam = new ProcessAllMoviesDialog(movies, UnsortedFiles);
  3155. pam.Owner = this;
  3156. this.Hide();
  3157. pam.ShowDialog();
  3158. this.Show();
  3159. if (pam.DialogResult == true)
  3160. {
  3161. tcTabs.SelectedIndex = LogTabIndex;
  3162. ShowCancelButtons();
  3163. MovieScout = SetMovieScout();
  3164. Thread th = null;
  3165. th = new Thread(delegate()
  3166. {
  3167. maxvalue += pam.mslist.Count;
  3168. foreach (MoviesSearch ms in pam.mslist)
  3169. {
  3170. if (ms.Skip)
  3171. Message("Skipped " + ms.Movie.Name, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  3172. else
  3173. {
  3174. ms.Movie.ID = ms.SelectedMovie.ID;
  3175. ProcessingSelectedMovie(ms.Movie, ms.SelectedMovie.Title, ms.SelectedMovie.Year, false);
  3176. }
  3177. SetTasbkBarProgressValue(++currentvalue);
  3178. }
  3179. MetadataCompleted(th, "Done.", true);
  3180. });
  3181. th.Name = "Processing All Movies";
  3182. th.SetApartmentState(ApartmentState.STA);
  3183. th.Start();
  3184. tvThreads.Add(th);
  3185. }
  3186. }
  3187. #endregion
  3188. #region Process Movie File Routines
  3189. //private void ProcessUnsortedFileCollection(Thread th, Movie m)
  3190. //{
  3191. // foreach (MovieFile mf in m.Files)
  3192. // {
  3193. // DecisionType Decision = ProcessingSelectedMovieFile(mf, true);
  3194. // if (Decision == DecisionType.Skip)
  3195. // Message("Skipped " + mf.Name, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  3196. // else if (Decision == DecisionType.Cancel)
  3197. // MetadataCompleted(th, "Canceled.", true);
  3198. // else
  3199. // MovieFileChanged(mf, false);
  3200. // }
  3201. //}
  3202. private void btnProcessSelectedMovieFile_Click(object sender, RoutedEventArgs e)
  3203. {
  3204. tcTabs.SelectedIndex = LogTabIndex;
  3205. ShowCancelButtons();
  3206. MovieScout = SetMovieScout();
  3207. MovieFile mf = SelectedMovieFile;
  3208. Thread th = null;
  3209. th = new Thread(delegate()
  3210. {
  3211. DecisionType Decision = ProcessingSelectedMovieFile(mf, false);
  3212. if (Decision == DecisionType.Cancel)
  3213. MetadataCompleted(th, "Canceled.", true);
  3214. else
  3215. MovieFileChanged(mf, mf.IsDeleted);
  3216. MetadataCompleted(th, "Done.", true);
  3217. });
  3218. th.Name = "Processing " + mf.Name;
  3219. th.SetApartmentState(ApartmentState.STA);
  3220. th.Start();
  3221. tvThreads.Add(th);
  3222. }
  3223. private DecisionType ProcessingSelectedMovieFile(MovieFile mf, bool CanUserSkip)
  3224. {
  3225. Movie m = mf.Movie;
  3226. Message("Processing File " + m.Name, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  3227. String SearchTerm = m.IsUnsortedFileCollection ? m.GetSearchTerm(mf.StrippedFileName) : null;
  3228. String SearchObjectName = m.IsUnsortedFileCollection ? mf.Name : m.Name;
  3229. SearchResultsDecision SearchDecision = SearchForID(m, true, SearchObjectName, SearchTerm, CanUserSkip, Properties.Settings.Default.forceEnterSearchTerm);
  3230. if (SearchDecision.Decision == DecisionType.Continue)
  3231. {
  3232. MediaScout.MovieXML selected = null;
  3233. try
  3234. {
  3235. selected = tmdb.Get(SearchDecision.SelectedID);
  3236. }
  3237. catch (Exception ex)
  3238. {
  3239. Message(ex.Message, MediaScout.MediaScoutMessage.MessageType.Error, 0);
  3240. }
  3241. if (selected != null)
  3242. {
  3243. if (!String.IsNullOrEmpty(selected.LocalTitle) && selected.LocalTitle != selected.Title)
  3244. SearchDecision.SelectedHasMultipleTitles = true;
  3245. if (!Properties.Settings.Default.AutoSelectMovieTitle && SearchDecision.SelectedHasMultipleTitles)
  3246. selected.Title = PromptForTitleSelectionDialog(selected);
  3247. MovieScout.m = selected;
  3248. String name = MovieScout.ProcessFile(m.Folderpath, new FileInfo(mf.Filepath), !m.IsUnsortedFileCollection, -1);
  3249. if (name != null)
  3250. {
  3251. if(m.IsUnsortedFileCollection)
  3252. mf.IsDeleted = true;
  3253. else
  3254. {
  3255. m.Name = name;
  3256. m.Folderpath = Properties.Settings.Default.MovieFolders + "\\" + name;
  3257. }
  3258. }
  3259. }
  3260. }
  3261. return SearchDecision.Decision;
  3262. }
  3263. private void btnProcessSelectedMovieFiles_Click(object sender, RoutedEventArgs e)
  3264. {
  3265. ProcessMultipleMovieFiles(BuildSelectedMovieFileList());
  3266. }
  3267. private void ProcessMultipleMovieFiles(ObservableCollection<MovieFile> files)
  3268. {
  3269. tcTabs.SelectedIndex = LogTabIndex;
  3270. ShowCancelButtons();
  3271. MovieScout = SetMovieScout();
  3272. Movie m = files[0].Movie;
  3273. Thread th = null;
  3274. th = new Thread(delegate()
  3275. {
  3276. maxvalue += files.Count;
  3277. foreach (MovieFile mf in files)
  3278. {
  3279. DecisionType Decision = ProcessingSelectedMovieFile(mf, true);
  3280. if (Decision == DecisionType.Skip)
  3281. Message("Skipped " + mf.Name, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  3282. else if (Decision == DecisionType.Cancel)
  3283. MetadataCompleted(th, "Canceled.", true);
  3284. SetTasbkBarProgressValue(++currentvalue);
  3285. }
  3286. for (int i = 0; i < files.Count; i++)
  3287. {
  3288. if (files[i].IsDeleted)
  3289. {
  3290. MovieFileChanged(files[i], true);
  3291. i--;
  3292. }
  3293. }
  3294. if (m.IsUnsortedFileCollection)
  3295. if (m.Files.Count == 0)
  3296. MovieChanged(m, true);
  3297. MetadataCompleted(th, "Done.", true);
  3298. });
  3299. th.Name = "Processing Movie Files";
  3300. th.SetApartmentState(ApartmentState.STA);
  3301. th.Start();
  3302. tvThreads.Add(th);
  3303. }
  3304. private void btnProcessAllMovieFile_Click(object sender, RoutedEventArgs e)
  3305. {
  3306. Movie m = SelectedMovie;
  3307. ProcessMultipleMovieFiles(m.Files);
  3308. }
  3309. #endregion
  3310. #endregion
  3311. #region Subtitles(TV, Seasons, And Episode) Routines
  3312. #region Sublight Video Hash Computation
  3313. private static byte[] GetLastBytes(byte[] arr, int n)
  3314. {
  3315. List<byte> newarr = new List<byte>();
  3316. //Copies Last n bytes
  3317. for (int j = 0; j < n; j++)
  3318. newarr.Add(arr[(arr.Length - 1) - j]);
  3319. return newarr.ToArray();
  3320. }
  3321. private static byte[] Invert(byte[] arr)
  3322. {
  3323. Array.Reverse(arr);
  3324. return arr;
  3325. }
  3326. private static byte[] ComputeMD5FromFile(string fileName, int nbytes)
  3327. {
  3328. System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
  3329. byte[] bs = System.Text.Encoding.UTF8.GetBytes(fileName);
  3330. bs = md5.ComputeHash(bs);
  3331. List<byte> newarr = new List<byte>();
  3332. //Copies First n bytes
  3333. for (int i = 0; i < nbytes; i++)
  3334. newarr.Add(bs[i]);
  3335. return newarr.ToArray();
  3336. //StringBuilder s = new StringBuilder();
  3337. //for(int i = 0 ; i < nbytes; i++)
  3338. //{
  3339. // byte b = bs[i];
  3340. // s.Append(b.ToString("x2").ToLower());
  3341. //}
  3342. //return s.ToString();
  3343. }
  3344. /// <summary>
  3345. /// C# algorithm which computes hash of video file. Computed hash is then used to find matching subtitles.
  3346. /// </summary>
  3347. /// <param name="filePath">Absolute path to video file.</param>
  3348. /// <returns>Computed hash value formated as hexadecimal string (52 characters). Returns null on failure.</returns>
  3349. public static string ComputeSublightVideoHash(string filePath)
  3350. {
  3351. try
  3352. {
  3353. if (!System.IO.File.Exists(filePath))
  3354. { return null; }
  3355. List<byte> hash = new List<byte>(26);
  3356. //0: reserved
  3357. hash.Insert(0, 0x0);
  3358. //1-2: video length in seconds
  3359. short runTime = (short)MediaScout.VideoInfo.GetRuntime(filePath);
  3360. if (BitConverter.IsLittleEndian)
  3361. hash.InsertRange(1, Invert(BitConverter.GetBytes(runTime)));
  3362. else
  3363. hash.InsertRange(1, BitConverter.GetBytes(runTime));
  3364. //3-8: file length in bytes
  3365. long fileLength = new FileInfo(filePath).Length;
  3366. if (BitConverter.IsLittleEndian)
  3367. hash.InsertRange(3, GetLastBytes(Invert(BitConverter.GetBytes(fileLength)), 6));
  3368. else
  3369. hash.InsertRange(3, GetLastBytes(BitConverter.GetBytes(fileLength), 6));
  3370. //9-24: MD5 hash for first 5 MB of file
  3371. hash.InsertRange(9, ComputeMD5FromFile(filePath, 5 * 1024 * 1024));
  3372. //25: control byte
  3373. int sum = 0;
  3374. for (int i = 0; i < 25; i++)
  3375. sum += hash[i];
  3376. hash.Insert(25, Convert.ToByte(sum % 256));
  3377. //convert to hex string
  3378. StringBuilder sbResult = new StringBuilder();
  3379. for (int i = 0; i < hash.Count; i++)
  3380. {
  3381. sbResult.AppendFormat("{0:x2}", hash[i]);
  3382. }
  3383. return sbResult.ToString();
  3384. }
  3385. catch
  3386. {
  3387. return null;
  3388. }
  3389. }
  3390. #endregion
  3391. private String GetSublightCmdOptions(String Folderpath)
  3392. {
  3393. if (!String.IsNullOrEmpty(Properties.Settings.Default.SublightUsername))
  3394. {
  3395. String cmdOptionsDir = "downloadbatch " + '"' + Folderpath + '"';
  3396. String cmdOptionsLanguage = " \"en\" ";
  3397. String cmdOptionsfiletypes = " \"" + Properties.Settings.Default.allowedFileTypes.Replace(".", "*.") + "\" ";
  3398. String cmdOptionsOverwrite = Properties.Settings.Default.overwriteFiles ? "" : "/smartDownload ";
  3399. String cmdOptionsMisc = "/recursive:true";
  3400. String cmdOptionsAuthentication = (String.IsNullOrEmpty(Properties.Settings.Default.SublightUsername) ? "" : " /username:\"" + Properties.Settings.Default.SublightUsername + "\"") + (String.IsNullOrEmpty(Properties.Settings.Default.SublightPassword) ? "" : " /password:\"" + Properties.Settings.Default.SublightPassword + "\"");
  3401. return cmdOptionsDir + cmdOptionsfiletypes + cmdOptionsLanguage + cmdOptionsOverwrite + cmdOptionsMisc + cmdOptionsAuthentication;
  3402. }
  3403. else
  3404. {
  3405. MessageBox.Show("Sublight Username is not defined");
  3406. btnSetSublightOptions_Click(null, null);
  3407. }
  3408. return null;
  3409. }
  3410. private String GetSublightCmdFileOptions(String Filepath)
  3411. {
  3412. if (!String.IsNullOrEmpty(Properties.Settings.Default.SublightUsername))
  3413. {
  3414. String cmdOptionsFile = "download " + '"' + Filepath + '"';
  3415. String cmdOptionsLanguage = " \"en\"";
  3416. String cmdOptionsAuthentication = (String.IsNullOrEmpty(Properties.Settings.Default.SublightUsername) ? "" : " /username:\"" + Properties.Settings.Default.SublightUsername + "\"");
  3417. return cmdOptionsFile + cmdOptionsLanguage + cmdOptionsAuthentication;
  3418. }
  3419. else
  3420. {
  3421. MessageBox.Show("Sublight Username is not defined");
  3422. btnSetSublightOptions_Click(null, null);
  3423. }
  3424. return null;
  3425. }
  3426. private ClientInfo GetSublightClientInfo()
  3427. {
  3428. String ClientId = "MediaScout";
  3429. String ApiKey = "6FE1A80F-8874-45ED-B5FB-E979B70DD6E6";
  3430. ClientInfo ci = new ClientInfo();
  3431. ci.ApiKey = ApiKey;
  3432. ci.ClientId = ClientId;
  3433. return ci;
  3434. }
  3435. //private void ShowNotImplemented()
  3436. //{
  3437. // MessageBox.Show("Not Implemented");
  3438. //}
  3439. private void btnDownloadSelectedTVSubtitles_Click(object sender, RoutedEventArgs e)
  3440. {
  3441. if(File.Exists(Properties.Settings.Default.SublightCmd))
  3442. {
  3443. String cmdOptions = GetSublightCmdOptions(SelectedTVShow.Folderpath);
  3444. if(cmdOptions!=null)
  3445. System.Diagnostics.Process.Start(Properties.Settings.Default.SublightCmd, cmdOptions);
  3446. }
  3447. }
  3448. private void btnDownloadAllTVSubtitles_Click(object sender, RoutedEventArgs e)
  3449. {
  3450. if (File.Exists(Properties.Settings.Default.SublightCmd))
  3451. {
  3452. foreach (String dir in Properties.Settings.Default.TVFolders)
  3453. {
  3454. String cmdOptions = GetSublightCmdOptions(dir);
  3455. if (cmdOptions != null)
  3456. System.Diagnostics.Process.Start(Properties.Settings.Default.SublightCmd, cmdOptions);
  3457. }
  3458. }
  3459. }
  3460. private void btnDownloadSelectedSeasonSubtitles_Click(object sender, RoutedEventArgs e)
  3461. {
  3462. if (File.Exists(Properties.Settings.Default.SublightCmd))
  3463. {
  3464. String cmdOptions = GetSublightCmdOptions(SelectedSeason.Folderpath);
  3465. if (cmdOptions != null)
  3466. System.Diagnostics.Process.Start(Properties.Settings.Default.SublightCmd, cmdOptions);
  3467. }
  3468. }
  3469. private void btnDownloadSelectedEpisodeSubtitles_Click(object sender, RoutedEventArgs e)
  3470. {
  3471. if (File.Exists(Properties.Settings.Default.SublightCmd))
  3472. {
  3473. String cmdOptions = GetSublightCmdFileOptions(SelectedEpisode.Filepath);
  3474. if (cmdOptions != null)
  3475. System.Diagnostics.Process.Start(Properties.Settings.Default.SublightCmd, cmdOptions);
  3476. }
  3477. }
  3478. private void btnFindSelectedEpisodeSubtitles_Click(object sender, RoutedEventArgs e)
  3479. {
  3480. if (File.Exists(Properties.Settings.Default.Sublight))
  3481. {
  3482. String cmdOptions = "file=\"" + SelectedEpisode.Filepath + "\"";
  3483. System.Diagnostics.Process.Start(Properties.Settings.Default.Sublight, cmdOptions);
  3484. }
  3485. }
  3486. private void btnDownloadSelectedMovieSubtitles_Click(object sender, RoutedEventArgs e)
  3487. {
  3488. if (File.Exists(Properties.Settings.Default.SublightCmd))
  3489. {
  3490. String cmdOptions = GetSublightCmdOptions(SelectedMovie.Folderpath);
  3491. if (cmdOptions != null)
  3492. System.Diagnostics.Process.Start(Properties.Settings.Default.SublightCmd, cmdOptions);
  3493. }
  3494. }
  3495. private void btnDownloadAllMovieSubtitles_Click(object sender, RoutedEventArgs e)
  3496. {
  3497. if (File.Exists(Properties.Settings.Default.SublightCmd))
  3498. {
  3499. foreach (String dir in Properties.Settings.Default.MovieFolders)
  3500. {
  3501. String cmdOptions = GetSublightCmdOptions(dir);
  3502. if (cmdOptions != null)
  3503. System.Diagnostics.Process.Start(Properties.Settings.Default.SublightCmd, cmdOptions);
  3504. }
  3505. }
  3506. }
  3507. private void btnDownloadSelectedMovieFileSubtitles_Click(object sender, RoutedEventArgs e)
  3508. {
  3509. WcfSublightClient client = new WcfSublightClient();
  3510. client.Open();
  3511. String[] args = null;
  3512. String[] settings = null;
  3513. String error = null;
  3514. Guid session = client.LogInAnonymous4(out settings, out error, GetSublightClientInfo(), args);
  3515. List<SubtitleLanguage> langs = new List<SubtitleLanguage>();
  3516. langs.Add(SubtitleLanguage.English);
  3517. Genre[] g = null;
  3518. String videohash = ComputeSublightVideoHash(SelectedMovieFile.Filepath);
  3519. Subtitle[] subtitles;
  3520. Release[] releases;
  3521. bool IsLimited;
  3522. client.SearchSubtitles3(session, videohash, SelectedMovie.Name, Int32.Parse(SelectedMovieFile.GetYear()),
  3523. new byte(), new int(), langs.ToArray(), g, "MediaScout", new float(),
  3524. out subtitles, out releases, out IsLimited, out error);
  3525. String ticket;
  3526. short que;
  3527. String plugin = null;
  3528. client.GetDownloadTicket(out ticket, out que, out error, session, plugin, subtitles[0].SubtitleID.ToString());
  3529. //if (File.Exists(Properties.Settings.Default.SublightCmd))
  3530. //{
  3531. // String cmdOptions = GetSublightCmdFileOptions(SelectedMovieFile.Filepath);
  3532. // if (cmdOptions != null)
  3533. // System.Diagnostics.Process.Start(Properties.Settings.Default.SublightCmd, cmdOptions);
  3534. //}
  3535. }
  3536. private void btnFindSelectedMovieFileSubtitles_Click(object sender, RoutedEventArgs e)
  3537. {
  3538. if (File.Exists(Properties.Settings.Default.Sublight))
  3539. {
  3540. String cmdOptions = "file=\"" + SelectedMovieFile.Filepath + "\"";
  3541. System.Diagnostics.Process.Start(Properties.Settings.Default.Sublight, cmdOptions);
  3542. }
  3543. }
  3544. #endregion
  3545. #region FS Watcher Functions
  3546. #region TV FS Watcher Routines
  3547. void TVFSWatcher_Changed(object sender, FileSystemEventArgs e)
  3548. {
  3549. //If it doesn't exist as directory then its is a file
  3550. if (!Directory.Exists(e.FullPath))
  3551. {
  3552. FileInfo fi = new FileInfo(e.FullPath);
  3553. if (AllowedFileTypes.Contains(fi.Extension) //make sure its an acceptable filetype
  3554. && !FileInUse(e.FullPath)) //make sure the file isn't in use, otherwise it can't be processed.
  3555. {
  3556. //Log it
  3557. Message("Autotron : " + e.FullPath, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  3558. int SeasonNum = -1;
  3559. DirectoryInfo seriesFolder = fi.Directory;
  3560. //Check if its a Season Folder or Specials Folder
  3561. //If the folder contains "Season" (or SeasonFolderName), infer it.
  3562. if (seriesFolder.Name.Contains(Properties.Settings.Default.SeasonFolderName) || seriesFolder.Name.Contains(Properties.Settings.Default.SpecialsFolderName))
  3563. {
  3564. if (seriesFolder.Name == Properties.Settings.Default.SpecialsFolderName)
  3565. SeasonNum = 0;
  3566. else
  3567. SeasonNum = Int32.Parse(seriesFolder.Name.Replace(Properties.Settings.Default.SeasonFolderName, ""));
  3568. seriesFolder = seriesFolder.Parent;
  3569. }
  3570. String ShowName = (seriesFolder.FullName != Properties.Settings.Default.TVDropBoxLocation) ? seriesFolder.Name : null;
  3571. StartTVShowProcess(seriesFolder, fi, ShowName, SeasonNum);
  3572. }
  3573. }
  3574. }
  3575. private bool StartTVShowProcess(DirectoryInfo SeriesFolder, FileInfo EpisodeFile, String ShowName, int SeasonNum)
  3576. {
  3577. String SearchTerm = (ShowName != null) ? ShowName : EpisodeFile.Name.Replace(EpisodeFile.Extension, "");
  3578. TVShow ts = new TVShow(SeriesFolder.FullName, SeriesFolder.Name, false);
  3579. SearchResultsDecision SearchDecision = SearchForID(ts, false, SearchTerm, SearchTerm, false, (ShowName != null) ? Properties.Settings.Default.forceEnterSearchTerm : true);
  3580. if (SearchDecision.Decision == DecisionType.Continue)
  3581. {
  3582. MediaScout.TVShowXML s = tvdb.GetTVShow(SearchDecision.SelectedID);
  3583. TVScout = SetTVScout();
  3584. TVScout.series = s;
  3585. TVFSWatcher.EnableRaisingEvents = false;
  3586. TVScout.ProcessEpisode(SeriesFolder.FullName, EpisodeFile, SeasonNum, (ShowName != null), -1);
  3587. TVFSWatcher.EnableRaisingEvents = true;
  3588. return true;
  3589. }
  3590. return false;
  3591. }
  3592. #endregion
  3593. #region Movie FS Watcher Routines
  3594. void MovieFSWatcher_Changed(object sender, FileSystemEventArgs e)
  3595. {
  3596. //If it doesn't exist as directory then its is a file
  3597. if (!Directory.Exists(e.FullPath))
  3598. {
  3599. FileInfo fi = new FileInfo(e.FullPath);
  3600. if (AllowedFileTypes.Contains(fi.Extension) //make sure its an acceptable filetype
  3601. && !FileInUse(e.FullPath)) //make sure the file isn't in use, otherwise it can't be processed.
  3602. {
  3603. //Log it
  3604. Message("Autotron : " + e.FullPath, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  3605. String MovieName = (fi.Directory.FullName != Properties.Settings.Default.MovieDropBoxLocation) ? fi.Directory.Name : null;
  3606. StartMovieProcess(fi.Directory, fi, MovieName);
  3607. }
  3608. }
  3609. else //It is a Directory
  3610. {
  3611. DirectoryInfo di = new DirectoryInfo(e.FullPath);
  3612. if (di.Parent.FullName == Properties.Settings.Default.MovieDropBoxLocation)
  3613. {
  3614. //Log it
  3615. Message("Autotron : " + e.FullPath, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  3616. StartMovieProcess(di, null, di.Name);
  3617. }
  3618. }
  3619. }
  3620. private bool StartMovieProcess(DirectoryInfo MovieFolder, FileInfo MovieFile, String MovieName)
  3621. {
  3622. Movie mo = null;
  3623. if (MovieFile == null)
  3624. mo = new Movie(MovieFolder.FullName, MovieFolder.Name, false);
  3625. else
  3626. mo = new Movie(MovieFolder.FullName, MovieFolder.Name, MovieFile);
  3627. String SearchTerm = (MovieFile == null) ? null : (MovieName!=null) ? mo.GetSearchTerm() : mo.Files[0].GetSearchTerm();
  3628. SearchResultsDecision SearchDecision = SearchForID(mo, true, SearchTerm, SearchTerm, false, Properties.Settings.Default.forceEnterSearchTerm);
  3629. if (SearchDecision.Decision == DecisionType.Continue)
  3630. {
  3631. MediaScout.MovieXML m = tmdb.Get(SearchDecision.SelectedID);
  3632. MovieScout = SetMovieScout();
  3633. MovieScout.m = m;
  3634. MovieFSWatcher.EnableRaisingEvents = false;
  3635. if (MovieFile != null)
  3636. MovieScout.ProcessFile(MovieFolder.FullName, MovieFile, (MovieName != null), -1);
  3637. else
  3638. MovieScout.ProcessDirectory(MovieFolder.FullName);
  3639. MovieFSWatcher.EnableRaisingEvents = true;
  3640. return true;
  3641. }
  3642. return false;
  3643. }
  3644. #endregion
  3645. #region File In Use Routines
  3646. //Check to see if the file is in use by attempting to open or create it. It will throw a (caught) exception if it is
  3647. private bool FileInUse(String file)
  3648. {
  3649. try
  3650. {
  3651. using (FileStream fs = new FileStream(file, FileMode.OpenOrCreate))
  3652. {
  3653. }
  3654. return false;
  3655. }
  3656. catch
  3657. {
  3658. return true;
  3659. }
  3660. }
  3661. #endregion
  3662. #endregion
  3663. #region Log Tab Functions
  3664. private void InsertHyperlink(RichTextBox rtb, TextPointer position)
  3665. {
  3666. string match = string.Empty;
  3667. Regex r = new Regex("(?:^|[\\s\\[\\]\\}\\{\\(\\)\\\'\\\"<>])((?:(?:https?|gopher|ftp|file|irc):\\/\\/|www\\.)[a-zA-Z0-9\\.\\-=;&%\\?]+(?:\\/?[a-zA-Z0-9\\.\\-=;&%\\?]*)*)");
  3668. Hyperlink h;
  3669. while (position != null)
  3670. {
  3671. if (position.CompareTo(rtb.Document.ContentEnd) == 0)
  3672. {
  3673. break;
  3674. }
  3675. if (position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text)
  3676. {
  3677. String text = position.GetTextInRun(LogicalDirection.Forward);
  3678. Int32 indexInRun = -1;
  3679. if (r.IsMatch(text))
  3680. {
  3681. Match m = r.Match(text);
  3682. match = m.Groups[1].Value;
  3683. indexInRun = m.Groups[1].Index;
  3684. }
  3685. if (indexInRun >= 0)
  3686. {
  3687. position = position.GetPositionAtOffset(indexInRun);
  3688. h = new Hyperlink(position, position.GetPositionAtOffset(match.Length));
  3689. h.Tag = match;
  3690. h.Foreground = Brushes.Blue;
  3691. h.TextDecorations = TextDecorations.Underline;
  3692. h.Cursor = System.Windows.Input.Cursors.Hand;
  3693. //h.MouseLeftButtonDown += new MouseButtonEventHandler(h_MouseLeftButtonDown);
  3694. position = position.GetPositionAtOffset(match.Length);
  3695. }
  3696. else
  3697. {
  3698. position = position.GetPositionAtOffset(text.Length);
  3699. }
  3700. }
  3701. else
  3702. {
  3703. position = position.GetNextContextPosition(LogicalDirection.Forward);
  3704. }
  3705. }
  3706. }
  3707. bool FirstTask = true;
  3708. public void TVScout_Message(string msg, MediaScout.MediaScoutMessage.MessageType mt, int level)
  3709. {
  3710. if (!Dispatcher.CheckAccess())
  3711. {
  3712. Dispatcher.Invoke(DispatcherPriority.Normal, new MediaScout.MediaScoutMessage.Message(TVScout_Message), msg, mt, level);
  3713. return;
  3714. }
  3715. if (msg != "Thread was being aborted.")
  3716. {
  3717. TextRange tr = new TextRange(rtbLog.Document.ContentEnd, rtbLog.Document.ContentEnd);
  3718. Display_Message(tr, msg, mt, level);
  3719. rtbLog.ScrollToEnd();
  3720. if(FirstTask)
  3721. FirstTask = false;
  3722. }
  3723. }
  3724. public void Display_Message(TextRange tr, string msg, MediaScout.MediaScoutMessage.MessageType mt, int level)
  3725. {
  3726. String tab = new String(' ', 4*level);
  3727. switch (mt)
  3728. {
  3729. case MediaScout.MediaScoutMessage.MessageType.Task:
  3730. tr.Text = (FirstTask ? "" : "\r") + tab + msg;
  3731. tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.White);
  3732. break;
  3733. case MediaScout.MediaScoutMessage.MessageType.TaskResult:
  3734. tr.Text = " : " + msg;
  3735. tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.BlanchedAlmond);
  3736. break;
  3737. case MediaScout.MediaScoutMessage.MessageType.TaskError:
  3738. tr.Text = " : " + msg;
  3739. tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Red);
  3740. break;
  3741. case MediaScout.MediaScoutMessage.MessageType.Error:
  3742. tr.Text = "\r" + tab + msg;
  3743. tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Red);
  3744. break;
  3745. }
  3746. }
  3747. #endregion
  3748. #region Images Functions
  3749. //TODO : 1 Improve Images Dialog Fucntions
  3750. #region Show Dialog Functions -- Needs Improvement
  3751. private void ShowActorImageDialog(Object obj, Person Actor, String file, String file1)
  3752. {
  3753. //if (!Dispatcher.CheckAccess())
  3754. //{
  3755. // Dispatcher.Invoke(DispatcherPriority.Normal, new PosterChangedHandler(ShowPosterDialog), obj, id, IsMovie, s, file);
  3756. // return;
  3757. //}
  3758. Movie m = null;
  3759. TVShow ts = null;
  3760. if (Actor.IsMovieActor)
  3761. m = obj as Movie;
  3762. else
  3763. ts = obj as TVShow;
  3764. ChangeActorImageDialog caid = new ChangeActorImageDialog(Actor.IsMovieActor ? m.ID : ts.ID, Actor.Name, null, Actor.IsMovieActor);
  3765. caid.Owner = this;
  3766. caid.ShowDialog();
  3767. if (caid.Decision == ImageWindowDecisionbType.DownloadAll)
  3768. {
  3769. ShowCancelButtons();
  3770. Thread th = null;
  3771. th = new Thread(delegate()
  3772. {
  3773. MediaScout.Posters[] posters = null;
  3774. posters = Actor.IsMovieActor ? tmdb.GetPersonImage(caid.SelectedActor.ID).ToArray() : null;
  3775. maxvalue += posters.Length;
  3776. int i = 0;
  3777. foreach (MediaScout.Posters p in posters)
  3778. {
  3779. try
  3780. {
  3781. if (Properties.Settings.Default.SaveXBMCMeta)
  3782. {
  3783. Message("Saving " + Actor.Name + " Image in \\" + caid.SelectedActor.GetXBMCDirectory() + " as " + file.Substring(file.LastIndexOf("\\") + 1) , MediaScout.MediaScoutMessage.MessageType.Task, 0);
  3784. caid.selected.SavePoster(file);
  3785. }
  3786. if (Properties.Settings.Default.SaveMyMoviesMeta)
  3787. {
  3788. Message("Saving" + Actor.Name + " Image in \\ImagesByName\\" + caid.SelectedActor.GetMyMoviesDirectory() + " as " + file1.Substring(file1.LastIndexOf("\\") + 1), MediaScout.MediaScoutMessage.MessageType.Task, 0);
  3789. if (Directory.Exists(Actor.MyMoviesFolderPath))
  3790. caid.selected.SavePoster(file1);
  3791. else
  3792. Message("ImagesByName Location Not Defined", MediaScout.MediaScoutMessage.MessageType.TaskError, 0);
  3793. }
  3794. }
  3795. catch (Exception ex)
  3796. {
  3797. Message(ex.Message, MediaScout.MediaScoutMessage.MessageType.Error, 0);
  3798. }
  3799. i++;
  3800. SetTasbkBarProgressValue(++currentvalue);
  3801. }
  3802. //if (app.showballoontip)
  3803. // app.notifyIcon.ShowBalloonTip(1, IsMovie ? m.Name : ts.Name , "All Posters Downloaded", System.Windows.Forms.ToolTipIcon.Info);
  3804. MetadataCompleted(th, "All Images Downloaded", true);
  3805. });
  3806. th.Name = (Actor.Name) + " Image";
  3807. th.SetApartmentState(ApartmentState.STA);
  3808. th.Start();
  3809. tvThreads.Add(th);
  3810. }
  3811. else if (caid.Decision == ImageWindowDecisionbType.PosterSelected)
  3812. {
  3813. Thread th = new Thread(delegate()
  3814. {
  3815. try
  3816. {
  3817. if (Properties.Settings.Default.SaveXBMCMeta)
  3818. {
  3819. Message("Saving " + Actor.Name + " Image in \\" + caid.SelectedActor.GetXBMCDirectory() + " as " + file.Substring(file.LastIndexOf("\\") + 1) , MediaScout.MediaScoutMessage.MessageType.Task, 0);
  3820. caid.selected.SavePoster(file);
  3821. }
  3822. if (Properties.Settings.Default.SaveMyMoviesMeta)
  3823. {
  3824. Message("Saving" + Actor.Name + " Image in \\ImagesByName\\" + caid.SelectedActor.GetMyMoviesDirectory() + " as " + file1.Substring(file1.LastIndexOf("\\") + 1), MediaScout.MediaScoutMessage.MessageType.Task, 0);
  3825. if (Directory.Exists(Actor.MyMoviesFolderPath))
  3826. caid.selected.SavePoster(file1);
  3827. else
  3828. Message("ImagesByName Location Not Defined", MediaScout.MediaScoutMessage.MessageType.TaskError, 0);
  3829. }
  3830. if (Actor.IsMovieActor)
  3831. m.LoadActorsThumb(Actor);
  3832. else
  3833. ts.LoadActorsThumb(Actor);
  3834. Message("Done.", MediaScout.MediaScoutMessage.MessageType.Task, 0);
  3835. }
  3836. catch (Exception ex)
  3837. {
  3838. Message(ex.Message, MediaScout.MediaScoutMessage.MessageType.Error, 0);
  3839. }
  3840. });
  3841. th.SetApartmentState(ApartmentState.STA);
  3842. th.Start();
  3843. }
  3844. else if (caid.Decision == ImageWindowDecisionbType.LocalPosterSelected)
  3845. {
  3846. String selfile = caid.selectedLocalPoster.Poster;
  3847. try
  3848. {
  3849. //if (File.Exists(file))
  3850. //{
  3851. // String renfile = file + "_temp";
  3852. // if (selfile != renfile)
  3853. // {
  3854. // File.Move(selfile, renfile);
  3855. // File.Move(file, selfile);
  3856. // File.Move(renfile, file);
  3857. // }
  3858. //}
  3859. //else
  3860. File.Copy(selfile, file);
  3861. if (Actor.IsMovieActor)
  3862. m.LoadActorsThumb(Actor);
  3863. else
  3864. ts.LoadActorsThumb(Actor);
  3865. }
  3866. catch (Exception ex)
  3867. {
  3868. Message(ex.Message, MediaScout.MediaScoutMessage.MessageType.Error, 0);
  3869. }
  3870. }
  3871. }
  3872. private void ShowPosterDialog(Object obj, String id, bool IsMovie, Season s, String file)
  3873. {
  3874. //if (!Dispatcher.CheckAccess())
  3875. //{
  3876. // Dispatcher.Invoke(DispatcherPriority.Normal, new PosterChangedHandler(ShowPosterDialog), obj, id, IsMovie, s, file);
  3877. // return;
  3878. //}
  3879. Movie m = null;
  3880. TVShow ts = null;
  3881. if (IsMovie)
  3882. m = obj as Movie;
  3883. else if (s == null)
  3884. ts = obj as TVShow;
  3885. String Folderpath = (IsMovie ? m.Folderpath : (s == null ? ts.Folderpath : s.Folderpath));
  3886. ChangeImageDialog cmb = new ChangeImageDialog(Folderpath, id, IsMovie, (s != null) ? s.GetNum() : -1, true);
  3887. cmb.Owner = this;
  3888. cmb.ShowDialog();
  3889. if (cmb.Decision == ImageWindowDecisionbType.DownloadAll)
  3890. {
  3891. ShowCancelButtons();
  3892. Thread th = null;
  3893. th = new Thread(delegate()
  3894. {
  3895. MediaScout.Posters[] posters = null;
  3896. if (IsMovie)
  3897. posters = tmdb.GetPosters(id, MoviePosterType.Poster);
  3898. else
  3899. posters = (s != null) ?
  3900. tvdb.GetPosters(id, TVShowPosterType.Season_Poster, s.GetNum())
  3901. :
  3902. tvdb.GetPosters(id, TVShowPosterType.Poster, -1);
  3903. maxvalue += posters.Length;
  3904. int i = 0;
  3905. foreach (MediaScout.Posters p in posters)
  3906. {
  3907. try
  3908. {
  3909. String posterfile = file.Substring(0, file.LastIndexOf(".")) + i + file.Substring(file.LastIndexOf("."));
  3910. Message("Saving Poster as " + posterfile.Substring(file.LastIndexOf("\\")+1), MediaScout.MediaScoutMessage.MessageType.Task, 0);
  3911. Debug.Write("Saving Poster " + p.Poster);
  3912. p.SavePoster(posterfile);
  3913. }
  3914. catch (Exception ex)
  3915. {
  3916. Message("Unable to Change Poster : " + ex.Message, MediaScout.MediaScoutMessage.MessageType.Error, 0);
  3917. }
  3918. i++;
  3919. SetTasbkBarProgressValue(++currentvalue);
  3920. }
  3921. //if (app.showballoontip)
  3922. // app.notifyIcon.ShowBalloonTip(1, IsMovie ? m.Name : ts.Name , "All Posters Downloaded", System.Windows.Forms.ToolTipIcon.Info);
  3923. MetadataCompleted(th, "All Posters Downloaded", true);
  3924. });
  3925. th.Name = (IsMovie ? m.Name : ts.Name) + " Poster";
  3926. th.SetApartmentState(ApartmentState.STA);
  3927. th.Start();
  3928. tvThreads.Add(th);
  3929. }
  3930. else if (cmb.Decision == ImageWindowDecisionbType.PosterSelected)
  3931. {
  3932. if (IsMovie)
  3933. UpdateMoviePoster(m, MoviePosterType.Poster, true);
  3934. else if (s == null)
  3935. UpdateTVPoster(ts, TVShowPosterType.Poster, true);
  3936. else
  3937. UpdateSeasonPoster(s, TVShowPosterType.Season_Poster, true);
  3938. Thread th = new Thread(delegate()
  3939. {
  3940. try
  3941. {
  3942. Message("Saving Poster as " + file.Substring(file.LastIndexOf("\\")+1), MediaScout.MediaScoutMessage.MessageType.Task, 0);
  3943. Debug.Write("Saving Poster " + cmb.selected.Poster);
  3944. cmb.selected.SavePoster(file);
  3945. if (IsMovie)
  3946. UpdateMoviePoster(m, MoviePosterType.Poster, false);
  3947. else if (s == null)
  3948. UpdateTVPoster(ts, TVShowPosterType.Poster, false);
  3949. else
  3950. UpdateSeasonPoster(s, TVShowPosterType.Season_Poster, false);
  3951. Message("Done.", MediaScout.MediaScoutMessage.MessageType.Task, 0);
  3952. }
  3953. catch (Exception ex)
  3954. {
  3955. Message("Unable to Change Poster : " + ex.Message, MediaScout.MediaScoutMessage.MessageType.Error, 0);
  3956. }
  3957. });
  3958. th.SetApartmentState(ApartmentState.STA);
  3959. th.Start();
  3960. }
  3961. else if (cmb.Decision == ImageWindowDecisionbType.LocalPosterSelected)
  3962. {
  3963. String selfile = cmb.selectedLocalPoster.Poster;
  3964. try
  3965. {
  3966. //if (File.Exists(file))
  3967. //{
  3968. // String renfile = file + "_temp";
  3969. // if (selfile != renfile)
  3970. // {
  3971. // File.Move(selfile, renfile);
  3972. // File.Move(file, selfile);
  3973. // File.Move(renfile, file);
  3974. // }
  3975. //}
  3976. //else
  3977. File.Copy(selfile, file);
  3978. if (IsMovie)
  3979. UpdateMoviePoster(m, MoviePosterType.Poster, false);
  3980. else if (s == null)
  3981. UpdateTVPoster(ts, TVShowPosterType.Poster, false);
  3982. else
  3983. UpdateSeasonPoster(s, TVShowPosterType.Season_Poster, false);
  3984. }
  3985. catch (Exception ex)
  3986. {
  3987. Message(ex.Message, MediaScout.MediaScoutMessage.MessageType.Error, 0);
  3988. }
  3989. }
  3990. }
  3991. private void ShowBackdropDialog(Object obj, String id, bool IsMovie, Season s, String file, String file1)
  3992. {
  3993. //if (!Dispatcher.CheckAccess())
  3994. //{
  3995. // Dispatcher.Invoke(DispatcherPriority.Normal, new BackdropChangedHandler(ShowBackdropDialog), obj, id, IsMovie, s, file, file1);
  3996. // return;
  3997. //}
  3998. Movie m = null;
  3999. TVShow ts = null;
  4000. if (IsMovie)
  4001. m = obj as Movie;
  4002. else if (s == null)
  4003. ts = obj as TVShow;
  4004. String Folderpath = (IsMovie ? m.Folderpath : (s == null ? ts.Folderpath : s.Folderpath));
  4005. ChangeImageDialog cmb = new ChangeImageDialog(Folderpath, id, IsMovie, (s!=null)? s.GetNum() : -1, false);
  4006. cmb.Owner = this;
  4007. cmb.ShowDialog();
  4008. if (cmb.Decision == ImageWindowDecisionbType.DownloadAll)
  4009. {
  4010. ShowCancelButtons();
  4011. Thread th = null;
  4012. th = new Thread(delegate()
  4013. {
  4014. MediaScout.Posters[] posters = null;
  4015. if(IsMovie)
  4016. posters = tmdb.GetPosters(id, MoviePosterType.Backdrop);
  4017. else
  4018. posters = (s!=null) ?
  4019. tvdb.GetPosters(id, TVShowPosterType.Season_Backdrop, s.GetNum())
  4020. :
  4021. tvdb.GetPosters(id, TVShowPosterType.Backdrop, -1);
  4022. maxvalue += posters.Length;
  4023. int i = 0;
  4024. foreach (MediaScout.Posters p in posters)
  4025. {
  4026. try
  4027. {
  4028. if (Properties.Settings.Default.SaveXBMCMeta)
  4029. {
  4030. String filefanart = file1.Substring(0, file1.LastIndexOf(".")) + i + file1.Substring(file1.LastIndexOf("."));
  4031. Message("Saving Backdrop as " + filefanart.Substring(filefanart.LastIndexOf("\\")+1), MediaScout.MediaScoutMessage.MessageType.Task, 0);
  4032. Debug.Write("Saving Backdrop " + p.Poster);
  4033. p.SavePoster(filefanart);
  4034. }
  4035. if (Properties.Settings.Default.SaveMyMoviesMeta)
  4036. {
  4037. String filebackdrop = file.Substring(0, file.LastIndexOf(".")) + i + file.Substring(file.LastIndexOf("."));
  4038. Message("Saving Backdrop as " + filebackdrop.Substring(filebackdrop.LastIndexOf("\\")+1), MediaScout.MediaScoutMessage.MessageType.Task, 0);
  4039. Debug.Write("Saving Backdrop " + p.Poster);
  4040. p.SavePoster(filebackdrop);
  4041. }
  4042. }
  4043. catch (Exception ex)
  4044. {
  4045. Message("Unable to Change Backdrop : " + ex.Message, MediaScout.MediaScoutMessage.MessageType.Error, 0);
  4046. }
  4047. i++;
  4048. SetTasbkBarProgressValue(++currentvalue);
  4049. }
  4050. //if (app.showballoontip)
  4051. // app.notifyIcon.ShowBalloonTip(1, IsMovie ? m.Name : ts.Name, "All Backdrops Downloaded", System.Windows.Forms.ToolTipIcon.Info);
  4052. MetadataCompleted(th, "All Backdrops Downloaded", true);
  4053. });
  4054. th.Name = (IsMovie ? m.Name : ts.Name) + " Backdrop";;
  4055. th.SetApartmentState(ApartmentState.STA);
  4056. th.Start();
  4057. tvThreads.Add(th);
  4058. }
  4059. else if (cmb.Decision == ImageWindowDecisionbType.PosterSelected)
  4060. {
  4061. if (IsMovie)
  4062. UpdateMoviePoster(m, MoviePosterType.Backdrop, true);
  4063. else if (s == null)
  4064. UpdateTVPoster(ts, TVShowPosterType.Backdrop, true);
  4065. else
  4066. UpdateSeasonPoster(s, TVShowPosterType.Season_Backdrop, true);
  4067. Thread th = new Thread(delegate()
  4068. {
  4069. try
  4070. {
  4071. if (Properties.Settings.Default.SaveXBMCMeta)
  4072. {
  4073. Message("Saving Backdrop as " + file1.Substring(file1.LastIndexOf("\\") + 1), MediaScout.MediaScoutMessage.MessageType.Task, 0);
  4074. Debug.Write("Saving Backdrop " + cmb.selected.Poster);
  4075. cmb.selected.SavePoster(file1);
  4076. }
  4077. if (Properties.Settings.Default.SaveMyMoviesMeta)
  4078. {
  4079. Message("Saving Backdrop as " + file.Substring(file.LastIndexOf("\\") + 1), MediaScout.MediaScoutMessage.MessageType.Task, 0);
  4080. Debug.Write("Saving Backdrop " + cmb.selected.Poster);
  4081. cmb.selected.SavePoster(file);
  4082. }
  4083. if (IsMovie)
  4084. UpdateMoviePoster(m, MoviePosterType.Backdrop, false);
  4085. else if (s == null)
  4086. UpdateTVPoster(ts, TVShowPosterType.Backdrop, false);
  4087. else
  4088. UpdateSeasonPoster(s, TVShowPosterType.Season_Backdrop, false);
  4089. Message("Done.", MediaScout.MediaScoutMessage.MessageType.Task, 0);
  4090. }
  4091. catch (Exception ex)
  4092. {
  4093. Message("Unable to Change Backdrop : " + ex.Message, MediaScout.MediaScoutMessage.MessageType.Error, 0);
  4094. }
  4095. });
  4096. th.SetApartmentState(ApartmentState.STA);
  4097. th.Start();
  4098. }
  4099. else if (cmb.Decision == ImageWindowDecisionbType.LocalPosterSelected)
  4100. {
  4101. try
  4102. {
  4103. String selfile = cmb.selectedLocalPoster.Poster;
  4104. if (Properties.Settings.Default.SaveXBMCMeta)
  4105. File.Copy(selfile, file1, true);
  4106. if (Properties.Settings.Default.SaveMyMoviesMeta)
  4107. File.Copy(selfile, file, true);
  4108. if (IsMovie)
  4109. UpdateMoviePoster(m, MoviePosterType.Backdrop, false);
  4110. else if (s == null)
  4111. UpdateTVPoster(ts, TVShowPosterType.Backdrop, false);
  4112. else
  4113. UpdateSeasonPoster(s, TVShowPosterType.Season_Backdrop, false);
  4114. }
  4115. catch (Exception ex)
  4116. {
  4117. Message(ex.Message, MediaScout.MediaScoutMessage.MessageType.Error, 0);
  4118. }
  4119. }
  4120. }
  4121. #endregion
  4122. #region TV Series Image Functions
  4123. #region Managed Image Display Routines
  4124. private void UpdateTVPoster(TVShow ts, TVShowPosterType type, bool IsLoading)
  4125. {
  4126. if (!Dispatcher.CheckAccess())
  4127. {
  4128. Dispatcher.Invoke(DispatcherPriority.Normal, new TVShowImageChangedHandler(UpdateTVPoster), ts, type, IsLoading);
  4129. return;
  4130. }
  4131. switch (type)
  4132. {
  4133. case TVShowPosterType.Poster:
  4134. if (IsLoading)
  4135. {
  4136. imgTVPoster.Source = null;
  4137. ts.isPosterLoading = true;
  4138. imgTVPoster.SetLoading = true;
  4139. }
  4140. else
  4141. {
  4142. ts.isPosterLoading = false;
  4143. if (ts == null)
  4144. imgTVPoster.Source = null;
  4145. else
  4146. imgTVPoster.Source = ts.GetImage(type);
  4147. //imgTVPoster.Visibility = (String.IsNullOrEmpty(ts.Poster) && !IsLoading) ? Visibility.Collapsed : Visibility.Visible;
  4148. }
  4149. break;
  4150. case TVShowPosterType.Backdrop:
  4151. if (IsLoading)
  4152. {
  4153. imgTVBackdrop.Source = null;
  4154. ts.isBackDropLoading = true;
  4155. imgTVBackdrop.SetLoading = true;
  4156. }
  4157. else
  4158. {
  4159. ts.isBackDropLoading = false;
  4160. if (ts == null)
  4161. imgTVBackdrop.Source = null;
  4162. else
  4163. imgTVBackdrop.Source = ts.GetImage(type);
  4164. //imgTVBackdrop.Visibility = (String.IsNullOrEmpty(ts.Backdrop) && !IsLoading) ? Visibility.Collapsed : Visibility.Visible;
  4165. }
  4166. break;
  4167. case TVShowPosterType.Banner:
  4168. if (IsLoading)
  4169. {
  4170. imgTVBanner.Source = null;
  4171. ts.isBannerLoading = true;
  4172. imgTVBanner.SetLoading = true;
  4173. }
  4174. else
  4175. {
  4176. ts.isBannerLoading = false;
  4177. if (ts == null)
  4178. imgTVBanner.Source = null;
  4179. else
  4180. imgTVBanner.Source = ts.GetImage(type);
  4181. //imgTVBanner.Visibility = (String.IsNullOrEmpty(ts.Banner) && !IsLoading) ? Visibility.Collapsed : Visibility.Visible;
  4182. }
  4183. break;
  4184. }
  4185. }
  4186. private void UpdateSeasonPoster(Season s, TVShowPosterType type, bool IsLoading)
  4187. {
  4188. if (!Dispatcher.CheckAccess())
  4189. {
  4190. Dispatcher.Invoke(DispatcherPriority.Normal, new SeasonImageChangedHandler(UpdateSeasonPoster), s, type, IsLoading);
  4191. return;
  4192. }
  4193. switch (type)
  4194. {
  4195. case TVShowPosterType.Season_Poster:
  4196. if (IsLoading)
  4197. {
  4198. imgSeasonPoster.Source = null;
  4199. s.isPosterLoading = true;
  4200. imgSeasonPoster.SetLoading = true;
  4201. }
  4202. else
  4203. {
  4204. s.isPosterLoading = false;
  4205. imgSeasonPoster.Source = s.GetImage(type);
  4206. }
  4207. //imgSeasonPoster.Visibility = (String.IsNullOrEmpty(s.Poster) && !IsLoading) ? Visibility.Collapsed : Visibility.Visible;
  4208. break;
  4209. case TVShowPosterType.Season_Backdrop:
  4210. if (IsLoading)
  4211. {
  4212. imgSeasonBackdrop.Source = null;
  4213. s.isBackDropLoading = true;
  4214. imgSeasonBackdrop.SetLoading = true;
  4215. }
  4216. else
  4217. {
  4218. s.isBackDropLoading = false;
  4219. imgSeasonBackdrop.Source = s.GetImage(type);
  4220. }
  4221. //imgSeasonBackdrop.Visibility = (String.IsNullOrEmpty(s.Backdrop) && !IsLoading) ? Visibility.Collapsed : Visibility.Visible;
  4222. break;
  4223. }
  4224. }
  4225. private void UpdateEpisodePoster(Episode e, String filename, bool IsLoading)
  4226. {
  4227. if (!Dispatcher.CheckAccess())
  4228. {
  4229. Dispatcher.Invoke(DispatcherPriority.Normal, new EpisodeImageChangedHandler(UpdateEpisodePoster), e, filename, IsLoading);
  4230. return;
  4231. }
  4232. if (IsLoading)
  4233. imgEpisodePoster.SetLoading = true;
  4234. else
  4235. imgEpisodePoster.Source = e.GetImage(filename);
  4236. //imgEpisodePoster.Visibility = (String.IsNullOrEmpty(e.Poster) && !IsLoading) ? Visibility.Collapsed : Visibility.Visible;
  4237. }
  4238. #endregion
  4239. #region TV And Season Poster Functions
  4240. private void btnChangeSelectedTVPoster_Click(object sender, RoutedEventArgs e)
  4241. {
  4242. TVShow ts = SelectedTVShow;
  4243. ChangeSelectedTVorSeasonPoster(ts, null, null, false);
  4244. }
  4245. private void btnChangeSelectedSeasonPoster_Click(object sender, RoutedEventArgs e)
  4246. {
  4247. Season s = SelectedSeason;
  4248. TVShow ts = s.TVShow;
  4249. ChangeSelectedTVorSeasonPoster(ts, s, null, false);
  4250. }
  4251. private void ChangeSelectedTVorSeasonPoster(TVShow ts, Season s, String id, bool noDialog)
  4252. {
  4253. bool IsSeason = (s != null) ? true : false;
  4254. String file = (IsSeason ? s.Folderpath : ts.Folderpath) + @"\folder.jpg";
  4255. if (noDialog)
  4256. {
  4257. if ((!File.Exists(file)) || (Properties.Settings.Default.forceUpdate))
  4258. {
  4259. MediaScout.Posters[] posters = tvdb.GetPosters(id, (IsSeason) ? TVShowPosterType.Season_Poster : TVShowPosterType.Poster, (IsSeason) ? s.GetNum() : -1);
  4260. if (posters != null)
  4261. {
  4262. try
  4263. {
  4264. Message("Saving Poster[ ( " + posters[0].Poster + ") as " + file, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  4265. posters[0].SavePoster(file);
  4266. }
  4267. catch (Exception ex)
  4268. {
  4269. Message("Unable to Change Poster : " + ex.Message, MediaScout.MediaScoutMessage.MessageType.Error, 0);
  4270. }
  4271. }
  4272. else
  4273. Message("No Posters Found", MediaScout.MediaScoutMessage.MessageType.Error, 0);
  4274. }
  4275. }
  4276. else
  4277. {
  4278. //ShowCancelButtons();
  4279. //th = new Thread(delegate()
  4280. //{
  4281. if (id == null)
  4282. id = SearchForID(ts, false, ts.Name, null, false, Properties.Settings.Default.forceEnterSearchTerm).SelectedID;
  4283. if (id != null)
  4284. ShowPosterDialog(ts, id, false, s, file);
  4285. //});
  4286. //th.SetApartmentState(ApartmentState.STA);
  4287. //th.Start();
  4288. //tvThreads.Add(th);
  4289. }
  4290. }
  4291. #endregion
  4292. #region TV And Season Backdrop Functions
  4293. private void btnChangeSelectedTVBackdrop_Click(object sender, RoutedEventArgs e)
  4294. {
  4295. TVShow ts = SelectedTVShow;
  4296. ChangeSelectedTVorSeasonBackdrop(ts, null, null, false);
  4297. }
  4298. private void btnChangeSelectedSeasonBackdrop_Click(object sender, RoutedEventArgs e)
  4299. {
  4300. Season s = SelectedSeason;
  4301. TVShow ts = s.TVShow;
  4302. ChangeSelectedTVorSeasonBackdrop(ts, s, null, false);
  4303. }
  4304. private void ChangeSelectedTVorSeasonBackdrop(TVShow ts, Season s, String id, bool noDialog)
  4305. {
  4306. bool IsSeason = (s != null) ? true : false;
  4307. String file = (IsSeason ? s.Folderpath : ts.Folderpath) + @"\backdrop.jpg";
  4308. String file1 = (IsSeason ? s.Folderpath : ts.Folderpath) + @"\fanart.jpg";
  4309. if (noDialog)
  4310. {
  4311. if ((!File.Exists(file)) || (Properties.Settings.Default.forceUpdate))
  4312. {
  4313. MediaScout.Posters[] posters = tvdb.GetPosters(id, (IsSeason) ? TVShowPosterType.Season_Backdrop : TVShowPosterType.Backdrop, (IsSeason) ? s.GetNum() : -1);
  4314. if (posters != null)
  4315. {
  4316. try
  4317. {
  4318. Message("Saving Backdrop[ ( " + posters[0].Poster + ") as " + file, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  4319. posters[0].SavePoster(file);
  4320. Message("Saving Backdrop[ ( " + posters[0].Poster + ") as " + file1, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  4321. posters[0].SavePoster(file1);
  4322. }
  4323. catch (Exception ex)
  4324. {
  4325. Message("Unable to Change Backdrop : " + ex.Message, MediaScout.MediaScoutMessage.MessageType.Error, 0);
  4326. }
  4327. }
  4328. else
  4329. Message("No Backdrops Found", MediaScout.MediaScoutMessage.MessageType.Error, 0);
  4330. }
  4331. }
  4332. else
  4333. {
  4334. //ShowCancelButtons();
  4335. //th = new Thread(delegate()
  4336. //{
  4337. if (id == null)
  4338. id = SearchForID(ts, false, ts.Name, null, false, Properties.Settings.Default.forceEnterSearchTerm).SelectedID;
  4339. if (id != null)
  4340. ShowBackdropDialog(ts, id, false, s, file, file1);
  4341. //});
  4342. //th.SetApartmentState(ApartmentState.STA);
  4343. //th.Start();
  4344. //tvThreads.Add(th);
  4345. }
  4346. }
  4347. #endregion
  4348. #region TV Banner Functions
  4349. private void btnChangeSelectedTVBanner_Click(object sender, RoutedEventArgs e)
  4350. {
  4351. TVShow s = SelectedTVShow;
  4352. ChangeSelectedTVBanner(s, null, false);
  4353. }
  4354. private void ChangeSelectedTVBanner(TVShow ts, String id, bool noDialog)
  4355. {
  4356. if (id == null)
  4357. id = SearchForID(ts, false, ts.Name, null, false, Properties.Settings.Default.forceEnterSearchTerm).SelectedID;
  4358. if (id != null)
  4359. {
  4360. if (noDialog)
  4361. {
  4362. String file = ts.Folderpath + @"\banner.jpg";
  4363. if ((!File.Exists(file)) || (Properties.Settings.Default.forceUpdate))
  4364. {
  4365. MediaScout.Posters[] posters = tvdb.GetPosters(id, TVShowPosterType.Banner, -1);
  4366. if (posters != null)
  4367. {
  4368. Message("Saving Banner ( " + posters[0].Poster + ") as " + file, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  4369. try
  4370. {
  4371. posters[0].SavePoster(file);
  4372. }
  4373. catch (Exception ex)
  4374. {
  4375. Message("Unable to Change Banner : " + ex.Message, MediaScout.MediaScoutMessage.MessageType.Error, 0);
  4376. }
  4377. }
  4378. else
  4379. Message("No Banners Found", MediaScout.MediaScoutMessage.MessageType.Error, 0);
  4380. }
  4381. }
  4382. else
  4383. {
  4384. ChangeTVBanner ctb = new ChangeTVBanner(id, tvdb);
  4385. ctb.Owner = this;
  4386. ctb.ShowDialog();
  4387. if (ctb.DownloadAll)
  4388. {
  4389. Thread dallb = new Thread(delegate()
  4390. {
  4391. MediaScout.Posters[] posters = tvdb.GetPosters(id, TVShowPosterType.Banner, -1);
  4392. maxvalue += posters.Length;
  4393. int i = 0;
  4394. foreach (MediaScout.Posters p in posters)
  4395. {
  4396. String file = ts.Folderpath + @"\banner" + i + ".jpg";
  4397. Message("Saving Banner (" + p.Poster + ") as " + file, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  4398. try
  4399. {
  4400. p.SavePoster(file);
  4401. }
  4402. catch (Exception ex)
  4403. {
  4404. Message("Unable to Change Banner : " + ex.Message, MediaScout.MediaScoutMessage.MessageType.Error, 0);
  4405. }
  4406. i++;
  4407. SetTasbkBarProgressValue(++currentvalue);
  4408. }
  4409. Message("All Banners Downloaded", MediaScout.MediaScoutMessage.MessageType.Task, 0);
  4410. //if(app.showballoontip)
  4411. // app.notifyIcon.ShowBalloonTip(1, ts.Name, "All Banners Downloaded", System.Windows.Forms.ToolTipIcon.Info);
  4412. });
  4413. dallb.SetApartmentState(ApartmentState.STA);
  4414. dallb.Start();
  4415. }
  4416. else if (ctb.selected != null)
  4417. {
  4418. UpdateTVPoster(ts, TVShowPosterType.Banner, true);
  4419. Thread th = new Thread(delegate()
  4420. {
  4421. String file = ts.Folderpath + @"\banner.jpg";
  4422. Message("Saving Banner (" + ctb.selected.Poster + ") as " + file, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  4423. try
  4424. {
  4425. ctb.selected.SavePoster(file);
  4426. UpdateTVPoster(ts, TVShowPosterType.Banner, false);
  4427. Message("Done.", MediaScout.MediaScoutMessage.MessageType.Task, 0);
  4428. }
  4429. catch (Exception ex)
  4430. {
  4431. Message("Unable to Change Backdrop : " + ex.Message, MediaScout.MediaScoutMessage.MessageType.Error, 0);
  4432. }
  4433. });
  4434. th.SetApartmentState(ApartmentState.STA);
  4435. th.Start();
  4436. }
  4437. }
  4438. }
  4439. }
  4440. #endregion
  4441. #region Episode Poster Functions
  4442. private void btnEpisodePosterFromFile_Click(object sender, RoutedEventArgs e)
  4443. {
  4444. Episode ep = SelectedEpisode;
  4445. String filename = null;
  4446. if (Properties.Settings.Default.SaveXBMCMeta)
  4447. {
  4448. FileInfo fi = new FileInfo(ep.Filepath);
  4449. filename = fi.Name.Replace(fi.Extension, "") + ".tbn";
  4450. Message("Saving Episode Poster as " + filename, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  4451. try
  4452. {
  4453. MediaScout.VideoInfo.SaveThumb(ep.Filepath, ep.Season.MetadataFolderPath + filename, 0.25);
  4454. Message("Done.", MediaScout.MediaScoutMessage.MessageType.Task, 0);
  4455. UpdateEpisodePoster(ep, filename, false);
  4456. }
  4457. catch (Exception ex)
  4458. {
  4459. Message(ex.Message, MediaScout.MediaScoutMessage.MessageType.TaskError, 0);
  4460. }
  4461. }
  4462. if (Properties.Settings.Default.SaveMyMoviesMeta)
  4463. {
  4464. if (!Directory.Exists(ep.Season.MetadataFolderPath))
  4465. MediaScout.IOFunctions.CreateHiddenFolder(ep.Season.MetadataFolderPath);
  4466. FileInfo fi = new FileInfo(ep.Filepath);
  4467. filename = ((ep.ID != null) ? ep.ID : fi.Name.Replace(fi.Extension, "")) + ".jpg";
  4468. Message("Saving Episode Poster as " + filename, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  4469. try
  4470. {
  4471. MediaScout.VideoInfo.SaveThumb(ep.Filepath, ep.Season.MetadataFolderPath + filename, 0.25);
  4472. Message("Done.", MediaScout.MediaScoutMessage.MessageType.Task, 0);
  4473. UpdateEpisodePoster(ep, filename, false);
  4474. }
  4475. catch (Exception ex)
  4476. {
  4477. Message(ex.Message, MediaScout.MediaScoutMessage.MessageType.TaskError, 0);
  4478. }
  4479. }
  4480. }
  4481. #endregion
  4482. #endregion
  4483. #region Movie Image Functions
  4484. #region Managed Image Display Routines
  4485. private void UpdateMoviePoster(Movie m, MoviePosterType type, bool IsLoading)
  4486. {
  4487. if (!Dispatcher.CheckAccess())
  4488. {
  4489. Dispatcher.Invoke(DispatcherPriority.Send, new MovieImageChangedHandler(UpdateMoviePoster), m, type, IsLoading);
  4490. return;
  4491. }
  4492. switch (type)
  4493. {
  4494. case MoviePosterType.Poster:
  4495. if (IsLoading)
  4496. {
  4497. imgMoviePoster.Source = null;
  4498. m.isPosterLoading = true;
  4499. imgMoviePoster.SetLoading = true;
  4500. }
  4501. else
  4502. {
  4503. m.isPosterLoading = false;
  4504. if (m == null)
  4505. imgMoviePoster.Source = null;
  4506. else
  4507. imgMoviePoster.Source = m.GetImage(type);
  4508. }
  4509. //imgMoviePoster.Visibility = (String.IsNullOrEmpty(m.Poster) &&!IsLoading) ? Visibility.Collapsed : Visibility.Visible;
  4510. break;
  4511. case MoviePosterType.Backdrop:
  4512. if (IsLoading)
  4513. {
  4514. imgMovieBackdrop.Source = null;
  4515. m.isBackDropLoading = true;
  4516. imgMovieBackdrop.SetLoading = true;
  4517. }
  4518. else
  4519. {
  4520. m.isBackDropLoading = false;
  4521. if (m == null)
  4522. imgMovieBackdrop.Source = null;
  4523. else
  4524. imgMovieBackdrop.Source = m.GetImage(type);
  4525. }
  4526. //imgMovieBackdrop.Visibility = (String.IsNullOrEmpty(m.Backdrop) && !IsLoading) ? Visibility.Collapsed : Visibility.Visible;
  4527. break;
  4528. }
  4529. }
  4530. private void UpdateMovieFilePoster(MovieFile mf, MoviePosterType type, bool IsLoading)
  4531. {
  4532. if (!Dispatcher.CheckAccess())
  4533. {
  4534. Dispatcher.Invoke(DispatcherPriority.Send, new MovieFileImageChangedHandler(UpdateMovieFilePoster), mf, type, IsLoading);
  4535. return;
  4536. }
  4537. switch (type)
  4538. {
  4539. case MoviePosterType.File_Poster:
  4540. if (IsLoading)
  4541. {
  4542. imgMovieFilePoster.Source = null;
  4543. mf.isPosterLoading = true;
  4544. imgMovieFilePoster.SetLoading = true;
  4545. }
  4546. else
  4547. {
  4548. mf.isPosterLoading = false;
  4549. imgMovieFilePoster.Source = mf.GetImage(type);
  4550. }
  4551. //imgMovieFilePoster.Visibility = (String.IsNullOrEmpty(mf.Poster) && !IsLoading) ? Visibility.Collapsed : Visibility.Visible;
  4552. break;
  4553. case MoviePosterType.File_Backdrop:
  4554. if (IsLoading)
  4555. {
  4556. imgMovieFileBackdrop.Source = null;
  4557. mf.isBackDropLoading = true;
  4558. imgMovieFileBackdrop.SetLoading = true;
  4559. }
  4560. else
  4561. {
  4562. mf.isBackDropLoading = false;
  4563. imgMovieFileBackdrop.Source = mf.GetImage(type);
  4564. }
  4565. //imgMovieFileBackdrop.Visibility = (String.IsNullOrEmpty(mf.Backdrop) && !IsLoading) ? Visibility.Collapsed : Visibility.Visible;
  4566. break;
  4567. }
  4568. }
  4569. #endregion
  4570. #region Movie Poster Functions
  4571. private void btnChangeMoviePoster_Click(object sender, RoutedEventArgs e)
  4572. {
  4573. Movie m = SelectedMovie;
  4574. ChangeSelectedMoviePoster(m, null, null, false);
  4575. }
  4576. private void btnChangeMovieFilePoster_Click(object sender, RoutedEventArgs e)
  4577. {
  4578. MovieFile mf = SelectedMovieFile;
  4579. Movie m = mf.Movie;
  4580. ChangeSelectedMoviePoster(m, null, null, false);
  4581. }
  4582. private void ChangeSelectedMoviePoster(Movie m, MovieFile mf, String id, bool noDialog)
  4583. {
  4584. String file = m.Folderpath + (mf!=null ? mf.StrippedFileName + ".tbn" : @"\folder.jpg");
  4585. if (noDialog)
  4586. {
  4587. if ((!File.Exists(file)) || (Properties.Settings.Default.forceUpdate))
  4588. {
  4589. MediaScout.Posters[] posters = tmdb.GetPosters(id, MoviePosterType.Poster);
  4590. if (posters != null)
  4591. {
  4592. Message("Saving Poster ( " + posters[0].Poster + ") as " + file, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  4593. try
  4594. {
  4595. posters[0].SavePoster(file);
  4596. }
  4597. catch (Exception ex)
  4598. {
  4599. Message("Unable to Change Poster : " + ex.Message, MediaScout.MediaScoutMessage.MessageType.Error, 0);
  4600. }
  4601. }
  4602. else
  4603. Message("No Posters found", MediaScout.MediaScoutMessage.MessageType.Error, 0);
  4604. }
  4605. }
  4606. else
  4607. {
  4608. //ShowCancelButtons();
  4609. //th = new Thread(delegate()
  4610. //{
  4611. if (id == null)
  4612. id = SearchForID(m, true, m.Name, null, false, Properties.Settings.Default.forceEnterSearchTerm).SelectedID;
  4613. if (id != null)
  4614. ShowPosterDialog(m, id, true, null, file);
  4615. //});
  4616. //th.SetApartmentState(ApartmentState.STA);
  4617. //th.Start();
  4618. //tvThreads.Add(th);
  4619. }
  4620. }
  4621. #endregion
  4622. #region Movie Backdrop Functions
  4623. private void btnChangeMovieBackdrop_Click(object sender, RoutedEventArgs e)
  4624. {
  4625. Movie m = SelectedMovie;
  4626. ChangeSelectedMovieBackdrop(m, null, m.ID, false);
  4627. }
  4628. private void btnChangeMovieFileBackdrop_Click(object sender, RoutedEventArgs e)
  4629. {
  4630. MovieFile mf = SelectedMovieFile;
  4631. Movie m = mf.Movie;
  4632. ChangeSelectedMovieBackdrop(m, mf, m.ID, false);
  4633. }
  4634. private void ChangeSelectedMovieBackdrop(Movie m, MovieFile mf, String id, bool noDialog)
  4635. {
  4636. String file = m.Folderpath + @"\backdrop.jpg";
  4637. String file1 = m.Folderpath + (mf != null ? mf.StrippedFileName + ".jpg" : @"\fanart.jpg");
  4638. if (noDialog)
  4639. {
  4640. if ((!File.Exists(file)) || (Properties.Settings.Default.forceUpdate))
  4641. {
  4642. MediaScout.Posters[] posters = tmdb.GetPosters(id, MoviePosterType.Backdrop);
  4643. if (posters != null)
  4644. {
  4645. Message("Saving Backdrop ( " + posters[0].Poster + ") as " + file, MediaScout.MediaScoutMessage.MessageType.Task, 0);
  4646. try
  4647. {
  4648. posters[0].SavePoster(file);
  4649. }
  4650. catch (Exception ex)
  4651. {
  4652. Message("Unable to Change Backdrop : " + ex.Message, MediaScout.MediaScoutMessage.MessageType.Error, 0);
  4653. }
  4654. }
  4655. else
  4656. Message("No Backdrops found", MediaScout.MediaScoutMessage.MessageType.Error, 0);
  4657. }
  4658. }
  4659. else
  4660. {
  4661. //ShowCancelButtons();
  4662. //th = new Thread(delegate()
  4663. // {
  4664. if (id == null)
  4665. id = SearchForID(m, true, m.Name, null, false, Properties.Settings.Default.forceEnterSearchTerm).SelectedID;
  4666. if (id != null)
  4667. ShowBackdropDialog(m, id, true, null, file, file1);
  4668. // });
  4669. //th.SetApartmentState(ApartmentState.STA);
  4670. //th.Start();
  4671. //tvThreads.Add(th);
  4672. }
  4673. }
  4674. #endregion
  4675. #endregion
  4676. #region Actor Thumb Images Function
  4677. private void btnChangeActorThumb_Click(object sender, RoutedEventArgs e)
  4678. {
  4679. Person p = SelectedPerson;
  4680. String file = p.XBMCFolderPath + "\\" + p.Name.Replace(" " ,"_") + ".jpg";
  4681. String file1 = p.MyMoviesFolderPath + "\\" + p.Name.Replace(" " ,"_") + @"\folder.jpg";
  4682. if (!Directory.Exists(p.XBMCFolderPath))
  4683. MediaScout.IOFunctions.CreateHiddenFolder(p.XBMCFolderPath);
  4684. if (!Directory.Exists(p.MyMoviesFolderPath + "\\" + p.Name.Replace(" ", "_")))
  4685. Directory.CreateDirectory(p.MyMoviesFolderPath + "\\" + p.Name.Replace(" ", "_"));
  4686. if(p.IsMovieActor)
  4687. ShowActorImageDialog(SelectedMovie, p, file, file1);
  4688. else
  4689. ShowActorImageDialog(SelectedTVShow, p, file, file1);
  4690. }
  4691. #endregion
  4692. #endregion
  4693. #region Options Routines : 47
  4694. #region TV Series Options Routines : 19
  4695. #region Sets the TV Folders
  4696. private void btnSetTVFolders_Click(object sender, RoutedEventArgs e)
  4697. {
  4698. FoldersDialog fd = new FoldersDialog(false);
  4699. fd.Owner = this;
  4700. if (fd.ShowDialog() == true)
  4701. {
  4702. if (Properties.Settings.Default.TVFolders == null)
  4703. Properties.Settings.Default.TVFolders = new System.Collections.Specialized.StringCollection();
  4704. else
  4705. Properties.Settings.Default.TVFolders.Clear();
  4706. foreach (String dir in fd.lstFolders.Items)
  4707. Properties.Settings.Default.TVFolders.Add(dir);
  4708. Properties.Settings.Default.Save();
  4709. resetTVfolder = true;
  4710. }
  4711. }
  4712. #endregion
  4713. #region TV DropBox Location
  4714. private void ChangeMonitorTVFolder()
  4715. {
  4716. if (Directory.Exists(txtTVDropBox.Text))
  4717. chkTVFSWatcher.IsEnabled = true;
  4718. }
  4719. private void TVDropBoxFolderChanged()
  4720. {
  4721. if (WindowLoaded)
  4722. {
  4723. if (Properties.Settings.Default.TVDropBoxLocation != txtTVDropBox.Text)
  4724. {
  4725. Properties.Settings.Default.TVDropBoxLocation = txtTVDropBox.Text;
  4726. Properties.Settings.Default.Save();
  4727. ChangeMonitorTVFolder();
  4728. }
  4729. }
  4730. }
  4731. private void txtTVDropBox_LostFocus(object sender, RoutedEventArgs e)
  4732. {
  4733. TVDropBoxFolderChanged();
  4734. }
  4735. private void btnBrowserTVDropBox_Click(object sender, RoutedEventArgs e)
  4736. {
  4737. System.Windows.Forms.FolderBrowserDialog myBrowser = new System.Windows.Forms.FolderBrowserDialog();
  4738. myBrowser.Description = "Select TV Shows DropBox folder";
  4739. if (Directory.Exists(txtTVDropBox.Text))
  4740. myBrowser.SelectedPath = txtTVDropBox.Text;
  4741. if (myBrowser.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  4742. {
  4743. txtTVDropBox.Text = myBrowser.SelectedPath;
  4744. TVDropBoxFolderChanged();
  4745. }
  4746. }
  4747. #endregion
  4748. #region TV FS Watcher Checkbox Functions
  4749. private void chkTVFSWatcher_ValueChanged(object sender, RoutedEventArgs e)
  4750. {
  4751. if (WindowLoaded)
  4752. {
  4753. if (TVFSWatcher == null)
  4754. {
  4755. TVFSWatcher = new FileSystemWatcher();
  4756. TVFSWatcher.Path = Properties.Settings.Default.TVDropBoxLocation;
  4757. TVFSWatcher.IncludeSubdirectories = true;
  4758. TVFSWatcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.DirectoryName;
  4759. TVFSWatcher.Created += new FileSystemEventHandler(TVFSWatcher_Changed);
  4760. TVFSWatcher.Changed += new FileSystemEventHandler(TVFSWatcher_Changed);
  4761. }
  4762. TVFSWatcher.EnableRaisingEvents = chkTVFSWatcher.IsChecked.Value;
  4763. Properties.Settings.Default.TVFSWatcher = chkTVFSWatcher.IsChecked.Value;
  4764. Properties.Settings.Default.Save();
  4765. }
  4766. }
  4767. private void chkTVFSWatcher_Unchecked(object sender, RoutedEventArgs e)
  4768. {
  4769. chkTVFSWatcher_ValueChanged(sender, e);
  4770. }
  4771. private void chkTVFSWatcher_Checked(object sender, RoutedEventArgs e)
  4772. {
  4773. chkTVFSWatcher_ValueChanged(sender, e);
  4774. }
  4775. #endregion
  4776. #region Options 1 Posters and Move TV File Options : 6
  4777. #region Get Series Posters
  4778. private void chkSeriesPosters_ValueChanged(object sender, RoutedEventArgs e)
  4779. {
  4780. if (WindowLoaded)
  4781. {
  4782. Properties.Settings.Default.getSeriesPosters = chkSeriesPosters.IsChecked.Value;
  4783. Properties.Settings.Default.Save();
  4784. }
  4785. }
  4786. private void chkSeriesPosters_Checked(object sender, RoutedEventArgs e)
  4787. {
  4788. chkSeriesPosters_ValueChanged(sender, e);
  4789. }
  4790. private void chkSeriesPosters_Unchecked(object sender, RoutedEventArgs e)
  4791. {
  4792. chkSeriesPosters_ValueChanged(sender, e);
  4793. }
  4794. #endregion
  4795. #region Get Season Posters
  4796. private void chkSeasonPosters_ValueChanged(object sender, RoutedEventArgs e)
  4797. {
  4798. if (WindowLoaded)
  4799. {
  4800. Properties.Settings.Default.getSeasonPosters = chkSeasonPosters.IsChecked.Value;
  4801. Properties.Settings.Default.Save();
  4802. }
  4803. }
  4804. private void chkSeasonPosters_Checked(object sender, RoutedEventArgs e)
  4805. {
  4806. chkSeasonPosters_ValueChanged(sender, e);
  4807. }
  4808. private void chkSeasonPosters_Unchecked(object sender, RoutedEventArgs e)
  4809. {
  4810. chkSeasonPosters_ValueChanged(sender, e);
  4811. }
  4812. #endregion
  4813. #region Get Episode Posters
  4814. private void chkEpPosters_ValueChanged(object sender, RoutedEventArgs e)
  4815. {
  4816. if (WindowLoaded)
  4817. {
  4818. Properties.Settings.Default.getEpisodePosters = chkEpPosters.IsChecked.Value;
  4819. Properties.Settings.Default.Save();
  4820. }
  4821. }
  4822. private void chkEpPosters_Checked(object sender, RoutedEventArgs e)
  4823. {
  4824. chkEpPosters_ValueChanged(sender, e);
  4825. }
  4826. private void chkEpPosters_Unchecked(object sender, RoutedEventArgs e)
  4827. {
  4828. chkEpPosters_ValueChanged(sender, e);
  4829. }
  4830. #endregion
  4831. #region Move TV Files
  4832. private void chkMoveTVFiles_ValueChanged(object sender, RoutedEventArgs e)
  4833. {
  4834. if (WindowLoaded)
  4835. {
  4836. Properties.Settings.Default.moveTVFiles = chkMoveTVFiles.IsChecked.Value;
  4837. Properties.Settings.Default.Save();
  4838. }
  4839. }
  4840. private void chkMoveTVFiles_Checked(object sender, RoutedEventArgs e)
  4841. {
  4842. chkMoveTVFiles_ValueChanged(sender, e);
  4843. }
  4844. private void chkMoveTVFiles_Unchecked(object sender, RoutedEventArgs e)
  4845. {
  4846. chkMoveTVFiles_ValueChanged(sender, e);
  4847. }
  4848. #endregion
  4849. #region Rename TV Files
  4850. private void chkRenameTVFiles_ValueChanged(object sender, RoutedEventArgs e)
  4851. {
  4852. if (WindowLoaded)
  4853. {
  4854. Properties.Settings.Default.renameTVFiles = chkRenameTVFiles.IsChecked.Value;
  4855. Properties.Settings.Default.Save();
  4856. }
  4857. }
  4858. private void chkRenameTVFiles_Checked(object sender, RoutedEventArgs e)
  4859. {
  4860. chkRenameTVFiles_ValueChanged(sender, e);
  4861. }
  4862. private void chkRenameTVFiles_Unchecked(object sender, RoutedEventArgs e)
  4863. {
  4864. chkRenameTVFiles_ValueChanged(sender, e);
  4865. }
  4866. #endregion
  4867. #region Save TV Actors Thumb
  4868. private void chkSaveTVActors_ValueChanged(object sender, RoutedEventArgs e)
  4869. {
  4870. if (WindowLoaded)
  4871. {
  4872. Properties.Settings.Default.SaveTVActors = chkSaveTVActors.IsChecked.Value;
  4873. Properties.Settings.Default.Save();
  4874. }
  4875. }
  4876. private void chkSaveTVActors_Checked(object sender, RoutedEventArgs e)
  4877. {
  4878. chkSaveTVActors_ValueChanged(sender, e);
  4879. }
  4880. private void chkSaveTVActors_Unchecked(object sender, RoutedEventArgs e)
  4881. {
  4882. chkSaveTVActors_ValueChanged(sender, e);
  4883. }
  4884. #endregion
  4885. #endregion
  4886. #region Options 2 Season Folder and All Images Options : 8
  4887. #region Season And Specials Folder Name
  4888. private void txtSeasonFolderName_LostFocus(object sender, RoutedEventArgs e)
  4889. {
  4890. if (WindowLoaded)
  4891. {
  4892. Properties.Settings.Default.SeasonFolderName = txtSeasonFolderName.Text;
  4893. Properties.Settings.Default.Save();
  4894. }
  4895. }
  4896. private void txtSpecialsFolderName_LostFocus(object sender, RoutedEventArgs e)
  4897. {
  4898. if (WindowLoaded)
  4899. {
  4900. Properties.Settings.Default.SpecialsFolderName = txtSpecialsFolderName.Text;
  4901. Properties.Settings.Default.Save();
  4902. }
  4903. }
  4904. #endregion
  4905. #region Download All Images
  4906. private void chkdownloadAllTVImages_ValueChanged(object sender, RoutedEventArgs e)
  4907. {
  4908. if (WindowLoaded)
  4909. {
  4910. chkdownloadAllTVBackdrops.IsChecked = chkdownloadAllTVImages.IsChecked.Value;
  4911. chkdownloadAllTVBanners.IsChecked = chkdownloadAllTVImages.IsChecked.Value;
  4912. chkdownloadAllTVPosters.IsChecked = chkdownloadAllTVImages.IsChecked.Value;
  4913. chkdownloadAllTVSeasonPosters.IsChecked = chkdownloadAllTVImages.IsChecked.Value;
  4914. chkdownloadAllTVSeasonBackdrops.IsChecked = chkdownloadAllTVImages.IsChecked.Value;
  4915. Properties.Settings.Default.downloadAllTVImages = chkdownloadAllTVImages.IsChecked.Value;
  4916. Properties.Settings.Default.Save();
  4917. }
  4918. }
  4919. private void chkdownloadAllTVImages_Checked(object sender, RoutedEventArgs e)
  4920. {
  4921. chkdownloadAllTVImages_ValueChanged(sender, e);
  4922. }
  4923. private void chkdownloadAllTVImages_Unchecked(object sender, RoutedEventArgs e)
  4924. {
  4925. chkdownloadAllTVImages_ValueChanged(sender, e);
  4926. }
  4927. #endregion
  4928. #region Download All Posters
  4929. private void chkdownloadAllTVPosters_ValueChanged(object sender, RoutedEventArgs e)
  4930. {
  4931. if (WindowLoaded)
  4932. {
  4933. Properties.Settings.Default.downloadAllTVPosters = chkdownloadAllTVPosters.IsChecked.Value;
  4934. Properties.Settings.Default.Save();
  4935. }
  4936. }
  4937. private void chkdownloadAllTVPosters_Checked(object sender, RoutedEventArgs e)
  4938. {
  4939. chkdownloadAllTVPosters_ValueChanged(sender, e);
  4940. }
  4941. private void chkdownloadAllTVPosters_Unchecked(object sender, RoutedEventArgs e)
  4942. {
  4943. chkdownloadAllTVPosters_ValueChanged(sender, e);
  4944. }
  4945. #endregion
  4946. #region Download All Backdrops
  4947. private void chkdownloadAllTVBackdrops_ValueChanged(object sender, RoutedEventArgs e)
  4948. {
  4949. if (WindowLoaded)
  4950. {
  4951. Properties.Settings.Default.downloadAllTVBackdrops = chkdownloadAllTVBackdrops.IsChecked.Value;
  4952. Properties.Settings.Default.Save();
  4953. }
  4954. }
  4955. private void chkdownloadAllTVBackdrops_Checked(object sender, RoutedEventArgs e)
  4956. {
  4957. chkdownloadAllTVBackdrops_ValueChanged(sender, e);
  4958. }
  4959. private void chkdownloadAllTVBackdrops_Unchecked(object sender, RoutedEventArgs e)
  4960. {
  4961. chkdownloadAllTVBackdrops_ValueChanged(sender, e);
  4962. }
  4963. #endregion
  4964. #region Download All Banners
  4965. private void chkdownloadAllTVBanners_ValueChanged(object sender, RoutedEventArgs e)
  4966. {
  4967. if (WindowLoaded)
  4968. {
  4969. Properties.Settings.Default.downloadAllTVBanners = chkdownloadAllTVBanners.IsChecked.Value;
  4970. Properties.Settings.Default.Save();
  4971. }
  4972. }
  4973. private void chkdownloadAllTVBanners_Checked(object sender, RoutedEventArgs e)
  4974. {
  4975. chkdownloadAllTVBanners_ValueChanged(sender, e);
  4976. }
  4977. private void chkdownloadAllTVBanners_Unchecked(object sender, RoutedEventArgs e)
  4978. {
  4979. chkdownloadAllTVBanners_ValueChanged(sender, e);
  4980. }
  4981. #endregion
  4982. #region Download All Season Posters
  4983. private void chkdownloadAllTVSeasonPosters_ValueChanged(object sender, RoutedEventArgs e)
  4984. {
  4985. if (WindowLoaded)
  4986. {
  4987. Properties.Settings.Default.downloadAllTVSeasonPosters = chkdownloadAllTVSeasonPosters.IsChecked.Value;
  4988. Properties.Settings.Default.Save();
  4989. }
  4990. }
  4991. private void chkdownloadAllTVSeasonPosters_Checked(object sender, RoutedEventArgs e)
  4992. {
  4993. chkdownloadAllTVSeasonPosters_ValueChanged(sender, e);
  4994. }
  4995. private void chkdownloadAllTVSeasonPosters_Unchecked(object sender, RoutedEventArgs e)
  4996. {
  4997. chkdownloadAllTVSeasonPosters_ValueChanged(sender, e);
  4998. }
  4999. #endregion
  5000. #region Download All Season Backdrops
  5001. private void chkdownloadAllTVSeasonBackdrops_ValueChanged(object sender, RoutedEventArgs e)
  5002. {
  5003. if (WindowLoaded)
  5004. {
  5005. Properties.Settings.Default.downloadAllTVSeasonBackdrops = chkdownloadAllTVSeasonBackdrops.IsChecked.Value;
  5006. Properties.Settings.Default.Save();
  5007. }
  5008. }
  5009. private void chkdownloadAllTVSeasonBackdrops_Checked(object sender, RoutedEventArgs e)
  5010. {
  5011. chkdownloadAllTVSeasonBackdrops_ValueChanged(sender, e);
  5012. }
  5013. private void chkdownloadAllTVSeasonBackdrops_Unchecked(object sender, RoutedEventArgs e)
  5014. {
  5015. chkdownloadAllTVSeasonBackdrops_ValueChanged(sender, e);
  5016. }
  5017. #endregion
  5018. #endregion
  5019. #region Options 3 Rename TV Files Options : 3
  5020. #region TV Rename Format
  5021. private void txtTVRenameFormat_LostFocus(object sender, RoutedEventArgs e)
  5022. {
  5023. if (WindowLoaded)
  5024. {
  5025. Properties.Settings.Default.TVfileformat = txtTVRenameFormat.Text;
  5026. Properties.Settings.Default.Save();
  5027. }
  5028. }
  5029. #endregion
  5030. #region Season Zero Pad Format
  5031. private void txtSeasonNumZeroPadding_LostFocus(object sender, RoutedEventArgs e)
  5032. {
  5033. if (WindowLoaded)
  5034. {
  5035. Properties.Settings.Default.SeasonNumZeroPadding = txtSeasonNumZeroPadding.Text;
  5036. Properties.Settings.Default.Save();
  5037. }
  5038. }
  5039. #endregion
  5040. #region Episode Zero Pad Format
  5041. private void txtEpisodeNumZeroPadding_LostFocus(object sender, RoutedEventArgs e)
  5042. {
  5043. if (WindowLoaded)
  5044. {
  5045. Properties.Settings.Default.EpisodeNumZeroPadding = txtEpisodeNumZeroPadding.Text;
  5046. Properties.Settings.Default.Save();
  5047. }
  5048. }
  5049. #endregion
  5050. #region Rename FormatText Changed (Not a Saveable Option)
  5051. private void txtTVRenameFormat_TextChanged(object sender, TextChangedEventArgs e)
  5052. {
  5053. setTVRenameExample();
  5054. }
  5055. private void txtSeasonNumZeroPad_TextChanged(object sender, TextChangedEventArgs e)
  5056. {
  5057. setTVRenameExample();
  5058. }
  5059. private void txtEpisodeNumZeroPad_TextChanged(object sender, TextChangedEventArgs e)
  5060. {
  5061. setTVRenameExample();
  5062. }
  5063. private void setTVRenameExample()
  5064. {
  5065. //Wrap this in a try because when MediaScout is initially loading the user set options, some of the UI
  5066. // elements do not exist yet and can crash
  5067. try
  5068. {
  5069. String ExampleFormat = makeEpisodeTargetName("Series Name", "1", "Episode Name", "3", "Suffix", ".ext");
  5070. if (ExampleFormat.Length > 0)
  5071. lblTVRenameExample.Content = ExampleFormat;
  5072. else
  5073. lblTVRenameExample.Content = "invalid";
  5074. }
  5075. catch { }
  5076. }
  5077. private String makeEpisodeTargetName(String SeriesName, String SeasonNum, String EpisodeName, String EpisodeNum, String Suffix, String FileExtention)
  5078. {
  5079. //Wrap this whole thing in a TRY/CATCH because an invalid format pettern would cause a crash
  5080. try
  5081. {
  5082. //Strip out the suffix from the rename format, alog with any leading characters that are not {varibles}
  5083. String TargetName = Regex.Replace(txtTVRenameFormat.Text, @"([^\}]*?\{4\}[^\{]*)", @"");
  5084. TargetName = String.Format(TargetName + FileExtention,
  5085. SeriesName,
  5086. SeasonNum.PadLeft(Int32.Parse(txtSeasonNumZeroPadding.Text), '0'),
  5087. EpisodeName,
  5088. EpisodeNum.PadLeft(Int32.Parse(txtEpisodeNumZeroPadding.Text), '0'));
  5089. // Should do sone "file safe" character checking here (or earlier)
  5090. return TargetName;
  5091. }
  5092. catch
  5093. {
  5094. // Could probably do something more graceful
  5095. return null;
  5096. }
  5097. }
  5098. #endregion
  5099. #endregion
  5100. #endregion
  5101. #region Movies Options Routines : 12
  5102. #region Sets the Movie Folders
  5103. private void btnSetMovieFolders_Click(object sender, RoutedEventArgs e)
  5104. {
  5105. FoldersDialog fd = new FoldersDialog(true);
  5106. fd.Owner = this;
  5107. if (fd.ShowDialog() == true)
  5108. {
  5109. if (Properties.Settings.Default.MovieFolders == null)
  5110. Properties.Settings.Default.MovieFolders = new System.Collections.Specialized.StringCollection();
  5111. else
  5112. Properties.Settings.Default.MovieFolders.Clear();
  5113. foreach (String dir in fd.lstFolders.Items)
  5114. Properties.Settings.Default.MovieFolders.Add(dir);
  5115. Properties.Settings.Default.Save();
  5116. resetMoviefolder = true;
  5117. }
  5118. }
  5119. #endregion
  5120. #region Movie DropBox Location
  5121. private void ChangeMonitorMovieFolder()
  5122. {
  5123. if (Directory.Exists(txtMovieDropBox.Text))
  5124. chkMovieFSWatcher.IsEnabled = true;
  5125. }
  5126. private void MovieDropBoxFolderChanged()
  5127. {
  5128. if (WindowLoaded)
  5129. {
  5130. if (Properties.Settings.Default.MovieDropBoxLocation != txtMovieDropBox.Text)
  5131. {
  5132. Properties.Settings.Default.MovieDropBoxLocation = txtMovieDropBox.Text;
  5133. Properties.Settings.Default.Save();
  5134. ChangeMonitorMovieFolder();
  5135. }
  5136. }
  5137. }
  5138. private void txtMovieDropBox_LostFocus(object sender, RoutedEventArgs e)
  5139. {
  5140. MovieDropBoxFolderChanged();
  5141. }
  5142. private void btnBrowserMovieDropBox_Click(object sender, RoutedEventArgs e)
  5143. {
  5144. System.Windows.Forms.FolderBrowserDialog myBrowser = new System.Windows.Forms.FolderBrowserDialog();
  5145. myBrowser.Description = "Select Movies DropBox folder";
  5146. if (Directory.Exists(txtMovieDropBox.Text))
  5147. myBrowser.SelectedPath = txtMovieDropBox.Text;
  5148. if (myBrowser.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  5149. {
  5150. txtMovieDropBox.Text = myBrowser.SelectedPath;
  5151. MovieDropBoxFolderChanged();
  5152. }
  5153. }
  5154. #endregion
  5155. #region Movie FS Watcher Checkbox Functions
  5156. private void chkMovieFSWatcher_ValueChanged(object sender, RoutedEventArgs e)
  5157. {
  5158. if (WindowLoaded)
  5159. {
  5160. if (MovieFSWatcher == null)
  5161. {
  5162. MovieFSWatcher = new FileSystemWatcher();
  5163. MovieFSWatcher.Path = Properties.Settings.Default.MovieDropBoxLocation;
  5164. MovieFSWatcher.IncludeSubdirectories = true;
  5165. MovieFSWatcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.DirectoryName;
  5166. MovieFSWatcher.Created += new FileSystemEventHandler(MovieFSWatcher_Changed);
  5167. MovieFSWatcher.Changed += new FileSystemEventHandler(MovieFSWatcher_Changed);
  5168. }
  5169. MovieFSWatcher.EnableRaisingEvents = chkMovieFSWatcher.IsChecked.Value;
  5170. Properties.Settings.Default.MovieFSWatcher = chkMovieFSWatcher.IsChecked.Value;
  5171. Properties.Settings.Default.Save();
  5172. }
  5173. }
  5174. private void chkMovieFSWatcher_Unchecked(object sender, RoutedEventArgs e)
  5175. {
  5176. chkMovieFSWatcher_ValueChanged(sender, e);
  5177. }
  5178. private void chkMovieFSWatcher_Checked(object sender, RoutedEventArgs e)
  5179. {
  5180. chkMovieFSWatcher_ValueChanged(sender, e);
  5181. }
  5182. #endregion
  5183. #region Options 1 Posters and Move, Rename Movie File Options : 5
  5184. #region Get Movie Posters
  5185. private void chkMoviesPosters_ValueChanged(object sender, RoutedEventArgs e)
  5186. {
  5187. if (WindowLoaded)
  5188. {
  5189. Properties.Settings.Default.getMoviePosters = chkMoviePosters.IsChecked.Value;
  5190. Properties.Settings.Default.Save();
  5191. }
  5192. }
  5193. private void chkMoviesPosters_Checked(object sender, RoutedEventArgs e)
  5194. {
  5195. chkMoviesPosters_ValueChanged(sender, e);
  5196. }
  5197. private void chkMoviesPosters_Unchecked(object sender, RoutedEventArgs e)
  5198. {
  5199. chkMoviesPosters_ValueChanged(sender, e);
  5200. }
  5201. #endregion
  5202. #region Get Movie File Posters
  5203. private void chkMovieFilePosters_ValueChanged(object sender, RoutedEventArgs e)
  5204. {
  5205. if (WindowLoaded)
  5206. {
  5207. Properties.Settings.Default.getMovieFilePosters = chkMovieFilePosters.IsChecked.Value;
  5208. Properties.Settings.Default.Save();
  5209. }
  5210. }
  5211. private void chkMovieFilePosters_Checked(object sender, RoutedEventArgs e)
  5212. {
  5213. chkMovieFilePosters_ValueChanged(sender, e);
  5214. }
  5215. private void chkMovieFilePosters_Unchecked(object sender, RoutedEventArgs e)
  5216. {
  5217. chkMovieFilePosters_ValueChanged(sender, e);
  5218. }
  5219. #endregion
  5220. #region Move Movie Files
  5221. private void chkMoveMovieFiles_ValueChanged(object sender, RoutedEventArgs e)
  5222. {
  5223. if (WindowLoaded)
  5224. {
  5225. Properties.Settings.Default.moveTVFiles = chkMoveMovieFiles.IsChecked.Value;
  5226. Properties.Settings.Default.Save();
  5227. }
  5228. }
  5229. private void chkMoveMovieFiles_Checked(object sender, RoutedEventArgs e)
  5230. {
  5231. chkMoveMovieFiles_ValueChanged(sender, e);
  5232. }
  5233. private void chkMoveMovieFiles_Unchecked(object sender, RoutedEventArgs e)
  5234. {
  5235. chkMoveMovieFiles_ValueChanged(sender, e);
  5236. }
  5237. #endregion
  5238. #region Save Movie Actors Thumb
  5239. private void chkSaveMovieActors_ValueChanged(object sender, RoutedEventArgs e)
  5240. {
  5241. if (WindowLoaded)
  5242. {
  5243. Properties.Settings.Default.SaveMovieActors = chkSaveMovieActors.IsChecked.Value;
  5244. Properties.Settings.Default.Save();
  5245. }
  5246. }
  5247. private void chkSaveMovieActors_Checked(object sender, RoutedEventArgs e)
  5248. {
  5249. chkSaveMovieActors_ValueChanged(sender, e);
  5250. }
  5251. private void chkSaveMovieActors_Unchecked(object sender, RoutedEventArgs e)
  5252. {
  5253. chkSaveMovieActors_ValueChanged(sender, e);
  5254. }
  5255. #endregion
  5256. #region Rename Movie Files And Dir
  5257. private void chkRenameMovieFiles_ValueChanged(object sender, RoutedEventArgs e)
  5258. {
  5259. if (WindowLoaded)
  5260. {
  5261. Properties.Settings.Default.renameMovieFiles = chkRenameMovieFiles.IsChecked.Value;
  5262. Properties.Settings.Default.Save();
  5263. }
  5264. }
  5265. private void chkRenameMovieFiles_Checked(object sender, RoutedEventArgs e)
  5266. {
  5267. chkRenameMovieFiles_ValueChanged(sender, e);
  5268. }
  5269. private void chkRenameMovieFiles_Unchecked(object sender, RoutedEventArgs e)
  5270. {
  5271. chkRenameMovieFiles_ValueChanged(sender, e);
  5272. }
  5273. #endregion
  5274. #endregion
  5275. #region Options 2 All Images Options : 3
  5276. #region Download All Movie Images
  5277. private void chkdownloadAllMovieImages_ValueChanged(object sender, RoutedEventArgs e)
  5278. {
  5279. if (WindowLoaded)
  5280. {
  5281. chkdownloadAllMovieBackdrops.IsChecked = chkdownloadAllMovieImages.IsChecked;
  5282. chkdownloadAllMoviePosters.IsChecked = chkdownloadAllMovieImages.IsChecked;
  5283. Properties.Settings.Default.downloadAllMovieImages = chkdownloadAllMovieImages.IsChecked.Value;
  5284. Properties.Settings.Default.Save();
  5285. }
  5286. }
  5287. private void chkdownloadAllMovieImages_Checked(object sender, RoutedEventArgs e)
  5288. {
  5289. chkdownloadAllMovieImages_ValueChanged(sender, e);
  5290. }
  5291. private void chkdownloadAllMovieImages_Unchecked(object sender, RoutedEventArgs e)
  5292. {
  5293. chkdownloadAllMovieImages_ValueChanged(sender, e);
  5294. }
  5295. #endregion
  5296. #region Download All Movie osters
  5297. private void chkdownloadAllMoviePosters_ValueChanged(object sender, RoutedEventArgs e)
  5298. {
  5299. if (WindowLoaded)
  5300. {
  5301. Properties.Settings.Default.downloadAllMoviePosters = chkdownloadAllMoviePosters.IsChecked.Value;
  5302. Properties.Settings.Default.Save();
  5303. }
  5304. }
  5305. private void chkdownloadAllMoviePosters_Checked(object sender, RoutedEventArgs e)
  5306. {
  5307. chkdownloadAllMoviePosters_ValueChanged(sender, e);
  5308. }
  5309. private void chkdownloadAllMoviePosters_Unchecked(object sender, RoutedEventArgs e)
  5310. {
  5311. chkdownloadAllMoviePosters_ValueChanged(sender, e);
  5312. }
  5313. #endregion
  5314. #region Download All Movie Backdrops
  5315. private void chkdownloadAllMovieBackdrops_ValueChanged(object sender, RoutedEventArgs e)
  5316. {
  5317. if (WindowLoaded)
  5318. {
  5319. Properties.Settings.Default.downloadAllMovieBackdrops = chkdownloadAllMovieBackdrops.IsChecked.Value;
  5320. Properties.Settings.Default.Save();
  5321. }
  5322. }
  5323. private void chkdownloadAllMovieBackdrops_Checked(object sender, RoutedEventArgs e)
  5324. {
  5325. chkdownloadAllMovieBackdrops_ValueChanged(sender, e);
  5326. }
  5327. private void chkdownloadAllMovieBackdrops_Unchecked(object sender, RoutedEventArgs e)
  5328. {
  5329. chkdownloadAllMovieBackdrops_ValueChanged(sender, e);
  5330. }
  5331. #endregion
  5332. #endregion
  5333. #region Options 3 Rename Movie File And Dir Options : 2
  5334. #region Movie File Rename Format
  5335. private void txtMovieFileRenameFormat_LostFocus(object sender, RoutedEventArgs e)
  5336. {
  5337. if (WindowLoaded)
  5338. {
  5339. Properties.Settings.Default.Moviefileformat = txtMovieFileRenameFormat.Text;
  5340. Properties.Settings.Default.Save();
  5341. }
  5342. }
  5343. #endregion
  5344. #region Movie Dir Rename Format
  5345. private void txtMovieDirRenameFormat_LostFocus(object sender, RoutedEventArgs e)
  5346. {
  5347. if (WindowLoaded)
  5348. {
  5349. Properties.Settings.Default.MovieDirformat = txtMovieDirRenameFormat.Text;
  5350. Properties.Settings.Default.Save();
  5351. }
  5352. }
  5353. #endregion
  5354. #region Movie Rename Format Text Changed ( Not a Saveable Option)
  5355. private void txtMovieFileRenameFormat_TextChanged(object sender, TextChangedEventArgs e)
  5356. {
  5357. setMovieFileRenameExample();
  5358. }
  5359. private void setMovieFileRenameExample()
  5360. {
  5361. //Wrap this in a try because when MediaScout is initially loading the user set options, some of the UI
  5362. // elements do not exist yet and can crash
  5363. try
  5364. {
  5365. String ExampleFormat = makeMovieTargetName(txtMovieFileRenameFormat.Text, "Movie Name", "2009", ".ext");
  5366. if (ExampleFormat.Length > 0)
  5367. lblMovieFileRenameExample.Content = ExampleFormat;
  5368. else
  5369. lblMovieFileRenameExample.Content = "invalid";
  5370. }
  5371. catch { }
  5372. }
  5373. private void txtMovieDirRenameFormat_TextChanged(object sender, TextChangedEventArgs e)
  5374. {
  5375. setMovieDirRenameExample();
  5376. }
  5377. private void setMovieDirRenameExample()
  5378. {
  5379. //Wrap this in a try because when MediaScout is initially loading the user set options, some of the UI
  5380. // elements do not exist yet and can crash
  5381. try
  5382. {
  5383. String ExampleFormat = makeMovieTargetName(txtMovieDirRenameFormat.Text, "Movie Name", "2009", "");
  5384. if (ExampleFormat.Length > 0)
  5385. lblMovieDirRenameExample.Content = ExampleFormat;
  5386. else
  5387. lblMovieDirRenameExample.Content = "invalid";
  5388. }
  5389. catch { }
  5390. }
  5391. private String makeMovieTargetName(String format, String MovieName, String Year, String FileExtention)
  5392. {
  5393. //Wrap this whole thing in a TRY/CATCH because an invalid format pettern would cause a crash
  5394. try
  5395. {
  5396. //Strip out the suffix from the rename format, alog with any leading characters that are not {varibles}
  5397. String TargetName = Regex.Replace(format, @"([^\}]*?\{4\}[^\{]*)", @"");
  5398. TargetName = String.Format(TargetName + FileExtention,
  5399. MovieName,
  5400. Year);
  5401. // Should do sone "file safe" character checking here (or earlier)
  5402. return TargetName;
  5403. }
  5404. catch
  5405. {
  5406. // Could probably do something more graceful
  5407. return null;
  5408. }
  5409. }
  5410. #endregion
  5411. #endregion
  5412. #endregion
  5413. #region Common Options : 16
  5414. #region Force Updating of Files
  5415. private void chkForceUpdate_ValueChanged(object sender, RoutedEventArgs e)
  5416. {
  5417. if (WindowLoaded)
  5418. {
  5419. Properties.Settings.Default.forceUpdate = chkForceUpdate.IsChecked.Value;
  5420. Properties.Settings.Default.Save();
  5421. }
  5422. }
  5423. private void chkForceUpdate_Checked(object sender, RoutedEventArgs e)
  5424. {
  5425. chkForceUpdate_ValueChanged(sender, e);
  5426. }
  5427. private void chkForceUpdate_Unchecked(object sender, RoutedEventArgs e)
  5428. {
  5429. chkForceUpdate_ValueChanged(sender, e);
  5430. }
  5431. #endregion
  5432. #region Hides Dialog
  5433. private void chkSilentMode_ValueChanged(object sender, RoutedEventArgs e)
  5434. {
  5435. if (WindowLoaded)
  5436. {
  5437. Properties.Settings.Default.SilentMode = chkSilentMode.IsChecked.Value;
  5438. Properties.Settings.Default.Save();
  5439. }
  5440. }
  5441. private void chkSilentMode_Checked(object sender, RoutedEventArgs e)
  5442. {
  5443. chkSilentMode_ValueChanged(sender, e);
  5444. }
  5445. private void chkSilentMode_Unchecked(object sender, RoutedEventArgs e)
  5446. {
  5447. chkSilentMode_ValueChanged(sender, e);
  5448. }
  5449. #endregion
  5450. #region Forces Search Dailog to Appear
  5451. private void chkforceEnterSearchTerm_ValueChanged(object sender, RoutedEventArgs e)
  5452. {
  5453. if (WindowLoaded)
  5454. {
  5455. Properties.Settings.Default.forceEnterSearchTerm = chkforceEnterSearchTerm.IsChecked.Value;
  5456. Properties.Settings.Default.Save();
  5457. }
  5458. }
  5459. private void chkforceEnterSearchTerm_Checked(object sender, RoutedEventArgs e)
  5460. {
  5461. chkforceEnterSearchTerm_ValueChanged(sender, e);
  5462. }
  5463. private void chkforceEnterSearchTerm_Unchecked(object sender, RoutedEventArgs e)
  5464. {
  5465. chkforceEnterSearchTerm_ValueChanged(sender, e);
  5466. }
  5467. #endregion
  5468. #region Allowed Filetypes
  5469. private void txtAllowedFiletypes_LostFocus(object sender, RoutedEventArgs e)
  5470. {
  5471. if (WindowLoaded)
  5472. {
  5473. if (Properties.Settings.Default.allowedFileTypes != txtAllowedFiletypes.Text)
  5474. {
  5475. Properties.Settings.Default.allowedFileTypes = txtAllowedFiletypes.Text;
  5476. Properties.Settings.Default.Save();
  5477. AllowedFileTypes = new List<string>(Properties.Settings.Default.allowedFileTypes.Split(';'));
  5478. resetTVfolder = true;
  5479. resetMoviefolder = true;
  5480. }
  5481. }
  5482. }
  5483. #endregion
  5484. #region Allowed Subtitles
  5485. private void txtAllowedSubtitles_LostFocus(object sender, RoutedEventArgs e)
  5486. {
  5487. if (WindowLoaded)
  5488. {
  5489. Properties.Settings.Default.allowedSubtitles = txtAllowedSubtitles.Text;
  5490. Properties.Settings.Default.Save();
  5491. AllowedSubtitleTypes = new List<string>(Properties.Settings.Default.allowedSubtitles.Split(';'));
  5492. }
  5493. }
  5494. #endregion
  5495. #region Search Term Filters
  5496. private void txtSearchTermFilters_LostFocus(object sender, RoutedEventArgs e)
  5497. {
  5498. if (WindowLoaded)
  5499. {
  5500. Properties.Settings.Default.SearchTermFilters = txtSearchTermFilters.Text;
  5501. Properties.Settings.Default.Save();
  5502. }
  5503. }
  5504. #endregion
  5505. #region Enable Glass Frame
  5506. private void chkEnableGlassFrame_ValueChanged(object sender, RoutedEventArgs e)
  5507. {
  5508. if (WindowLoaded)
  5509. {
  5510. SetGlassFrame(chkEnableGlassFrame.IsChecked.Value);
  5511. Properties.Settings.Default.EnableGlassFrame = chkEnableGlassFrame.IsChecked.Value;
  5512. Properties.Settings.Default.Save();
  5513. }
  5514. }
  5515. private void chkEnableGlassFrame_Checked(object sender, RoutedEventArgs e)
  5516. {
  5517. chkEnableGlassFrame_ValueChanged(sender, e);
  5518. }
  5519. private void chkEnableGlassFrame_Unchecked(object sender, RoutedEventArgs e)
  5520. {
  5521. chkEnableGlassFrame_ValueChanged(sender, e);
  5522. }
  5523. #endregion
  5524. #region Save XBMC Meta
  5525. private void chkSaveXBMCMeta_ValueChanged(object sender, RoutedEventArgs e)
  5526. {
  5527. if (WindowLoaded)
  5528. {
  5529. Properties.Settings.Default.SaveXBMCMeta = chkSaveXBMCMeta.IsChecked.Value;
  5530. Properties.Settings.Default.Save();
  5531. }
  5532. }
  5533. private void chkSaveXBMCMeta_Checked(object sender, RoutedEventArgs e)
  5534. {
  5535. chkSaveXBMCMeta_ValueChanged(sender, e);
  5536. }
  5537. private void chkSaveXBMCMeta_Unchecked(object sender, RoutedEventArgs e)
  5538. {
  5539. chkSaveXBMCMeta_ValueChanged(sender, e);
  5540. }
  5541. #endregion
  5542. #region Save MyMovies Meta
  5543. private void chkSaveMMMeta_ValueChanged(object sender, RoutedEventArgs e)
  5544. {
  5545. if (WindowLoaded)
  5546. {
  5547. Properties.Settings.Default.SaveMyMoviesMeta = chkSaveMMMeta.IsChecked.Value;
  5548. Properties.Settings.Default.Save();
  5549. }
  5550. }
  5551. private void chkSaveMMMeta_Checked(object sender, RoutedEventArgs e)
  5552. {
  5553. chkSaveMMMeta_ValueChanged(sender, e);
  5554. }
  5555. private void chkSaveMMMeta_Unchecked(object sender, RoutedEventArgs e)
  5556. {
  5557. chkSaveMMMeta_ValueChanged(sender, e);
  5558. }
  5559. #endregion
  5560. #region Set Sublight Options 4
  5561. private void btnSetSublightOptions_Click(object sender, RoutedEventArgs e)
  5562. {
  5563. SublightOptionsDialog sod = new SublightOptionsDialog();
  5564. sod.Owner = this;
  5565. if (sod.ShowDialog() == true)
  5566. {
  5567. Properties.Settings.Default.SublightUsername = sod.txtSublightUsername.Text;
  5568. Properties.Settings.Default.SublightPassword = sod.txtSublightPassword.Text;
  5569. Properties.Settings.Default.SublightCmd = sod.txtSublightCmd.Text;
  5570. Properties.Settings.Default.Sublight = sod.txtSublight.Text;
  5571. Properties.Settings.Default.Save();
  5572. }
  5573. }
  5574. #endregion
  5575. #region Overwrite Files
  5576. private void chkOverwrite_ValueChanged(object sender, RoutedEventArgs e)
  5577. {
  5578. if (WindowLoaded)
  5579. {
  5580. Properties.Settings.Default.overwriteFiles = chkOverwrite.IsChecked.Value;
  5581. Properties.Settings.Default.Save();
  5582. }
  5583. }
  5584. private void chkOverwrite_Unchecked(object sender, RoutedEventArgs e)
  5585. {
  5586. chkOverwrite_ValueChanged(sender, e);
  5587. }
  5588. private void chkOverwrite_Checked(object sender, RoutedEventArgs e)
  5589. {
  5590. chkOverwrite_ValueChanged(sender, e);
  5591. }
  5592. #endregion
  5593. #region ImagesByName Location
  5594. private void btnBrowseIBN_Click(object sender, RoutedEventArgs e)
  5595. {
  5596. if (WindowLoaded)
  5597. {
  5598. System.Windows.Forms.FolderBrowserDialog myBrowser = new System.Windows.Forms.FolderBrowserDialog();
  5599. myBrowser.Description = "Select ImagesByName Folder";
  5600. if (Directory.Exists(txtImagesByName.Text))
  5601. myBrowser.SelectedPath = txtImagesByName.Text;
  5602. if (myBrowser.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  5603. {
  5604. txtImagesByName.Text = myBrowser.SelectedPath;
  5605. if (Properties.Settings.Default.ImagesByNameLocation != txtImagesByName.Text)
  5606. {
  5607. Properties.Settings.Default.ImagesByNameLocation = txtImagesByName.Text;
  5608. Properties.Settings.Default.Save();
  5609. }
  5610. }
  5611. }
  5612. }
  5613. private void txtImagesByName_LostFocus(object sender, RoutedEventArgs e)
  5614. {
  5615. if (WindowLoaded)
  5616. {
  5617. if (Properties.Settings.Default.ImagesByNameLocation != txtImagesByName.Text)
  5618. {
  5619. Properties.Settings.Default.ImagesByNameLocation = txtImagesByName.Text;
  5620. Properties.Settings.Default.Save();
  5621. }
  5622. }
  5623. }
  5624. #endregion
  5625. #region Auto Select Movie Title
  5626. private void chkAutoSelectMovieTitle_ValueChanged(object sender, RoutedEventArgs e)
  5627. {
  5628. if (WindowLoaded)
  5629. {
  5630. Properties.Settings.Default.AutoSelectMovieTitle = chkAutoSelectMovieTitle.IsChecked.Value;
  5631. Properties.Settings.Default.Save();
  5632. }
  5633. }
  5634. private void chkAutoSelectMovieTitle_Checked(object sender, RoutedEventArgs e)
  5635. {
  5636. chkAutoSelectMovieTitle_ValueChanged(sender, e);
  5637. }
  5638. private void chkAutoSelectMovieTitle_Unchecked(object sender, RoutedEventArgs e)
  5639. {
  5640. chkAutoSelectMovieTitle_ValueChanged(sender, e);
  5641. }
  5642. #endregion
  5643. #region Search Term Filters
  5644. private void txtFilenameReplaceChar_LostFocus(object sender, RoutedEventArgs e)
  5645. {
  5646. if (WindowLoaded)
  5647. {
  5648. Properties.Settings.Default.FilenameReplaceChar = txtFilenameReplaceChar.Text;
  5649. Properties.Settings.Default.Save();
  5650. }
  5651. }
  5652. #endregion
  5653. private void btnAbout_Click(object sender, RoutedEventArgs e)
  5654. {
  5655. About ab = new About(false);
  5656. ab.Owner = this;
  5657. ab.ShowDialog();
  5658. }
  5659. private void btnReset_Click(object sender, RoutedEventArgs e)
  5660. {
  5661. if (MessageBox.Show(this, "Are You sure you want to reset all settings?", "MediaScout", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes)
  5662. {
  5663. Properties.Settings.Default.Reset();
  5664. LoadOptions();
  5665. }
  5666. }
  5667. #endregion
  5668. #endregion
  5669. #region TVDb Tab Routines
  5670. private void btnOpenTVDb_Click(object sender, RoutedEventArgs e)
  5671. {
  5672. if (SelectedTVShow.ID != null)
  5673. System.Diagnostics.Process.Start("http://thetvdb.com/?tab=series&id=" + SelectedTVShow.ID + "&lid=7");
  5674. else
  5675. System.Diagnostics.Process.Start("http://thetvdb.com/?string=" + SelectedTVShow.Name + "&searchseriesid=&tab=listseries&function=Search");
  5676. }
  5677. #endregion
  5678. #region TMDb Tab Routines
  5679. private void btnOpenTMDb_Click(object sender, RoutedEventArgs e)
  5680. {
  5681. if (SelectedMovie.ID != null)
  5682. System.Diagnostics.Process.Start("http://www.themoviedb.org/movie/" + SelectedMovie.ID);
  5683. }
  5684. #endregion
  5685. #region Windows Mouse Wheel Routines
  5686. //protected override void OnPreviewMouseWheel(MouseWheelEventArgs args)
  5687. //{
  5688. // base.OnPreviewMouseWheel(args);
  5689. // if (Keyboard.IsKeyDown(Key.LeftCtrl) ||
  5690. // Keyboard.IsKeyDown(Key.RightCtrl))
  5691. // zoomslider.Value += (args.Delta > 0) ? 0.1 : -0.1;
  5692. //}
  5693. //protected override void OnPreviewMouseDown(MouseButtonEventArgs args)
  5694. //{
  5695. // base.OnPreviewMouseDown(args);
  5696. // if (Keyboard.IsKeyDown(Key.LeftCtrl) ||
  5697. // Keyboard.IsKeyDown(Key.RightCtrl))
  5698. // if (args.MiddleButton == MouseButtonState.Pressed)
  5699. // zoomslider.ResetZoom();
  5700. //}
  5701. #endregion
  5702. #region Save Routines
  5703. private void btnSaveTVShow_Click(object sender, RoutedEventArgs e)
  5704. {
  5705. if (Properties.Settings.Default.SaveMyMoviesMeta)
  5706. SelectedTVShow.XMLBase.SaveXML(SelectedTVShow.Folderpath);
  5707. if (Properties.Settings.Default.SaveXBMCMeta)
  5708. SelectedTVShow.NFOBase.Save(SelectedTVShow.NFOFile);
  5709. SelectedTVShow.MetadataChanged = false;
  5710. }
  5711. private void btnSaveMovie_Click(object sender, RoutedEventArgs e)
  5712. {
  5713. if (Properties.Settings.Default.SaveMyMoviesMeta)
  5714. SelectedMovie.XMLBase.SaveXML(SelectedMovie.Folderpath);
  5715. if (Properties.Settings.Default.SaveXBMCMeta)
  5716. SelectedMovie.NFOBase.Save(SelectedMovie.NFOFile);
  5717. SelectedMovie.MetadataChanged = false;
  5718. }
  5719. private void btnSaveEpisode_Click(object sender, RoutedEventArgs e)
  5720. {
  5721. if (Properties.Settings.Default.SaveMyMoviesMeta)
  5722. SelectedEpisode.XMLBase.SaveXML(SelectedEpisode.Season.Folderpath, SelectedEpisode.StrippedFileName);
  5723. if (Properties.Settings.Default.SaveXBMCMeta)
  5724. SelectedEpisode.NFOBase.Save(SelectedEpisode.NFOFile);
  5725. SelectedEpisode.MetadataChanged = false;
  5726. }
  5727. #endregion
  5728. #region Search Routines
  5729. public bool TVShowSearchContains(object tvshow)
  5730. {
  5731. TVShow ts = tvshow as TVShow;
  5732. bool success = false;
  5733. //Return members whose Orders have not been filled
  5734. success = (ts.Name.LastIndexOf(txtSearchTVShow.Text, StringComparison.CurrentCultureIgnoreCase) != -1)
  5735. ||
  5736. (ts.Year!=null && ts.Year.LastIndexOf(txtSearchTVShow.Text) != -1)
  5737. ||
  5738. (ts.Genre !=null && ts.Genre.Contains(new MediaScout.Genre() { name = txtSearchTVShow.Text }));
  5739. return success;
  5740. }
  5741. private void txtSearchTVShow_Search(object sender, RoutedEventArgs e)
  5742. {
  5743. CollectionView source = CollectionViewSource.GetDefaultView(tvTVShows.ItemsSource) as CollectionView;
  5744. source.Filter += new Predicate<object>(TVShowSearchContains);
  5745. }
  5746. public bool MovieSearchContains(object movie)
  5747. {
  5748. Movie m = movie as Movie;
  5749. bool success = false;
  5750. //Return members whose Orders have not been filled
  5751. success = (m.Name.LastIndexOf(txtSearchMovie.Text, StringComparison.CurrentCultureIgnoreCase) != -1)
  5752. ||
  5753. (m.Year != null && m.Year.LastIndexOf(txtSearchMovie.Text) != -1)
  5754. ||
  5755. (m.Genre != null && m.Genre.Contains(new MediaScout.Genre() { name = txtSearchMovie.Text }));
  5756. return success;
  5757. }
  5758. private void txtSearchMovie_Search(object sender, RoutedEventArgs e)
  5759. {
  5760. CollectionView source = CollectionViewSource.GetDefaultView(lbMovies.ItemsSource) as CollectionView;
  5761. source.Filter += new Predicate<object>(MovieSearchContains);
  5762. }
  5763. #endregion #endregion
  5764. }
  5765. public enum ImageWindowDecisionbType
  5766. {
  5767. PosterSelected,
  5768. DownloadAll,
  5769. LocalPosterSelected,
  5770. Cancel
  5771. }
  5772. public enum DecisionType
  5773. {
  5774. Continue,
  5775. Cancel,
  5776. Skip,
  5777. SearchAgain
  5778. }
  5779. }