2828import java .awt .Frame ;
2929import java .awt .event .ActionEvent ;
3030import java .awt .event .ActionListener ;
31-
3231import java .io .*;
3332import java .text .SimpleDateFormat ;
3433import java .util .*;
4544
4645import processing .app .contrib .*;
4746import processing .core .*;
47+ import processing .data .StringDict ;
48+ import processing .data .StringList ;
4849
4950
5051/**
@@ -438,9 +439,7 @@ public Base(String[] args) throws Exception {
438439 }
439440
440441 // check for updates
441- if (Preferences .getBoolean ("update.check" )) { //$NON-NLS-1$
442- new UpdateCheck (this );
443- }
442+ new UpdateCheck (this );
444443 }
445444
446445
@@ -517,6 +516,60 @@ public List<ExamplesContribution> getExampleContribs() {
517516 }
518517
519518
519+ private List <Contribution > getInstalledContribs () {
520+ List <Contribution > contributions = new ArrayList <Contribution >();
521+
522+ List <ModeContribution > modeContribs = getModeContribs ();
523+ contributions .addAll (modeContribs );
524+
525+ for (ModeContribution modeContrib : modeContribs ) {
526+ Mode mode = modeContrib .getMode ();
527+ contributions .addAll (new ArrayList <Library >(mode .contribLibraries ));
528+ }
529+
530+ // TODO this duplicates code in Editor, but it's not editor-specific
531+ // List<ToolContribution> toolContribs =
532+ // ToolContribution.loadAll(Base.getSketchbookToolsFolder());
533+ // contributions.addAll(toolContribs);
534+ contributions .addAll (ToolContribution .loadAll (getSketchbookToolsFolder ()));
535+
536+ contributions .addAll (getExampleContribs ());
537+ return contributions ;
538+ }
539+
540+
541+ public byte [] getInstalledContribsInfo () {
542+ List <Contribution > contribs = getInstalledContribs ();
543+ StringList entries = new StringList ();
544+ for (Contribution c : contribs ) {
545+ String entry = c .getTypeName () + "=" +
546+ PApplet .urlEncode (String .format ("name=%s\n url=%s\n revision=%d\n version=%s" ,
547+ c .getName (), c .getUrl (),
548+ c .getVersion (), c .getPrettyVersion ()));
549+ entries .append (entry );
550+ }
551+ String joined =
552+ "id=" + Preferences .get ("update.id" ) + "&" + entries .join ("&" );
553+ // StringBuilder sb = new StringBuilder();
554+ // try {
555+ // // Truly ridiculous attempt to shove everything into a GET request.
556+ // // More likely to be seen as part of a grand plot.
557+ // ByteArrayOutputStream baos = new ByteArrayOutputStream();
558+ // GZIPOutputStream output = new GZIPOutputStream(baos);
559+ // PApplet.saveStream(output, new ByteArrayInputStream(joined.getBytes()));
560+ // output.close();
561+ // byte[] b = baos.toByteArray();
562+ // for (int i = 0; i < b.length; i++) {
563+ // sb.append(PApplet.hex(b[i], 2));
564+ // }
565+ // } catch (IOException e) {
566+ // e.printStackTrace();
567+ // }
568+ // return sb.toString();
569+ return joined .getBytes ();
570+ }
571+
572+
520573 // Because of variations in native windowing systems, no guarantees about
521574 // changes to the focused and active Windows can be made. Developers must
522575 // never assume that this Window is the focused or active Window until this
@@ -2335,7 +2388,7 @@ static public byte[] loadBytesRaw(File file) throws IOException {
23352388 * Changed in 3.0a6 to return null (rather than empty hash) if no file,
23362389 * and changed return type to Map instead of HashMap.
23372390 */
2338- static public Map < String , String > readSettings (File inputFile ) {
2391+ static public StringDict readSettings (File inputFile ) {
23392392 if (!inputFile .exists ()) {
23402393 if (DEBUG ) System .err .println (inputFile + " does not exist." );
23412394 return null ;
@@ -2353,13 +2406,13 @@ static public Map<String, String> readSettings(File inputFile) {
23532406 * Parse a String array that contains attribute/value pairs separated
23542407 * by = (the equals sign). The # (hash) symbol is used to denote comments.
23552408 * Comments can be anywhere on a line. Blank lines are ignored.
2356- * In 3.0a6, no longer taking a blank HahMap as param; no cases in the main
2409+ * In 3.0a6, no longer taking a blank HashMap as param; no cases in the main
23572410 * PDE code of adding to a (Hash)Map. Also returning the Map instead of void.
23582411 * Both changes modify the method signature, but this was only used by the
23592412 * contrib classes.
23602413 */
2361- static public Map < String , String > readSettings (String filename , String [] lines ) {
2362- Map < String , String > settings = new HashMap <> ();
2414+ static public StringDict readSettings (String filename , String [] lines ) {
2415+ StringDict settings = new StringDict ();
23632416 for (String line : lines ) {
23642417 // Remove comments
23652418 int commentMarker = line .indexOf ('#' );
@@ -2379,7 +2432,7 @@ static public Map<String, String> readSettings(String filename, String[] lines)
23792432 } else {
23802433 String attr = line .substring (0 , equals ).trim ();
23812434 String valu = line .substring (equals + 1 ).trim ();
2382- settings .put (attr , valu );
2435+ settings .set (attr , valu );
23832436 }
23842437 }
23852438 }
@@ -2734,8 +2787,9 @@ static public String contentsToClassPath(File folder) {
27342787 * @param path the input classpath
27352788 * @return array of possible package names
27362789 */
2737- static public String [] packageListFromClassPath (String path ) {
2738- Map <String , Object > map = new HashMap <String , Object >();
2790+ static public StringList packageListFromClassPath (String path ) {
2791+ // Map<String, Object> map = new HashMap<String, Object>();
2792+ StringList list = new StringList ();
27392793 String pieces [] =
27402794 PApplet .split (path , File .pathSeparatorChar );
27412795
@@ -2746,32 +2800,35 @@ static public String[] packageListFromClassPath(String path) {
27462800 if (pieces [i ].toLowerCase ().endsWith (".jar" ) ||
27472801 pieces [i ].toLowerCase ().endsWith (".zip" )) {
27482802 //System.out.println("checking " + pieces[i]);
2749- packageListFromZip (pieces [i ], map );
2803+ packageListFromZip (pieces [i ], list );
27502804
27512805 } else { // it's another type of file or directory
27522806 File dir = new File (pieces [i ]);
27532807 if (dir .exists () && dir .isDirectory ()) {
2754- packageListFromFolder (dir , null , map );
2808+ packageListFromFolder (dir , null , list );
27552809 //importCount = magicImportsRecursive(dir, null,
27562810 // map);
27572811 //imports, importCount);
27582812 }
27592813 }
27602814 }
2761- int mapCount = map .size ();
2762- String output [] = new String [mapCount ];
2763- int index = 0 ;
2764- Set <String > set = map .keySet ();
2765- for (String s : set ) {
2766- output [index ++] = s .replace ('/' , '.' );
2815+ // int mapCount = map.size();
2816+ // String output[] = new String[mapCount];
2817+ // int index = 0;
2818+ // Set<String> set = map.keySet();
2819+ // for (String s : set) {
2820+ // output[index++] = s.replace('/', '.');
2821+ // }
2822+ // return output;
2823+ StringList outgoing = new StringList (list .size ());
2824+ for (String item : list ) {
2825+ outgoing .append (item .replace ('/' , '.' ));
27672826 }
2768- //System.arraycopy(imports, 0, output, 0, importCount);
2769- //PApplet.printarr(output);
2770- return output ;
2827+ return outgoing ;
27712828 }
27722829
27732830
2774- static private void packageListFromZip (String filename , Map < String , Object > map ) {
2831+ static private void packageListFromZip (String filename , StringList list ) {
27752832 try {
27762833 ZipFile file = new ZipFile (filename );
27772834 Enumeration entries = file .entries ();
@@ -2786,9 +2843,10 @@ static private void packageListFromZip(String filename, Map<String, Object> map)
27862843 if (slash == -1 ) continue ;
27872844
27882845 String pname = name .substring (0 , slash );
2789- if (map .get (pname ) == null ) {
2790- map .put (pname , new Object ());
2791- }
2846+ // if (map.get(pname) == null) {
2847+ // map.put(pname, new Object());
2848+ // }
2849+ list .appendUnique (pname );
27922850 }
27932851 }
27942852 }
@@ -2807,10 +2865,8 @@ static private void packageListFromZip(String filename, Map<String, Object> map)
28072865 * walk down into that folder and continue.
28082866 */
28092867 static private void packageListFromFolder (File dir , String sofar ,
2810- Map <String , Object > map ) {
2811- //String imports[],
2812- //int importCount) {
2813- //System.err.println("checking dir '" + dir + "'");
2868+ StringList list ) {
2869+ // Map<String, Object> map) {
28142870 boolean foundClass = false ;
28152871 String files [] = dir .list ();
28162872
@@ -2821,15 +2877,16 @@ static private void packageListFromFolder(File dir, String sofar,
28212877 if (sub .isDirectory ()) {
28222878 String nowfar =
28232879 (sofar == null ) ? files [i ] : (sofar + "." + files [i ]);
2824- packageListFromFolder (sub , nowfar , map );
2880+ packageListFromFolder (sub , nowfar , list );
28252881 //System.out.println(nowfar);
28262882 //imports[importCount++] = nowfar;
28272883 //importCount = magicImportsRecursive(sub, nowfar,
28282884 // imports, importCount);
28292885 } else if (!foundClass ) { // if no classes found in this folder yet
28302886 if (files [i ].endsWith (".class" )) {
28312887 //System.out.println("unique class: " + files[i] + " for " + sofar);
2832- map .put (sofar , new Object ());
2888+ // map.put(sofar, new Object());
2889+ list .appendUnique (sofar );
28332890 foundClass = true ;
28342891 }
28352892 }
0 commit comments