当前位置: 首页>>代码示例>>C#>>正文


C# IFileSystemResourceAccessor.Clone方法代码示例

本文整理汇总了C#中IFileSystemResourceAccessor.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# IFileSystemResourceAccessor.Clone方法的具体用法?C# IFileSystemResourceAccessor.Clone怎么用?C# IFileSystemResourceAccessor.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IFileSystemResourceAccessor的用法示例。


在下文中一共展示了IFileSystemResourceAccessor.Clone方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TryMatchImdbId

    /// <summary>
    /// Tries to read a valid IMDB id from additional .nfo or .txt files.
    /// </summary>
    /// <param name="fsra">FileSystemResourceAccessor</param>
    /// <param name="imdbId">Returns a valid IMDB or <c>null</c></param>
    /// <returns>true if matched</returns>
    public static bool TryMatchImdbId(IFileSystemResourceAccessor fsra, out string imdbId)
    {
      imdbId = null;
      if (fsra == null)
        return false;

      // First try to find a nfo file that has the same name as our main movie.
      if (fsra.IsFile)
        foreach (string extension in NFO_EXTENSIONS)
        {
          string metaFilePath = ResourcePathHelper.ChangeExtension(fsra.CanonicalLocalResourcePath.ToString(), extension);
          if (TryRead(metaFilePath, out imdbId))
            return true;
        }

      // Prepare a list of paths to check: for chained resource path we will also check relative parent paths (like for DVD-ISO files)
      List<string> pathsToCheck = new List<string> { fsra.CanonicalLocalResourcePath.ToString() };
      if (fsra.CanonicalLocalResourcePath.PathSegments.Count > 1)
      {
        string canocialPath = fsra.CanonicalLocalResourcePath.ToString();
        pathsToCheck.Add(canocialPath.Substring(0, canocialPath.LastIndexOf('>')));
      }

      // Then test for special named files, like "movie.nfo"
      foreach (string path in pathsToCheck)
        foreach (string fileName in NFO_FILENAMES)
        {
          string metaFilePath = ResourcePathHelper.GetDirectoryName(path);
          metaFilePath = ResourcePathHelper.Combine(metaFilePath, fileName);
          if (TryRead(metaFilePath, out imdbId))
            return true;
        }

      // Now check siblings of movie for any IMDB id containing filename.
      IFileSystemResourceAccessor directoryFsra = null;
      if (!fsra.IsFile)
        directoryFsra = fsra.Clone() as IFileSystemResourceAccessor;
      if (fsra.IsFile)
        directoryFsra = GetContainingDirectory(fsra);

      if (directoryFsra == null)
        return false;

      using (directoryFsra)
        foreach (IFileSystemResourceAccessor file in directoryFsra.GetFiles())
          using (file)
            if (ImdbIdMatcher.TryMatchImdbId(file.ResourceName, out imdbId))
              return true;

      return false;
    }
开发者ID:HAF-Blade,项目名称:MediaPortal-2,代码行数:57,代码来源:NfoReader.cs


注:本文中的IFileSystemResourceAccessor.Clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。