Skip to content

Commit 33969c9

Browse files
earlephilhowerigrr
authored andcommitted
Use cleaner path finding code, misc. cleanup
Instead of a bunch of nested if-elses, use a list of strings to try iterating over to fins python(.exe). Replace 1-line if-else with ternary operator
1 parent c231545 commit 33969c9

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

src/ESP8266FS.java

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,7 @@ private void createAndUpload(){
208208
File espota = new File(platform.getFolder()+"/tools");
209209
File esptool = new File(platform.getFolder()+"/tools");
210210
String serialPort = PreferencesData.get("serial.port");
211-
String pythonCmd;
212-
if(PreferencesData.get("runtime.os").contentEquals("windows"))
213-
pythonCmd = "python.exe";
214-
else
215-
pythonCmd = "python";
211+
String pythonCmd = PreferencesData.get("runtime.os").contentEquals("windows") ? "python.exe" : "python";
216212
String uploadCmd = "";
217213

218214
//make sure the serial port or IP is defined
@@ -228,21 +224,12 @@ private void createAndUpload(){
228224
uploadCmd = uploadPyFile.getAbsolutePath();
229225
}
230226
// Find python.exe if present, don't fail if not found for backwards compat
231-
String toolPyCmd = pythonCmd;
232-
if ((toolPyCmd != null ) && !toolPyCmd.isEmpty()) {
233-
File toolPyFile = new File(platform.getFolder()+"/tools", toolPyCmd);
227+
String[] paths = { platform.getFolder()+"/tools", platform.getFolder()+"/tools/python", PreferencesData.get("runtime.tools.python.path") };
228+
for (String s: paths) {
229+
File toolPyFile = new File(s, pythonCmd);
234230
if (toolPyFile.exists() && toolPyFile.isFile() && toolPyFile.canExecute()) {
235231
pythonCmd = toolPyFile.getAbsolutePath();
236-
} else {
237-
toolPyFile = new File(platform.getFolder()+"/tools/python", toolPyCmd);
238-
if (toolPyFile.exists() && toolPyFile.isFile() && toolPyFile.canExecute()) {
239-
pythonCmd = toolPyFile.getAbsolutePath();
240-
} else {
241-
toolPyFile = new File(PreferencesData.get("runtime.tools.python.path"), toolPyCmd);
242-
if (toolPyFile.exists() && toolPyFile.isFile() && toolPyFile.canExecute()) {
243-
pythonCmd = toolPyFile.getAbsolutePath();
244-
}
245-
}
232+
break;
246233
}
247234
}
248235
// pythonCmd now points to either an installed exe with full path or just plain "python(.exe)"
@@ -338,12 +325,12 @@ private void createAndUpload(){
338325
System.out.println("[SPIFFS] reset : "+resetMethod);
339326
System.out.println("[SPIFFS] port : "+serialPort);
340327
System.out.println("[SPIFFS] speed : "+uploadSpeed);
341-
if (uploadCmd != null && !uploadCmd.isEmpty()) {
328+
if (!uploadCmd.isEmpty()) {
342329
System.out.println("[SPIFFS] python : "+pythonCmd);
343330
System.out.println("[SPIFFS] uploader : "+uploadCmd);
344331
}
345332
System.out.println();
346-
if (uploadCmd != null && !uploadCmd.isEmpty()) {
333+
if (!uploadCmd.isEmpty()) {
347334
sysExec(new String[]{pythonCmd, uploadCmd, "--chip", "esp8266", "--port", serialPort, "--baud", uploadSpeed, "write_flash", uploadAddress, imagePath, "--end"});
348335
} else {
349336
sysExec(new String[]{esptool.getAbsolutePath(), "-cd", resetMethod, "-cb", uploadSpeed, "-cp", serialPort, "-ca", uploadAddress, "-cf", imagePath});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy