Skip to content

Commit e17d5d0

Browse files
committed
fix(core,data): build opencc dictionaries in the user data dir
1 parent 11b59b8 commit e17d5d0

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

app/src/main/java/com/osfans/trime/core/Rime.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ public static boolean selectSchema(String schemaId) {
356356
public static Rime get(boolean full_check) {
357357
if (self == null) {
358358
if (full_check) {
359-
OpenCCDictManager.internalDeploy();
359+
OpenCCDictManager.buildOpenCCDict();
360360
}
361361
self = new Rime(full_check);
362362
}

app/src/main/java/com/osfans/trime/data/opencc/OpenCCDictManager.kt

+17-11
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,23 @@ object OpenCCDictManager {
1616
System.loadLibrary("rime_jni")
1717
}
1818

19-
private val openccDictDir = File(
20-
DataManager.getDataDir("opencc")
21-
).also { it.mkdirs() }
19+
val sharedDir = File(DataManager.sharedDataDir, "opencc").also { it.mkdirs() }
20+
val userDir = File(DataManager.userDataDir, "opencc").also { it.mkdirs() }
2221

23-
fun dictionaries(): List<Dictionary> = openccDictDir
22+
fun sharedDictionaries(): List<Dictionary> = sharedDir
2423
.listFiles()
25-
?.mapNotNull { Dictionary.new(it) }
26-
?.toList() ?: listOf()
24+
?.mapNotNull { Dictionary.new(it) } ?: listOf()
2725

28-
fun openccDictionaries(): List<OpenCCDictionary> =
29-
dictionaries().mapNotNull { it as? OpenCCDictionary }
26+
fun userDictionaries(): List<Dictionary> = userDir
27+
.listFiles()
28+
?.mapNotNull { Dictionary.new(it) } ?: listOf()
29+
30+
fun getAllDictionaries(): List<Dictionary> =
31+
if (sharedDir.path == userDir.path) userDictionaries()
32+
else (sharedDictionaries() + userDictionaries())
33+
34+
fun openCCDictionaries(): List<OpenCCDictionary> =
35+
getAllDictionaries().mapNotNull { it as? OpenCCDictionary }
3036

3137
fun importFromFile(file: File): OpenCCDictionary {
3238
val raw = Dictionary.new(file)
@@ -35,7 +41,7 @@ object OpenCCDictManager {
3541
// preserve original file name
3642
val new = raw.toOpenCCDictionary(
3743
File(
38-
openccDictDir,
44+
userDir,
3945
file.nameWithoutExtension + ".${Dictionary.Type.OPENCC.ext}"
4046
)
4147
)
@@ -47,8 +53,8 @@ object OpenCCDictManager {
4753
* Convert internal text dict to opencc format
4854
*/
4955
@JvmStatic
50-
fun internalDeploy() {
51-
for (d in dictionaries()) {
56+
fun buildOpenCCDict() {
57+
for (d in getAllDictionaries()) {
5258
if (d is TextDictionary) {
5359
val result: OpenCCDictionary
5460
measureTimeMillis {

0 commit comments

Comments
 (0)