Silenced the System.Drawing.Image exceptions

The ProfileAdapter and ShortcutAdapters used
by the ImageListView Control unfortunately
have to access the sizes of the bitmaps being
loaded into the respective imagelistviews. I
can't find anyway of stopping the GDI+
from complaining about the Bitmap being
accessed by multiple different threads (as
ImageListView creates one thread per image.
This will be fixed once I move to this being a
WPF application as we'll use a different control.
This commit is contained in:
terrymacdonald
2020-07-24 16:51:48 +12:00
parent f23ae340a7
commit 5004f5f76a
20 changed files with 197 additions and 115 deletions

View File

@ -26,6 +26,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>true</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>

View File

@ -22,6 +22,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<UseVSHostingProcess>true</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>

View File

@ -102,7 +102,7 @@ namespace HeliosPlus.Shared
}
catch (Exception ex)
{
Console.WriteLine($"ShortcutItem/Instansiation exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"ShortcutItem/Instansiation exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// ignored
}*/

View File

@ -58,7 +58,7 @@ namespace HeliosPlus.Shared
}
catch (Exception ex)
{
Console.WriteLine($"ShortcutItem/Instansiation exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"ShortcutItem/Instansiation exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// ignored
}
@ -171,7 +171,7 @@ namespace HeliosPlus.Shared
}
catch (Exception ex)
{
Console.WriteLine($"ProfileRepository/RemoveProfile exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"ProfileRepository/RemoveProfile exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// TODO check and report
}
}
@ -206,7 +206,7 @@ namespace HeliosPlus.Shared
}
catch (Exception ex)
{
Console.WriteLine($"ProfileRepository/RemoveProfile exception 2: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"ProfileRepository/RemoveProfile exception 2: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// TODO check and report
}
}
@ -241,7 +241,7 @@ namespace HeliosPlus.Shared
}
catch (Exception ex)
{
Console.WriteLine($"ProfileRepository/RemoveProfile exception 3: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"ProfileRepository/RemoveProfile exception 3: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// TODO check and report
}
}
@ -426,7 +426,7 @@ namespace HeliosPlus.Shared
catch (Exception ex)
{
// ignored
Console.WriteLine($"ProfileRepository/LoadProfiles exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"ProfileRepository/LoadProfiles exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
Console.WriteLine($"Unable to load Profiles from JSON file {_profileStorageJsonFileName}: " + ex.Message);
}
@ -481,7 +481,7 @@ namespace HeliosPlus.Shared
}
catch (Exception ex)
{
Console.WriteLine($"ProfileRepository/SaveProfiles exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"ProfileRepository/SaveProfiles exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
Console.WriteLine($"Unable to create Profile folder {_profileStorageJsonPath}: " + ex.Message);
}
@ -506,7 +506,7 @@ namespace HeliosPlus.Shared
}
catch (Exception ex)
{
Console.WriteLine($"ProfileRepository/SaveProfiles exception 2: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"ProfileRepository/SaveProfiles exception 2: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
Console.WriteLine($"Unable to save Profile JSON file {_profileStorageJsonFileName}: " + ex.Message);
}
@ -527,7 +527,7 @@ namespace HeliosPlus.Shared
}
catch (Exception ex)
{
Console.WriteLine($"ProfileRepository/SaveProfileIconToCache exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"ProfileRepository/SaveProfileIconToCache exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// If we fail to create an icon based on the Profile, then we use the standard HeliosPlus profile one.
// Which is created on program startup.
File.Copy(AppHeliosPlusIconFilename, profile.SavedProfileIconCacheFilename);

View File

@ -21,6 +21,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>true</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>

View File

@ -103,7 +103,7 @@ namespace HeliosPlus.GameLibraries
}
catch (SecurityException ex)
{
Console.WriteLine($"SteamGame/IsRunning securityexception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"SteamGame/IsRunning securityexception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
if (ex.Source != null)
Console.WriteLine("SecurityException source: {0} - Message: {1}", ex.Source, ex.Message);
throw;
@ -112,7 +112,7 @@ namespace HeliosPlus.GameLibraries
{
// Extract some information from this exception, and then
// throw it to the parent method.
Console.WriteLine($"SteamGame/IsRunning ioexception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"SteamGame/IsRunning ioexception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
if (ex.Source != null)
Console.WriteLine("IOException source: {0} - Message: {1}", ex.Source, ex.Message);
throw;
@ -138,7 +138,7 @@ namespace HeliosPlus.GameLibraries
}
catch (SecurityException ex)
{
Console.WriteLine($"SteamGame/IsUpdating securityexception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"SteamGame/IsUpdating securityexception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
if (ex.Source != null)
Console.WriteLine("SecurityException source: {0} - Message: {1}", ex.Source, ex.Message);
throw;
@ -147,7 +147,7 @@ namespace HeliosPlus.GameLibraries
{
// Extract some information from this exception, and then
// throw it to the parent method.
Console.WriteLine($"SteamGame/IsUpdating ioexception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"SteamGame/IsUpdating ioexception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
if (ex.Source != null)
Console.WriteLine("IOException source: {0} - Message: {1}", ex.Source, ex.Message);
throw;

View File

@ -435,7 +435,7 @@ namespace HeliosPlus.GameLibraries
}
catch (ArgumentException ex)
{
Console.WriteLine($"SteamGame/GetAllInstalledGames exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"SteamGame/GetAllInstalledGames exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
//we just want to ignore it if we try to add it twice....
}
@ -558,28 +558,28 @@ namespace HeliosPlus.GameLibraries
}
catch (SecurityException ex)
{
Console.WriteLine($"SteamGame/GetAllInstalledGames securityexception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"SteamGame/GetAllInstalledGames securityexception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
if (ex.Source != null)
Console.WriteLine("SecurityException source: {0} - Message: {1}", ex.Source, ex.Message);
throw;
}
catch (UnauthorizedAccessException ex)
{
Console.WriteLine($"SteamGame/GetAllInstalledGames unauthorizedaccessexception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"SteamGame/GetAllInstalledGames unauthorizedaccessexception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
if (ex.Source != null)
Console.WriteLine("UnauthorizedAccessException source: {0} - Message: {1}", ex.Source, ex.Message);
throw;
}
catch (ObjectDisposedException ex)
{
Console.WriteLine($"SteamGame/GetAllInstalledGames objectdisposedexceptions: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"SteamGame/GetAllInstalledGames objectdisposedexceptions: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
if (ex.Source != null)
Console.WriteLine("ObjectDisposedException source: {0} - Message: {1}", ex.Source, ex.Message);
throw;
}
catch (IOException ex)
{
Console.WriteLine($"SteamGame/GetAllInstalledGames ioexception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"SteamGame/GetAllInstalledGames ioexception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// Extract some information from this exception, and then
// throw it to the parent method.
if (ex.Source != null)

View File

@ -104,7 +104,7 @@ namespace HeliosPlus.GameLibraries
}
catch (SecurityException ex)
{
Console.WriteLine($"SteamGame/IsUpdating securityexception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"SteamGame/IsUpdating securityexception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
if (ex.Source != null)
Console.WriteLine("SecurityException source: {0} - Message: {1}", ex.Source, ex.Message);
throw;
@ -113,7 +113,7 @@ namespace HeliosPlus.GameLibraries
{
// Extract some information from this exception, and then
// throw it to the parent method.
Console.WriteLine($"SteamGame/IsUpdating ioexception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"SteamGame/IsUpdating ioexception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
if (ex.Source != null)
Console.WriteLine("IOException source: {0} - Message: {1}", ex.Source, ex.Message);
throw;
@ -139,7 +139,7 @@ namespace HeliosPlus.GameLibraries
}
catch (SecurityException ex)
{
Console.WriteLine($"SteamGame/IsUpdating securityexception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"SteamGame/IsUpdating securityexception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
if (ex.Source != null)
Console.WriteLine("SecurityException source: {0} - Message: {1}", ex.Source, ex.Message);
throw;
@ -148,7 +148,7 @@ namespace HeliosPlus.GameLibraries
{
// Extract some information from this exception, and then
// throw it to the parent method.
Console.WriteLine($"SteamGame/IsUpdating ioexception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"SteamGame/IsUpdating ioexception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
if (ex.Source != null)
Console.WriteLine("IOException source: {0} - Message: {1}", ex.Source, ex.Message);
throw;
@ -325,7 +325,7 @@ namespace HeliosPlus.GameLibraries
}
catch (ArgumentException ex)
{
Console.WriteLine($"UplayGame/GetAllInstalledGames argumentexception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"UplayGame/GetAllInstalledGames argumentexception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
//we just want to ignore it if we try to add it twice....
}

View File

@ -39,6 +39,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<UseVSHostingProcess>true</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>

View File

@ -52,7 +52,7 @@ namespace HeliosPlus.InterProcess
}
catch (Exception ex)
{
Console.WriteLine($"IPCClient/QueryAll exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"IPCClient/QueryAll exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// ignored
}
@ -82,7 +82,7 @@ namespace HeliosPlus.InterProcess
}
catch (Exception ex)
{
Console.WriteLine($"IPCClient/QueryByStatus exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"IPCClient/QueryByStatus exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// ignored
}
}

View File

@ -53,7 +53,7 @@ namespace HeliosPlus.InterProcess
}
catch (Exception ex)
{
Console.WriteLine($"IPCService/StartService exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"IPCService/StartService exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
try
{
_serviceHost?.Close();

View File

@ -138,7 +138,7 @@ namespace HeliosPlus {
}
catch (CommandParsingException ex)
{
Console.WriteLine($"Program/Main commandParsingException: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"Program/Main commandParsingException: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// You'll always want to catch this exception, otherwise it will generate a messy and confusing error for the end user.
// the message will usually be something like:
// "Unrecognized command or argument '<invalid-command>'"
@ -146,7 +146,7 @@ namespace HeliosPlus {
}
catch (Exception ex)
{
Console.WriteLine($"Program/Main exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"Program/Main exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
Console.WriteLine("Unable to execute application: {0}", ex.Message);
}
return 0;
@ -179,7 +179,7 @@ namespace HeliosPlus {
}
catch (Exception ex)
{
Console.WriteLine($"Program/StartUpNormally exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"Program/StartUpNormally exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// TODO
}
}
@ -228,7 +228,7 @@ namespace HeliosPlus {
}
catch (Exception ex)
{
Console.WriteLine($"Program/StartUpNormally exception 2: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"Program/StartUpNormally exception 2: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// TODO
}
@ -238,7 +238,7 @@ namespace HeliosPlus {
}
catch (Exception ex)
{
Console.WriteLine($"Program/StartUpNormally exception 3: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"Program/StartUpNormally exception 3: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
MessageBox.Show(
ex.Message,
Language.Fatal_Error,

View File

@ -339,7 +339,7 @@ namespace HeliosPlus
}
catch (Exception ex)
{
Console.WriteLine($"ShortcutItem/ExtractVisataIcon exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"ShortcutItem/ExtractVisataIcon exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
return null;
}
return bmpPngExtracted;

View File

@ -128,7 +128,7 @@ namespace HeliosPlus
}
catch (Exception ex)
{
Console.WriteLine($"ShortcutRepository/RemoveShortcut exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"ShortcutRepository/RemoveShortcut exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// TODO check and report
}
@ -178,7 +178,7 @@ namespace HeliosPlus
}
catch (Exception ex)
{
Console.WriteLine($"ShortcutRepository/RemoveShortcut exception 2: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"ShortcutRepository/RemoveShortcut exception 2: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// TODO check and report
}
@ -350,7 +350,7 @@ namespace HeliosPlus
}
catch (Exception ex)
{
Console.WriteLine($"ShortcutRepository/SaveShortcuts exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"ShortcutRepository/SaveShortcuts exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
Console.WriteLine($"Unable to create Shortcut folder {_shortcutStorageJsonPath}: " + ex.Message);
@ -376,7 +376,7 @@ namespace HeliosPlus
}
catch (Exception ex)
{
Console.WriteLine($"ShortcutRepository/SaveShortcuts exception 2: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"ShortcutRepository/SaveShortcuts exception 2: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
Console.WriteLine($"Unable to save Shortcut JSON file {_shortcutStorageJsonFileName}: " + ex.Message);
}
@ -434,7 +434,7 @@ namespace HeliosPlus
}
catch (Exception ex)
{
Console.WriteLine($"ShortcutRepository/SaveShortcutIconToCache exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"ShortcutRepository/SaveShortcutIconToCache exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// If we fail to create an icon based on the original executable or game
// Then we use the standard HeliosPlus profile one.
@ -537,7 +537,7 @@ namespace HeliosPlus
}
catch (Exception ex)
{
Console.WriteLine($"ShortcutItem/Run exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"ShortcutItem/Run exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// ignored
}
@ -550,7 +550,7 @@ namespace HeliosPlus
}
catch (Exception ex)
{
Console.WriteLine($"ShortcutItem/Run exception 2: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"ShortcutItem/Run exception 2: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// ignored
}
}
@ -624,7 +624,7 @@ namespace HeliosPlus
}
catch (Exception ex)
{
Console.WriteLine($"Program/SwitchToSteamGame exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"Program/SwitchToSteamGame exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// ignored
}
@ -752,7 +752,7 @@ namespace HeliosPlus
}
catch (Exception ex)
{
Console.WriteLine($"ShortcutRepository/ApplyTopology exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"ShortcutRepository/ApplyTopology exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// ignored
}
}

View File

@ -190,7 +190,7 @@ namespace HeliosPlus.UIForms
}
catch (Exception ex)
{
Console.WriteLine($"ApplyingChangesForm/SplashForm_FormClosing exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"ApplyingChangesForm/SplashForm_FormClosing exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// ignored
}
}, this), new SafeInvoker(() =>
@ -216,7 +216,7 @@ namespace HeliosPlus.UIForms
}
catch (Exception ex)
{
Console.WriteLine($"ApplyingChangesForm/SplashForm_Shown exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"ApplyingChangesForm/SplashForm_Shown exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// ignored
}
}, this), new SafeInvoker(DoTimeout, this));

View File

@ -10768,7 +10768,7 @@
<value>Microsoft Sans Serif, 21.75pt</value>
</data>
<data name="btn_setup_game_shortcuts.Location" type="System.Drawing.Point, System.Drawing">
<value>212, 182</value>
<value>212, 184</value>
</data>
<data name="btn_setup_game_shortcuts.Size" type="System.Drawing.Size, System.Drawing">
<value>360, 50</value>
@ -10798,7 +10798,7 @@
<value>Flat</value>
</data>
<data name="btn_exit.Location" type="System.Drawing.Point, System.Drawing">
<value>697, 354</value>
<value>698, 347</value>
</data>
<data name="btn_exit.Size" type="System.Drawing.Size, System.Drawing">
<value>75, 23</value>

View File

@ -66,7 +66,7 @@ namespace HeliosPlus.UIForms
}
catch (Exception ex)
{
Console.WriteLine($"ProfileAdaptor/GetThumbnail exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"ProfileAdaptor/GetThumbnail exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// If we have a problem with converting the submitted key to a profile
// Then we return null
return null;
@ -103,7 +103,7 @@ namespace HeliosPlus.UIForms
}
catch (Exception ex)
{
Console.WriteLine($"ProfileAdaptor/GertUniqueIdentifier exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"ProfileAdaptor/GertUniqueIdentifier exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// If we have a problem with converting the submitted key to a profile
// Then we return null
return null;
@ -127,7 +127,7 @@ namespace HeliosPlus.UIForms
}
catch (Exception ex)
{
Console.WriteLine($"ProfileAdaptor/GetSourceImage exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"ProfileAdaptor/GetSourceImage exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// If we have a problem with converting the submitted key to a profile
// Then we return null
return null;
@ -158,16 +158,52 @@ namespace HeliosPlus.UIForms
// Get file info
if (profileToUse.ProfileBitmap is Bitmap)
{
// 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 = profileToUse.ProfileBitmap.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 = profileToUse.ProfileBitmap.PhysicalDimension;
gotSizeF = true;
}
catch (Exception ex)
{
// catch the System.Drawing.Image exception created while accessing the Size
}
}
string name = profileToUse.Name;
string filepath = Path.GetDirectoryName(profileToUse.SavedProfileIconCacheFilename);
string filename = Path.GetFileName(profileToUse.SavedProfileIconCacheFilename);
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));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.FilePath, string.Empty, ""));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.FolderName, string.Empty, ""));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Dimensions, string.Empty, new Size(profileToUse.ProfileBitmap.Width, profileToUse.ProfileBitmap.Height)));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Resolution, string.Empty, new SizeF((float)profileToUse.ProfileBitmap.Width, (float)profileToUse.ProfileBitmap.Height)));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.ImageDescription, string.Empty, profileToUse.Name));
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 ?? ""));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.EquipmentModel, string.Empty, ""));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.DateTaken, string.Empty, now));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Artist, string.Empty, ""));
@ -185,7 +221,7 @@ namespace HeliosPlus.UIForms
}
catch (Exception ex)
{
Console.WriteLine($"ProfileAdaptor/Utility.Tuple exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"ProfileAdaptor/Utility.Tuple exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// If we have a problem with converting the submitted key to a profile
// Then we return null
return null;

View File

@ -3,9 +3,8 @@ using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace HeliosPlus.UIForms
{
@ -20,7 +19,7 @@ namespace HeliosPlus.UIForms
private bool disposed;
/// <summary>
/// Initializes a new instance of the <see cref="FileSystemAdaptor"/> class.
/// Initializes a new instance of the <see cref="ShortcutAdaptor"/> class.
/// </summary>
public ShortcutAdaptor()
{
@ -49,13 +48,14 @@ namespace HeliosPlus.UIForms
return null;
}
//Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(() => { return false; });
Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(() => { return false; });
//return shortcut.ShortcutBitmap.GetThumbnailImage(size.Width, size.Height, myCallback, IntPtr.Zero);
//return Manina.Windows.Forms.Instance.GetThumbnail(shortcut.ShortcutBitmap, size, useEmbeddedThumbnails, useExifOrientation);
return shortcut.ShortcutBitmap;
}
catch (Exception ex)
{
Console.WriteLine($"ShortcutAdapter/GetThumbnail exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"ShortcutAdapter/GetThumbnail exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// If we have a problem with converting the submitted key to a profile
// Then we return null
@ -83,11 +83,24 @@ namespace HeliosPlus.UIForms
try
{
ShortcutItem shortcut = (ShortcutItem) key;
return shortcut.Name;
//return shortcut.Name;
StringBuilder sb = new StringBuilder();
sb.Append(shortcut.ToString());// Filename
sb.Append(':');
sb.Append(size.Width); // Thumbnail size
sb.Append(',');
sb.Append(size.Height);
sb.Append(':');
sb.Append(useEmbeddedThumbnails);
sb.Append(':');
sb.Append(useExifOrientation);
return sb.ToString();
}
catch (Exception ex)
{
Console.WriteLine($"ShortcutAdapter/GetUniqueIdentifier exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"ShortcutAdapter/GetUniqueIdentifier exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// If we have a problem with converting the submitted key to a Shortcut
// Then we return null
return null;
@ -111,7 +124,7 @@ namespace HeliosPlus.UIForms
}
catch (Exception ex)
{
Console.WriteLine($"ShortcutAdaptor/GetSourceImage exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"ShortcutAdaptor/GetSourceImage exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// If we have a problem with converting the submitted key to a profile
// Then we return null
@ -138,16 +151,53 @@ namespace HeliosPlus.UIForms
// Get file info
if (shortcut.ShortcutBitmap is Bitmap)
{
// 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);
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));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.FilePath, string.Empty, shortcut.SavedShortcutIconCacheFilename));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.FolderName, string.Empty, ""));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Dimensions, string.Empty, new Size(shortcut.ShortcutBitmap.Width, shortcut.ShortcutBitmap.Height)));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Resolution, string.Empty, new SizeF((float)shortcut.ShortcutBitmap.Width, (float)shortcut.ShortcutBitmap.Height)));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.ImageDescription, string.Empty, shortcut.Name));
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 ?? ""));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.EquipmentModel, string.Empty, ""));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.DateTaken, string.Empty, now));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Artist, string.Empty, ""));
@ -165,7 +215,7 @@ namespace HeliosPlus.UIForms
}
catch (Exception ex)
{
Console.WriteLine($"ShortcutAdapter/Utility.Tuple exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"ShortcutAdapter/Utility.Tuple exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
// If we have a problem with converting the submitted key to a profile
// Then we return null
return null;

View File

@ -672,7 +672,7 @@ namespace HeliosPlus.UIForms
}
catch (Exception ex)
{
Console.WriteLine($"ShortcutForm exception: {ex.Message}: {ex.InnerException}");
Console.WriteLine($"ShortcutForm exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
il_games.Images.Add(Image.FromFile("Resources/Steam.ico"));
}
} else

View File

@ -30,17 +30,10 @@ namespace HeliosPlus.UIForms
//_shortcutAdaptor = new ShortcutAdaptor();
//_shortcutRepository = new ShortcutRepository();
//_profileRepository = new ProfileRepository();
}
private void btn_new_Click(object sender, EventArgs e)
{
var shortcutForm = new ShortcutForm();
shortcutForm.ShowDialog(this);
if (shortcutForm.DialogResult == DialogResult.OK)
{
ShortcutRepository.AddShortcut(shortcutForm.Shortcut);
RefreshShortcutLibraryUI();
}
ilv_saved_shortcuts.MultiSelect = false;
ilv_saved_shortcuts.ThumbnailSize = new Size(100,100);
ilv_saved_shortcuts.AllowDrag = false;
ilv_saved_shortcuts.AllowDrop = false;
}
private void btn_back_Click(object sender, EventArgs e)
@ -57,8 +50,9 @@ namespace HeliosPlus.UIForms
private void RefreshShortcutLibraryUI()
{
if (ShortcutRepository.ShortcutCount > 0)
{
if (ShortcutRepository.ShortcutCount == 0)
return;
// Temporarily stop updating the saved_profiles listview
ilv_saved_shortcuts.SuspendLayout();
@ -70,35 +64,21 @@ namespace HeliosPlus.UIForms
//newItem = new ImageListViewItem(loadedProfile.SavedProfileCacheFilename, loadedProfile.Name);
//newItem = new ImageListViewItem(loadedProfile, loadedProfile.Name);
newItem = new ImageListViewItem(loadedShortcut, loadedShortcut.Name);
// Select it if its the selectedProfile
if (_selectedShortcut is ShortcutItem && _selectedShortcut.Equals(loadedShortcut))
newItem.Selected = true;
//ilv_saved_profiles.Items.Add(newItem);
ilv_saved_shortcuts.Items.Add(newItem, _shortcutAdaptor);
}
if (_selectedShortcut != null && _selectedShortcut is ShortcutItem)
RefreshImageListView(_selectedShortcut);
// Restart updating the saved_profiles listview
ilv_saved_shortcuts.ResumeLayout();
}
// Refresh the image list view
//RefreshImageListView(_selectedShortcut);
}
private void RefreshImageListView(ShortcutItem shortcut)
{
ilv_saved_shortcuts.ClearSelection();
IEnumerable<ImageListViewItem> matchingImageListViewItems = (from item in ilv_saved_shortcuts.Items where item.Text == shortcut.Name select item);
if (matchingImageListViewItems.Any())
{
matchingImageListViewItems.First().Selected = true;
matchingImageListViewItems.First().Focused = true;
}
}
private ShortcutItem GetShortcutFromName(string shortcutName)
{
return (from item in ShortcutRepository.AllShortcuts where item.Name == shortcutName select item).First();
@ -186,6 +166,18 @@ namespace HeliosPlus.UIForms
}
private void btn_new_Click(object sender, EventArgs e)
{
var shortcutForm = new ShortcutForm();
shortcutForm.ShowDialog(this);
if (shortcutForm.DialogResult == DialogResult.OK)
{
ShortcutRepository.AddShortcut(shortcutForm.Shortcut);
_selectedShortcut = shortcutForm.Shortcut;
RefreshShortcutLibraryUI();
}
}
private void btn_edit_Click(object sender, EventArgs e)
{
if (_selectedShortcut == null)