aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common.Implementations
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2014-10-06 19:58:46 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2014-10-06 19:58:46 -0400
commitf02f3222085311b2a2cacab6642ad987a4176e65 (patch)
tree9f317e5a3f087d4b4c5e523a8d8552d7d248567e /MediaBrowser.Common.Implementations
parenta9eed234ba2a366fe014f0cc6f462c3764528948 (diff)
remove mono compiler directives
Diffstat (limited to 'MediaBrowser.Common.Implementations')
-rw-r--r--MediaBrowser.Common.Implementations/BaseApplicationHost.cs11
-rw-r--r--MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs42
2 files changed, 29 insertions, 24 deletions
diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs
index c59d1a3b0..5a5d48ac2 100644
--- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs
+++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs
@@ -196,12 +196,15 @@ namespace MediaBrowser.Common.Implementations
/// <summary>
/// Initializes a new instance of the <see cref="BaseApplicationHost{TApplicationPathsType}"/> class.
/// </summary>
- protected BaseApplicationHost(TApplicationPathsType applicationPaths, ILogManager logManager)
+ protected BaseApplicationHost(TApplicationPathsType applicationPaths,
+ ILogManager logManager,
+ IFileSystem fileSystem)
{
FailedAssemblies = new List<string>();
ApplicationPaths = applicationPaths;
LogManager = logManager;
+ FileSystemManager = fileSystem;
ConfigurationManager = GetConfigurationManager();
}
@@ -441,7 +444,6 @@ namespace MediaBrowser.Common.Implementations
RegisterSingleInstance(TaskManager);
- FileSystemManager = CreateFileSystemManager();
RegisterSingleInstance(FileSystemManager);
HttpClient = new HttpClientManager.HttpClientManager(ApplicationPaths, Logger, FileSystemManager, ConfigurationManager);
@@ -485,11 +487,6 @@ namespace MediaBrowser.Common.Implementations
}
}
- protected virtual IFileSystem CreateFileSystemManager()
- {
- return new CommonFileSystem(Logger, true);
- }
-
/// <summary>
/// Gets a list of types within an assembly
/// This will handle situations that would normally throw an exception - such as a type within the assembly that depends on some other non-existant reference
diff --git a/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs b/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs
index 2d67ec975..cc89fad35 100644
--- a/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs
+++ b/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs
@@ -15,11 +15,31 @@ namespace MediaBrowser.Common.Implementations.IO
protected ILogger Logger;
private readonly bool _supportsAsyncFileStreams;
+ private char[] _invalidFileNameChars;
- public CommonFileSystem(ILogger logger, bool supportsAsyncFileStreams)
+ public CommonFileSystem(ILogger logger, bool supportsAsyncFileStreams, bool usePresetInvalidFileNameChars)
{
Logger = logger;
_supportsAsyncFileStreams = supportsAsyncFileStreams;
+
+ SetInvalidFileNameChars(usePresetInvalidFileNameChars);
+ }
+
+ private void SetInvalidFileNameChars(bool usePresetInvalidFileNameChars)
+ {
+ // GetInvalidFileNameChars is less restrictive in Linux/Mac than Windows, this mimic Windows behavior for mono under Linux/Mac.
+
+ if (usePresetInvalidFileNameChars)
+ {
+ _invalidFileNameChars = new char[41] { '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07',
+ '\x08', '\x09', '\x0A', '\x0B', '\x0C', '\x0D', '\x0E', '\x0F', '\x10', '\x11', '\x12',
+ '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1A', '\x1B', '\x1C', '\x1D',
+ '\x1E', '\x1F', '\x22', '\x3C', '\x3E', '\x7C', ':', '*', '?', '\\', '/' };
+ }
+ else
+ {
+ _invalidFileNameChars = Path.GetInvalidFileNameChars();
+ }
}
/// <summary>
@@ -129,18 +149,6 @@ namespace MediaBrowser.Common.Implementations.IO
/// The space char
/// </summary>
private const char SpaceChar = ' ';
- /// <summary>
- /// The invalid file name chars
- /// </summary>
- #if __MonoCS__
- //GetInvalidFileNameChars is less restrictive in Linux/Mac than Windows, this mimic Windows behavior for mono under Linux/Mac.
- private static readonly char[] InvalidFileNameChars = new char [41] { '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07',
- '\x08', '\x09', '\x0A', '\x0B', '\x0C', '\x0D', '\x0E', '\x0F', '\x10', '\x11', '\x12',
- '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1A', '\x1B', '\x1C', '\x1D',
- '\x1E', '\x1F', '\x22', '\x3C', '\x3E', '\x7C', ':', '*', '?', '\\', '/' };
- #else
- private static readonly char[] InvalidFileNameChars = Path.GetInvalidFileNameChars();
- #endif
/// <summary>
/// Takes a filename and removes invalid characters
@@ -157,7 +165,7 @@ namespace MediaBrowser.Common.Implementations.IO
var builder = new StringBuilder(filename);
- foreach (var c in InvalidFileNameChars)
+ foreach (var c in _invalidFileNameChars)
{
builder = builder.Replace(c, SpaceChar);
}
@@ -300,7 +308,7 @@ namespace MediaBrowser.Common.Implementations.IO
{
throw new ArgumentNullException("path");
}
-
+
return path.IndexOf(parentPath.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase) != -1;
}
@@ -310,12 +318,12 @@ namespace MediaBrowser.Common.Implementations.IO
{
throw new ArgumentNullException("path");
}
-
+
var parent = Path.GetDirectoryName(path);
if (!string.IsNullOrEmpty(parent))
{
- return false;
+ return false;
}
return true;