]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - src/com/hughes/android/dictionary/DictionaryManagerActivity.java
Remove dead code.
[Dictionary.git] / src / com / hughes / android / dictionary / DictionaryManagerActivity.java
index 833429ad522c3fa480011d96b3dd958a1e400df4..5264248171c5b33def0dc102f344a71cc94d3f84 100644 (file)
@@ -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);