Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions Mint/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,38 @@ private void LoadOptions()
checkAutoStart.Checked = Options.CurrentOptions.AutoStart;
}

static string Sha256(string randomString)
{
var crypt = new System.Security.Cryptography.SHA256Managed();
var hash = new System.Text.StringBuilder();
byte[] crypto = crypt.ComputeHash(Encoding.UTF8.GetBytes(randomString));
foreach (byte theByte in crypto)
{
hash.Append(theByte.ToString("x2"));
}
return hash.ToString();
}

readonly static string _iconCache = Application.StartupPath + "\\.mint_cache";

private Bitmap ExtractOrLoadIcon(string exeFilePath)
{
_ = Directory.CreateDirectory(_iconCache);
string pathHash = Sha256(exeFilePath);
string iconPath = _iconCache + "\\" + pathHash + ".png";
if (File.Exists(iconPath))
{
return new Bitmap(iconPath);
}
else
{
Bitmap extracted = Icon.ExtractAssociatedIcon(exeFilePath).ToBitmap();
extracted.Save(iconPath);
return extracted;
}

}

private void BuildLauncherMenu()
{
launcherMenu.Items.Clear();
Expand Down Expand Up @@ -185,7 +217,7 @@ private void BuildLauncherMenu()

if (!string.IsNullOrEmpty(x.AppGroup))
{
subItem = new ToolStripMenuItem(x.AppTitle, !isDeadItem ? Icon.ExtractAssociatedIcon(x.AppLink).ToBitmap() : null);
subItem = new ToolStripMenuItem(x.AppTitle, !isDeadItem ? ExtractOrLoadIcon(x.AppLink) : null);
subItem.Click += subItem_Click;
if (!isDeadItem)
{
Expand All @@ -201,7 +233,7 @@ private void BuildLauncherMenu()
}
else
{
i = new ToolStripMenuItem(x.AppTitle, !isDeadItem ? (Icon.ExtractAssociatedIcon(x.AppLink)).ToBitmap() : null);
i = new ToolStripMenuItem(x.AppTitle, !isDeadItem ? (ExtractOrLoadIcon(x.AppLink)) : null);
if (!isDeadItem)
{
i.ForeColor = Color.GhostWhite;
Expand Down