Skip to content

Fix taskbar shorcut update #1490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions src/Squirrel/ShellFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,18 @@ ushort timeOut
this.shortcutFile = linkFile;
}
}

/// <summary>
/// Indicates whether the target is in the given directory.
/// </summary>
/// <param name="directory">The directory.</param>
/// <returns>true if the target is in the given directory; otherwise, false.</returns>
internal bool IsTargetInDirectory(
string directory)
{
return System.IO.Path.GetDirectoryName(Target)
.Equals(directory, StringComparison.OrdinalIgnoreCase);
}
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Squirrel/UpdateManager.ApplyReleases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ void fixPinnedExecutables(SemanticVersion newCurrentVersion, bool removeAll = fa
try {
if (shortcut == null) continue;
if (String.IsNullOrWhiteSpace(shortcut.Target)) continue;
if (!shortcut.Target.StartsWith(rootAppDirectory, StringComparison.OrdinalIgnoreCase)) continue;
if (!shortcut.IsTargetInDirectory(rootAppDirectory)) continue;

if (removeAll) {
Utility.DeleteFileHarder(shortcut.ShortCutFile);
Expand Down
23 changes: 23 additions & 0 deletions test/ShellLinkTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Squirrel.Shell;
using Xunit;

namespace Squirrel.Tests
{
public class ShellLinkTests
{
[Theory]
[InlineData(@"C:\MyApp\MyApp.exe", @"C:\MyApp", true)]
[InlineData(@"C:\MyApp\MyApp.exe", @"C:\MyAppTwo", false)]
public void IsTargetInDirectoryTest(
string target,
string directory,
bool isTargetInDirectory)
{
var shellLink = new ShellLink
{
Target = target
};
Assert.Equal(isTargetInDirectory, shellLink.IsTargetInDirectory(directory));
}
}
}
1 change: 1 addition & 0 deletions test/Squirrel.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ReleaseEntryTests.cs" />
<Compile Include="ReleasePackageTests.cs" />
<Compile Include="ShellLinkTests.cs" />
<Compile Include="SquirrelAwareExecutableDetectorTests.cs" />
<Compile Include="TestHelpers\AssertExtensions.cs" />
<Compile Include="TestHelpers\ExposedClass.cs" />
Expand Down