From 02fedead11f738c09e503c3bdc74e2dd98e21cc8 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 3 Jun 2013 22:02:49 -0400 Subject: re-factored some file system access --- .../MediaEncoder/MediaEncoder.cs | 39 +++++++++------------- 1 file changed, 15 insertions(+), 24 deletions(-) (limited to 'MediaBrowser.Server.Implementations/MediaEncoder') diff --git a/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs b/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs index ce39ffc06..fbb5a2010 100644 --- a/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs +++ b/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs @@ -94,29 +94,20 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder } /// - /// The _media tools path + /// Gets the media tools path. /// - private string _mediaToolsPath; - /// - /// Gets the folder path to tools - /// - /// The media tools path. - private string MediaToolsPath + /// if set to true [create]. + /// System.String. + private string GetMediaToolsPath(bool create) { - get - { - if (_mediaToolsPath == null) - { - _mediaToolsPath = Path.Combine(_appPaths.ProgramDataPath, "ffmpeg"); - - if (!Directory.Exists(_mediaToolsPath)) - { - Directory.CreateDirectory(_mediaToolsPath); - } - } + var path = Path.Combine(_appPaths.ProgramDataPath, "ffmpeg"); - return _mediaToolsPath; + if (create && !Directory.Exists(path)) + { + Directory.CreateDirectory(path); } + + return path; } /// @@ -185,7 +176,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder var filename = resource.Substring(resource.IndexOf(prefix, StringComparison.OrdinalIgnoreCase) + prefix.Length); - var versionedDirectoryPath = Path.Combine(MediaToolsPath, Path.GetFileNameWithoutExtension(filename)); + var versionedDirectoryPath = Path.Combine(GetMediaToolsPath(true), Path.GetFileNameWithoutExtension(filename)); if (!Directory.Exists(versionedDirectoryPath)) { @@ -570,14 +561,14 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder } var offsetParam = offset.Ticks > 0 ? "-ss " + offset.TotalSeconds + " " : string.Empty; - + var process = new Process { StartInfo = new ProcessStartInfo { RedirectStandardOutput = false, RedirectStandardError = true, - + CreateNoWindow = true, UseShellExecute = false, FileName = FFMpegPath, @@ -744,7 +735,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder RedirectStandardOutput = false, RedirectStandardError = true, - + FileName = FFMpegPath, Arguments = string.Format("{0}-i {1} -map 0:{2} -an -vn -c:s ass \"{3}\"", offsetParam, inputPath, subtitleStreamIndex, outputPath), WindowStyle = ProcessWindowStyle.Hidden, @@ -759,7 +750,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder var logFilePath = Path.Combine(_appPaths.LogDirectoryPath, "ffmpeg-sub-extract-" + Guid.NewGuid() + ".txt"); var logFileStream = new FileStream(logFilePath, FileMode.Create, FileAccess.Write, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous); - + try { process.Start(); -- cgit v1.2.3