Skip to content

Commit

Permalink
Bugfixes
Browse files Browse the repository at this point in the history
Changed sysExec() to be based on: https://www.infoworld.com/article/2071275/when-runtime-exec---won-t.html
The original way hangs on long uploading.
  • Loading branch information
lorol committed Dec 22, 2020
1 parent e4c702f commit b97f756
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 41 deletions.
98 changes: 59 additions & 39 deletions src/ESP32FS.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@

package com.esp32.mkspiffs;

import java.io.File;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.*;
import java.io.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import javax.swing.JOptionPane;
Expand All @@ -51,6 +47,32 @@

import cc.arduino.files.DeleteFilesOnShutdown;

/**
* Taken from https://www.infoworld.com/article/2071275/when-runtime-exec---won-t.html?page=3
*/
class StreamGobbler extends Thread {
InputStream is;
String type;

StreamGobbler(InputStream is, String type) {
this.is = is;
this.type = type;
}

public void run() {
try {
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line=null;
while ( (line = br.readLine()) != null)
System.out.println(type + ">" + line);
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}


/**
* Example Tools menu entry.
*/
Expand All @@ -71,31 +93,26 @@ public String getMenuTitle() {

private int listenOnProcess(String[] arguments){
try {
final Process p = ProcessUtils.exec(arguments);
Thread thread = new Thread() {
public void run() {
try {
InputStreamReader reader = new InputStreamReader(p.getInputStream());
int c;
while ((c = reader.read()) != -1)
System.out.print((char) c);
reader.close();

reader = new InputStreamReader(p.getErrorStream());
while ((c = reader.read()) != -1)
System.err.print((char) c);
reader.close();
} catch (Exception e){}
}
};
thread.start();
int res = p.waitFor();
thread.join();
return res;
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(arguments);
// any error message?
StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "E");

// any output?
StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "O");

// kick them off
errorGobbler.start();
outputGobbler.start();

// any error???
int exitVal = proc.waitFor();

return exitVal;
} catch (Exception e){
return -1;
}
}
}

private void sysExec(final String[] arguments){
Thread thread = new Thread() {
Expand Down Expand Up @@ -328,9 +345,12 @@ private void createAndUpload(){
isNetwork = true;
espota = new File(platform.getFolder()+"/tools", espotaCmd);
if(!espota.exists() || !espota.isFile()){
System.err.println();
editor.statusError(typefs + " Error: espota not found!");
return;
espota = new File(platform.getFolder()+"/tools", "espota.py"); //fall-back to .py
if(!espota.exists() || !espota.isFile()){
System.err.println();
editor.statusError(typefs + " Error: espota not found!");
return;
}
}
System.out.println("espota : "+espota.getAbsolutePath());
System.out.println();
Expand All @@ -354,11 +374,10 @@ private void createAndUpload(){
}
}
}
System.out.println("esptool : "+esptool.getAbsolutePath());
System.out.println();
}
System.out.println("esptool : "+esptool.getAbsolutePath());
System.out.println();



//load a list of all files
int fileCount = 0;
File dataFolder = new File(editor.getSketch().getFolder(), "data");
Expand Down Expand Up @@ -426,9 +445,10 @@ private void createAndUpload(){

if(isNetwork){
System.out.println("[" + typefs + "] IP : "+serialPort);
System.out.println();
System.out.println("Running: " + espota.getAbsolutePath() + " -i " + serialPort + " -p 3232 -s -f " + imagePath);
System.out.println();
if(espota.getAbsolutePath().endsWith(".py"))
sysExec(new String[]{pythonCmd, espota.getAbsolutePath(), "-i", serialPort, "-p", "3232", "-s", "-f", imagePath});
sysExec(new String[]{pythonCmd, espota.getAbsolutePath(), "-i", serialPort, "-p", "3232", "-s", "-f", imagePath}); // other flags , "-d", "-r", "-t", "50"
else
sysExec(new String[]{espota.getAbsolutePath(), "-i", serialPort, "-p", "3232", "-s", "-f", imagePath});
} else {
Expand Down Expand Up @@ -507,9 +527,9 @@ private void eraseFlash(){
}
}
}
System.out.println("esptool : "+esptool.getAbsolutePath());
System.out.println();
}
System.out.println("esptool : "+esptool.getAbsolutePath());
System.out.println();

Object[] options = { "Yes", "No" };
String title = "Erase All Flash";
Expand Down
Empty file removed src/bin/placeholder
Empty file.
4 changes: 2 additions & 2 deletions src/make_win.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
del bin\*.jar
rd /S /Q bin\com
"C:\Program Files (x86)\Java\jdk1.8.0_152\bin\javac.exe" -target 1.8 -cp ".;arduino-core.jar;commons-codec-1.7.jar;pde.jar" -d bin ESP32FS.java
javac.exe -target 1.8 -cp ".;arduino-core.jar;commons-codec-1.7.jar;pde.jar" -d bin ESP32FS.java
cd bin
"C:\Program Files (x86)\Java\jdk1.8.0_152\bin\jar.exe" cvfM esp32fs.jar *
jar.exe cvfM esp32fs.jar *
pause

0 comments on commit b97f756

Please sign in to comment.