Skip to content

Commit

Permalink
Merge pull request Squirrel#155 from flagbug/portable-shortcut
Browse files Browse the repository at this point in the history
Added a shortcut location for the application root directory
  • Loading branch information
anaisbetts committed Dec 7, 2014
2 parents 8caaf63 + c18db14 commit 34c638a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/Squirrel/IUpdateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ namespace Squirrel
public enum ShortcutLocation {
StartMenu = 1 << 0,
Desktop = 1 << 1,
Startup = 1 << 2
Startup = 1 << 2,
/// <summary>
/// A shortcut in the application folder, useful for portable applications.
/// </summary>
AppRoot = 1 << 3
}

public interface IUpdateManager : IDisposable, IEnableLogger
Expand Down
5 changes: 4 additions & 1 deletion src/Squirrel/UpdateManager.ApplyReleases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void CreateShortcutsForExecutable(string exeName, ShortcutLocation locati
var exePath = Path.Combine(Utility.AppDirForRelease(rootAppDirectory, thisRelease), exeName);
var fileVerInfo = FileVersionInfo.GetVersionInfo(exePath);

foreach (var f in new[] { ShortcutLocation.StartMenu, ShortcutLocation.Desktop, ShortcutLocation.Startup, }) {
foreach (var f in (ShortcutLocation[]) Enum.GetValues(typeof(ShortcutLocation))) {
if (!locations.HasFlag(f)) continue;

var file = linkTargetForVersionInfo(f, zf, fileVerInfo);
Expand Down Expand Up @@ -573,6 +573,9 @@ string getLinkTarget(ShortcutLocation location, string title, string application
case ShortcutLocation.Startup:
dir = Environment.GetFolderPath (Environment.SpecialFolder.Startup);
break;
case ShortcutLocation.AppRoot:
dir = rootAppDirectory;
break;
}

if (createDirectoryIfNecessary && !Directory.Exists(dir)) {
Expand Down
4 changes: 2 additions & 2 deletions test/ApplyReleasesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,11 @@ public async Task CreateShortcutsRoundTrip()
}

var fixture = new UpdateManager.ApplyReleasesImpl("theApp", Path.Combine(path, "theApp"));
fixture.CreateShortcutsForExecutable("SquirrelAwareApp.exe", ShortcutLocation.Desktop | ShortcutLocation.StartMenu | ShortcutLocation.Startup, false);
fixture.CreateShortcutsForExecutable("SquirrelAwareApp.exe", ShortcutLocation.Desktop | ShortcutLocation.StartMenu | ShortcutLocation.Startup | ShortcutLocation.AppRoot, false);

// NB: COM is Weird.
Thread.Sleep(1000);
fixture.RemoveShortcutsForExecutable("SquirrelAwareApp.exe", ShortcutLocation.Desktop | ShortcutLocation.StartMenu | ShortcutLocation.Startup);
fixture.RemoveShortcutsForExecutable("SquirrelAwareApp.exe", ShortcutLocation.Desktop | ShortcutLocation.StartMenu | ShortcutLocation.Startup | ShortcutLocation.AppRoot);

// NB: Squirrel-Aware first-run might still be running, slow
// our roll before blowing away the temp path
Expand Down

0 comments on commit 34c638a

Please sign in to comment.