Skip to content

Commit

Permalink
Allow users of Update.exe to specify the shortcut locations via anoth…
Browse files Browse the repository at this point in the history
…er command-line argument.
  • Loading branch information
CharlieHess committed Jan 22, 2015
1 parent 0548edd commit f0077cb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/Squirrel/IUpdateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Squirrel
{
[Flags]
public enum ShortcutLocation {
None = 0,
StartMenu = 1 << 0,
Desktop = 1 << 1,
Startup = 1 << 2,
Expand Down
2 changes: 2 additions & 0 deletions src/Squirrel/UpdateManager.ApplyReleases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public void CreateShortcutsForExecutable(string exeName, ShortcutLocation locati
var fileVerInfo = FileVersionInfo.GetVersionInfo(exePath);

foreach (var f in (ShortcutLocation[]) Enum.GetValues(typeof(ShortcutLocation))) {
if (f == ShortcutLocation.None) continue;
if (!locations.HasFlag(f)) continue;

var file = linkTargetForVersionInfo(f, zf, fileVerInfo);
Expand Down Expand Up @@ -161,6 +162,7 @@ public void RemoveShortcutsForExecutable(string exeName, ShortcutLocation locati
Path.Combine(Utility.AppDirForRelease(rootAppDirectory, thisRelease), exeName));

foreach (var f in (ShortcutLocation[]) Enum.GetValues(typeof(ShortcutLocation))) {
if (f == ShortcutLocation.None) continue;
if (!locations.HasFlag(f)) continue;

var file = linkTargetForVersionInfo(f, zf, fileVerInfo);
Expand Down
35 changes: 29 additions & 6 deletions src/Update/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ int main(string[] args)
string processStartArgs = default(string);
string appName = default(string);
string setupIcon = default(string);
string shortcutArgs = default(string);

opts = new OptionSet() {
"Usage: Squirrel.exe command [OPTS]",
Expand Down Expand Up @@ -105,6 +106,7 @@ int main(string[] args)
{ "s|silent", "Silent install", _ => silentInstall = true},
{ "b=|baseUrl=", "Provides a base URL to prefix the RELEASES file packages with", v => baseUrl = v, true},
{ "a=|process-start-args=", "Arguments that will be used when starting executable", v => processStartArgs = v, true},
{ "l=|shortcut-locations=", "Comma-separated string of shortcut locations, e.g. 'Desktop,StartMenu'", v => shortcutArgs = v},
};

opts.Parse(args);
Expand Down Expand Up @@ -138,10 +140,10 @@ int main(string[] args)
Releasify(target, releaseDir, packagesDir, bootstrapperExe, backgroundGif, signingParameters, baseUrl, setupIcon);
break;
case UpdateAction.Shortcut:
Shortcut(target);
Shortcut(target, shortcutArgs);
break;
case UpdateAction.Deshortcut:
Deshortcut(target);
Deshortcut(target, shortcutArgs);
break;
case UpdateAction.ProcessStart:
ProcessStart(processStart, processStartArgs);
Expand Down Expand Up @@ -391,29 +393,37 @@ public void Releasify(string package, string targetDir = null, string packagesDi

}

public void Shortcut(string exeName)
public void Shortcut(string exeName, string shortcutArgs)
{
if (String.IsNullOrWhiteSpace(exeName)) {
ShowHelp();
return;
}

var appName = getAppNameFromDirectory();
var locations = String.IsNullOrWhiteSpace(shortcutArgs)
? ShortcutLocation.StartMenu | ShortcutLocation.Desktop
: parseShortcutLocations(shortcutArgs);

using (var mgr = new UpdateManager("", appName, FrameworkVersion.Net45)) {
mgr.CreateShortcutsForExecutable(exeName, ShortcutLocation.Desktop | ShortcutLocation.StartMenu, false);
mgr.CreateShortcutsForExecutable(exeName, locations, false);
}
}

public void Deshortcut(string exeName)
public void Deshortcut(string exeName, string shortcutArgs)
{
if (String.IsNullOrWhiteSpace(exeName)) {
ShowHelp();
return;
}

var appName = getAppNameFromDirectory();
var locations = String.IsNullOrWhiteSpace(shortcutArgs)
? ShortcutLocation.StartMenu | ShortcutLocation.Desktop
: parseShortcutLocations(shortcutArgs);

using (var mgr = new UpdateManager("", appName, FrameworkVersion.Net45)) {
mgr.RemoveShortcutsForExecutable(exeName, ShortcutLocation.Desktop | ShortcutLocation.StartMenu);
mgr.RemoveShortcutsForExecutable(exeName, locations);
}
}

Expand Down Expand Up @@ -594,6 +604,19 @@ static string getAppNameFromDirectory(string path = null)
return (new DirectoryInfo(path)).Name;
}

static ShortcutLocation parseShortcutLocations(string shortcutArgs)
{
var locations = ShortcutLocation.None;
var args = shortcutArgs.Split(new[] { ',' });

foreach (var arg in args) {
var location = (ShortcutLocation)(Enum.Parse(typeof(ShortcutLocation), arg, false));
locations |= location;
}

return locations;
}

static int consoleCreated = 0;
static void ensureConsole()
{
Expand Down

0 comments on commit f0077cb

Please sign in to comment.