Toast.makeText(context, getString(R.string.unzippingDictionary, dest),
Toast.LENGTH_LONG).show();
- if (unzipInstall(context, Uri.parse(dest), dest)) {
+ if (unzipInstall(context, Uri.parse(dest), dest, true)) {
finishedDownloadIds.add(downloadId);
Log.w(LOG, "Unzipping finished: " + dest + " Id: " + downloadId);
}
}
};
- private boolean unzipInstall(Context context, Uri zipUri, String dest) {
+ private boolean unzipInstall(Context context, Uri zipUri, String dest, boolean delete) {
File localZipFile = null;
InputStream zipFileStream = null;
ZipInputStream zipFile = null;
localZipFile = null;
} else {
localZipFile = new File(zipUri.getPath());
- zipFileStream = new FileInputStream(localZipFile);
+ try {
+ zipFileStream = new FileInputStream(localZipFile);
+ } catch (Exception e) {
+ if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
+ ActivityCompat.requestPermissions(this,
+ new String[] {Manifest.permission.READ_EXTERNAL_STORAGE,
+ Manifest.permission.WRITE_EXTERNAL_STORAGE
+ }, 0);
+ return false;
+ }
+ throw e;
+ }
}
zipFile = new ZipInputStream(new BufferedInputStream(zipFileStream));
final ZipEntry zipEntry = zipFile.getNextEntry();
Toast.LENGTH_LONG).show();
result = true;
} catch (Exception e) {
- String msg = getString(R.string.unzippingFailed, dest);
+ String msg = getString(R.string.unzippingFailed, dest + ": " + e.getMessage());
File dir = application.getDictDir();
if (!dir.canWrite() || !application.checkFileCreate(dir)) {
msg = getString(R.string.notWritable, dir.getAbsolutePath());
try {
if (zipFileStream != null) zipFileStream.close();
} catch (IOException e) {}
- if (localZipFile != null) localZipFile.delete();
+ if (localZipFile != null && delete) localZipFile.delete();
}
return result;
}
intent.getAction().equals(Intent.ACTION_VIEW)) {
blockAutoLaunch = true;
Uri uri = intent.getData();
- unzipInstall(this, uri, uri.getLastPathSegment());
+ unzipInstall(this, uri, uri.getLastPathSegment(), false);
}
}
startActivity(DictionaryActivity.getLaunchIntent(getApplicationContext(),
new File(prefs.getString(C.DICT_FILE, "")),
prefs.getString(C.INDEX_SHORT_NAME, ""),
- prefs.getString(C.SEARCH_TOKEN, "")));
+ ""));
finish();
return;
}
final Editor editor = prefs.edit();
editor.remove(C.DICT_FILE);
editor.remove(C.INDEX_SHORT_NAME);
- editor.remove(C.SEARCH_TOKEN);
editor.commit();
application.backgroundUpdateDictionaries(dictionaryUpdater);