Skip to content

Commit e53992b

Browse files
committed
Display download percentage when fetching library info
1 parent f35bb56 commit e53992b

File tree

3 files changed

+64
-55
lines changed

3 files changed

+64
-55
lines changed

app/src/processing/app/contrib/ContributionManager.java

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1616
GNU General Public License for more details.
1717
18-
You should have received a copy of the GNU General Public License along
18+
You should have received a copy of the GNU General Public License along
1919
with this program; if not, write to the Free Software Foundation, Inc.
2020
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2121
*/
@@ -43,7 +43,7 @@ public class ContributionManager {
4343
/**
4444
* Blocks until the file is downloaded or an error occurs. Returns true if the
4545
* file was successfully downloaded, false otherwise.
46-
*
46+
*
4747
* @param source
4848
* the URL of the file to download
4949
* @param dest
@@ -67,17 +67,18 @@ static boolean download(URL source, File dest, ProgressMonitor progress) {
6767
conn.setReadTimeout(60 * 1000);
6868
conn.setRequestMethod("GET");
6969
conn.connect();
70-
70+
7171
if (progress != null) {
7272
// TODO this is often -1, may need to set progress to indeterminate
7373
int fileSize = conn.getContentLength();
74+
progress.max = fileSize;
7475
// System.out.println("file size is " + fileSize);
75-
progress.startTask(Language.text("contrib.progress.downloading"), fileSize);
76+
progress.startTask(Language.text("contrib.progress.downloading"), fileSize);
7677
}
77-
78+
7879
InputStream in = conn.getInputStream();
7980
FileOutputStream out = new FileOutputStream(dest);
80-
81+
8182
byte[] b = new byte[8192];
8283
int amount;
8384
if (progress != null) {
@@ -95,7 +96,7 @@ static boolean download(URL source, File dest, ProgressMonitor progress) {
9596
out.flush();
9697
out.close();
9798
success = true;
98-
99+
99100
} catch (SocketTimeoutException ste) {
100101
if (progress != null) {
101102
progress.error(ste);
@@ -106,15 +107,15 @@ static boolean download(URL source, File dest, ProgressMonitor progress) {
106107
progress.error(ioe);
107108
progress.cancel();
108109
}
109-
// Hiding stack trace. An error has been shown where needed.
110+
// Hiding stack trace. An error has been shown where needed.
110111
// ioe.printStackTrace();
111112
}
112113
if (progress != null)
113114
progress.finished();
114115
return success;
115116
}
116117

117-
118+
118119
/**
119120
* Non-blocking call to download and install a contribution in a new thread.
120121
*
@@ -143,10 +144,10 @@ public void run() {
143144

144145
try {
145146
download(url, contribZip, downloadProgress);
146-
147+
147148
if (!downloadProgress.isCanceled() && !downloadProgress.isError()) {
148149
installProgress.startTask(Language.text("contrib.progress.installing"), ProgressMonitor.UNKNOWN);
149-
LocalContribution contribution =
150+
LocalContribution contribution =
150151
ad.install(editor.getBase(), contribZip, false, status);
151152

152153
if (contribution != null) {
@@ -196,11 +197,11 @@ public void run() {
196197

197198
/**
198199
* Non-blocking call to download and install a contribution in a new thread.
199-
*
200+
*
200201
* @param url
201202
* Direct link to the contribution.
202203
* @param ad
203-
* The AvailableContribution to be downloaded and installed.
204+
* The AvailableContribution to be downloaded and installed.
204205
*/
205206
static void downloadAndInstallOnStartup(final Base base, final URL url,
206207
final AvailableContribution ad) {
@@ -215,7 +216,7 @@ public void run() {
215216

216217
try {
217218
download(url, contribZip, null);
218-
219+
219220
LocalContribution contribution = ad.install(base, contribZip,
220221
false, null);
221222

@@ -233,7 +234,7 @@ public void run() {
233234
}
234235

235236
contribZip.delete();
236-
237+
237238
handleUpdateFailedMarkers(ad, filename.substring(0, filename.lastIndexOf('.')));
238239

239240
} catch (Exception e) {
@@ -353,27 +354,27 @@ static public String getFileName(File libFile) {
353354

354355
return fileName;
355356
}
356-
357-
358-
/**
357+
358+
359+
/**
359360
* Called by Base to clean up entries previously marked for deletion
360361
* and remove any "requires restart" flags.
361362
* Also updates all entries previously marked for update.
362363
*/
363364
static public void cleanup(final Base base) throws Exception {
364-
365+
365366
deleteTemp(Base.getSketchbookModesFolder());
366367
deleteTemp(Base.getSketchbookToolsFolder());
367-
368+
368369
deleteFlagged(Base.getSketchbookLibrariesFolder());
369370
deleteFlagged(Base.getSketchbookModesFolder());
370371
deleteFlagged(Base.getSketchbookToolsFolder());
371-
372+
372373
installPreviouslyFailed(base, Base.getSketchbookModesFolder());
373374
updateFlagged(base, Base.getSketchbookModesFolder());
374-
375+
375376
updateFlagged(base, Base.getSketchbookToolsFolder());
376-
377+
377378
SwingWorker s = new SwingWorker<Void, Void>() {
378379

379380
@Override
@@ -389,8 +390,8 @@ protected Void doInBackground() throws Exception {
389390
};
390391
s.execute();
391392

392-
393-
393+
394+
394395
clearRestartFlags(Base.getSketchbookModesFolder());
395396
clearRestartFlags(Base.getSketchbookToolsFolder());
396397
}
@@ -400,7 +401,7 @@ protected Void doInBackground() throws Exception {
400401
* Deletes the icky tmp folders that were left over from installs and updates
401402
* in the previous run of Processing. Needed to be called only on the tools
402403
* and modes sketchbook folders.
403-
*
404+
*
404405
* @param root
405406
*/
406407
static private void deleteTemp(File root) {
@@ -421,7 +422,7 @@ static private void deleteTemp(File root) {
421422

422423
/**
423424
* Deletes all the modes/tools/libs that are flagged for removal.
424-
*
425+
*
425426
* @param root
426427
* @throws Exception
427428
*/
@@ -436,12 +437,12 @@ public boolean accept(File folder) {
436437
Base.removeDir(folder);
437438
}
438439
}
439-
440-
440+
441+
441442
/**
442443
* Installs all the modes/tools whose installation failed during an
443444
* auto-update the previous time Processing was started up.
444-
*
445+
*
445446
* @param base
446447
* @param root
447448
* @throws Exception
@@ -470,7 +471,7 @@ public boolean accept(File folder) {
470471

471472
/**
472473
* Updates all the flagged modes/tools.
473-
*
474+
*
474475
* @param base
475476
* @param root
476477
* @throws Exception
@@ -502,24 +503,24 @@ else if (type.equalsIgnoreCase("libraries")) //putting this here, just in case
502503
updateContribsNames.add(properties.get("name"));
503504
Base.removeDir(folder);
504505
}
505-
506+
506507
Iterator<AvailableContribution> iter = contribListing.advertisedContributions.iterator();
507508
while (iter.hasNext()) {
508509
AvailableContribution availableContribs = iter.next();
509510
if (updateContribsNames.contains(availableContribs.getName())) {
510511
updateContribsList.add(availableContribs);
511512
}
512513
}
513-
514+
514515
Iterator<AvailableContribution> iter2 = updateContribsList.iterator();
515516
while (iter2.hasNext()) {
516517
AvailableContribution contribToUpdate = iter2.next();
517518
installOnStartUp(base, contribToUpdate);
518519
contribListing.replaceContribution(contribToUpdate, contribToUpdate);
519520
}
520521
}
521-
522-
522+
523+
523524
static private void installOnStartUp(final Base base, final AvailableContribution availableContrib) {
524525
if (availableContrib.link == null) {
525526
Base.showWarning(Language.interpolate("contrib.errors.update_on_restart_failed", availableContrib.getName()),
@@ -528,16 +529,16 @@ static private void installOnStartUp(final Base base, final AvailableContributio
528529
}
529530
try {
530531
URL downloadUrl = new URL(availableContrib.link);
531-
532+
532533
ContributionManager.downloadAndInstallOnStartup(base, downloadUrl, availableContrib);
533-
534+
534535
} catch (MalformedURLException e) {
535536
Base.showWarning(Language.interpolate("contrib.errors.update_on_restart_failed", availableContrib.getName()),
536537
Language.text("contrib.errors.malformed_url"), e);
537538
}
538539
}
539-
540-
540+
541+
541542
static private void clearRestartFlags(File root) throws Exception {
542543
File[] folderList = root.listFiles(new FileFilter() {
543544
public boolean accept(File folder) {

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,11 +459,18 @@ protected void updateContributionListing() {
459459

460460

461461
protected void downloadAndUpdateContributionListing() {
462-
status.setMessage(Language.text("contrib.status.downloading_list"));
463462
retryConnectingButton.setEnabled(false);
464463
contribListing.downloadAvailableList(new ProgressMonitor() {
465-
466-
public void finished() {
464+
465+
@Override
466+
public void setProgress(int value) {
467+
super.setProgress(value);
468+
int percent = (int)(value * 100.0f / this.max);
469+
status.setMessage(Language.text("contrib.status.downloading_list") + " (" + percent + "%)");
470+
}
471+
472+
@Override
473+
public void finished() {
467474
super.finished();
468475

469476
updateContributionListing();

app/src/processing/app/contrib/ProgressMonitor.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1616
GNU General Public License for more details.
1717
18-
You should have received a copy of the GNU General Public License along
18+
You should have received a copy of the GNU General Public License along
1919
with this program; if not, write to the Free Software Foundation, Inc.
2020
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2121
*/
@@ -36,7 +36,7 @@
3636
//
3737
// /**
3838
// * Starts a new task with the given name.
39-
// *
39+
// *
4040
// * @param maxValue
4141
// * the amount of progress that must be made before a task is
4242
// * finished. This may be set to UNKNOWN.
@@ -64,28 +64,28 @@
6464
// * Requests for the task to be cancelled by setting isCanceled() to true.
6565
// */
6666
// public void cancel();
67-
//
67+
//
6868
// /**
6969
// * @return <code>true</code> if an error occured while completing the task
7070
// */
7171
// public boolean isError();
72-
//
72+
//
7373
// /**
7474
// * @return an exception that caused the error, may be null.
7575
// */
7676
// public Exception getException();
77-
//
77+
//
7878
// /**
7979
// * Indicates that an error occurred while performing the task. Exception may
8080
// * be null.
8181
// */
8282
// public void error(Exception e);
83-
//
83+
//
8484
// /**
8585
// * Returns true if this task is complete
8686
// */
8787
// public boolean isFinished();
88-
//
88+
//
8989
// /**
9090
// * This is called when the current task is finished. This should always be
9191
// * called when a task is finished, whether or not an error occurred or the
@@ -102,15 +102,16 @@ abstract class ProgressMonitor {
102102
boolean error = false;
103103
boolean finished = false;
104104
Exception exception;
105+
int max;
105106
int progress = 0;
106-
107+
107108
public void startTask(String name, int maxValue) {
108109
}
109-
110+
110111
public void setProgress(int value) {
111112
progress = value;
112113
}
113-
114+
114115
public int getProgress() {
115116
return progress;
116117
}
@@ -122,7 +123,7 @@ public boolean isCanceled() {
122123
public void cancel() {
123124
canceled = true;
124125
}
125-
126+
126127
public boolean isError() {
127128
return error;
128129
}
@@ -135,11 +136,11 @@ public void error(Exception e) {
135136
error = true;
136137
exception = e;
137138
}
138-
139+
139140
public boolean isFinished() {
140141
return finished;
141142
}
142-
143+
143144
public void finished() {
144145
finished = true;
145146
}

0 commit comments

Comments
 (0)