From 7c58be397bf038ccf5cb6f127d78472884556372 Mon Sep 17 00:00:00 2001 From: Claudio Indellicati Date: Fri, 22 Aug 2014 17:43:41 +0200 Subject: [PATCH] Fixed wrong sketch structure check in Editor and SketchData. --- app/src/processing/app/Editor.java | 9 ++++----- app/src/processing/app/SketchData.java | 13 +++++++++++-- app/src/processing/app/debug/Compiler.java | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 4ece3c233..dffa9e871 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -2124,15 +2124,14 @@ public class Editor extends JFrame implements RunnerListener { * Second stage of open, occurs after having checked to see if the * modifications (if any) to the previous sketch need to be saved. */ - protected boolean handleOpenInternal(File file) { + protected boolean handleOpenInternal(File sketchFile) { // check to make sure that this .pde file is // in a folder of the same name - String fileName = file.getName(); + String fileName = sketchFile.getName(); - if (SketchData.checkSketchFile(file)) { - // no beef with this guy + File file = SketchData.checkSketchFile(sketchFile); - } else if (!fileName.endsWith(".ino") && !fileName.endsWith(".pde")) { + if ((file == null) && !fileName.endsWith(".ino") && !fileName.endsWith(".pde")) { Base.showWarning(_("Bad file selected"), _("Arduino can only open its own sketches\n" + "and other files ending in .ino or .pde"), null); diff --git a/app/src/processing/app/SketchData.java b/app/src/processing/app/SketchData.java index aedf1f511..948613a6e 100644 --- a/app/src/processing/app/SketchData.java +++ b/app/src/processing/app/SketchData.java @@ -52,7 +52,7 @@ public class SketchData { //System.out.println("sketch dir is " + folder); } - static public boolean checkSketchFile(File file) { + static public File checkSketchFile(File file) { // check to make sure that this .pde file is // in a folder of the same name String fileName = file.getName(); @@ -63,7 +63,16 @@ public class SketchData { String inoName = parentName + ".ino"; File altInoFile = new File(parent, inoName); - return pdeName.equals(fileName) || inoName.equals(fileName) || altPdeFile.exists() || altInoFile.exists(); + if (pdeName.equals(fileName) || inoName.equals(fileName)) + return file; + + if (altPdeFile.exists()) + return altPdeFile; + + if (altInoFile.exists()) + return altInoFile; + + return null; } /** diff --git a/app/src/processing/app/debug/Compiler.java b/app/src/processing/app/debug/Compiler.java index 12909b9f9..b606bb39c 100644 --- a/app/src/processing/app/debug/Compiler.java +++ b/app/src/processing/app/debug/Compiler.java @@ -83,7 +83,7 @@ public class Compiler implements MessageConsumer { private ProgressListener progressListener; static public String build(SketchData data, String buildPath, File tempBuildFolder, ProgressListener progListener, boolean verbose) throws RunnerException { - if (!SketchData.checkSketchFile(data.getPrimaryFile())) + if (SketchData.checkSketchFile(data.getPrimaryFile()) == null) BaseNoGui.showError(_("Bad file selected"), _("Bad sketch primary file or bad sketck directory structure"), null);