|
|
@ -1,4 +1,4 @@ |
|
|
|
package io.legado.app.help |
|
|
|
package io.legado.app.help.config |
|
|
|
|
|
|
|
|
|
|
|
import android.graphics.Color |
|
|
|
import android.graphics.Color |
|
|
|
import android.graphics.drawable.BitmapDrawable |
|
|
|
import android.graphics.drawable.BitmapDrawable |
|
|
@ -8,6 +8,7 @@ import androidx.annotation.Keep |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.constant.AppLog |
|
|
|
import io.legado.app.constant.AppLog |
|
|
|
import io.legado.app.constant.PreferKey |
|
|
|
import io.legado.app.constant.PreferKey |
|
|
|
|
|
|
|
import io.legado.app.help.DefaultData |
|
|
|
import io.legado.app.help.coroutine.Coroutine |
|
|
|
import io.legado.app.help.coroutine.Coroutine |
|
|
|
import io.legado.app.model.NoStackTraceException |
|
|
|
import io.legado.app.model.NoStackTraceException |
|
|
|
import io.legado.app.ui.book.read.page.provider.ChapterProvider |
|
|
|
import io.legado.app.ui.book.read.page.provider.ChapterProvider |
|
|
@ -16,7 +17,6 @@ import kotlinx.coroutines.Dispatchers.IO |
|
|
|
import kotlinx.coroutines.withContext |
|
|
|
import kotlinx.coroutines.withContext |
|
|
|
import splitties.init.appCtx |
|
|
|
import splitties.init.appCtx |
|
|
|
import java.io.File |
|
|
|
import java.io.File |
|
|
|
import java.io.IOException |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 阅读界面配置 |
|
|
|
* 阅读界面配置 |
|
|
@ -366,64 +366,65 @@ object ReadBookConfig { |
|
|
|
return exportConfig |
|
|
|
return exportConfig |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Throws(IOException::class) |
|
|
|
suspend fun import(byteArray: ByteArray): Result<Config> { |
|
|
|
suspend fun import(byteArray: ByteArray): Config { |
|
|
|
return kotlin.runCatching { |
|
|
|
return withContext(IO) { |
|
|
|
withContext(IO) { |
|
|
|
val configZipPath = FileUtils.getPath(appCtx.externalCache, "readConfig.zip") |
|
|
|
val configZipPath = FileUtils.getPath(appCtx.externalCache, "readConfig.zip") |
|
|
|
FileUtils.deleteFile(configZipPath) |
|
|
|
FileUtils.deleteFile(configZipPath) |
|
|
|
val zipFile = FileUtils.createFileIfNotExist(configZipPath) |
|
|
|
val zipFile = FileUtils.createFileIfNotExist(configZipPath) |
|
|
|
zipFile.writeBytes(byteArray) |
|
|
|
zipFile.writeBytes(byteArray) |
|
|
|
val configDirPath = FileUtils.getPath(appCtx.externalCache, "readConfig") |
|
|
|
val configDirPath = FileUtils.getPath(appCtx.externalCache, "readConfig") |
|
|
|
FileUtils.deleteFile(configDirPath) |
|
|
|
FileUtils.deleteFile(configDirPath) |
|
|
|
@Suppress("BlockingMethodInNonBlockingContext") |
|
|
|
@Suppress("BlockingMethodInNonBlockingContext") |
|
|
|
ZipUtils.unzipFile(zipFile, FileUtils.createFolderIfNotExist(configDirPath)) |
|
|
|
ZipUtils.unzipFile(zipFile, FileUtils.createFolderIfNotExist(configDirPath)) |
|
|
|
val configDir = FileUtils.createFolderIfNotExist(configDirPath) |
|
|
|
val configDir = FileUtils.createFolderIfNotExist(configDirPath) |
|
|
|
val configFile = configDir.getFile(configFileName) |
|
|
|
val configFile = configDir.getFile(configFileName) |
|
|
|
val config: Config = GSON.fromJsonObject<Config>(configFile.readText()).getOrThrow() |
|
|
|
val config: Config = GSON.fromJsonObject<Config>(configFile.readText()).getOrThrow() |
|
|
|
?: throw NoStackTraceException("排版配置格式错误") |
|
|
|
?: throw NoStackTraceException("排版配置格式错误") |
|
|
|
if (config.textFont.isNotEmpty()) { |
|
|
|
if (config.textFont.isNotEmpty()) { |
|
|
|
val fontName = FileUtils.getName(config.textFont) |
|
|
|
val fontName = FileUtils.getName(config.textFont) |
|
|
|
val fontPath = |
|
|
|
val fontPath = |
|
|
|
FileUtils.getPath(appCtx.externalFiles, "font", fontName) |
|
|
|
FileUtils.getPath(appCtx.externalFiles, "font", fontName) |
|
|
|
if (!FileUtils.exist(fontPath)) { |
|
|
|
if (!FileUtils.exist(fontPath)) { |
|
|
|
configDir.getFile(fontName).copyTo(File(fontPath)) |
|
|
|
configDir.getFile(fontName).copyTo(File(fontPath)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
config.textFont = fontPath |
|
|
|
} |
|
|
|
} |
|
|
|
config.textFont = fontPath |
|
|
|
if (config.bgType == 2) { |
|
|
|
} |
|
|
|
val bgName = FileUtils.getName(config.bgStr) |
|
|
|
if (config.bgType == 2) { |
|
|
|
val bgPath = FileUtils.getPath(appCtx.externalFiles, "bg", bgName) |
|
|
|
val bgName = FileUtils.getName(config.bgStr) |
|
|
|
if (!FileUtils.exist(bgPath)) { |
|
|
|
val bgPath = FileUtils.getPath(appCtx.externalFiles, "bg", bgName) |
|
|
|
val bgFile = configDir.getFile(bgName) |
|
|
|
if (!FileUtils.exist(bgPath)) { |
|
|
|
if (bgFile.exists()) { |
|
|
|
val bgFile = configDir.getFile(bgName) |
|
|
|
bgFile.copyTo(File(bgPath)) |
|
|
|
if (bgFile.exists()) { |
|
|
|
} |
|
|
|
bgFile.copyTo(File(bgPath)) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
config.bgStr = bgPath |
|
|
|
} |
|
|
|
} |
|
|
|
config.bgStr = bgPath |
|
|
|
if (config.bgTypeNight == 2) { |
|
|
|
} |
|
|
|
val bgName = FileUtils.getName(config.bgStrNight) |
|
|
|
if (config.bgTypeNight == 2) { |
|
|
|
val bgPath = FileUtils.getPath(appCtx.externalFiles, "bg", bgName) |
|
|
|
val bgName = FileUtils.getName(config.bgStrNight) |
|
|
|
if (!FileUtils.exist(bgPath)) { |
|
|
|
val bgPath = FileUtils.getPath(appCtx.externalFiles, "bg", bgName) |
|
|
|
val bgFile = configDir.getFile(bgName) |
|
|
|
if (!FileUtils.exist(bgPath)) { |
|
|
|
if (bgFile.exists()) { |
|
|
|
val bgFile = configDir.getFile(bgName) |
|
|
|
bgFile.copyTo(File(bgPath)) |
|
|
|
if (bgFile.exists()) { |
|
|
|
} |
|
|
|
bgFile.copyTo(File(bgPath)) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
config.bgStrNight = bgPath |
|
|
|
} |
|
|
|
} |
|
|
|
config.bgStrNight = bgPath |
|
|
|
if (config.bgTypeEInk == 2) { |
|
|
|
} |
|
|
|
val bgName = FileUtils.getName(config.bgStrEInk) |
|
|
|
if (config.bgTypeEInk == 2) { |
|
|
|
val bgPath = FileUtils.getPath(appCtx.externalFiles, "bg", bgName) |
|
|
|
val bgName = FileUtils.getName(config.bgStrEInk) |
|
|
|
if (!FileUtils.exist(bgPath)) { |
|
|
|
val bgPath = FileUtils.getPath(appCtx.externalFiles, "bg", bgName) |
|
|
|
val bgFile = configDir.getFile(bgName) |
|
|
|
if (!FileUtils.exist(bgPath)) { |
|
|
|
if (bgFile.exists()) { |
|
|
|
val bgFile = configDir.getFile(bgName) |
|
|
|
bgFile.copyTo(File(bgPath)) |
|
|
|
if (bgFile.exists()) { |
|
|
|
} |
|
|
|
bgFile.copyTo(File(bgPath)) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
config.bgStrEInk = bgPath |
|
|
|
} |
|
|
|
} |
|
|
|
config.bgStrEInk = bgPath |
|
|
|
return@withContext config |
|
|
|
} |
|
|
|
} |
|
|
|
return@withContext config |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|