public ImageSource Extract(File file)
{
try {
if (new List<string> {".ico", ".png", ".jpg", ".gif"}.Contains(file.Extension.ToLower())) {
if (!file.Exists()) return new BitmapImage();
return new BitmapImage(new Uri(file.FullName));
}
Icon icon = ExtractIcon(ActualFile(file));
Bitmap bmp = icon.ToBitmap();
DestroyIcon(icon.Handle);
var strm = new MemoryStream();
bmp.Save(strm, ImageFormat.Png);
return Extract(strm);
}
catch (ExternalException exception) {
LogManager.WriteLog(exception);
return new BitmapImage();
}
catch (DirectoryNotFoundException exception) {
LogManager.WriteLog("Requested file: {0}", file);
LogManager.WriteLog(exception);
return new BitmapImage();
}
catch (ArgumentException exception) {
LogManager.WriteLog("Requested file: {0}", file);
LogManager.WriteLog(exception);
return new BitmapImage();
}
}