From 271fc01bc6e08a19db8c0611cee9b8044cedc108 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Thu, 5 Aug 2021 22:29:32 -0400 Subject: [PATCH] initial code to install a contrib from a pdex file --- app/src/processing/app/Base.java | 12 ++++- .../app/contrib/AvailableContribution.java | 46 +++++++++++++++++-- todo.txt | 3 ++ 3 files changed, 54 insertions(+), 7 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index bace3ed72..3ea401bd3 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1340,9 +1340,17 @@ public class Base { return null; // no luck } else if (path.endsWith(CONTRIB_BUNDLE_EXT)) { - // TODO Install a contrib here + try { + // TODO should probably prompt the user first + LocalContribution contrib = + AvailableContribution.install(this, new File(path)); + if (contrib == null) { + System.err.println("Could not install a contrib from " + path); + } + } catch (IOException e) { + Messages.err("Error while installing " + path, e); + } return null; - } return handleOpen(path, false); diff --git a/app/src/processing/app/contrib/AvailableContribution.java b/app/src/processing/app/contrib/AvailableContribution.java index 4c7a86ac0..184ae050a 100644 --- a/app/src/processing/app/contrib/AvailableContribution.java +++ b/app/src/processing/app/contrib/AvailableContribution.java @@ -23,11 +23,11 @@ package processing.app.contrib; import java.io.*; +import java.util.Enumeration; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; -import processing.app.Base; -import processing.app.Language; -import processing.app.Platform; -import processing.app.Util; +import processing.app.*; import processing.core.PApplet; import processing.data.StringDict; import processing.data.StringList; @@ -83,6 +83,43 @@ public class AvailableContribution extends Contribution { } + static ContributionType matchContribType(String path) { + String filename = path.substring(path.lastIndexOf('/') + 1); + for (ContributionType type : ContributionType.values()) { + if (filename.equals(type.getPropertiesName())) { + return type; + } + } + return null; + } + + + static public LocalContribution install(Base base, File contribArchive) throws IOException { + AvailableContribution ac = null; + + ZipFile zf = new ZipFile(contribArchive); + Enumeration entries = zf.entries(); + while (entries.hasMoreElements()) { + ZipEntry entry = (ZipEntry) entries.nextElement(); + String name = entry.getName(); + if (name.endsWith(".properties")) { + ContributionType type = matchContribType(name); + if (type != null) { + StringDict params = new StringDict(PApplet.createReader(zf.getInputStream(entry))); + ac = new AvailableContribution(type, params); + break; + } + } + } + zf.close(); + + if (ac != null) { + return ac.install(base, contribArchive, false, null); + } + return null; + } + + /** * @param contribArchive * a zip file containing the library to install @@ -109,7 +146,6 @@ public class AvailableContribution extends Contribution { } Util.unzip(contribArchive, tempFolder); - LocalContribution installedContrib = null; // Find the first legitimate folder in what we just unzipped File contribFolder = type.findCandidate(tempFolder); diff --git a/todo.txt b/todo.txt index b7702f41b..fb4ec7eca 100755 --- a/todo.txt +++ b/todo.txt @@ -25,6 +25,8 @@ X standard key shortcuts on macOS https://support.apple.com/en-us/HT201236 X update to JDK 11.0.12+7 X rewrite download handler to just use a simple _ remove the rest of the jre downloader code +X initial code to install a contrib from a pdex file +_ test to make sure it's behaving properly Sam updates X can we get rid of pdexEnabled? does the current code work w/ java tabs? @@ -42,6 +44,7 @@ o probably being removed from future OS X versions before release _ update the README for alpha 6 (and this release too, when ready) +_ add issue for implementing the Linux file associations in install.sh _ don't allow "Show Sketch Folder" for untitled sketches