mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-17 06:52:18 +01:00
Installation folder check both at startup and when user attempts to change
sketchbook location. Fixes #2719
This commit is contained in:
parent
054a901b99
commit
bede6967d5
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -754,10 +754,33 @@ public class BaseNoGui {
|
||||
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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user