1+ /*
2+ * This file is part of Arduino.
3+ *
4+ * Copyright 2019 Arduino LLC (http://www.arduino.cc/)
5+ *
6+ * Arduino is free software; you can redistribute it and/or modify
7+ * it under the terms of the GNU General Public License as published by
8+ * the Free Software Foundation; either version 2 of the License, or
9+ * (at your option) any later version.
10+ *
11+ * This program is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ * GNU General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU General Public License
17+ * along with this program; if not, write to the Free Software
18+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+ *
20+ * As a special exception, you may use this file as part of a free software
21+ * library without restriction. Specifically, if other files instantiate
22+ * templates or use macros or inline functions from this file, or you compile
23+ * this file and link it with other files to produce an executable, this
24+ * file does not by itself cause the resulting executable to be covered by
25+ * the GNU General Public License. This exception does not however
26+ * invalidate any other reasons why the executable file might be covered by
27+ * the GNU General Public License.
28+ */
29+
30+ package cc .arduino .cli ;
31+
32+ import static processing .app .I18n .format ;
33+ import static processing .app .I18n .tr ;
34+
35+ import cc .arduino .cli .commands .Common .DownloadProgress ;
36+ import cc .arduino .contributions .ProgressListener ;
37+ import cc .arduino .utils .MultiStepProgress ;
38+ import cc .arduino .utils .Progress ;
39+
40+ class ProgressWrapper {
41+ final ProgressListener progressListener ;
42+ String file = "" ;
43+ String url = "" ;
44+ private long downloaded , totalSize ;
45+ Progress progress = new MultiStepProgress (1 );
46+
47+ public ProgressWrapper (ProgressListener progressListener ) {
48+ this .progressListener = progressListener ;
49+ }
50+
51+ public void update (DownloadProgress d ) {
52+ if (d == null ) {
53+ return ;
54+ }
55+ if (!d .getFile ().isEmpty ()) {
56+ file = d .getFile ();
57+ }
58+ if (!d .getUrl ().isEmpty ()) {
59+ url = d .getUrl ();
60+ }
61+ if (d .getTotalSize () > 0 ) {
62+ totalSize = d .getTotalSize ();
63+ }
64+ if (d .getDownloaded () > 0 ) {
65+ downloaded = d .getDownloaded ();
66+ }
67+
68+ String msg = format (tr ("Downloaded {0}kb of {1}kb." ), downloaded , totalSize );
69+ if (d .getCompleted ()) {
70+ file = "" ;
71+ url = "" ;
72+ totalSize = 0 ;
73+ downloaded = 0 ;
74+ } else {
75+ progress .setStatus ("Downloading " + file + url + " (" + downloaded
76+ + " of " + totalSize + ")" );
77+ progress .setProgress (((float ) downloaded / totalSize ) * 100 );
78+ }
79+ progressListener .onProgress (progress );
80+ }
81+ }
0 commit comments