Do not delete dictionary when downloading
app/src/main/java/eu/lepiller/nani/DictionaryDownloadService.java
256 | 256 | File temporaryFile = e.getValue().first; | |
257 | 257 | File cacheFile = e.getValue().second; | |
258 | 258 | ||
259 | - | boolean newFile = downloadSha256(new URL(uri + ".sha256"), new File(cacheFile + ".sha256")); | |
259 | + | boolean newFile = downloadSha256(new URL(uri + ".sha256"), new File(temporaryFile + ".sha256")); | |
260 | 260 | if(newFile) { | |
261 | - | d.remove(); | |
261 | + | d.removeTemporary(); | |
262 | 262 | } | |
263 | 263 | ||
264 | 264 | long expectedFileLength = getRange(new URL(uri)); |
app/src/main/java/eu/lepiller/nani/dictionary/Dictionary.java
5 | 5 | import android.graphics.Canvas; | |
6 | 6 | import android.graphics.drawable.BitmapDrawable; | |
7 | 7 | import android.graphics.drawable.Drawable; | |
8 | + | import android.util.Log; | |
8 | 9 | import android.util.Pair; | |
9 | 10 | ||
10 | 11 | import androidx.core.content.res.ResourcesCompat; | |
… | |||
125 | 126 | ||
126 | 127 | abstract public void remove(); | |
127 | 128 | ||
129 | + | public void removeTemporary() { | |
130 | + | if(getTemporaryFile().exists()) | |
131 | + | if(!getTemporaryFile().delete()) | |
132 | + | Log.w("DICTIONARY", getTemporaryFile() + " was not deleted as expected."); | |
133 | + | } | |
134 | + | ||
128 | 135 | public static String readSha256FromFile(File file) throws IOException { | |
129 | 136 | StringBuilder sb = new StringBuilder(); | |
130 | 137 | char[] data = new char[4096]; |
app/src/main/java/eu/lepiller/nani/dictionary/RadicalDict.java
35 | 35 | radicalStrokeCount.clear(); | |
36 | 36 | radicals.clear(); | |
37 | 37 | } | |
38 | + | ||
38 | 39 | private void fillStrokeCount(RandomAccessFile file) throws IOException{ | |
39 | 40 | int size = file.readShort(); | |
40 | 41 | for(int i=0; i<size; i++) { |