aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2013-10-31 10:03:23 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2013-10-31 10:03:23 -0400
commit6c8d9192985036acb3d1fe626ed57980bb862d6a (patch)
tree94d59b266b877bf0b073c5e3291cb2822dc055f7 /MediaBrowser.Controller
parent579b507f7fa322fdf8a746b6e787015d0567e2a6 (diff)
replace file system calls with IFileSystem when needed
Diffstat (limited to 'MediaBrowser.Controller')
-rw-r--r--MediaBrowser.Controller/Entities/BaseItem.cs5
-rw-r--r--MediaBrowser.Controller/Entities/User.cs2
-rw-r--r--MediaBrowser.Controller/IO/FileData.cs3
-rw-r--r--MediaBrowser.Controller/IO/FileSystem.cs71
-rw-r--r--MediaBrowser.Controller/IO/IFileSystem.cs53
-rw-r--r--MediaBrowser.Controller/MediaBrowser.Controller.csproj2
-rw-r--r--MediaBrowser.Controller/MediaInfo/FFMpegManager.cs8
-rw-r--r--MediaBrowser.Controller/Resolvers/EntityResolutionHelper.cs9
8 files changed, 17 insertions, 136 deletions
diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs
index f1937a4616..839fe34ffe 100644
--- a/MediaBrowser.Controller/Entities/BaseItem.cs
+++ b/MediaBrowser.Controller/Entities/BaseItem.cs
@@ -1,4 +1,5 @@
using MediaBrowser.Common.Extensions;
+using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.IO;
@@ -1737,7 +1738,7 @@ namespace MediaBrowser.Controller.Entities
if (locationType == LocationType.Remote ||
locationType == LocationType.Virtual)
{
- return File.GetLastWriteTimeUtc(imagePath);
+ return FileSystem.GetLastWriteTimeUtc(imagePath);
}
var metaFileEntry = ResolveArgs.GetMetaFileByPath(imagePath);
@@ -1754,7 +1755,7 @@ namespace MediaBrowser.Controller.Entities
}
// See if we can avoid a file system lookup by looking for the file in ResolveArgs
- return metaFileEntry == null ? File.GetLastWriteTimeUtc(imagePath) : metaFileEntry.LastWriteTimeUtc;
+ return metaFileEntry == null ? FileSystem.GetLastWriteTimeUtc(imagePath) : FileSystem.GetLastWriteTimeUtc(metaFileEntry);
}
}
}
diff --git a/MediaBrowser.Controller/Entities/User.cs b/MediaBrowser.Controller/Entities/User.cs
index 9d85399067..06f50e552b 100644
--- a/MediaBrowser.Controller/Entities/User.cs
+++ b/MediaBrowser.Controller/Entities/User.cs
@@ -165,7 +165,7 @@ namespace MediaBrowser.Controller.Entities
// Ensure it's been lazy loaded
var config = Configuration;
- return File.GetLastWriteTimeUtc(ConfigurationFilePath);
+ return FileSystem.GetLastWriteTimeUtc(ConfigurationFilePath);
}
}
diff --git a/MediaBrowser.Controller/IO/FileData.cs b/MediaBrowser.Controller/IO/FileData.cs
index 726467fa6a..270afd89a1 100644
--- a/MediaBrowser.Controller/IO/FileData.cs
+++ b/MediaBrowser.Controller/IO/FileData.cs
@@ -1,4 +1,5 @@
-using MediaBrowser.Controller.Library;
+using MediaBrowser.Common.IO;
+using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Generic;
diff --git a/MediaBrowser.Controller/IO/FileSystem.cs b/MediaBrowser.Controller/IO/FileSystem.cs
deleted file mode 100644
index b08e8da274..0000000000
--- a/MediaBrowser.Controller/IO/FileSystem.cs
+++ /dev/null
@@ -1,71 +0,0 @@
-using MediaBrowser.Model.Logging;
-using System;
-using System.IO;
-
-namespace MediaBrowser.Controller.IO
-{
- /// <summary>
- /// Class FileSystem
- /// </summary>
- public static class FileSystem
- {
- /// <summary>
- /// Gets the creation time UTC.
- /// </summary>
- /// <param name="info">The info.</param>
- /// <param name="logger">The logger.</param>
- /// <returns>DateTime.</returns>
- public static DateTime GetLastWriteTimeUtc(FileSystemInfo info, ILogger logger)
- {
- // This could throw an error on some file systems that have dates out of range
-
- try
- {
- return info.LastWriteTimeUtc;
- }
- catch (Exception ex)
- {
- logger.ErrorException("Error determining LastAccessTimeUtc for {0}", ex, info.FullName);
- return DateTime.MinValue;
- }
- }
-
- /// <summary>
- /// Copies all.
- /// </summary>
- /// <param name="source">The source.</param>
- /// <param name="target">The target.</param>
- /// <exception cref="System.ArgumentNullException">source</exception>
- /// <exception cref="System.ArgumentException">The source and target directories are the same</exception>
- public static void CopyAll(string source, string target)
- {
- if (string.IsNullOrEmpty(source))
- {
- throw new ArgumentNullException("source");
- }
- if (string.IsNullOrEmpty(target))
- {
- throw new ArgumentNullException("target");
- }
-
- if (source.Equals(target, StringComparison.OrdinalIgnoreCase))
- {
- throw new ArgumentException("The source and target directories are the same");
- }
-
- // Check if the target directory exists, if not, create it.
- Directory.CreateDirectory(target);
-
- foreach (var file in Directory.EnumerateFiles(source))
- {
- File.Copy(file, Path.Combine(target, Path.GetFileName(file)), true);
- }
-
- // Copy each subdirectory using recursion.
- foreach (var dir in Directory.EnumerateDirectories(source))
- {
- CopyAll(dir, Path.Combine(target, Path.GetFileName(dir)));
- }
- }
- }
-}
diff --git a/MediaBrowser.Controller/IO/IFileSystem.cs b/MediaBrowser.Controller/IO/IFileSystem.cs
deleted file mode 100644
index cbc5c7bf34..0000000000
--- a/MediaBrowser.Controller/IO/IFileSystem.cs
+++ /dev/null
@@ -1,53 +0,0 @@
-using System;
-using System.IO;
-
-namespace MediaBrowser.Controller.IO
-{
- /// <summary>
- /// Interface IFileSystem
- /// </summary>
- public interface IFileSystem
- {
- /// <summary>
- /// Determines whether the specified filename is shortcut.
- /// </summary>
- /// <param name="filename">The filename.</param>
- /// <returns><c>true</c> if the specified filename is shortcut; otherwise, <c>false</c>.</returns>
- bool IsShortcut(string filename);
-
- /// <summary>
- /// Resolves the shortcut.
- /// </summary>
- /// <param name="filename">The filename.</param>
- /// <returns>System.String.</returns>
- string ResolveShortcut(string filename);
-
- /// <summary>
- /// Creates the shortcut.
- /// </summary>
- /// <param name="shortcutPath">The shortcut path.</param>
- /// <param name="target">The target.</param>
- void CreateShortcut(string shortcutPath, string target);
-
- /// <summary>
- /// Gets the file system info.
- /// </summary>
- /// <param name="path">The path.</param>
- /// <returns>FileSystemInfo.</returns>
- FileSystemInfo GetFileSystemInfo(string path);
-
- /// <summary>
- /// Gets the valid filename.
- /// </summary>
- /// <param name="filename">The filename.</param>
- /// <returns>System.String.</returns>
- string GetValidFilename(string filename);
-
- /// <summary>
- /// Gets the creation time UTC.
- /// </summary>
- /// <param name="info">The info.</param>
- /// <returns>DateTime.</returns>
- DateTime GetCreationTimeUtc(FileSystemInfo info);
- }
-}
diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj
index c379714aa3..978d56bd4e 100644
--- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj
+++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj
@@ -94,7 +94,6 @@
<Compile Include="Entities\ImageSourceInfo.cs" />
<Compile Include="Entities\LinkedChild.cs" />
<Compile Include="Entities\MusicVideo.cs" />
- <Compile Include="IO\IFileSystem.cs" />
<Compile Include="Library\ILibraryPostScanTask.cs" />
<Compile Include="Library\ILibraryPrescanTask.cs" />
<Compile Include="Library\IMetadataSaver.cs" />
@@ -141,7 +140,6 @@
<Compile Include="Entities\Video.cs" />
<Compile Include="Entities\CollectionFolder.cs" />
<Compile Include="Entities\Year.cs" />
- <Compile Include="IO\FileSystem.cs" />
<Compile Include="IO\IDirectoryWatchers.cs" />
<Compile Include="IServerApplicationHost.cs" />
<Compile Include="IServerApplicationPaths.cs" />
diff --git a/MediaBrowser.Controller/MediaInfo/FFMpegManager.cs b/MediaBrowser.Controller/MediaInfo/FFMpegManager.cs
index 87036df84e..fd1b12c2f2 100644
--- a/MediaBrowser.Controller/MediaInfo/FFMpegManager.cs
+++ b/MediaBrowser.Controller/MediaInfo/FFMpegManager.cs
@@ -1,6 +1,7 @@
using MediaBrowser.Common.IO;
using MediaBrowser.Common.MediaInfo;
using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
@@ -35,6 +36,8 @@ namespace MediaBrowser.Controller.MediaInfo
private readonly ILogger _logger;
private readonly IItemRepository _itemRepo;
+ private readonly IFileSystem _fileSystem;
+
/// <summary>
/// Initializes a new instance of the <see cref="FFMpegManager" /> class.
/// </summary>
@@ -43,12 +46,13 @@ namespace MediaBrowser.Controller.MediaInfo
/// <param name="logger">The logger.</param>
/// <param name="itemRepo">The item repo.</param>
/// <exception cref="System.ArgumentNullException">zipClient</exception>
- public FFMpegManager(IServerApplicationPaths appPaths, IMediaEncoder encoder, ILogger logger, IItemRepository itemRepo)
+ public FFMpegManager(IServerApplicationPaths appPaths, IMediaEncoder encoder, ILogger logger, IItemRepository itemRepo, IFileSystem fileSystem)
{
_appPaths = appPaths;
_encoder = encoder;
_logger = logger;
_itemRepo = itemRepo;
+ _fileSystem = fileSystem;
VideoImageCache = new FileSystemRepository(VideoImagesDataPath);
SubtitleCache = new FileSystemRepository(SubtitleCachePath);
@@ -203,7 +207,7 @@ namespace MediaBrowser.Controller.MediaInfo
if (stream.IsExternal)
{
- ticksParam += File.GetLastWriteTimeUtc(stream.Path).Ticks;
+ ticksParam += _fileSystem.GetLastWriteTimeUtc(stream.Path).Ticks;
}
return SubtitleCache.GetResourcePath(input.Id + "_" + subtitleStreamIndex + "_" + input.DateModified.Ticks + ticksParam, outputExtension);
diff --git a/MediaBrowser.Controller/Resolvers/EntityResolutionHelper.cs b/MediaBrowser.Controller/Resolvers/EntityResolutionHelper.cs
index 5d61e5eb9c..1e4fabc7c2 100644
--- a/MediaBrowser.Controller/Resolvers/EntityResolutionHelper.cs
+++ b/MediaBrowser.Controller/Resolvers/EntityResolutionHelper.cs
@@ -1,4 +1,5 @@
-using MediaBrowser.Controller.Entities;
+using MediaBrowser.Common.IO;
+using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Library;
using System;
@@ -149,7 +150,7 @@ namespace MediaBrowser.Controller.Resolvers
item.DateCreated = fileSystem.GetCreationTimeUtc(childData);
}
- item.DateModified = childData.LastWriteTimeUtc;
+ item.DateModified = fileSystem.GetLastWriteTimeUtc(childData);
}
else
{
@@ -161,7 +162,7 @@ namespace MediaBrowser.Controller.Resolvers
{
item.DateCreated = fileSystem.GetCreationTimeUtc(fileData);
}
- item.DateModified = fileData.LastWriteTimeUtc;
+ item.DateModified = fileSystem.GetLastWriteTimeUtc(fileData);
}
}
}
@@ -171,7 +172,7 @@ namespace MediaBrowser.Controller.Resolvers
{
item.DateCreated = fileSystem.GetCreationTimeUtc(args.FileInfo);
}
- item.DateModified = args.FileInfo.LastWriteTimeUtc;
+ item.DateModified = fileSystem.GetLastWriteTimeUtc(args.FileInfo);
}
}
}