update image saver

This commit is contained in:
Luke Pulverenti 2016-01-16 22:23:59 -05:00
parent 0355ada899
commit 268b1c7916
1 changed files with 8 additions and 5 deletions

View File

@ -133,6 +133,7 @@ namespace MediaBrowser.Providers.Manager
source = memoryStream; source = memoryStream;
var currentImage = GetCurrentImage(item, type, index); var currentImage = GetCurrentImage(item, type, index);
var savedPaths = new List<string>();
using (source) using (source)
{ {
@ -146,17 +147,17 @@ namespace MediaBrowser.Providers.Manager
{ {
retryPath = retryPaths[currentPathIndex]; retryPath = retryPaths[currentPathIndex];
} }
await SaveImageToLocation(source, path, retryPath, cancellationToken).ConfigureAwait(false); var savedPath = await SaveImageToLocation(source, path, retryPath, cancellationToken).ConfigureAwait(false);
savedPaths.Add(savedPath);
currentPathIndex++; currentPathIndex++;
} }
} }
// Set the path into the item // Set the path into the item
SetImagePath(item, type, imageIndex, paths[0]); SetImagePath(item, type, imageIndex, savedPaths[0]);
// Delete the current path // Delete the current path
if (currentImage != null && currentImage.IsLocalFile && !paths.Contains(currentImage.Path, StringComparer.OrdinalIgnoreCase)) if (currentImage != null && currentImage.IsLocalFile && !savedPaths.Contains(currentImage.Path, StringComparer.OrdinalIgnoreCase))
{ {
var currentPath = currentImage.Path; var currentPath = currentImage.Path;
@ -184,11 +185,12 @@ namespace MediaBrowser.Providers.Manager
} }
} }
private async Task SaveImageToLocation(Stream source, string path, string retryPath, CancellationToken cancellationToken) private async Task<string> SaveImageToLocation(Stream source, string path, string retryPath, CancellationToken cancellationToken)
{ {
try try
{ {
await SaveImageToLocation(source, path, cancellationToken).ConfigureAwait(false); await SaveImageToLocation(source, path, cancellationToken).ConfigureAwait(false);
return path;
} }
catch (UnauthorizedAccessException) catch (UnauthorizedAccessException)
{ {
@ -207,6 +209,7 @@ namespace MediaBrowser.Providers.Manager
source.Position = 0; source.Position = 0;
await SaveImageToLocation(source, retryPath, cancellationToken).ConfigureAwait(false); await SaveImageToLocation(source, retryPath, cancellationToken).ConfigureAwait(false);
return retryPath;
} }
/// <summary> /// <summary>