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
1 changed files with 55 additions and 51 deletions

View File

@ -2131,68 +2131,72 @@ public class Editor extends JFrame implements RunnerListener {
File file = SketchData.checkSketchFile(sketchFile);
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);
return false;
if (file == null)
{
if (!fileName.endsWith(".ino") && !fileName.endsWith(".pde")) {
} else {
String properParent =
fileName.substring(0, fileName.length() - 4);
Base.showWarning(_("Bad file selected"),
_("Arduino can only open its own sketches\n" +
"and other files ending in .ino or .pde"), null);
return false;
Object[] options = { _("OK"), _("Cancel") };
String prompt = I18n.format(_("The file \"{0}\" needs to be inside\n" +
} else {
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" +
"Create this folder, move the file, and continue?"),
fileName,
properParent);
int result = JOptionPane.showOptionDialog(this,
prompt,
_("Moving"),
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[0]);
int result = JOptionPane.showOptionDialog(this,
prompt,
_("Moving"),
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[0]);
if (result == JOptionPane.YES_OPTION) {
// create properly named folder
File properFolder = new File(file.getParent(), properParent);
if (properFolder.exists()) {
Base.showWarning(_("Error"),
I18n.format(
_("A folder named \"{0}\" already exists. " +
"Can't open sketch."),
properParent
),
if (result == JOptionPane.YES_OPTION) {
// create properly named folder
File properFolder = new File(sketchFile.getParent(), properParent);
if (properFolder.exists()) {
Base.showWarning(_("Error"),
I18n.format(
_("A folder named \"{0}\" already exists. " +
"Can't open sketch."),
properParent
),
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;
}
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;
}
}