2021-05-20 20:10:19 +00:00
|
|
|
#nullable disable
|
2020-08-04 14:20:52 +00:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-10-18 11:52:32 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Concurrent;
|
2020-03-24 15:12:06 +00:00
|
|
|
using System.Diagnostics;
|
2019-10-18 11:52:32 +00:00
|
|
|
using System.Globalization;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using MediaBrowser.Common.Configuration;
|
|
|
|
using MediaBrowser.Common.Extensions;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
using MediaBrowser.Controller.MediaEncoding;
|
|
|
|
using MediaBrowser.Model.Dto;
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
using MediaBrowser.Model.IO;
|
|
|
|
using MediaBrowser.Model.MediaInfo;
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
namespace MediaBrowser.MediaEncoding.Attachments
|
|
|
|
{
|
2019-12-26 22:09:00 +00:00
|
|
|
public class AttachmentExtractor : IAttachmentExtractor, IDisposable
|
2019-10-18 11:52:32 +00:00
|
|
|
{
|
2020-06-06 00:15:56 +00:00
|
|
|
private readonly ILogger<AttachmentExtractor> _logger;
|
2019-10-18 11:52:32 +00:00
|
|
|
private readonly IApplicationPaths _appPaths;
|
|
|
|
private readonly IFileSystem _fileSystem;
|
|
|
|
private readonly IMediaEncoder _mediaEncoder;
|
|
|
|
private readonly IMediaSourceManager _mediaSourceManager;
|
|
|
|
|
2019-12-26 22:09:00 +00:00
|
|
|
private readonly ConcurrentDictionary<string, SemaphoreSlim> _semaphoreLocks =
|
|
|
|
new ConcurrentDictionary<string, SemaphoreSlim>();
|
|
|
|
|
|
|
|
private bool _disposed = false;
|
|
|
|
|
2019-10-18 11:52:32 +00:00
|
|
|
public AttachmentExtractor(
|
2019-11-07 16:55:39 +00:00
|
|
|
ILogger<AttachmentExtractor> logger,
|
2019-10-18 11:52:32 +00:00
|
|
|
IApplicationPaths appPaths,
|
|
|
|
IFileSystem fileSystem,
|
|
|
|
IMediaEncoder mediaEncoder,
|
2019-11-07 19:24:49 +00:00
|
|
|
IMediaSourceManager mediaSourceManager)
|
2019-10-18 11:52:32 +00:00
|
|
|
{
|
2019-11-07 16:55:39 +00:00
|
|
|
_logger = logger;
|
2019-10-18 11:52:32 +00:00
|
|
|
_appPaths = appPaths;
|
|
|
|
_fileSystem = fileSystem;
|
|
|
|
_mediaEncoder = mediaEncoder;
|
|
|
|
_mediaSourceManager = mediaSourceManager;
|
|
|
|
}
|
|
|
|
|
2019-12-26 22:09:00 +00:00
|
|
|
/// <inheritdoc />
|
2021-12-24 21:18:24 +00:00
|
|
|
public async Task<(MediaAttachment Attachment, Stream Stream)> GetAttachment(BaseItem item, string mediaSourceId, int attachmentStreamIndex, CancellationToken cancellationToken)
|
2019-10-18 11:52:32 +00:00
|
|
|
{
|
2022-10-06 18:21:23 +00:00
|
|
|
ArgumentNullException.ThrowIfNull(item);
|
2019-11-05 13:16:46 +00:00
|
|
|
|
2019-10-18 11:52:32 +00:00
|
|
|
if (string.IsNullOrWhiteSpace(mediaSourceId))
|
|
|
|
{
|
|
|
|
throw new ArgumentNullException(nameof(mediaSourceId));
|
|
|
|
}
|
|
|
|
|
2020-01-10 23:08:47 +00:00
|
|
|
var mediaSources = await _mediaSourceManager.GetPlaybackMediaSources(item, null, true, false, cancellationToken).ConfigureAwait(false);
|
2019-11-06 14:46:31 +00:00
|
|
|
var mediaSource = mediaSources
|
|
|
|
.FirstOrDefault(i => string.Equals(i.Id, mediaSourceId, StringComparison.OrdinalIgnoreCase));
|
|
|
|
if (mediaSource == null)
|
2019-11-04 19:34:21 +00:00
|
|
|
{
|
|
|
|
throw new ResourceNotFoundException($"MediaSource {mediaSourceId} not found");
|
|
|
|
}
|
2019-12-26 22:09:00 +00:00
|
|
|
|
2019-11-06 14:46:31 +00:00
|
|
|
var mediaAttachment = mediaSource.MediaAttachments
|
|
|
|
.FirstOrDefault(i => i.Index == attachmentStreamIndex);
|
|
|
|
if (mediaAttachment == null)
|
2019-11-04 19:34:21 +00:00
|
|
|
{
|
|
|
|
throw new ResourceNotFoundException($"MediaSource {mediaSourceId} has no attachment with stream index {attachmentStreamIndex}");
|
|
|
|
}
|
2019-12-26 22:09:00 +00:00
|
|
|
|
2019-10-18 11:52:32 +00:00
|
|
|
var attachmentStream = await GetAttachmentStream(mediaSource, mediaAttachment, cancellationToken)
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
|
|
return (mediaAttachment, attachmentStream);
|
|
|
|
}
|
|
|
|
|
2022-02-06 13:02:01 +00:00
|
|
|
public async Task ExtractAllAttachments(
|
|
|
|
string inputFile,
|
|
|
|
MediaSourceInfo mediaSource,
|
|
|
|
string outputPath,
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
{
|
2022-03-12 20:46:29 +00:00
|
|
|
var semaphore = _semaphoreLocks.GetOrAdd(outputPath, key => new SemaphoreSlim(1, 1));
|
2022-02-06 13:02:01 +00:00
|
|
|
|
2022-03-12 20:46:29 +00:00
|
|
|
await semaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
|
2022-02-06 13:02:01 +00:00
|
|
|
|
2022-03-13 10:20:09 +00:00
|
|
|
try
|
2022-03-12 20:46:29 +00:00
|
|
|
{
|
2022-03-13 10:20:09 +00:00
|
|
|
if (!Directory.Exists(outputPath))
|
2022-02-06 13:02:01 +00:00
|
|
|
{
|
|
|
|
await ExtractAllAttachmentsInternal(
|
|
|
|
_mediaEncoder.GetInputArgument(inputFile, mediaSource),
|
|
|
|
outputPath,
|
2022-03-09 19:47:03 +00:00
|
|
|
false,
|
2022-02-06 13:02:01 +00:00
|
|
|
cancellationToken).ConfigureAwait(false);
|
|
|
|
}
|
2022-03-13 10:20:09 +00:00
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
semaphore.Release();
|
2022-02-06 13:02:01 +00:00
|
|
|
}
|
2022-03-09 19:47:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public async Task ExtractAllAttachmentsExternal(
|
|
|
|
string inputArgument,
|
|
|
|
string id,
|
|
|
|
string outputPath,
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
{
|
2022-03-12 20:46:29 +00:00
|
|
|
var semaphore = _semaphoreLocks.GetOrAdd(outputPath, key => new SemaphoreSlim(1, 1));
|
2022-03-09 19:47:03 +00:00
|
|
|
|
2022-03-12 20:46:29 +00:00
|
|
|
await semaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
|
2022-03-09 19:47:03 +00:00
|
|
|
|
2022-03-13 10:20:09 +00:00
|
|
|
try
|
2022-03-12 20:46:29 +00:00
|
|
|
{
|
2022-03-13 10:20:09 +00:00
|
|
|
if (!File.Exists(Path.Join(outputPath, id)))
|
2022-03-09 19:47:03 +00:00
|
|
|
{
|
|
|
|
await ExtractAllAttachmentsInternal(
|
|
|
|
inputArgument,
|
|
|
|
outputPath,
|
|
|
|
true,
|
|
|
|
cancellationToken).ConfigureAwait(false);
|
2022-03-13 10:20:09 +00:00
|
|
|
|
2022-03-09 19:47:03 +00:00
|
|
|
if (Directory.Exists(outputPath))
|
|
|
|
{
|
|
|
|
File.Create(Path.Join(outputPath, id));
|
|
|
|
}
|
|
|
|
}
|
2022-02-06 13:02:01 +00:00
|
|
|
}
|
2022-03-13 10:20:09 +00:00
|
|
|
finally
|
|
|
|
{
|
|
|
|
semaphore.Release();
|
|
|
|
}
|
2022-02-06 13:02:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private async Task ExtractAllAttachmentsInternal(
|
|
|
|
string inputPath,
|
|
|
|
string outputPath,
|
2022-03-09 19:47:03 +00:00
|
|
|
bool isExternal,
|
2022-02-06 13:02:01 +00:00
|
|
|
CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(inputPath))
|
|
|
|
{
|
|
|
|
throw new ArgumentNullException(nameof(inputPath));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(outputPath))
|
|
|
|
{
|
|
|
|
throw new ArgumentNullException(nameof(outputPath));
|
|
|
|
}
|
|
|
|
|
2022-03-12 20:46:29 +00:00
|
|
|
Directory.CreateDirectory(outputPath);
|
2022-02-06 13:02:01 +00:00
|
|
|
|
|
|
|
var processArgs = string.Format(
|
|
|
|
CultureInfo.InvariantCulture,
|
2022-03-09 19:47:03 +00:00
|
|
|
"-dump_attachment:t \"\" -y -i {0} -t 0 -f null null",
|
2022-02-06 13:02:01 +00:00
|
|
|
inputPath);
|
|
|
|
|
|
|
|
int exitCode;
|
|
|
|
|
|
|
|
using (var process = new Process
|
|
|
|
{
|
|
|
|
StartInfo = new ProcessStartInfo
|
|
|
|
{
|
|
|
|
Arguments = processArgs,
|
|
|
|
FileName = _mediaEncoder.EncoderPath,
|
|
|
|
UseShellExecute = false,
|
|
|
|
CreateNoWindow = true,
|
|
|
|
WindowStyle = ProcessWindowStyle.Hidden,
|
|
|
|
WorkingDirectory = outputPath,
|
|
|
|
ErrorDialog = false
|
|
|
|
},
|
|
|
|
EnableRaisingEvents = true
|
|
|
|
})
|
|
|
|
{
|
|
|
|
_logger.LogInformation("{File} {Arguments}", process.StartInfo.FileName, process.StartInfo.Arguments);
|
|
|
|
|
|
|
|
process.Start();
|
|
|
|
|
|
|
|
var ranToCompletion = await ProcessExtensions.WaitForExitAsync(process, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
if (!ranToCompletion)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
_logger.LogWarning("Killing ffmpeg attachment extraction process");
|
|
|
|
process.Kill();
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
_logger.LogError(ex, "Error killing attachment extraction process");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exitCode = ranToCompletion ? process.ExitCode : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
var failed = false;
|
|
|
|
|
|
|
|
if (exitCode != 0)
|
|
|
|
{
|
2022-03-09 19:47:03 +00:00
|
|
|
if (isExternal && exitCode == 1)
|
2022-02-06 13:02:01 +00:00
|
|
|
{
|
2022-03-09 19:47:03 +00:00
|
|
|
// ffmpeg returns exitCode 1 because there is no video or audio stream
|
|
|
|
// this can be ignored
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
failed = true;
|
|
|
|
|
|
|
|
_logger.LogWarning("Deleting extracted attachments {Path} due to failure: {ExitCode}", outputPath, exitCode);
|
|
|
|
try
|
2022-02-06 13:02:01 +00:00
|
|
|
{
|
|
|
|
Directory.Delete(outputPath);
|
|
|
|
}
|
2022-03-09 19:47:03 +00:00
|
|
|
catch (IOException ex)
|
|
|
|
{
|
|
|
|
_logger.LogError(ex, "Error deleting extracted attachments {Path}", outputPath);
|
|
|
|
}
|
2022-02-06 13:02:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!Directory.Exists(outputPath))
|
|
|
|
{
|
|
|
|
failed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (failed)
|
|
|
|
{
|
|
|
|
_logger.LogError("ffmpeg attachment extraction failed for {InputPath} to {OutputPath}", inputPath, outputPath);
|
|
|
|
|
|
|
|
throw new InvalidOperationException(
|
|
|
|
string.Format(CultureInfo.InvariantCulture, "ffmpeg attachment extraction failed for {0} to {1}", inputPath, outputPath));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_logger.LogInformation("ffmpeg attachment extraction completed for {Path} to {Path}", inputPath, outputPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-18 11:52:32 +00:00
|
|
|
private async Task<Stream> GetAttachmentStream(
|
|
|
|
MediaSourceInfo mediaSource,
|
|
|
|
MediaAttachment mediaAttachment,
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
{
|
2020-09-24 06:41:42 +00:00
|
|
|
var attachmentPath = await GetReadableFile(mediaSource.Path, mediaSource.Path, mediaSource, mediaAttachment, cancellationToken).ConfigureAwait(false);
|
2021-06-12 20:20:35 +00:00
|
|
|
return AsyncFile.OpenRead(attachmentPath);
|
2019-10-18 11:52:32 +00:00
|
|
|
}
|
|
|
|
|
2019-12-26 22:09:00 +00:00
|
|
|
private async Task<string> GetReadableFile(
|
2019-10-18 11:52:32 +00:00
|
|
|
string mediaPath,
|
2019-12-26 22:09:00 +00:00
|
|
|
string inputFile,
|
2020-09-24 06:41:42 +00:00
|
|
|
MediaSourceInfo mediaSource,
|
2019-10-18 11:52:32 +00:00
|
|
|
MediaAttachment mediaAttachment,
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
{
|
2020-09-24 06:41:42 +00:00
|
|
|
var outputPath = GetAttachmentCachePath(mediaPath, mediaSource, mediaAttachment.Index);
|
|
|
|
await ExtractAttachment(inputFile, mediaSource, mediaAttachment.Index, outputPath, cancellationToken)
|
2019-10-18 11:52:32 +00:00
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
2019-11-04 19:48:28 +00:00
|
|
|
return outputPath;
|
2019-10-18 11:52:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private async Task ExtractAttachment(
|
2019-12-26 22:09:00 +00:00
|
|
|
string inputFile,
|
2020-09-24 06:41:42 +00:00
|
|
|
MediaSourceInfo mediaSource,
|
2019-10-18 11:52:32 +00:00
|
|
|
int attachmentStreamIndex,
|
|
|
|
string outputPath,
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
{
|
2019-12-26 22:09:00 +00:00
|
|
|
var semaphore = _semaphoreLocks.GetOrAdd(outputPath, key => new SemaphoreSlim(1, 1));
|
2019-10-18 11:52:32 +00:00
|
|
|
|
|
|
|
await semaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (!File.Exists(outputPath))
|
|
|
|
{
|
2019-12-26 22:09:00 +00:00
|
|
|
await ExtractAttachmentInternal(
|
2020-10-01 20:20:28 +00:00
|
|
|
_mediaEncoder.GetInputArgument(inputFile, mediaSource),
|
2019-12-26 22:09:00 +00:00
|
|
|
attachmentStreamIndex,
|
|
|
|
outputPath,
|
|
|
|
cancellationToken).ConfigureAwait(false);
|
2019-10-18 11:52:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
semaphore.Release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private async Task ExtractAttachmentInternal(
|
|
|
|
string inputPath,
|
|
|
|
int attachmentStreamIndex,
|
|
|
|
string outputPath,
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(inputPath))
|
|
|
|
{
|
|
|
|
throw new ArgumentNullException(nameof(inputPath));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(outputPath))
|
|
|
|
{
|
|
|
|
throw new ArgumentNullException(nameof(outputPath));
|
|
|
|
}
|
|
|
|
|
|
|
|
Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
|
|
|
|
|
2019-11-07 16:59:54 +00:00
|
|
|
var processArgs = string.Format(
|
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
"-dump_attachment:{1} {2} -i {0} -t 0 -f null null",
|
|
|
|
inputPath,
|
|
|
|
attachmentStreamIndex,
|
|
|
|
outputPath);
|
2019-10-18 11:52:32 +00:00
|
|
|
|
2020-03-27 00:42:28 +00:00
|
|
|
int exitCode;
|
2019-10-18 11:52:32 +00:00
|
|
|
|
2020-04-11 17:25:50 +00:00
|
|
|
using (var process = new Process
|
|
|
|
{
|
2020-04-11 17:46:31 +00:00
|
|
|
StartInfo = new ProcessStartInfo
|
|
|
|
{
|
|
|
|
Arguments = processArgs,
|
|
|
|
FileName = _mediaEncoder.EncoderPath,
|
|
|
|
UseShellExecute = false,
|
|
|
|
CreateNoWindow = true,
|
|
|
|
WindowStyle = ProcessWindowStyle.Hidden,
|
|
|
|
ErrorDialog = false
|
|
|
|
},
|
|
|
|
EnableRaisingEvents = true
|
|
|
|
})
|
2020-03-27 00:42:28 +00:00
|
|
|
{
|
|
|
|
_logger.LogInformation("{File} {Arguments}", process.StartInfo.FileName, process.StartInfo.Arguments);
|
2019-10-18 11:52:32 +00:00
|
|
|
|
2020-03-27 00:42:28 +00:00
|
|
|
process.Start();
|
2019-10-18 11:52:32 +00:00
|
|
|
|
2020-11-13 16:01:55 +00:00
|
|
|
var ranToCompletion = await ProcessExtensions.WaitForExitAsync(process, cancellationToken).ConfigureAwait(false);
|
2020-03-27 00:42:28 +00:00
|
|
|
|
|
|
|
if (!ranToCompletion)
|
2019-10-18 11:52:32 +00:00
|
|
|
{
|
2020-03-27 00:42:28 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
_logger.LogWarning("Killing ffmpeg attachment extraction process");
|
|
|
|
process.Kill();
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
_logger.LogError(ex, "Error killing attachment extraction process");
|
|
|
|
}
|
2019-10-18 11:52:32 +00:00
|
|
|
}
|
|
|
|
|
2020-03-27 00:42:28 +00:00
|
|
|
exitCode = ranToCompletion ? process.ExitCode : -1;
|
|
|
|
}
|
2020-01-10 23:08:47 +00:00
|
|
|
|
2019-10-18 11:52:32 +00:00
|
|
|
var failed = false;
|
|
|
|
|
2019-11-04 15:58:56 +00:00
|
|
|
if (exitCode != 0)
|
2019-10-18 11:52:32 +00:00
|
|
|
{
|
|
|
|
failed = true;
|
|
|
|
|
2019-11-04 16:16:57 +00:00
|
|
|
_logger.LogWarning("Deleting extracted attachment {Path} due to failure: {ExitCode}", outputPath, exitCode);
|
2019-10-18 11:52:32 +00:00
|
|
|
try
|
|
|
|
{
|
2019-11-07 13:56:12 +00:00
|
|
|
if (File.Exists(outputPath))
|
|
|
|
{
|
|
|
|
_fileSystem.DeleteFile(outputPath);
|
|
|
|
}
|
2019-10-18 11:52:32 +00:00
|
|
|
}
|
|
|
|
catch (IOException ex)
|
|
|
|
{
|
|
|
|
_logger.LogError(ex, "Error deleting extracted attachment {Path}", outputPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!File.Exists(outputPath))
|
|
|
|
{
|
|
|
|
failed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (failed)
|
|
|
|
{
|
2021-11-09 21:29:33 +00:00
|
|
|
_logger.LogError("ffmpeg attachment extraction failed for {InputPath} to {OutputPath}", inputPath, outputPath);
|
2019-10-18 11:52:32 +00:00
|
|
|
|
2021-11-09 21:29:33 +00:00
|
|
|
throw new InvalidOperationException(
|
|
|
|
string.Format(CultureInfo.InvariantCulture, "ffmpeg attachment extraction failed for {0} to {1}", inputPath, outputPath));
|
2019-10-18 11:52:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-04 16:39:40 +00:00
|
|
|
_logger.LogInformation("ffmpeg attachment extraction completed for {Path} to {Path}", inputPath, outputPath);
|
2019-10-18 11:52:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-24 06:41:42 +00:00
|
|
|
private string GetAttachmentCachePath(string mediaPath, MediaSourceInfo mediaSource, int attachmentStreamIndex)
|
2019-10-18 11:52:32 +00:00
|
|
|
{
|
2019-11-07 16:25:44 +00:00
|
|
|
string filename;
|
2020-09-24 06:41:42 +00:00
|
|
|
if (mediaSource.Protocol == MediaProtocol.File)
|
2019-10-18 11:52:32 +00:00
|
|
|
{
|
|
|
|
var date = _fileSystem.GetLastWriteTimeUtc(mediaPath);
|
2020-08-20 10:16:24 +00:00
|
|
|
filename = (mediaPath + attachmentStreamIndex.ToString(CultureInfo.InvariantCulture) + "_" + date.Ticks.ToString(CultureInfo.InvariantCulture)).GetMD5().ToString("D", CultureInfo.InvariantCulture);
|
2019-10-18 11:52:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-20 10:16:24 +00:00
|
|
|
filename = (mediaPath + attachmentStreamIndex.ToString(CultureInfo.InvariantCulture)).GetMD5().ToString("D", CultureInfo.InvariantCulture);
|
2019-10-18 11:52:32 +00:00
|
|
|
}
|
2019-12-26 22:09:00 +00:00
|
|
|
|
2019-11-04 16:45:31 +00:00
|
|
|
var prefix = filename.Substring(0, 1);
|
2019-12-26 22:09:00 +00:00
|
|
|
return Path.Combine(_appPaths.DataPath, "attachments", prefix, filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
Dispose(true);
|
|
|
|
GC.SuppressFinalize(this);
|
2019-10-18 11:52:32 +00:00
|
|
|
}
|
|
|
|
|
2019-12-26 22:09:00 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Releases unmanaged and - optionally - managed resources.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
|
|
{
|
|
|
|
if (_disposed)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (disposing)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
_disposed = true;
|
|
|
|
}
|
2019-10-18 11:52:32 +00:00
|
|
|
}
|
|
|
|
}
|