Skip to content

Commit acf444b

Browse files
Merge pull request tjackenpacken#59 from PikeNote/master
Improve Efficency
2 parents e9480ab + d3b1069 commit acf444b

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

main/Classes/Category.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using IWshRuntimeLibrary;
1+
using client.User_controls;
22
using System;
33
using System.Collections.Generic;
44
using System.Drawing;
@@ -186,23 +186,23 @@ public void cacheIcons()
186186
{
187187
String filePath = ShortcutList[i].FilePath;
188188

189-
// Process .lnk (shortcut) files differently
189+
ucProgramShortcut programShortcutControl = Application.OpenForms["frmGroup"].Controls["pnlShortcuts"].Controls[i] as ucProgramShortcut;
190+
string savePath;
191+
190192
if (ShortcutList[i].isWindowsApp)
191193
{
192-
handleWindowsApp.getWindowsAppIcon(filePath, true).Save(iconPath + "\\" + specialCharRegex.Replace(filePath, string.Empty) + ".png");
193-
}
194-
else if (Path.GetExtension(filePath).ToLower() == ".lnk")
195-
{
196-
Forms.frmGroup.handleLnkExt(filePath).Save(iconPath + "\\" + Path.GetFileNameWithoutExtension(filePath) + ".png");
194+
savePath = iconPath + "\\" + specialCharRegex.Replace(filePath, string.Empty) + ".png";
197195
} else if (Directory.Exists(filePath))
198196
{
199-
handleFolder.GetFolderIcon(filePath).ToBitmap().Save(iconPath + "\\" + Path.GetFileNameWithoutExtension(filePath) + "_FolderObjTSKGRoup.png");
197+
savePath = iconPath + "\\" + Path.GetFileNameWithoutExtension(filePath) + "_FolderObjTSKGRoup.png";
200198
} else
201199
{
202-
// Extracts icon from the .exe if the provided file is not a shortcut file
203-
Icon.ExtractAssociatedIcon(Environment.ExpandEnvironmentVariables(filePath)).ToBitmap().Save(iconPath + "\\" + Path.GetFileNameWithoutExtension(filePath) + ".png");
200+
savePath = iconPath + "\\" + Path.GetFileNameWithoutExtension(filePath) + ".png";
204201
}
205-
}
202+
203+
programShortcutControl.logo.Save(savePath);
204+
205+
}
206206
}
207207

208208
// Try to load an iamge from the cache

main/Classes/handleWindowsApp.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class handleWindowsApp
1313
public static Dictionary<string, string> fileDirectoryCache = new Dictionary<string, string>();
1414

1515
private static PackageManager pkgManger = new PackageManager();
16-
public static Image getWindowsAppIcon(String file, bool alreadyAppID = false)
16+
public static Bitmap getWindowsAppIcon(String file, bool alreadyAppID = false)
1717
{
1818
// Get the app's ID from its shortcut target file (Ex. 4DF9E0F8.Netflix_mcm4njqhnhss8!Netflix.app)
1919
String microsoftAppName = (!alreadyAppID) ? GetLnkTarget(file) : file;

main/Forms/frmGroup.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ private void pnlAddShortcut_Click(object sender, EventArgs e)
173173
{
174174
addShortcut(file);
175175
}
176+
resetSelection();
176177
}
177178

178179
if (pnlShortcuts.Controls.Count != 0)
@@ -217,8 +218,6 @@ private void pnlDragDropExt(object sender, DragEventArgs e)
217218
// Handle adding the shortcut to list
218219
private void addShortcut(String file, bool isExtension = false)
219220
{
220-
resetSelection();
221-
222221
String workingDirec = getProperDirectory(file);
223222

224223
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)
373372
}
374373

375374
// Handle returning images of icon files (.lnk)
376-
public static Image handleLnkExt(String file)
375+
public static Bitmap handleLnkExt(String file)
377376
{
378377
IWshShortcut lnkIcon = (IWshShortcut)new WshShell().CreateShortcut(file);
379378
String[] icLocation = lnkIcon.IconLocation.Split(',');

main/User controls/ucProgramShortcut.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public partial class ucProgramShortcut : UserControl
1515

1616
public bool IsSelected = false;
1717
public int Position { get; set; }
18+
19+
public Bitmap logo;
1820
public ucProgramShortcut()
1921
{
2022
InitializeComponent();
@@ -59,26 +61,26 @@ private void ucProgramShortcut_Load(object sender, EventArgs e)
5961
// 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
6062
if (imageExtension == ".lnk")
6163
{
62-
picShortcut.BackgroundImage = frmGroup.handleLnkExt(Shortcut.FilePath);
64+
picShortcut.BackgroundImage = logo = frmGroup.handleLnkExt(Shortcut.FilePath);
6365
}
6466
else
6567
{
66-
picShortcut.BackgroundImage = Icon.ExtractAssociatedIcon(Shortcut.FilePath).ToBitmap();
68+
picShortcut.BackgroundImage = logo = Icon.ExtractAssociatedIcon(Shortcut.FilePath).ToBitmap();
6769
}
6870

6971
} else if (Directory.Exists(Shortcut.FilePath))
7072
{
7173
try
7274
{
73-
picShortcut.BackgroundImage = handleFolder.GetFolderIcon(Shortcut.FilePath).ToBitmap();
75+
picShortcut.BackgroundImage = logo = handleFolder.GetFolderIcon(Shortcut.FilePath).ToBitmap();
7476
}
7577
catch (Exception ex)
7678
{
7779
MessageBox.Show(ex.Message);
7880
}
7981
} else
8082
{
81-
picShortcut.BackgroundImage = global::client.Properties.Resources.Error;
83+
picShortcut.BackgroundImage = logo = global::client.Properties.Resources.Error;
8284
}
8385

8486
if (Position == 0)

0 commit comments

Comments
 (0)