From 36c085d91894d19324169bb56a217e1df59ec533 Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Tue, 18 May 2021 21:24:36 +1200 Subject: [PATCH] Initially working iconextrator code This code now will cope with incorrectly formatted icons, and will simply ignore them and move on to the next one. This also fixes a game ILV adaptor error which was causing argumentnullexceptions --- DisplayMagician/DisplayMagician.csproj | 8 +- DisplayMagician/ImageUtils.cs | 257 ++-- DisplayMagician/ShortcutItem.cs | 1139 +---------------- DisplayMagician/UIForms/GameAdaptor.cs | 32 +- .../UIForms/ImageListViewRenderers.cs | 1 - DisplayMagician/UIForms/ProfileAdaptor.cs | 4 +- DisplayMagician/UIForms/ShortcutAdaptor.cs | 12 +- .../UIForms/ShortcutForm.Designer.cs | 2 +- DisplayMagician/UIForms/ShortcutForm.cs | 8 +- 9 files changed, 173 insertions(+), 1290 deletions(-) diff --git a/DisplayMagician/DisplayMagician.csproj b/DisplayMagician/DisplayMagician.csproj index c1eb41d..a454225 100644 --- a/DisplayMagician/DisplayMagician.csproj +++ b/DisplayMagician/DisplayMagician.csproj @@ -41,7 +41,7 @@ 4 false true - true + false AnyCPU @@ -280,9 +280,6 @@ 1.11.33 - - 1.0.2.1-beta - 0.73.0 @@ -319,6 +316,9 @@ 0.3.1.152 + + 1.0.3-rc + 1.3.0.13 diff --git a/DisplayMagician/ImageUtils.cs b/DisplayMagician/ImageUtils.cs index 16c7c82..71178cf 100644 --- a/DisplayMagician/ImageUtils.cs +++ b/DisplayMagician/ImageUtils.cs @@ -21,6 +21,11 @@ namespace DisplayMagician public static Image RoundCorners(Image StartImage, int CornerRadius) { + if (StartImage == null) + { + throw new ArgumentNullException("StartImage"); + } + CornerRadius *= 2; Bitmap RoundedImage = new Bitmap(StartImage.Width, StartImage.Height); using (Graphics g = Graphics.FromImage(RoundedImage)) @@ -98,6 +103,11 @@ namespace DisplayMagician public static Image MakeGrayscale(Image original) { + if (original == null) + { + throw new ArgumentNullException("original"); + } + //create a blank bitmap the same size as original Image newBitmap = new Bitmap(original.Width, original.Height); @@ -132,101 +142,6 @@ namespace DisplayMagician return newBitmap; } - /* 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)) @@ -238,15 +153,24 @@ namespace DisplayMagician Icon myIcon = null; Bitmap bm = null; Bitmap bmToReturn = new Bitmap(1, 1); - try - { + + try { List myExtractedIcons = MintPlayer.IconUtils.IconExtractor.Split(fileNameAndPath); + Size largeSize = new Size(256, 256); foreach (Icon myExtractedIcon in myExtractedIcons) { - Size largeSize = new Size(256, 256); - myIcon = myExtractedIcon.TryGetIcon(largeSize, 32, true, true); - + + try + { + myIcon = (Icon)IconUtil.TryGetIcon(myExtractedIcon, largeSize, 32, true, true); + } + catch (ArgumentNullException nullex) + { + logger.Debug(nullex, $"ShortcutItem/GetMeABitmapFromFile: There was a faulty icon image within this icon that we couldn't test, so skipping it."); + continue; + } + if (myIcon != null) { bm = myIcon.ToBitmap(); @@ -254,22 +178,25 @@ namespace DisplayMagician 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."); + logger.Trace($"ShortcutItem/GetMeABitmapFromFile: 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 Split the icon using MintPlayer IconExtractor! "); } + 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}."); + logger.Trace($"ShortcutItem/GetMeABitmapFromFile: 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); @@ -283,7 +210,7 @@ namespace DisplayMagician 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."); + logger.Trace($"ShortcutItem/GetMeABitmapFromFile: 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) @@ -305,7 +232,7 @@ namespace DisplayMagician 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."); + logger.Trace($"ShortcutItem/GetMeABitmapFromFile: This new bitmap from the icon file {fileNameAndPath} is larger than the previous one at {bm.Width} x {bm.Height}, so using that instead."); } } } @@ -316,6 +243,7 @@ namespace DisplayMagician } else { + try { List myIcons = ImageUtils.ExtractIconsFromExe(fileNameAndPath, true); @@ -328,7 +256,7 @@ namespace DisplayMagician 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."); + logger.Trace($"ShortcutItem/GetMeABitmapFromFile: This new bitmap from the icon file {fileNameAndPath} is larger than the previous one at {bm.Width} x {bm.Height}, so using that instead."); } } } @@ -349,7 +277,7 @@ namespace DisplayMagician 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."); + logger.Trace($"ShortcutItem/GetMeABitmapFromFile: This new bitmap from the icon file {fileNameAndPath} is larger than the previous one at {bm.Width} x {bm.Height}, so using that instead."); } } } @@ -386,7 +314,7 @@ namespace DisplayMagician if (fileNamesAndPaths.Count == 0) { - logger.Warn($"ShortcutItem/ToSmallBitmap2: The fileNamesAndPaths list is empty! Can't get the large bitmap."); + logger.Warn($"ShortcutItem/GetMeABitmapFromFile2: The fileNamesAndPaths list is empty! Can't get the bitmap from the files."); return null; } foreach (string fileNameAndPath in fileNamesAndPaths) @@ -540,80 +468,85 @@ namespace DisplayMagician } [DllImport("Shell32", CharSet = CharSet.Auto)] - private static unsafe extern int ExtractIconEx(string lpszFile, int nIconIndex, IntPtr[] phIconLarge, IntPtr[] phIconSmall, int nIcons); + private static 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); + private static extern int DestroyIcon(IntPtr hIcon); public static List ExtractIconsFromExe(string file, bool large) { - unsafe + int readIconCount = 0; + IntPtr[] hLargeIconEx = new IntPtr[] { IntPtr.Zero }; + IntPtr[] hSmallIconEx = new IntPtr[] { IntPtr.Zero }; + + try { - int readIconCount = 0; - IntPtr[] hLargeIconEx = new IntPtr[] { IntPtr.Zero }; - IntPtr[] hSmallIconEx = new IntPtr[] { IntPtr.Zero }; - - try + List extractedIcons = new List() { }; + // First we get the total number of icons using ExtractIconEx + int totalIconCount = ExtractIconEx(file, -1, null, null, 0); + if (totalIconCount > 0) { - List extractedIcons = new List() { }; - // 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++) { - 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) { - 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) { - 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; + 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); } } - 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) + /*foreach (IntPtr ptr in hLargeIconEx) if (ptr != IntPtr.Zero) DestroyIcon(ptr); foreach (IntPtr ptr in hSmallIconEx) if (ptr != IntPtr.Zero) - DestroyIcon(ptr); + DestroyIcon(ptr);*/ + + 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)] @@ -647,7 +580,7 @@ namespace DisplayMagician /// Size of the icon to load. If there is no such size available, a larger or smaller /// sized-icon is scaled. /// List of all icons. - public static Icon GetIconFromExe(string path = null, string resId = "#32512", int size = 32) + public static Icon GetIconFromExe(string path = null, int size = 256, string resId = "#32512") { // load module IntPtr h; diff --git a/DisplayMagician/ShortcutItem.cs b/DisplayMagician/ShortcutItem.cs index 5dd50b5..e8414cc 100644 --- a/DisplayMagician/ShortcutItem.cs +++ b/DisplayMagician/ShortcutItem.cs @@ -116,7 +116,7 @@ namespace DisplayMagician private ShortcutValidity _isValid; private List _shortcutErrors = new List(); private List _startPrograms; - private Bitmap _shortcutBitmap, _originalLargeBitmap; + private Bitmap _shortcutBitmap, _originalBitmap; [JsonIgnore] #pragma warning disable CS3008 // Identifier is not CLS-compliant public string _originalIconPath; @@ -154,584 +154,6 @@ namespace DisplayMagician } - - public ShortcutItem( - string name, -#pragma warning disable CS3001 // Argument type is not CLS-compliant - ProfileItem profile, -#pragma warning restore CS3001 // Argument type is not CLS-compliant - ShortcutPermanence displayPermanence, - ShortcutPermanence audioPermanence, - ShortcutPermanence capturePermanence, - string originalIconPath, - bool changeAudioDevice = false, - string audioDevice = "", - bool setAudioVolume = false, - decimal audioVolume = -1, - bool changeCaptureDevice = false, - string captureDevice = "", - bool setCaptureVolume = false, - decimal captureVolume = -1, - List startPrograms = null, - bool autoName = true, - string uuid = "", - Keys hotkey = Keys.None - ) : this() - { - if (!String.IsNullOrWhiteSpace(uuid)) - _uuid = uuid; - _name = name; - _category = ShortcutCategory.NoGame; - _profileToUse = profile; - _changeAudioDevice = changeAudioDevice; - _audioDevice = audioDevice; - _setAudioVolume = setAudioVolume; - _audioVolume = audioVolume; - _changeCaptureDevice = changeCaptureDevice; - _captureDevice = captureDevice; - _setCaptureVolume = setCaptureVolume; - _captureVolume = captureVolume; - _displayPermanence = displayPermanence; - _audioPermanence = audioPermanence; - _capturePermanence = capturePermanence; - _autoName = autoName; - _startPrograms = startPrograms; - _originalIconPath = originalIconPath; - _hotkey = hotkey; - - // Now we need to find and populate the profileUuid - _profileUuid = profile.UUID; - - // We create the OriginalLargeBitmap from the IconPath - //_originalLargeBitmap = ToLargeBitmap(_originalIconPath); - //_originalSmallBitmap = ToSmallBitmap(_originalIconPath); - _originalLargeBitmap = ImageUtils.GetMeABitmapFromFile(_originalIconPath); - - // We create the ShortcutBitmap from the OriginalBitmap - // (We only do it if there is a valid profile) - if (_profileToUse is ProfileItem) - _shortcutBitmap = ToBitmapOverlay(_originalLargeBitmap, _profileToUse.ProfileTightestBitmap, 256, 256); - - RefreshValidity(); - } - - public ShortcutItem( - string name, - string profileUuid, - ShortcutPermanence displayPermanence, - ShortcutPermanence audioPermanence, - ShortcutPermanence capturePermanence, - string originalIconPath, - bool changeAudioDevice = false, - string audioDevice = "", - bool setAudioVolume = false, - decimal audioVolume = -1, - bool changeCaptureDevice = false, - string captureDevice = "", - bool setCaptureVolume = false, - decimal captureVolume = -1, - List startPrograms = null, - bool autoName = true, - string uuid = "", - Keys hotkey = Keys.None - ) : this() - { - if (!String.IsNullOrWhiteSpace(uuid)) - _uuid = uuid; - _name = name; - _profileUuid = profileUuid; - _category = ShortcutCategory.NoGame; - _changeAudioDevice = changeAudioDevice; - _audioDevice = audioDevice; - _setAudioVolume = setAudioVolume; - _audioVolume = audioVolume; - _changeCaptureDevice = changeCaptureDevice; - _captureDevice = captureDevice; - _setCaptureVolume = setCaptureVolume; - _captureVolume = captureVolume; - _displayPermanence = displayPermanence; - _audioPermanence = audioPermanence; - _capturePermanence = capturePermanence; - _autoName = autoName; - _startPrograms = startPrograms; - _originalIconPath = originalIconPath; - _hotkey = hotkey; - - // Now we need to find and populate the profileToUse - foreach (ProfileItem profileToTest in ProfileRepository.AllProfiles) - { - if (profileToTest.UUID.Equals(_profileUuid, StringComparison.OrdinalIgnoreCase)) - { - _profileToUse = profileToTest; - break; - } - - } - - if (_profileToUse == null) - { - throw new Exception($"Trying to create a ShortcutItem and cannot find a loaded profile with UUID {uuid}."); - } - - // We create the OriginalBitmap from the IconPath - //_originalLargeBitmap = ToLargeBitmap(_originalIconPath); - _originalLargeBitmap = ImageUtils.GetMeABitmapFromFile(_originalIconPath); - - // We create the ShortcutBitmap from the OriginalBitmap - // (We only do it if there is a valid profile) - if (_profileToUse is ProfileItem) - _shortcutBitmap = ToBitmapOverlay(_originalLargeBitmap, _profileToUse.ProfileTightestBitmap, 256, 256); - - RefreshValidity(); - } - - - - public ShortcutItem( - string name, -#pragma warning disable CS3001 // Argument type is not CLS-compliant - ProfileItem profile, -#pragma warning restore CS3001 // Argument type is not CLS-compliant - string gameAppId, - string gameName, - SupportedGameLibraryType gameLibrary, - int gameTimeout, - string gameArguments, - bool gameArgumentsRequired, - string differentGameExeToMonitor, - bool monitorDifferentGameExe, - ShortcutPermanence displayPermanence, - ShortcutPermanence audioPermanence, - ShortcutPermanence capturePermanence, - string originalIconPath, - bool changeAudioDevice = false, - string audioDevice = "", - bool setAudioVolume = false, - decimal audioVolume = -1, - bool changeCaptureDevice = false, - string captureDevice = "", - bool setCaptureVolume = false, - decimal captureVolume = -1, - List startPrograms = null, - bool autoName = true, - string uuid = "", - Keys hotkey = Keys.None - ) : this() - { - if (!String.IsNullOrWhiteSpace(uuid)) - _uuid = uuid; - _name = name; - _profileToUse = profile; - _category = ShortcutCategory.Game; - _gameAppId = gameAppId; - _gameName = gameName; - _gameLibrary = gameLibrary; - _startTimeout = gameTimeout; - _gameArguments = gameArguments; - _gameArgumentsRequired = gameArgumentsRequired; - _differentGameExeToMonitor = differentGameExeToMonitor; - _monitorDifferentGameExe = monitorDifferentGameExe; - _changeAudioDevice = changeAudioDevice; - _audioDevice = audioDevice; - _setAudioVolume = setAudioVolume; - _audioVolume = audioVolume; - _changeCaptureDevice = changeCaptureDevice; - _captureDevice = captureDevice; - _setCaptureVolume = setCaptureVolume; - _captureVolume = captureVolume; - _displayPermanence = displayPermanence; - _audioPermanence = audioPermanence; - _capturePermanence = capturePermanence; - _autoName = autoName; - _startPrograms = startPrograms; - _originalIconPath = originalIconPath; - _hotkey = hotkey; - - // Now we need to find and populate the profileUuid - _profileUuid = profile.UUID; - - // We create the OriginalLargeBitmap from the IconPath - //_originalLargeBitmap = ToLargeBitmap(_originalIconPath); - //_originalSmallBitmap = ToSmallBitmap(_originalIconPath); - _originalLargeBitmap = ImageUtils.GetMeABitmapFromFile(_originalIconPath); - - // We create the ShortcutBitmap from the OriginalBitmap - // (We only do it if there is a valid profile) - if (_profileToUse is ProfileItem) - _shortcutBitmap = ToBitmapOverlay(_originalLargeBitmap, _profileToUse.ProfileTightestBitmap, 256, 256); - - RefreshValidity(); - } - - public ShortcutItem( - string name, -#pragma warning disable CS3001 // Argument type is not CLS-compliant - ProfileItem profile, -#pragma warning restore CS3001 // Argument type is not CLS-compliant - GameStruct game, - ShortcutPermanence displayPermanence, - ShortcutPermanence audioPermanence, - ShortcutPermanence capturePermanence, - string originalIconPath, - bool changeAudioDevice = false, - string audioDevice = "", - bool setAudioVolume = false, - decimal audioVolume = -1, - bool changeCaptureDevice = false, - string captureDevice = "", - bool setCaptureVolume = false, - decimal captureVolume = -1, - List startPrograms = null, - bool autoName = true, - string uuid = "", - Keys hotkey = Keys.None - ) : this() - { - // Create a new UUID for the shortcut if one wasn't created already - if (!String.IsNullOrWhiteSpace(uuid)) - _uuid = uuid; - _name = name; - _profileToUse = profile; - _category = ShortcutCategory.Game; - _gameAppId = game.GameToPlay.Id; - _gameName = game.GameToPlay.Name; - _gameLibrary = game.GameToPlay.GameLibrary; - _startTimeout = game.StartTimeout; - _gameArguments = game.GameArguments; - _gameArgumentsRequired = game.GameArgumentsRequired; - _differentGameExeToMonitor = game.DifferentGameExeToMonitor; - _monitorDifferentGameExe = game.MonitorDifferentGameExe; - _changeAudioDevice = changeAudioDevice; - _audioDevice = audioDevice; - _setAudioVolume = setAudioVolume; - _audioVolume = audioVolume; - _changeCaptureDevice = changeCaptureDevice; - _captureDevice = captureDevice; - _setCaptureVolume = setCaptureVolume; - _captureVolume = captureVolume; - _displayPermanence = displayPermanence; - _audioPermanence = audioPermanence; - _capturePermanence = capturePermanence; - _autoName = autoName; - _startPrograms = startPrograms; - _originalIconPath = originalIconPath; - _hotkey = hotkey; - - // Now we need to find and populate the profileUuid - _profileUuid = profile.UUID; - - // We create the OriginalBitmap from the IconPath - //_originalLargeBitmap = ToLargeBitmap(_originalIconPath); - _originalLargeBitmap = ImageUtils.GetMeABitmapFromFile(_originalIconPath); - - // We create the ShortcutBitmap from the OriginalBitmap - // (We only do it if there is a valid profile) - if (_profileToUse is ProfileItem) - _shortcutBitmap = ToBitmapOverlay(_originalLargeBitmap, _profileToUse.ProfileTightestBitmap, 256, 256); - - RefreshValidity(); - } - - - - public ShortcutItem( - string name, - string profileUuid, - GameStruct game, - ShortcutPermanence displayPermanence, - ShortcutPermanence audioPermanence, - ShortcutPermanence capturePermanence, - string originalIconPath, - bool changeAudioDevice = false, - string audioDevice = "", - bool setAudioVolume = false, - decimal audioVolume = -1, - bool changeCaptureDevice = false, - string captureDevice = "", - bool setCaptureVolume = false, - decimal captureVolume = -1, - List startPrograms = null, - bool autoName = true, - string uuid = "", - Keys hotkey = Keys.None - ) : this() - { - if (!String.IsNullOrWhiteSpace(uuid)) - _uuid = uuid; - _name = name; - _profileUuid = profileUuid; - _category = ShortcutCategory.Game; - _gameAppId = game.GameToPlay.Id; - _gameName = game.GameToPlay.Name; - _gameLibrary = game.GameToPlay.GameLibrary; - _startTimeout = game.StartTimeout; - _gameArguments = game.GameArguments; - _gameArgumentsRequired = game.GameArgumentsRequired; - _differentGameExeToMonitor = game.DifferentGameExeToMonitor; - _monitorDifferentGameExe = game.MonitorDifferentGameExe; - _gameArgumentsRequired = false; - _changeAudioDevice = changeAudioDevice; - _audioDevice = audioDevice; - _setAudioVolume = setAudioVolume; - _audioVolume = audioVolume; - _changeCaptureDevice = changeCaptureDevice; - _captureDevice = captureDevice; - _setCaptureVolume = setCaptureVolume; - _captureVolume = captureVolume; - _displayPermanence = displayPermanence; - _audioPermanence = audioPermanence; - _capturePermanence = capturePermanence; - _autoName = autoName; - _startPrograms = startPrograms; - _originalIconPath = originalIconPath; - _hotkey = hotkey; - - // Now we need to find and populate the profileToUse - foreach (ProfileItem profileToTest in ProfileRepository.AllProfiles) - { - if (profileToTest.UUID.Equals(_profileUuid,StringComparison.OrdinalIgnoreCase)) - { - _profileToUse = profileToTest; - break; - } - - } - - if (_profileToUse == null) - { - throw new Exception($"Trying to create a ShortcutItem and cannot find a loaded profile with UUID {uuid}."); - } - - // We create the OriginalBitmap from the IconPath - //_originalLargeBitmap = ToLargeBitmap(_originalIconPath); - _originalLargeBitmap = ImageUtils.GetMeABitmapFromFile(_originalIconPath); - - // We create the ShortcutBitmap from the OriginalBitmap - // (We only do it if there is a valid profile) - if (_profileToUse is ProfileItem) - _shortcutBitmap = ToBitmapOverlay(_originalLargeBitmap, _profileToUse.ProfileTightestBitmap, 256, 256); - - RefreshValidity(); - } - - public ShortcutItem( - string name, -#pragma warning disable CS3001 // Argument type is not CLS-compliant - ProfileItem profile, -#pragma warning restore CS3001 // Argument type is not CLS-compliant - string differentExecutableToMonitor, - string executableNameAndPath, - int executableTimeout, - string executableArguments, - bool executableArgumentsRequired, - bool processNameToMonitorUsesExecutable, - ShortcutPermanence displayPermanence, - ShortcutPermanence audioPermanence, - ShortcutPermanence capturePermanence, - string originalIconPath, - bool changeAudioDevice = false, - string audioDevice = "", - bool setAudioVolume = false, - decimal audioVolume = -1, - bool changeCaptureDevice = false, - string captureDevice = "", - bool setCaptureVolume = false, - decimal captureVolume = -1, - List startPrograms = null, - bool autoName = true, - string uuid = "", - Keys hotkey = Keys.None - ) : this() - { - if (!String.IsNullOrWhiteSpace(uuid)) - _uuid = uuid; - _name = name; - _profileToUse = profile; - _category = ShortcutCategory.Application; - _differentExecutableToMonitor = differentExecutableToMonitor; - _executableNameAndPath = executableNameAndPath; - _startTimeout = executableTimeout; - _executableArguments = executableArguments; - _executableArgumentsRequired = executableArgumentsRequired; - _processNameToMonitorUsesExecutable = processNameToMonitorUsesExecutable; - _changeAudioDevice = changeAudioDevice; - _audioDevice = audioDevice; - _setAudioVolume = setAudioVolume; - _audioVolume = audioVolume; - _changeCaptureDevice = changeCaptureDevice; - _captureDevice = captureDevice; - _setCaptureVolume = setCaptureVolume; - _captureVolume = captureVolume; - _displayPermanence = displayPermanence; - _audioPermanence = audioPermanence; - _capturePermanence = capturePermanence; - _autoName = autoName; - _startPrograms = startPrograms; - _originalIconPath = originalIconPath; - _hotkey = hotkey; - - // Now we need to find and populate the profileUuid - _profileUuid = profile.UUID; - - // We create the OriginalBitmap from the IconPath - //_originalLargeBitmap = ToLargeBitmap(_originalIconPath); - _originalLargeBitmap = ImageUtils.GetMeABitmapFromFile(_originalIconPath); - - // We create the ShortcutBitmap from the OriginalBitmap - // (We only do it if there is a valid profile) - //if (_profileToUse is ProfileItem) - // _shortcutBitmap = ToBitmapOverlay(_originalLargeBitmap, _profileToUse.ProfileTightestBitmap, 256, 256); - _shortcutBitmap = ToBitmapOverlay(_originalLargeBitmap, _profileToUse.ProfileTightestBitmap, 256, 256); - - RefreshValidity(); - } - - public ShortcutItem( - string name, -#pragma warning disable CS3001 // Argument type is not CLS-compliant - ProfileItem profile, -#pragma warning restore CS3001 // Argument type is not CLS-compliant - Executable executable, - ShortcutPermanence displayPermanence, - ShortcutPermanence audioPermanence, - ShortcutPermanence capturePermanence, - string originalIconPath, - bool changeAudioDevice = false, - string audioDevice = "", - bool setAudioVolume = false, - decimal audioVolume = -1, - bool changeCaptureDevice = false, - string captureDevice = "", - bool setCaptureVolume = false, - decimal captureVolume = -1, - List startPrograms = null, - bool autoName = true, - string uuid = "", - Keys hotkey = Keys.None - ) : this() - { - if (!String.IsNullOrWhiteSpace(uuid)) - _uuid = uuid; - _name = name; - _profileToUse = profile; - _category = ShortcutCategory.Application; - _differentExecutableToMonitor = executable.DifferentExecutableToMonitor; - _executableNameAndPath = executable.ExecutableNameAndPath; - _startTimeout = executable.ExecutableTimeout; - _executableArguments = executable.ExecutableArguments; - _executableArgumentsRequired = executable.ExecutableArgumentsRequired; - _processNameToMonitorUsesExecutable = executable.ProcessNameToMonitorUsesExecutable; - _changeAudioDevice = changeAudioDevice; - _audioDevice = audioDevice; - _setAudioVolume = setAudioVolume; - _audioVolume = audioVolume; - _changeCaptureDevice = changeCaptureDevice; - _captureDevice = captureDevice; - _setCaptureVolume = setCaptureVolume; - _captureVolume = captureVolume; - _displayPermanence = displayPermanence; - _audioPermanence = audioPermanence; - _capturePermanence = capturePermanence; - _autoName = autoName; - _startPrograms = startPrograms; - _originalIconPath = originalIconPath; - _hotkey = hotkey; - - // Now we need to find and populate the profileUuid - _profileUuid = profile.UUID; - - // We create the OriginalBitmap from the IconPath - //_originalLargeBitmap = ToLargeBitmap(_originalIconPath); - _originalLargeBitmap = ImageUtils.GetMeABitmapFromFile(_originalIconPath); - - // We create the ShortcutBitmap from the OriginalBitmap - // (We only do it if there is a valid profile) - //if (_profileToUse is ProfileItem) - // _shortcutBitmap = ToBitmapOverlay(_originalLargeBitmap, _profileToUse.ProfileTightestBitmap, 256, 256); - _shortcutBitmap = ToBitmapOverlay(_originalLargeBitmap, _profileToUse.ProfileTightestBitmap, 256, 256); - - RefreshValidity(); - } - - public ShortcutItem( - string name, - string profileUuid, - Executable executable, - ShortcutPermanence displayPermanence, - ShortcutPermanence audioPermanence, - ShortcutPermanence capturePermanence, - string originalIconPath, - bool changeAudioDevice = false, - string audioDevice = "", - bool setAudioVolume = false, - decimal audioVolume = -1, - bool changeCaptureDevice = false, - string captureDevice = "", - bool setCaptureVolume = false, - decimal captureVolume = -1, - List startPrograms = null, - bool autoName = true, - string uuid = "", - Keys hotkey = Keys.None - ) : this() - { - if (!String.IsNullOrWhiteSpace(uuid)) - _uuid = uuid; - _name = name; - _profileUuid = profileUuid; - _category = ShortcutCategory.Application; - _differentExecutableToMonitor = executable.DifferentExecutableToMonitor; - _executableNameAndPath = executable.ExecutableNameAndPath; - _startTimeout = executable.ExecutableTimeout; - _executableArguments = executable.ExecutableArguments; - _executableArgumentsRequired = executable.ExecutableArgumentsRequired; - _processNameToMonitorUsesExecutable = executable.ProcessNameToMonitorUsesExecutable; - _changeAudioDevice = changeAudioDevice; - _audioDevice = audioDevice; - _setAudioVolume = setAudioVolume; - _audioVolume = audioVolume; - _changeCaptureDevice = changeCaptureDevice; - _captureDevice = captureDevice; - _setCaptureVolume = setCaptureVolume; - _captureVolume = captureVolume; - _displayPermanence = displayPermanence; - _audioPermanence = audioPermanence; - _capturePermanence = capturePermanence; - _autoName = autoName; - _startPrograms = startPrograms; - _originalIconPath = originalIconPath; - _hotkey = hotkey; - - // Now we need to find and populate the profileToUse - foreach (ProfileItem profileToTest in ProfileRepository.AllProfiles) - { - if (profileToTest.UUID.Equals(_profileUuid, StringComparison.OrdinalIgnoreCase)) - { - _profileToUse = profileToTest; - break; - } - - } - - if (_profileToUse == null) - { - throw new Exception($"Trying to create a ShortcutItem and cannot find a loaded profile with UUID {uuid}."); - } - - // We create the OriginalBitmap from the IconPath - //_originalLargeBitmap = ToLargeBitmap(_originalIconPath); - _originalLargeBitmap = ImageUtils.GetMeABitmapFromFile(_originalIconPath); - - // We create the ShortcutBitmap from the OriginalBitmap - // (We only do it if there is a valid profile) - //if (_profileToUse is ProfileItem) - // _shortcutBitmap = ToBitmapOverlay(_originalLargeBitmap, _profileToUse.ProfileTightestBitmap, 256, 256); - _shortcutBitmap = ToBitmapOverlay(_originalLargeBitmap, _profileToUse.ProfileTightestBitmap, 256, 256); - - RefreshValidity(); - } - - public static Version Version { get => new Version(1, 0); @@ -1197,12 +619,12 @@ namespace DisplayMagician { get { - return _originalLargeBitmap; + return _originalBitmap; } set { - _originalLargeBitmap = value; + _originalBitmap = value; // And we do the same for the Bitmap overlay, but only if the ProfileToUse is set //if (_profileToUse is ProfileItem) @@ -1311,164 +733,12 @@ namespace DisplayMagician // Now we need to find and populate the profileUuid _profileUuid = profile.UUID; - // We create the OriginalLargeBitmap from the IconPath - //_originalLargeBitmap = ToLargeBitmap(_originalIconPath); - _originalLargeBitmap = ImageUtils.GetMeABitmapFromFile(_originalIconPath); + _originalBitmap = profile.ProfileBitmap; // We create the ShortcutBitmap from the OriginalBitmap // (We only do it if there is a valid profile) - if (_profileToUse is ProfileItem) - _shortcutBitmap = ToBitmapOverlay(_originalLargeBitmap, _profileToUse.ProfileTightestBitmap, 256, 256); - - ReplaceShortcutIconInCache(); - RefreshValidity(); - } - - public void UpdateNoGameShortcut( - string name, - string profileUuid, - ShortcutPermanence displayPermanence, - ShortcutPermanence audioPermanence, - ShortcutPermanence capturePermanence, - string originalIconPath, - bool changeAudioDevice = false, - string audioDevice = "", - bool setAudioVolume = false, - decimal audioVolume = -1, - bool changeCaptureDevice = false, - string captureDevice = "", - bool setCaptureVolume = false, - decimal captureVolume = -1, - List startPrograms = null, - bool autoName = true, - string uuid = "", - Keys hotkey = Keys.None - ) - { - if (!String.IsNullOrWhiteSpace(uuid)) - _uuid = uuid; - _name = name; - _profileUuid = profileUuid; - _category = ShortcutCategory.NoGame; - _changeAudioDevice = changeAudioDevice; - _audioDevice = audioDevice; - _setAudioVolume = setAudioVolume; - _audioVolume = audioVolume; - _changeCaptureDevice = changeCaptureDevice; - _captureDevice = captureDevice; - _setCaptureVolume = setCaptureVolume; - _captureVolume = captureVolume; - _displayPermanence = displayPermanence; - _audioPermanence = audioPermanence; - _capturePermanence = capturePermanence; - _autoName = autoName; - _startPrograms = startPrograms; - _originalIconPath = originalIconPath; - _hotkey = hotkey; - - // Now we need to find and populate the profileToUse - foreach (ProfileItem profileToTest in ProfileRepository.AllProfiles) - { - if (profileToTest.UUID.Equals(_profileUuid, StringComparison.OrdinalIgnoreCase)) - { - _profileToUse = profileToTest; - break; - } - - } - - if (_profileToUse == null) - { - throw new Exception($"Trying to create a ShortcutItem and cannot find a loaded profile with UUID {uuid}."); - } - - // We create the OriginalBitmap from the IconPath - //_originalLargeBitmap = ToLargeBitmap(_originalIconPath); - _originalLargeBitmap = ImageUtils.GetMeABitmapFromFile(_originalIconPath); - - // We create the ShortcutBitmap from the OriginalBitmap - // (We only do it if there is a valid profile) - if (_profileToUse is ProfileItem) - _shortcutBitmap = ToBitmapOverlay(_originalLargeBitmap, _profileToUse.ProfileTightestBitmap, 256, 256); - - ReplaceShortcutIconInCache(); - RefreshValidity(); - } - - - - public void UpdateGameShortcut( - string name, -#pragma warning disable CS3001 // Argument type is not CLS-compliant - ProfileItem profile, -#pragma warning restore CS3001 // Argument type is not CLS-compliant - string gameAppId, - string gameName, - SupportedGameLibraryType gameLibrary, - int gameTimeout, - string gameArguments, - bool gameArgumentsRequired, - string differentGameExeToMonitor, - bool monitorDifferentGameExe, - ShortcutPermanence displayPermanence, - ShortcutPermanence audioPermanence, - ShortcutPermanence capturePermanence, - string originalIconPath, - bool changeAudioDevice = false, - string audioDevice = "", - bool setAudioVolume = false, - decimal audioVolume = -1, - bool changeCaptureDevice = false, - string captureDevice = "", - bool setCaptureVolume = false, - decimal captureVolume = -1, - List startPrograms = null, - bool autoName = true, - string uuid = "", - Keys hotkey = Keys.None - ) - { - if (!String.IsNullOrWhiteSpace(uuid)) - _uuid = uuid; - _name = name; - _profileToUse = profile; - _category = ShortcutCategory.Game; - _gameAppId = gameAppId; - _gameName = gameName; - _gameLibrary = gameLibrary; - _startTimeout = gameTimeout; - _gameArguments = gameArguments; - _gameArgumentsRequired = gameArgumentsRequired; - _differentGameExeToMonitor = differentGameExeToMonitor; - _monitorDifferentGameExe = monitorDifferentGameExe; - _changeAudioDevice = changeAudioDevice; - _audioDevice = audioDevice; - _setAudioVolume = setAudioVolume; - _audioVolume = audioVolume; - _changeCaptureDevice = changeCaptureDevice; - _captureDevice = captureDevice; - _setCaptureVolume = setCaptureVolume; - _captureVolume = captureVolume; - _displayPermanence = displayPermanence; - _audioPermanence = audioPermanence; - _capturePermanence = capturePermanence; - _autoName = autoName; - _startPrograms = startPrograms; - _originalIconPath = originalIconPath; - _hotkey = hotkey; - - // Now we need to find and populate the profileUuid - _profileUuid = profile.UUID; - - // We create the OriginalLargeBitmap from the IconPath - //_originalLargeBitmap = ToLargeBitmap(_originalIconPath); - //_originalSmallBitmap = ToSmallBitmap(_originalIconPath); - _originalLargeBitmap = ImageUtils.GetMeABitmapFromFile(_originalIconPath); - - // We create the ShortcutBitmap from the OriginalBitmap - // (We only do it if there is a valid profile) - if (_profileToUse is ProfileItem) - _shortcutBitmap = ToBitmapOverlay(_originalLargeBitmap, _profileToUse.ProfileTightestBitmap, 256, 256); + //if (_profileToUse is ProfileItem) + // _shortcutBitmap = ToBitmapOverlay(_originalBitmap, _profileToUse.ProfileTightestBitmap, 256, 256); ReplaceShortcutIconInCache(); RefreshValidity(); @@ -1531,169 +801,20 @@ namespace DisplayMagician // Now we need to find and populate the profileUuid _profileUuid = profile.UUID; - // We create the OriginalBitmap from the IconPath - //_originalLargeBitmap = ToLargeBitmap(_originalIconPath); - _originalLargeBitmap = ImageUtils.GetMeABitmapFromFile(_originalIconPath); - - // We create the ShortcutBitmap from the OriginalBitmap - // (We only do it if there is a valid profile) - if (_profileToUse is ProfileItem) - _shortcutBitmap = ToBitmapOverlay(_originalLargeBitmap, _profileToUse.ProfileTightestBitmap, 256, 256); - - ReplaceShortcutIconInCache(); - RefreshValidity(); - } - - - - public void UpdateGameShortcut( - string name, - string profileUuid, - GameStruct game, - ShortcutPermanence displayPermanence, - ShortcutPermanence audioPermanence, - ShortcutPermanence capturePermanence, - string originalIconPath, - bool changeAudioDevice = false, - string audioDevice = "", - bool setAudioVolume = false, - decimal audioVolume = -1, - bool changeCaptureDevice = false, - string captureDevice = "", - bool setCaptureVolume = false, - decimal captureVolume = -1, - List startPrograms = null, - bool autoName = true, - string uuid = "", - Keys hotkey = Keys.None - ) - { - if (!String.IsNullOrWhiteSpace(uuid)) - _uuid = uuid; - _name = name; - _profileUuid = profileUuid; - _category = ShortcutCategory.Game; - _gameAppId = game.GameToPlay.Id; - _gameName = game.GameToPlay.Name; - _gameLibrary = game.GameToPlay.GameLibrary; - _startTimeout = game.StartTimeout; - _gameArguments = game.GameArguments; - _gameArgumentsRequired = game.GameArgumentsRequired; - _differentGameExeToMonitor = game.DifferentGameExeToMonitor; - _monitorDifferentGameExe = game.MonitorDifferentGameExe; - _changeAudioDevice = changeAudioDevice; - _audioDevice = audioDevice; - _setAudioVolume = setAudioVolume; - _audioVolume = audioVolume; - _changeCaptureDevice = changeCaptureDevice; - _captureDevice = captureDevice; - _setCaptureVolume = setCaptureVolume; - _captureVolume = captureVolume; - _displayPermanence = displayPermanence; - _audioPermanence = audioPermanence; - _capturePermanence = capturePermanence; - _autoName = autoName; - _startPrograms = startPrograms; - _originalIconPath = originalIconPath; - _hotkey = hotkey; - - // Now we need to find and populate the profileToUse - foreach (ProfileItem profileToTest in ProfileRepository.AllProfiles) + // We create the OriginalBitmap + // Find the game bitmap that matches the game name we just got + foreach (var aGame in DisplayMagician.GameLibraries.GameLibrary.AllInstalledGamesInAllLibraries) { - if (profileToTest.UUID.Equals(_profileUuid, StringComparison.OrdinalIgnoreCase)) + if (aGame.Name.Equals(_gameName)) { - _profileToUse = profileToTest; - break; - } - + _originalBitmap = aGame.GameBitmap; + } } - - if (_profileToUse == null) - { - throw new Exception($"Trying to create a ShortcutItem and cannot find a loaded profile with UUID {uuid}."); - } - - // We create the OriginalBitmap from the IconPath - //_originalLargeBitmap = ToLargeBitmap(_originalIconPath); - _originalLargeBitmap = ImageUtils.GetMeABitmapFromFile(_originalIconPath); - + // We create the ShortcutBitmap from the OriginalBitmap // (We only do it if there is a valid profile) if (_profileToUse is ProfileItem) - _shortcutBitmap = ToBitmapOverlay(_originalLargeBitmap, _profileToUse.ProfileTightestBitmap, 256, 256); - - ReplaceShortcutIconInCache(); - RefreshValidity(); - } - - public void UpdateExecutableShortcut( - string name, -#pragma warning disable CS3001 // Argument type is not CLS-compliant - ProfileItem profile, -#pragma warning restore CS3001 // Argument type is not CLS-compliant - string differentExecutableToMonitor, - string executableNameAndPath, - int executableTimeout, - string executableArguments, - bool executableArgumentsRequired, - bool processNameToMonitorUsesExecutable, - ShortcutPermanence displayPermanence, - ShortcutPermanence audioPermanence, - ShortcutPermanence capturePermanence, - string originalIconPath, - bool changeAudioDevice = false, - string audioDevice = "", - bool setAudioVolume = false, - decimal audioVolume = -1, - bool changeCaptureDevice = false, - string captureDevice = "", - bool setCaptureVolume = false, - decimal captureVolume = -1, - List startPrograms = null, - bool autoName = true, - Keys hotkey = Keys.None, - string uuid = "" - ) - { - if (!String.IsNullOrWhiteSpace(uuid)) - _uuid = uuid; - _name = name; - _profileToUse = profile; - _category = ShortcutCategory.Application; - _differentExecutableToMonitor = differentExecutableToMonitor; - _executableNameAndPath = executableNameAndPath; - _startTimeout = executableTimeout; - _executableArguments = executableArguments; - _executableArgumentsRequired = executableArgumentsRequired; - _processNameToMonitorUsesExecutable = processNameToMonitorUsesExecutable; - _changeAudioDevice = changeAudioDevice; - _audioDevice = audioDevice; - _setAudioVolume = setAudioVolume; - _audioVolume = audioVolume; - _changeCaptureDevice = changeCaptureDevice; - _captureDevice = captureDevice; - _setCaptureVolume = setCaptureVolume; - _captureVolume = captureVolume; - _displayPermanence = displayPermanence; - _audioPermanence = audioPermanence; - _capturePermanence = capturePermanence; - _autoName = autoName; - _startPrograms = startPrograms; - _originalIconPath = originalIconPath; - _hotkey = hotkey; - - // Now we need to find and populate the profileUuid - _profileUuid = profile.UUID; - - // We create the OriginalBitmap from the IconPath - //_originalLargeBitmap = ToLargeBitmap(_originalIconPath); - _originalLargeBitmap = ImageUtils.GetMeABitmapFromFile(_originalIconPath); - - // We create the ShortcutBitmap from the OriginalBitmap - // (We only do it if there is a valid profile) - //if (_profileToUse is ProfileItem) - // _shortcutBitmap = ToBitmapOverlay(_originalLargeBitmap, _profileToUse.ProfileTightestBitmap, 256, 256); - _shortcutBitmap = ToBitmapOverlay(_originalLargeBitmap, _profileToUse.ProfileTightestBitmap, 256, 256); + _shortcutBitmap = ToBitmapOverlay(_originalBitmap, _profileToUse.ProfileTightestBitmap, 256, 256); ReplaceShortcutIconInCache(); RefreshValidity(); @@ -1754,109 +875,20 @@ namespace DisplayMagician _profileUuid = profile.UUID; // We create the OriginalBitmap from the IconPath - //_originalLargeBitmap = ToLargeBitmap(_originalIconPath); - _originalLargeBitmap = ImageUtils.GetMeABitmapFromFile(_originalIconPath); + //_originalLargeBitmap = ToLargeBitmap(_originalIconPath); + // We create the OriginalBitmap + _originalBitmap = ImageUtils.GetMeABitmapFromFile(_originalIconPath); // We create the ShortcutBitmap from the OriginalBitmap // (We only do it if there is a valid profile) //if (_profileToUse is ProfileItem) // _shortcutBitmap = ToBitmapOverlay(_originalLargeBitmap, _profileToUse.ProfileTightestBitmap, 256, 256); - _shortcutBitmap = ToBitmapOverlay(_originalLargeBitmap, _profileToUse.ProfileTightestBitmap, 256, 256); + _shortcutBitmap = ToBitmapOverlay(_originalBitmap, _profileToUse.ProfileTightestBitmap, 256, 256); ReplaceShortcutIconInCache(); RefreshValidity(); } - public void UpdateExecutableShortcut( - string name, - string profileUuid, - Executable executable, - ShortcutPermanence displayPermanence, - ShortcutPermanence audioPermanence, - ShortcutPermanence capturePermanence, - string originalIconPath, - bool changeAudioDevice = false, - string audioDevice = "", - bool setAudioVolume = false, - decimal audioVolume = -1, - bool changeCaptureDevice = false, - string captureDevice = "", - bool setCaptureVolume = false, - decimal captureVolume = -1, - List startPrograms = null, - bool autoName = true, - Keys hotkey = Keys.None, - string uuid = "" - ) - { - if (!String.IsNullOrWhiteSpace(uuid)) - _uuid = uuid; - _name = name; - _profileUuid = profileUuid; - _category = ShortcutCategory.Application; - _differentExecutableToMonitor = executable.DifferentExecutableToMonitor; - _executableNameAndPath = executable.ExecutableNameAndPath; - _startTimeout = executable.ExecutableTimeout; - _executableArguments = executable.ExecutableArguments; - _executableArgumentsRequired = executable.ExecutableArgumentsRequired; - _processNameToMonitorUsesExecutable = executable.ProcessNameToMonitorUsesExecutable; - _changeAudioDevice = changeAudioDevice; - _audioDevice = audioDevice; - _setAudioVolume = setAudioVolume; - _audioVolume = audioVolume; - _changeCaptureDevice = changeCaptureDevice; - _captureDevice = captureDevice; - _setCaptureVolume = setCaptureVolume; - _captureVolume = captureVolume; - _displayPermanence = displayPermanence; - _audioPermanence = audioPermanence; - _capturePermanence = capturePermanence; - _autoName = autoName; - _startPrograms = startPrograms; - _originalIconPath = originalIconPath; - _hotkey = hotkey; - - // Now we need to find and populate the profileToUse - foreach (ProfileItem profileToTest in ProfileRepository.AllProfiles) - { - if (profileToTest.UUID.Equals(_profileUuid, StringComparison.OrdinalIgnoreCase)) - { - _profileToUse = profileToTest; - break; - } - - } - - if (_profileToUse == null) - { - throw new Exception($"Trying to create a ShortcutItem and cannot find a loaded profile with UUID {uuid}."); - } - - // We create the OriginalBitmap from the IconPath - /*if (_originalIconPath.EndsWith(".ico")) - { - Icon icoIcon = new Icon(_originalIconPath, 256, 256); - //_originalBitmap = ExtractVistaIcon(biggestIcon); - _originalLargeBitmap = icoIcon.ToBitmap(); - icoIcon.Dispose(); - } - else - { - _originalLargeBitmap = ToLargeBitmap(_originalIconPath); - }*/ - _originalLargeBitmap = ImageUtils.GetMeABitmapFromFile(_originalIconPath); - - // We create the ShortcutBitmap from the OriginalBitmap - // (We only do it if there is a valid profile) - //if (_profileToUse is ProfileItem) - // _shortcutBitmap = ToBitmapOverlay(_originalLargeBitmap, _profileToUse.ProfileTightestBitmap, 256, 256); - _shortcutBitmap = ToBitmapOverlay(_originalLargeBitmap, _profileToUse.ProfileTightestBitmap, 256, 256); - - ReplaceShortcutIconInCache(); - RefreshValidity(); - } - - public bool CopyTo (ShortcutItem shortcut, bool overwriteUUID = true) { if (!(shortcut is ShortcutItem)) @@ -1994,125 +1026,40 @@ namespace DisplayMagician } - /*public static Bitmap ToLargeBitmap(string fileNameAndPath) - { - Bitmap bm = 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 load the icon file from {fileNameAndPath}."); - Icon icoIcon = new Icon(fileNameAndPath, 256, 256); - logger.Trace($"ShortcutItem/ToLargeBitmap: Attempting to convert the icon file {fileNameAndPath} to a bitmap."); - bm = icoIcon.ToBitmap(); - logger.Trace($"ShortcutItem/ToLargeBitmap: Emptying the memory area used but the icon to stop memory leaks."); - icoIcon.Dispose(); - } - else - { - logger.Trace($"ShortcutItem/ToLargeBitmap: The file {fileNameAndPath} isn't an Icon file, so trying to use GetLargeBitmapFromFile to extract the image."); - bm = IconFromFile.GetLargeBitmapFromFile(fileNameAndPath, true, false); - } - return bm; - } - 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."); - bm = IconFromFile.GetLargeBitmapFromFile(fileNameAndPath, true, false); - return bm; - } - 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 ToSmallBitmap(string fileNameAndPath) - { - Bitmap bm = 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; - } - - - if (fileNameAndPath.EndsWith(".ico")) - { - logger.Trace($"ShortcutItem/ToSmallBitmap: The file we want to get the image from is an icon file. Attempting to load the icon file from {fileNameAndPath}."); - Size iconSize = new Size(128, 128); - Icon iconToReturn = new Icon(fileNameAndPath, iconSize); - *//*if (iconToReturn.Size.Width < iconSize.Width || iconToReturn.Size.Height < iconSize.Height) - { - // If the Icon is too small then we should try the Exe itself to see if its bigger - bm = IconFromFile.GetSmallBitmapFromFile(fileNameAndPath, false, false, false); - }*//* - //Icon iconToReturn = IconFromFile.GetLargeIconFromFile(fileNameAndPath, true, true); - //Icon iconToReturn = IconUtil.TryGetIcon(myIcon,iconSize,24,true,true); - logger.Trace($"ShortcutItem/ToSmallBitmap: Attempting to convert the icon file {fileNameAndPath} to a bitmap."); - bm = iconToReturn.ToBitmap(); - logger.Trace($"ShortcutItem/ToSmallBitmap: Emptying the memory area used but the icon to stop memory leaks."); - iconToReturn.Dispose(); - } - else - { - logger.Trace($"ShortcutItem/ToSmallBitmap: The file {fileNameAndPath} isn't an Icon file, so trying to use GetSmallBitmapFromFile to extract the image."); - bm = IconFromFile.GetSmallBitmapFromFile(fileNameAndPath, false, false, false); - } - return bm; - } - 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."); - bm = IconFromFile.GetSmallBitmapFromFile(fileNameAndPath, false, false, false); - return bm; - } - catch (Exception innerex) - { - logger.Warn(innerex, $"ShortcutItem/ToSmallBitmap: Exception while trying to save the Shortcut icon a second time. Giving up."); - return null; - } - } - }*/ - public Bitmap ToBitmapOverlay(Bitmap originalBitmap, Bitmap overlayBitmap, int width, int height, PixelFormat format = PixelFormat.Format32bppArgb) { if (originalBitmap == null) { - logger.Trace($"ShortcutItem/ToBitmapOverlay: OriginalBitmap is null, so we'll try to make the BitmapOverlay using GameLibrary Icon."); - if (_gameLibrary == SupportedGameLibraryType.Steam) + if (_category == ShortcutCategory.Application) { - logger.Trace($"ShortcutItem/SaveShortcutIconToCache: Using the Steam icon as the icon instead."); - originalBitmap = Properties.Resources.Steam.ToBitmap(); + logger.Trace($"ShortcutItem/SaveShortcutIconToCache: Using the executable icon as the icon instead."); + originalBitmap = ImageUtils.GetMeABitmapFromFile(_executableNameAndPath); } - else if (_gameLibrary == SupportedGameLibraryType.Uplay) + else if (_category == ShortcutCategory.Game) { - logger.Trace($"ShortcutItem/SaveShortcutIconToCache: Using the Uplay icon as the icon instead."); - originalBitmap = Properties.Resources.Uplay.ToBitmap(); + logger.Trace($"ShortcutItem/ToBitmapOverlay: OriginalBitmap is null, so we'll try to make the BitmapOverlay using GameLibrary Icon."); + if (_gameLibrary == SupportedGameLibraryType.Steam) + { + logger.Trace($"ShortcutItem/SaveShortcutIconToCache: Using the Steam icon as the icon instead."); + originalBitmap = Properties.Resources.Steam.ToBitmap(); + } + else if (_gameLibrary == SupportedGameLibraryType.Uplay) + { + logger.Trace($"ShortcutItem/SaveShortcutIconToCache: Using the Uplay icon as the icon instead."); + originalBitmap = Properties.Resources.Uplay.ToBitmap(); + } + else if (_gameLibrary == SupportedGameLibraryType.Origin) + { + logger.Trace($"ShortcutItem/SaveShortcutIconToCache: Using the Origin icon as the icon instead."); + originalBitmap = Properties.Resources.Origin.ToBitmap(); + } } - else if (_gameLibrary == SupportedGameLibraryType.Origin) + else { - logger.Trace($"ShortcutItem/SaveShortcutIconToCache: Using the Origin icon as the icon instead."); - originalBitmap = Properties.Resources.Origin.ToBitmap(); + logger.Trace($"ShortcutItem/SaveShortcutIconToCache: Using the profile icon as the icon instead."); + originalBitmap = _profileToUse.ProfileBitmap; } + } if (overlayBitmap == null) @@ -2141,7 +1088,7 @@ namespace DisplayMagician public MultiIcon ToIconOverlay() #pragma warning restore CS3002 // Return type is not CLS-compliant { - return ImageUtils.ToIconOverlay(_originalLargeBitmap, ProfileToUse.ProfileTightestBitmap); + return ImageUtils.ToIconOverlay(_originalBitmap, ProfileToUse.ProfileTightestBitmap); } public void RefreshValidity() diff --git a/DisplayMagician/UIForms/GameAdaptor.cs b/DisplayMagician/UIForms/GameAdaptor.cs index fc9c6c1..0cb5908 100644 --- a/DisplayMagician/UIForms/GameAdaptor.cs +++ b/DisplayMagician/UIForms/GameAdaptor.cs @@ -45,7 +45,9 @@ namespace DisplayMagician.UIForms Game game = (Game)key; Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(() => { return false; }); + return game.GameBitmap.GetThumbnailImage(256, 256, myCallback, IntPtr.Zero); + } catch (Exception ex) { @@ -99,8 +101,8 @@ namespace DisplayMagician.UIForms try { - string gameName = (string)key; - return gameName; + Game game = (Game)key; + return game.Name; } catch (Exception ex) { @@ -126,10 +128,10 @@ namespace DisplayMagician.UIForms try { - ShortcutItem shortcut = (ShortcutItem)key; + Game game = (Game)key; // Get file info - if (shortcut.ShortcutBitmap is Bitmap) + if (game.GameBitmap is Bitmap) { // Have to do some gymnastics to get rid of the // System.Drawing.Image exception created while accessing the Size @@ -139,13 +141,13 @@ namespace DisplayMagician.UIForms { try { - mySize = shortcut.ShortcutBitmap.Size; + mySize = game.GameBitmap.Size; gotSize = true; } catch (Exception ex) { // catch the System.Drawing.Image exception created while accessing the Size - logger.Warn(ex, "ShortcutAdaptor/GetDetails: System.Drawing.Image exception caused while trying to get the ProfileBitmap Size as an Integer."); + logger.Warn(ex, "GameAdapter/GetDetails: System.Drawing.Image exception caused while trying to get the GameBitmap Size as an Integer."); } } @@ -157,26 +159,28 @@ namespace DisplayMagician.UIForms { try { - mySizeF = shortcut.ShortcutBitmap.PhysicalDimension; + mySizeF = game.GameBitmap.PhysicalDimension; gotSizeF = true; } catch (Exception ex) { // catch the System.Drawing.Image exception created while accessing the Size - logger.Warn(ex, "ShortcutAdaptor/GetDetails: System.Drawing.Image exception caused while trying to get the ProfileBitmap Size as a Float."); + logger.Warn(ex, "GameAdapter/GetDetails: System.Drawing.Image exception caused while trying to get the GameBitmap Size as a Float."); } } - string name = shortcut.Name; - string filepath = Path.GetDirectoryName(shortcut.SavedShortcutIconCacheFilename); - string filename = Path.GetFileName(shortcut.SavedShortcutIconCacheFilename); + string name = game.Name; + //string filepath = Path.GetDirectoryName(shortcut.SavedShortcutIconCacheFilename); + //string filename = Path.GetFileName(shortcut.SavedShortcutIconCacheFilename); DateTime now = DateTime.Now; details.Add(new Utility.Tuple(ColumnType.DateCreated, string.Empty, now)); details.Add(new Utility.Tuple(ColumnType.DateAccessed, string.Empty, now)); details.Add(new Utility.Tuple(ColumnType.DateModified, string.Empty, now)); details.Add(new Utility.Tuple(ColumnType.FileSize, string.Empty, (long)0)); - details.Add(new Utility.Tuple(ColumnType.FilePath, string.Empty, filepath ?? "")); - details.Add(new Utility.Tuple(ColumnType.FolderName, string.Empty, filepath ?? "")); + //details.Add(new Utility.Tuple(ColumnType.FilePath, string.Empty, filepath ?? "")); + //details.Add(new Utility.Tuple(ColumnType.FolderName, string.Empty, filepath ?? "")); + details.Add(new Utility.Tuple(ColumnType.FilePath, string.Empty, "")); + details.Add(new Utility.Tuple(ColumnType.FolderName, string.Empty, "")); details.Add(new Utility.Tuple(ColumnType.Dimensions, string.Empty, mySize)); details.Add(new Utility.Tuple(ColumnType.Resolution, string.Empty, mySizeF)); details.Add(new Utility.Tuple(ColumnType.ImageDescription, string.Empty, name ?? "")); @@ -197,7 +201,7 @@ namespace DisplayMagician.UIForms } catch (Exception ex) { - logger.Warn(ex, "ShortcutAdapter/Utility.Tuple: Exception caused while trying to add details to the Game ImageListViewItem."); + logger.Warn(ex, "GameAdapter/Utility.Tuple: Exception caused while trying to add details to the Game ImageListViewItem."); // If we have a problem with converting the submitted key to a profile // Then we return null return null; diff --git a/DisplayMagician/UIForms/ImageListViewRenderers.cs b/DisplayMagician/UIForms/ImageListViewRenderers.cs index def7a54..43b0314 100644 --- a/DisplayMagician/UIForms/ImageListViewRenderers.cs +++ b/DisplayMagician/UIForms/ImageListViewRenderers.cs @@ -421,7 +421,6 @@ namespace DisplayMagician.UIForms } } - // Draw the image Image img = ImageUtils.RoundCorners(item.GetCachedImage(CachedImageType.Thumbnail), 20); if (img != null) { diff --git a/DisplayMagician/UIForms/ProfileAdaptor.cs b/DisplayMagician/UIForms/ProfileAdaptor.cs index f3b8c1b..fde8022 100644 --- a/DisplayMagician/UIForms/ProfileAdaptor.cs +++ b/DisplayMagician/UIForms/ProfileAdaptor.cs @@ -121,8 +121,8 @@ namespace DisplayMagician.UIForms try { - string profileName = (string)key; - return profileName; + ProfileItem profile = (ProfileItem)key; + return profile.Name; } catch (Exception ex) { diff --git a/DisplayMagician/UIForms/ShortcutAdaptor.cs b/DisplayMagician/UIForms/ShortcutAdaptor.cs index b7bb75f..0ae3c2f 100644 --- a/DisplayMagician/UIForms/ShortcutAdaptor.cs +++ b/DisplayMagician/UIForms/ShortcutAdaptor.cs @@ -49,7 +49,7 @@ namespace DisplayMagician.UIForms } catch (Exception ex) { - Console.WriteLine($"ShortcutAdapter/GetThumbnail exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}"); + logger.Warn(ex, $"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 @@ -81,7 +81,7 @@ namespace DisplayMagician.UIForms } catch (Exception ex) { - Console.WriteLine($"ShortcutAdapter/GetUniqueIdentifier exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}"); + logger.Warn(ex, $"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; @@ -100,12 +100,12 @@ namespace DisplayMagician.UIForms try { - string shortcutName = (string)key; - return shortcutName; + ShortcutItem shortcut = (ShortcutItem)key; + return shortcut.Name; } catch (Exception ex) { - Console.WriteLine($"ShortcutAdaptor/GetSourceImage exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}"); + logger.Warn(ex, $"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 @@ -198,7 +198,7 @@ namespace DisplayMagician.UIForms } catch (Exception ex) { - Console.WriteLine($"ShortcutAdapter/Utility.Tuple exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}"); + logger.Warn(ex, $"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; diff --git a/DisplayMagician/UIForms/ShortcutForm.Designer.cs b/DisplayMagician/UIForms/ShortcutForm.Designer.cs index f99b99c..79423ce 100644 --- a/DisplayMagician/UIForms/ShortcutForm.Designer.cs +++ b/DisplayMagician/UIForms/ShortcutForm.Designer.cs @@ -205,7 +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); + //this.tabc_shortcut.VisibleChanged += new System.EventHandler(this.tabc_shortcut_VisibleChanged); // // tabp_display // diff --git a/DisplayMagician/UIForms/ShortcutForm.cs b/DisplayMagician/UIForms/ShortcutForm.cs index 8583c97..dde6eca 100644 --- a/DisplayMagician/UIForms/ShortcutForm.cs +++ b/DisplayMagician/UIForms/ShortcutForm.cs @@ -1071,7 +1071,7 @@ namespace DisplayMagician.UIForms cb_args_game.Checked = true; } //select the loaded Game item if it is there - foreach (ImageListViewItem gameItem in ilv_games.Items) + /*foreach (ImageListViewItem gameItem in ilv_games.Items) { if (gameItem.Text.Equals(_shortcutToEdit.GameName)) { @@ -1080,7 +1080,7 @@ namespace DisplayMagician.UIForms break; } } - } +*/ } cb_autosuggest.Checked = _shortcutToEdit.AutoName; @@ -2199,11 +2199,11 @@ namespace DisplayMagician.UIForms EnableSaveButtonIfValid(); } - private void tabc_shortcut_VisibleChanged(object sender, EventArgs e) + /*private void tabc_shortcut_VisibleChanged(object sender, EventArgs e) { if (tabc_shortcut.Visible == true) SelectGameInImageListView(); - } + }*/ /*private void ilv_games_VisibleChanged(object sender, EventArgs e) {