1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-16 11:21:18 +03:00

Fixed wrong sketch structure check.

This commit is contained in:
Claudio Indellicati
2014-09-18 12:35:25 +02:00
committed by Cristian Maglie
parent 2702ccef0c
commit c2223107b1

View File

@ -2131,68 +2131,72 @@ public class Editor extends JFrame implements RunnerListener {
File file = SketchData.checkSketchFile(sketchFile); File file = SketchData.checkSketchFile(sketchFile);
if ((file == null) && !fileName.endsWith(".ino") && !fileName.endsWith(".pde")) { if (file == null)
Base.showWarning(_("Bad file selected"), {
_("Arduino can only open its own sketches\n" + if (!fileName.endsWith(".ino") && !fileName.endsWith(".pde")) {
"and other files ending in .ino or .pde"), null);
return false;
} else { Base.showWarning(_("Bad file selected"),
String properParent = _("Arduino can only open its own sketches\n" +
fileName.substring(0, fileName.length() - 4); "and other files ending in .ino or .pde"), null);
return false;
Object[] options = { _("OK"), _("Cancel") }; } else {
String prompt = I18n.format(_("The file \"{0}\" needs to be inside\n" + String properParent =
fileName.substring(0, fileName.length() - 4);
Object[] options = { _("OK"), _("Cancel") };
String prompt = I18n.format(_("The file \"{0}\" needs to be inside\n" +
"a sketch folder named \"{1}\".\n" + "a sketch folder named \"{1}\".\n" +
"Create this folder, move the file, and continue?"), "Create this folder, move the file, and continue?"),
fileName, fileName,
properParent); properParent);
int result = JOptionPane.showOptionDialog(this, int result = JOptionPane.showOptionDialog(this,
prompt, prompt,
_("Moving"), _("Moving"),
JOptionPane.YES_NO_OPTION, JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, JOptionPane.QUESTION_MESSAGE,
null, null,
options, options,
options[0]); options[0]);
if (result == JOptionPane.YES_OPTION) { if (result == JOptionPane.YES_OPTION) {
// create properly named folder // create properly named folder
File properFolder = new File(file.getParent(), properParent); File properFolder = new File(sketchFile.getParent(), properParent);
if (properFolder.exists()) { if (properFolder.exists()) {
Base.showWarning(_("Error"), Base.showWarning(_("Error"),
I18n.format( I18n.format(
_("A folder named \"{0}\" already exists. " + _("A folder named \"{0}\" already exists. " +
"Can't open sketch."), "Can't open sketch."),
properParent properParent
), ),
null); null);
return false;
}
if (!properFolder.mkdirs()) {
//throw new IOException("Couldn't create sketch folder");
Base.showWarning(_("Error"),
_("Could not create the sketch folder."), null);
return false;
}
// copy the sketch inside
File properPdeFile = new File(properFolder, sketchFile.getName());
try {
Base.copyFile(file, properPdeFile);
} catch (IOException e) {
Base.showWarning(_("Error"), _("Could not copy to a proper location."), e);
return false;
}
// remove the original file, so user doesn't get confused
sketchFile.delete();
// update with the new path
file = properPdeFile;
} else if (result == JOptionPane.NO_OPTION) {
return false; return false;
} }
if (!properFolder.mkdirs()) {
//throw new IOException("Couldn't create sketch folder");
Base.showWarning(_("Error"),
_("Could not create the sketch folder."), null);
return false;
}
// copy the sketch inside
File properPdeFile = new File(properFolder, file.getName());
try {
Base.copyFile(file, properPdeFile);
} catch (IOException e) {
Base.showWarning(_("Error"), _("Could not copy to a proper location."), e);
return false;
}
// remove the original file, so user doesn't get confused
file.delete();
// update with the new path
file = properPdeFile;
} else if (result == JOptionPane.NO_OPTION) {
return false;
} }
} }