Skip to content

Commit bede696

Browse files
author
Federico Fissore
committed
Installation folder check both at startup and when user attempts to change
sketchbook location. Fixes #2719
1 parent 054a901 commit bede696

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

app/src/cc/arduino/view/preferences/Preferences.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.awt.event.ActionListener;
4040
import java.awt.event.WindowEvent;
4141
import java.io.File;
42+
import java.util.*;
4243

4344
import static processing.app.I18n._;
4445

@@ -588,6 +589,12 @@ private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
588589
}//GEN-LAST:event_cancelButtonActionPerformed
589590

590591
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
592+
java.util.List<String> errors = validateData();
593+
if (!errors.isEmpty()) {
594+
Base.showWarning(_("Error"), errors.get(0), null);
595+
return;
596+
}
597+
591598
savePreferencesData();
592599
for (Editor editor : base.getEditors()) {
593600
editor.applyPreferences();
@@ -619,6 +626,14 @@ private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
619626
private javax.swing.JCheckBox verifyUploadBox;
620627
// End of variables declaration//GEN-END:variables
621628

629+
private java.util.List<String> validateData() {
630+
java.util.List<String> errors = new LinkedList<String>();
631+
if (FileUtils.isSubDirectory(new File(sketchbookLocationField.getText()), new File(PreferencesData.get("runtime.ide.path")))) {
632+
errors.add(_("The specified sketchbook folder contains your copy of the IDE.\nPlease choose a different folder for your sketchbook."));
633+
}
634+
return errors;
635+
}
636+
622637
private void savePreferencesData() {
623638
String oldPath = PreferencesData.get("sketchbook.path");
624639
String newPath = sketchbookLocationField.getText();

app/src/processing/app/Base.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ public Base(String[] args) throws Exception {
274274
BaseNoGui.notifier = new GUIUserNotifier(this);
275275
this.recentSketchesMenuItems = new LinkedList<JMenuItem>();
276276

277+
BaseNoGui.checkInstallationFolder();
278+
277279
String sketchbookPath = BaseNoGui.getSketchbookPath();
278280

279281
// If no path is set, get the default sketchbook folder for this platform

app/src/processing/app/helpers/GUIUserNotifier.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void showMessage(String title, String message) {
4848
public void showWarning(String title, String message, Exception e) {
4949
if (title == null) title = _("Warning");
5050

51-
JOptionPane.showMessageDialog(new Frame(), message, title,
51+
JOptionPane.showMessageDialog(base.getActiveEditor(), message, title,
5252
JOptionPane.WARNING_MESSAGE);
5353

5454
if (e != null) e.printStackTrace();

arduino-core/src/processing/app/BaseNoGui.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,10 +754,33 @@ static public void main(String args[]) throws Exception {
754754
initPortableFolder();
755755

756756
initParameters(args);
757-
757+
758+
checkInstallationFolder();
759+
758760
init(args);
759761
}
760762

763+
public static void checkInstallationFolder() {
764+
if (isIDEInstalledIntoSettingsFolder()) {
765+
showError(_("Incorrect IDE installation folder"), _("Your copy of the IDE is installed in a subfolder of your settings folder.\nPlease move the IDE to another folder."), 10);
766+
}
767+
if (isIDEInstalledIntoSketchbookFolder()) {
768+
showError(_("Incorrect IDE installation folder"), _("Your copy of the IDE is installed in a subfolder of your sketchbook.\nPlease move the IDE to another folder."), 10);
769+
}
770+
}
771+
772+
public static boolean isIDEInstalledIntoSketchbookFolder() {
773+
return PreferencesData.has("sketchbook.path") && FileUtils.isSubDirectory(new File(PreferencesData.get("sketchbook.path")), new File(PreferencesData.get("runtime.ide.path")));
774+
}
775+
776+
public static boolean isIDEInstalledIntoSettingsFolder() {
777+
try {
778+
return FileUtils.isSubDirectory(BaseNoGui.getPlatform().getSettingsFolder(), new File(PreferencesData.get("runtime.ide.path")));
779+
} catch (Exception e) {
780+
return false;
781+
}
782+
}
783+
761784
static public void onBoardOrPortChange() {
762785
examplesFolder = getContentFile("examples");
763786
toolsFolder = getContentFile("tools");

0 commit comments

Comments
 (0)