mirror of
https://github.com/processing/processing4.git
synced 2026-02-15 03:15:40 +01:00
more cleanup of contrib managers
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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<InstalledContribution> getContributions(ContributionType type, Editor editor) {
|
||||
static ArrayList<InstalledContribution> listContributions(ContributionType type, Editor editor) {
|
||||
ArrayList<InstalledContribution> contribs = new ArrayList<InstalledContribution>();
|
||||
switch (type) {
|
||||
case LIBRARY:
|
||||
|
||||
@@ -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);
|
||||
// }
|
||||
|
||||
@@ -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<InstalledContribution> 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) {
|
||||
|
||||
Reference in New Issue
Block a user