1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-08-01 03:47:23 +03:00

Installation folder check both at startup and when user attempts to change

sketchbook location. Fixes #2719
This commit is contained in:
Federico Fissore
2015-06-03 17:27:57 +02:00
parent 054a901b99
commit bede6967d5
4 changed files with 42 additions and 2 deletions

View File

@ -39,6 +39,7 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.io.File;
import java.util.*;
import static processing.app.I18n._;
@ -588,6 +589,12 @@ public class Preferences extends javax.swing.JDialog {
}//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();
@ -619,6 +626,14 @@ public class Preferences extends javax.swing.JDialog {
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();

View File

@ -274,6 +274,8 @@ public class Base {
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

View File

@ -48,7 +48,7 @@ public class GUIUserNotifier extends UserNotifier {
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();