/animeplugin3/MyAnimePlugin3/Windows/MainWindow.cs
C# | 6383 lines | 4770 code | 1172 blank | 441 comment | 1268 complexity | 2668427969cd4f7a48e0ceea8b6abd0b MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- using System;
- using System.Collections.Generic;
- using System.Windows.Forms;
- using ConsoleApplication2.com.amazon.webservices;
- using MediaPortal.GUI.Library;
- using MediaPortal.Dialogs;
- using MyAnimePlugin3.ConfigFiles;
- using MyAnimePlugin3.DataHelpers;
- using System.IO;
- using Cornerstone.MP;
- using System.ComponentModel;
- using System.Threading;
- using System.Xml;
- using BinaryNorthwest;
- using System.Runtime.InteropServices;
- using MyAnimePlugin3.Downloads;
- using Action = MediaPortal.GUI.Library.Action;
- using System.Collections;
- using MyAnimePlugin3.ViewModel;
- using MyAnimePlugin3.ImageManagement;
- using MyAnimePlugin3.MultiSortLib;
- using MediaPortal.Player;
-
- namespace MyAnimePlugin3
- {
- public class MainWindow : GUIWindow, ISetupForm
- {
- #region GUI Controls
-
- [SkinControlAttribute(2)]
- protected GUIButtonControl btnDisplayOptions = null;
- //[SkinControlAttribute(3)] protected GUIButtonControl btnLayout = null;
- [SkinControlAttribute(4)]
- protected GUIButtonControl btnSettings = null;
- [SkinControlAttribute(11)]
- protected GUIButtonControl btnChangeLayout = null;
- [SkinControlAttribute(12)]
- protected GUIButtonControl btnSwitchUser = null;
-
- [SkinControlAttribute(920)] protected GUIButtonControl btnWindowContinueWatching = null;
- [SkinControlAttribute(921)] protected GUIButtonControl btnWindowUtilities = null;
- [SkinControlAttribute(922)] protected GUIButtonControl btnWindowCalendar = null;
- [SkinControlAttribute(923)] protected GUIButtonControl btnWindowDownloads = null;
- //[SkinControlAttribute(924)] protected GUIButtonControl btnWindowCollectionStats = null;
- [SkinControlAttribute(925)] protected GUIButtonControl btnWindowRecommendations = null;
- [SkinControlAttribute(926)] protected GUIButtonControl btnWindowRandom = null;
- [SkinControlAttribute(927)] protected GUIButtonControl btnWindowPlaylists = null;
-
- [SkinControlAttribute(50)]
- protected GUIFacadeControl m_Facade = null;
- //[SkinControlAttribute(51)]
- //protected GUIListControl test = null;
-
- //[SkinControlAttribute(526)] protected GUIImage loadingImage = null;
-
- // let the skins react to what we are displaying
- // all these controls are imported from Anime3_Dummy.xml
- [SkinControlAttribute(1232)]
- protected GUILabelControl dummyIsFanartLoaded = null;
- [SkinControlAttribute(1233)]
- protected GUILabelControl dummyIsDarkFanartLoaded = null;
- [SkinControlAttribute(1234)]
- protected GUILabelControl dummyIsLightFanartLoaded = null;
- [SkinControlAttribute(1235)]
- protected GUILabelControl dummyLayoutListMode = null;
- [SkinControlAttribute(1236)]
- protected GUILabelControl dummyLayoutFilmstripMode = null;
- [SkinControlAttribute(1242)]
- protected GUILabelControl dummyLayoutWideBanners = null;
-
- [SkinControlAttribute(1237)]
- protected GUILabelControl dummyIsSeries = null;
- [SkinControlAttribute(1238)]
- protected GUILabelControl dummyIsGroups = null;
- [SkinControlAttribute(1250)]
- protected GUILabelControl dummyIsGroupFilters = null;
- [SkinControlAttribute(1239)]
- protected GUILabelControl dummyIsEpisodes = null;
- [SkinControlAttribute(1240)]
- protected GUILabelControl dummyIsEpisodeTypes = null;
-
- [SkinControlAttribute(1241)]
- protected GUILabelControl dummyIsFanartColorAvailable = null;
-
- [SkinControlAttribute(1243)]
- protected GUILabelControl dummyIsWatched = null;
- [SkinControlAttribute(1244)]
- protected GUILabelControl dummyIsAvailable = null;
-
- [SkinControlAttribute(1245)]
- protected GUILabelControl dummyFave = null;
- [SkinControlAttribute(1246)]
- protected GUILabelControl dummyMissingEps = null;
- [SkinControlAttribute(1247)]
- protected GUILabelControl dummyUserHasVotedSeries = null;
-
- [SkinControlAttribute(3401)]
- protected GUILabelControl dummyQueueAniDB = null;
- [SkinControlAttribute(3402)]
- protected GUILabelControl dummyQueueHasher = null;
- [SkinControlAttribute(3403)]
- protected GUILabelControl dummyQueueImages = null;
-
- [SkinControlAttribute(3463)]
- protected GUIControl dummyFindActive = null;
- [SkinControlAttribute(3464)]
- protected GUIControl dummyFindModeT9 = null;
- [SkinControlAttribute(3465)]
- protected GUIControl dummyFindModeText = null;
-
- #endregion
-
- public static Listlevel listLevel = Listlevel.GroupFilter;
- public static object parentLevelObject = null;
- private static Random groupRandom = new Random();
-
- public static RandomSeriesEpisodeLevel RandomWindow_RandomLevel = RandomSeriesEpisodeLevel.All;
- public static RandomObjectType RandomWindow_RandomType = RandomObjectType.Series;
- public static object RandomWindow_LevelObject = null;
- public static AnimeSeriesVM RandomWindow_CurrentSeries = null;
- public static AnimeEpisodeVM RandomWindow_CurrentEpisode = null;
- public static int RandomWindow_MatchesFound = 0;
-
- public static bool RandomWindow_SeriesWatched = true;
- public static bool RandomWindow_SeriesUnwatched = true;
- public static bool RandomWindow_SeriesPartiallyWatched = true;
- public static bool RandomWindow_SeriesOnlyComplete = true;
- public static bool RandomWindow_SeriesAllCategories = true;
- public static string RandomWindow_SeriesCategories = "";
-
- public static bool RandomWindow_EpisodeWatched = true;
- public static bool RandomWindow_EpisodeUnwatched = true;
- public static bool RandomWindow_EpisodeAllCategories = true;
- public static string RandomWindow_EpisodeCategories = "";
-
- //private bool fanartSet = false;
-
- private readonly int artworkDelay = 5;
- private System.Timers.Timer displayGrpFilterTimer = null;
- private System.Timers.Timer displayGrpTimer = null;
-
- public static int? animeSeriesIDToBeRated = null;
-
- public static AnimePluginSettings settings = null;
- public static JMMServerHelper ServerHelper = new JMMServerHelper();
-
- public static List<string> completedTorrents = new List<string>();
- public static DownloadSearchCriteria currentDownloadSearch = null;
- public static List<DownloadSearchCriteria> downloadSearchHistory = new List<DownloadSearchCriteria>();
- public static List<List<TorrentLink>> downloadSearchResultsHistory = new List<List<TorrentLink>>();
-
- public static int LastFocusType = -1; //
- public static int LastFocusID = -1; //
-
-
- public static int GlobalSeriesID = -1; // either AnimeSeriesID
- public static int GlobalAnimeID = -1; // AnimeID
- public static int GlobalSeiyuuID = -1; // SeiyuuID
-
- public static int CurrentCalendarMonth = DateTime.Now.Month;
- public static int CurrentCalendarYear = DateTime.Now.Year;
- public static int CurrentCalendarButton = 4;
-
- public static VideoHandler vidHandler;
-
- public static UTorrentHelper uTorrent = new UTorrentHelper();
-
- public static View currentView = null;
- public static ViewClassification currentViewClassification = ViewClassification.Views;
- public static string currentStaticViewID = ""; // used to stored current year, genre etc in static views
-
- private GUIFacadeControl.Layout groupViewMode = GUIFacadeControl.Layout.List; // Poster List
- private GUIFacadeControl.Layout seriesViewMode = GUIFacadeControl.Layout.List;
- //private GUIFacadeControl.Layout episodeTypesViewMode = GUIFacadeControl.Layout.List; // List
- private GUIFacadeControl.Layout episodesViewMode = GUIFacadeControl.Layout.List; // List
-
- private List<GUIListItem> itemsForDelayedImgLoading = null;
-
- private BackgroundWorker workerFacade = null;
- private BackgroundWorker downloadImagesWorker = new BackgroundWorker();
- public static ImageDownloader imageHelper = null;
-
- private AsyncImageResource listPoster = null;
- private AsyncImageResource fanartTexture = null;
- //private bool isInitialGroupLoad = true;
-
- public static GroupFilterVM curGroupFilter = null;
- public static GroupFilterVM curGroupFilterSub = null;
- public static GroupFilterVM curGroupFilterSub2 = null;
- public static AnimeGroupVM curAnimeGroup = null;
- public static AnimeGroupVM curAnimeGroupViewed = null;
- public static AnimeSeriesVM curAnimeSeries = null;
- public static AnimeEpisodeTypeVM curAnimeEpisodeType = null;
- private AnimeEpisodeVM curAnimeEpisode = null;
-
- Dictionary<int, QuickSort> GroupFilterQuickSorts = null;
-
-
-
- private System.Timers.Timer searchTimer = null;
- private System.Timers.Timer autoUpdateTimer = null;
- private SearchCollection search = null;
- private List<GUIListItem> lstFacadeItems = null;
- private string searchSound = "click.wav";
-
- public delegate void OnToggleWatchedHandler(List<AnimeEpisodeVM> episodes, bool state);
- public event OnToggleWatchedHandler OnToggleWatched;
- protected void ToggleWatchedEvent(List<AnimeEpisodeVM> episodes, bool state)
- {
- if (OnToggleWatched != null)
- {
- OnToggleWatched(episodes, state);
- }
- }
-
- public delegate void OnRateSeriesHandler(AnimeSeriesVM series, string rateValue);
- public event OnRateSeriesHandler OnRateSeries;
- protected void RateSeriesEvent(AnimeSeriesVM series, string rateValue)
- {
- if (OnRateSeries != null)
- {
- OnRateSeries(series, rateValue);
- }
- }
-
- public MainWindow()
- {
- // get ID of windowplugin belonging to this setup
- // enter your own unique code
- GetID = Constants.PlugInInfo.ID;
-
- try
- {
- settings = new AnimePluginSettings();
-
- imageHelper = new ImageDownloader();
- imageHelper.Init();
-
- listPoster = new AsyncImageResource();
- listPoster.Property = "#Anime3.GroupSeriesPoster";
- listPoster.Delay = artworkDelay;
-
- fanartTexture = new AsyncImageResource();
- fanartTexture.Property = "#Anime3.Fanart.1";
- fanartTexture.Delay = artworkDelay;
-
- GroupFilterQuickSorts = new Dictionary<int, QuickSort>();
-
- //searching
- searchTimer = new System.Timers.Timer();
- searchTimer.AutoReset = true;
- searchTimer.Interval = settings.FindTimeout_s * 1000;
- searchTimer.Elapsed += new System.Timers.ElapsedEventHandler(searchTimer_Elapsed);
-
- //set the search key sound to the same sound for the REMOTE_1 key
- Key key = new Key('1', (int)Keys.D1);
- MediaPortal.GUI.Library.Action action = new MediaPortal.GUI.Library.Action();
- ActionTranslator.GetAction(GetID, key, ref action);
- searchSound = action.SoundFileName;
-
- // timer for automatic updates
- autoUpdateTimer = new System.Timers.Timer();
- autoUpdateTimer.AutoReset = true;
- autoUpdateTimer.Interval = 5 * 60 * 1000; // 5 minutes * 60 seconds
- autoUpdateTimer.Elapsed += new System.Timers.ElapsedEventHandler(autoUpdateTimer_Elapsed);
-
- downloadImagesWorker.DoWork += new DoWorkEventHandler(downloadImagesWorker_DoWork);
-
- this.OnToggleWatched += new OnToggleWatchedHandler(MainWindow_OnToggleWatched);
-
- g_Player.PlayBackEnded += new g_Player.EndedHandler(g_Player_PlayBackEnded);
- }
- catch (Exception ex)
- {
- BaseConfig.MyAnimeLog.Write(ex.ToString());
- throw;
- }
- }
-
-
-
- void MainWindow_OnToggleWatched(List<AnimeEpisodeVM> episodes, bool state)
- {
- string msg = string.Format("OnToggleWatched: {0} / {1}", episodes.Count, state);
- BaseConfig.MyAnimeLog.Write(msg);
- }
-
- private void DownloadAllImages()
- {
- //if (!downloadImagesWorker.IsBusy)
- // downloadImagesWorker.RunWorkerAsync();
- }
-
- void downloadImagesWorker_DoWork(object sender, DoWorkEventArgs e)
- {
- // 1. Download posters from AniDB
- List<JMMServerBinary.Contract_AniDBAnime> contracts = JMMServerVM.Instance.clientBinaryHTTP.GetAllAnime();
-
- int i = 0;
- foreach (JMMServerBinary.Contract_AniDBAnime anime in contracts)
- {
- //Thread.Sleep(5); // don't use too many resources
- imageHelper.DownloadAniDBCover(new AniDB_AnimeVM(anime), false);
- i++;
-
- //if (i == 80) break;
- }
-
- // 2. Download posters from TvDB
- List<JMMServerBinary.Contract_TvDB_ImagePoster> posters = JMMServerVM.Instance.clientBinaryHTTP.GetAllTvDBPosters(null);
- foreach (JMMServerBinary.Contract_TvDB_ImagePoster poster in posters)
- {
- //Thread.Sleep(5); // don't use too many resources
- imageHelper.DownloadTvDBPoster(new TvDB_ImagePosterVM(poster), false);
- }
-
- // 2a. Download posters from MovieDB
- List<JMMServerBinary.Contract_MovieDB_Poster> moviePosters = JMMServerVM.Instance.clientBinaryHTTP.GetAllMovieDBPosters(null);
- foreach (JMMServerBinary.Contract_MovieDB_Poster poster in moviePosters)
- {
- //Thread.Sleep(5); // don't use too many resources
- imageHelper.DownloadMovieDBPoster(new MovieDB_PosterVM(poster), false);
- }
-
- // 3. Download wide banners from TvDB
- List<JMMServerBinary.Contract_TvDB_ImageWideBanner> banners = JMMServerVM.Instance.clientBinaryHTTP.GetAllTvDBWideBanners(null);
- foreach (JMMServerBinary.Contract_TvDB_ImageWideBanner banner in banners)
- {
- //Thread.Sleep(5); // don't use too many resources
- imageHelper.DownloadTvDBWideBanner(new TvDB_ImageWideBannerVM(banner), false);
- }
-
- // 4. Download fanart from TvDB
- List<JMMServerBinary.Contract_TvDB_ImageFanart> fanarts = JMMServerVM.Instance.clientBinaryHTTP.GetAllTvDBFanart(null);
- foreach (JMMServerBinary.Contract_TvDB_ImageFanart fanart in fanarts)
- {
- //Thread.Sleep(5); // don't use too many resources
- imageHelper.DownloadTvDBFanart(new TvDB_ImageFanartVM(fanart), false);
- }
-
- // 4a. Download fanart from MovieDB
- List<JMMServerBinary.Contract_MovieDB_Fanart> movieFanarts = JMMServerVM.Instance.clientBinaryHTTP.GetAllMovieDBFanart(null);
- foreach (JMMServerBinary.Contract_MovieDB_Fanart fanart in movieFanarts)
- {
- //Thread.Sleep(5); // don't use too many resources
- imageHelper.DownloadMovieDBFanart(new MovieDB_FanartVM(fanart), false);
- }
-
- // 5. Download episode images from TvDB
- List<JMMServerBinary.Contract_TvDB_Episode> eps = JMMServerVM.Instance.clientBinaryHTTP.GetAllTvDBEpisodes(null);
- foreach (JMMServerBinary.Contract_TvDB_Episode episode in eps)
- {
- //Thread.Sleep(5); // don't use too many resources
- imageHelper.DownloadTvDBEpisode(new TvDB_EpisodeVM(episode), false);
- }
-
- // 6. Download posters from Trakt
- List<JMMServerBinary.Contract_Trakt_ImagePoster> traktPosters = JMMServerVM.Instance.clientBinaryHTTP.GetAllTraktPosters(null);
- foreach (JMMServerBinary.Contract_Trakt_ImagePoster traktposter in traktPosters)
- {
- //Thread.Sleep(5); // don't use too many resources
- if (string.IsNullOrEmpty(traktposter.ImageURL)) continue;
- imageHelper.DownloadTraktPoster(new Trakt_ImagePosterVM(traktposter), false);
- }
-
- // 7. Download fanart from Trakt
- List<JMMServerBinary.Contract_Trakt_ImageFanart> traktFanarts = JMMServerVM.Instance.clientBinaryHTTP.GetAllTraktFanart(null);
- foreach (JMMServerBinary.Contract_Trakt_ImageFanart traktFanart in traktFanarts)
- {
- //Thread.Sleep(5); // don't use too many resources
- if (string.IsNullOrEmpty(traktFanart.ImageURL)) continue;
- imageHelper.DownloadTraktFanart(new Trakt_ImageFanartVM(traktFanart), false);
- }
-
- // 8. Download episode images from Trakt
- List<JMMServerBinary.Contract_Trakt_Episode> traktEpisodes = JMMServerVM.Instance.clientBinaryHTTP.GetAllTraktEpisodes(null);
- foreach (JMMServerBinary.Contract_Trakt_Episode traktEp in traktEpisodes)
- {
- //Thread.Sleep(5); // don't use too many resources
- if (string.IsNullOrEmpty(traktEp.EpisodeImage)) continue;
-
- // special case for trak episodes
- // Trakt will return the fanart image when no episode image exists, but we don't want this
- int pos = traktEp.EpisodeImage.IndexOf(@"episodes/");
- if (pos <= 0) continue;
-
- imageHelper.DownloadTraktEpisode(new Trakt_EpisodeVM(traktEp), false);
- }
-
-
- }
-
-
-
-
- #region External Event Handlers
-
- #endregion
-
- public override bool Init()
- {
- try
- {
- BaseConfig.MyAnimeLog.Write("INIT MAIN WINDOW");
-
- vidHandler = new VideoHandler();
- vidHandler.DefaultAudioLanguage = settings.DefaultAudioLanguage;
- vidHandler.DefaultSubtitleLanguage = settings.DefaultSubtitleLanguage;
-
- }
- catch (Exception ex)
- {
- BaseConfig.MyAnimeLog.Write("Error on init: {0}", ex.ToString());
- }
-
- return Load(GUIGraphicsContext.Skin + @"\Anime3_Main.xml");
- }
-
- void Instance_ServerStatusEvent(Events.ServerStatusEventArgs ev)
- {
- setGUIProperty("HasherQueueCount", ev.HasherQueueCount.ToString());
- setGUIProperty("HasherQueueState", ev.HasherQueueState);
- setGUIProperty("HasherQueueRunning", ev.HasherQueueRunning ? "Running" : "Paused");
-
- setGUIProperty("GeneralQueueCount", ev.GeneralQueueCount.ToString());
- setGUIProperty("GeneralQueueState", ev.GeneralQueueState);
- setGUIProperty("GeneralQueueRunning", ev.GeneralQueueRunning ? "Running" : "Paused");
-
- setGUIProperty("ImagesQueueCount", ev.ImagesQueueCount.ToString());
- setGUIProperty("ImagesQueueState", ev.ImagesQueueState);
- setGUIProperty("ImagesQueueRunning", ev.ImagesQueueRunning ? "Running" : "Paused");
-
- if (dummyQueueAniDB != null) dummyQueueAniDB.Visible = ev.GeneralQueueCount >= 0;
- if (dummyQueueHasher != null) dummyQueueHasher.Visible = ev.HasherQueueCount >= 0;
- if (dummyQueueImages != null) dummyQueueImages.Visible = ev.ImagesQueueCount >= 0;
- }
-
-
- #region ISetupForm Members
-
- // Returns the name of the plugin which is shown in the plugin menu
- public string PluginName()
- {
- return Constants.PlugInInfo.NAME;
- }
-
- // Returns the description of the plugin is shown in the plugin menu
- public string Description()
- {
- return Constants.PlugInInfo.DESCRIPTION;
- }
-
- // Returns the author of the plugin which is shown in the plugin menu
- public string Author()
- {
- return Constants.PlugInInfo.AUTHOR;
- }
-
- // show the setup dialog
- public void ShowPlugin()
- {
- frmConfig cfg = new frmConfig();
- cfg.ShowDialog();
- }
-
- // Indicates whether plugin can be enabled/disabled
- public bool CanEnable()
- {
- return true;
- }
-
- // Enter the id number here again
- public int GetWindowId()
- {
- return Constants.PlugInInfo.ID;
- }
-
- // Indicates if plugin is enabled by default;
- public bool DefaultEnabled()
- {
- return true;
- }
-
- // indicates if a plugin has it's own setup screen
- public bool HasSetup()
- {
- return true;
- }
-
-
-
-
-
-
-
- /// <summary>
- /// If the plugin should have it's own button on the main menu of MediaPortal then it
- /// should return true to this method, otherwise if it should not be on home
- /// it should return false
- /// </summary>
- /// <param name="strButtonText">text the button should have</param>
- /// <param name="strButtonImage">image for the button, or empty for default</param>
- /// <param name="strButtonImageFocus">image for the button, or empty for default</param>
- /// <param name="strPictureImage">subpicture for the button or empty for none</param>
- /// <returns>true : plugin needs it's own button on home
- /// false : plugin does not need it's own button on home</returns>
-
- public bool GetHome(out string strButtonText, out string strButtonImage, out string strButtonImageFocus, out string strPictureImage)
- {
- AnimePluginSettings sett = new AnimePluginSettings();
-
- strButtonText = sett.PluginName;
- strButtonImage = String.Empty;
- strButtonImageFocus = String.Empty;
- strPictureImage = "hover_my anime3.jpg";
- return true;
- }
-
-
-
- #endregion
-
- private void EvaluateVisibility()
- {
- bool fave = false;
- bool missing = false;
-
- if (curAnimeGroup != null)
- {
- if (curAnimeGroup.IsFave == 1)
- fave = true;
-
- //BaseConfig.MyAnimeLog.Write("settings.ShowMissing: {0}", settings.ShowMissing);
- bool missingVisible = false;
- if (settings.ShowMissing && listLevel == Listlevel.Series && curAnimeSeries != null)
- {
- missingVisible = curAnimeSeries.HasMissingEpisodesGroups;
- }
-
- if (settings.ShowMissing && listLevel == Listlevel.Group)
- {
- missingVisible = curAnimeGroup.HasMissingEpisodes;
- }
-
- if (settings.ShowMissing)
- {
- missing = missingVisible;
- }
- if (dummyFave != null) dummyFave.Visible = fave;
- if (dummyMissingEps != null) dummyMissingEps.Visible = missing;
- //BaseConfig.MyAnimeLog.Write("EvaluateVisibility:: {0} - {1} - {2}", imgListFave != null, curAnimeGroup.IsFave, dummyLayoutListMode.Visible);
- }
-
- //EvaluateServerStatus();
- }
-
- protected override void OnPageDestroy(int new_windowId)
- {
-
- hook.IsEnabled = false;
- hook.UnHook();
- hook = null;
- UnSubClass();
-
- base.OnPageDestroy(new_windowId);
- }
-
- #region Detect application focus
- const int GWL_WNDPROC = (-4);
- const int WM_ACTIVATEAPP = 0x1C;
-
- // This static method is required because legacy OSes do not support
- // SetWindowLongPtr
- public static IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong)
- {
- if (IntPtr.Size == 8)
- return SetWindowLongPtr64(hWnd, nIndex, dwNewLong);
- else
- return new IntPtr(SetWindowLong32(hWnd, nIndex, dwNewLong.ToInt32()));
- }
-
- [DllImport("user32.dll", EntryPoint = "SetWindowLong")]
- private static extern int SetWindowLong32(IntPtr hWnd, int nIndex, int dwNewLong);
-
- [DllImport("user32.dll", EntryPoint = "SetWindowLongPtr")]
- private static extern IntPtr SetWindowLongPtr64(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
-
- [DllImport("user32.dll", EntryPoint = "CallWindowProc")]
- private static extern int CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hwnd, int msg, int wParam, int lParam);
- private delegate int WindowProc(IntPtr hwnd, int msg, int wParam, int lParam);
-
- IntPtr DefWindowProc = IntPtr.Zero;
- WindowProc NewWindowProc = null;
- void SubClass()
- {
- IntPtr hWnd = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
- NewWindowProc = new WindowProc(MyWindowProc);
- DefWindowProc = SetWindowLongPtr(hWnd, GWL_WNDPROC, Marshal.GetFunctionPointerForDelegate(NewWindowProc));
- }
-
- void UnSubClass()
- {
- IntPtr hWnd = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
- DefWindowProc = SetWindowLongPtr(hWnd, GWL_WNDPROC, DefWindowProc);
- DefWindowProc = IntPtr.Zero;
- }
-
- int MyWindowProc(System.IntPtr hWnd, int msg, int wParam, int lParam)
- {
- if (msg == WM_ACTIVATEAPP)
- {
- //disable keyboard hook if app is inactive
- // wParam=1 when activating, 0 when desactivating
- hook.IsEnabled = (wParam == 1);
- }
-
- return CallWindowProc(DefWindowProc, hWnd, msg, wParam, lParam);
- }
- #endregion
-
- protected override void OnPageLoad()
- {
- BaseConfig.MyAnimeLog.Write("Starting page load...");
-
- SubClass();
-
- hook = new KeyboardHook();
- hook.KeyDown += new KeyEventHandlerEx(hook_KeyDown);
- hook.KeyUp += new KeyEventHandlerEx(hook_KeyUp);
- hook.IsEnabled = true;
-
- if (!isFirstInitDone)
- OnFirstStart();
-
- currentViewClassification = settings.LastViewClassification;
- currentStaticViewID = settings.LastStaticViewID;
- currentView = settings.LastView;
-
-
-
- groupViewMode = settings.LastGroupViewMode;
- m_Facade.CurrentLayout = groupViewMode;
- //backdrop.LoadingImage = loadingImage;
-
- Console.Write(JMMServerVM.Instance.ServerOnline.ToString());
-
- LoadFacade();
- m_Facade.Focus = true;
-
- SkinSettings.Load();
-
- //MainWindow.anidbProcessor.UpdateVotesHTTP(MainWindow.settings.Username, MainWindow.settings.Password);
-
-
-
- autoUpdateTimer.Start();
-
- BaseConfig.MyAnimeLog.Write("Thumbs Setting Folder: {0}", settings.ThumbsFolder);
-
- //searching
- setGUIProperty(guiProperty.FindInput, " ");
- setGUIProperty(guiProperty.FindText, " ");
- setGUIProperty(guiProperty.FindMatch, " ");
-
-
-
- search = new SearchCollection();
- search.List = m_Facade;
- search.ListItemSearchProperty = "DVDLabel";
- search.Mode = settings.FindMode;
- search.StartWord = settings.FindStartWord;
-
- UpdateSearchPanel(false);
-
-
- DownloadAllImages();
- }
-
-
- void autoUpdateTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
- {
-
- }
-
-
- private void AddFacadeItem(GUIListItem item)
- {
- int selectedIndex = m_Facade.SelectedListItemIndex;
- SaveOrRestoreFacadeItems(false);
-
- m_Facade.Add(item);
-
- if (searchTimer.Enabled)
- DoSearch(selectedIndex);
- }
-
- private void LoadFacade()
- {
- try
- {
- if (workerFacade == null)
- {
- workerFacade = new BackgroundWorker();
- workerFacade.WorkerReportsProgress = true;
- workerFacade.WorkerSupportsCancellation = true;
-
- workerFacade.DoWork += new DoWorkEventHandler(workerFacade_DoWork);
- workerFacade.RunWorkerCompleted += new RunWorkerCompletedEventHandler(workerFacade_RunWorkerCompleted);
- workerFacade.ProgressChanged += new ProgressChangedEventHandler(workerFacade_ProgressChanged);
- }
-
- lock (workerFacade)
- {
- if (workerFacade.IsBusy) // we have to wait - complete method will call LoadFacade again
- {
- if (!workerFacade.CancellationPending)
- workerFacade.CancelAsync();
- return;
- }
- prepareLoadFacade();
- workerFacade.RunWorkerAsync();
- }
- }
- catch (Exception ex)
- {
- BaseConfig.MyAnimeLog.Write("LoadFacade ERROR:: {0}", ex);
- }
- }
-
- void prepareLoadFacade()
- {
-
-
- try
- {
- GUIControl.ClearControl(this.GetID, m_Facade.GetID);
-
- SetFacade();
-
- this.m_Facade.ListLayout.Clear();
-
- if (this.m_Facade.ThumbnailLayout != null)
- this.m_Facade.ThumbnailLayout.Clear();
-
- if (this.m_Facade.FilmstripLayout != null)
- this.m_Facade.FilmstripLayout.Clear();
-
- if (this.m_Facade.CoverFlowLayout != null)
- this.m_Facade.CoverFlowLayout.Clear();
-
-
- if (m_Facade != null) m_Facade.Focus = true;
-
- }
- catch (Exception ex)
- {
- BaseConfig.MyAnimeLog.Write(ex.ToString());
- }
- }
-
- void workerFacade_ProgressChanged(object sender, ProgressChangedEventArgs e)
- {
- try
- {
-
- BackgroundFacadeLoadingArgument arg = e.UserState as BackgroundFacadeLoadingArgument;
-
- if (workerFacade.CancellationPending)
- {
- BaseConfig.MyAnimeLog.Write("bg_ProgressChanged cancelled");
- return;
- }
-
- if (arg == null || arg.Type == BackGroundLoadingArgumentType.None) return;
-
- switch (arg.Type)
- {
- case BackGroundLoadingArgumentType.ListFullElement:
- case BackGroundLoadingArgumentType.ListElementForDelayedImgLoading:
- List<GUIListItem> ls = arg.Argument as List<GUIListItem>;
- if (m_Facade != null && ls != null && ls.Count > 0)
- {
- foreach (GUIListItem gli in ls)
- {
- //BaseConfig.MyAnimeLog.Write("workerFacade_ProgressChanged - ListElementForDelayedImgLoading");
- // Messages are not recieved in OnMessage for Filmstrip, instead subscribe to OnItemSelected
- if (m_Facade.CurrentLayout == GUIFacadeControl.Layout.Filmstrip || m_Facade.CurrentLayout == GUIFacadeControl.Layout.CoverFlow)
- gli.OnItemSelected += new GUIListItem.ItemSelectedHandler(onFacadeItemSelected);
-
-
- AddFacadeItem(gli);
- if (arg.Type == BackGroundLoadingArgumentType.ListElementForDelayedImgLoading)
- {
- if (itemsForDelayedImgLoading == null)
- itemsForDelayedImgLoading = new List<GUIListItem>();
- itemsForDelayedImgLoading.Add(gli);
- }
- }
- if (this.m_Facade.SelectedListItemIndex < 1)
- {
- this.m_Facade.Focus = true;
- SelectItem(arg.IndexArgument);
- }
- }
- break;
- case BackGroundLoadingArgumentType.DelayedImgLoading:
- {
- if (itemsForDelayedImgLoading != null && itemsForDelayedImgLoading.Count > arg.IndexArgument)
- {
- string image = arg.Argument as string;
- itemsForDelayedImgLoading[arg.IndexArgument].IconImageBig = image;
- }
- }
- break;
-
- case BackGroundLoadingArgumentType.DelayedImgInit:
- itemsForDelayedImgLoading = null;
- break;
- case BackGroundLoadingArgumentType.SetFacadeMode:
- GUIFacadeControl.Layout viewMode = (GUIFacadeControl.Layout)arg.Argument;
- //setFacadeMode(viewMode);
- break;
-
- case BackGroundLoadingArgumentType.ElementSelection:
- {
- // thread told us which element it'd like to select
- // however the user might have already started moving around
- // if that is the case, we don't select anything
- if (this.m_Facade != null && this.m_Facade.SelectedListItemIndex < 1)
- {
- this.m_Facade.Focus = true;
- SelectItem(arg.IndexArgument);
- }
- }
- break;
- }
-
- }
- catch (Exception ex)
- {
- BaseConfig.MyAnimeLog.Write(string.Format("Error in bg_ProgressChanged: {0}: {1}", ex.Message, ex.InnerException));
- }
- }
-
- bool m_bQuickSelect = false;
- void SelectItem(int index)
- {
- //BaseConfig.MyAnimeLog.Write("SelectItem: {0}", index.ToString());
-
- // Hack for 'set' SelectedListItemIndex not being implemented in Filmstrip View
- // Navigate to selected using OnAction instead
- if (m_Facade.CurrentLayout == GUIFacadeControl.Layout.Filmstrip || m_Facade.CurrentLayout == GUIFacadeControl.Layout.CoverFlow)
- {
-
- if (listLevel == Listlevel.Series || listLevel == Listlevel.Group)
- {
- int currentIndex = m_Facade.SelectedListItemIndex;
- if (index >= 0 && index < m_Facade.Count && index != currentIndex)
- {
- m_bQuickSelect = true;
- int increment = (currentIndex < index) ? 1 : -1;
- MediaPortal.GUI.Library.Action.ActionType actionType = (currentIndex < index) ? MediaPortal.GUI.Library.Action.ActionType.ACTION_MOVE_RIGHT : MediaPortal.GUI.Library.Action.ActionType.ACTION_MOVE_LEFT;
- for (int i = currentIndex; i != index; i += increment)
- {
- // Now push fields to skin
- if (i == (index - increment))
- m_bQuickSelect = false;
-
- m_Facade.OnAction(new MediaPortal.GUI.Library.Action(actionType, 0, 0));
- }
- m_bQuickSelect = false;
- }
- else
- {
- if (listLevel == Listlevel.Group && m_Facade.Count > 0)
- {
- Group_OnItemSelected(m_Facade.SelectedListItem);
- }
- }
- }
-
- }
- else
- m_Facade.SelectedListItemIndex = index;
- }
-
- void workerFacade_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
- {
- // ZF - seems to be crashing because of facade being null sometimes, before getting inside the plugin
- if (m_Facade == null)
- return;
-
- if (e.Cancelled)
- {
- LoadFacade(); // we only cancel if the user clicked something while we were still loading
- // whatever was selected we will enter (this is because m_selected whatever will not get updated
- // even if the user selects somethign else while we wait for cancellation due to it being a different listlevel)
- return;
- }
-
- if (m_Facade == null)
- return;
-
- m_Facade.Focus = true;
- }
-
- void workerFacade_DoWork(object sender, DoWorkEventArgs e)
- {
- bgLoadFacade();
- if (workerFacade.CancellationPending)
- e.Cancel = true;
- }
-
- void ReportFacadeLoadingProgress(BackGroundLoadingArgumentType type, int indexArgument, object state)
- {
- if (!workerFacade.CancellationPending)
- {
- BackgroundFacadeLoadingArgument Arg = new BackgroundFacadeLoadingArgument();
- Arg.Type = type;
- Arg.IndexArgument = indexArgument;
- Arg.Argument = state;
-
- workerFacade.ReportProgress(0, Arg);
- }
- }
-
- void bgLoadFacade()
- {
- try
- {
- GUIListItem item = null;
- int selectedIndex = -1;
- int count = 0;
- bool delayedImageLoading = false;
- List<AnimeGroupVM> groups = null;
- List<GroupFilterVM> groupFilters = null;
- List<GUIListItem> list = new List<GUIListItem>();
- BackGroundLoadingArgumentType type = BackGroundLoadingArgumentType.None;
-
- switch (listLevel)
- {
- #region Group Filters
- case Listlevel.GroupFilter:
- {
- // List/Poster/Banner
-
- setGUIProperty("SimpleCurrentView", "Group Filters");
-
- if (groupViewMode != GUIFacadeControl.Layout.List)
- {
- // reinit the itemsList
- delayedImageLoading = true;
- ReportFacadeLoadingProgress(BackGroundLoadingArgumentType.DelayedImgInit, 0, null);
- }
-
- // text as usual
- ReportFacadeLoadingProgress(BackGroundLoadingArgumentType.SetFacadeMode, 0, GUIFacadeControl.Layout.List);
-
- if (workerFacade.CancellationPending)
- return;
-
- BaseConfig.MyAnimeLog.Write("bgLoadFacde: Group Filters");
- groupFilters = FacadeHelper.GetGroupFilters();
- type = BackGroundLoadingArgumentType.ListFullElement;
-
- setGUIProperty(guiProperty.GroupCount, groupFilters.Count.ToString());
-
- foreach (GroupFilterVM grpFilter in groupFilters)
- {
- if (workerFacade.CancellationPending) return;
- try
- {
- item = null;
-
- SetGroupFilterListItem(ref item, grpFilter);
-
- if (curGroupFilter != null)
- {
- if (grpFilter.GroupFilterID.Value == curGroupFilter.GroupFilterID.Value)
- {
- selectedIndex = count;
- }
- }
- else
- {
- if (selectedIndex == -1)
- selectedIndex = count;
- }
-
-
- if (workerFacade.CancellationPending) return;
- else
- {
- list.Add(item);
- }
-
- }
- catch (Exception ex)
- {
- string msg = string.Format("The 'LoadFacade' function has generated an error displaying list items: {0} - {1}", listLevel, ex.ToString());
- BaseConfig.MyAnimeLog.Write(msg);
- }
- count++;
- }
- }
- break;
- #endregion
-
- #region Group Filters - Sub
- case Listlevel.GroupFilterSub:
- {
- // List/Poster/Banner
-
- setGUIProperty("SimpleCurrentView", curGroupFilter.GroupFilterName);
-
- if (groupViewMode != GUIFacadeControl.Layout.List)
- {
- // reinit the itemsList
- delayedImageLoading = true;
- ReportFacadeLoadingProgress(BackGroundLoadingArgumentType.DelayedImgInit, 0, null);
- }
-
- // text as usual
- ReportFacadeLoadingProgress(BackGroundLoadingArgumentType.SetFacadeMode, 0, GUIFacadeControl.Layout.List);
-
- if (workerFacade.CancellationPending)
- return;
-
- BaseConfig.MyAnimeLog.Write("bgLoadFacde: Group Filters");
- groupFilters = FacadeHelper.GetGroupFilters();
- type = BackGroundLoadingArgumentType.ListFullElement;
-
- setGUIProperty(guiProperty.GroupCount, "0");
-
- foreach (GroupFilterVM grpFilter in FacadeHelper.GetTopLevelPredefinedGroupFilters())
- {
- if (workerFacade.CancellationPending) return;
- try
- {
- item = null;
-
- SetGroupFilterListItem(ref item, grpFilter);
-
- if (curGroupFilter != null)
- {
- if (grpFilter.GroupFilterID.Value == curGroupFilter.GroupFilterID.Value)
- {
- selectedIndex = count;
- }
- }
- else
- {
- if (selectedIndex == -1)
- selectedIndex = count;
- }
-
-
- if (workerFacade.CancellationPending) return;
- else
- {
- list.Add(item);
- }
-
- }
- catch (Exception ex)
- {
- string msg = string.Format("The 'LoadFacade' function has generated an error displaying list items: {0} - {1}", listLevel, ex.ToString());
- BaseConfig.MyAnimeLog.Write(msg);
- }
- count++;
- }
- }
- break;
- #endregion
-
- #region Group Filters - Sub2
- case Listlevel.GroupFilterSub2:
- {
- // List/Poster/Banner
-
- setGUIProperty("SimpleCurrentView", curGroupFilter.GroupFilterName);
-
- if (groupViewMode != GUIFacadeControl.Layout.List)
- {
- // reinit the itemsList
- delayedImageLoading = true;
- ReportFacadeLoadingProgress(BackGroundLoadingArgumentType.DelayedImgInit, 0, null);
- }
-
- // text as usual
- ReportFacadeLoadingProgress(BackGroundLoadingArgumentType.SetFacadeMode, 0, GUIFacadeControl.Layout.List);
-
- if (workerFacade.CancellationPending)
- return;
-
- BaseConfig.MyAnimeLog.Write("bgLoadFacde: Group Filters");
- groupFilters = FacadeHelper.GetGroupFilters();
- type = BackGroundLoadingArgumentType.ListFullElement;
-
- setGUIProperty(guiProperty.GroupCount, "0");
-
- foreach (GroupFilterVM grpFilter in FacadeHelper.GetGroupFiltersForPredefined(curGroupFilterSub))
- {
- if (workerFacade.CancellationPending) return;
- try
- {
- item = null;
-
- SetGroupFilterListItem(ref item, grpFilter);
-
- if (curGroupFilter != null)
- {
- if (grpFilter.GroupFilterID.Value == curGroupFilter.GroupFilterID.Value)
- {
- selectedIndex = count;
- }
- }
- else
- {
- if (selectedIndex == -1)
- selectedIndex = count;
- }
-
-
- if (workerFacade.CancellationPending) return;
- else
- {
- list.Add(item);
- }
-
- }
- catch (Exception ex)
- {
- string msg = string.Format("The 'LoadFacade' function has generated an error displaying list items: {0} - {1}", listLevel, ex.ToString());
- BaseConfig.MyAnimeLog.Write(msg);
- }
- count++;
- }
- }
- break;
- #endregion
-
- #region Groups
- case Listlevel.Group:
- {
- // List/Poster/Banner
-
- setGUIProperty("SimpleCurrentView", curGroupFilter.GroupFilterName);
-
- if (groupViewMode != GUIFacadeControl.Layout.List)
- {
- // reinit the itemsList
- delayedImageLoading = true;
- ReportFacadeLoadingProgress(BackGroundLoadingArgumentType.DelayedImgInit, 0, null);
- }
-
- if (groupViewMode != GUIFacadeControl.Layout.List)
- {
- // graphical
- ReportFacadeLoadingProgress(BackGroundLoadingArgumentType.SetFacadeMode, 0, GUIFacadeControl.Layout.AlbumView);
- }
- else
- {
- // text as usual
- ReportFacadeLoadingProgress(BackGroundLoadingArgumentType.SetFacadeMode, 0, GUIFacadeControl.Layout.List);
- }
-
- if (workerFacade.CancellationPending)
- return;
-
- if (curGroupFilterSub2 == null)
- groups = JMMServerHelper.GetAnimeGroupsForFilter(curGroupFilter);
- else
- {
- groups = new List<AnimeGroupVM>();
-
-
-
- List<AnimeGroupVM> tempGroups = JMMServerHelper.GetAnimeGroupsForFilter(GroupFilterHelper.AllGroupsFilter);
- foreach (AnimeGroupVM grp in tempGroups)
- {
- if (curGroupFilterSub2.GroupFilterID.Value == Constants.StaticGF.Predefined_Categories_Child)
- {
- if (grp.Categories.Contains(curGroupFilterSub2.PredefinedCriteria))
- groups.Add(grp);
- }
- if (curGroupFilterSub2.GroupFilterID.Value == Constants.StaticGF.Predefined_Years_Child)
- {
- // find all the groups that qualify by this year
- int startYear = 0;
- if (!grp.Stat_AirDate_Min.HasValue) continue;
- startYear = grp.Stat_AirDate_Min.Value.Year;
-
- int endYear = int.MaxValue;
- if (grp.Stat_AirDate_Max.HasValue) endYear = grp.Stat_AirDate_Max.Value.Year;
-
- int critYear = 0;
- if (!int.TryParse(curGroupFilterSub2.PredefinedCriteria, out critYear)) continue;
-
- if (critYear >= startYear && critYear <= endYear) groups.Add(grp);
-
- }
- }
- }
-
- // re-sort if user has set a quick sort
- if (GroupFilterQuickSorts.ContainsKey(curGroupFilter.GroupFilterID.Value))
- {
- BaseConfig.MyAnimeLog.Write("APPLYING QUICK SORT");
-
- GroupFilterSorting sortType = GroupFilterHelper.GetEnumForText_Sorting(GroupFilterQuickSorts[curGroupFilter.GroupFilterID.Value].SortType);
- SortPropOrFieldAndDirection sortProp = GroupFilterHelper.GetSortDescription(sortType, GroupFilterQuickSorts[curGroupFilter.GroupFilterID.Value].SortDirection);
- List<SortPropOrFieldAndDirection> sortCriteria = new List<SortPropOrFieldAndDirection>();
- sortCriteria.Add(sortProp);
- groups = Sorting.MultiSort<AnimeGroupVM>(groups, sortCriteria);
- }
-
-
- // Update Series Count Property
- setGUIProperty(guiProperty.GroupCount, groups.Count.ToString());
- type = (groupViewMode != GUIFacadeControl.Layout.List) ? BackGroundLoadingArgumentType.ListElementForDelayedImgLoading : BackGroundLoadingArgumentType.ListFullElement;
-
- int seriesCount = 0;
-
- double totalTime = 0;
- DateTime start = DateTime.Now;
-
- BaseConfig.MyAnimeLog.Write("Building groups: " + curGroupFilter.GroupFilterName);
- foreach (AnimeGroupVM grp in groups)
- {
- if (workerFacade.CancellationPending) return;
- try
- {
- item = null;
-
- //BaseConfig.MyAnimeLog.Write(string.Format("{0} - {1}", grp.GroupName, grp.AniDBRating));
-
- SetGroupListItem(ref item, grp);
-
- if (settings.HideWatchedFiles && grp.UnwatchedEpisodeCount <= 0)
- {
- //watched files should be hidden and entire group is watched
- // -> hide entire group
- continue;
- }
-
- seriesCount += grp.AllSeriesCount;
-
- if (curAnimeGroup != null)
- {
- if (grp.AnimeGroupID == curAnimeGroup.AnimeGroupID)
- {
- selectedIndex = count;
- }
- }
- else
- {
- if (selectedIndex == -1)
- selectedIndex = count;
- }
-
-
- if (workerFacade.CancellationPending) return;
- else
- {
- list.Add(item);
- }
-
- }
- catch (Exception ex)
- {
- string msg = string.Format("The 'LoadFacade' function has generated an error displaying list items: {0} - {1}", listLevel, ex.ToString());
- BaseConfig.MyAnimeLog.Write(msg);
- }
- count++;
- }
-
- TimeSpan ts2 = DateTime.Now - start;
- totalTime += ts2.TotalMilliseconds;
-
- BaseConfig.MyAnimeLog.Write("Total time for rendering groups: {0}-{1}", groups.Count, totalTime);
-
- setGUIProperty(guiProperty.SeriesCount, seriesCount.ToString());
-
-
-
-
- }
- break;
- #endregion
-
- #region Series
- case Listlevel.Series:
- {
- // this level includes series as well as sub-groups
-
- if (seriesViewMode != GUIFacadeControl.Layout.List)
- {
- // reinit the itemsList
- delayedImageLoading = true;
- ReportFacadeLoadingProgress(BackGroundLoadingArgumentType.DelayedImgInit, 0, null);
- }
-
- if (workerFacade.CancellationPending) return;
-
- List<SortPropOrFieldAndDirection> sortCriteria = null;
-
- List<AnimeGroupVM> subGroups = curAnimeGroupViewed.SubGroups;
- if (subGroups.Count > 0)
- {
- sortCriteria = new List<SortPropOrFieldAndDirection>();
- sortCriteria.Add(new SortPropOrFieldAndDirection("SortName", false, SortType.eString));
- subGroups = Sorting.MultiSort<AnimeGroupVM>(subGroups, sortCriteria);
- }
-
- // get the series for this group
- List<AnimeSeriesVM> seriesList = curAnimeGroupViewed.ChildSeries;
- if (seriesList.Count > 0)
- {
- sortCriteria = new List<SortPropOrFieldAndDirection>();
- sortCriteria.Add(new SortPropOrFieldAndDirection("AirDate", false, SortType.eDateTime));
- seriesList = Sorting.MultiSort<AnimeSeriesVM>(seriesList, sortCriteria);
- }
- //if (seriesList.Count == 0)
- // bFacadeEmpty = true;
-
- // Update Series Count Property
- setGUIProperty(guiProperty.SeriesCount, seriesList.Count.ToString());
-
- // now sort the groups by air date
-
-
- type = BackGroundLoadingArgumentType.ListFullElement;
-
- foreach (AnimeGroupVM grp in subGroups)
- {
- if (workerFacade.CancellationPending) return;
- try
- {
- item = null;
-
- SetGroupListItem(ref item, grp);
-
- if (settings.HideWatchedFiles && grp.UnwatchedEpisodeCount <= 0)
- {
- //watched files should be hidden and entire group is watched
- // -> hide entire group
- continue;
- }
-
- if (workerFacade.CancellationPending) return;
- else
- {
- list.Add(item);
- }
-
- }
- catch (Exception ex)
- {
- string msg = string.Format("The 'LoadFacade' function has generated an error displaying list items: {0} - {1}", listLevel, ex.ToString());
- BaseConfig.MyAnimeLog.Write(msg);
- }
- }
-
- foreach (AnimeSeriesVM ser in seriesList)
- {
- //BaseConfig.MyAnimeLog.Write("LoadFacade-Series:: {0}", ser);
- if (workerFacade.CancellationPending) return;
- try
- {
- item = null;
-
- SetSeriesListItem(ref item, ser);
-
- if (settings.HideWatchedFiles && ser.UnwatchedEpisodeCount <= 0)
- {
- //watched files should be hidden and entire series is watched
- // -> hide entire series
- continue;
- }
-
- if (workerFacade.CancellationPending) return;
- else
- {
- list.Add(item);
- }
-
- }
- catch (Exception ex)
- {
- string msg = string.Format("The 'LoadFacade' function has generated an error displaying list items: {0} - {1}", listLevel, ex.ToString());
- BaseConfig.MyAnimeLog.Write(msg);
- }
- count++;
- }
- }
- break;
- #endregion
-
- #region Episode Types
- case Listlevel.EpisodeTypes:
- {
-
- if (workerFacade.CancellationPending) return;
-
- //List<AnimeEpisodeType> anEpTypes = AnimeSeries.GetEpisodeTypes(curAnimeSeries.AnimeSeriesID.Value);
- type = BackGroundLoadingArgumentType.ListFullElement;
- foreach (AnimeEpisodeTypeVM anEpType in curAnimeSeries.EpisodeTypesToDisplay)
- {
- item = null;
- SetEpisodeTypeListItem(ref item, anEpType);
-
- if (workerFacade.CancellationPending) return;
- else
- {
- list.Add(item);
- }
- count++;
- }
- }
- break;
- #endregion
-
- #region Episodes
- case Listlevel.Episode:
- {
-
- if (workerFacade.CancellationPending) return;
-
- if (curAnimeSeries == null) return;
-
- // get the episodes for this series / episode types
- //BaseConfig.MyAnimeLog.Write("GetEpisodes:: {0}", curAnimeSeries.AnimeSeriesID.Value);
-
- //List<AnimeEpisode> episodeList = AnimeSeries.GetEpisodes(curAnimeSeries.AnimeSeriesID.Value);
- curAnimeSeries.RefreshEpisodes();
- List<AnimeEpisodeVM> episodeList = curAnimeSeries.GetEpisodesToDisplay(curAnimeEpisodeType.EpisodeType);
-
- // Update Series Count Property
- //setGUIProperty(guiProperty.SeriesCount, episodeList.Count.ToString());
-
- bool foundFirstUnwatched = false;
- type = BackGroundLoadingArgumentType.ListFullElement;
- foreach (AnimeEpisodeVM ep in episodeList)
- {
- //BaseConfig.MyAnimeLog.Write("LoadFacade-Episodes:: {0}", ep);
- if (workerFacade.CancellationPending) return;
- try
- {
- item = null;
- bool isWatched = SetEpisodeListItem(ref item, ep);
-
- if (isWatched && settings.HideWatchedFiles)
- continue;
-
- if (!foundFirstUnwatched && !isWatched && ep.LocalFileCount > 0)
- {
- selectedIndex = count;
- foundFirstUnwatched = true;
- }
-
- if (workerFacade.CancellationPending) return;
- else
- {
- list.Add(item);
- }
-
- }
- catch (Exception ex)
- {
- string msg = string.Format("The 'LoadFacade' function has generated an error displaying list items: {0} - {1}", listLevel, ex.ToString());
- BaseConfig.MyAnimeLog.Write(msg);
- }
- count++;
- }
-
- SetFanartForEpisodes();
- }
- setGUIProperty(guiProperty.EpisodeCount, count.ToString());
- break;
- #endregion
-
- }
-
-
- #region Report ItemToAutoSelect
-
- if (selectedIndex == -1)
- selectedIndex = 0;
-
- BaseConfig.MyAnimeLog.Write("Report ItemToAutoSelect: {0}", selectedIndex.ToString());
-
- #endregion
-
- ReportFacadeLoadingProgress(type, selectedIndex, list);
-
- SetFacade();
-
- #region DelayedImageLoading
-
- // we only use delayed image loading for the main groups view
- // since the other views will not have enough items to be concerned about
-
-
-
- if (delayedImageLoading && groups != null)
- {
- BaseConfig.MyAnimeLog.Write("delayedImageLoading: Started");
- // This is a perfect oportunity to use all cores on the machine
- // we queue each image up to be loaded, resize and put them into memory in parallel
-
-
- // Set the amount of threads to the amount of CPU cores in the machine.
- int MaxThreads = Environment.ProcessorCount;
- // This keeps track of how many of the threads have terminated
- int done = 0;
- // Pool of threads.
- List<Thread> ImageLoadThreadPool = new List<Thread>();
- // List of Groups in theā¦
Large files files are truncated, but you can click here to view the full file