@@ -264,6 +264,7 @@ private void bgwDownloader_DoWork(object sender, DoWorkEventArgs e)
264264 private void calculateFilesSize ( )
265265 {
266266 fireEventFromBgw ( Event . CalculationFileSizesStarted ) ;
267+ bool headVerb = true ;
267268 m_totalSize = 0 ;
268269 string message ;
269270 for ( Int32 fileNr = 0 ; fileNr < this . Files . Count ; fileNr ++ )
@@ -274,12 +275,13 @@ private void calculateFilesSize()
274275 //Probe 1
275276 HttpWebRequest webReq = ( HttpWebRequest ) WebRequest . Create ( this . Files [ fileNr ] . Path ) ;
276277 webReq . UserAgent = Constants . SymbolServer ;
278+ webReq . Method = "HEAD" ;
277279 HttpWebResponse webResp = ( HttpWebResponse ) webReq . GetResponseNoException ( ) ;
278280
279281 //Probe 2
280282 if ( webResp . StatusCode == HttpStatusCode . NotFound )
281283 {
282- webResp = Retry ( fileNr ) ;
284+ webResp = Retry ( fileNr , headVerb ) ;
283285 }
284286
285287 if ( webResp . StatusCode == HttpStatusCode . OK )
@@ -310,12 +312,14 @@ private void calculateFilesSize()
310312 fireEventFromBgw ( Event . FileSizesCalculationComplete ) ;
311313 }
312314
313- private HttpWebResponse Retry ( int fileNr )
315+ private HttpWebResponse Retry ( int fileNr , bool headVerb )
314316 {
315317 string path = this . Files [ fileNr ] . Path ;
316318 path = ProbeWithUnderscore ( path ) ;
317319 var webReq = ( HttpWebRequest ) System . Net . WebRequest . Create ( path ) ;
318320 webReq . UserAgent = Constants . SymbolServer ;
321+ if ( headVerb )
322+ webReq . Method = "HEAD" ;
319323 return ( HttpWebResponse ) webReq . GetResponseNoException ( ) ;
320324 }
321325
@@ -344,11 +348,18 @@ private long ProcessFileSize(HttpWebResponse webResp, out string filePath)
344348 {
345349 file = file . Substring ( 5 , file . Length - 5 ) ; //Removing PATH: from the output
346350
347- System . IO . FileInfo fInfo = new System . IO . FileInfo ( file ) ;
348- if ( fInfo . Exists )
351+ try
352+ {
353+ System . IO . FileInfo fInfo = new System . IO . FileInfo ( file ) ;
354+ if ( fInfo . Exists )
355+ {
356+ length = fInfo . Length ;
357+ filePath = file ;
358+ }
359+ }
360+ catch ( Exception ex )
349361 {
350- length = fInfo . Length ;
351- filePath = file ;
362+ WriteToLog ( file , ex ) ;
352363 }
353364 }
354365 else
@@ -389,6 +400,7 @@ private void fireEventFromBgw(Event eventName)
389400
390401 private void downloadFile ( Int32 fileNr )
391402 {
403+ bool headVerb = false ;
392404 m_currentFileSize = 0 ;
393405 bool fileptr = false ;
394406 fireEventFromBgw ( Event . FileDownloadAttempting ) ;
@@ -417,7 +429,7 @@ private void downloadFile(Int32 fileNr)
417429 webResp = ( HttpWebResponse ) webReq . GetResponseNoException ( ) ;
418430 if ( webResp . StatusCode == HttpStatusCode . NotFound )
419431 {
420- webResp = Retry ( fileNr ) ;
432+ webResp = Retry ( fileNr , headVerb ) ;
421433
422434 if ( webResp . StatusCode == HttpStatusCode . OK )
423435 {
@@ -433,7 +445,8 @@ private void downloadFile(Int32 fileNr)
433445
434446 if ( webResp . StatusCode != HttpStatusCode . OK )
435447 {
436- FailedFiles . Add ( file . Name , " - " + webResp . StatusCode + " " + webResp . StatusDescription ) ;
448+ if ( ! FailedFiles . ContainsKey ( file . Name ) )
449+ FailedFiles . Add ( file . Name , " - " + webResp . StatusCode + " " + webResp . StatusDescription ) ;
437450 }
438451 }
439452 else if ( webResp . StatusCode == HttpStatusCode . OK )
@@ -559,7 +572,7 @@ public static void WriteToLog(string fileName, Exception exc)
559572 using ( FileStream fs = new FileStream ( "Log.txt" , FileMode . Append ) )
560573 using ( StreamWriter sr = new StreamWriter ( fs ) )
561574 {
562- sr . WriteLine ( DateTime . Now . ToString ( ) + " " + fileName + ": " + exc . Message ) ;
575+ sr . WriteLine ( DateTime . Now . ToString ( ) + " " + fileName + " - " + exc . Message ) ;
563576 }
564577 }
565578
@@ -568,7 +581,7 @@ public static void WriteToLog(string fileName, string text)
568581 using ( FileStream fs = new FileStream ( "Log.txt" , FileMode . Append ) )
569582 using ( StreamWriter sr = new StreamWriter ( fs ) )
570583 {
571- sr . WriteLine ( DateTime . Now . ToString ( ) + " " + fileName + ": " + text ) ;
584+ sr . WriteLine ( DateTime . Now . ToString ( ) + " " + fileName + " - " + text ) ;
572585 }
573586 }
574587
0 commit comments