From 067d51deaab72ade505a853425aca737cb738606 Mon Sep 17 00:00:00 2001 From: pesckal Date: Wed, 26 Oct 2011 06:08:28 +0000 Subject: [PATCH] use ids when installing contributions --- .../processing/app/ContributionManager.java | 24 ++++++++++++++----- .../contribution/InstalledContribution.java | 6 +++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/app/src/processing/app/ContributionManager.java b/app/src/processing/app/ContributionManager.java index be73bed53..153b7d17a 100644 --- a/app/src/processing/app/ContributionManager.java +++ b/app/src/processing/app/ContributionManager.java @@ -168,6 +168,19 @@ public class ContributionManager { return null; } + static File getSketchbookContribFolder(Base base, Type type) { + switch (type) { + case LIBRARY: + case LIBRARY_COMPILATION: + return base.getSketchbookLibrariesFolder(); + case TOOL: + return base.getSketchbookToolsFolder(); + case MODE: + return base.getSketchbookModesFolder(); + } + return null; + } + static InstalledContribution create(Base base, Type type, File folder) { switch (type) { case LIBRARY: @@ -286,17 +299,16 @@ public class ContributionManager { String libFolderName = newLib.getFolder().getName(); - File libraryDestination = editor.getBase().getSketchbookLibrariesFolder(); + File libraryDestination = ContributionManager + .getSketchbookContribFolder(editor.getBase(), newLib.getType()); File newLibDest = new File(libraryDestination, libFolderName); for (InstalledContribution oldLib : oldLibs) { - // XXX: Handle other cases when installing libraries. - // -What if a library by the same name is already installed? - // -What if newLibDest exists, but isn't used by an existing library? - if (oldLib.getFolder().exists() && oldLib.getFolder().equals(newLibDest)) { + if ((oldLib.getFolder().exists() && oldLib.getFolder().equals(newLibDest)) + || (oldLib.getId() != null && oldLib.getId().equals(newLib.getId()))) { - if (ContributionManager.requiresRestart(newLib)) { + if (ContributionManager.requiresRestart(oldLib)) { // XXX: We can't replace stuff, soooooo.... do something different if (!backupContribution(editor, oldLib, false, statusBar)) { return null; diff --git a/app/src/processing/app/contribution/InstalledContribution.java b/app/src/processing/app/contribution/InstalledContribution.java index d5503744d..cbcf6fb02 100644 --- a/app/src/processing/app/contribution/InstalledContribution.java +++ b/app/src/processing/app/contribution/InstalledContribution.java @@ -30,6 +30,7 @@ import processing.app.*; public abstract class InstalledContribution implements Contribution { protected String name; // "pdf" or "PDF Export" + protected String id; // 1 protected String category; // "Sound" protected String authorList; // Ben Fry protected String url; // http://processing.org @@ -52,6 +53,7 @@ public abstract class InstalledContribution implements Contribution { properties = Base.readSettings(propertiesFile); name = properties.get("name"); + id = properties.get("id"); category = ContributionListing.getCategory(properties.get("category")); if (name == null) { name = folder.getName(); @@ -86,6 +88,10 @@ public abstract class InstalledContribution implements Contribution { return name; } + public String getId() { + return id; + } + public String getAuthorList() { return authorList; }