@@ -89,10 +89,10 @@ public string SetupBinary(string url, string zipPath, string binaryPath)
89
89
Exception renameException = null ;
90
90
try
91
91
{
92
- string [ ] files = Directory . GetFiles ( stagingDir ) ;
92
+ var files = Directory . GetFiles ( stagingDir ) ;
93
93
94
94
// Copy the files and overwrite destination files if they already exist.
95
- foreach ( string file in files )
95
+ foreach ( var file in files )
96
96
{
97
97
// Use static Path methods to extract only the file name from the path.
98
98
var fileName = Path . GetFileName ( file ) ;
@@ -116,6 +116,7 @@ public string SetupBinary(string url, string zipPath, string binaryPath)
116
116
{
117
117
Console . Error . WriteLine ( ex . ToString ( ) ) ;
118
118
}
119
+
119
120
try
120
121
{
121
122
RemoveZip ( zipPath ) ;
@@ -141,23 +142,19 @@ public string DownloadZip(string url, string destination)
141
142
if ( File . Exists ( destination ) ) return destination ;
142
143
if ( Proxy == null ) CheckProxySystemVariables ( ) ;
143
144
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 ( ) )
152
146
{
153
- using ( var webClient = new WebClient ( ) )
147
+ if ( Proxy != null )
154
148
{
155
- webClient . DownloadFile ( new Uri ( url ) , destination ) ;
149
+ webClient . Proxy = Proxy ;
156
150
}
151
+
152
+ webClient . DownloadFile ( new Uri ( url ) , destination ) ;
157
153
}
158
154
159
155
return destination ;
160
156
}
157
+
161
158
protected void CheckProxySystemVariables ( )
162
159
{
163
160
const string nameHttp = "HTTP_PROXY" ;
@@ -187,17 +184,16 @@ protected string UnZip(string path, string destination, string name)
187
184
{
188
185
foreach ( ZipEntry zipEntry in zip )
189
186
{
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 ) )
191
191
{
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 ) )
194
195
{
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 ) ;
201
197
}
202
198
}
203
199
}
0 commit comments