@@ -8,24 +8,24 @@ public class DownloadClient : IDisposable
88 {
99 private HttpClient httpClient = new HttpClient ( ) ;
1010 private HttpRequestMessage httpRequestMessage = new HttpRequestMessage ( ) ;
11- private static string httpUserAgent = "Spore-ModAPI-Launcher-Kit/" + UpdateManager . CurrentVersion . ToString ( ) ;
12-
11+ private static readonly string httpUserAgent = "Spore-ModAPI-Launcher-Kit/" + UpdateManager . CurrentVersion . ToString ( ) ;
1312
1413 public delegate void DownloadClientEventHandler ( object source , int percentage ) ;
15- public event DownloadClientEventHandler DownloadProgressChanged ;
14+ public event DownloadClientEventHandler DownloadProgressChanged = null ;
1615
1716 private void copyStreamWithProgress ( Stream inputStrem , Stream outputStream )
1817 {
1918 long streamLength = inputStrem . Length ;
20- long totalBytesRead = 0 ;
2119 byte [ ] buffer = new byte [ 4096 ] ;
22- int bytesRead = 0 ;
20+ long totalBytesRead = 0 ;
21+ int bytesRead ;
2322 int percentageDownloaded = 0 ;
2423 int percentage ;
2524
2625 while ( ( bytesRead = inputStrem . Read ( buffer , 0 , buffer . Length ) ) > 0 )
2726 {
2827 outputStream . Write ( buffer , 0 , bytesRead ) ;
28+ totalBytesRead += bytesRead ;
2929
3030 // only trigger event when percentage has changed
3131 percentage = ( int ) ( ( double ) totalBytesRead / ( double ) streamLength * 100.0 ) ;
@@ -34,8 +34,6 @@ private void copyStreamWithProgress(Stream inputStrem, Stream outputStream)
3434 percentageDownloaded = percentage ;
3535 DownloadProgressChanged ? . Invoke ( this , percentage ) ;
3636 }
37-
38- totalBytesRead += bytesRead ;
3937 }
4038 }
4139
@@ -118,6 +116,7 @@ protected virtual void Dispose(bool disposing)
118116
119117 httpClient = null ;
120118 httpRequestMessage = null ;
119+ DownloadProgressChanged = null ;
121120 }
122121 }
123122 }
0 commit comments