1414using System . Web ;
1515using System . IO ;
1616using System . Net ;
17+ using System . Net . Mime ;
1718using System . Threading ;
1819
1920namespace com . erlange . wbmdl
@@ -276,6 +277,7 @@ static List<Archive> GetResponse(string url)
276277 request . Method = "GET" ;
277278 using ( HttpWebResponse response = ( HttpWebResponse ) request . GetResponse ( ) )
278279 {
280+
279281 using ( StreamReader reader = new StreamReader ( response . GetResponseStream ( ) , Encoding . UTF8 ) )
280282 {
281283 string line , original , urlId , timestamp , fileName , localPath , localPathTimestamp ;
@@ -286,12 +288,20 @@ static List<Archive> GetResponse(string url)
286288 timestamp = line . Split ( ' ' ) [ 2 ] ;
287289 fileName = urlId . Split ( '/' ) [ urlId . Split ( '/' ) . Length - 1 ] . Split ( '?' ) [ 0 ] ;
288290 original = @line . Split ( ' ' ) [ 3 ] ;
289-
291+
290292 uri = new Uri ( original ) ;
291293
294+
292295 if ( urlId . EndsWith ( "/" ) || ! fileName . Contains ( "." ) )
293296 fileName = defaultIndexFile ;
294297
298+
299+ if ( ! string . IsNullOrEmpty ( response . GetResponseHeader ( "content-disposition" ) ) )
300+ {
301+ System . Net . Mime . ContentDisposition cd = new System . Net . Mime . ContentDisposition ( response . GetResponseHeader ( "content-disposition" ) ) ;
302+ fileName = cd . FileName ;
303+ }
304+
295305 localPath = uri . Host + "/" + uri . AbsolutePath . Replace ( fileName , "" ) ;
296306 localPath += HttpUtility . UrlEncode ( uri . Query . Replace ( "?" , "" ) ) ;
297307 localPath += "/" + fileName ;
@@ -413,6 +423,7 @@ static void DownloadArchives(List<Archive> archives, string path, bool isAllTime
413423 {
414424 using ( WebClient client = new WebClient ( ) )
415425 {
426+ //client.DownloadFileCompleted += Client_DownloadFileCompleted;
416427 foreach ( Archive archive in archives )
417428 {
418429 uri = new Uri ( archive . Original ) ;
@@ -422,8 +433,16 @@ static void DownloadArchives(List<Archive> archives, string path, bool isAllTime
422433 }
423434 }
424435 }
436+
437+ private static void Client_DownloadFileCompleted ( object sender , System . ComponentModel . AsyncCompletedEventArgs e )
438+ {
439+ throw new NotImplementedException ( ) ;
440+ }
441+
425442 static void DownloadSingleArchive ( WebClient client , Archive archive , string path , bool isAllHttpStatus )
426443 {
444+
445+
427446 string dirPath = path . Replace ( archive . Filename , "" ) ;
428447 string filePath = path ;
429448 try
@@ -432,6 +451,16 @@ static void DownloadSingleArchive(WebClient client, Archive archive, string path
432451 Directory . CreateDirectory ( dirPath ) ;
433452
434453 client . DownloadFile ( archive . UrlId , filePath ) ;
454+ if ( ! string . IsNullOrEmpty ( client . ResponseHeaders [ "Content-Disposition" ] ) )
455+ {
456+ ContentDisposition cd = new ContentDisposition ( client . ResponseHeaders [ "Content-Disposition" ] ) ;
457+ string cdFilePath = System . IO . Path . Combine ( dirPath , cd . FileName ) ;
458+ if ( System . IO . File . Exists ( cdFilePath ) )
459+ File . Delete ( cdFilePath ) ;
460+
461+ System . IO . File . Move ( filePath , cdFilePath ) ;
462+ filePath = cdFilePath ;
463+ }
435464
436465 lock ( threadLocker )
437466 archiveCount ++ ;
0 commit comments