Ejemplo n.º 1
0
        /// <summary>
        /// Helper method which simulates a user navigation under this view specification to the given <paramref name="targetPath"/>
        /// under the given <paramref name="localShare"/>.
        /// </summary>
        /// <param name="localShare">Client or server share which is located at the local system.</param>
        /// <param name="targetPath">Resource path to navigate to. This path must be located under the given <paramref name="localShare"/>'s base path.</param>
        /// <param name="navigateToViewDlgt">Callback which will be called for each view specification to navigate to to do the actual navigation.</param>
        public void Navigate(Share localShare, ResourcePath targetPath, NavigateToViewDlgt navigateToViewDlgt)
        {
            NavigateToLocalRootView(localShare, navigateToViewDlgt);
            IResourceAccessor startRA;

            if (!localShare.BaseResourcePath.TryCreateLocalResourceAccessor(out startRA))
            {
                return;
            }
            IFileSystemResourceAccessor current = startRA as IFileSystemResourceAccessor;

            if (current == null)
            {
                // Wrong path resource, cannot navigate. Should not happen if the share is based on a filesystem resource,
                // but might happen if we have found a non-standard share.
                startRA.Dispose();
                return;
            }
            while (true)
            {
                ICollection <IFileSystemResourceAccessor> children = FileSystemResourceNavigator.GetChildDirectories(current, false);
                current.Dispose();
                current = null;
                if (children != null)
                {
                    foreach (IFileSystemResourceAccessor childDirectory in children)
                    {
                        using (childDirectory)
                        {
                            if (childDirectory.CanonicalLocalResourcePath.IsSameOrParentOf(targetPath))
                            {
                                current = childDirectory;
                                break;
                            }
                        }
                    }
                }
                if (current == null)
                {
                    break;
                }
                ViewSpecification newVS = NavigateCreateViewSpecification(localShare.SystemId, current);
                if (newVS == null)
                {
                    current.Dispose();
                    return;
                }
                navigateToViewDlgt(newVS);
            }
        }
 protected override void FreeData()
 {
     _texture = null;
     _stream.Close();
     _resourceAccessor.Dispose();
     base.FreeData();
 }
Ejemplo n.º 3
0
 public virtual void Dispose()
 {
     if (_accessor != null)
     {
         _accessor.Dispose();
     }
 }
        /// <summary>
        /// Returns a resource accessor instance of interface <see cref="ILocalFsResourceAccessor"/>. This instance will return the
        /// given <paramref name="baseResourceAccessor"/>, casted to <see cref="ILocalFsResourceAccessor"/> if possible, or
        /// a new instance of <see cref="StreamedResourceToLocalFsAccessBridge"/> to provide the <see cref="ILocalFsResourceAccessor"/>
        /// instance.
        /// </summary>
        /// <remarks>
        /// The ownership of the given <paramref name="baseResourceAccessor"/> is transferred from the caller to the returned
        /// result value. That means, if this method succeeds, the caller must dispose the result value, it must not dispose
        /// the given <paramref name="baseResourceAccessor"/> any more.
        /// </remarks>
        /// <param name="baseResourceAccessor">Resource accessor which is used to provide the resource contents.</param>
        /// <param name="path">Relative path based on the given baseResourceAccessor.</param>
        /// <returns>Resource accessor which implements <see cref="ILocalFsResourceAccessor"/>.</returns>
        public static ILocalFsResourceAccessor GetLocalFsResourceAccessor(IFileSystemResourceAccessor baseResourceAccessor, string path)
        {
            // Try to get an ILocalFsResourceAccessor
            ILocalFsResourceAccessor result = baseResourceAccessor as ILocalFsResourceAccessor;

            if (result != null)
            {
                // Simple case: The media item is located in the local file system or the resource provider returns
                // an ILocalFsResourceAccessor from elsewhere - simply return it
                return(result);
            }

            // Set up a resource bridge mapping the remote or complex resource to a local file or directory
            string            key = baseResourceAccessor.CanonicalLocalResourcePath.Serialize();
            MountingDataProxy md;
            bool dispose = false;

            lock (_syncObj)
            {
                if (_activeMounts.TryGetValue(key, out md))
                {
                    // Base accessor not needed - we use our cached accessor
                    dispose = true;
                }
                else
                {
                    _activeMounts.Add(key, md = CreateMountingDataProxy(key, baseResourceAccessor));
                }
            }
            if (dispose)
            {
                baseResourceAccessor.Dispose();
            }
            return(new StreamedResourceToLocalFsAccessBridge(md, path));
        }
        public IFileSystemResourceAccessor GetResource(string path)
        {
            IFileSystemResourceAccessor ra = (IFileSystemResourceAccessor)_mountingDataProxy.ResourceAccessor.Clone();

            try
            {
                return(GetLocalFsResourceAccessor(ra, ProviderPathHelper.Combine(_path, path)));
            }
            catch
            {
                ra.Dispose();
                throw;
            }
        }
Ejemplo n.º 6
0
 public void Dispose()
 {
     try
     {
         if (_resourceAccessor != null)
         {
             _resourceAccessor.Dispose();
         }
     }
     catch (Exception e)
     {
         ServiceRegistration.Get <ILogger>().Warn("PendingImportResource: Could not dispose resource", e);
     }
 }
Ejemplo n.º 7
0
 public void Dispose()
 {
     if (_baseAccessor == null)
     {
         // Already disposed
         return;
     }
     if (!UnmountResource())
     {
         // The ownership was transferred to the resource mounting service, so if unmounting was succesful, we must not dispose our base accessor
         _baseAccessor.Dispose();
     }
     _baseAccessor = null;
 }
Ejemplo n.º 8
0
 public void Dispose()
 {
     _parentImportJobController.UnregisterPendingImportResource(this);
     try
     {
         if (_resourceAccessor != null)
         {
             _resourceAccessor.Dispose();
             _resourceAccessor = null;
         }
     }
     catch (Exception e)
     {
         ServiceRegistration.Get <ILogger>().Warn("PendingImportResource: Could not dispose resource", e);
     }
 }
Ejemplo n.º 9
0
 public virtual void Dispose()
 {
     foreach (FileHandle handle in _fileHandles)
     {
         handle.Cleanup();
     }
     if (_resourceAccessor != null)
     {
         try
         {
             _resourceAccessor.Dispose();
         }
         catch (Exception e)
         {
             ServiceRegistration.Get <ILogger>().Warn("Dokan virtual filesystem resource: Error disposing resource accessor '{0}'", e, _resourceAccessor);
         }
     }
     _resourceAccessor = null;
 }
Ejemplo n.º 10
0
 public void Dispose()
 {
     foreach (string tempFilePath in _tempFilePaths.Values)
     {
         try
         {
             File.Delete(tempFilePath);
         }
         catch (Exception e)
         {
             ServiceRegistration.Get <ILogger>().Warn("ZipResourceProxy: Unable to delete temp file '{0}'", e, tempFilePath);
         }
     }
     _tempFilePaths.Clear();
     CloseZipFile();
     if (_zipFileResourceAccessor != null)
     {
         _zipFileResourceAccessor.Dispose();
         _zipFileResourceAccessor = null;
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Creates a new <see cref="LocalFsResourceAccessor"/> instance. The given <paramref name="mediaItemAccessor"/> will be either directly used or
        /// given over to the <see cref="StreamedResourceToLocalFsAccessBridge"/>. The caller must call <see cref="Dispose"/> on the created <see cref="LocalFsResourceAccessorHelper"/>
        /// instance but must not dispose the given <paramref name="mediaItemAccessor"/>.
        /// </summary>
        /// <param name="mediaItemAccessor">IResourceAccessor.</param>
        public LocalFsResourceAccessorHelper(IResourceAccessor mediaItemAccessor)
        {
            _localFsra    = mediaItemAccessor as ILocalFsResourceAccessor;
            _disposeLfsra = null;
            if (_localFsra != null)
            {
                return;
            }

            IFileSystemResourceAccessor localFsra = (IFileSystemResourceAccessor)mediaItemAccessor.Clone();

            try
            {
                _localFsra    = StreamedResourceToLocalFsAccessBridge.GetLocalFsResourceAccessor(localFsra);
                _disposeLfsra = _localFsra;
            }
            catch (Exception)
            {
                localFsra.Dispose();
                throw;
            }
        }
Ejemplo n.º 12
0
 public void Dispose()
 {
     if (_diskFileSystem != null)
     {
         IDisposable d = _diskFileSystem as IDisposable;
         if (d != null)
         {
             d.Dispose();
         }
         _diskFileSystem = null;
     }
     if (_underlayingStream != null)
     {
         _underlayingStream.Dispose();
         _underlayingStream = null;
     }
     if (_isoFileResourceAccessor != null)
     {
         _isoFileResourceAccessor.Dispose();
         _isoFileResourceAccessor = null;
     }
 }
Ejemplo n.º 13
0
 public void Dispose()
 {
     _resourceAccessor.Dispose();
     _resourceAccessor = null;
 }
    /// <summary>
    /// Returns a resource accessor instance of interface <see cref="ILocalFsResourceAccessor"/>. This instance will return the
    /// given <paramref name="baseResourceAccessor"/>, casted to <see cref="ILocalFsResourceAccessor"/> if possible, or
    /// a new instance of <see cref="StreamedResourceToLocalFsAccessBridge"/> to provide the <see cref="ILocalFsResourceAccessor"/>
    /// instance.
    /// </summary>
    /// <remarks>
    /// The ownership of the given <paramref name="baseResourceAccessor"/> is transferred from the caller to the returned
    /// result value. That means, if this method succeeds, the caller must dispose the result value, it must not dispose
    /// the given <paramref name="baseResourceAccessor"/> any more.
    /// </remarks>
    /// <param name="baseResourceAccessor">Resource accessor which is used to provide the resource contents.</param>
    /// <param name="path">Relative path based on the given baseResourceAccessor.</param>
    /// <returns>Resource accessor which implements <see cref="ILocalFsResourceAccessor"/>.</returns>
    public static ILocalFsResourceAccessor GetLocalFsResourceAccessor(IFileSystemResourceAccessor baseResourceAccessor, string path)
    {
      // Try to get an ILocalFsResourceAccessor
      ILocalFsResourceAccessor result = baseResourceAccessor as ILocalFsResourceAccessor;
      if (result != null)
          // Simple case: The media item is located in the local file system or the resource provider returns
          // an ILocalFsResourceAccessor from elsewhere - simply return it
        return result;

      // Set up a resource bridge mapping the remote or complex resource to a local file or directory
      string key = baseResourceAccessor.CanonicalLocalResourcePath.Serialize();
      MountingDataProxy md;
      bool dispose = false;
      lock (_syncObj)
      {
        if (_activeMounts.TryGetValue(key, out md))
            // Base accessor not needed - we use our cached accessor
          dispose = true;
        else
          _activeMounts.Add(key, md = CreateMountingDataProxy(key, baseResourceAccessor));
      }
      if (dispose)
        baseResourceAccessor.Dispose();
      return new StreamedResourceToLocalFsAccessBridge(md, path);
    }
        public bool TryExtractMetadata(IResourceAccessor mediaItemAccessor, IDictionary <Guid, MediaItemAspect> extractedAspectData, bool forceQuickMode)
        {
            try
            {
                VideoResult result = null;
                IFileSystemResourceAccessor fsra = mediaItemAccessor as IFileSystemResourceAccessor;
                if (fsra == null)
                {
                    return(false);
                }
                if (!fsra.IsFile && fsra.ResourceExists("VIDEO_TS"))
                {
                    IFileSystemResourceAccessor fsraVideoTs = fsra.GetResource("VIDEO_TS");
                    if (fsraVideoTs != null && fsraVideoTs.ResourceExists("VIDEO_TS.IFO"))
                    {
                        // Video DVD
                        using (MediaInfoWrapper videoTsInfo = ReadMediaInfo(fsraVideoTs.GetResource("VIDEO_TS.IFO")))
                        {
                            if (!videoTsInfo.IsValid || videoTsInfo.GetVideoCount() == 0)
                            {
                                return(false); // Invalid video_ts.ifo file
                            }
                            result = VideoResult.CreateDVDInfo(fsra.ResourceName, videoTsInfo);
                        }
                        // Iterate over all video files; MediaInfo finds different audio/video metadata for each .ifo file
                        ICollection <IFileSystemResourceAccessor> files = fsraVideoTs.GetFiles();
                        if (files != null)
                        {
                            foreach (IFileSystemResourceAccessor file in files)
                            {
                                string lowerPath = (file.ResourcePathName ?? string.Empty).ToLowerInvariant();
                                if (!lowerPath.EndsWith(".ifo") || lowerPath.EndsWith("video_ts.ifo"))
                                {
                                    continue;
                                }
                                using (MediaInfoWrapper mediaInfo = ReadMediaInfo(file))
                                {
                                    // Before we start evaluating the file, check if it is a video at all
                                    if (mediaInfo.IsValid && mediaInfo.GetVideoCount() == 0)
                                    {
                                        continue;
                                    }
                                    result.AddMediaInfo(mediaInfo);
                                }
                            }
                        }
                    }
                }
                else if (fsra.IsFile)
                {
                    string filePath = fsra.ResourcePathName;
                    if (!HasVideoExtension(filePath))
                    {
                        return(false);
                    }
                    using (MediaInfoWrapper fileInfo = ReadMediaInfo(fsra))
                    {
                        // Before we start evaluating the file, check if it is a video at all
                        if (!fileInfo.IsValid || (fileInfo.GetVideoCount() == 0 && !IsWorkaroundRequired(filePath)))
                        {
                            return(false);
                        }

                        string mediaTitle = DosPathHelper.GetFileNameWithoutExtension(fsra.ResourceName);
                        result = VideoResult.CreateFileInfo(mediaTitle, fileInfo);
                    }
                    using (Stream stream = fsra.OpenRead())
                        result.MimeType = MimeTypeDetector.GetMimeType(stream, DEFAULT_MIMETYPE);
                }
                if (result != null)
                {
                    result.UpdateMetadata(extractedAspectData);

                    ILocalFsResourceAccessor disposeLfsra = null;
                    try
                    {
                        ILocalFsResourceAccessor lfsra = fsra as ILocalFsResourceAccessor;
                        if (lfsra == null && !forceQuickMode)
                        { // In case forceQuickMode, we only want local browsing
                            IFileSystemResourceAccessor localFsra = (IFileSystemResourceAccessor)fsra.Clone();
                            try
                            {
                                lfsra        = StreamedResourceToLocalFsAccessBridge.GetLocalFsResourceAccessor(localFsra);
                                disposeLfsra = lfsra; // Remember to dispose the extra resource accessor instance
                            }
                            catch (Exception)
                            {
                                localFsra.Dispose();
                            }
                        }
                        if (lfsra != null)
                        {
                            string localFsPath = lfsra.LocalFileSystemPath;
                            ExtractMatroskaTags(localFsPath, extractedAspectData, forceQuickMode);
                            ExtractMp4Tags(localFsPath, extractedAspectData, forceQuickMode);
                            ExtractThumbnailData(localFsPath, extractedAspectData, forceQuickMode);
                        }
                    }
                    finally
                    {
                        if (disposeLfsra != null)
                        {
                            disposeLfsra.Dispose();
                        }
                    }
                    return(true);
                }
            }
            catch (Exception e)
            {
                // Only log at the info level here - And simply return false. This lets the caller know that we
                // couldn't perform our task here.
                ServiceRegistration.Get <ILogger>().Info("VideoMetadataExtractor: Exception reading resource '{0}' (Text: '{1}')", mediaItemAccessor.CanonicalLocalResourcePath, e.Message);
            }
            return(false);
        }