public void CreateShortcuts(UpdateInfo updateInfo) { var appPath = _pathProvider.GetAppPath(updateInfo); foreach (var shortcut in GetShortcuts(updateInfo)) { try { var lnkFilename = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), shortcut.Title + ".lnk"); var target = Path.Combine(appPath, shortcut.TargetPath); if (!File.Exists(target)) { _logger.Warn("File \"{0}\" does not exist, nevertheless we'll create the shortcut."); } new ShellLink { Target = target, Description = shortcut.Description, Arguments = shortcut.Arguments, IconPath = shortcut.IconPath, IconIndex = shortcut.IconIndex, }.Save(lnkFilename); _logger.Info("Created shortcut for \"{0}\" at \"{1}\".", target, lnkFilename); } catch (Exception ex) { _logger.ErrorException(String.Format("Creating shortcut \"{0}\" to \"{1}\" failed", shortcut.Title, shortcut.TargetPath), ex); } } }
private IEnumerable<Shortcut> GetShortcuts(UpdateInfo updateInfo) { var nuUpdateConfigPath = Path.Combine(_pathProvider.GetAppPath(updateInfo), "NuUpdate.xml"); var instructions = File.Exists(nuUpdateConfigPath) ? UpdateInstructions.Load(nuUpdateConfigPath) : null; if (instructions != null && instructions.Shortcuts != null && instructions.Shortcuts.Length > 0) { _logger.Info("Found shortcut information in update instructions."); return instructions.Shortcuts; } else { _logger.Info("No update instructions found, creating a shortcut for each executable in start menu."); return Directory .EnumerateFiles(_pathProvider.GetAppPath(updateInfo), "*.exe") .Select(exePath => new Shortcut { Title = Path.GetFileNameWithoutExtension(exePath), TargetPath = exePath, }); } }
public void UpdateUninstallInformation(UpdateInfo updateInfo) { var installPath = Path.Combine(_pathProvider.AppPathBase, "install.exe"); var estimatedSize = ( GetFolderSize(_pathProvider.GetAppPath(updateInfo)) + GetFolderSize(_pathProvider.NuGetCachePath) + new FileInfo(installPath).Length) >> 10; using ( var keyUninstall = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall", true)) { Debug.Assert(keyUninstall != null, "keyUninstall != null"); using (var key = keyUninstall.OpenSubKey(_packageId, true) ?? keyUninstall.CreateSubKey(_packageId)) { Debug.Assert(key != null, "key != null"); if (updateInfo.Package.IconUrl != null) { key.SetValue("DisplayIcon", updateInfo.Package.IconUrl); } else { key.SetValue("DisplayIcon", installPath + ",0"); } key.SetValue("DisplayName", updateInfo.Package.Id, RegistryValueKind.String); key.SetValue("DisplayVersion", updateInfo.Version.ToString(), RegistryValueKind.String); key.SetValue("InstallDate", DateTimeOffset.Now.ToString("yyyyMMdd")); key.SetValue("UninstallString", installPath + " /uninstall", RegistryValueKind.ExpandString); key.SetValue("InstallLocation", _pathProvider.AppPathBase, RegistryValueKind.ExpandString); key.SetValue("Publisher", String.Join(", ", updateInfo.Package.Authors), RegistryValueKind.String); key.SetValue("VersionMajor", updateInfo.Version.Version.Major, RegistryValueKind.DWord); key.SetValue("VersionMinor", updateInfo.Version.Version.Minor, RegistryValueKind.DWord); key.SetValue("EstimatedSize", estimatedSize, RegistryValueKind.DWord); key.SetValue("NoModify", 1, RegistryValueKind.DWord); } } }
public void DownloadPackage(UpdateInfo updateInfo, Action<int> callbackPercentCompleted = null) { var onProgressAvailable = callbackPercentCompleted != null ? (sender, args) => callbackPercentCompleted(args.PercentComplete) : (EventHandler<ProgressEventArgs>)null; if (onProgressAvailable != null) { ProgressAvailable += onProgressAvailable; } // this line forces NuGet to download the package updateInfo.Package.HasProjectContent(); if (onProgressAvailable != null) { ProgressAvailable -= onProgressAvailable; } }
public void CreateShortcuts(UpdateInfo updateInfo) { new ShortcutHandler(_pathProvider).CreateShortcuts(updateInfo); }
public UpdateInfo CheckForUpdate(bool includePrereleases = false) { var versionSpec = _currentVersion != null ? new VersionSpec { MinVersion = new SemanticVersion(_currentVersion), IsMinInclusive = false } : null; var packages = _packageRepository.FindPackages(_packageId, versionSpec, includePrereleases, true).ToArray(); _availableUpdates = packages.Select(p => new UpdateInfo(p)).ToList(); RaiseAvailableUpdatesChanged(); // IsAbsoluteLatestVersion and IsLatestVersion are not what I expected them to be... //_latestPackage = _availableUpdates.SingleOrDefault( // p => includePrereleases ? p.Package.IsAbsoluteLatestVersion : p.Package.IsLatestVersion) // ?? _availableUpdates.OrderByDescending(p => p.Version).FirstOrDefault(); _latestPackage = _availableUpdates.OrderByDescending(p => p.Version).FirstOrDefault(); if (_latestPackage == null) { _logger.Debug("No updates found"); } else { _logger.Debug("Found {0} updates, latest is {1}", _availableUpdates.Count, _latestPackage.Version); } return _latestPackage; }
public void ApplyUpdate(UpdateInfo updateInfo) { var targetFolder = _pathProvider.GetAppPath(updateInfo); _logger.Info("Target path is " + targetFolder); if (Directory.Exists(targetFolder)) { Directory.Delete(targetFolder, true); } Directory.CreateDirectory(targetFolder); foreach (var contentFile in GetFiles(updateInfo.Package)) { _logger.Info("Extracting " + contentFile.Item1.Path); var targetPath = Path.Combine(targetFolder, contentFile.Item2); var targetDir = Path.GetDirectoryName(targetPath); if (targetDir != null && !Directory.Exists(targetDir)) { Directory.CreateDirectory(targetDir); } using (var input = contentFile.Item1.GetStream()) { using (var output = File.Create(targetPath)) { input.CopyTo(output); } } } }
public string GetAppPath(UpdateInfo updateInfo) { return GetAppPath(updateInfo.Version); }