/// <summary> /// Unregisters an application as a candidate for a default program in the current system. This can only be applied machine-wide, not per user. /// </summary> /// <param name="defaultProgram">The default program information to be removed.</param> /// <param name="accessPoint">Indicates that the program was set as the current default for the service it provides.</param> /// <exception cref="IOException">A problem occurs while writing to the filesystem or registry.</exception> /// <exception cref="UnauthorizedAccessException">Write access to the filesystem or registry is not permitted.</exception> /// <exception cref="InvalidDataException">The data in <paramref name="defaultProgram"/> is invalid.</exception> public static void Unregister([NotNull] Store.Model.Capabilities.DefaultProgram defaultProgram, bool accessPoint = false) { #region Sanity checks if (defaultProgram == null) { throw new ArgumentNullException("defaultProgram"); } #endregion if (string.IsNullOrEmpty(defaultProgram.ID)) { throw new InvalidDataException("Missing ID"); } if (string.IsNullOrEmpty(defaultProgram.Service)) { throw new InvalidDataException("Missing Service"); } using (var serviceKey = Registry.LocalMachine.OpenSubKey(RegKeyMachineClients + @"\" + defaultProgram.Service, writable: true)) { if (accessPoint) { // TODO: Restore previous default } // Remove appropriate purpose flag and check if there are others bool otherFlags; using (var appKey = serviceKey.OpenSubKey(defaultProgram.ID, writable: true)) { if (appKey == null) { otherFlags = false; } else { appKey.DeleteValue(accessPoint ? FileType.PurposeFlagAccessPoint : FileType.PurposeFlagCapability, throwOnMissingValue: false); otherFlags = appKey.GetValueNames().Any(name => name.StartsWith(FileType.PurposeFlagPrefix)); } } // Delete app key if there are no other references if (!otherFlags) { try { serviceKey.DeleteSubKeyTree(defaultProgram.ID); } #region Error handling catch (ArgumentException) { // Ignore missing registry keys } #endregion } } }
/// <summary> /// Unregisters an application as a candidate for a default program in the current system. This can only be applied machine-wide, not per user. /// </summary> /// <param name="defaultProgram">The default program information to be removed.</param> /// <param name="machineWide">Apply the registration machine-wide instead of just for the current user.</param> /// <param name="accessPoint">Indicates that the program was set as the current default for the service it provides.</param> /// <exception cref="IOException">A problem occurs while writing to the filesystem.</exception> /// <exception cref="UnauthorizedAccessException">Write access to the filesystem is not permitted.</exception> /// <exception cref="InvalidDataException">The data in <paramref name="defaultProgram"/> is invalid.</exception> public static void Unregister([NotNull] Store.Model.Capabilities.DefaultProgram defaultProgram, bool machineWide, bool accessPoint = false) { #region Sanity checks if (defaultProgram == null) { throw new ArgumentNullException(nameof(defaultProgram)); } #endregion if (string.IsNullOrEmpty(defaultProgram.ID)) { throw new InvalidDataException("Missing ID"); } if (string.IsNullOrEmpty(defaultProgram.Service)) { throw new InvalidDataException("Missing Service"); } // TODO: Implement }
/// <summary> /// Registers an application as a candidate for a default program for some service in the current system. /// </summary> /// <param name="target">The application being integrated.</param> /// <param name="defaultProgram">The default program information to be registered.</param> /// <param name="machineWide">Apply the registration machine-wide instead of just for the current user.</param> /// <param name="handler">A callback object used when the the user is to be informed about the progress of long-running operations such as downloads.</param> /// <param name="accessPoint">Indicates that the program should be set as the current default for the service it provides.</param> /// <exception cref="OperationCanceledException">The user canceled the task.</exception> /// <exception cref="IOException">A problem occurs while writing to the filesystem.</exception> /// <exception cref="WebException">A problem occured while downloading additional data (such as icons).</exception> /// <exception cref="UnauthorizedAccessException">Write access to the filesystem is not permitted.</exception> /// <exception cref="InvalidDataException">The data in <paramref name="defaultProgram"/> is invalid.</exception> public static void Register(FeedTarget target, [NotNull] Store.Model.Capabilities.DefaultProgram defaultProgram, bool machineWide, [NotNull] ITaskHandler handler, bool accessPoint = false) { #region Sanity checks if (defaultProgram == null) { throw new ArgumentNullException("defaultProgram"); } if (handler == null) { throw new ArgumentNullException("handler"); } #endregion if (string.IsNullOrEmpty(defaultProgram.ID)) { throw new InvalidDataException("Missing ID"); } if (string.IsNullOrEmpty(defaultProgram.Service)) { throw new InvalidDataException("Missing Service"); } // TODO: Implement }
/// <summary> /// Registers an application as a candidate for a default program for some service in the current system. This can only be applied machine-wide, not per user. /// </summary> /// <param name="target">The application being integrated.</param> /// <param name="defaultProgram">The default program information to be registered.</param> /// <param name="handler">A callback object used when the the user is to be informed about the progress of long-running operations such as downloads.</param> /// <param name="accessPoint">Indicates that the program should be set as the current default for the service it provides.</param> /// <exception cref="OperationCanceledException">The user canceled the task.</exception> /// <exception cref="IOException">A problem occurs while writing to the filesystem or registry.</exception> /// <exception cref="WebException">A problem occured while downloading additional data (such as icons).</exception> /// <exception cref="UnauthorizedAccessException">Write access to the filesystem or registry is not permitted.</exception> /// <exception cref="InvalidDataException">The data in <paramref name="defaultProgram"/> is invalid.</exception> public static void Register(FeedTarget target, [NotNull] Store.Model.Capabilities.DefaultProgram defaultProgram, [NotNull] ITaskHandler handler, bool accessPoint = false) { #region Sanity checks if (defaultProgram == null) { throw new ArgumentNullException("defaultProgram"); } if (handler == null) { throw new ArgumentNullException("handler"); } #endregion if (string.IsNullOrEmpty(defaultProgram.ID)) { throw new InvalidDataException("Missing ID"); } if (string.IsNullOrEmpty(defaultProgram.Service)) { throw new InvalidDataException("Missing Service"); } using (var serviceKey = Registry.LocalMachine.CreateSubKeyChecked(RegKeyMachineClients + @"\" + defaultProgram.Service)) { using (var appKey = serviceKey.CreateSubKeyChecked(defaultProgram.ID)) { // Add flag to remember whether created for capability or access point appKey.SetValue(accessPoint ? FileType.PurposeFlagAccessPoint : FileType.PurposeFlagCapability, ""); appKey.SetValue("", target.Feed.Name); FileType.RegisterVerbCapability(appKey, target, defaultProgram, true, handler); // Set callbacks for Windows SPAD using (var installInfoKey = appKey.CreateSubKeyChecked(RegSubKeyInstallInfo)) { string exePath = Path.Combine(Locations.InstallBase, "0install-win.exe").EscapeArgument(); installInfoKey.SetValue(RegValueReinstallCommand, exePath + " integrate-app --machine --batch --add=defaults " + target.Uri.ToStringRfc().EscapeArgument()); installInfoKey.SetValue(RegValueShowIconsCommand, exePath + " integrate-app --machine --batch --add=icons " + target.Uri.ToStringRfc().EscapeArgument()); installInfoKey.SetValue(RegValueHideIconsCommand, exePath + " integrate-app --machine --batch --remove=icons " + target.Uri.ToStringRfc().EscapeArgument()); installInfoKey.SetValue(RegValueIconsVisible, 0, RegistryValueKind.DWord); } if (defaultProgram.Service == Store.Model.Capabilities.DefaultProgram.ServiceMail) { var mailToProtocol = new Store.Model.Capabilities.UrlProtocol { Verbs = { new Verb { Name = Verb.NameOpen } } }; using (var mailToKey = appKey.CreateSubKeyChecked(@"Protocols\mailto")) FileType.RegisterVerbCapability(mailToKey, target, mailToProtocol, true, handler); } } if (accessPoint) { serviceKey.SetValue("", defaultProgram.ID); } } }
/// <summary> /// Toggles the registry entry indicating whether icons for the application are currently visible. /// </summary> /// <param name="defaultProgram">The default program information to be modified.</param> /// <param name="iconsVisible"><see langword="true"/> if the icons are currently visible, <see langword="false"/> if the icons are currently not visible.</param> internal static void ToggleIconsVisible(Store.Model.Capabilities.DefaultProgram defaultProgram, bool iconsVisible) { using (var installInfoKey = Registry.LocalMachine.OpenSubKeyChecked(RegKeyMachineClients + @"\" + defaultProgram.Service + @"\" + defaultProgram.ID + @"\" + RegSubKeyInstallInfo, writable: true)) installInfoKey.SetValue(RegValueIconsVisible, iconsVisible ? 1 : 0, RegistryValueKind.DWord); }