OSDN Git Service

na-get-lib,起動高速化機能追加時にインストール済みソフトのバージョン認識がされていないことがあったのを修正。
[applistation/AppliStation.git] / na-get-lib / NaGet.Net / GuidEnumeratorForCategories.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using Microsoft.Win32;\r
4 \r
5 namespace NaGet.Net\r
6 {\r
7         /// <summary>\r
8         /// ICatManagerの暫定的かつピュアC#実装。レジストリを舐めてICatManagerと同等の機能を実現する。\r
9         /// </summary>\r
10         class GuidEnumeratorForCategories : IEnumerable<Guid>, IDisposable\r
11         {\r
12                 private RegistryKey key;\r
13                 \r
14                 private string[] subkeys;\r
15                 \r
16                 private Guid catGuid;\r
17                 \r
18                 public GuidEnumeratorForCategories(Guid category)\r
19                 {\r
20                         key = Registry.ClassesRoot.OpenSubKey(@"CLSID", false);\r
21                         subkeys = key.GetSubKeyNames();\r
22                         catGuid = category;\r
23                 }\r
24                 \r
25                 public void Dispose()\r
26                 {\r
27                         if (key != null) {\r
28                                 key.Close();\r
29                         }\r
30                         GC.SuppressFinalize(this);\r
31                 }\r
32                 \r
33                 \r
34                 public IEnumerator<Guid> GetEnumerator()\r
35                 {\r
36                         return _getEnumerator();\r
37                 }\r
38                 \r
39                 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()\r
40                 {\r
41                         return _getEnumerator();\r
42                 }\r
43                 \r
44                 private IEnumerator<Guid> _getEnumerator()\r
45                 {\r
46                         // レジストリ内のImplemented Category内の値と比較する値\r
47                         string strCategory = catGuid.ToString("B").ToUpper();\r
48                         \r
49                         foreach (string subkey in subkeys) {\r
50                                 // "CLSID"、基本タイプ("...046}")は無視する\r
51                                 if ((subkey == "CLSID") ||\r
52                                      subkey.EndsWith("-0000-0000-C000-000000000046}", StringComparison.OrdinalIgnoreCase)) {\r
53                                         continue;\r
54                                 }\r
55 \r
56                                 // Implemented Categoryにあれば、subkeyをGUIDに変換して返す\r
57                                 RegistryKey guidKey = key.OpenSubKey(string.Format(@"{0}\Implemented Categories\{1}", subkey, strCategory), false);\r
58                                 if (guidKey != null) {\r
59                                         guidKey.Close();\r
60                                         yield return new Guid(subkey);\r
61                                 }\r
62                         }\r
63                 }\r
64         }\r
65 }\r