diff options
author | 2012-05-23 00:09:51 -0700 | |
---|---|---|
committer | 2012-05-23 00:09:51 -0700 | |
commit | 7555c3bb18230ce1e76d77e13183f3a17975f019 (patch) | |
tree | 0dcd21abb21b3fc4f375a5d1a9bdaf346856abf6 /java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java | |
parent | 307b882c09c4f9bae53b4aeaa8bfb7d57ee88854 (diff) | |
parent | 41531cfb7413b22267b17359a76fc47432152d57 (diff) | |
download | latinime-7555c3bb18230ce1e76d77e13183f3a17975f019.tar.gz latinime-7555c3bb18230ce1e76d77e13183f3a17975f019.tar.xz latinime-7555c3bb18230ce1e76d77e13183f3a17975f019.zip |
am 41531cfb: am ff4c037c: Merge "Remove an updated dictionary that changed locales" into jb-dev
* commit '41531cfb7413b22267b17359a76fc47432152d57':
Remove an updated dictionary that changed locales
Diffstat (limited to 'java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java index 5acd62904..063243e1b 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java @@ -283,6 +283,39 @@ class BinaryDictionaryGetter { } /** + * Remove all files with the passed id, except the passed file. + * + * If a dictionary with a given ID has a metadata change that causes it to change + * path, we need to remove the old version. The only way to do this is to check all + * installed files for a matching ID in a different directory. + */ + public static void removeFilesWithIdExcept(final Context context, final String id, + final File fileToKeep) { + try { + final File canonicalFileToKeep = fileToKeep.getCanonicalFile(); + final File[] directoryList = getCachedDirectoryList(context); + if (null == directoryList) return; + for (File directory : directoryList) { + // There is one directory per locale. See #getCachedDirectoryList + if (!directory.isDirectory()) continue; + final File[] wordLists = directory.listFiles(); + if (null == wordLists) continue; + for (File wordList : wordLists) { + final String fileId = getWordListIdFromFileName(wordList.getName()); + if (fileId.equals(id)) { + if (!canonicalFileToKeep.equals(wordList.getCanonicalFile())) { + wordList.delete(); + } + } + } + } + } catch (java.io.IOException e) { + Log.e(TAG, "IOException trying to cleanup files : " + e); + } + } + + + /** * Returns the id associated with the main word list for a specified locale. * * Word lists stored in Android Keyboard's resources are referred to as the "main" |