2 using System.Collections.Generic;
\r
3 using System.Text.RegularExpressions;
\r
4 using Microsoft.Win32;
\r
6 namespace NaGet.Packages.Install
\r
9 /// レジストリ登録されているアンインストーラに関するユーティリティ
\r
11 public sealed class RegistriedUninstallers
\r
14 /// アンインストーラのレジストリの格納されているルートキーの文字列表現
\r
16 public const string UninstallersKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
\r
19 /// アンインストーラのレジストリの格納されているルートキーの文字列表現
\r
21 public const string UninstallersKeyWow6432 = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
\r
24 /// アンインストーラのレジストリのキーを返す。
\r
26 public static IEnumerable<RegistryKey> RegistryKeies {
\r
28 RegistryKey key = null;
\r
34 key = Registry.LocalMachine.OpenSubKey(UninstallersKey, false);
\r
35 } catch (System.Security.SecurityException) {
\r
42 // UninstallersKeyWow6432
\r
44 key = Registry.LocalMachine.OpenSubKey(UninstallersKeyWow6432, false);
\r
45 } catch (System.Security.SecurityException) {
\r
56 key = Registry.CurrentUser.OpenSubKey(UninstallersKey, false);
\r
57 } catch (System.Security.SecurityException) {
\r
64 // UninstallersKeyWow6432
\r
66 key = Registry.CurrentUser.OpenSubKey(UninstallersKeyWow6432, false);
\r
67 } catch (System.Security.SecurityException) {
\r
78 /// アンインストーラをイテレートする
\r
80 public static IEnumerable<UninstallInformation> Uninstallers {
\r
82 foreach (RegistryKey regkey in RegistryKeies) {
\r
83 foreach (string key in regkey.GetSubKeyNames()) {
\r
84 UninstallInformation info;
\r
85 using (RegistryKey subregkey = regkey.OpenSubKey(key, false)) {
\r
86 info = UninstallInformation.NewInstance(subregkey);
\r
89 if (info.IsOSPatch || info.IsSystemComponent || string.IsNullOrEmpty(info.DisplayName) ) {
\r
100 /// レジストリを走査してインストール済みのソフトを検出する
\r
102 /// <param name="list">
\r
106 /// インストール済みのパッケージを返すイテレータ
\r
108 public static IEnumerable<InstalledPackage> DetectInstalledPackages(PackageList<Package> pkgList)
\r
110 foreach (UninstallInformation info in RegistriedUninstallers.Uninstallers) {
\r
111 foreach (Package pkg in pkgList) {
\r
112 if (pkg.Type != InstallerType.ARCHIVE
\r
113 && pkg.Type != InstallerType.ITSELF
\r
114 && pkg.UninstallerKey != null) {
\r
115 Match match = Regex.Match(info.DisplayName, pkg.UninstallerKey);
\r
117 if (match.Success) {
\r
118 yield return InstalledPackage.PackageConverter(pkg, info);
\r
128 /// パッケージに対応するインストールパッケージを返す。
\r
129 /// インストール終了確認などに使用。
\r
131 /// <param name="pkg">対応するパッケージ</param>
\r
132 /// <returns>インストール情報</returns>
\r
133 public static InstalledPackage GetInstalledPackageFor(Package pkg)
\r
135 if (pkg.Type == InstallerType.ARCHIVE
\r
136 || pkg.Type == InstallerType.ITSELF
\r
137 || pkg.Type == InstallerType.CANNOT_INSTALL) {
\r
141 foreach (UninstallInformation info in RegistriedUninstallers.Uninstallers) {
\r
142 Match match = Regex.Match(info.DisplayName, pkg.UninstallerKey);
\r
144 if (match.Success) {
\r
145 return InstalledPackage.PackageConverter(pkg, info);
\r