Skip to content

Commit a01e4e2

Browse files
committed
working on privacy-ravaging list of installed libraries to be sent to the server (#3365)
1 parent 7ecf92a commit a01e4e2

7 files changed

Lines changed: 104 additions & 49 deletions

File tree

app/src/processing/app/Base.java

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.awt.Frame;
2929
import java.awt.event.ActionEvent;
3030
import java.awt.event.ActionListener;
31-
3231
import java.io.*;
3332
import java.text.SimpleDateFormat;
3433
import java.util.*;
@@ -45,6 +44,7 @@
4544

4645
import processing.app.contrib.*;
4746
import processing.core.*;
47+
import processing.data.StringList;
4848

4949

5050
/**
@@ -528,6 +528,58 @@ public List<ExamplesContribution> getExampleContribs() {
528528
}
529529

530530

531+
private List<Contribution> getInstalledContribs() {
532+
List<Contribution> contributions = new ArrayList<Contribution>();
533+
534+
List<ModeContribution> modeContribs = getModeContribs();
535+
contributions.addAll(modeContribs);
536+
537+
for (ModeContribution modeContrib : modeContribs) {
538+
Mode mode = modeContrib.getMode();
539+
contributions.addAll(new ArrayList<Library>(mode.contribLibraries));
540+
}
541+
542+
// TODO this duplicates code in Editor, but it's not editor-specific
543+
// List<ToolContribution> toolContribs =
544+
// ToolContribution.loadAll(Base.getSketchbookToolsFolder());
545+
// contributions.addAll(toolContribs);
546+
contributions.addAll(ToolContribution.loadAll(getSketchbookToolsFolder()));
547+
548+
contributions.addAll(getExampleContribs());
549+
return contributions;
550+
}
551+
552+
553+
public String getInstalledContribsInfo() {
554+
List<Contribution> contribs = getInstalledContribs();
555+
StringList entries = new StringList();
556+
for (Contribution c : contribs) {
557+
String entry = c.getTypeName() + "=" +
558+
PApplet.urlEncode(String.format("name=%s\nurl=%s\nrevision=%d\nversion=%s",
559+
c.getName(), c.getUrl(),
560+
c.getVersion(), c.getPrettyVersion()));
561+
entries.append(entry);
562+
}
563+
String joined = "id=" + Preferences.get("update.id") + entries.join("&");
564+
StringBuilder sb = new StringBuilder();
565+
try {
566+
// Truly ridiculous attempt to shove everything into a GET request.
567+
// More likely to be seen as part of a grand plot.
568+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
569+
GZIPOutputStream output = new GZIPOutputStream(baos);
570+
PApplet.saveStream(output, new ByteArrayInputStream(joined.getBytes()));
571+
output.close();
572+
byte[] b = baos.toByteArray();
573+
for (int i = 0; i < b.length; i++) {
574+
sb.append(PApplet.hex(b[i], 2));
575+
}
576+
} catch (IOException e) {
577+
e.printStackTrace();
578+
}
579+
return sb.toString();
580+
}
581+
582+
531583
// Because of variations in native windowing systems, no guarantees about
532584
// changes to the focused and active Windows can be made. Developers must
533585
// never assume that this Window is the focused or active Window until this

app/src/processing/app/UpdateCheck.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ public void run() {
6767
} catch (Exception e) {
6868
// This can safely be ignored, too many situations where no net
6969
// connection is available that behave in strange ways.
70-
// Covers likely IOException, InterruptedException, and any others.
71-
}
70+
// Covers likely IOException, InterruptedException, and any others.
71+
}
7272
}
7373
}, "Update Checker").start();
7474
}
@@ -122,14 +122,14 @@ public void updateCheck() throws IOException, InterruptedException {
122122
// Wait for xml file to be downloaded and updates to come in.
123123
// (this should really be handled better).
124124
Thread.sleep(5 * 1000);
125-
if ((!base.libraryManagerFrame.hasAlreadyBeenOpened()
126-
&& !base.toolManagerFrame.hasAlreadyBeenOpened()
127-
&& !base.modeManagerFrame.hasAlreadyBeenOpened()
128-
&& !base.exampleManagerFrame.hasAlreadyBeenOpened())
129-
&& (base.libraryManagerFrame.hasUpdates(base)
130-
|| base.toolManagerFrame.hasUpdates(base)
131-
|| base.modeManagerFrame.hasUpdates(base)
132-
|| base.exampleManagerFrame.hasUpdates(base))) {
125+
if ((!base.libraryManagerFrame.hasAlreadyBeenOpened() &&
126+
!base.toolManagerFrame.hasAlreadyBeenOpened() &&
127+
!base.modeManagerFrame.hasAlreadyBeenOpened() &&
128+
!base.exampleManagerFrame.hasAlreadyBeenOpened()) &&
129+
(base.libraryManagerFrame.hasUpdates(base) ||
130+
base.toolManagerFrame.hasUpdates(base) ||
131+
base.modeManagerFrame.hasUpdates(base) ||
132+
base.exampleManagerFrame.hasUpdates(base))) {
133133
promptToOpenContributionManager();
134134
}
135135
}

app/src/processing/app/contrib/AvailableContribution.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public AvailableContribution(ContributionType type, Map<String, String> params)
4444

4545
//category = ContributionListing.getCategory(params.get("category"));
4646
categories = parseCategories(params.get("category"));
47-
specifiedImports = parseImports(params.get("imports"));
47+
imports = parseImports(params.get("imports"));
4848
name = params.get("name");
4949
authorList = params.get("authorList");
5050
url = params.get("url");
@@ -258,7 +258,7 @@ public boolean writePropertiesFile(File propFile) {
258258
specifiedImport = getImportStr();
259259
} else {
260260
StringBuilder sbImport = new StringBuilder();
261-
for (String it : specifiedImports) {
261+
for (String it : imports) {
262262
sbImport.append(it);
263263
sbImport.append(',');
264264
}

app/src/processing/app/contrib/Contribution.java

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
Part of the Processing project - http://processing.org
55
6-
Copyright (c) 2013 The Processing Foundation
6+
Copyright (c) 2013-15 The Processing Foundation
77
Copyright (c) 2011-12 Ben Fry and Casey Reas
88
99
This program is free software; you can redistribute it and/or modify
@@ -32,28 +32,21 @@ abstract public class Contribution {
3232
static final String SPECIAL_CATEGORY_NAME = "Starred";
3333
static final List validCategories =
3434
Arrays.asList("3D", "Animation", "Data", "Geometry", "GUI", "Hardware",
35-
"I/O", "Math", "Simulation", "Sound", SPECIAL_CATEGORY_NAME, "Typography",
36-
"Utilities", "Video & Vision", "Other");
35+
"I/O", "Math", "Simulation", "Sound", SPECIAL_CATEGORY_NAME,
36+
"Typography", "Utilities", "Video & Vision", "Other");
3737

38-
//protected String category; // "Sound"
3938
protected List<String> categories; // "Sound", "Typography"
40-
protected String name; // "pdf" or "PDF Export"
41-
protected String authorList; // Ben Fry
42-
protected String url; // http://processing.org
43-
protected String sentence; // Write graphics to PDF files.
44-
protected String paragraph; // <paragraph length description for site>
45-
protected int version; // 102
46-
protected String prettyVersion; // "1.0.2"
47-
protected long lastUpdated; // 1402805757
48-
protected int minRevision; // 0
49-
protected int maxRevision; // 227
50-
protected List<String> specifiedImports; // pdf.export.*,pdf.convert.common.*
51-
52-
53-
// "Sound"
54-
// public String getCategory() {
55-
// return category;
56-
// }
39+
protected String name; // "pdf" or "PDF Export"
40+
protected String authorList; // [Ben Fry](http://benfry.com)
41+
protected String url; // http://processing.org
42+
protected String sentence; // Write graphics to PDF files.
43+
protected String paragraph; // <paragraph length description for site>
44+
protected int version; // 102
45+
protected String prettyVersion; // "1.0.2"
46+
protected long lastUpdated; // 1402805757
47+
protected int minRevision; // 0
48+
protected int maxRevision; // 227
49+
protected List<String> imports; // pdf.export.*,pdf.convert.common.*
5750

5851

5952
// "Sound", "Utilities"... see valid list in ContributionListing
@@ -87,26 +80,27 @@ protected boolean hasCategory(String category) {
8780

8881
// pdf.export.*,pdf.convert.common.*
8982
protected List<String> getImports() {
90-
return specifiedImports;
83+
return imports;
9184
}
9285

9386

9487
protected String getImportStr() {
95-
if (specifiedImports == null || specifiedImports.isEmpty()) {
88+
if (imports == null || imports.isEmpty()) {
9689
return "";
9790
}
9891
StringBuilder sb = new StringBuilder();
99-
for (String importName : specifiedImports) {
92+
for (String importName : imports) {
10093
sb.append(importName);
10194
sb.append(',');
10295
}
10396
sb.deleteCharAt(sb.length() - 1); // delete last comma
10497
return sb.toString();
10598
}
10699

100+
107101
protected boolean hasImport(String importName) {
108-
if (specifiedImports != null && importName != null) {
109-
for (String c : specifiedImports) {
102+
if (imports != null && importName != null) {
103+
for (String c : imports) {
110104
if (importName.equalsIgnoreCase(c)) {
111105
return true;
112106
}

app/src/processing/app/contrib/ContributionListing.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,14 +392,21 @@ private ArrayList<ContributionChangeListener> getContributionListeners() {
392392
* Starts a new thread to download the advertised list of contributions.
393393
* Only one instance will run at a time.
394394
*/
395-
protected void downloadAvailableList(final ContribProgressMonitor progress) {
395+
protected void downloadAvailableList(final Base base,
396+
final ContribProgressMonitor progress) {
396397
new Thread(new Runnable() {
397398
public void run() {
398399
downloadingListingLock.lock();
399400

400401
URL url = null;
401402
try {
402403
url = new URL(LISTING_URL);
404+
// final String contribInfo =
405+
// base.getInstalledContribsInfo();
406+
//// "?id=" + Preferences.get("update.id") +
407+
//// "&" + base.getInstalledContribsInfo();
408+
// url = new URL(LISTING_URL + "?" + contribInfo);
409+
// System.out.println(contribInfo.length() + " " + contribInfo);
403410
} catch (MalformedURLException e) {
404411
progress.error(e);
405412
progress.finished();

app/src/processing/app/contrib/ContributionManagerDialog.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public boolean hasUpdates(Base base) {
103103
return contribListing.hasUpdates(base);
104104
}
105105

106+
106107
public void showFrame(final Editor editor) {
107108
this.editor = editor;
108109

@@ -132,6 +133,8 @@ public void actionPerformed(ActionEvent arg0) {
132133
}
133134
}
134135

136+
// Why the f*k is this happening here? This is nuts, and likely
137+
// to cause all kinds of hell across different platforms. [fry]
135138
// Thanks to http://stackoverflow.com/a/4160543
136139
StringBuilder cmd = new StringBuilder();
137140
cmd.append(System.getProperty("java.home") + File.separator + "bin"
@@ -165,7 +168,7 @@ public void actionPerformed(ActionEvent arg0) {
165168
// The message is set to null so that every time the retry button is hit
166169
// no previous error is displayed in the status
167170
status.setMessage(null);
168-
downloadAndUpdateContributionListing();
171+
downloadAndUpdateContributionListing(editor.getBase());
169172
}
170173
});
171174

@@ -186,7 +189,7 @@ public void actionPerformed(ActionEvent arg0) {
186189
updateContributionListing();
187190

188191
} else {
189-
downloadAndUpdateContributionListing();
192+
downloadAndUpdateContributionListing(editor.getBase());
190193
}
191194
}
192195

@@ -433,9 +436,9 @@ protected void filterLibraries(String category, List<String> filters, boolean is
433436

434437
protected void updateContributionListing() {
435438
if (editor != null) {
436-
ArrayList<Contribution> contributions = new ArrayList<Contribution>();
439+
List<Contribution> contributions = new ArrayList<Contribution>();
437440

438-
ArrayList<Library> libraries =
441+
List<Library> libraries =
439442
new ArrayList<Library>(editor.getMode().contribLibraries);
440443
contributions.addAll(libraries);
441444

@@ -467,11 +470,10 @@ protected void updateContributionListing() {
467470
}
468471

469472

470-
protected void downloadAndUpdateContributionListing() {
473+
protected void downloadAndUpdateContributionListing(Base base) {
471474
retryConnectingButton.setEnabled(false);
472475
status.setMessage(Language.text("contrib.status.downloading_list"));
473-
contribListing.downloadAvailableList(new ContribProgressBar(progressBar) {
474-
476+
contribListing.downloadAvailableList(base, new ContribProgressBar(progressBar) {
475477

476478
@Override
477479
public void startTask(String name, int maxValue) {

app/src/processing/app/contrib/LocalContribution.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public LocalContribution(File folder) {
6060
name = properties.get("name");
6161
id = properties.get("id");
6262
categories = parseCategories(properties.get("category"));
63-
specifiedImports = parseImports(properties.get("imports"));
63+
imports = parseImports(properties.get("imports"));
6464
if (name == null) {
6565
name = folder.getName();
6666
}
@@ -550,7 +550,7 @@ static protected String findClassInZipFileList(String base, File[] fileList) {
550550
*/
551551
public String[] getSpecifiedImports() {
552552

553-
return specifiedImports != null ? specifiedImports.toArray(new String[0]) : null;
553+
return imports != null ? imports.toArray(new String[0]) : null;
554554
}
555555

556556
/**

0 commit comments

Comments
 (0)