diff --git a/main/Classes/Category.cs b/main/Classes/Category.cs index 9f9bd8b..9403e2f 100644 --- a/main/Classes/Category.cs +++ b/main/Classes/Category.cs @@ -1,4 +1,4 @@ -using IWshRuntimeLibrary; +using client.User_controls; using System; using System.Collections.Generic; using System.Drawing; @@ -186,23 +186,23 @@ public void cacheIcons() { String filePath = ShortcutList[i].FilePath; - // Process .lnk (shortcut) files differently + ucProgramShortcut programShortcutControl = Application.OpenForms["frmGroup"].Controls["pnlShortcuts"].Controls[i] as ucProgramShortcut; + string savePath; + if (ShortcutList[i].isWindowsApp) { - handleWindowsApp.getWindowsAppIcon(filePath, true).Save(iconPath + "\\" + specialCharRegex.Replace(filePath, string.Empty) + ".png"); - } - else if (Path.GetExtension(filePath).ToLower() == ".lnk") - { - Forms.frmGroup.handleLnkExt(filePath).Save(iconPath + "\\" + Path.GetFileNameWithoutExtension(filePath) + ".png"); + savePath = iconPath + "\\" + specialCharRegex.Replace(filePath, string.Empty) + ".png"; } else if (Directory.Exists(filePath)) { - handleFolder.GetFolderIcon(filePath).ToBitmap().Save(iconPath + "\\" + Path.GetFileNameWithoutExtension(filePath) + "_FolderObjTSKGRoup.png"); + savePath = iconPath + "\\" + Path.GetFileNameWithoutExtension(filePath) + "_FolderObjTSKGRoup.png"; } else { - // Extracts icon from the .exe if the provided file is not a shortcut file - Icon.ExtractAssociatedIcon(Environment.ExpandEnvironmentVariables(filePath)).ToBitmap().Save(iconPath + "\\" + Path.GetFileNameWithoutExtension(filePath) + ".png"); + savePath = iconPath + "\\" + Path.GetFileNameWithoutExtension(filePath) + ".png"; } - } + + programShortcutControl.logo.Save(savePath); + + } } // Try to load an iamge from the cache diff --git a/main/Classes/handleWindowsApp.cs b/main/Classes/handleWindowsApp.cs index 7a7af29..2d9eafa 100644 --- a/main/Classes/handleWindowsApp.cs +++ b/main/Classes/handleWindowsApp.cs @@ -13,7 +13,7 @@ class handleWindowsApp public static Dictionary fileDirectoryCache = new Dictionary(); private static PackageManager pkgManger = new PackageManager(); - public static Image getWindowsAppIcon(String file, bool alreadyAppID = false) + public static Bitmap getWindowsAppIcon(String file, bool alreadyAppID = false) { // Get the app's ID from its shortcut target file (Ex. 4DF9E0F8.Netflix_mcm4njqhnhss8!Netflix.app) String microsoftAppName = (!alreadyAppID) ? GetLnkTarget(file) : file; diff --git a/main/Forms/frmGroup.cs b/main/Forms/frmGroup.cs index 6cba13e..273d8cf 100644 --- a/main/Forms/frmGroup.cs +++ b/main/Forms/frmGroup.cs @@ -173,6 +173,7 @@ private void pnlAddShortcut_Click(object sender, EventArgs e) { addShortcut(file); } + resetSelection(); } if (pnlShortcuts.Controls.Count != 0) @@ -217,8 +218,6 @@ private void pnlDragDropExt(object sender, DragEventArgs e) // Handle adding the shortcut to list private void addShortcut(String file, bool isExtension = false) { - resetSelection(); - String workingDirec = getProperDirectory(file); ProgramShortcut psc = new ProgramShortcut() { FilePath = Environment.ExpandEnvironmentVariables(file), isWindowsApp = isExtension, WorkingDirectory = workingDirec }; //Create new shortcut obj @@ -373,7 +372,7 @@ private void handleIcon(String file, String imageExtension) } // Handle returning images of icon files (.lnk) - public static Image handleLnkExt(String file) + public static Bitmap handleLnkExt(String file) { IWshShortcut lnkIcon = (IWshShortcut)new WshShell().CreateShortcut(file); String[] icLocation = lnkIcon.IconLocation.Split(','); diff --git a/main/User controls/ucProgramShortcut.cs b/main/User controls/ucProgramShortcut.cs index f86aec7..13bf4a1 100644 --- a/main/User controls/ucProgramShortcut.cs +++ b/main/User controls/ucProgramShortcut.cs @@ -15,6 +15,8 @@ public partial class ucProgramShortcut : UserControl public bool IsSelected = false; public int Position { get; set; } + + public Bitmap logo; public ucProgramShortcut() { InitializeComponent(); @@ -59,18 +61,18 @@ private void ucProgramShortcut_Load(object sender, EventArgs e) // Depending on the extension, the icon can be directly extracted or it has to be gotten through other methods as to not get the shortcut arrow if (imageExtension == ".lnk") { - picShortcut.BackgroundImage = frmGroup.handleLnkExt(Shortcut.FilePath); + picShortcut.BackgroundImage = logo = frmGroup.handleLnkExt(Shortcut.FilePath); } else { - picShortcut.BackgroundImage = Icon.ExtractAssociatedIcon(Shortcut.FilePath).ToBitmap(); + picShortcut.BackgroundImage = logo = Icon.ExtractAssociatedIcon(Shortcut.FilePath).ToBitmap(); } } else if (Directory.Exists(Shortcut.FilePath)) { try { - picShortcut.BackgroundImage = handleFolder.GetFolderIcon(Shortcut.FilePath).ToBitmap(); + picShortcut.BackgroundImage = logo = handleFolder.GetFolderIcon(Shortcut.FilePath).ToBitmap(); } catch (Exception ex) { @@ -78,7 +80,7 @@ private void ucProgramShortcut_Load(object sender, EventArgs e) } } else { - picShortcut.BackgroundImage = global::client.Properties.Resources.Error; + picShortcut.BackgroundImage = logo = global::client.Properties.Resources.Error; } if (Position == 0)