Skip to content

Commit 1862827

Browse files
author
Federico Fissore
committed
Portable folder can now be set to any arbitrary path, not just subfolders
of "portable". Fixes #4103
1 parent 907af81 commit 1862827

File tree

4 files changed

+12
-19
lines changed

4 files changed

+12
-19
lines changed

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

-6
Original file line numberDiff line numberDiff line change
@@ -556,12 +556,6 @@ private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
556556
File file = Base.selectFolder(tr("Select new sketchbook location"), dflt, this);
557557
if (file != null) {
558558
String path = file.getAbsolutePath();
559-
if (BaseNoGui.getPortableFolder() != null) {
560-
path = FileUtils.relativePath(BaseNoGui.getPortableFolder().toString(), path);
561-
if (path == null) {
562-
path = BaseNoGui.getPortableSketchbookFolder();
563-
}
564-
}
565559
sketchbookLocationField.setText(path);
566560
}
567561
}//GEN-LAST:event_browseButtonActionPerformed

app/src/processing/app/Base.java

+1-7
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ protected boolean restoreSketches() throws Exception {
523523
if (path == null) {
524524
continue;
525525
}
526-
if (BaseNoGui.getPortableFolder() != null) {
526+
if (BaseNoGui.getPortableFolder() != null && !new File(path).isAbsolute()) {
527527
File absolute = new File(BaseNoGui.getPortableFolder(), path);
528528
try {
529529
path = absolute.getCanonicalPath();
@@ -570,12 +570,6 @@ protected void storeSketches() {
570570
if (path.startsWith(untitledPath) && !editor.getSketch().isModified()) {
571571
continue;
572572
}
573-
if (BaseNoGui.getPortableFolder() != null) {
574-
path = FileUtils.relativePath(BaseNoGui.getPortableFolder().toString(), path);
575-
if (path == null) {
576-
continue;
577-
}
578-
}
579573
PreferencesData.set("last.sketch" + index + ".path", path);
580574

581575
int[] location = editor.getPlacement();

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

+10-6
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,11 @@ static public File getSettingsFolder() {
267267
}
268268

269269
static public File getSketchbookFolder() {
270-
if (portableFolder != null)
271-
return new File(portableFolder, PreferencesData.get("sketchbook.path"));
272-
return absoluteFile(PreferencesData.get("sketchbook.path"));
270+
String sketchBookPath = PreferencesData.get("sketchbook.path");
271+
if (getPortableFolder() != null && !new File(sketchBookPath).isAbsolute()) {
272+
return new File(getPortableFolder(), sketchBookPath);
273+
}
274+
return absoluteFile(sketchBookPath);
273275
}
274276

275277
static public File getSketchbookHardwareFolder() {
@@ -301,10 +303,11 @@ static public String getSketchbookPath() {
301303
// If it doesn't, warn the user that the sketchbook folder is being reset.
302304
if (sketchbookPath != null) {
303305
File sketchbookFolder;
304-
if (getPortableFolder() != null)
306+
if (getPortableFolder() != null && !new File(sketchbookPath).isAbsolute()) {
305307
sketchbookFolder = new File(getPortableFolder(), sketchbookPath);
306-
else
308+
} else {
307309
sketchbookFolder = absoluteFile(sketchbookPath);
310+
}
308311
if (!sketchbookFolder.exists()) {
309312
showWarning(tr("Sketchbook folder disappeared"),
310313
tr("The sketchbook folder no longer exists.\n" +
@@ -658,8 +661,9 @@ static protected void initPlatform() {
658661
static public void initPortableFolder() {
659662
// Portable folder
660663
portableFolder = getContentFile("portable");
661-
if (!portableFolder.exists())
664+
if (!portableFolder.exists()) {
662665
portableFolder = null;
666+
}
663667
}
664668

665669
static public void initVersion() {

build/shared/revisions.txt

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ ARDUINO 1.6.7
55
* Serial plotter now allows to plot multiple values at once. Thanks @henningpohl
66
* New translations
77
* Added support to file:// protocol for boards manager URLs
8+
* Portable sketchbook folder can now be any arbitrary location
89

910
[libraries]
1011
* SPI: Added SPI.transfer16(...) function to SAM core.

0 commit comments

Comments
 (0)