diff --git a/app/src/processing/app/ContributionManager.java b/app/src/processing/app/ContributionManager.java
index 6b496721f..9518f1c5d 100644
--- a/app/src/processing/app/ContributionManager.java
+++ b/app/src/processing/app/ContributionManager.java
@@ -390,14 +390,17 @@ public class ContributionManager {
public void run() {
progressMonitor.startTask("Removing", ProgressMonitor.UNKNOWN);
+ boolean doBackup = Preferences.getBoolean("contribution.backup.on_remove");
if (ContributionManager.requiresRestart(contribution)) {
- if (backupContribution(contribution, false)) {
+
+ if (!doBackup || (doBackup && backupContribution(contribution, false))) {
if (ContributionManager.flagForDeletion(contribution)) {
contribListing.replaceContribution(contribution, contribution);
}
}
} else {
- if (backupContribution(contribution, true)) {
+ if ((!doBackup && contribution.getFolder().delete())
+ || (doBackup && backupContribution(contribution, true))) {
Contribution advertisedVersion = contribListing
.getAdvertisedContribution(contribution);
@@ -407,6 +410,12 @@ public class ContributionManager {
contribListing.replaceContribution(contribution,
advertisedVersion);
}
+ } else {
+ if (doBackup) {
+
+ } else {
+ statusBar.setErrorMessage("Could not delete the contribution's files");
+ }
}
}
refreshInstalled();
@@ -709,8 +718,6 @@ public class ContributionManager {
File libraryDestination = editor.getBase().getSketchbookLibrariesFolder();
File newLibDest = new File(libraryDestination, libFolderName);
- boolean doInstall = true;
-
for (Library oldLib : oldLibs) {
// XXX: Handle other cases when installing libraries.
@@ -719,40 +726,51 @@ public class ContributionManager {
if (oldLib.getFolder().exists() && oldLib.getFolder().equals(newLibDest)) {
int result = 0;
+ boolean doBackup = Preferences.getBoolean("contribution.backup.on_install");
if (confirmReplace) {
- result = Base.showYesNoQuestion(editor, "Replace",
- "Replace existing \"" + oldLib.getName() + "\" library?",
- "An existing copy of the \"" + oldLib.getName() + "\" library
"+
- "has been found in your sketchbook. Clicking “Yes�
"+
- "will move the existing library to a backup folder
" +
- " in libraries/old before replacing it.");
- }
- if (!confirmReplace || result == JOptionPane.YES_OPTION) {
- if (!backupContribution(oldLib, true)) {
- return null;
+ if (doBackup) {
+ result = Base.showYesNoQuestion(editor, "Replace",
+ "Replace pre-existing \"" + oldLib.getName() + "\" library?",
+ "A pre-existing copy of the \"" + oldLib.getName() + "\" library
"+
+ "has been found in your sketchbook. Clicking “Yes”
"+
+ "will move the existing library to a backup folder
" +
+ " in libraries/old before replacing it.");
+ if (result != JOptionPane.YES_OPTION || !backupContribution(oldLib, true)) {
+ return null;
+ }
+ } else {
+ result = Base.showYesNoQuestion(editor, "Replace",
+ "Replace pre-existing \"" + oldLib.getName() + "\" library?",
+ "A pre-existing copy of the \"" + oldLib.getName() + "\" library
"+
+ "has been found in your sketchbook. Clicking “Yes”
"+
+ "will permanently delete this library and all of its contents
"+
+ "before replacing it.");
+ if (result != JOptionPane.YES_OPTION || !oldLib.getFolder().delete()) {
+ return null;
+ }
}
} else {
- doInstall = false;
+ if (doBackup && !backupContribution(oldLib, true)
+ || !doBackup && !oldLib.getFolder().delete()) {
+ return null;
+ }
}
}
}
- if (doInstall) {
- // Move newLib to the sketchbook library folder
- if (newLib.getFolder().renameTo(newLibDest)) {
- return new Library(newLibDest, null);
+ // Move newLib to the sketchbook library folder
+ if (newLib.getFolder().renameTo(newLibDest)) {
+ return new Library(newLibDest, null);
// try {
// FileUtils.copyDirectory(newLib.folder, libFolder);
// FileUtils.deleteQuietly(newLib.folder);
// newLib.folder = libFolder;
// } catch (IOException e) {
- } else {
- statusBar.setErrorMessage("Could not move library \""
- + newLib.getName() + "\" to sketchbook.");
- }
+ } else {
+ statusBar.setErrorMessage("Could not move library \""
+ + newLib.getName() + "\" to sketchbook.");
+ return null;
}
-
- return null;
}
public void refreshInstalled() {
diff --git a/build/shared/lib/preferences.txt b/build/shared/lib/preferences.txt
index 8cde01b70..95d519f3a 100755
--- a/build/shared/lib/preferences.txt
+++ b/build/shared/lib/preferences.txt
@@ -54,6 +54,17 @@ last.sketch.count=0
# true if you want sketches to re-open when you next run processing
last.sketch.restore=true
+# by default, contributions are moved to backup folders when
+# they are removed or replaced. The locations of the backup
+# folders are:
+# sketchbook/libraries/old
+# sketchbook/tools/old
+# sketchbook/modes/old
+# true to backup contributions when "Remove" button is pressed
+contribution.backup.on_remove = true
+# true to backup contributions when installing a newer version
+# (for example, from a plb file)
+contribution.backup.on_install = true
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!