@@ -8,9 +8,12 @@ namespace WebDriverManager.Services.Impl
88{
99 public class BinaryService : IBinaryService
1010 {
11+ static readonly object _object = new object ( ) ;
12+
1113 public string SetupBinary ( string url , string zipDestination , string binDestination , string binaryName )
1214 {
1315 if ( File . Exists ( binDestination ) ) return binDestination ;
16+ FileHelper . CreateDestinationDirectory ( zipDestination ) ;
1417 zipDestination = DownloadZip ( url , zipDestination ) ;
1518 FileHelper . CreateDestinationDirectory ( binDestination ) ;
1619 binDestination = UnZip ( zipDestination , binDestination , binaryName ) ;
@@ -25,33 +28,39 @@ protected string DownloadZip(string url, string destination)
2528 {
2629 webClient . DownloadFile ( new Uri ( url ) , destination ) ;
2730 }
31+
2832 return destination ;
2933 }
3034
3135 protected string UnZip ( string path , string destination , string name )
3236 {
33- var zipName = Path . GetFileName ( path ) ;
34- if ( zipName != null && zipName . Equals ( name , StringComparison . CurrentCultureIgnoreCase ) )
35- {
36- File . Copy ( path , destination ) ;
37- return destination ;
38- }
39- using ( var zip = ZipFile . Open ( path , ZipArchiveMode . Read ) )
37+ lock ( _object )
4038 {
41- foreach ( var entry in zip . Entries )
39+ var zipName = Path . GetFileName ( path ) ;
40+ if ( zipName != null && zipName . Equals ( name , StringComparison . CurrentCultureIgnoreCase ) )
4241 {
43- if ( entry . Name == name )
42+ File . Copy ( path , destination ) ;
43+ return destination ;
44+ }
45+
46+ using ( var zip = ZipFile . Open ( path , ZipArchiveMode . Read ) )
47+ {
48+ foreach ( var entry in zip . Entries )
4449 {
45- entry . ExtractToFile ( destination , true ) ;
50+ if ( entry . Name == name )
51+ {
52+ entry . ExtractToFile ( destination , true ) ;
53+ }
4654 }
4755 }
56+
57+ return destination ;
4858 }
49- return destination ;
5059 }
5160
5261 protected void RemoveZip ( string path )
5362 {
5463 File . Delete ( path ) ;
5564 }
5665 }
57- }
66+ }
0 commit comments