/// <summary> /// Called when a shortcut is extracted from the installer and needs to be installed to the device OS /// </summary> /// <param name="shortcutInfo"></param> public virtual void OnInstallShortcut(ref ShortcutInstallInfo shortcutInfo) { string shortcutFile = SI.Path.Combine(shortcutInfo.ShortcutLocation, shortcutInfo.ShortcutName); if (!SI.File.Exists(shortcutInfo.TargetLocation)) { if (ShortcutFailure != null) { bool cancel = false; ShortcutFailure(shortcutInfo, new SI.FileNotFoundException("Target file does not exist"), ref cancel); if (!cancel) { m_failedShortcuts++; } } else { m_failedShortcuts++; } return; } using (SI.TextWriter writer = SI.File.CreateText(shortcutFile)) { int length = shortcutInfo.TargetLocation.Length; length += (length.ToString().Length + 1); writer.Write(string.Format("{0}#{1}", length, shortcutInfo.TargetLocation)); } }
/// <summary> /// Installs all shortcuts packaged in the installer to the local device /// </summary> public void InstallShortcuts() { m_failedShortcuts = 0; if (m_descriptor.Shortcuts == null) { return; } foreach (InstallerLink link in m_descriptor.Shortcuts) { InstallerFile file = m_descriptor.GetFileByFileID(link.TargetFileID); string targetFolder = ReplaceSpecialFolderStrings(string.Copy(m_descriptor.GetDirectoryByID(file.DirectoryID).GetString(m_descriptor.Strings))); string targetFile = string.Copy(file.FileName); string shortcutName = link.GetString(m_descriptor.Strings); string shortcutLocation = ReplaceSpecialFolderStrings(link.ShortcutLocation.ToString()); ShortcutInstallInfo shortcutInfo = null; try { shortcutInfo = new ShortcutInstallInfo(shortcutLocation, shortcutName, SI.Path.Combine(targetFolder, targetFile)); OnInstallShortcut(ref shortcutInfo); } catch (Exception ex) { if (ShortcutFailure != null) { bool cancel = false; ShortcutFailure(shortcutInfo, ex, ref cancel); if (!cancel) { m_failedShortcuts++; } } else { m_failedShortcuts++; } } } }