Skip to content

Commit

Permalink
Shortcut enumeration fix
Browse files Browse the repository at this point in the history
Merged patch from @sm-g to fix empty shortcut lists occurring
  • Loading branch information
Jonno12345 committed Mar 13, 2016
1 parent 01049c9 commit 069af4e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
47 changes: 30 additions & 17 deletions TileIconifier/Forms/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ private void FullUpdate(object sender, DoWorkEventArgs e)
lstShortcuts.DataSource = _shortcutsList;
}



private void GetPinnedStartMenuInformation()
{
if (!getPinnedItemsRequiresPowershellToolStripMenuItem.Checked)
Expand All @@ -91,8 +89,6 @@ private void GetPinnedStartMenuInformation()
return;
}



_shortcutsList = _shortcutsList.OrderByDescending(s => s.IsPinned)
.ThenBy(s => s.ShortcutFileInfo.Name)
.ToList();
Expand All @@ -102,7 +98,6 @@ private void GetPinnedStartMenuInformation()
File.Delete(tempFilePath);
}
catch { }

}

private void MarkPinnedShortcuts(string tempFilePath)
Expand Down Expand Up @@ -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)
Expand All @@ -167,7 +186,6 @@ private void btnIconify_Click(object sender, EventArgs e)
}
}


private void btnRemove_Click(object sender, EventArgs e)
{
if (!DoValidation())
Expand All @@ -182,7 +200,6 @@ private void btnRemove_Click(object sender, EventArgs e)
}
}


private bool DoValidation()
{
ResetValidation();
Expand All @@ -195,7 +212,6 @@ private void ResetValidation()
txtBGColour.BackColor = Color.White;
pctMediumIcon.BackColor = SystemColors.Control;
pctSmallIcon.BackColor = SystemColors.Control;

}

private bool ValidateColour()
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -321,7 +337,6 @@ private void getPinnedItemsRequiresPowershellToolStripMenuItem_Click(object send
}));
else
getPinnedItemsRequiresPowershellToolStripMenuItem.Checked = false;

}
else
{
Expand Down Expand Up @@ -362,7 +377,6 @@ private void pctMediumIcon_Click(object sender, EventArgs e)
UpdateShortcut();
}
catch (UserCancellationException) { }

}

private void pctSmallIcon_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -410,7 +424,6 @@ private void radFGLight_CheckedChanged(object sender, EventArgs e)

private void btnUndo_Click(object sender, EventArgs e)
{

_currentShortcut.UndoChanges();

UpdateShortcut();
Expand All @@ -434,4 +447,4 @@ private void RemoveEventHandlers()
this.lstShortcuts.SelectedIndexChanged -= new System.EventHandler(this.lstShortcuts_SelectedIndexChanged);
}
}
}
}
4 changes: 2 additions & 2 deletions TileIconifier/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.2")]
[assembly: AssemblyFileVersion("1.0.0.2")]
[assembly: AssemblyVersion("1.0.0.4")]
[assembly: AssemblyFileVersion("1.0.0.4")]
5 changes: 1 addition & 4 deletions TileIconifier/TileIconifier.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<PropertyGroup />
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -77,7 +75,6 @@
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ShortcutItem\ShortcutItemParameters.cs" />
<Compile Include="testing.cs" />
<Compile Include="TileIconifier.cs" />
<Compile Include="Forms\frmAbout.cs">
<SubType>Form</SubType>
Expand Down

0 comments on commit 069af4e

Please sign in to comment.