@@ -58,6 +58,10 @@ public function isInstalled(): bool
5858
5959 public function getInstallBinaryPath (): string
6060 {
61+ if ('\\' === \DIRECTORY_SEPARATOR ) {
62+ return Path::join ($ this ->installDirectory , 'minify.exe ' );
63+ }
64+
6165 return Path::join ($ this ->installDirectory , 'minify ' );
6266 }
6367
@@ -82,32 +86,30 @@ public function download(string $version): void
8286 $ this ->filesystem ->appendToFile ($ downloadFilename , $ chunk ->getContent (), true );
8387 }
8488
85- if (str_ends_with ($ downloadFilename , '.zip ' )) {
86- $ download = function () use ($ downloadFilename , $ tempDir ) {
87- $ archive = new \ZipArchive ();
88- $ archive ->open ($ downloadFilename );
89- $ archive ->extractTo ($ tempDir , 'minify ' );
90- $ archive ->close ();
91- };
92- } else {
93- $ download = function () use ($ downloadFilename , $ tempDir ) {
94- $ archive = new \PharData ($ downloadFilename );
95- $ archive ->extractTo ($ tempDir , ['minify ' ], true );
96- };
97- }
89+ $ this ->filesystem ->mkdir (Path::getDirectory ($ this ->getInstallBinaryPath ()));
9890
99- try {
100- $ download ();
101- } catch (\Throwable $ e ) {
102- throw new InstallException (sprintf ('Error extracting the binary from archive "%s". ' , $ downloadFilename ), 0 , $ e ->getPrevious ());
103- }
104-
105- $ this ->filesystem ->mkdir (dirname ($ this ->getInstallBinaryPath ()));
10691 if (str_ends_with ($ downloadFilename , '.zip ' )) {
92+ // Windows archive (minify.exe)
93+ $ archive = new \ZipArchive ();
94+ if (true !== $ archive ->open ($ downloadFilename )) {
95+ throw new InstallException (sprintf ('Error opening archive "%s". ' , $ downloadFilename ));
96+ }
97+ if (false === $ archive ->extractTo ($ tempDir , 'minify.exe ' )) {
98+ throw new InstallException (sprintf ('Error extracting minify.exe from archive "%s". ' , $ downloadFilename ));
99+ }
100+ $ archive ->close ();
107101 $ this ->filesystem ->copy (Path::join ($ tempDir , 'minify.exe ' ), $ this ->getInstallBinaryPath ());
102+ $ this ->filesystem ->chmod ($ this ->getInstallBinaryPath (), 0755 );
108103 } else {
104+ $ archive = new \PharData ($ downloadFilename );
105+ try {
106+ $ archive ->extractTo ($ tempDir , ['minify ' ], true );
107+ } catch (\Exception $ e ) {
108+ throw new InstallException (sprintf ('Error extracting the binary from archive "%s". ' , $ downloadFilename ), 0 , $ e );
109+ }
109110 $ this ->filesystem ->copy (Path::join ($ tempDir , 'minify ' ), $ this ->getInstallBinaryPath ());
110111 }
112+
111113 $ this ->filesystem ->remove ($ tempDir );
112114 }
113115
0 commit comments