OSDN Git Service

na-get-lib,all-get,インストール除外リストの設定を追加。all-get.exeのcheckupgrade表示への反映
[applistation/AppliStation.git] / na-get-lib / NaGet / Env.cs
1 using System;\r
2 using System.IO;\r
3 using System.Net;\r
4 \r
5 namespace NaGet\r
6 {\r
7         /// <summary>\r
8         /// 環境変数などを取り扱うクラス\r
9         /// </summary>\r
10         public sealed class Env\r
11         {               \r
12                 /// <summary>\r
13                 /// 呼び出し禁止\r
14                 /// </summary>\r
15                 private Env()\r
16                 {\r
17                 }\r
18                 \r
19                 #region pref.xml関連\r
20                 \r
21                 /// <summary>\r
22                 /// 設定を格納\r
23                 /// </summary>\r
24                 private static NaGetLibPref pref;\r
25                 \r
26                 /// <summary>\r
27                 /// 設定(のクローンオブジェクト)を返す。\r
28                 /// </summary>\r
29                 public static NaGetLibPref Pref {\r
30                         get {\r
31                                 NaGetLibPref prefCopied = new NaGetLibPref();\r
32                                 \r
33                                 if (pref == null) {\r
34                                         LoadPref();\r
35                                 }\r
36                                 NaGet.Utils.FieldCopy(pref, ref prefCopied);\r
37                                 \r
38                                 return prefCopied;\r
39                         }\r
40                 }\r
41                 \r
42                 /// <summary>\r
43                 /// 設定ファイルのある場所を取得する\r
44                 /// </summary>\r
45                 public static string PrefPath {\r
46                         get {\r
47                                 return Path.Combine(Environment.CurrentDirectory, "pref.xml");\r
48                         }\r
49                 }\r
50                 \r
51                 /// <summary>\r
52                 /// 設定ファイルを読み込む。または再読み込みする。\r
53                 /// </summary>\r
54                 public static void LoadPref()\r
55                 {\r
56                         string path = PrefPath;\r
57                         try {\r
58                                 if (! File.Exists(path)) throw new FileNotFoundException(string.Empty, path);\r
59                                 pref = NaGet.Utils.GetDeserializedObject<NaGetLibPref>(path);\r
60                         } catch(Exception) {\r
61                                 pref = new NaGetLibPref();\r
62                         }\r
63                 }\r
64                 \r
65                 \r
66                 #endregion\r
67 \r
68                 #region ファイルパス\r
69                 \r
70                 /// <summary>\r
71                 /// ファイルリスト提供レポジトリリストのファイル\r
72                 /// </summary>\r
73                 public static readonly string RepositoriesListFile = "repos.list.xml";\r
74 \r
75                 /// <summary>\r
76                 /// ファイルリストから読み込まれたパッケージのリストファイル\r
77                 /// </summary>\r
78                 public static readonly string PackageListFile = "packages.list.xml";\r
79 \r
80                 /// <summary>\r
81                 /// 本ソフトウェアを介してインストールされたパッケージのリストファイル\r
82                 /// </summary>\r
83                 public static readonly string ArchiveInstalledPackageListFile = "packages.envinstalled.xml";\r
84 \r
85                 /// <summary>\r
86                 /// システムから検出されたパッケージのリストファイル\r
87                 /// </summary>\r
88                 public static readonly string SystemInstalledPackageListFile = "packages.sysinstalled.xml";\r
89                 \r
90                 /// <summary>\r
91                 /// インストールログファイル\r
92                 /// </summary>\r
93                 public static readonly string SystemInstalledPackageLogFile = "packages.sysinstalled.log.xml";\r
94                 \r
95                 /// <summary>\r
96                 /// アプリケーションデータを保存するフォルダーのパス\r
97                 /// </summary>\r
98                 public static string AppDataFolderPath\r
99                 {\r
100                         get {\r
101                                 if (pref == null) LoadPref();\r
102                                 \r
103                                 if (! string.IsNullOrEmpty(pref.AppDataFolder)) {\r
104                                         return pref.AppDataFolder;\r
105                                 }\r
106                                 \r
107                                 return Environment.CurrentDirectory;\r
108                         }\r
109                 }\r
110 \r
111                 /// <summary>\r
112                 /// インストーラーの一時置き場の親ディレクトリ\r
113                 /// </summary>\r
114                 public static string ArchiveFolderPath\r
115                 {\r
116                         get {\r
117                                 if (pref == null) LoadPref();\r
118 \r
119                                 if (! string.IsNullOrEmpty(pref.CacheFolder)) {\r
120                                         return pref.CacheFolder;\r
121                                 }\r
122                                 \r
123                                 return Path.Combine(AppDataFolderPath, "Cache");\r
124                         \r
125                         }\r
126                 }\r
127                 \r
128                 /// <summary>\r
129                 /// アーカイバ方式のパッケージのインストール先フォルダー\r
130                 /// </summary>\r
131                 public static string ArchiveProgramFiles {\r
132                         get {\r
133                                 return Path.Combine(AppDataFolderPath, "progs");\r
134                         }\r
135                 }\r
136                 \r
137                 /// <summary>\r
138                 /// アーカイバ方式のパッケージのプログラムグループフォルダー\r
139                 /// </summary>\r
140                 public static string ArchiveProgramGroup {\r
141                         get {\r
142                                 return Path.Combine(AppDataFolderPath, "programs");\r
143                         }\r
144                 }\r
145 \r
146                 /// <summary>\r
147                 /// アーカイバ方式のパッケージのSystem32のフォルダー\r
148                 /// </summary>\r
149                 public static string ArchiveSystem32 {\r
150                         get {\r
151                                 return Path.Combine(ArchiveProgramFiles, ".system32");\r
152                         }\r
153                 }\r
154                 \r
155                 #endregion\r
156                 \r
157                 #region ネットワーク\r
158                 \r
159                 /// <summary>\r
160                 /// ウェブアクセスのためのプロキシを取得する。\r
161                 /// </summary>\r
162                 /// <returns>プロキシ</returns>\r
163                 public static IWebProxy WebProxy\r
164                 {\r
165                         get {\r
166                                 if (pref == null) LoadPref();\r
167                                 \r
168                                 if (string.IsNullOrEmpty(pref.ProxyAddress)) {\r
169                                         // 設定されていないときはシステムのデフォルトを使う\r
170                                         return WebRequest.GetSystemWebProxy();\r
171                                 } else if (pref.ProxyAddress == "-") {\r
172                                         // "-"のとき直接接続\r
173                                         return null;\r
174                                 } else {\r
175                                         // host:portが設定されているならば、それをもとに設定\r
176                                         WebProxy proxy = new WebProxy(pref.ProxyAddress);\r
177                                         \r
178                                         // 認証プロキシの場合、認証情報を付加する\r
179                                         try {\r
180                                                 Uri uri = new Uri(pref.ProxyAddress);\r
181                                                 if (! string.IsNullOrEmpty(uri.UserInfo)) {\r
182                                                         int pos = uri.UserInfo.IndexOf(':');\r
183                                                         if (pos >= 0) {\r
184                                                                 proxy.Credentials = new NetworkCredential(\r
185                                                                         uri.UserInfo.Substring(0, pos),\r
186                                                                         uri.UserInfo.Substring(pos+1)\r
187                                                                 );\r
188                                                         }\r
189                                                 }\r
190                                         } catch (Exception) {\r
191                                         }\r
192                                         \r
193                                         return proxy;\r
194                                 }\r
195                         }\r
196                 }\r
197                 \r
198                 #endregion\r
199                 \r
200                 #region インストールプロセス\r
201                 \r
202                 /// <summary>\r
203                 /// インストーラーをウイルススキャンするか?\r
204                 /// </summary>\r
205                 public static bool EnableScanInstallerFile {\r
206                         get {\r
207                                 if (pref == null) LoadPref();\r
208                                 return pref.EnableScanInstallerFile;\r
209                         }\r
210                         set {\r
211                                 if (pref == null) LoadPref();\r
212                                 pref.EnableScanInstallerFile = value;\r
213                         }\r
214                 }\r
215 \r
216                 /// <summary>\r
217                 /// インストールプロセスをバックグラウンドで行うか?\r
218                 /// </summary>\r
219                 public static bool InstallProcessOnBackground {\r
220                         get {\r
221                                 if (pref == null) LoadPref();\r
222                                 return pref.InstallOnBackground;\r
223                         }\r
224                         set {\r
225                                 if (pref == null) LoadPref();\r
226                                 pref.EnableScanInstallerFile = value;\r
227                         }\r
228                 }\r
229                 \r
230                 /// <summary>\r
231                 /// アップデートから除外するパッケージの名前\r
232                 /// </summary>\r
233                 public static string[] ExcludeUpdatePackageNames {\r
234                         get {\r
235                                 if (pref == null) LoadPref();\r
236                                 return pref.ExcludeUpdatePackageNames;\r
237                         }\r
238                         set {\r
239                                 if (pref == null) LoadPref();\r
240                                 pref.ExcludeUpdatePackageNames = value;\r
241                         }\r
242                 }\r
243                 \r
244                 #endregion\r
245                 \r
246         }\r
247 }\r