OSDN Git Service

na-get-lib,ダウンロードファイル名をContent-Dispositionヘッダから取得するコードを独自コードに変更し、不明慮なライセンスのコードを消去した
[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                 }\r
31                 \r
32                 \r
33                 public IEnumerator<Guid> GetEnumerator()\r
34                 {\r
35                         return _getEnumerator();\r
36                 }\r
37                 \r
38                 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()\r
39                 {\r
40                         return _getEnumerator();\r
41                 }\r
42                 \r
43                 private IEnumerator<Guid> _getEnumerator()\r
44                 {\r
45                         // レジストリ内のImplemented Category内の値と比較する値\r
46                         string strCategory = catGuid.ToString("B").ToUpper();\r
47                         \r
48                         foreach (string subkey in subkeys) {\r
49                                 // "CLSID"、基本タイプ("...046}")は無視する\r
50                                 if ((subkey == "CLSID") ||\r
51                                      subkey.EndsWith("-0000-0000-C000-000000000046}", StringComparison.OrdinalIgnoreCase)) {\r
52                                         continue;\r
53                                 }\r
54 \r
55                                 // Implemented Categoryにあれば、subkeyをGUIDに変換して返す\r
56                                 RegistryKey guidKey = key.OpenSubKey(string.Format(@"{0}\Implemented Categories\{1}", subkey, strCategory), false);\r
57                                 if (guidKey != null) {\r
58                                         guidKey.Close();\r
59                                         yield return new Guid(subkey);\r
60                                 }\r
61                         }\r
62                 }\r
63         }\r
64 }\r