X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=src%2Fcom%2Fhughes%2Fandroid%2Fdictionary%2FDictionaryManagerActivity.java;h=5264248171c5b33def0dc102f344a71cc94d3f84;hb=dd3ab1add7051a20887e8db6150c1a00a42404a1;hp=833429ad522c3fa480011d96b3dd958a1e400df4;hpb=ca0becd6bc2bb0fa98925ffc6fa1b26964129c89;p=Dictionary.git diff --git a/src/com/hughes/android/dictionary/DictionaryManagerActivity.java b/src/com/hughes/android/dictionary/DictionaryManagerActivity.java index 833429a..5264248 100644 --- a/src/com/hughes/android/dictionary/DictionaryManagerActivity.java +++ b/src/com/hughes/android/dictionary/DictionaryManagerActivity.java @@ -188,7 +188,7 @@ public class DictionaryManagerActivity extends ActionBarActivity { 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); } @@ -196,7 +196,7 @@ public class DictionaryManagerActivity extends ActionBarActivity { } }; - 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; @@ -208,7 +208,18 @@ public class DictionaryManagerActivity extends ActionBarActivity { 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(); @@ -225,7 +236,7 @@ public class DictionaryManagerActivity extends ActionBarActivity { 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()); @@ -242,7 +253,7 @@ public class DictionaryManagerActivity extends ActionBarActivity { try { if (zipFileStream != null) zipFileStream.close(); } catch (IOException e) {} - if (localZipFile != null) localZipFile.delete(); + if (localZipFile != null && delete) localZipFile.delete(); } return result; } @@ -347,7 +358,7 @@ public class DictionaryManagerActivity extends ActionBarActivity { intent.getAction().equals(Intent.ACTION_VIEW)) { blockAutoLaunch = true; Uri uri = intent.getData(); - unzipInstall(this, uri, uri.getLastPathSegment()); + unzipInstall(this, uri, uri.getLastPathSegment(), false); } } @@ -457,7 +468,7 @@ public class DictionaryManagerActivity extends ActionBarActivity { startActivity(DictionaryActivity.getLaunchIntent(getApplicationContext(), new File(prefs.getString(C.DICT_FILE, "")), prefs.getString(C.INDEX_SHORT_NAME, ""), - prefs.getString(C.SEARCH_TOKEN, ""))); + "")); finish(); return; } @@ -467,7 +478,6 @@ public class DictionaryManagerActivity extends ActionBarActivity { 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);