Skip to content

Commit

Permalink
Merge pull request #59 from PikeNote/master
Browse files Browse the repository at this point in the history
Improve Efficency
  • Loading branch information
tjackenpacken authored Jan 5, 2021
2 parents e9480ab + d3b1069 commit acf444b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
22 changes: 11 additions & 11 deletions main/Classes/Category.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using IWshRuntimeLibrary;
using client.User_controls;
using System;
using System.Collections.Generic;
using System.Drawing;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion main/Classes/handleWindowsApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class handleWindowsApp
public static Dictionary<string, string> fileDirectoryCache = new Dictionary<string, string>();

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;
Expand Down
5 changes: 2 additions & 3 deletions main/Forms/frmGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ private void pnlAddShortcut_Click(object sender, EventArgs e)
{
addShortcut(file);
}
resetSelection();
}

if (pnlShortcuts.Controls.Count != 0)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(',');
Expand Down
10 changes: 6 additions & 4 deletions main/User controls/ucProgramShortcut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public partial class ucProgramShortcut : UserControl

public bool IsSelected = false;
public int Position { get; set; }

public Bitmap logo;
public ucProgramShortcut()
{
InitializeComponent();
Expand Down Expand Up @@ -59,26 +61,26 @@ 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)
{
MessageBox.Show(ex.Message);
}
} else
{
picShortcut.BackgroundImage = global::client.Properties.Resources.Error;
picShortcut.BackgroundImage = logo = global::client.Properties.Resources.Error;
}

if (Position == 0)
Expand Down

0 comments on commit acf444b

Please sign in to comment.