diff options
| author | LukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com> | 2012-08-23 16:51:10 -0400 |
|---|---|---|
| committer | LukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com> | 2012-08-23 16:51:10 -0400 |
| commit | f218e6b5832ad2eec2c6391bf2f942ecd6a0330f (patch) | |
| tree | 34b3de714c5769da5e2f50aece3aa56b4af58c41 /MediaBrowser.Controller/IO/FileData.cs | |
| parent | 8d693fd2ab2fecb4e15801c5d7104678ca791432 (diff) | |
More comments and cleanup. Added special feature provider for movies
Diffstat (limited to 'MediaBrowser.Controller/IO/FileData.cs')
| -rw-r--r-- | MediaBrowser.Controller/IO/FileData.cs | 61 |
1 files changed, 50 insertions, 11 deletions
diff --git a/MediaBrowser.Controller/IO/FileData.cs b/MediaBrowser.Controller/IO/FileData.cs index eca166ead..21d090a27 100644 --- a/MediaBrowser.Controller/IO/FileData.cs +++ b/MediaBrowser.Controller/IO/FileData.cs @@ -1,33 +1,62 @@ using System;
+using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
-using System.Runtime.ConstrainedExecution;
-using Microsoft.Win32.SafeHandles;
-using System.Collections.Generic;
-using System.Linq;
-
namespace MediaBrowser.Controller.IO
{
+ /// <summary>
+ /// Provides low level File access that is much faster than the File/Directory api's
+ /// </summary>
public static class FileData
{
public const int MAX_PATH = 260;
public const int MAX_ALTERNATE = 14;
- public static WIN32_FIND_DATA GetFileData(string fileName)
+ /// <summary>
+ /// Gets information about a path
+ /// </summary>
+ public static WIN32_FIND_DATA GetFileData(string path)
{
WIN32_FIND_DATA data;
- IntPtr handle = FindFirstFile(fileName, out data);
+ IntPtr handle = FindFirstFile(path, out data);
if (handle == IntPtr.Zero)
throw new IOException("FindFirstFile failed");
FindClose(handle);
- data.Path = fileName;
+ data.Path = path;
return data;
}
+ /// <summary>
+ /// Gets all file system entries within a foler
+ /// </summary>
public static IEnumerable<WIN32_FIND_DATA> GetFileSystemEntries(string path, string searchPattern)
{
+ return GetFileSystemEntries(path, searchPattern, true, true);
+ }
+
+ /// <summary>
+ /// Gets all files within a folder
+ /// </summary>
+ public static IEnumerable<WIN32_FIND_DATA> GetFiles(string path, string searchPattern)
+ {
+ return GetFileSystemEntries(path, searchPattern, true, false);
+ }
+
+ /// <summary>
+ /// Gets all sub-directories within a folder
+ /// </summary>
+ public static IEnumerable<WIN32_FIND_DATA> GetDirectories(string path, string searchPattern)
+ {
+ return GetFileSystemEntries(path, searchPattern, false, true);
+ }
+
+ /// <summary>
+ /// Gets all file system entries within a foler
+ /// </summary>
+ public static IEnumerable<WIN32_FIND_DATA> GetFileSystemEntries(string path, string searchPattern, bool includeFiles, bool includeDirectories)
+ {
string lpFileName = Path.Combine(path, searchPattern);
WIN32_FIND_DATA lpFindFileData;
@@ -43,14 +72,14 @@ namespace MediaBrowser.Controller.IO yield break;
}
- if (IsValid(lpFindFileData.cFileName))
+ if (IncludeInOutput(lpFindFileData.cFileName, lpFindFileData.dwFileAttributes, includeFiles, includeDirectories))
{
yield return lpFindFileData;
}
while (FindNextFile(handle, out lpFindFileData) != IntPtr.Zero)
{
- if (IsValid(lpFindFileData.cFileName))
+ if (IncludeInOutput(lpFindFileData.cFileName, lpFindFileData.dwFileAttributes, includeFiles, includeDirectories))
{
lpFindFileData.Path = Path.Combine(path, lpFindFileData.cFileName);
yield return lpFindFileData;
@@ -60,7 +89,7 @@ namespace MediaBrowser.Controller.IO FindClose(handle);
}
- private static bool IsValid(string cFileName)
+ private static bool IncludeInOutput(string cFileName, FileAttributes attributes, bool includeFiles, bool includeDirectories)
{
if (cFileName.Equals(".", StringComparison.OrdinalIgnoreCase))
{
@@ -71,6 +100,16 @@ namespace MediaBrowser.Controller.IO return false;
}
+ if (!includeFiles && !attributes.HasFlag(FileAttributes.Directory))
+ {
+ return false;
+ }
+
+ if (!includeDirectories && attributes.HasFlag(FileAttributes.Directory))
+ {
+ return false;
+ }
+
return true;
}
|
