fix missing image cache

This commit is contained in:
bao-qian 2016-05-03 23:36:47 +01:00
parent c2132e3772
commit 461e650e05

View File

@ -130,43 +130,42 @@ namespace Wox.Infrastructure.Image
if (string.IsNullOrEmpty(path)) if (string.IsNullOrEmpty(path))
{ {
image = ImageSources[ErrorIcon]; image = ImageSources[ErrorIcon];
_cache.Add(ErrorIcon);
} }
else if (ImageSources.ContainsKey(path)) else if (ImageSources.ContainsKey(path))
{ {
image = ImageSources[path]; image = ImageSources[path];
_cache.Add(path);
} }
else else
{ {
string ext = Path.GetExtension(path).ToLower();
if (path.StartsWith("data:", StringComparison.OrdinalIgnoreCase)) if (path.StartsWith("data:", StringComparison.OrdinalIgnoreCase))
{ {
image = new BitmapImage(new Uri(path)); image = new BitmapImage(new Uri(path));
ImageSources[path] = image;
} }
else if (Path.IsPathRooted(path)) else if (Path.IsPathRooted(path))
{ {
if (Directory.Exists(path)) if (Directory.Exists(path))
{ {
image = ShellIcon(path); image = ShellIcon(path);
ImageSources[path] = image;
} }
else if (File.Exists(path)) else if (File.Exists(path))
{ {
if (ImageExtions.Contains(ext)) var externsion = Path.GetExtension(path).ToLower();
if (ImageExtions.Contains(externsion))
{ {
image = new BitmapImage(new Uri(path)); image = new BitmapImage(new Uri(path));
ImageSources[path] = image;
} }
else else
{ {
image = AssociatedIcon(path); image = AssociatedIcon(path);
ImageSources[path] = image;
} }
} }
else else
{ {
image = ImageSources[ErrorIcon]; image = ImageSources[ErrorIcon];
path = ErrorIcon;
} }
} }
else else
@ -175,13 +174,16 @@ namespace Wox.Infrastructure.Image
if (File.Exists(defaultDirectoryPath)) if (File.Exists(defaultDirectoryPath))
{ {
image = new BitmapImage(new Uri(defaultDirectoryPath)); image = new BitmapImage(new Uri(defaultDirectoryPath));
ImageSources[path] = image;
} }
else else
{ {
image = ImageSources[ErrorIcon]; image = ImageSources[ErrorIcon];
path = ErrorIcon;
} }
} }
ImageSources[path] = image;
_cache.Add(path);
} }
return image; return image;
} }