|
13 | 13 | import java.net.http.HttpResponse; |
14 | 14 | import java.nio.channels.Channels; |
15 | 15 | import java.nio.channels.FileChannel; |
| 16 | +import java.nio.file.Files; |
16 | 17 | import java.nio.file.Path; |
17 | 18 | import java.nio.file.StandardOpenOption; |
18 | 19 | import java.security.MessageDigest; |
@@ -54,7 +55,14 @@ public String description() { |
54 | 55 | return switch (downloadThread.getState()) { |
55 | 56 | case NEW -> Localization.get().getString("org.cryptomator.api.update.download.new"); |
56 | 57 | case TERMINATED -> Localization.get().getString("org.cryptomator.api.update.download.done"); |
57 | | - default -> Localization.get().getString("org.cryptomator.api.update.download.progress").formatted(preparationProgress() * 100); |
| 58 | + default -> { |
| 59 | + double progress = preparationProgress(); |
| 60 | + if (progress < 0.0) { |
| 61 | + yield Localization.get().getString("org.cryptomator.api.update.download.indeterminateProgress"); |
| 62 | + } else { |
| 63 | + yield Localization.get().getString("org.cryptomator.api.update.download.progress").formatted(progress * 100.0); |
| 64 | + } |
| 65 | + } |
58 | 66 | }; |
59 | 67 | } |
60 | 68 |
|
@@ -86,6 +94,11 @@ public boolean await(long timeout, TimeUnit unit) throws InterruptedException { |
86 | 94 | @Override |
87 | 95 | public void cancel() { |
88 | 96 | downloadThread.interrupt(); |
| 97 | + try { |
| 98 | + Files.deleteIfExists(destination); |
| 99 | + } catch (IOException e) { |
| 100 | + // ignore, this is a best-effort cleanup |
| 101 | + } |
89 | 102 | } |
90 | 103 |
|
91 | 104 | protected void download() { |
@@ -119,7 +132,7 @@ protected void downloadInternal(HttpClient client, HttpRequest request) throws I |
119 | 132 | // prepare checksum calculation |
120 | 133 | MessageDigest sha256; |
121 | 134 | try { |
122 | | - sha256 = MessageDigest.getInstance("SHA-256"); // Initialize SHA-256 digest, not used here but can be extended for checksum validation |
| 135 | + sha256 = MessageDigest.getInstance("SHA-256"); |
123 | 136 | } catch (NoSuchAlgorithmException e) { |
124 | 137 | throw new AssertionError("Every implementation of the Java platform is required to support [...] SHA-256", e); |
125 | 138 | } |
|
0 commit comments