fixes #626 - Image editing page errors if an image is missing

This commit is contained in:
Luke Pulverenti 2013-11-15 10:09:52 -05:00
parent b5fa3833f7
commit 340c80bcec

View File

@ -402,41 +402,24 @@ namespace MediaBrowser.Api.Images
foreach (var image in item.Images) foreach (var image in item.Images)
{ {
var path = image.Value; var info = GetImageInfo(image.Value, item, null, image.Key);
var fileInfo = new FileInfo(path); if (info != null)
var size = _imageProcessor.GetImageSize(path);
list.Add(new ImageInfo
{ {
Path = path, list.Add(info);
ImageType = image.Key, }
ImageTag = _imageProcessor.GetImageCacheTag(item, image.Key, path),
Size = fileInfo.Length,
Width = Convert.ToInt32(size.Width),
Height = Convert.ToInt32(size.Height)
});
} }
var index = 0; var index = 0;
foreach (var image in item.BackdropImagePaths) foreach (var image in item.BackdropImagePaths)
{ {
var fileInfo = new FileInfo(image); var info = GetImageInfo(image, item, index, ImageType.Backdrop);
var size = _imageProcessor.GetImageSize(image); if (info != null)
list.Add(new ImageInfo
{ {
Path = image, list.Add(info);
ImageIndex = index, }
ImageType = ImageType.Backdrop,
ImageTag = _imageProcessor.GetImageCacheTag(item, ImageType.Backdrop, image),
Size = fileInfo.Length,
Width = Convert.ToInt32(size.Width),
Height = Convert.ToInt32(size.Height)
});
index++; index++;
} }
@ -445,20 +428,12 @@ namespace MediaBrowser.Api.Images
foreach (var image in item.ScreenshotImagePaths) foreach (var image in item.ScreenshotImagePaths)
{ {
var fileInfo = new FileInfo(image); var info = GetImageInfo(image, item, index, ImageType.Screenshot);
var size = _imageProcessor.GetImageSize(image); if (info != null)
list.Add(new ImageInfo
{ {
Path = image, list.Add(info);
ImageIndex = index, }
ImageType = ImageType.Screenshot,
ImageTag = _imageProcessor.GetImageCacheTag(item, ImageType.Screenshot, image),
Size = fileInfo.Length,
Width = Convert.ToInt32(size.Width),
Height = Convert.ToInt32(size.Height)
});
index++; index++;
} }
@ -475,20 +450,12 @@ namespace MediaBrowser.Api.Images
{ {
var image = chapter.ImagePath; var image = chapter.ImagePath;
var fileInfo = new FileInfo(image); var info = GetImageInfo(image, item, index, ImageType.Chapter);
var size = _imageProcessor.GetImageSize(image); if (info != null)
list.Add(new ImageInfo
{ {
Path = image, list.Add(info);
ImageIndex = index, }
ImageType = ImageType.Chapter,
ImageTag = _imageProcessor.GetImageCacheTag(item, ImageType.Chapter, image),
Size = fileInfo.Length,
Width = Convert.ToInt32(size.Width),
Height = Convert.ToInt32(size.Height)
});
} }
index++; index++;
@ -498,6 +465,33 @@ namespace MediaBrowser.Api.Images
return list; return list;
} }
private ImageInfo GetImageInfo(string path, BaseItem item, int? imageIndex, ImageType type)
{
try
{
var fileInfo = new FileInfo(path);
var size = _imageProcessor.GetImageSize(path);
return new ImageInfo
{
Path = path,
ImageIndex = imageIndex,
ImageType = type,
ImageTag = _imageProcessor.GetImageCacheTag(item, type, path),
Size = fileInfo.Length,
Width = Convert.ToInt32(size.Width),
Height = Convert.ToInt32(size.Height)
};
}
catch (IOException ex)
{
Logger.ErrorException("Error getting image information for {0}", ex, path);
return null;
}
}
/// <summary> /// <summary>
/// Gets the specified request. /// Gets the specified request.
/// </summary> /// </summary>