using System;\r
using System.Net;\r
+using System.Net.Mime;\r
using System.IO;\r
-using System.Collections;\r
using System.Threading;\r
using NaGet.SubCommands;\r
\r
/// <summary>\r
/// Webレスポンスからダウンロードしたファイルの名前を取得\r
/// </summary>\r
- /// <param name="response"></param>\r
- /// <returns></returns>\r
+ /// <remarks>Content-Dispositionヘッダから取得あるいはURLの末尾から推定します</remarks>\r
+ /// <param name="response">レスポンスオブジェクト</param>\r
+ /// <returns>取得したファイル名</returns>\r
private string getFileNameFromWebResponse(WebResponse response)\r
{\r
if (response is HttpWebResponse) {\r
string contentDisposition = ((HttpWebResponse) response).Headers["Content-Disposition"];\r
\r
- // TODO check license for http://www.atmarkit.co.jp/fdotnet/dotnettips/618downnoname/downnoname.html\r
if (! string.IsNullOrEmpty(contentDisposition)) {\r
- System.Text.RegularExpressions.Regex re = new System.Text.RegularExpressions.Regex(\r
- @"filename\s*=\s*(?:""(?<filename>[^""]*)""|(?<filename>[^;]*))",\r
- System.Text.RegularExpressions.RegexOptions.IgnoreCase);\r
- \r
- System.Text.RegularExpressions.Match m = re.Match(contentDisposition);\r
- if (m.Success) {\r
- return m.Groups["filename"].Value;\r
+ try {\r
+ ContentDisposition parser = new ContentDisposition(contentDisposition);\r
+ if (! string.IsNullOrEmpty(parser.FileName)) {\r
+ return parser.FileName;\r
+ }\r
+ } catch (FormatException) {\r
}\r
}\r
}\r