2 using System.Xml.Serialization;
\r
3 using Microsoft.Win32;
\r
5 namespace NaGet.Packages.Install
\r
8 /// アンインストール情報の抽象化クラス
\r
10 public class UninstallInformation
\r
15 public string DisplayName;
\r
18 /// バージョン。DisplayVersion
\r
20 public string DisplayVersion;
\r
25 public string Publisher;
\r
28 /// アイコンのパス。DisplayIcon
\r
30 public string IconPath;
\r
33 /// 「変更」・「修復」のコマンド文字列。ModifyPath
\r
35 public string ModifyPath;
\r
38 /// 「アンインストール」のコマンド文字列。UninstallString
\r
40 public string UninstallString;
\r
43 /// サイレントアンインストールのコマンド文字列。QuietUninstallString
\r
45 public string QuietUninstallString;
\r
50 public string URLInfoAbout;
\r
53 /// 「変更」ができるか否かのフラグ。NoModifyの逆(きちんと動かない??)
\r
55 public bool CanModify = false;
\r
58 /// 「修復」ができるか否かのフラグ。NoRepairの逆(きちんと動かない??)
\r
60 public bool CanRepair = false;
\r
63 /// 「アンインストール」ができるか否かのフラグ。NoRemoveの逆
\r
65 public bool CanRemove = true;
\r
70 public bool IsSystemComponent = false;
\r
75 public bool IsOSPatch = false;
\r
78 /// アンインストールにmsiexecを使うか否か
\r
80 public bool WindowsInstaller = false;
\r
86 public DateTime? InstallDate = null;
\r
89 /// ソフトをインストールした日付、のレジストリ登録文字列表現
\r
91 [XmlElement("InstallDate")]
\r
92 public string InstallDateString {
\r
93 get { return (InstallDate != null)? InstallDate.Value.ToString("yyyyMMdd") : null; }
\r
95 if ((! string.IsNullOrEmpty(value)) &&
\r
96 System.Text.RegularExpressions.Regex.IsMatch(value, @"^[0-9]{8}$")) {
\r
98 InstallDate = new DateTime(
\r
99 int.Parse(value.Substring(0,4)),
\r
100 int.Parse(value.Substring(4,2)),
\r
101 int.Parse(value.Substring(6,2))
\r
103 } catch (Exception) {
\r
106 InstallDate = null;
\r
114 public string InstallLocation;
\r
117 /// (推定の)アプリケーションの占有する容量(キロバイト単位)
\r
119 public int EstimatedSize = 0;
\r
124 /// レジストリのキーからアンインストール情報を取得する
\r
126 /// <param name="regKey">アンインストール情報を示す</param>
\r
127 /// <returns>生成されたアンインストール</returns>
\r
128 public static UninstallInformation NewInstance(RegistryKey regKey)
\r
130 UninstallInformation uninstInfo = new UninstallInformation();
\r
132 uninstInfo.DisplayName = (regKey.GetValue("DisplayName") as string) ?? string.Empty;
\r
133 uninstInfo.DisplayVersion = regKey.GetValue("DisplayVersion", null) as string;
\r
134 uninstInfo.Publisher = regKey.GetValue("Publisher", null) as string;
\r
135 uninstInfo.URLInfoAbout = regKey.GetValue("URLInfoAbout", null) as string;
\r
136 uninstInfo.IconPath = regKey.GetValue("DisplayIcon", null) as string;
\r
137 uninstInfo.ModifyPath = regKey.GetValue("ModifyPath", null) as string;
\r
138 uninstInfo.UninstallString = regKey.GetValue("UninstallString", null) as string;
\r
139 uninstInfo.QuietUninstallString = regKey.GetValue("QuietUninstallString", null) as string;
\r
141 uninstInfo.CanModify = ((int) regKey.GetValue("NoModify", 1)) != 1;
\r
142 } catch (InvalidCastException) {}
\r
144 uninstInfo.CanRepair = ((int) regKey.GetValue("NoRepair", 1)) != 1;
\r
145 } catch (InvalidCastException) {}
\r
147 uninstInfo.CanRemove = ((int) regKey.GetValue("NoRemove", 1)) != 1;
\r
148 } catch (InvalidCastException) {}
\r
150 uninstInfo.WindowsInstaller = ((int) regKey.GetValue("WindowsInstaller", 0)) == 1;
\r
151 } catch (InvalidCastException) {}
\r
153 uninstInfo.IsSystemComponent = ((int) regKey.GetValue("SystemComponent", 0)) > 0;
\r
154 } catch (InvalidCastException) {}
\r
155 uninstInfo.IsOSPatch = (regKey.GetValue("ParentKeyName", null) as string) == "OperatingSystem";
\r
156 uninstInfo.InstallDateString = regKey.GetValue("InstallDate", null) as string;
\r
157 uninstInfo.InstallLocation = regKey.GetValue("InstallLocation", null) as string;
\r
159 uninstInfo.EstimatedSize = (int) regKey.GetValue("EstimatedSize", 0);
\r
160 } catch (InvalidCastException) {}
\r
162 PrefixWithSlowInfoCache(ref uninstInfo, regKey);
\r
168 /// SlowInfoCacheを読み込んで情報を補完
\r
170 /// <param name="uninstInfo">アンインストール情報</param>
\r
171 /// <param name="regKey">元のレジストリキー</param>
\r
172 private static void PrefixWithSlowInfoCache(ref UninstallInformation uninstInfo, RegistryKey regKey)
\r
175 byte[] slowInfoCache;
\r
177 string arpCacheKey = string.Format(@"{0}\..\..\App Management\ARPCache\{1}", regKey.Name, System.IO.Path.GetFileName(regKey.Name));
\r
178 arpCacheKey = NaGet.Utils.GetDotsRemovedPath(arpCacheKey);
\r
179 slowInfoCache = (byte[]) Registry.GetValue(arpCacheKey, "SlowInfoCache", null);
\r
181 if (slowInfoCache == null || slowInfoCache.Length <= 0) {
\r
182 arpCacheKey = @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Management\ARPCache\"+System.IO.Path.GetFileName(regKey.Name);
\r
183 slowInfoCache = (byte[]) Registry.GetValue(arpCacheKey, "SlowInfoCache", null);
\r
186 if (slowInfoCache != null && slowInfoCache.Length > 0) {
\r
187 Int32 size = BitConverter.ToInt32(slowInfoCache, 0);
\r
188 Int32 hasName = BitConverter.ToInt32(slowInfoCache, 4);
\r
189 Int64 installSize = BitConverter.ToInt64(slowInfoCache, 8);
\r
190 //Int64 lastUsed = BitConverter.ToInt64(slowInfoCache, 16);
\r
191 //Int32 freq = BitConverter.ToInt32(slowInfoCache, 24);
\r
193 if (installSize > 0) {
\r
194 uninstInfo.EstimatedSize = (int)(installSize >> 10);
\r
197 string filename = null;
\r
198 if (hasName != 0) {
\r
201 while (pos < slowInfoCache.Length) {
\r
202 if (slowInfoCache[pos] == 0) {
\r
208 filename = System.Text.Encoding.Unicode.GetString(slowInfoCache, offset, pos-offset);
\r
210 if (string.IsNullOrEmpty(uninstInfo.IconPath) && System.IO.File.Exists(filename)) {
\r
211 uninstInfo.IconPath = filename;
\r
215 } catch (Exception) {
\r
220 /// パッケージ情報からアンインストーラー情報を生成する
\r
222 /// <param name="pkg">パッケージ</param>
\r
223 /// <returns>生成されたアンインストール</returns>
\r
224 public static UninstallInformation NewInstance(Package pkg)
\r
226 UninstallInformation uninstInfo = new UninstallInformation();
\r
228 uninstInfo.DisplayName = pkg.Name;
\r
229 uninstInfo.DisplayVersion = pkg.Version;
\r
230 uninstInfo.Publisher = pkg.Author;
\r
231 uninstInfo.URLInfoAbout = (pkg.Url != null)? pkg.Url.Href : null;
\r
232 uninstInfo.IconPath = null; // TODO
\r
233 uninstInfo.ModifyPath = null;
\r
234 uninstInfo.UninstallString = null; // TODO
\r
235 uninstInfo.CanModify = false;
\r
236 uninstInfo.CanRepair = false;
\r
237 uninstInfo.CanRemove = true;
\r
238 uninstInfo.WindowsInstaller = false;
\r
239 uninstInfo.IsSystemComponent = false;
\r
240 uninstInfo.IsOSPatch = false;
\r
241 uninstInfo.InstallLocation = null;
\r
242 uninstInfo.InstallDate = null;
\r
243 uninstInfo.EstimatedSize = 0;
\r