string installAppVersion(IAppSetup app, Version newCurrentVersion, IEnumerable <ShortcutCreationRequest> shortcutRequestsToIgnore, bool isFirstInstall) { try { if (isFirstInstall) { log.Info("installAppVersion: Doing first install for {0}", app.Target); app.OnAppInstall(); } log.Info("installAppVersion: Doing install for version {0} {1}", newCurrentVersion, app.Target); app.OnVersionInstalled(newCurrentVersion); } catch (Exception ex) { log.ErrorException("App threw exception on install: " + app.GetType().FullName, ex); throw; } var shortcutList = Enumerable.Empty <ShortcutCreationRequest>(); try { shortcutList = app.GetAppShortcutList(); shortcutList.ForEach(x => log.Info("installAppVersion: we have a shortcut {0}", x.TargetPath)); } catch (Exception ex) { log.ErrorException("App threw exception on shortcut uninstall: " + app.GetType().FullName, ex); throw; } shortcutList .Where(x => !shortcutRequestsToIgnore.Contains(x)) .ForEach(x => { var shortcut = x.GetLinkTarget(applicationName, true); var fi = fileSystem.GetFileInfo(shortcut); log.Info("installAppVersion: checking shortcut {0}", fi.FullName); if (fi.Exists) { log.Info("installAppVersion: deleting existing file"); fi.Delete(); } fileSystem.CreateDirectoryRecursive(fi.Directory.FullName); var sl = new ShellLink { Target = x.TargetPath, IconPath = x.IconLibrary, IconIndex = x.IconIndex, Arguments = x.Arguments, WorkingDirectory = x.WorkingDirectory, Description = x.Description, }; sl.Save(shortcut); }); return(app.LaunchOnSetup ? app.Target : null); }
void updateLink(ShellLink shortcut, string[] oldAppDirectories, string newAppPath) { log.Info("Processing shortcut '{0}'", shortcut.Target); foreach (var oldAppDirectory in oldAppDirectories) { if (!shortcut.Target.StartsWith(oldAppDirectory, StringComparison.OrdinalIgnoreCase)) { log.Info("Does not match '{0}', continuing to next directory", oldAppDirectory); continue; } // replace old app path with new app path and check, if executable still exists var newTarget = Path.Combine(newAppPath, shortcut.Target.Substring(oldAppDirectory.Length + 1)); if (fileSystem.GetFileInfo(newTarget).Exists) { shortcut.Target = newTarget; // replace working directory too if appropriate if (shortcut.WorkingDirectory.StartsWith(oldAppDirectory, StringComparison.OrdinalIgnoreCase)) { log.Info("Changing new directory to '{0}'", newAppPath); shortcut.WorkingDirectory = Path.Combine(newAppPath, shortcut.WorkingDirectory.Substring(oldAppDirectory.Length + 1)); } shortcut.Save(); } else { log.Info("Unpinning {0} from taskbar", shortcut.Target); TaskbarHelper.UnpinFromTaskbar(shortcut.Target); } break; } }
string installAppVersion(IAppSetup app, Version newCurrentVersion, IEnumerable<ShortcutCreationRequest> shortcutRequestsToIgnore, bool isFirstInstall) { try { if (isFirstInstall) { log.Info("installAppVersion: Doing first install for {0}", app.Target); app.OnAppInstall(); } log.Info("installAppVersion: Doing install for version {0} {1}", newCurrentVersion, app.Target); app.OnVersionInstalled(newCurrentVersion); } catch (Exception ex) { log.ErrorException("App threw exception on install: " + app.GetType().FullName, ex); throw; } var shortcutList = Enumerable.Empty<ShortcutCreationRequest>(); try { shortcutList = app.GetAppShortcutList(); shortcutList.ForEach(x => log.Info("installAppVersion: we have a shortcut {0}", x.TargetPath)); } catch (Exception ex) { log.ErrorException("App threw exception on shortcut uninstall: " + app.GetType().FullName, ex); throw; } shortcutList .Where(x => !shortcutRequestsToIgnore.Contains(x)) .ForEach(x => { var shortcut = x.GetLinkTarget(applicationName, true); var fi = fileSystem.GetFileInfo(shortcut); log.Info("installAppVersion: checking shortcut {0}", fi.FullName); if (fi.Exists) { log.Info("installAppVersion: deleting existing file"); fi.Delete(); } fileSystem.CreateDirectoryRecursive(fi.Directory.FullName); var sl = new ShellLink { Target = x.TargetPath, IconPath = x.IconLibrary, IconIndex = x.IconIndex, Arguments = x.Arguments, WorkingDirectory = x.WorkingDirectory, Description = x.Description, }; sl.Save(shortcut); }); return app.LaunchOnSetup ? app.Target : null; }