10
10
import processing .app .Platform ;
11
11
import processing .app .Preferences ;
12
12
import processing .app .ui .Toolkit ;
13
+ import processing .core .PApplet ;
13
14
14
15
import javax .swing .*;
15
16
import javax .swing .border .EmptyBorder ;
@@ -86,25 +87,25 @@ protected Object doInBackground() throws Exception {
86
87
87
88
// tools
88
89
File downloadedTools = new File (tempFolder , downloadUrls .toolsFilename );
89
- downloadAndUnpack (downloadUrls .toolsUrl , downloadedTools , sdkFolder );
90
+ downloadAndUnpack (downloadUrls .toolsUrl , downloadedTools , sdkFolder , true );
90
91
91
92
// platform-tools
92
93
File downloadedPlatformTools = new File (tempFolder , downloadUrls .platformToolsFilename );
93
- downloadAndUnpack (downloadUrls .platformToolsUrl , downloadedPlatformTools , sdkFolder );
94
+ downloadAndUnpack (downloadUrls .platformToolsUrl , downloadedPlatformTools , sdkFolder , true );
94
95
95
96
// build-tools
96
97
File downloadedBuildTools = new File (tempFolder , downloadUrls .buildToolsFilename );
97
- downloadAndUnpack (downloadUrls .buildToolsUrl , downloadedBuildTools , buildToolsFolder );
98
+ downloadAndUnpack (downloadUrls .buildToolsUrl , downloadedBuildTools , buildToolsFolder , true );
98
99
99
100
// platform
100
101
File downloadedPlatform = new File (tempFolder , downloadUrls .platformFilename );
101
- downloadAndUnpack (downloadUrls .platformUrl , downloadedPlatform , platformsFolder );
102
+ downloadAndUnpack (downloadUrls .platformUrl , downloadedPlatform , platformsFolder , false );
102
103
103
104
// usb driver
104
105
if (Platform .isWindows ()) {
105
106
File usbDriverFolder = new File (extrasFolder , "google" );
106
107
File downloadedFolder = new File (tempFolder , "latest_usb_driver_windows.zip" );
107
- downloadAndUnpack (URL_USB_DRIVER , downloadedFolder , usbDriverFolder );
108
+ downloadAndUnpack (URL_USB_DRIVER , downloadedFolder , usbDriverFolder , false );
108
109
}
109
110
110
111
if (Platform .isLinux () || Platform .isMacOS ()) {
@@ -135,7 +136,7 @@ protected void done() {
135
136
}
136
137
137
138
private void downloadAndUnpack (String urlString , File saveTo ,
138
- File unpackTo ) throws IOException {
139
+ File unpackTo , boolean setExec ) throws IOException {
139
140
URL url = null ;
140
141
try {
141
142
url = new URL (urlString );
@@ -167,7 +168,7 @@ private void downloadAndUnpack(String urlString, File saveTo,
167
168
inputStream .close ();
168
169
outputStream .close ();
169
170
170
- extractFolder (saveTo , unpackTo );
171
+ extractFolder (saveTo , unpackTo , setExec );
171
172
}
172
173
173
174
/*
@@ -370,7 +371,7 @@ public void actionPerformed(ActionEvent actionEvent) {
370
371
}
371
372
372
373
373
- static void extractFolder (File file , File newPath ) throws IOException {
374
+ static void extractFolder (File file , File newPath , boolean setExec ) throws IOException {
374
375
int BUFFER = 2048 ;
375
376
zip = new ZipFile (file );
376
377
Enumeration <? extends ZipEntry > zipFileEntries = zip .entries ();
@@ -387,7 +388,16 @@ static void extractFolder(File file, File newPath) throws IOException {
387
388
// create the parent directory structure if needed
388
389
destinationParent .mkdirs ();
389
390
391
+ String ext = PApplet .getExtension (currentEntry );
392
+ if (setExec && ext .equals ("unknown" )) {
393
+ // On some OS X machines the android binaries loose their executable
394
+ // attribute, rendering the mode unusable
395
+ destFile .setExecutable (true );
396
+ }
397
+
390
398
if (!entry .isDirectory ()) {
399
+ // should preserve permissions
400
+ // https://bitbucket.org/atlassian/amps/pull-requests/21/amps-904-preserve-executable-file-status/diff
391
401
BufferedInputStream is = new BufferedInputStream (zip
392
402
.getInputStream (entry ));
393
403
int currentByte ;
0 commit comments