PageRenderTime 91ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 1ms

/Branches/krishmav/MediaScout/MainWindow.xaml.cs

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