@capgo/capacitor-updater 5.0.18 → 5.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdater.java +37 -31
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +1 -1
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +25 -22
- package/ios/Plugin/CapacitorUpdaterPlugin.swift +1 -1
- package/package.json +1 -1
|
@@ -158,10 +158,12 @@ public class CapacitorUpdater {
|
|
|
158
158
|
private File unzip(final String id, final File zipFile, final String dest)
|
|
159
159
|
throws IOException {
|
|
160
160
|
final File targetDirectory = new File(this.documentsDir, dest);
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
161
|
+
try (
|
|
162
|
+
final BufferedInputStream bis = new BufferedInputStream(
|
|
163
|
+
new FileInputStream(zipFile)
|
|
164
|
+
);
|
|
165
|
+
final ZipInputStream zis = new ZipInputStream(bis)
|
|
166
|
+
) {
|
|
165
167
|
int count;
|
|
166
168
|
final int bufferSize = 8192;
|
|
167
169
|
final byte[] buffer = new byte[bufferSize];
|
|
@@ -220,12 +222,6 @@ public class CapacitorUpdater {
|
|
|
220
222
|
lengthRead += entry.getCompressedSize();
|
|
221
223
|
}
|
|
222
224
|
return targetDirectory;
|
|
223
|
-
} finally {
|
|
224
|
-
try {
|
|
225
|
-
zis.close();
|
|
226
|
-
} catch (final IOException e) {
|
|
227
|
-
Log.e(TAG, "Failed to close zip input stream", e);
|
|
228
|
-
}
|
|
229
225
|
}
|
|
230
226
|
}
|
|
231
227
|
|
|
@@ -419,13 +415,10 @@ public class CapacitorUpdater {
|
|
|
419
415
|
) throws IOException {
|
|
420
416
|
final URL u = new URL(url);
|
|
421
417
|
final URLConnection connection = u.openConnection();
|
|
422
|
-
final InputStream is = u.openStream();
|
|
423
|
-
final DataInputStream dis = new DataInputStream(is);
|
|
424
418
|
|
|
425
419
|
final File target = new File(this.documentsDir, dest);
|
|
426
420
|
target.getParentFile().mkdirs();
|
|
427
421
|
target.createNewFile();
|
|
428
|
-
final FileOutputStream fos = new FileOutputStream(target);
|
|
429
422
|
|
|
430
423
|
final long totalLength = connection.getContentLength();
|
|
431
424
|
final int bufferSize = 1024;
|
|
@@ -435,14 +428,20 @@ public class CapacitorUpdater {
|
|
|
435
428
|
int bytesRead = bufferSize;
|
|
436
429
|
int percent = 0;
|
|
437
430
|
this.notifyDownload(id, 10);
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
final
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
431
|
+
try (
|
|
432
|
+
final InputStream is = u.openStream();
|
|
433
|
+
final DataInputStream dis = new DataInputStream(is);
|
|
434
|
+
final FileOutputStream fos = new FileOutputStream(target)
|
|
435
|
+
) {
|
|
436
|
+
while ((length = dis.read(buffer)) > 0) {
|
|
437
|
+
fos.write(buffer, 0, length);
|
|
438
|
+
final int newPercent = (int) ((bytesRead / (float) totalLength) * 100);
|
|
439
|
+
if (totalLength > 1 && newPercent != percent) {
|
|
440
|
+
percent = newPercent;
|
|
441
|
+
this.notifyDownload(id, this.calcTotalPercent(percent, 10, 70));
|
|
442
|
+
}
|
|
443
|
+
bytesRead += length;
|
|
444
444
|
}
|
|
445
|
-
bytesRead += length;
|
|
446
445
|
}
|
|
447
446
|
return target;
|
|
448
447
|
}
|
|
@@ -506,17 +505,24 @@ public class CapacitorUpdater {
|
|
|
506
505
|
byte[] decryptedSessionKey = CryptoCipher.decryptRSA(sessionKey, pKey);
|
|
507
506
|
SecretKey sKey = CryptoCipher.byteToSessionKey(decryptedSessionKey);
|
|
508
507
|
byte[] content = new byte[(int) file.length()];
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
508
|
+
|
|
509
|
+
try (
|
|
510
|
+
final FileInputStream fis = new FileInputStream(file);
|
|
511
|
+
final BufferedInputStream bis = new BufferedInputStream(fis);
|
|
512
|
+
final DataInputStream dis = new DataInputStream(bis)
|
|
513
|
+
) {
|
|
514
|
+
dis.readFully(content);
|
|
515
|
+
dis.close();
|
|
516
|
+
byte[] decrypted = CryptoCipher.decryptAES(content, sKey, iv);
|
|
517
|
+
// write the decrypted string to the file
|
|
518
|
+
try (
|
|
519
|
+
final FileOutputStream fos = new FileOutputStream(
|
|
520
|
+
file.getAbsolutePath()
|
|
521
|
+
)
|
|
522
|
+
) {
|
|
523
|
+
fos.write(decrypted);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
520
526
|
} catch (GeneralSecurityException e) {
|
|
521
527
|
Log.i(TAG, "decryptFile fail");
|
|
522
528
|
this.sendStats("decrypt_fail", version);
|
|
@@ -55,7 +55,7 @@ public class CapacitorUpdaterPlugin
|
|
|
55
55
|
private static final String channelUrlDefault =
|
|
56
56
|
"https://api.capgo.app/channel_self";
|
|
57
57
|
|
|
58
|
-
private final String PLUGIN_VERSION = "5.0.
|
|
58
|
+
private final String PLUGIN_VERSION = "5.0.19";
|
|
59
59
|
private static final String DELAY_CONDITION_PREFERENCES = "";
|
|
60
60
|
|
|
61
61
|
private SharedPreferences.Editor editor;
|
|
@@ -55,32 +55,35 @@ public class DownloadService extends IntentService {
|
|
|
55
55
|
try {
|
|
56
56
|
final URL u = new URL(url);
|
|
57
57
|
final URLConnection connection = u.openConnection();
|
|
58
|
-
final InputStream is = u.openStream();
|
|
59
|
-
final DataInputStream dis = new DataInputStream(is);
|
|
60
58
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
try (
|
|
60
|
+
final InputStream is = u.openStream();
|
|
61
|
+
final DataInputStream dis = new DataInputStream(is)
|
|
62
|
+
) {
|
|
63
|
+
final File target = new File(documentsDir, dest);
|
|
64
|
+
target.getParentFile().mkdirs();
|
|
65
|
+
target.createNewFile();
|
|
66
|
+
try (final FileOutputStream fos = new FileOutputStream(target)) {
|
|
67
|
+
final long totalLength = connection.getContentLength();
|
|
68
|
+
final int bufferSize = 1024;
|
|
69
|
+
final byte[] buffer = new byte[bufferSize];
|
|
70
|
+
int length;
|
|
65
71
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
this.notifyDownload(id, this.calcTotalPercent(percent, 10, 70));
|
|
72
|
+
int bytesRead = bufferSize;
|
|
73
|
+
int percent = 0;
|
|
74
|
+
this.notifyDownload(id, 10);
|
|
75
|
+
while ((length = dis.read(buffer)) > 0) {
|
|
76
|
+
fos.write(buffer, 0, length);
|
|
77
|
+
final int newPercent = (int) ((bytesRead * 100) / totalLength);
|
|
78
|
+
if (totalLength > 1 && newPercent != percent) {
|
|
79
|
+
percent = newPercent;
|
|
80
|
+
this.notifyDownload(id, this.calcTotalPercent(percent, 10, 70));
|
|
81
|
+
}
|
|
82
|
+
bytesRead += length;
|
|
83
|
+
}
|
|
84
|
+
publishResults(dest, id, version, checksum, sessionKey, "");
|
|
80
85
|
}
|
|
81
|
-
bytesRead += length;
|
|
82
86
|
}
|
|
83
|
-
publishResults(dest, id, version, checksum, sessionKey, "");
|
|
84
87
|
} catch (Exception e) {
|
|
85
88
|
e.printStackTrace();
|
|
86
89
|
publishResults(
|
|
@@ -15,7 +15,7 @@ import Version
|
|
|
15
15
|
@objc(CapacitorUpdaterPlugin)
|
|
16
16
|
public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
17
17
|
private var implementation = CapacitorUpdater()
|
|
18
|
-
private let PLUGIN_VERSION: String = "5.0.
|
|
18
|
+
private let PLUGIN_VERSION: String = "5.0.19"
|
|
19
19
|
static let updateUrlDefault = "https://api.capgo.app/updates"
|
|
20
20
|
static let statsUrlDefault = "https://api.capgo.app/stats"
|
|
21
21
|
static let channelUrlDefault = "https://api.capgo.app/channel_self"
|