Unwrapped GetDirectoryName and DirectorySeperatorChar

This commit is contained in:
Erwin de Haan
2019-01-26 21:47:11 +01:00
parent a05d803d4c
commit 3a831994f6
73 changed files with 119 additions and 114 deletions

View File

@@ -127,7 +127,7 @@ namespace Emby.Server.Implementations.AppBase
Logger.LogInformation("Saving system configuration");
var path = CommonApplicationPaths.SystemConfigurationFilePath;
FileSystem.CreateDirectory(FileSystem.GetDirectoryName(path));
FileSystem.CreateDirectory(Path.GetDirectoryName(path));
lock (_configurationSyncLock)
{
@@ -294,7 +294,7 @@ namespace Emby.Server.Implementations.AppBase
_configurations.AddOrUpdate(key, configuration, (k, v) => configuration);
var path = GetConfigurationFile(key);
FileSystem.CreateDirectory(FileSystem.GetDirectoryName(path));
FileSystem.CreateDirectory(Path.GetDirectoryName(path));
lock (_configurationSyncLock)
{

View File

@@ -48,7 +48,7 @@ namespace Emby.Server.Implementations.AppBase
// If the file didn't exist before, or if something has changed, re-save
if (buffer == null || !buffer.SequenceEqual(newBytes))
{
fileSystem.CreateDirectory(fileSystem.GetDirectoryName(path));
fileSystem.CreateDirectory(Path.GetDirectoryName(path));
// Save it after load in case we got new items
fileSystem.WriteAllBytes(path, newBytes);

View File

@@ -355,7 +355,7 @@ namespace Emby.Server.Implementations.Channels
return;
}
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path));
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
_jsonSerializer.SerializeToFile(mediaSources, path);
}
@@ -834,7 +834,7 @@ namespace Emby.Server.Implementations.Channels
{
try
{
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path));
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
_jsonSerializer.SerializeToFile(result, path);
}

View File

@@ -53,7 +53,7 @@ namespace Emby.Server.Implementations.Devices
{
var path = CachePath;
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path));
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
lock (_syncLock)
{

View File

@@ -76,7 +76,7 @@ namespace Emby.Server.Implementations.Devices
public void SaveCapabilities(string deviceId, ClientCapabilities capabilities)
{
var path = Path.Combine(GetDevicePath(deviceId), "capabilities.json");
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path));
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
lock (_capabilitiesSyncLock)
{
@@ -239,7 +239,7 @@ namespace Emby.Server.Implementations.Devices
path = Path.Combine(path, file.Name);
path = Path.ChangeExtension(path, MimeTypes.ToExtension(file.MimeType) ?? "jpg");
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path));
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
await EnsureLibraryFolder(uploadPathInfo.Item2, uploadPathInfo.Item3).ConfigureAwait(false);
@@ -275,7 +275,7 @@ namespace Emby.Server.Implementations.Devices
private void AddCameraUpload(string deviceId, LocalFileInfo file)
{
var path = Path.Combine(GetDevicePath(deviceId), "camerauploads.json");
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path));
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
lock (_cameraUploadSyncLock)
{

View File

@@ -92,7 +92,7 @@ namespace Emby.Server.Implementations.FFMpeg
else
{
info = existingVersion;
versionedDirectoryPath = _fileSystem.GetDirectoryName(info.EncoderPath);
versionedDirectoryPath = Path.GetDirectoryName(info.EncoderPath);
excludeFromDeletions.Add(versionedDirectoryPath);
}
}
@@ -130,7 +130,7 @@ namespace Emby.Server.Implementations.FFMpeg
{
EncoderPath = encoder,
ProbePath = probe,
Version = Path.GetFileName(_fileSystem.GetDirectoryName(probe))
Version = Path.GetFileName(Path.GetDirectoryName(probe))
};
}
}

View File

@@ -305,7 +305,7 @@ namespace Emby.Server.Implementations.HttpClientManager
private async Task CacheResponse(HttpResponseInfo response, string responseCachePath)
{
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(responseCachePath));
_fileSystem.CreateDirectory(Path.GetDirectoryName(responseCachePath));
using (var fileStream = _fileSystem.GetFileStream(responseCachePath, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.None, true))
{

View File

@@ -189,7 +189,7 @@ namespace Emby.Server.Implementations.IO
{
item = LibraryManager.FindByPath(path, null);
path = _fileSystem.GetDirectoryName(path);
path = System.IO.Path.GetDirectoryName(path);
}
if (item != null)

View File

@@ -483,7 +483,7 @@ namespace Emby.Server.Implementations.IO
}
// Go up a level
var parent = _fileSystem.GetDirectoryName(i);
var parent = Path.GetDirectoryName(i);
if (!string.IsNullOrEmpty(parent))
{
if (_fileSystem.AreEqual(parent, path))
@@ -509,7 +509,7 @@ namespace Emby.Server.Implementations.IO
private void CreateRefresher(string path)
{
var parentPath = _fileSystem.GetDirectoryName(path);
var parentPath = Path.GetDirectoryName(path);
lock (_activeRefreshers)
{
@@ -538,7 +538,7 @@ namespace Emby.Server.Implementations.IO
}
// They are siblings. Rebase the refresher to the parent folder.
if (string.Equals(parentPath, _fileSystem.GetDirectoryName(refresher.Path), StringComparison.Ordinal))
if (string.Equals(parentPath, Path.GetDirectoryName(refresher.Path), StringComparison.Ordinal))
{
refresher.ResetPath(parentPath, path);
return;

View File

@@ -99,7 +99,7 @@ namespace Emby.Server.Implementations.Images
CancellationToken cancellationToken)
{
var outputPathWithoutExtension = Path.Combine(ApplicationPaths.TempDirectory, Guid.NewGuid().ToString("N"));
FileSystem.CreateDirectory(FileSystem.GetDirectoryName(outputPathWithoutExtension));
FileSystem.CreateDirectory(Path.GetDirectoryName(outputPathWithoutExtension));
string outputPath = CreateImage(item, itemsWithImages, outputPathWithoutExtension, imageType, 0);
if (string.IsNullOrEmpty(outputPath))
@@ -165,7 +165,7 @@ namespace Emby.Server.Implementations.Images
private string CreateCollage(BaseItem primaryItem, List<BaseItem> items, string outputPath, int width, int height)
{
FileSystem.CreateDirectory(FileSystem.GetDirectoryName(outputPath));
FileSystem.CreateDirectory(Path.GetDirectoryName(outputPath));
var options = new ImageCollageOptions
{

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
@@ -146,7 +147,7 @@ namespace Emby.Server.Implementations.Library
if (parent != null)
{
// Don't resolve these into audio files
if (string.Equals(_fileSystem.GetFileNameWithoutExtension(filename), BaseItem.ThemeSongFilename) && _libraryManager.IsAudioFile(filename))
if (string.Equals(Path.GetFileNameWithoutExtension(filename), BaseItem.ThemeSongFilename) && _libraryManager.IsAudioFile(filename))
{
return true;
}

View File

@@ -1228,7 +1228,7 @@ namespace Emby.Server.Implementations.Library
private string GetCollectionType(string path)
{
return _fileSystem.GetFilePaths(path, new[] { ".collection" }, true, false)
.Select(i => _fileSystem.GetFileNameWithoutExtension(i))
.Select(i => Path.GetFileNameWithoutExtension(i))
.FirstOrDefault(i => !string.IsNullOrEmpty(i));
}
@@ -2976,7 +2976,7 @@ namespace Emby.Server.Implementations.Library
var rootFolderPath = ConfigurationManager.ApplicationPaths.DefaultUserViewsPath;
var virtualFolderPath = Path.Combine(rootFolderPath, virtualFolderName);
var shortcutFilename = _fileSystem.GetFileNameWithoutExtension(path);
var shortcutFilename = Path.GetFileNameWithoutExtension(path);
var lnk = Path.Combine(virtualFolderPath, shortcutFilename + ShortcutFileExtension);

View File

@@ -670,7 +670,7 @@ namespace Emby.Server.Implementations.Library
if (cacheFilePath != null)
{
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(cacheFilePath));
_fileSystem.CreateDirectory(Path.GetDirectoryName(cacheFilePath));
_jsonSerializer.SerializeToFile(mediaInfo, cacheFilePath);
//_logger.LogDebug("Saved media info to {0}", cacheFilePath);

View File

@@ -43,7 +43,7 @@ namespace Emby.Server.Implementations.Library.Resolvers
var filename = Path.GetFileNameWithoutExtension(args.Path);
// Make sure the image doesn't belong to a video file
var files = args.DirectoryService.GetFiles(_fileSystem.GetDirectoryName(args.Path));
var files = args.DirectoryService.GetFiles(Path.GetDirectoryName(args.Path));
var libraryOptions = args.GetLibraryOptions();
foreach (var file in files)

View File

@@ -1080,7 +1080,7 @@ namespace Emby.Server.Implementations.Library
var path = GetPolicyFilePath(user);
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path));
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
lock (_policySyncLock)
{
@@ -1176,7 +1176,7 @@ namespace Emby.Server.Implementations.Library
config = _jsonSerializer.DeserializeFromString<UserConfiguration>(json);
}
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path));
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
lock (_configSyncLock)
{

View File

@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Net;
@@ -41,7 +42,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
private async Task RecordFromDirectStreamProvider(IDirectStreamProvider directStreamProvider, string targetFile, TimeSpan duration, Action onStarted, CancellationToken cancellationToken)
{
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(targetFile));
_fileSystem.CreateDirectory(Path.GetDirectoryName(targetFile));
using (var output = _fileSystem.GetFileStream(targetFile, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read))
{
@@ -77,7 +78,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
{
_logger.LogInformation("Opened recording stream from tuner provider");
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(targetFile));
_fileSystem.CreateDirectory(Path.GetDirectoryName(targetFile));
using (var output = _fileSystem.GetFileStream(targetFile, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read))
{

View File

@@ -1489,7 +1489,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
{
_logger.LogInformation("Triggering refresh on {path}", path);
var item = GetAffectedBaseItem(_fileSystem.GetDirectoryName(path));
var item = GetAffectedBaseItem(Path.GetDirectoryName(path));
if (item != null)
{
@@ -1500,8 +1500,8 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
RefreshPaths = new string[]
{
path,
_fileSystem.GetDirectoryName(path),
_fileSystem.GetDirectoryName(_fileSystem.GetDirectoryName(path))
Path.GetDirectoryName(path),
Path.GetDirectoryName(Path.GetDirectoryName(path))
}
}, RefreshPriority.High);
@@ -1512,13 +1512,13 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
{
BaseItem item = null;
var parentPath = _fileSystem.GetDirectoryName(path);
var parentPath = Path.GetDirectoryName(path);
while (item == null && !string.IsNullOrEmpty(path))
{
item = _libraryManager.FindByPath(path, null);
path = _fileSystem.GetDirectoryName(path);
path = Path.GetDirectoryName(path);
}
if (item != null)
@@ -1676,7 +1676,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
while (FileExists(path, timerId))
{
var parent = _fileSystem.GetDirectoryName(originalPath);
var parent = Path.GetDirectoryName(originalPath);
var name = Path.GetFileNameWithoutExtension(originalPath);
name += " - " + index.ToString(CultureInfo.InvariantCulture);
@@ -1822,7 +1822,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
return;
}
var imageSavePath = Path.Combine(_fileSystem.GetDirectoryName(recordingPath), imageSaveFilenameWithoutExtension);
var imageSavePath = Path.Combine(Path.GetDirectoryName(recordingPath), imageSaveFilenameWithoutExtension);
// preserve original image extension
imageSavePath = Path.ChangeExtension(imageSavePath, Path.GetExtension(image.Path));

View File

@@ -79,7 +79,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
private Task RecordFromFile(MediaSourceInfo mediaSource, string inputFile, string targetFile, TimeSpan duration, Action onStarted, CancellationToken cancellationToken)
{
_targetPath = targetFile;
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(targetFile));
_fileSystem.CreateDirectory(Path.GetDirectoryName(targetFile));
var process = _processFactory.Create(new ProcessOptions
{
@@ -105,7 +105,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
_logger.LogInformation(commandLineLogMessage);
var logFilePath = Path.Combine(_appPaths.LogDirectoryPath, "record-transcode-" + Guid.NewGuid() + ".txt");
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(logFilePath));
_fileSystem.CreateDirectory(Path.GetDirectoryName(logFilePath));
// FFMpeg writes debug/error info to stderr. This is useful when debugging so let's put it in the log directory.
_logFileStream = _fileSystem.GetFileStream(logFilePath, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, true);

View File

@@ -70,7 +70,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
}
var file = _dataPath + ".json";
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(file));
_fileSystem.CreateDirectory(Path.GetDirectoryName(file));
lock (_fileDataLock)
{

View File

@@ -83,7 +83,7 @@ namespace Jellyfin.Server.Implementations.LiveTv.Listings
}).ConfigureAwait(false);
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(cacheFile));
_fileSystem.CreateDirectory(Path.GetDirectoryName(cacheFile));
_fileSystem.CopyFile(tempFile, cacheFile, true);

View File

@@ -95,7 +95,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
{
try
{
FileSystem.CreateDirectory(FileSystem.GetDirectoryName(channelCacheFile));
FileSystem.CreateDirectory(Path.GetDirectoryName(channelCacheFile));
JsonSerializer.SerializeToFile(channels, channelCacheFile);
}
catch (IOException)

View File

@@ -53,7 +53,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
var uri = new Uri(mediaSource.Path);
var localPort = _networkManager.GetRandomUnusedUdpPort();
FileSystem.CreateDirectory(FileSystem.GetDirectoryName(TempFilePath));
FileSystem.CreateDirectory(Path.GetDirectoryName(TempFilePath));
Logger.LogInformation("Opening HDHR UDP Live stream from {host}", uri.Host);

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Net;
@@ -35,7 +36,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
var url = mediaSource.Path;
FileSystem.CreateDirectory(FileSystem.GetDirectoryName(TempFilePath));
FileSystem.CreateDirectory(Path.GetDirectoryName(TempFilePath));
var typeName = GetType().Name;
Logger.LogInformation("Opening " + typeName + " Live stream from {0}", url);

View File

@@ -337,7 +337,7 @@ namespace Emby.Server.Implementations.Localization
.Where(i => i != null)
.ToDictionary(i => i.Name, StringComparer.OrdinalIgnoreCase);
var countryCode = _fileSystem.GetFileNameWithoutExtension(file)
var countryCode = Path.GetFileNameWithoutExtension(file)
.Split('-')
.Last();

View File

@@ -141,7 +141,7 @@ namespace Emby.Server.Implementations.MediaEncoder
var inputPath = MediaEncoderHelpers.GetInputArgument(_fileSystem, video.Path, protocol, null, Array.Empty<string>());
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path));
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
var container = video.Container;

View File

@@ -455,7 +455,7 @@ namespace Emby.Server.Implementations.Playlists
private string NormalizeItemPath(string playlistPath, string itemPath)
{
return MakeRelativePath(_fileSystem.GetDirectoryName(playlistPath), itemPath);
return MakeRelativePath(Path.GetDirectoryName(playlistPath), itemPath);
}
private static string MakeRelativePath(string folderPath, string fileAbsolutePath)

View File

@@ -42,11 +42,11 @@ namespace Emby.Server.Implementations
private string GetResourcePath(string basePath, string virtualPath)
{
var fullPath = Path.Combine(basePath, virtualPath.Replace('/', _fileSystem.DirectorySeparatorChar));
var fullPath = Path.Combine(basePath, virtualPath.Replace('/', Path.DirectorySeparatorChar));
try
{
fullPath = _fileSystem.GetFullPath(fullPath);
fullPath = Path.GetFullPath(fullPath);
}
catch (Exception ex)
{

View File

@@ -139,7 +139,7 @@ namespace Emby.Server.Implementations.ScheduledTasks
{
previouslyFailedImages.Add(key);
var parentPath = _fileSystem.GetDirectoryName(failHistoryPath);
var parentPath = Path.GetDirectoryName(failHistoryPath);
_fileSystem.CreateDirectory(parentPath);

View File

@@ -151,7 +151,7 @@ namespace Emby.Server.Implementations.ScheduledTasks
_lastExecutionResult = value;
var path = GetHistoryFilePath();
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path));
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
lock (_lastExecutionResultSyncLock)
{
@@ -565,7 +565,7 @@ namespace Emby.Server.Implementations.ScheduledTasks
{
var path = GetConfigurationFilePath();
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path));
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
JsonSerializer.SerializeToFile(triggers, path);
}

View File

@@ -570,7 +570,7 @@ namespace Emby.Server.Implementations.Updates
// Success - move it to the real target
try
{
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(target));
_fileSystem.CreateDirectory(Path.GetDirectoryName(target));
_fileSystem.CopyFile(tempFile, target, true);
//If it is an archive - write out a version file so we know what it is
if (isArchive)
@@ -611,7 +611,7 @@ namespace Emby.Server.Implementations.Updates
_logger.LogInformation("Deleting plugin file {0}", path);
// Make this case-insensitive to account for possible incorrect assembly naming
var file = _fileSystem.GetFilePaths(_fileSystem.GetDirectoryName(path))
var file = _fileSystem.GetFilePaths(Path.GetDirectoryName(path))
.FirstOrDefault(i => string.Equals(i, path, StringComparison.OrdinalIgnoreCase));
if (!string.IsNullOrWhiteSpace(file))