diff --git a/arduino-core/src/processing/app/debug/Compiler.java b/arduino-core/src/processing/app/debug/Compiler.java index e4155d4b4..5f1bf9ad5 100644 --- a/arduino-core/src/processing/app/debug/Compiler.java +++ b/arduino-core/src/processing/app/debug/Compiler.java @@ -1219,7 +1219,10 @@ public class Compiler implements MessageConsumer { //7. Save the .hex file void saveHex() throws RunnerException { - if (!prefs.containsKey("recipe.output.tmp_file") || !prefs.containsKey("recipe.output.save_file")) { + List compiledSketches = new ArrayList<>(prefs.subTree("recipe.output.tmp_file", 1).values()); + List copyOfCompiledSketches = new ArrayList<>(prefs.subTree("recipe.output.save_file", 1).values()); + + if (isExportCompiledSketchSupported(compiledSketches, copyOfCompiledSketches)) { System.err.println(_("Warning: This core does not support exporting sketches. Please consider upgrading it or contacting its author")); return; } @@ -1227,21 +1230,23 @@ public class Compiler implements MessageConsumer { PreferencesMap dict = new PreferencesMap(prefs); dict.put("ide_version", "" + BaseNoGui.REVISION); - try { - List compiledSketches = new ArrayList(prefs.subTree("recipe.output.tmp_file", 1).values()); - if (!compiledSketches.isEmpty()) { - List copyOfCompiledSketches = new ArrayList(prefs.subTree("recipe.output.save_file", 1).values()); - for (int i = 0; i < compiledSketches.size(); i++) { - saveHex(compiledSketches.get(i), copyOfCompiledSketches.get(i), prefs); - } - } else { - saveHex(prefs.getOrExcept("recipe.output.tmp_file"), prefs.getOrExcept("recipe.output.save_file"), prefs); + if (!compiledSketches.isEmpty()) { + for (int i = 0; i < compiledSketches.size(); i++) { + saveHex(compiledSketches.get(i), copyOfCompiledSketches.get(i), prefs); + } + } else { + try { + saveHex(prefs.getOrExcept("recipe.output.tmp_file"), prefs.getOrExcept("recipe.output.save_file"), prefs); + } catch (PreferencesMapException e) { + throw new RunnerException(e); } - } catch (Exception e) { - throw new RunnerException(e); } } + private boolean isExportCompiledSketchSupported(List compiledSketches, List copyOfCompiledSketches) { + return (compiledSketches.isEmpty() || copyOfCompiledSketches.isEmpty() || copyOfCompiledSketches.size() < compiledSketches.size()) && (!prefs.containsKey("recipe.output.tmp_file") || !prefs.containsKey("recipe.output.save_file")); + } + private void saveHex(String compiledSketch, String copyOfCompiledSketch, PreferencesMap dict) throws RunnerException { try { compiledSketch = StringReplacer.replaceFromMapping(compiledSketch, dict);