23
23
24
24
package com .esp32 .mkspiffs ;
25
25
26
- import java .io .File ;
27
- import java .io .FileReader ;
28
- import java .io .BufferedReader ;
29
- import java .io .InputStreamReader ;
30
- import java .io .IOException ;
26
+ import java .util .*;
27
+ import java .io .*;
31
28
32
29
import java .text .SimpleDateFormat ;
33
- import java .util .Date ;
34
30
import java .lang .reflect .Field ;
35
31
import java .lang .reflect .InvocationTargetException ;
36
32
import javax .swing .JOptionPane ;
51
47
52
48
import cc .arduino .files .DeleteFilesOnShutdown ;
53
49
50
+ /**
51
+ * Taken from https://www.infoworld.com/article/2071275/when-runtime-exec---won-t.html?page=3
52
+ */
53
+ class StreamGobbler extends Thread {
54
+ InputStream is ;
55
+ String type ;
56
+
57
+ StreamGobbler (InputStream is , String type ) {
58
+ this .is = is ;
59
+ this .type = type ;
60
+ }
61
+
62
+ public void run () {
63
+ try {
64
+ InputStreamReader isr = new InputStreamReader (is );
65
+ BufferedReader br = new BufferedReader (isr );
66
+ String line =null ;
67
+ while ( (line = br .readLine ()) != null )
68
+ System .out .println (type + ">" + line );
69
+ } catch (IOException ioe ) {
70
+ ioe .printStackTrace ();
71
+ }
72
+ }
73
+ }
74
+
75
+
54
76
/**
55
77
* Example Tools menu entry.
56
78
*/
@@ -71,31 +93,26 @@ public String getMenuTitle() {
71
93
72
94
private int listenOnProcess (String [] arguments ){
73
95
try {
74
- final Process p = ProcessUtils .exec (arguments );
75
- Thread thread = new Thread () {
76
- public void run () {
77
- try {
78
- InputStreamReader reader = new InputStreamReader (p .getInputStream ());
79
- int c ;
80
- while ((c = reader .read ()) != -1 )
81
- System .out .print ((char ) c );
82
- reader .close ();
83
-
84
- reader = new InputStreamReader (p .getErrorStream ());
85
- while ((c = reader .read ()) != -1 )
86
- System .err .print ((char ) c );
87
- reader .close ();
88
- } catch (Exception e ){}
89
- }
90
- };
91
- thread .start ();
92
- int res = p .waitFor ();
93
- thread .join ();
94
- return res ;
96
+ Runtime rt = Runtime .getRuntime ();
97
+ Process proc = rt .exec (arguments );
98
+ // any error message?
99
+ StreamGobbler errorGobbler = new StreamGobbler (proc .getErrorStream (), "E" );
100
+
101
+ // any output?
102
+ StreamGobbler outputGobbler = new StreamGobbler (proc .getInputStream (), "O" );
103
+
104
+ // kick them off
105
+ errorGobbler .start ();
106
+ outputGobbler .start ();
107
+
108
+ // any error???
109
+ int exitVal = proc .waitFor ();
110
+
111
+ return exitVal ;
95
112
} catch (Exception e ){
96
113
return -1 ;
97
114
}
98
- }
115
+ }
99
116
100
117
private void sysExec (final String [] arguments ){
101
118
Thread thread = new Thread () {
@@ -328,9 +345,12 @@ private void createAndUpload(){
328
345
isNetwork = true ;
329
346
espota = new File (platform .getFolder ()+"/tools" , espotaCmd );
330
347
if (!espota .exists () || !espota .isFile ()){
331
- System .err .println ();
332
- editor .statusError (typefs + " Error: espota not found!" );
333
- return ;
348
+ espota = new File (platform .getFolder ()+"/tools" , "espota.py" ); //fall-back to .py
349
+ if (!espota .exists () || !espota .isFile ()){
350
+ System .err .println ();
351
+ editor .statusError (typefs + " Error: espota not found!" );
352
+ return ;
353
+ }
334
354
}
335
355
System .out .println ("espota : " +espota .getAbsolutePath ());
336
356
System .out .println ();
@@ -354,11 +374,10 @@ private void createAndUpload(){
354
374
}
355
375
}
356
376
}
377
+ System .out .println ("esptool : " +esptool .getAbsolutePath ());
378
+ System .out .println ();
357
379
}
358
- System .out .println ("esptool : " +esptool .getAbsolutePath ());
359
- System .out .println ();
360
-
361
-
380
+
362
381
//load a list of all files
363
382
int fileCount = 0 ;
364
383
File dataFolder = new File (editor .getSketch ().getFolder (), "data" );
@@ -426,9 +445,10 @@ private void createAndUpload(){
426
445
427
446
if (isNetwork ){
428
447
System .out .println ("[" + typefs + "] IP : " +serialPort );
429
- System .out .println ();
448
+ System .out .println ("Running: " + espota .getAbsolutePath () + " -i " + serialPort + " -p 3232 -s -f " + imagePath );
449
+ System .out .println ();
430
450
if (espota .getAbsolutePath ().endsWith (".py" ))
431
- sysExec (new String []{pythonCmd , espota .getAbsolutePath (), "-i" , serialPort , "-p" , "3232" , "-s" , "-f" , imagePath });
451
+ sysExec (new String []{pythonCmd , espota .getAbsolutePath (), "-i" , serialPort , "-p" , "3232" , "-s" , "-f" , imagePath }); // other flags , "-d", "-r", "-t", "50"
432
452
else
433
453
sysExec (new String []{espota .getAbsolutePath (), "-i" , serialPort , "-p" , "3232" , "-s" , "-f" , imagePath });
434
454
} else {
@@ -507,9 +527,9 @@ private void eraseFlash(){
507
527
}
508
528
}
509
529
}
530
+ System .out .println ("esptool : " +esptool .getAbsolutePath ());
531
+ System .out .println ();
510
532
}
511
- System .out .println ("esptool : " +esptool .getAbsolutePath ());
512
- System .out .println ();
513
533
514
534
Object [] options = { "Yes" , "No" };
515
535
String title = "Erase All Flash" ;
0 commit comments