@@ -89,10 +89,10 @@ public string SetupBinary(string url, string zipPath, string binaryPath)
8989 Exception renameException = null ;
9090 try
9191 {
92- string [ ] files = Directory . GetFiles ( stagingDir ) ;
92+ var files = Directory . GetFiles ( stagingDir ) ;
9393
9494 // Copy the files and overwrite destination files if they already exist.
95- foreach ( string file in files )
95+ foreach ( var file in files )
9696 {
9797 // Use static Path methods to extract only the file name from the path.
9898 var fileName = Path . GetFileName ( file ) ;
@@ -116,6 +116,7 @@ public string SetupBinary(string url, string zipPath, string binaryPath)
116116 {
117117 Console . Error . WriteLine ( ex . ToString ( ) ) ;
118118 }
119+
119120 try
120121 {
121122 RemoveZip ( zipPath ) ;
@@ -141,23 +142,19 @@ public string DownloadZip(string url, string destination)
141142 if ( File . Exists ( destination ) ) return destination ;
142143 if ( Proxy == null ) CheckProxySystemVariables ( ) ;
143144
144- if ( Proxy != null )
145- {
146- using ( var webClient = new WebClient ( ) { Proxy = Proxy } )
147- {
148- webClient . DownloadFile ( new Uri ( url ) , destination ) ;
149- }
150- }
151- else
145+ using ( var webClient = new WebClient ( ) )
152146 {
153- using ( var webClient = new WebClient ( ) )
147+ if ( Proxy != null )
154148 {
155- webClient . DownloadFile ( new Uri ( url ) , destination ) ;
149+ webClient . Proxy = Proxy ;
156150 }
151+
152+ webClient . DownloadFile ( new Uri ( url ) , destination ) ;
157153 }
158154
159155 return destination ;
160156 }
157+
161158 protected void CheckProxySystemVariables ( )
162159 {
163160 const string nameHttp = "HTTP_PROXY" ;
@@ -187,17 +184,16 @@ protected string UnZip(string path, string destination, string name)
187184 {
188185 foreach ( ZipEntry zipEntry in zip )
189186 {
190- if ( zipEntry . Name . EndsWith ( name ) && zipEntry . IsFile )
187+ if ( ! zipEntry . Name . EndsWith ( name ) || ! zipEntry . IsFile ) continue ;
188+
189+ var buffer = new byte [ 4096 ] ;
190+ using ( var zipStream = zip . GetInputStream ( zipEntry ) )
191191 {
192- byte [ ] buffer = new byte [ 4096 ] ;
193- using ( Stream zipStream = zip . GetInputStream ( zipEntry ) )
192+ // Unzip file in buffered chunks. This is just as fast as unpacking to a buffer the full size
193+ // of the file, but does not waste memory.
194+ using ( var streamWriter = File . Create ( destination ) )
194195 {
195- // Unzip file in buffered chunks. This is just as fast as unpacking to a buffer the full size
196- // of the file, but does not waste memory.
197- using ( FileStream streamWriter = File . Create ( destination ) )
198- {
199- StreamUtils . Copy ( zipStream , streamWriter , buffer ) ;
200- }
196+ StreamUtils . Copy ( zipStream , streamWriter , buffer ) ;
201197 }
202198 }
203199 }
0 commit comments