mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
initial code to install a contrib from a pdex file
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 <get>
|
||||
_ 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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user