diff options
| author | LukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com> | 2012-08-20 19:53:32 -0400 |
|---|---|---|
| committer | LukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com> | 2012-08-20 19:53:32 -0400 |
| commit | 758d18a652a157240bd80e9e2db7b47688ba3d3b (patch) | |
| tree | 7bb579872bf46ffee47261bc4257220a58eaf995 /MediaBrowser.Controller/IO | |
| parent | 6fbeee841f5c5f77e0a309a8fa6736b31b7210ec (diff) | |
Switched to low-level io methods for better performance
Diffstat (limited to 'MediaBrowser.Controller/IO')
| -rw-r--r-- | MediaBrowser.Controller/IO/DirectoryWatchers.cs | 6 | ||||
| -rw-r--r-- | MediaBrowser.Controller/IO/FileData.cs | 96 |
2 files changed, 99 insertions, 3 deletions
diff --git a/MediaBrowser.Controller/IO/DirectoryWatchers.cs b/MediaBrowser.Controller/IO/DirectoryWatchers.cs index e4eadbbd0..0a96990bf 100644 --- a/MediaBrowser.Controller/IO/DirectoryWatchers.cs +++ b/MediaBrowser.Controller/IO/DirectoryWatchers.cs @@ -83,7 +83,7 @@ namespace MediaBrowser.Controller.IO List<string> paths = affectedPaths;
affectedPaths = new List<string>();
- await ProcessPathChanges(paths);
+ await ProcessPathChanges(paths).ConfigureAwait(false);
}
private async Task ProcessPathChanges(IEnumerable<string> paths)
@@ -105,11 +105,11 @@ namespace MediaBrowser.Controller.IO return folder != null && folder.IsRoot;
}))
{
- await Kernel.Instance.ReloadRoot();
+ await Kernel.Instance.ReloadRoot().ConfigureAwait(false);
}
else
{
- await Task.WhenAll(itemsToRefresh.Select(i => Kernel.Instance.ReloadItem(i)));
+ await Task.WhenAll(itemsToRefresh.Select(i => Kernel.Instance.ReloadItem(i))).ConfigureAwait(false);
}
}
diff --git a/MediaBrowser.Controller/IO/FileData.cs b/MediaBrowser.Controller/IO/FileData.cs new file mode 100644 index 000000000..843a7e8fe --- /dev/null +++ b/MediaBrowser.Controller/IO/FileData.cs @@ -0,0 +1,96 @@ +using System;
+using System.IO;
+using System.Runtime.InteropServices;
+
+namespace MediaBrowser.Controller.IO
+{
+ public static class FileData
+ {
+ public const int MAX_PATH = 260;
+ public const int MAX_ALTERNATE = 14;
+
+ public static WIN32_FIND_DATA GetFileData(string fileName)
+ {
+ WIN32_FIND_DATA data;
+ IntPtr handle = FindFirstFile(fileName, out data);
+ if (handle == IntPtr.Zero)
+ throw new IOException("FindFirstFile failed");
+ FindClose(handle);
+ return data;
+ }
+
+ [DllImport("kernel32")]
+ private static extern IntPtr FindFirstFile(string fileName, out WIN32_FIND_DATA data);
+
+ [DllImport("kernel32")]
+ private static extern bool FindClose(IntPtr hFindFile);
+
+
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ public struct FILETIME
+ {
+ public uint dwLowDateTime;
+ public uint dwHighDateTime;
+ }
+
+ [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
+ public struct WIN32_FIND_DATA
+ {
+ public FileAttributes dwFileAttributes;
+ public FILETIME ftCreationTime;
+ public FILETIME ftLastAccessTime;
+ public FILETIME ftLastWriteTime;
+ public int nFileSizeHigh;
+ public int nFileSizeLow;
+ public int dwReserved0;
+ public int dwReserved1;
+
+ [MarshalAs(UnmanagedType.ByValTStr, SizeConst = FileData.MAX_PATH)]
+ public string cFileName;
+
+ [MarshalAs(UnmanagedType.ByValTStr, SizeConst = FileData.MAX_ALTERNATE)]
+ public string cAlternate;
+
+ public bool IsDirectory
+ {
+ get
+ {
+ return dwFileAttributes.HasFlag(FileAttributes.Directory);
+ }
+ }
+
+ public DateTime CreationTime
+ {
+ get
+ {
+ return ParseFileTime(ftCreationTime);
+ }
+ }
+
+ public DateTime LastAccessTime
+ {
+ get
+ {
+ return ParseFileTime(ftLastAccessTime);
+ }
+ }
+
+ public DateTime LastWriteTime
+ {
+ get
+ {
+ return ParseFileTime(ftLastWriteTime);
+ }
+ }
+
+ private DateTime ParseFileTime(FILETIME filetime)
+ {
+ long highBits = filetime.dwHighDateTime;
+ highBits = highBits << 32;
+ return DateTime.FromFileTime(highBits + (long)filetime.dwLowDateTime);
+ }
+ }
+
+}
|
