context: // Type: FanartHandler.FanartSelected
  // Assembly: FanartHandler, Version=4.0.3.0, Culture=neutral, PublicKeyToken=null
  // MVID: 073E8D78-B6AE-4F86-BDE9-3E09A337833B
  
  extern alias FHNLog;
  
  using MediaPortal.GUI.Library;
  
  using FHNLog.NLog;
  
  using System;
  using System.Collections;
  using System.IO;
  using System.Collections.Generic;
  
  namespace FanartHandler
  {
    internal class FanartSelected
    {
      // Private
      private static readonly Logger logger = LogManager.GetCurrentClassLogger();
      private bool DoShowImageOne = true;
      private Hashtable propertiesSelect;
  
      private string CurrSelectedMovie;
      private string CurrSelectedMovieTitle;
      private string CurrSelectedMusic;
      private string CurrSelectedMusicArtist;
      private string CurrSelectedMusicAlbum;
      private string CurrSelectedScorecenter;
      private string CurrSelectedScorecenterGenre;
      private string CurrSelectedPicture;
      private string CurrSelectedPictureImage;
  
      private ArrayList ListSelectedMovies;
      private ArrayList ListSelectedMusic;
      private ArrayList ListSelectedScorecenter;
      private ArrayList ListSelectedPictures;
  
      private int PrevSelectedMusic;
      private int PrevSelectedVideo;
      private int PrevSelectedScorecenter;
      private int PrevSelectedPicture;
  
      private bool FanartAvailableMusic;
      private bool FanartAvailableMovies;
      private bool FanartAvailableScorecenter;
      private bool FanartAvailablePictures;
  
      /// <summary>
      /// Fanart Control Visible
      /// -1 Unknown, 0 Hiden, 1 Visible
      /// </summary>
      private int ControlVisible;
      /// <summary>
      /// Fanart Image Control Visible
      /// -1 Unknown, 0 Hiden, 1 Visible
      /// </summary>
      private int ControlImageVisible;
  
      private Hashtable CurrentSelectedImageNames;
  
      // Public
      public bool FanartAvailable { get; set; }
  
      public int RefreshTickCount { get; set; }
  
      public Hashtable WindowsUsingFanartSelectedMusic { get; set; }
      public Hashtable WindowsUsingFanartSelectedMovie { get; set; }
      public Hashtable WindowsUsingFanartSelectedScoreCenter { get; set; }
      public Hashtable WindowsUsingFanartSelectedPictures { get; set; }
  
      public bool IsSelectedScoreCenter { get; set; }
      public bool IsSelectedVideo { get; set; }
      public bool IsSelectedMusic { get; set; }
      public bool IsSelectedPicture { get; set; }
  
      static FanartSelected()
      {
      }
  
      public FanartSelected()
      {
        DoShowImageOne = true;
        FanartAvailable = false;
        FanartAvailableMusic = false;
        FanartAvailableMovies = false;
        FanartAvailableScorecenter = false;
        FanartAvailablePictures = false;
  
        RefreshTickCount = 0;
        PrevSelectedVideo = -1;
        PrevSelectedMusic = -1;
        PrevSelectedScorecenter = -1;
        PrevSelectedPicture = -1;
  
        CurrentSelectedImageNames = new Hashtable();
        propertiesSelect = new Hashtable();
  
        ListSelectedMovies = new ArrayList();
        ListSelectedMusic = new ArrayList();
        ListSelectedScorecenter = new ArrayList();
        ListSelectedPictures = new ArrayList();
  
        WindowsUsingFanartSelectedMusic = new Hashtable();
        WindowsUsingFanartSelectedMovie = new Hashtable();
        WindowsUsingFanartSelectedPictures = new Hashtable();
        WindowsUsingFanartSelectedScoreCenter = new Hashtable();
  
        IsSelectedPicture = false;
        IsSelectedMusic = false;
        IsSelectedVideo = false;
        IsSelectedScoreCenter = false;
  
        ClearCurrProperties();
      }
  
      public void ClearCurrProperties()
      {
        CurrSelectedMovie = string.Empty;
        CurrSelectedMovieTitle = string.Empty;
        CurrSelectedMusic = string.Empty;
        CurrSelectedMusicArtist = string.Empty;
        CurrSelectedMusicAlbum = string.Empty;
        CurrSelectedScorecenter = string.Empty;
        CurrSelectedScorecenterGenre = string.Empty;
        CurrSelectedPicture = string.Empty;
        CurrSelectedPictureImage = string.Empty;
  
        ControlVisible = -1;
        ControlImageVisible = -1;
      }
  
      public bool CheckValidWindowIDForFanart()
      {
        return (Utils.ContainsID(WindowsUsingFanartSelectedMusic) || 
                Utils.ContainsID(WindowsUsingFanartSelectedScoreCenter) || 
                Utils.ContainsID(WindowsUsingFanartSelectedMovie) || 
                Utils.ContainsID(WindowsUsingFanartSelectedPictures));
      }
  
      #region Generic Selected Properties
      public void RefreshGenericSelectedProperties(Utils.SelectedType property, ref ArrayList listSelectedGeneric, Utils.Category category, Utils.SubCategory subcategory, ref string currSelectedGeneric, ref string currSelectedGenericTitle)
      {
        try
        {
          if (Utils.GetIsStopping())
            return;
  
          if (currSelectedGeneric == null)
          {
            currSelectedGeneric = string.Empty;
          }
          if (currSelectedGenericTitle == null)
          {
            currSelectedGenericTitle = string.Empty;
          }
  
          var isMusic = (property == Utils.SelectedType.Music);
          var isVideo = (property == Utils.SelectedType.Movie);
          var isMusicVideo = false;
  
          var SelectedAlbum = (string) null;
          var SelectedGenre = (string) null;
          var SelectedStudios = (string) null;
          var SelectedItem = (string) null;
  
          string strMode = isMusic ? "music" : "movie";
  
          Utils.GetSelectedItem(ref SelectedItem, ref SelectedAlbum, ref SelectedGenre, ref SelectedStudios, ref isMusicVideo);
  
          // var FanartNotFound = true;
          if (!string.IsNullOrWhiteSpace(SelectedItem) && !SelectedItem.Equals("..", StringComparison.CurrentCulture))
          {
            var flag = (!currSelectedGenericTitle.Equals(SelectedItem, StringComparison.CurrentCulture));
            if (flag || (RefreshTickCount >= Utils.MaxRefreshTickCount))
            {
              var oldFanart = currSelectedGeneric;
              var newFanart = string.Empty;
              int prevSelectedGeneric = (isMusic || isMusicVideo) ? PrevSelectedMusic : PrevSelectedVideo;
  
              if (flag) // (!currSelectedGenericTitle.Equals(SelectedItem, StringComparison.CurrentCulture))
              {
                currSelectedGeneric = string.Empty;
                prevSelectedGeneric = -1;
                SetCurrentSelectedImageNames(null, category, subcategory);
                if (isMusic || isMusicVideo)
                  FanartAvailableMusic = false;
                else
                  FanartAvailableMovies = false;
              }
  
              newFanart = GetFilename(SelectedItem, SelectedAlbum, ref currSelectedGeneric, ref prevSelectedGeneric, category, subcategory, flag, isMusic);
              if (string.IsNullOrEmpty(newFanart) && (Utils.iActiveWindow == 2003 || Utils.iActiveWindow == 6 || Utils.iActiveWindow == 25))  // Dialog Video Info || My Video || My Video Title
              {
                newFanart = Utils.GetProperty("#myvideosuserfanart");
                if (string.IsNullOrEmpty(newFanart))
                {
                  newFanart = GetFilename(Utils.iActiveWindow != 2003 ? Utils.GetProperty("#selecteditem") : Utils.GetProperty("#title"), null, ref currSelectedGeneric, ref prevSelectedGeneric, category, subcategory, flag, isMusic);
                }
              }
              // Genre
              if (string.IsNullOrEmpty(newFanart) && !string.IsNullOrEmpty(SelectedGenre) && Utils.UseGenreFanart)
              {
                newFanart = GetFilename(Utils.GetGenres(SelectedGenre), null, ref currSelectedGeneric, ref prevSelectedGeneric, category, subcategory, flag, isMusic);
                // logger.Debug("*** Genres: " + SelectedGenre + " - " + Utils.GetGenres(SelectedGenre) + " - " + newFanart);
              }
              // Random
              if (string.IsNullOrEmpty(newFanart) && isMusic)
              {
                newFanart = Utils.GetRandomDefaultBackdrop(ref currSelectedGeneric, ref prevSelectedGeneric);
              }
  
              if (isMusic || isMusicVideo)
                PrevSelectedMusic = prevSelectedGeneric;
              else
                PrevSelectedVideo = prevSelectedGeneric;
  
              if (!string.IsNullOrEmpty(newFanart))
              {
                if (isMusic || isMusicVideo)
                  FanartAvailableMusic = true;
                else
                  FanartAvailableMovies = true;
                currSelectedGeneric = newFanart;
  
                if (newFanart.Equals(oldFanart, StringComparison.CurrentCulture))
                {
                  DoShowImageOne = !DoShowImageOne;
                }
                if (DoShowImageOne)
                {
                  Utils.AddProperty(ref propertiesSelect, strMode + ".backdrop1.selected", newFanart, ref listSelectedGeneric);
                  // logger.Debug("*** Image 1: " + newFanart);
                }
                else
                {
                  Utils.AddProperty(ref propertiesSelect, strMode + ".backdrop2.selected", newFanart, ref listSelectedGeneric);
                  // logger.Debug("*** Image 2: " + newFanart);
                }
              }
              else
              {
                Utils.AddProperty(ref propertiesSelect, strMode + ".backdrop1.selected", string.Empty, ref listSelectedGeneric);
                Utils.AddProperty(ref propertiesSelect, strMode + ".backdrop2.selected", string.Empty, ref listSelectedGeneric);
              }
              currSelectedGenericTitle = SelectedItem;
              ResetRefreshTickCount();
            }
          }
          else
          {
            currSelectedGeneric = string.Empty;
            currSelectedGenericTitle = string.Empty;
  
            if (isMusic || isMusicVideo)
            {
              PrevSelectedMusic = -1;
            }
            else
            {
              PrevSelectedVideo = -1;
            }
  
            Utils.AddProperty(ref propertiesSelect, strMode + ".backdrop1.selected", string.Empty, ref listSelectedGeneric);
            Utils.AddProperty(ref propertiesSelect, strMode + ".backdrop2.selected", string.Empty, ref listSelectedGeneric);
            // logger.Debug("*** Image 1,2: Empty...");
            //
            SetCurrentSelectedImageNames(null, category, subcategory); 
            if (isMusic || isMusicVideo)
            {
              FanartAvailableMusic = false;
            }
            else
            {
              FanartAvailableMovies = false;
            }
          }
        }
        catch (Exception ex)
        {
          logger.Error("RefreshGenericSelectedProperties: " + ex);
        }
      }
      #endregion
  
      #region Refresh Music Selected Properties
      public void RefreshMusicSelectedProperties()
      {
        try
        {
          if (Utils.GetIsStopping())
            return;
  
          var album = string.Empty;
          var genre = Utils.GetProperty("#music.genre").Replace(" / ", "|").Replace(", ", "|");
          var SelectedItem = Utils.GetMusicArtistFromListControl(ref album);
          // logger.Info("*** GMAFLC: R - ["+SelectedItem+"] ["+album+"]");
  
          // var FanartNotFound = true;
          if (!string.IsNullOrWhiteSpace(SelectedItem) && !SelectedItem.Equals("..", StringComparison.CurrentCulture))
          {
            var oldFanart = CurrSelectedMusic;
            var newFanart = string.Empty;
            var flag = (!CurrSelectedMusicArtist.Equals(SelectedItem, StringComparison.CurrentCulture) || !CurrSelectedMusicAlbum.Equals(album, StringComparison.CurrentCulture));
  
  
gt:           if (flag || (RefreshTickCount >= Utils.MaxRefreshTickCount))