28
28
29
29
import processing .app .Platform ;
30
30
import processing .app .Preferences ;
31
+ import processing .app .exec .LineProcessor ;
32
+ import processing .app .exec .StreamPump ;
31
33
import processing .app .ui .Toolkit ;
32
34
import processing .core .PApplet ;
33
35
@@ -381,28 +383,7 @@ public void run() {
381
383
} else {
382
384
// x86
383
385
Preferences .set ("android.system.image.type" , "x86" );
384
- File haxmFolder = AndroidSDK .getHAXMInstallerFolder ();
385
- if (haxmFolder .exists () && !Platform .isLinux ()) {
386
- AndroidUtil .showMessage (HAXM_INSTALL_TITLE , HAXM_INSTALL_MESSAGE );
387
-
388
- File exec = new File (haxmFolder , "HAXM installation" );
389
- System .out .println (exec .getAbsolutePath () + " " + exec .exists ());
390
-
391
- ProcessBuilder pb ;
392
- if (Platform .isWindows ())
393
- pb = new ProcessBuilder ("cmd.exe" , "/c" , "start" , "silent_install.bat" );
394
- else
395
- pb = new ProcessBuilder (exec .getAbsolutePath ());
396
-
397
- // pb.directory(haxmFolder);
398
- try {
399
- pb .start ().waitFor ();
400
- } catch (InterruptedException e ) {
401
- e .printStackTrace ();
402
- } catch (IOException e ) {
403
- e .printStackTrace ();
404
- }
405
- }
386
+ installHAXM ();
406
387
}
407
388
downloadTask = new DownloadTask ();
408
389
downloadTask .addPropertyChangeListener (this );
@@ -418,6 +399,49 @@ public boolean cancelled() {
418
399
public boolean getResult () {
419
400
return result ;
420
401
}
402
+
403
+ static public void installHAXM () {
404
+ File haxmFolder = AndroidSDK .getHAXMInstallerFolder ();
405
+ if (haxmFolder .exists () && !Platform .isLinux ()) {
406
+ AndroidUtil .showMessage (HAXM_INSTALL_TITLE , HAXM_INSTALL_MESSAGE );
407
+
408
+ File exec = new File (haxmFolder , "HAXM installation" );
409
+ System .out .println (exec .getAbsolutePath () + " " + exec .exists ());
410
+
411
+ ProcessBuilder pb ;
412
+ if (Platform .isWindows ())
413
+ pb = new ProcessBuilder ("cmd.exe" , "/c" , "start" , "silent_install.bat" );
414
+ else
415
+ pb = new ProcessBuilder (exec .getAbsolutePath ());
416
+ pb .redirectErrorStream (true );
417
+
418
+ pb .directory (haxmFolder );
419
+ Process process = null ;
420
+ try {
421
+ process = pb .start ();
422
+ } catch (IOException e ) {
423
+ e .printStackTrace ();
424
+ }
425
+
426
+ if (process != null ) {
427
+ try {
428
+ StreamPump output = new StreamPump (process .getInputStream (), "HAXM: " );
429
+ output .addTarget (new LineProcessor () {
430
+ @ Override
431
+ public void processLine (String line ) {
432
+ System .out .println ("HAXM: " + line );
433
+ }
434
+ }).start ();
435
+
436
+ process .waitFor ();
437
+ } catch (final InterruptedException ie ) {
438
+ ie .printStackTrace ();
439
+ } finally {
440
+ process .destroy ();
441
+ }
442
+ }
443
+ }
444
+ }
421
445
422
446
private void createLayout () {
423
447
Container outer = getContentPane ();
0 commit comments