Пример #1
0
 private static void VolumeInserted(int bitMask)
 {
   string str = DVM.MaskToLogicalPaths(bitMask);
   if (Settings.Instance.ExtensiveLogging)
   {
     Log.Info("iMONLCDg.UpdateDisplay.VolumeInserted(): volume inserted in drive {0}", str);
   }
   var drive = new CDDrive();
   if (drive.IsOpened)
   {
     drive.Close();
   }
   drive.Open(str[0]);
   while (!drive.IsCDReady())
   {
     Thread.Sleep(100);
   }
   drive.Refresh();
   if (drive.GetNumAudioTracks() > 0)
   {
     Inserted_Media[str[0] - 'A'] = 1;
     if (Settings.Instance.ExtensiveLogging)
     {
       Log.Info("iMONLCDg.UpdateDisplay.VolumeInserted(): Audio CD inserted in drive {0}", str);
     }
     drive.Close();
   }
   else
   {
     drive.Close();
     if (Directory.Exists(str + @"\VIDEO_TS"))
     {
       Inserted_Media[str[0] - 'A'] = 2;
       if (Settings.Instance.ExtensiveLogging)
       {
         Log.Info("iMONLCDg.UpdateDisplay.VolumeInserted(): DVD inserted in drive {0}", str);
       }
     }
     else
     {
       Inserted_Media[str[0] - 'A'] = 4;
       if (Settings.Instance.ExtensiveLogging)
       {
         Log.Info("iMONLCDg.UpdateDisplay.VolumeInserted(): Unknown Media inserted in drive {0}", str);
       }
     }
   }
 }
Пример #2
0
    /// <summary>
    /// This method returns an arraylist of GUIListItems for the specified folder
    /// If the folder is protected by a pincode then the user is asked to enter the pincode
    /// and the folder contents are only returned when the pincode is correct
    /// </summary>
    /// <param name="strDir">The path to load items from</param>
    /// <param name="loadHidden">The path to load items from even hidden one</param>
    /// <returns>A list of GUIListItems for the specified folder</returns>
    public List<GUIListItem> GetDirectoryExt(string strDir, bool loadHidden)
    {
      if (String.IsNullOrEmpty(strDir))
      {
        m_strPreviousDir = "";
        CurrentShare = "";
        return GetRootExt();
      }

      //if we have a folder like D:\ then remove the \
      if (strDir.EndsWith(@"\"))
      {
        strDir = strDir.Substring(0, strDir.Length - 1);
      }

      List<GUIListItem> items = new List<GUIListItem>();

      if (strDir.Length > 254)
      {
        Log.Warn("VirtualDirectory: GetDirectoryExt received a path which contains too many chars");
        return items;
      }

      //get the parent folder
      string strParent = "";
      if (IsRemote(strDir))
      {
        int ipos = strDir.LastIndexOf(@"/");
        if (ipos > 0)
        {
          strParent = strDir.Substring(0, ipos);
        }
      }
      else
      {
        int ipos = strDir.LastIndexOf(@"\");
        if (ipos > 0)
        {
          strParent = strDir.Substring(0, ipos);
        }
      }

      //is this directory protected
      string iPincodeCorrect;
      if (IsProtectedShare(strDir, out iPincodeCorrect))
      {
        #region Pin protected

        bool retry = true;
        {
          while (retry)
          {
            //no, then ask user to enter the pincode
            GUIMessage msgGetPassword = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GET_PASSWORD, 0, 0, 0, 0, 0, 0);
            GUIWindowManager.SendMessage(msgGetPassword);

            if (msgGetPassword.Label != iPincodeCorrect)
            {
              GUIMessage msgWrongPassword = new GUIMessage(GUIMessage.MessageType.GUI_MSG_WRONG_PASSWORD, 0, 0, 0, 0, 0,
                                                           0);
              GUIWindowManager.SendMessage(msgWrongPassword);

              if (!(bool)msgWrongPassword.Object)
              {
                GUIListItem itemTmp = new GUIListItem();
                itemTmp.IsFolder = true;
                itemTmp.Label = "..";
                itemTmp.Label2 = "";
                itemTmp.Path = m_strPreviousDir;
                Utils.SetDefaultIcons(itemTmp);
                items.Add(itemTmp);
                return items;
              }
            }
            else
              retry = false;
          }
        }

        #endregion
      }
      //Setting current share;
      SetCurrentShare(strDir);

      //check if this is an image file like .iso, .nrg,...
      //ifso then ask daemontools to automount it

      bool VirtualShare = false;
      if (!IsRemote(strDir))
      {
        if (DaemonTools.IsEnabled)
        {
          #region DaemonTools

          string extension = Path.GetExtension(strDir);
          if (IsImageFile(extension))
          {
            if (!DaemonTools.IsMounted(strDir))
            {
              string virtualPath;
              if (DaemonTools.Mount(strDir, out virtualPath))
              {
                strDir = virtualPath;
                VirtualShare = true;
              }
            }
            else
            {
              strDir = DaemonTools.GetVirtualDrive();
              VirtualShare = true;
            }
          }

          #endregion
        }
      }

      GUIListItem item;
      if (!IsRootShare(strDir) || VirtualShare)
      {
        item = new GUIListItem();
        item.IsFolder = true;
        item.Label = "..";
        item.Label2 = "";
        Utils.SetDefaultIcons(item);

        item.Path = strParent == strDir ? "" : strParent;
        items.Add(item);
      }
      else
      {
        item = new GUIListItem();
        item.IsFolder = true;
        item.Label = "..";
        item.Label2 = "";
        item.Path = "";
        Utils.SetDefaultIcons(item);
        items.Add(item);
      }

      if (IsRemote(strDir))
      {
        #region Remote files

        FTPClient ftp = GetFtpClient(strDir);
        if (ftp == null) return items;

        string folder = strDir.Substring("remote:".Length);
        string[] subitems = folder.Split(new char[] {'?'});
        if (subitems[4] == string.Empty) subitems[4] = "/";

        FTPFile[] files;
        try
        {
          ftp.ChDir(subitems[4]);
          files = ftp.DirDetails(); //subitems[4]);
        }
        catch (Exception)
        {
          //maybe this socket has timed out, remove it and get a new one
          FtpConnectionCache.Remove(ftp);
          ftp = GetFtpClient(strDir);
          if (ftp == null) return items;
          try
          {
            ftp.ChDir(subitems[4]);
          }
          catch (Exception ex)
          {
            Log.Info("VirtualDirectory:unable to chdir to remote folder:{0} reason:{1} {2}", subitems[4], ex.Message,
                     ex.StackTrace);
            return items;
          }
          try
          {
            files = ftp.DirDetails(); //subitems[4]);
          }
          catch (Exception ex)
          {
            Log.Info("VirtualDirectory:unable to get remote folder:{0} reason:{1}  {2}", subitems[4], ex.Message,
                     ex.StackTrace);
            return items;
          }
        }
        for (int i = 0; i < files.Length; ++i)
        {
          FTPFile file = files[i];
          //Log.Info("VirtualDirectory: {0} {1}",file.Name,file.Dir);
          if (file.Dir)
          {
            if (file.Name != "." && file.Name != "..")
            {
              item = new GUIListItem();
              item.IsFolder = true;
              item.Label = file.Name;
              item.Label2 = "";
              item.Path = String.Format("{0}/{1}", strDir, file.Name);
              item.IsRemote = true;
              item.FileInfo = null;
              Utils.SetDefaultIcons(item);
              string pin;
              if (!IsProtectedShare(item.Path, out pin))
              {
                Utils.SetThumbnails(ref item);
              }
              items.Add(item);
            }
          }
          else
          {
            if (IsValidExtension(file.Name))
            {
              item = new GUIListItem();
              item.IsFolder = false;
              item.Label = Utils.GetFilename(file.Name);
              item.Label2 = "";
              item.Path = String.Format("{0}/{1}", strDir, file.Name);
              item.IsRemote = true;
              if (IsRemoteFileDownloaded(item.Path, file.Size))
              {
                item.Path = GetLocalFilename(item.Path);
                item.IsRemote = false;
              }
              else if (FtpConnectionCache.IsDownloading(item.Path))
              {
                item.IsDownloading = true;
              }
              item.FileInfo = new FileInformation();
              DateTime modified = file.LastModified;
              item.FileInfo.CreationTime = modified;
              item.FileInfo.Length = file.Size;
              Utils.SetDefaultIcons(item);
              Utils.SetThumbnails(ref item);
              items.Add(item);
            }
          }
        }

        #endregion
      }
      else
      {
        #region CDDA comment

        /* Here is the trick to play Enhanced CD and not only CD-DA: 
         * we force the creation of GUIListItem of Red Book tracks.
         * Track names are made up on-the-fly, using naming conventions
         * (Track%%.cda) and are not really retrieved from the drive
         * directory, as opposed to the old method.
         * If the data session happens to be the first to be recorded
         * then the old method can't read the Red Book structure.
         * Current audio tracks number is found using Windows API 
         * (dependances on the Ripper package).
         * These are not really limitations (because it was already
         * the way CD-DA playing was handled before) but worth noting:
         * -The drive structure is browsed twice, once in Autoplay and
         *    the other one here.
         * -CD-DA and Enhanced CD share the same methods.
         * -A CD Audio must be a Windows drive letter followed by a
         *    semi-colon (mounted images should work, Windows shared
         *    drives seem not to).
         * Works with Windows Media Player
         * Seems to work with Winamp (didn't make more than one experiment)
         * Wasn't tested with other players
         */

        #endregion

        bool doesContainRedBookData = false;

        if (item.IsFolder && strDir.Length == 2 && strDir[1] == ':')
        {
          try
          {
            CDDrive m_Drive = new CDDrive();

            if (m_Drive.IsOpened)
              m_Drive.Close();

            if (m_Drive.Open(strDir[0]) && m_Drive.IsCDReady() && m_Drive.Refresh())
            {
              int totalNumberOfTracks = m_Drive.GetNumTracks();
              //int totalNumberOfRedBookTracks = 0;
              for (int i = 1; i <= totalNumberOfTracks; i++)
                if (m_Drive.IsAudioTrack(i))
                {
                  doesContainRedBookData = true;
                  //totalNumberOfRedBookTracks++;
                }
            }
            m_Drive.Close();
          }
          catch (Exception) {}
        }

        HandleLocalFilesInDir(strDir, ref items, doesContainRedBookData, loadHidden);

        // CUE Filter
        items =
          (List<GUIListItem>)CueUtil.CUEFileListFilter<GUIListItem>(items, CueUtil.CUE_TRACK_FILE_GUI_LIST_ITEM_BUILDER);
      }
      m_strPreviousDir = strDir;
      return items;
    }
Пример #3
0
    private void UpdateIcons()
    {
      ulong optionBitmask = 0L;
      ulong num2;
      bool flag = false;
      var icon = new DiskIcon();
      Log.Debug("iMONLCDg.UpdateIcons(): Starting Icon Update Thread");
      var mask = new BuiltinIconMask();
      var drive = new CDDrive();
      if (DisplaySettings.BlankDisplayWithVideo & DisplaySettings.EnableDisplayAction)
      {
        GUIWindowManager.OnNewAction += OnExternalAction;
      }
      for (int i = 0; i < 0x1b; i++)
      {
        Inserted_Media[i] = 0;
      }
      if (DisplayOptions.DiskIcon & DisplayOptions.DiskMonitor)
      {
        char[] cDDriveLetters = CDDrive.GetCDDriveLetters();
        var arg = cDDriveLetters.Length;
        Log.Debug("iMONLCDg.UpdateIcons(): Found {0} CD/DVD Drives.", arg);
        for (int j = 0; j < cDDriveLetters.Length; j++)
        {
          if (drive.Open(cDDriveLetters[j]))
          {
            Log.Debug("iMONLCDg.UpdateIcons(): Checking media in Drive {0}.", cDDriveLetters[j]);
            bool flag2 = false;
            for (int k = 0; k < 10; k++)
            {
              if (drive.IsCDReady())
              {
                flag2 = true;
              }
              else
              {
                Thread.Sleep(50);
              }
            }
            if (flag2)
            {
              Log.Debug("iMONLCDg.UpdateIcons(): Waiting for Drive {0} to refresh.", cDDriveLetters[j]);
              drive.Refresh();
              if (drive.GetNumAudioTracks() > 0)
              {
                Inserted_Media[cDDriveLetters[j] - 'A'] = 1;
                Log.Debug("iMONLCDg.UpdateIcons(): Found Audio CD in Drive {0}.", cDDriveLetters[j]);
              }
              else if (File.Exists(cDDriveLetters[j] + @"\VIDEO_TS"))
              {
                Inserted_Media[cDDriveLetters[j] - 'A'] = 2;
                Log.Debug("iMONLCDg.UpdateIcons(): Found DVD in Drive {0}.", cDDriveLetters[j]);
              }
              else
              {
                Inserted_Media[cDDriveLetters[j] - 'A'] = 4;
                Log.Debug("iMONLCDg.UpdateIcons(): Unknown media found in Drive {0}.", cDDriveLetters[j]);
              }
            }
            else
            {
              Inserted_Media[cDDriveLetters[j] - 'A'] = 0;
              Log.Debug("iMONLCDg.UpdateIcons(): No media found in Drive {0}.", cDDriveLetters[j]);
            }
          }
          drive.Close();
        }
      }
      if (DisplayOptions.DiskIcon & DisplayOptions.DiskMonitor)
      {
        ActivateDVM();
      }
      icon.Reset();
      while (true)
      {
        do
        {
          lock (ThreadMutex)
          {
            if (DoDebug)
            {
              Log.Info("iMONLCDg.UpdateIcons(): Checking for Thread termination request");
            }
            if (_stopUpdateIconThread)
            {
              Log.Info("iMONLCDg.UpdateIcons(): Icon Update Thread terminating");
              _stopUpdateIconThread = false;
              if (DisplaySettings.BlankDisplayWithVideo & DisplaySettings.EnableDisplayAction)
              {
                GUIWindowManager.OnNewAction -= OnExternalAction;
              }
              if (DVM != null)
              {
                DVM.Dispose();
                DVM = null;
              }
              return;
            }
            if ((!DVMactive & DisplayOptions.DiskIcon) & DisplayOptions.DiskMonitor)
            {
              ActivateDVM();
            }
            num2 = optionBitmask;
            flag = !flag;
            int num7 = _CurrentLargeIcon;
            LastVolLevel = volLevel;
            LastProgLevel = progLevel;
            int num8 = 0;
            icon.Off();
            icon.Animate();
            if (DoDebug)
            {
              Log.Info("iMONLCDg.UpdateIcons(): Checking TV Card status: IsAnyCardRecording = {0}, IsViewing = {1}",
                       MiniDisplayHelper.IsCaptureCardRecording().ToString(),
                       MiniDisplayHelper.IsCaptureCardViewing().ToString());
            }
            MiniDisplayHelper.GetSystemStatus(ref MPStatus);
            Check_Idle_State();
            if (DoDebug)
            {
              Log.Info("iMONLCDg.UpdateIcons(): System Status: Plugin Status = {0}, IsIdle = {1}",
                       MPStatus.CurrentPluginStatus.ToString(), MPStatus.MP_Is_Idle);
            }
            optionBitmask = ConvertPluginIconsToDriverIcons(MPStatus.CurrentIconMask);
            if ((optionBitmask & (0x400000000L)) > 0L)
            {
              num8 = 5;
            }
            else if ((optionBitmask & (8L)) > 0L)
            {
              num8 = 1;
            }
            if (MiniDisplayHelper.IsCaptureCardViewing() && !MPStatus.Media_IsTimeshifting)
            {
              icon.On();
              icon.InvertOn();
              icon.RotateCW();
            }
            if (_mpIsIdle)
            {
              num8 = 0;
            }
            if (MPStatus.MediaPlayer_Playing)
            {
              icon.On();
              if ((MPStatus.CurrentIconMask & (0x10L)) > 0L)
              {
                icon.InvertOff();
              }
              else
              {
                icon.InvertOn();
              }
              if ((MPStatus.CurrentIconMask & (0x10000000000L)) > 0L)
              {
                icon.RotateCCW();
              }
              else
              {
                icon.RotateCW();
              }
              icon.FlashOff();
              if (((((((MPStatus.CurrentIconMask & (0x40L)) > 0L) |
                      ((MPStatus.CurrentIconMask & (8L)) > 0L)) |
                     (MPStatus.CurrentPluginStatus == Status.PlayingDVD)) |
                    (MPStatus.CurrentPluginStatus == Status.PlayingTV)) |
                   (MPStatus.CurrentPluginStatus == Status.PlayingVideo)) |
                  (MPStatus.CurrentPluginStatus == Status.Timeshifting))
              {
                if ((MPStatus.CurrentPluginStatus == Status.PlayingTV) |
                    ((MPStatus.CurrentIconMask & (8L)) > 0L))
                {
                  num8 = 1;
                }
                else
                {
                  num8 = 2;
                }
                if (DisplaySettings.BlankDisplayWithVideo)
                {
                  DisplayOff();
                }
              }
              else
              {
                num8 = 3;
              }
              GetEQ();
            }
            else if (MPStatus.MediaPlayer_Paused)
            {
              icon.On();
              lock (DWriteMutex)
              {
                EQSettings._EqDataAvailable = false;
                _iconThread.Priority = ThreadPriority.BelowNormal;
              }
              RestoreDisplayFromVideoOrIdle();
              icon.FlashOn();
              num8 = 6;
            }
            else
            {
              icon.Off();
              RestoreDisplayFromVideoOrIdle();
              lock (DWriteMutex)
              {
                EQSettings._EqDataAvailable = false;
                _iconThread.Priority = ThreadPriority.BelowNormal;
              }
            }
            if ((!MiniDisplayHelper.Player_Playing() & !MiniDisplayHelper.IsCaptureCardViewing()) ||
                (DisplayOptions.DiskIcon & !DisplayOptions.DiskMediaStatus))
            {
              int num9 = 0;
              if (DisplayOptions.DiskIcon)
              {
                for (int m = 0; m < 0x1b; m++)
                {
                  num9 |= Inserted_Media[m];
                }
                switch (num9)
                {
                  case 1:
                    optionBitmask |= mask.ICON_CDIn;
                    goto Label_06B0;

                  case 2:
                    optionBitmask |= mask.ICON_DVDIn;
                    goto Label_06B0;
                }
                if (num9 > 0)
                {
                  optionBitmask |= mask.ICON_DiskOn;
                }
              }
            }
            Label_06B0:
            if (DisplayOptions.DiskIcon & DisplayOptions.DiskMediaStatus)
            {
              optionBitmask |= icon.Mask;
            }
            if (DoDebug)
            {
              Log.Info("iMONLCDg.UpdateIcons(): last = {0}, new = {1}, disk mask = {2}",
                       num2.ToString("X0000000000000000"), optionBitmask.ToString("X0000000000000000"),
                       icon.Mask.ToString("X0000000000000000"));
            }
            if (optionBitmask != num2)
            {
              lock (DWriteMutex)
              {
                SendData(iMonCommand.General.SetIcons, optionBitmask);
              }
            }
            DisplayEQ();
            if (DisplayOptions.VolumeDisplay || DisplayOptions.ProgressDisplay)
            {
              lock (DWriteMutex)
              {
                ShowProgressBars();
              }
            }
            if (num8 != num7)
            {
              _CurrentLargeIcon = num8;
            }
          }
        } while (EQSettings._EqDataAvailable && !MPStatus.MediaPlayer_Paused);
        Thread.Sleep(200);
      }
    }