Skip to content

Instantly share code, notes, and snippets.

@sm-g
Created March 13, 2016 04:36
Show Gist options
  • Save sm-g/25b66ef6ee87e306f237 to your computer and use it in GitHub Desktop.
Save sm-g/25b66ef6ee87e306f237 to your computer and use it in GitHub Desktop.
TileIconify1
From 772de67a9a1eca8f6e6f462a9f9c841ccab3ad10 Mon Sep 17 00:00:00 2001
From: smg <semagerasimov@gmail.com>
Date: Sun, 13 Mar 2016 11:32:45 +0700
Subject: [PATCH] fix EnumerateShortcuts access denied
---
TileIconifier/Forms/frmMain.cs | 47 +++++++++++++++++++++++++++---------------
1 file changed, 30 insertions(+), 17 deletions(-)
diff --git a/TileIconifier/Forms/frmMain.cs b/TileIconifier/Forms/frmMain.cs
index 7f644e4..3e34119 100644
--- a/TileIconifier/Forms/frmMain.cs
+++ b/TileIconifier/Forms/frmMain.cs
@@ -64,8 +64,6 @@ private void FullUpdate(object sender, DoWorkEventArgs e)
lstShortcuts.DataSource = _shortcutsList;
}
-
-
private void GetPinnedStartMenuInformation()
{
if (!getPinnedItemsRequiresPowershellToolStripMenuItem.Checked)
@@ -91,8 +89,6 @@ private void GetPinnedStartMenuInformation()
return;
}
-
-
_shortcutsList = _shortcutsList.OrderByDescending(s => s.IsPinned)
.ThenBy(s => s.ShortcutFileInfo.Name)
.ToList();
@@ -102,7 +98,6 @@ private void GetPinnedStartMenuInformation()
File.Delete(tempFilePath);
}
catch { }
-
}
private void MarkPinnedShortcuts(string tempFilePath)
@@ -135,15 +130,39 @@ private void EnumerateShortcuts()
@"%APPDATA%\Microsoft\Windows\Start Menu"
};
- foreach (var PathToScan in PathsToScan)
+ foreach (var pathToScan in PathsToScan)
{
- var FileEnumeration = new DirectoryInfo(Environment.ExpandEnvironmentVariables(PathToScan)).EnumerateFiles("*.lnk", SearchOption.AllDirectories);
- _shortcutsList.AddRange(FileEnumeration.Select(f => new ShortcutItem(f))
- .Where(f => !string.IsNullOrEmpty(f.ExeFilePath) && File.Exists(f.ExeFilePath)));
+ ApplyAllFiles(Environment.ExpandEnvironmentVariables(pathToScan), f =>
+ {
+ var fi = new FileInfo(f);
+ if (!fi.Extension.Equals(".lnk", StringComparison.OrdinalIgnoreCase))
+ return;
+
+ var shortcutItem = new ShortcutItem(fi);
+ if (!string.IsNullOrEmpty(shortcutItem.ExeFilePath) && File.Exists(shortcutItem.ExeFilePath))
+ _shortcutsList.Add(shortcutItem);
+ });
}
_shortcutsList = _shortcutsList.OrderBy(f => f.ShortcutFileInfo.Name).ToList();
+ }
+ private void ApplyAllFiles(string folder, Action<string> fileAction)
+ {
+ foreach (string file in Directory.GetFiles(folder))
+ {
+ fileAction(file);
+ }
+ foreach (string subDir in Directory.GetDirectories(folder))
+ {
+ try
+ {
+ ApplyAllFiles(subDir, fileAction);
+ }
+ catch
+ {
+ }
+ }
}
private void btnIconify_Click(object sender, EventArgs e)
@@ -167,7 +186,6 @@ private void btnIconify_Click(object sender, EventArgs e)
}
}
-
private void btnRemove_Click(object sender, EventArgs e)
{
if (!DoValidation())
@@ -182,7 +200,6 @@ private void btnRemove_Click(object sender, EventArgs e)
}
}
-
private bool DoValidation()
{
ResetValidation();
@@ -195,7 +212,6 @@ private void ResetValidation()
txtBGColour.BackColor = Color.White;
pctMediumIcon.BackColor = SystemColors.Control;
pctSmallIcon.BackColor = SystemColors.Control;
-
}
private bool ValidateColour()
@@ -263,7 +279,7 @@ private void UpdateShortcut()
//only show remove if the icon is successfully iconified
btnRemove.Enabled = _currentShortcut.IsIconified;
-
+
//update the picture boxes to show the relevant images
pctStandardIcon.Image = _currentShortcut.StandardIcon.ToBitmap();
pctMediumIcon.Image = _currentShortcut.MediumImage;
@@ -321,7 +337,6 @@ private void getPinnedItemsRequiresPowershellToolStripMenuItem_Click(object send
}));
else
getPinnedItemsRequiresPowershellToolStripMenuItem.Checked = false;
-
}
else
{
@@ -362,7 +377,6 @@ private void pctMediumIcon_Click(object sender, EventArgs e)
UpdateShortcut();
}
catch (UserCancellationException) { }
-
}
private void pctSmallIcon_Click(object sender, EventArgs e)
@@ -410,7 +424,6 @@ private void radFGLight_CheckedChanged(object sender, EventArgs e)
private void btnUndo_Click(object sender, EventArgs e)
{
-
_currentShortcut.UndoChanges();
UpdateShortcut();
@@ -434,4 +447,4 @@ private void RemoveEventHandlers()
this.lstShortcuts.SelectedIndexChanged -= new System.EventHandler(this.lstShortcuts_SelectedIndexChanged);
}
}
-}
+}
\ No newline at end of file
--
2.7.1.windows.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment