diff --git a/app/src/processing/app/contrib/AdvertisedContribution.java b/app/src/processing/app/contrib/AdvertisedContribution.java index 250c3d92c..be83c2600 100644 --- a/app/src/processing/app/contrib/AdvertisedContribution.java +++ b/app/src/processing/app/contrib/AdvertisedContribution.java @@ -67,8 +67,7 @@ class AdvertisedContribution implements Contribution { // Unzip the file into the modes, tools, or libraries folder inside the // sketchbook. Unzipping to /tmp is problematic because it may be on // another file system, so move/rename operations will break. - File sketchbookContribFolder = - ContributionManager.getSketchbookContribFolder(editor.getBase(), type); + File sketchbookContribFolder = type.getSketchbookContribFolder(); File tempFolder = null; try { @@ -94,7 +93,7 @@ class AdvertisedContribution implements Contribution { contribFolder = InstalledContribution.findCandidate(tempFolder, type); } - InstalledContribution outgoing = null; + InstalledContribution installedContrib = null; if (contribFolder == null) { statusBar.setErrorMessage("Could not find a " + type + " in the downloaded file."); @@ -102,11 +101,15 @@ class AdvertisedContribution implements Contribution { } else { File propFile = new File(contribFolder, type + ".properties"); - if (writePropertiesFile(propFile)) { + if (!writePropertiesFile(propFile)) { + // 1. contribFolder now has a legit contribution, load it to get info. InstalledContribution newContrib = ContributionManager.load(editor.getBase(), contribFolder, type); - outgoing = - newContrib.install(editor, confirmReplace, statusBar); + + // 2. Check to make sure nothing has the same name already, + // backup old if needed, then move things into place and reload. + installedContrib = + newContrib.moveAndLoad(editor, confirmReplace, statusBar); } else { statusBar.setErrorMessage("Error overwriting .properties file."); @@ -117,7 +120,7 @@ class AdvertisedContribution implements Contribution { if (tempFolder.exists()) { Base.removeDir(tempFolder); } - return outgoing; + return installedContrib; } diff --git a/app/src/processing/app/contrib/ContributionManager.java b/app/src/processing/app/contrib/ContributionManager.java index dfc7478d0..23a7b1a44 100644 --- a/app/src/processing/app/contrib/ContributionManager.java +++ b/app/src/processing/app/contrib/ContributionManager.java @@ -115,9 +115,9 @@ public class ContributionManager { ContributionListing.download(url, contribZip, downloadProgress); if (!downloadProgress.isCanceled() && !downloadProgress.isError()) { - installProgress.startTask("Installing", ProgressMonitor.UNKNOWN); - InstalledContribution contribution = null; - contribution = ad.install(editor, contribZip, false, statusBar); + installProgress.startTask("Installing...", ProgressMonitor.UNKNOWN); + InstalledContribution contribution = + ad.install(editor, contribZip, false, statusBar); if (contribution != null) { contribListing.replaceContribution(ad, contribution); @@ -179,20 +179,6 @@ public class ContributionManager { // } - static File getSketchbookContribFolder(Base base, ContributionType 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 load(Base base, File folder, ContributionType type) { switch (type) { case LIBRARY: @@ -208,7 +194,7 @@ public class ContributionManager { } - static ArrayList getContributions(ContributionType type, Editor editor) { + static ArrayList listContributions(ContributionType type, Editor editor) { ArrayList contribs = new ArrayList(); switch (type) { case LIBRARY: diff --git a/app/src/processing/app/contrib/ContributionType.java b/app/src/processing/app/contrib/ContributionType.java index e6916c114..18e0d05e0 100644 --- a/app/src/processing/app/contrib/ContributionType.java +++ b/app/src/processing/app/contrib/ContributionType.java @@ -1,5 +1,9 @@ package processing.app.contrib; +import java.io.File; + +import processing.app.Base; + public enum ContributionType { // LIBRARY, LIBRARY_COMPILATION, TOOL, MODE; LIBRARY, TOOL, MODE; @@ -59,6 +63,19 @@ public enum ContributionType { } + public File getSketchbookContribFolder() { + switch (this) { + case LIBRARY: + return Base.getSketchbookLibrariesFolder(); + case TOOL: + return Base.getSketchbookToolsFolder(); + case MODE: + return Base.getSketchbookModesFolder(); + } + return null; + } + + // static public boolean validName(String s) { // return "library".equals(s) || "tool".equals(s) || "mode".equals(s); // } diff --git a/app/src/processing/app/contrib/InstalledContribution.java b/app/src/processing/app/contrib/InstalledContribution.java index 518ec2dc4..c2bc26a22 100644 --- a/app/src/processing/app/contrib/InstalledContribution.java +++ b/app/src/processing/app/contrib/InstalledContribution.java @@ -187,16 +187,15 @@ public abstract class InstalledContribution implements Contribution { } - InstalledContribution install(Editor editor, - boolean confirmReplace, - ErrorWidget statusBar) { + InstalledContribution moveAndLoad(Editor editor, + boolean confirmReplace, + ErrorWidget statusBar) { ArrayList oldContribs = - ContributionManager.getContributions(getType(), editor); + ContributionManager.listContributions(getType(), editor); String contribFolderName = getFolder().getName(); - File contribTypeFolder = - ContributionManager.getSketchbookContribFolder(editor.getBase(), getType()); + File contribTypeFolder = getType().getSketchbookContribFolder(); File contribFolder = new File(contribTypeFolder, contribFolderName); for (InstalledContribution oldContrib : oldContribs) {