Added preference to determine if contribution should be moved to a backup directory when installing/removing it

This commit is contained in:
pesckal
2011-08-31 20:47:22 +00:00
parent 3638a78218
commit 7cb7265472
2 changed files with 54 additions and 25 deletions
+43 -25
View File
@@ -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<br>"+
"has been found in your sketchbook. Clicking “Yesâ€Â<br>"+
"will move the existing library to a backup folder<br>" +
" in <i>libraries/old</i> 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<br>"+
"has been found in your sketchbook. Clicking “Yes”<br>"+
"will move the existing library to a backup folder<br>" +
" in <i>libraries/old</i> 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<br>"+
"has been found in your sketchbook. Clicking “Yes”<br>"+
"will permanently delete this library and all of its contents<br>"+
"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() {
+11
View File
@@ -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
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!