Skip to content

Commit

Permalink
Installation folder check both at startup and when user attempts to c…
Browse files Browse the repository at this point in the history
…hange

sketchbook location. Fixes esp8266#2719
  • Loading branch information
Federico Fissore committed Jun 3, 2015
1 parent 054a901 commit bede696
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
15 changes: 15 additions & 0 deletions app/src/cc/arduino/view/preferences/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.io.File;
import java.util.*;

import static processing.app.I18n._;

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

private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
java.util.List<String> errors = validateData();
if (!errors.isEmpty()) {
Base.showWarning(_("Error"), errors.get(0), null);
return;
}

savePreferencesData();
for (Editor editor : base.getEditors()) {
editor.applyPreferences();
Expand Down Expand Up @@ -619,6 +626,14 @@ private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
private javax.swing.JCheckBox verifyUploadBox;
// End of variables declaration//GEN-END:variables

private java.util.List<String> validateData() {
java.util.List<String> errors = new LinkedList<String>();
if (FileUtils.isSubDirectory(new File(sketchbookLocationField.getText()), new File(PreferencesData.get("runtime.ide.path")))) {
errors.add(_("The specified sketchbook folder contains your copy of the IDE.\nPlease choose a different folder for your sketchbook."));
}
return errors;
}

private void savePreferencesData() {
String oldPath = PreferencesData.get("sketchbook.path");
String newPath = sketchbookLocationField.getText();
Expand Down
2 changes: 2 additions & 0 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ public Base(String[] args) throws Exception {
BaseNoGui.notifier = new GUIUserNotifier(this);
this.recentSketchesMenuItems = new LinkedList<JMenuItem>();

BaseNoGui.checkInstallationFolder();

String sketchbookPath = BaseNoGui.getSketchbookPath();

// If no path is set, get the default sketchbook folder for this platform
Expand Down
2 changes: 1 addition & 1 deletion app/src/processing/app/helpers/GUIUserNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void showMessage(String title, String message) {
public void showWarning(String title, String message, Exception e) {
if (title == null) title = _("Warning");

JOptionPane.showMessageDialog(new Frame(), message, title,
JOptionPane.showMessageDialog(base.getActiveEditor(), message, title,
JOptionPane.WARNING_MESSAGE);

if (e != null) e.printStackTrace();
Expand Down
25 changes: 24 additions & 1 deletion arduino-core/src/processing/app/BaseNoGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -754,10 +754,33 @@ static public void main(String args[]) throws Exception {
initPortableFolder();

initParameters(args);


checkInstallationFolder();

init(args);
}

public static void checkInstallationFolder() {
if (isIDEInstalledIntoSettingsFolder()) {
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);
}
if (isIDEInstalledIntoSketchbookFolder()) {
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);
}
}

public static boolean isIDEInstalledIntoSketchbookFolder() {
return PreferencesData.has("sketchbook.path") && FileUtils.isSubDirectory(new File(PreferencesData.get("sketchbook.path")), new File(PreferencesData.get("runtime.ide.path")));
}

public static boolean isIDEInstalledIntoSettingsFolder() {
try {
return FileUtils.isSubDirectory(BaseNoGui.getPlatform().getSettingsFolder(), new File(PreferencesData.get("runtime.ide.path")));
} catch (Exception e) {
return false;
}
}

static public void onBoardOrPortChange() {
examplesFolder = getContentFile("examples");
toolsFolder = getContentFile("tools");
Expand Down

0 comments on commit bede696

Please sign in to comment.