Mostly working Game icons!

Well this took enough time! I have
almost corrected all the issues with
the icon parsing functions, but I still
have a couple of edge cases to fix.
This commit is contained in:
Terry MacDonald 2021-05-16 21:46:58 +12:00
parent 22964f07df
commit 5bdb2adba8
8 changed files with 440 additions and 247 deletions

View File

@ -41,6 +41,7 @@
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<UseVSHostingProcess>true</UseVSHostingProcess>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -279,6 +280,9 @@
<PackageReference Include="HtmlAgilityPack">
<Version>1.11.33</Version>
</PackageReference>
<PackageReference Include="IconExtractor">
<Version>1.0.1</Version>
</PackageReference>
<PackageReference Include="IconExtractor.dll">
<Version>1.0.2.1-beta</Version>
</PackageReference>
@ -295,7 +299,7 @@
<Version>3.1.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications">
<Version>7.0.1</Version>
<Version>7.0.2</Version>
</PackageReference>
<PackageReference Include="MintPlayer.IconUtils">
<Version>1.0.4</Version>
@ -310,7 +314,7 @@
<Version>2.1.0</Version>
</PackageReference>
<PackageReference Include="NLog">
<Version>4.7.9</Version>
<Version>4.7.10</Version>
</PackageReference>
<PackageReference Include="QueryString.NET">
<Version>1.0.0</Version>

View File

@ -583,10 +583,10 @@ namespace DisplayMagician
IntPtr hIcon = IntPtr.Zero;
int ILD_TRANSPARENT = 1;
hres = iml.GetIcon(iconIndex, ILD_TRANSPARENT, ref hIcon);
//if (hres == 0)
//{
// throw (new System.Exception("Error iml.GetIcon"));
//}
/*if (hres == 0)
{
return new Bitmap(1, 1);
}*/
var myIcon = System.Drawing.Icon.FromHandle(hIcon);
Bitmap bm = myIcon.ToBitmap();

View File

@ -10,6 +10,8 @@ using System.Text;
using System.Threading.Tasks;
using TsudaKageyu;
using DisplayMagicianShared;
using MintPlayer.IconUtils;
using System.Runtime.InteropServices;
namespace DisplayMagician
{
@ -130,126 +132,172 @@ namespace DisplayMagician
return newBitmap;
}
/* public static Bitmap ToLargeBitmap(string fileNameAndPath)
{
Bitmap bmToReturn = null;
/* public static Bitmap ToLargeBitmap(string fileNameAndPath)
{
Bitmap bmToReturn = null;
try
{
if (String.IsNullOrWhiteSpace(fileNameAndPath))
{
logger.Warn($"ShortcutItem/ToLargeBitmap: Bitmap fileNameAndPath is empty! Unable to get the large icon from the file (256px x 256px).");
return null;
}
if (fileNameAndPath.EndsWith(".ico"))
{
logger.Trace($"ShortcutItem/ToLargeBitmap: The file we want to get the image from is an icon file. Attempting to extract the icon file from {fileNameAndPath}.");
Icon myIcon = new Icon(fileNameAndPath,128,128);
bmToReturn = myIcon.ToBitmap();
MultiIcon myMultiIcon = new MultiIcon();
SingleIcon mySingleIcon = myMultiIcon.Add("Icon1");
//mySingleIcon.CreateFrom(fileNameAndPath,IconOutputFormat.Vista);
mySingleIcon.Load(fileNameAndPath);
Bitmap bm = null;
foreach (IconImage myIconImage in mySingleIcon)
{
bm = myIconImage.Image;
if (bm.Width > bmToReturn.Width && bm.Height > bmToReturn.Height)
{
bmToReturn = bm;
logger.Trace($"ShortcutItem/ToLargeBitmap: This new bitmap from the icon file {fileNameAndPath} is larger than the previous one at {bm.Width} x {bm.Height}, so using that instead.");
}
}
}
else
{
Icon myIcon = Icon.ExtractAssociatedIcon(fileNameAndPath);
bmToReturn = myIcon.ToBitmap();
logger.Trace($"ShortcutItem/ToLargeBitmap: The file {fileNameAndPath} isn't an Icon file, so trying to use GetLargeBitmapFromFile to extract the image.");
Bitmap bm = null;
bm = IconFromFile.GetLargeBitmapFromFile(fileNameAndPath, false, false);
if (bm.Width > bmToReturn.Width && bm.Height > bmToReturn.Height)
{
bmToReturn = bm;
logger.Trace($"ShortcutItem/ToLargeBitmap: This new bitmap from the icon file {fileNameAndPath} is larger than the previous one at {bm.Width} x {bm.Height}, so using that instead.");
}
}
return bmToReturn;
}
catch (Exception ex)
{
logger.Warn(ex, $"ShortcutItem/ToLargeBitmap: Exception while trying to save the Shortcut icon initially. Trying again with GetLargeBitmapFromFile.");
try
{
logger.Trace($"ShortcutItem/ToLargeBitmap: Attempt2. The file {fileNameAndPath} isn't an Icon file, so trying to use GetLargeBitmapFromFile to extract the image.");
bmToReturn = IconFromFile.GetLargeBitmapFromFile(fileNameAndPath, true, false);
return bmToReturn;
}
catch (Exception innerex)
{
logger.Warn(innerex, $"ShortcutItem/ToLargeBitmap: Exception while trying to save the Shortcut icon a second time. Giving up.");
return null;
}
}
}
public static Bitmap ToLargeBitmap(ArrayList fileNamesAndPaths)
{
Bitmap bmToReturn = null;
if (fileNamesAndPaths.Count == 0)
{
logger.Warn($"ShortcutItem/ToLargeBitmap2: The fileNamesAndPaths list is empty! Can't get the large bitmap.");
return null;
}
foreach (string fileNameAndPath in fileNamesAndPaths)
{
Bitmap bm = ToLargeBitmap(fileNameAndPath);
if (bmToReturn == null)
{
bmToReturn = bm;
}
if (bm.Width > bmToReturn.Width && bm.Height > bmToReturn.Height)
{
bmToReturn = bm;
}
}
return bmToReturn;
}*/
public static Bitmap GetMeABitmapFromFile(string fileNameAndPath)
{
if (String.IsNullOrWhiteSpace(fileNameAndPath))
{
logger.Warn($"ShortcutItem/GetMeABitmapFromFile: Bitmap fileNameAndPath is empty! Unable to get the icon from the file.");
return null;
}
Icon myIcon = null;
Bitmap bm = null;
Bitmap bmToReturn = new Bitmap(1, 1);
try
{
if (String.IsNullOrWhiteSpace(fileNameAndPath))
{
logger.Warn($"ShortcutItem/ToLargeBitmap: Bitmap fileNameAndPath is empty! Unable to get the large icon from the file (256px x 256px).");
return null;
}
if (fileNameAndPath.EndsWith(".ico"))
List<Icon> myExtractedIcons = MintPlayer.IconUtils.IconExtractor.Split(fileNameAndPath);
foreach (Icon myExtractedIcon in myExtractedIcons)
{
logger.Trace($"ShortcutItem/ToLargeBitmap: The file we want to get the image from is an icon file. Attempting to extract the icon file from {fileNameAndPath}.");
Size largeSize = new Size(256, 256);
myIcon = myExtractedIcon.TryGetIcon(largeSize, 32, true, true);
Icon myIcon = new Icon(fileNameAndPath,128,128);
bmToReturn = myIcon.ToBitmap();
MultiIcon myMultiIcon = new MultiIcon();
SingleIcon mySingleIcon = myMultiIcon.Add("Icon1");
//mySingleIcon.CreateFrom(fileNameAndPath,IconOutputFormat.Vista);
mySingleIcon.Load(fileNameAndPath);
Bitmap bm = null;
foreach (IconImage myIconImage in mySingleIcon)
if (myIcon != null)
{
bm = myIconImage.Image;
bm = myIcon.ToBitmap();
if (bm.Width > bmToReturn.Width && bm.Height > bmToReturn.Height)
{
bmToReturn = bm;
logger.Trace($"ShortcutItem/ToLargeBitmap: This new bitmap from the icon file {fileNameAndPath} is larger than the previous one at {bm.Width} x {bm.Height}, so using that instead.");
logger.Trace($"ShortcutItem/ToSmallBitmap: This new bitmap from the icon file {fileNameAndPath} is larger than the previous one at {bm.Width} x {bm.Height}, so using that instead.");
}
}
}
}
else
{
Icon myIcon = Icon.ExtractAssociatedIcon(fileNameAndPath);
bmToReturn = myIcon.ToBitmap();
}
catch (Exception ex)
{
logger.Warn(ex, $"ShortcutItem/GetMeABitmapFromFile: Exception while trying to Split the icon using MintPlayer IconExtractor! ");
}
logger.Trace($"ShortcutItem/ToLargeBitmap: The file {fileNameAndPath} isn't an Icon file, so trying to use GetLargeBitmapFromFile to extract the image.");
Bitmap bm = null;
bm = IconFromFile.GetLargeBitmapFromFile(fileNameAndPath, false, false);
if (fileNameAndPath.EndsWith(".ico"))
{
try
{
logger.Trace($"ShortcutItem/ToSmallBitmap: The file we want to get the image from is an icon file. Attempting to extract the icon file from {fileNameAndPath}.");
myIcon = new Icon(fileNameAndPath, 256, 256);
//Icon myIcon = Icon.ExtractAssociatedIcon(fileNameAndPath);
bm = myIcon.ToBitmap();
//myIcon = Icon.ExtractAssociatedIcon(fileNameAndPath);
//bm = myIcon.ToBitmap();
if (bm.Width > bmToReturn.Width && bm.Height > bmToReturn.Height)
{
bmToReturn = bm;
logger.Trace($"ShortcutItem/ToLargeBitmap: This new bitmap from the icon file {fileNameAndPath} is larger than the previous one at {bm.Width} x {bm.Height}, so using that instead.");
logger.Trace($"ShortcutItem/ToSmallBitmap: This new bitmap from the icon file {fileNameAndPath} is larger than the previous one at {bm.Width} x {bm.Height}, so using that instead.");
}
}
return bmToReturn;
}
catch (Exception ex)
{
logger.Warn(ex, $"ShortcutItem/ToLargeBitmap: Exception while trying to save the Shortcut icon initially. Trying again with GetLargeBitmapFromFile.");
catch (Exception ex)
{
logger.Warn(ex, $"ShortcutItem/GetMeABitmapFromFile: Exception while trying to extract the icon from a *.ico using Standard Icon tools.");
}
try
{
logger.Trace($"ShortcutItem/ToLargeBitmap: Attempt2. The file {fileNameAndPath} isn't an Icon file, so trying to use GetLargeBitmapFromFile to extract the image.");
bmToReturn = IconFromFile.GetLargeBitmapFromFile(fileNameAndPath, true, false);
return bmToReturn;
}
catch (Exception innerex)
{
logger.Warn(innerex, $"ShortcutItem/ToLargeBitmap: Exception while trying to save the Shortcut icon a second time. Giving up.");
return null;
}
}
}
public static Bitmap ToLargeBitmap(ArrayList fileNamesAndPaths)
{
Bitmap bmToReturn = null;
if (fileNamesAndPaths.Count == 0)
{
logger.Warn($"ShortcutItem/ToLargeBitmap2: The fileNamesAndPaths list is empty! Can't get the large bitmap.");
return null;
}
foreach (string fileNameAndPath in fileNamesAndPaths)
{
Bitmap bm = ToLargeBitmap(fileNameAndPath);
if (bmToReturn == null)
{
bmToReturn = bm;
}
if (bm.Width > bmToReturn.Width && bm.Height > bmToReturn.Height)
{
bmToReturn = bm;
}
}
return bmToReturn;
}*/
public static Bitmap GetMeABitmapFromFile(string fileNameAndPath)
{
Bitmap bmToReturn = null;
try
{
if (String.IsNullOrWhiteSpace(fileNameAndPath))
{
logger.Warn($"ShortcutItem/ToSmallBitmap: Bitmap fileNameAndPath is empty! Unable to get the small icon from the file (128px x 128px).");
return null;
}
Icon myIcon = null;
Bitmap bm = null;
if (fileNameAndPath.EndsWith(".ico"))
{
logger.Trace($"ShortcutItem/ToSmallBitmap: The file we want to get the image from is an icon file. Attempting to extract the icon file from {fileNameAndPath}.");
myIcon = new Icon(fileNameAndPath, 128, 128);
//Icon myIcon = Icon.ExtractAssociatedIcon(fileNameAndPath);
bmToReturn = myIcon.ToBitmap();
MultiIcon myMultiIcon = new MultiIcon();
SingleIcon mySingleIcon = myMultiIcon.Add("Icon1");
mySingleIcon.CreateFrom(fileNameAndPath, IconOutputFormat.Vista);
//mySingleIcon.Load(fileNameAndPath, IconOutputFormat.All);
mySingleIcon.Load(fileNameAndPath);
foreach (IconImage myIconImage in mySingleIcon)
{
bm = myIconImage.Image;
@ -260,32 +308,39 @@ namespace DisplayMagician
logger.Trace($"ShortcutItem/ToSmallBitmap: This new bitmap from the icon file {fileNameAndPath} is larger than the previous one at {bm.Width} x {bm.Height}, so using that instead.");
}
}
myIcon = Icon.ExtractAssociatedIcon(fileNameAndPath);
bm = myIcon.ToBitmap();
if (bm.Width > bmToReturn.Width && bm.Height > bmToReturn.Height)
}
catch (Exception ex)
{
logger.Warn(ex, $"ShortcutItem/GetMeABitmapFromFile: Exception while trying to extract the icon from a *.ico using MultiIcon tools.");
}
}
else
{
try
{
List<Icon> myIcons = ImageUtils.ExtractIconsFromExe(fileNameAndPath, true);
if (myIcons != null && myIcons.Count > 0)
{
bmToReturn = bm;
logger.Trace($"ShortcutItem/ToSmallBitmap: This new bitmap from the icon file {fileNameAndPath} is larger than the previous one at {bm.Width} x {bm.Height}, so using that instead.");
foreach (Icon myExtractedIcon in myIcons)
{
bm = myExtractedIcon.ToBitmap();
if (bm.Width > bmToReturn.Width && bm.Height > bmToReturn.Height)
{
bmToReturn = bm;
logger.Trace($"ShortcutItem/ToSmallBitmap: This new bitmap from the icon file {fileNameAndPath} is larger than the previous one at {bm.Width} x {bm.Height}, so using that instead.");
}
}
}
}
else
catch (Exception ex)
{
myIcon = Icon.ExtractAssociatedIcon(fileNameAndPath);
bmToReturn = myIcon.ToBitmap();
logger.Warn(ex, $"ShortcutItem/GetMeABitmapFromFile: Exception while trying to extract the icon from an *.exe or *.dll using ImageUtils.ExtractIconsFromExe.");
}
logger.Trace($"ShortcutItem/ToSmallBitmap: The file {fileNameAndPath} isn't an Icon file, so trying to use GetLargeBitmapFromFile to extract the image.");
//bm = IconFromFile.GetSmallBitmapFromFile(fileNameAndPath, false, false, false);
bm = IconFromFile.GetSmallBitmapFromFile(fileNameAndPath, false, false, false);
if (bm.Width > bmToReturn.Width && bm.Height > bmToReturn.Height)
{
bmToReturn = bm;
logger.Trace($"ShortcutItem/ToSmallBitmap: This new bitmap from the icon file {fileNameAndPath} is larger than the previous one at {bm.Width} x {bm.Height}, so using that instead.");
}
IconExtractor ie = new IconExtractor(fileNameAndPath);
try
{
var ie = new TsudaKageyu.IconExtractor(fileNameAndPath);
Icon[] allIcons = ie.GetAllIcons();
foreach (Icon myExtractedIcon in allIcons)
{
@ -297,25 +352,31 @@ namespace DisplayMagician
logger.Trace($"ShortcutItem/ToSmallBitmap: This new bitmap from the icon file {fileNameAndPath} is larger than the previous one at {bm.Width} x {bm.Height}, so using that instead.");
}
}
}
catch (Exception ex)
{
logger.Warn(ex, $"ShortcutItem/GetMeABitmapFromFile: Exception while trying to extract the icon from an *.exe or *.dll using TsudaKageyu.IconExtractor.");
}
}
if (bmToReturn == null)
{
// If we couldn't get any bitmaps at all
logger.Warn( $"ShortcutItem/GetMeABitmapFromFile: Haven't managed to get a valid icon file so returning null :(.");
return null;
}
else if (bmToReturn.Width == 1 && bmToReturn.Height == 1)
{
// If we couldn't extract anything, so we return null
logger.Warn($"ShortcutItem/GetMeABitmapFromFile: Haven't managed to get a valid icon file so returning null instead of a 1x1 bitmap!.");
return null;
}
else
{
return bmToReturn;
}
catch (Exception ex)
{
logger.Warn(ex, $"ShortcutItem/ToSmallBitmap: Exception while trying to save the Shortcut icon initially. Trying again with GetSmallBitmapFromFile.");
try
{
logger.Trace($"ShortcutItem/ToSmallBitmap: Attempt2. The file {fileNameAndPath} isn't an Icon file, so trying to use GetSmallBitmapFromFile to extract the image.");
bmToReturn = IconFromFile.GetSmallBitmapFromFile(fileNameAndPath, false, false, false);
return bmToReturn;
}
catch (Exception innerex)
{
logger.Warn(innerex, $"ShortcutItem/ToSmallBitmap: Exception while trying to save the Shortcut icon a second time. Giving up.");
return null;
}
}
}
public static Bitmap GetMeABitmapFromFile(ArrayList fileNamesAndPaths)
@ -336,7 +397,7 @@ namespace DisplayMagician
{
bmToReturn = bm;
}
if (bm.Width > bmToReturn.Width && bm.Height > bmToReturn.Height)
if (bm != null && bm.Width > bmToReturn.Width && bm.Height > bmToReturn.Height)
{
bmToReturn = bm;
}
@ -477,6 +538,144 @@ namespace DisplayMagician
return null;
}
}
}
[DllImport("Shell32", CharSet = CharSet.Auto)]
private static unsafe extern int ExtractIconEx(string lpszFile, int nIconIndex, IntPtr[] phIconLarge, IntPtr[] phIconSmall, int nIcons);
[DllImport("user32.dll", EntryPoint = "DestroyIcon", SetLastError = true)]
private static unsafe extern int DestroyIcon(IntPtr hIcon);
public static List<Icon> ExtractIconsFromExe(string file, bool large)
{
unsafe
{
int readIconCount = 0;
IntPtr[] hLargeIconEx = new IntPtr[] { IntPtr.Zero };
IntPtr[] hSmallIconEx = new IntPtr[] { IntPtr.Zero };
try
{
List<Icon> extractedIcons = new List<Icon>() { };
// First we get the total number of icons using ExtractIconEx
int totalIconCount = ExtractIconEx(file, -1, null, null, 0);
if (totalIconCount > 0)
{
for (int iconNum = 0; iconNum < totalIconCount; iconNum++)
{
hLargeIconEx = new IntPtr[] { IntPtr.Zero };
hSmallIconEx = new IntPtr[] { IntPtr.Zero };
//if (large)
//readIconCount = ExtractIconEx(file, 0, hIconEx, hDummy, 1);
// readIconCount = ExtractIconEx(file, iconNum, hIconEx, null, 1);
//else
//readIconCount = ExtractIconEx(file, 0, hDummy, hIconEx, 1);
// readIconCount = ExtractIconEx(file, iconNum, null, hIconEx, 1);
readIconCount = ExtractIconEx(file, iconNum, hLargeIconEx, hSmallIconEx, 1);
if (readIconCount > 0)
{
if (hLargeIconEx[0] != IntPtr.Zero)
{
Icon extractedIcon = (Icon)Icon.FromHandle(hLargeIconEx[0]).Clone();
extractedIcons.Add(extractedIcon);
}
else if (hSmallIconEx[0] != IntPtr.Zero)
{
Icon extractedIcon = (Icon)Icon.FromHandle(hSmallIconEx[0]).Clone();
extractedIcons.Add(extractedIcon);
}
// GET FIRST EXTRACTED ICON
return extractedIcons;
}
}
return extractedIcons;
}
else
return null;
}
catch (Exception ex)
{
/* EXTRACT ICON ERROR */
// BUBBLE UP
throw new ApplicationException("Could not extract icon", ex);
}
finally
{
// RELEASE RESOURCES
foreach (IntPtr ptr in hLargeIconEx)
if (ptr != IntPtr.Zero)
DestroyIcon(ptr);
foreach (IntPtr ptr in hSmallIconEx)
if (ptr != IntPtr.Zero)
DestroyIcon(ptr);
}
}
}
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern IntPtr LoadImage(IntPtr hinst, string lpszName, uint uType,
int cxDesired, int cyDesired, uint fuLoad);
/*[DllImport("user32.dll", SetLastError = true)]
private static extern int DestroyIcon(IntPtr hIcon);*/
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern IntPtr LoadLibraryEx(string lpFileName, IntPtr hFile, LoadLibraryFlags dwFlags);
private enum LoadLibraryFlags : uint
{
DONT_RESOLVE_DLL_REFERENCES = 0x00000001,
LOAD_IGNORE_CODE_AUTHZ_LEVEL = 0x00000010,
LOAD_LIBRARY_AS_DATAFILE = 0x00000002,
LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE = 0x00000040,
LOAD_LIBRARY_AS_IMAGE_RESOURCE = 0x00000020,
LOAD_WITH_ALTERED_SEARCH_PATH = 0x00000008
}
/// <summary>
/// Returns an icon of given size.
/// </summary>
/// <param name="path">Path to a file (.exe/.dll) that contains the icons.
/// Skip it or use <c>null</c> to use current application's file.</param>
/// <param name="resId">Name of the resource icon that should be loaded.
/// Skip it to use the default <c>#32512</c> (value of <c>IDI_APPLICATION</c>) to use
/// the application's icon.</param>
/// <param name="size">Size of the icon to load. If there is no such size available, a larger or smaller
/// sized-icon is scaled.</param>
/// <returns>List of all icons.</returns>
public static Icon GetIconFromExe(string path = null, string resId = "#32512", int size = 32)
{
// load module
IntPtr h;
if (path == null)
//h = Marshal.GetHINSTANCE(Assembly.GetEntryAssembly().GetModules()[0]);
return null;
else
{
h = LoadLibraryEx(path, IntPtr.Zero, LoadLibraryFlags.LOAD_LIBRARY_AS_DATAFILE);
if (h == IntPtr.Zero)
return null;
}
// 1 is IMAGE_ICON
IntPtr ptr = LoadImage(h, resId, 1, size, size, 0);
if (ptr != IntPtr.Zero)
{
try
{
Icon icon = (Icon)Icon.FromHandle(ptr).Clone();
return icon;
}
finally
{
DestroyIcon(ptr);
}
}
return null;
}
}
}

View File

@ -881,18 +881,25 @@ namespace DisplayMagician {
Bitmap bm = null;
try
{
/*ArrayList filesToSearchForIcon = new ArrayList();
filesToSearchForIcon.Add(game.ExePath);
filesToSearchForIcon.Add(game.IconPath);
ArrayList filesToSearchForIcon = new ArrayList();
filesToSearchForIcon.Add(game.ExePath);
if (game.IconPath != game.ExePath)
filesToSearchForIcon.Add(game.IconPath);
bm = ImageUtils.ToSmallBitmap(filesToSearchForIcon);*/
bm = ImageUtils.GetMeABitmapFromFile(filesToSearchForIcon);
//bm = ImageUtils.GetMeABitmapFromFile(game.IconPath);
bm = ImageUtils.GetMeABitmapFromFile(game.IconPath);
}
catch (Exception ex)
{
logger.Error(ex, $"Program/LoadGamesInBackground: Exception building game bitmaps during load");
logger.Error(ex, $"Program/LoadGamesInBackground: Exception building game bitmaps during load");
}
if (bm == null)
{
if (game.GameLibrary.Equals(SupportedGameLibraryType.Steam))
bm = Properties.Resources.Steam.ToBitmap();
else if (game.GameLibrary.Equals(SupportedGameLibraryType.Uplay))
@ -902,6 +909,7 @@ namespace DisplayMagician {
else
bm = Properties.Resources.DisplayMagician.ToBitmap();
}
game.GameBitmap = bm;
}

View File

@ -205,6 +205,7 @@ namespace DisplayMagician.UIForms
this.tabc_shortcut.ShowToolTips = true;
this.tabc_shortcut.Size = new System.Drawing.Size(1090, 654);
this.tabc_shortcut.TabIndex = 28;
this.tabc_shortcut.VisibleChanged += new System.EventHandler(this.tabc_shortcut_VisibleChanged);
//
// tabp_display
//
@ -896,13 +897,16 @@ namespace DisplayMagician.UIForms
//
// ilv_games
//
this.ilv_games.Dock = System.Windows.Forms.DockStyle.Bottom;
this.ilv_games.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.ilv_games.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.ilv_games.IntegralScroll = true;
this.ilv_games.Location = new System.Drawing.Point(0, 97);
this.ilv_games.Name = "ilv_games";
this.ilv_games.PersistentCacheDirectory = "";
this.ilv_games.PersistentCacheSize = ((long)(100));
this.ilv_games.Size = new System.Drawing.Size(1076, 226);
this.ilv_games.SortOrder = Manina.Windows.Forms.SortOrder.Ascending;
this.ilv_games.TabIndex = 28;
this.ilv_games.UseWIC = true;
this.ilv_games.ItemClick += new Manina.Windows.Forms.ItemClickEventHandler(this.ilv_games_ItemClick);
@ -1405,6 +1409,6 @@ namespace DisplayMagician.UIForms
private System.Windows.Forms.FlowLayoutPanel flp_start_programs;
private System.Windows.Forms.Button btn_add_new_start_program;
private System.Windows.Forms.Label label3;
private Manina.Windows.Forms.ImageListView ilv_games;
internal Manina.Windows.Forms.ImageListView ilv_games;
}
}

View File

@ -463,7 +463,7 @@ namespace DisplayMagician.UIForms
_capturePermanence = ShortcutPermanence.Temporary;
}
// Scan through the list of
// Add the startprograms to the list
List<StartProgram> newStartPrograms = new List<StartProgram>() { };
foreach (StartProgramControl myStartProgramControl in flp_start_programs.Controls)
{
@ -472,55 +472,7 @@ namespace DisplayMagician.UIForms
// Replace the old start programs with the ones we've created now
_startPrograms = newStartPrograms;
// Save the start program 1
/*StartProgram myStartProgram = new StartProgram
{
Priority = 1,
Enabled = cb_start_program1.Checked,
Executable = txt_start_program1.Text,
ExecutableArgumentsRequired = cb_start_program_pass_args1.Checked,
Arguments = txt_start_program_args1.Text,
CloseOnFinish = cb_start_program_close1.Checked,
DontStartIfAlreadyRunning = cb_dont_start_if_running1.Checked
};
_startPrograms.Add(myStartProgram);
myStartProgram = new StartProgram
{
Priority = 2,
Executable = txt_start_program2.Text,
Enabled = cb_start_program2.Checked,
ExecutableArgumentsRequired = cb_start_program_pass_args2.Checked,
Arguments = txt_start_program_args2.Text,
CloseOnFinish = cb_start_program_close2.Checked,
DontStartIfAlreadyRunning = cb_dont_start_if_running2.Checked
};
_startPrograms.Add(myStartProgram);
myStartProgram = new StartProgram
{
Priority = 3,
Executable = txt_start_program3.Text,
Enabled = cb_start_program3.Checked,
ExecutableArgumentsRequired = cb_start_program_pass_args3.Checked,
Arguments = txt_start_program_args3.Text,
CloseOnFinish = cb_start_program_close3.Checked,
DontStartIfAlreadyRunning = cb_dont_start_if_running3.Checked
};
_startPrograms.Add(myStartProgram);
myStartProgram = new StartProgram
{
Priority = 4,
Executable = txt_start_program4.Text,
Enabled = cb_start_program4.Checked,
ExecutableArgumentsRequired = cb_start_program_pass_args4.Checked,
Arguments = txt_start_program_args4.Text,
CloseOnFinish = cb_start_program_close4.Checked,
DontStartIfAlreadyRunning = cb_dont_start_if_running4.Checked
};
_startPrograms.Add(myStartProgram); */
// Now we create the Shortcut Object ready to save
// If we're launching a game
if (rb_launcher.Checked)
@ -731,21 +683,26 @@ namespace DisplayMagician.UIForms
IEnumerable<ImageListViewItem> matchingImageListViewItems = (from item in ilv_saved_profiles.Items where item.Text == profile.Name select item);
if (matchingImageListViewItems.Any())
{
matchingImageListViewItems.First().Selected = true;
matchingImageListViewItems.First().Focused = true;
matchingImageListViewItems.First().Enabled = true;
ImageListViewItem itemToSelect = matchingImageListViewItems.First();
itemToSelect.Selected = true;
itemToSelect.Focused = true;
itemToSelect.Enabled = true;
ilv_saved_profiles.EnsureVisible(itemToSelect.Index);
}
}
private void RefreshGameImageListView(Game game)
private void SelectGameInImageListView()
{
ilv_games.ClearSelection();
IEnumerable<ImageListViewItem> matchingImageListViewItems = (from item in ilv_games.Items where item.Text == game.Name select item);
IEnumerable<ImageListViewItem> matchingImageListViewItems = (from item in ilv_games.Items where item.Text == _shortcutToEdit.GameName select item);
if (matchingImageListViewItems.Any())
{
matchingImageListViewItems.First().Selected = true;
matchingImageListViewItems.First().Focused = true;
matchingImageListViewItems.First().Enabled = true;
ImageListViewItem itemToSelect = matchingImageListViewItems.First();
itemToSelect.Selected = true;
itemToSelect.Focused = true;
itemToSelect.Enabled = true;
ilv_games.EnsureVisible(itemToSelect.Index);
ilv_games.Refresh();
}
}
@ -965,17 +922,6 @@ namespace DisplayMagician.UIForms
rb_set_capture_volume.Checked = false;
}
// Populate a full list of games
// Start with the Steam Games
/*allGames = new List<Game>();
allGames.AddRange(SteamLibrary.GetLibrary().AllInstalledGames);
// Then add the Uplay Games
allGames.AddRange(UplayLibrary.GetLibrary().AllInstalledGames);
// Then add the Origin Games
allGames.AddRange(OriginLibrary.GetLibrary().AllInstalledGames);*/
// Load all the Games into the Games ListView
foreach (var game in DisplayMagician.GameLibraries.GameLibrary.AllInstalledGamesInAllLibraries.OrderBy(game => game.Name))
{
@ -985,7 +931,8 @@ namespace DisplayMagician.UIForms
ilv_games.Items.Add(newItem, _gameAdaptor);
}
SelectGameInImageListView();
if (_shortcutToEdit != null)
{
if (ProfileRepository.ContainsProfile(_shortcutToEdit.ProfileUUID))
@ -1129,6 +1076,7 @@ namespace DisplayMagician.UIForms
if (gameItem.Text.Equals(_shortcutToEdit.GameName))
{
gameItem.Selected = true;
ilv_games.EnsureVisible(gameItem.Index);
break;
}
}
@ -1427,21 +1375,36 @@ namespace DisplayMagician.UIForms
ilv_saved_profiles.ResumeLayout();
}
if (DisplayMagician.GameLibraries.GameLibrary.AllInstalledGamesInAllLibraries.Count > 0)
/*if (DisplayMagician.GameLibraries.GameLibrary.AllInstalledGamesInAllLibraries.Count > 0)
{
// Temporarily stop updating the saved_profiles listview
ilv_games.SuspendLayout();
ImageListViewItem newItem = null;
ImageListViewItem ilvItem = null;
foreach (Game loadedGame in DisplayMagician.GameLibraries.GameLibrary.AllInstalledGamesInAllLibraries)
{
bool thisLoadedProfileIsAlreadyHere = (from item in ilv_games.Items where item.Text == loadedGame.Name orderby item.Text select item.Text).Any();
if (!thisLoadedProfileIsAlreadyHere)
{
newItem = new ImageListViewItem(loadedGame, loadedGame.Name);
ilvItem = new ImageListViewItem(loadedGame, loadedGame.Name);
//ilv_saved_profiles.Items.Add(newItem);
ilv_games.Items.Add(newItem, _gameAdaptor);
ilv_games.Items.Add(ilvItem, _gameAdaptor);
}
}
// If a game has been selected
if (!String.IsNullOrEmpty(_shortcutToEdit.GameName))
{
foreach (ImageListViewItem gameItem in ilv_games.Items)
{
if (gameItem.Text == _shortcutToEdit.GameName)
{
gameItem.Selected = true;
ilv_games.EnsureVisible(gameItem.Index);
}
}
}
@ -1449,7 +1412,7 @@ namespace DisplayMagician.UIForms
// Restart updating the saved_profiles listview
ilv_games.ResumeLayout();
}
*/
UpdateHotkeyLabel(_shortcutToEdit.Hotkey);
EnableSaveButtonIfValid();
}
@ -2235,5 +2198,17 @@ namespace DisplayMagician.UIForms
SuggestShortcutName();
EnableSaveButtonIfValid();
}
private void tabc_shortcut_VisibleChanged(object sender, EventArgs e)
{
if (tabc_shortcut.Visible == true)
SelectGameInImageListView();
}
/*private void ilv_games_VisibleChanged(object sender, EventArgs e)
{
if (ilv_games.SelectedItems.Count > 0)
ilv_games.EnsureVisible(ilv_games.SelectedItems[0].Index);
}*/
}
}

View File

@ -256,30 +256,33 @@ namespace DisplayMagician.UIForms
private void btn_edit_Click(object sender, EventArgs e)
{
int currentIlvIndex = ilv_saved_shortcuts.SelectedItems[0].Index;
string shortcutUUID = ilv_saved_shortcuts.Items[currentIlvIndex].EquipmentModel;
_selectedShortcut = GetShortcutFromUUID(shortcutUUID);
if (_selectedShortcut == null)
return;
this.Cursor = Cursors.WaitCursor;
// We need to stop ImageListView redrawing things before we're ready
// This stops an exception when ILV is just too keen!
var shortcutForm = new ShortcutForm(_selectedShortcut);
//ilv_saved_shortcuts.SuspendLayout();
shortcutForm.ShowDialog(this);
if (shortcutForm.DialogResult == DialogResult.OK)
if (ilv_saved_shortcuts.SelectedItems.Count > 0)
{
RefreshShortcutLibraryUI();
// As this is an edit, we need to manually force saving the shortcut library
ShortcutRepository.SaveShortcuts();
}
int currentIlvIndex = ilv_saved_shortcuts.SelectedItems[0].Index;
string shortcutUUID = ilv_saved_shortcuts.Items[currentIlvIndex].EquipmentModel;
_selectedShortcut = GetShortcutFromUUID(shortcutUUID);
this.Cursor = Cursors.Default;
if (_selectedShortcut == null)
return;
this.Cursor = Cursors.WaitCursor;
// We need to stop ImageListView redrawing things before we're ready
// This stops an exception when ILV is just too keen!
var shortcutForm = new ShortcutForm(_selectedShortcut);
//ilv_saved_shortcuts.SuspendLayout();
shortcutForm.ShowDialog(this);
if (shortcutForm.DialogResult == DialogResult.OK)
{
RefreshShortcutLibraryUI();
// As this is an edit, we need to manually force saving the shortcut library
ShortcutRepository.SaveShortcuts();
}
this.Cursor = Cursors.Default;
}
}
private void btn_delete_Click(object sender, EventArgs e)

View File

@ -125,7 +125,7 @@
<Version>2.1.0</Version>
</PackageReference>
<PackageReference Include="NLog">
<Version>4.7.9</Version>
<Version>4.7.10</Version>
</PackageReference>
<PackageReference Include="NvAPIWrapper.Net">
<Version>0.8.1.101</Version>