Skip to content

Commit 7b841b8

Browse files
committed
fix: getExternalFilesDir null (#1333)
1 parent d2e337c commit 7b841b8

File tree

2 files changed

+15
-29
lines changed

2 files changed

+15
-29
lines changed

app/src/main/kotlin/li/songe/gkd/util/FolderExt.kt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package li.songe.gkd.util
33
import android.text.format.DateUtils
44
import androidx.annotation.WorkerThread
55
import kotlinx.serialization.Serializable
6+
import kotlinx.serialization.json.Json
67
import li.songe.gkd.META
78
import li.songe.gkd.app
89
import li.songe.gkd.data.AppInfo
@@ -21,7 +22,15 @@ fun File.autoMk(): File {
2122
}
2223

2324
private val filesDir: File by lazy {
24-
app.getExternalFilesDir(null) ?: error("failed getExternalFilesDir")
25+
val markFile = app.filesDir.resolve(".gkd")
26+
if (markFile.isFile) {
27+
app.filesDir
28+
} else {
29+
// fix #1333
30+
app.getExternalFilesDir(null) ?: app.filesDir.also {
31+
markFile.createNewFile()
32+
}
33+
}
2534
}
2635

2736
val dbFolder: File
@@ -42,7 +51,7 @@ val crashTempFolder: File
4251
get() = filesDir.resolve("crash/temp").autoMk()
4352

4453
val privateStoreFolder: File
45-
get() = app.filesDir.resolve("store").autoMk()
54+
get() = app.filesDir.resolve("private-store").autoMk()
4655

4756
private val cacheDir by lazy { app.externalCacheDir ?: app.cacheDir }
4857
val coilCacheDir: File
@@ -87,10 +96,6 @@ private data class AppJsonData(
8796
fun buildLogFile(): File {
8897
val tempDir = createGkdTempDir()
8998
val files = mutableListOf(dbFolder, storeFolder, subsFolder, logFolder, crashFolder)
90-
tempDir.resolve("meta.json").also {
91-
it.writeText(toJson5String(META))
92-
files.add(it)
93-
}
9499
tempDir.resolve("apps.json").also {
95100
it.writeText(json.encodeToString(AppJsonData()))
96101
files.add(it)
@@ -108,8 +113,11 @@ fun buildLogFile(): File {
108113
it.appendText("\nappListAuthAbnormalFlow: ${appListAuthAbnormalFlow.value}")
109114
files.add(it)
110115
}
116+
val formattedJson = Json(from = json) {
117+
prettyPrint = true
118+
}
111119
tempDir.resolve("gkd-${META.versionCode}-v${META.versionName}.json").also {
112-
it.writeText(json.encodeToString(META))
120+
it.writeText(formattedJson.encodeToString(META))
113121
files.add(it)
114122
}
115123
val logZipFile = sharedDir.resolve("log-${System.currentTimeMillis()}.zip")
Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,8 @@
11
<paths>
2-
<files-path
3-
name="files_path"
4-
path="." />
5-
62
<cache-path
73
name="cache_path"
84
path="." />
9-
10-
<external-path
11-
name="external_path"
12-
path="." />
13-
14-
<external-files-path
15-
name="external_files_path"
16-
path="." />
17-
185
<external-cache-path
196
name="external_cache_path"
207
path="." />
21-
22-
<external-media-path
23-
name="external_media_path"
24-
path="." />
25-
26-
<root-path
27-
name="root"
28-
path="." />
298
</paths>
30-

0 commit comments

Comments
 (0)