2020-05-16 11:16:46 +00:00
|
|
|
|
using Manina.Windows.Forms;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
2020-07-24 04:51:48 +00:00
|
|
|
|
using System.Net;
|
2020-05-16 11:16:46 +00:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace HeliosPlus.UIForms
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
#region Shortcut Adaptor
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A custom item adaptor for ImageListView that reads from a Profile.
|
|
|
|
|
/// </summary>
|
|
|
|
|
class ShortcutAdaptor : ImageListView.ImageListViewItemAdaptor
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
private bool disposed;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2020-07-24 04:51:48 +00:00
|
|
|
|
/// Initializes a new instance of the <see cref="ShortcutAdaptor"/> class.
|
2020-05-16 11:16:46 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
public ShortcutAdaptor()
|
|
|
|
|
{
|
|
|
|
|
disposed = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the thumbnail image for the given item.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="key">Item key.</param>
|
|
|
|
|
/// <param name="size">Requested image size.</param>
|
|
|
|
|
/// <param name="useEmbeddedThumbnails">Embedded thumbnail usage.</param>
|
|
|
|
|
/// <param name="useExifOrientation">true to automatically rotate images based on Exif orientation; otherwise false.</param>
|
|
|
|
|
/// <returns>The thumbnail image from the given item or null if an error occurs.</returns>
|
|
|
|
|
public override Image GetThumbnail(object key, Size size, UseEmbeddedThumbnails useEmbeddedThumbnails, bool useExifOrientation)
|
|
|
|
|
{
|
|
|
|
|
if (disposed)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-06-07 08:48:45 +00:00
|
|
|
|
ShortcutItem shortcut = (ShortcutItem) key;
|
2020-05-16 11:16:46 +00:00
|
|
|
|
|
2020-07-24 04:51:48 +00:00
|
|
|
|
Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(() => { return false; });
|
2020-10-18 10:04:08 +00:00
|
|
|
|
return shortcut.ShortcutBitmap.GetThumbnailImage(256, 256, myCallback, IntPtr.Zero);
|
2020-05-16 11:16:46 +00:00
|
|
|
|
}
|
2020-07-15 08:11:38 +00:00
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2020-07-24 04:51:48 +00:00
|
|
|
|
Console.WriteLine($"ShortcutAdapter/GetThumbnail exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
|
2020-07-15 08:11:38 +00:00
|
|
|
|
|
2020-05-16 11:16:46 +00:00
|
|
|
|
// If we have a problem with converting the submitted key to a profile
|
|
|
|
|
// Then we return null
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns a unique identifier for this thumbnail to be used in persistent
|
|
|
|
|
/// caching.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="key">Item key.</param>
|
|
|
|
|
/// <param name="size">Requested image size.</param>
|
|
|
|
|
/// <param name="useEmbeddedThumbnails">Embedded thumbnail usage.</param>
|
|
|
|
|
/// <param name="useExifOrientation">true to automatically rotate images based on Exif orientation; otherwise false.</param>
|
|
|
|
|
/// <returns>A unique identifier string for the thumnail.</returns>
|
|
|
|
|
public override string GetUniqueIdentifier(object key, Size size, UseEmbeddedThumbnails useEmbeddedThumbnails, bool useExifOrientation)
|
|
|
|
|
{
|
|
|
|
|
if (disposed)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-07-15 08:11:38 +00:00
|
|
|
|
ShortcutItem shortcut = (ShortcutItem) key;
|
2020-07-24 04:51:48 +00:00
|
|
|
|
//return shortcut.Name;
|
|
|
|
|
|
2020-10-18 10:04:08 +00:00
|
|
|
|
return shortcut.Name;
|
2020-05-16 11:16:46 +00:00
|
|
|
|
}
|
2020-07-15 08:11:38 +00:00
|
|
|
|
catch (Exception ex)
|
2020-05-16 11:16:46 +00:00
|
|
|
|
{
|
2020-07-24 04:51:48 +00:00
|
|
|
|
Console.WriteLine($"ShortcutAdapter/GetUniqueIdentifier exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
|
2020-06-01 10:25:52 +00:00
|
|
|
|
// If we have a problem with converting the submitted key to a Shortcut
|
2020-05-16 11:16:46 +00:00
|
|
|
|
// Then we return null
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the path to the source image for use in drag operations.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="key">Item key.</param>
|
|
|
|
|
/// <returns>The path to the source image.</returns>
|
|
|
|
|
public override string GetSourceImage(object key)
|
|
|
|
|
{
|
|
|
|
|
if (disposed)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string shortcutName = (string)key;
|
|
|
|
|
return shortcutName;
|
|
|
|
|
}
|
2020-07-15 08:11:38 +00:00
|
|
|
|
catch (Exception ex)
|
2020-05-16 11:16:46 +00:00
|
|
|
|
{
|
2020-07-24 04:51:48 +00:00
|
|
|
|
Console.WriteLine($"ShortcutAdaptor/GetSourceImage exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
|
2020-07-15 08:11:38 +00:00
|
|
|
|
|
2020-05-16 11:16:46 +00:00
|
|
|
|
// If we have a problem with converting the submitted key to a profile
|
|
|
|
|
// Then we return null
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the details for the given item.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="key">Item key.</param>
|
|
|
|
|
/// <returns>An array of tuples containing item details or null if an error occurs.</returns>
|
|
|
|
|
public override Utility.Tuple<ColumnType, string, object>[] GetDetails(object key)
|
|
|
|
|
{
|
|
|
|
|
if (disposed)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
List<Utility.Tuple<ColumnType, string, object>> details = new List<Utility.Tuple<ColumnType, string, object>>();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-06-07 08:48:45 +00:00
|
|
|
|
ShortcutItem shortcut = (ShortcutItem) key;
|
2020-05-16 11:16:46 +00:00
|
|
|
|
|
|
|
|
|
// Get file info
|
2020-06-01 10:25:52 +00:00
|
|
|
|
if (shortcut.ShortcutBitmap is Bitmap)
|
2020-05-16 11:16:46 +00:00
|
|
|
|
{
|
2020-07-24 04:51:48 +00:00
|
|
|
|
// Have to do some gymnastics to get rid of the
|
|
|
|
|
// System.Drawing.Image exception created while accessing the Size
|
|
|
|
|
bool gotSize = false;
|
|
|
|
|
Size mySize = new Size(256,256);
|
|
|
|
|
while (!gotSize)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
mySize = shortcut.ShortcutBitmap.Size;
|
|
|
|
|
gotSize = true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
// catch the System.Drawing.Image exception created while accessing the Size
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Have to do some gymnastics to get rid of the
|
|
|
|
|
// System.Drawing.Image exception created while accessing the SizeF
|
|
|
|
|
bool gotSizeF = false;
|
|
|
|
|
SizeF mySizeF = new SizeF(256, 256);
|
|
|
|
|
while (!gotSizeF)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
mySizeF = shortcut.ShortcutBitmap.PhysicalDimension;
|
|
|
|
|
gotSizeF = true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
// catch the System.Drawing.Image exception created while accessing the Size
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string name = shortcut.Name;
|
|
|
|
|
string filepath = Path.GetDirectoryName(shortcut.SavedShortcutIconCacheFilename);
|
|
|
|
|
string filename = Path.GetFileName(shortcut.SavedShortcutIconCacheFilename);
|
2020-05-19 09:41:26 +00:00
|
|
|
|
DateTime now = DateTime.Now;
|
|
|
|
|
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.DateCreated, string.Empty, now));
|
|
|
|
|
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.DateAccessed, string.Empty, now));
|
|
|
|
|
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.DateModified, string.Empty, now));
|
|
|
|
|
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.FileSize, string.Empty, (long)0));
|
2020-07-24 04:51:48 +00:00
|
|
|
|
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.FilePath, string.Empty, filepath ?? ""));
|
|
|
|
|
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.FolderName, string.Empty, filepath ?? ""));
|
|
|
|
|
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Dimensions, string.Empty, mySize));
|
|
|
|
|
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Resolution, string.Empty, mySizeF));
|
|
|
|
|
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.ImageDescription, string.Empty, name ?? ""));
|
2020-05-16 11:16:46 +00:00
|
|
|
|
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.EquipmentModel, string.Empty, ""));
|
2020-05-19 09:41:26 +00:00
|
|
|
|
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.DateTaken, string.Empty, now));
|
2020-05-16 11:16:46 +00:00
|
|
|
|
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Artist, string.Empty, ""));
|
|
|
|
|
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Copyright, string.Empty, ""));
|
|
|
|
|
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.ExposureTime, string.Empty, (float)0));
|
|
|
|
|
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.FNumber, string.Empty, (float)0));
|
|
|
|
|
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.ISOSpeed, string.Empty, (ushort)0));
|
|
|
|
|
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.UserComment, string.Empty, ""));
|
|
|
|
|
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Rating, string.Empty, (ushort)0));
|
|
|
|
|
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Software, string.Empty, ""));
|
|
|
|
|
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.FocalLength, string.Empty, (float)0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return details.ToArray();
|
|
|
|
|
}
|
2020-07-15 08:11:38 +00:00
|
|
|
|
catch (Exception ex)
|
2020-05-16 11:16:46 +00:00
|
|
|
|
{
|
2020-07-24 04:51:48 +00:00
|
|
|
|
Console.WriteLine($"ShortcutAdapter/Utility.Tuple exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
|
2020-05-16 11:16:46 +00:00
|
|
|
|
// If we have a problem with converting the submitted key to a profile
|
|
|
|
|
// Then we return null
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Dispose()
|
|
|
|
|
{
|
|
|
|
|
disposed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|