working to handle how compatibility check happens

This commit is contained in:
Ben Fry
2023-01-14 22:02:38 -05:00
parent 5b8c8b11a3
commit 71e31bcd02
8 changed files with 65 additions and 21 deletions
+3 -3
View File
@@ -773,10 +773,10 @@ public class Base {
contribModes = new ArrayList<>();
}
File modesFolder = getSketchbookModesFolder();
List<ModeContribution> contribModes = getContribModes();
List<ModeContribution> knownList = getContribModes();
Map<File, ModeContribution> known = new HashMap<>();
for (ModeContribution contrib : contribModes) {
for (ModeContribution contrib : knownList) {
known.put(contrib.getFolder(), contrib);
}
File[] potential = ContributionType.MODE.listCandidates(modesFolder);
@@ -1599,7 +1599,7 @@ public class Base {
"while opening a new editor window. Please report this.", t, true);
} else {
Messages.showTrace("Mode Problems",
"A nasty error occurred while trying to use " + nextMode.getTitle() + ".\n" +
"A nasty error occurred while trying to use " + nextMode.getTitle() + "”.\n" +
"It may not be compatible with this version of Processing.\n" +
"Try updating the Mode or contact its author for a new version.", t, false);
}
@@ -26,6 +26,7 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import processing.app.Base;
import processing.core.PApplet;
import processing.data.StringDict;
import processing.data.StringList;
@@ -189,8 +190,9 @@ abstract public class Contribution {
}
public boolean isCompatible(int versionNum) {
return ((maxRevision == 0 || versionNum <= maxRevision) && versionNum >= minRevision);
public boolean isCompatible() {
final int revisionNum = Base.getRevision();
return ((maxRevision == 0 || revisionNum <= maxRevision) && revisionNum >= minRevision);
}
@@ -245,6 +247,7 @@ abstract public class Contribution {
*/
/*
static public StringDict loadProperties(File contribFolder,
ContributionType type) {
File propertiesFile = new File(contribFolder, type.getPropertiesName());
@@ -253,6 +256,7 @@ abstract public class Contribution {
}
return null;
}
*/
/**
@@ -306,8 +306,8 @@ public class ContributionListing {
if (contrib.isInstalled()) {
Contribution available = findAvailableContribution(contrib);
return available != null &&
(available.getVersion() > contrib.getVersion() &&
available.isCompatible(Base.getRevision()));
available.getVersion() > contrib.getVersion() &&
available.isCompatible();
}
return false;
}
@@ -31,6 +31,8 @@ import processing.app.Library;
import processing.app.Messages;
import processing.app.Util;
import processing.app.ui.Editor;
import processing.core.PApplet;
import processing.data.StringDict;
public enum ContributionType {
@@ -69,6 +71,17 @@ public enum ContributionType {
}
public StringDict loadProperties(File contribFolder) {
File propertiesFile = new File(contribFolder, getPropertiesName());
if (propertiesFile.exists()) {
return Util.readSettings(propertiesFile, false);
} else {
System.err.println("Not found: " + propertiesFile);
}
return null;
}
public File createTempFolder() throws IOException {
return Util.createTempFolder(toString(), "tmp", getSketchbookFolder());
}
@@ -116,7 +129,35 @@ public enum ContributionType {
public boolean isCandidate(File potential) {
return (potential.isDirectory() &&
new File(potential, toString()).exists() &&
!isTempFolderName(potential.getName()));
!isTempFolderName(potential.getName()) &&
isCompatible(potential));
}
/**
* Whether this contrib is compatible with this revision of Processing.
*/
private boolean isCompatible(File contribFolder) {
StringDict properties = loadProperties(contribFolder);
if (properties != null) {
final int revisionNum = Base.getRevision();
int minRevision = 0;
String minRev = properties.get("minRevision");
if (minRev != null) {
minRevision = PApplet.parseInt(minRev, 0);
}
int maxRevision = 0;
String maxRev = properties.get("maxRevision");
if (maxRev != null) {
maxRevision = PApplet.parseInt(maxRev, 0);
}
return ((maxRevision == 0 || revisionNum <= maxRevision) && revisionNum >= minRevision);
}
// Maybe it's ok, maybe it's not. Don't know him; can't vouch for him.
return true;
}
@@ -60,8 +60,8 @@ public class ExamplesContribution extends LocalContribution {
}
static public boolean isCompatible(Base base, StringDict props) {
return isCompatible(base.getActiveEditor().getMode(), props);
static public boolean isModeCompatible(Base base, StringDict props) {
return isModeCompatible(base.getActiveEditor().getMode(), props);
}
@@ -69,7 +69,7 @@ public class ExamplesContribution extends LocalContribution {
* Determine whether the example is compatible with the current Mode.
* @return true if compatible with the Mode of the currently active editor
*/
static public boolean isCompatible(Mode mode, StringDict props) {
static public boolean isModeCompatible(Mode mode, StringDict props) {
String currentIdentifier = mode.getIdentifier();
StringList compatibleList = parseModeList(props);
if (compatibleList.size() == 0) {
@@ -103,7 +103,7 @@ public class ListPanel extends JPanel implements Scrollable {
if (rowValue instanceof SectionHeaderContribution) {
c.setBackground(sectionColor);
} else if (isRowSelected(row)) {
if (((Contribution) rowValue).isCompatible(Base.getRevision())) {
if (((Contribution) rowValue).isCompatible()) {
c.setBackground(selectionColor);
} else {
c.setBackground(selectionColorIncompatible);
@@ -238,7 +238,7 @@ public class ListPanel extends JPanel implements Scrollable {
if (ContributionListing.getInstance().hasUpdates(c)) {
pos = 2;
}
if (!c.isCompatible(Base.getRevision())) {
if (!c.isCompatible()) {
// This is weird because it means some grayed-out items will
// show up before non-gray items. We probably need another
// state icon for 'installed but incompatible' [fry 220116]
@@ -387,7 +387,7 @@ public class ListPanel extends JPanel implements Scrollable {
if (contribution instanceof SectionHeaderContribution) {
// grouping color for libraries, modes, tools headers in updates panel
label.setForeground(textColorIncompatible);
} else if (contribution.isCompatible(Base.getRevision())) {
} else if (contribution.isCompatible()) {
label.setForeground(textColor);
} else {
label.setForeground(textColorIncompatible);
@@ -405,7 +405,7 @@ public class ListPanel extends JPanel implements Scrollable {
// float amount = detail.getProgressAmount();
// icon = (amount == -1) ? downloadingIcon : renderProgressIcon(amount);
} else if (contribution.isInstalled()) {
if (!contribution.isCompatible(Base.getRevision())) {
if (!contribution.isCompatible()) {
icon = incompatibleIcon;
} else if (ContributionListing.getInstance().hasUpdates(contribution)) {
icon = updateAvailableIcon;
@@ -45,7 +45,6 @@ import processing.app.laf.PdeButtonUI;
import processing.app.laf.PdeProgressBarUI;
import processing.app.ui.Theme;
import processing.app.ui.Toolkit;
import processing.app.Base;
import processing.app.Platform;
@@ -414,10 +413,10 @@ class StatusPanel extends JPanel {
installButton.setEnabled(!contrib.isInstalled() &&
listing.isDownloaded() &&
contrib.isCompatible(Base.getRevision()) &&
contrib.isCompatible() &&
!detail.installInProgress);
if (contrib.isCompatible(Base.getRevision())) {
if (contrib.isCompatible()) {
if (installButton.isEnabled()) {
if (latestVersion != null) {
updateLabel.setText(latestVersion + " available");
+3 -3
View File
@@ -57,7 +57,6 @@ import processing.app.Mode;
import processing.app.Platform;
import processing.app.Preferences;
import processing.app.SketchReference;
import processing.app.contrib.Contribution;
import processing.app.contrib.ContributionManager;
import processing.app.contrib.ContributionType;
import processing.app.contrib.ExamplesContribution;
@@ -350,9 +349,10 @@ public class ExamplesFrame extends JFrame {
if (folders != null) {
for (File sub : folders) {
StringDict props =
Contribution.loadProperties(sub, ContributionType.EXAMPLES);
//Contribution.loadProperties(sub, ContributionType.EXAMPLES);
ContributionType.EXAMPLES.loadProperties(sub);
if (props != null) {
if (ExamplesContribution.isCompatible(base, props)) {
if (ExamplesContribution.isModeCompatible(base, props)) {
DefaultMutableTreeNode subNode =
new DefaultMutableTreeNode(props.get("name"));
if (base.addSketches(subNode, sub, true)) {