This commit is contained in:
kunfei
2022-03-11 14:41:21 +08:00
parent 296346669e
commit e8cea822a2
13 changed files with 99 additions and 44 deletions
@@ -31,14 +31,14 @@ object BookHelp {
private val downloadImages = CopyOnWriteArraySet<String>()
fun clearCache() {
FileUtils.deleteFile(
FileUtils.delete(
FileUtils.getPath(downloadDir, cacheFolderName)
)
}
fun clearCache(book: Book) {
val filePath = FileUtils.getPath(downloadDir, cacheFolderName, book.getFolderName())
FileUtils.deleteFile(filePath)
FileUtils.delete(filePath)
}
/**
@@ -53,7 +53,7 @@ object BookHelp {
val file = downloadDir.getFile(cacheFolderName)
file.listFiles()?.forEach { bookFile ->
if (!bookFolderNames.contains(bookFile.name)) {
FileUtils.deleteFile(bookFile.absolutePath)
FileUtils.delete(bookFile.absolutePath)
}
}
}
@@ -177,7 +177,7 @@ interface JsExtensions {
FileUtils.createFolderIfNotExist(FileUtils.getCachePath()),
"${MD5Utils.md5Encode16(url)}.${type}"
)
FileUtils.deleteFile(zipPath)
FileUtils.delete(zipPath)
val zipFile = FileUtils.createFileIfNotExist(zipPath)
StringUtils.hexStringToByte(content).let {
if (it.isNotEmpty()) {
@@ -363,11 +363,11 @@ interface JsExtensions {
FileUtils.createFolderIfNotExist(FileUtils.getCachePath()),
FileUtils.getNameExcludeExtension(zipPath)
)
FileUtils.deleteFile(unzipPath)
FileUtils.delete(unzipPath)
val zipFile = getFile(zipPath)
val unzipFolder = FileUtils.createFolderIfNotExist(unzipPath)
ZipUtils.unzipFile(zipFile, unzipFolder)
FileUtils.deleteFile(zipFile.absolutePath)
FileUtils.delete(zipFile.absolutePath)
return unzipPath.substring(FileUtils.getCachePath().length)
}
@@ -388,7 +388,7 @@ interface JsExtensions {
contents.deleteCharAt(contents.length - 1)
}
}
FileUtils.deleteFile(unzipFolder.absolutePath)
FileUtils.delete(unzipFolder.absolutePath)
return contents.toString()
}
@@ -1,29 +1,101 @@
package io.legado.app.help
import io.legado.app.utils.FileUtils
import io.legado.app.utils.MD5Utils
import io.legado.app.utils.externalFiles
import splitties.init.appCtx
import java.io.File
object RuleBigDataHelp {
fun putBookVariable(bookUrl: String, key: String, value: String?) {
private val ruleDataDir = FileUtils.createFolderIfNotExist(appCtx.externalFiles, "ruleData")
private val bookData = FileUtils.createFolderIfNotExist(ruleDataDir, "book")
private val rssData = FileUtils.createFolderIfNotExist(ruleDataDir, "rss")
fun putBookVariable(bookUrl: String, key: String, value: String?) {
val md5BookUrl = MD5Utils.md5Encode(bookUrl)
val md5Key = MD5Utils.md5Encode(key)
if (value == null) {
FileUtils.delete(FileUtils.getPath(bookData, md5BookUrl, "$md5Key.txt"), true)
} else {
val valueFile = FileUtils.createFileIfNotExist(bookData, md5BookUrl, "$md5Key.txt")
valueFile.writeText(value)
val bookUrlFile = File(FileUtils.getPath(bookData, md5BookUrl, "bookUrl.txt"))
if (!bookUrlFile.exists()) {
bookUrlFile.writeText(bookUrl)
}
}
}
fun getBookVariable(bookUrl: String, key: String?): String? {
val md5BookUrl = MD5Utils.md5Encode(bookUrl)
val md5Key = MD5Utils.md5Encode(key)
val file = File(FileUtils.getPath(bookData, md5BookUrl, "$md5Key.txt"))
if (file.exists()) {
return file.readText()
}
return null
}
fun putChapterVariable(bookUrl: String, chapterUrl: String, key: String, value: String?) {
val md5BookUrl = MD5Utils.md5Encode(bookUrl)
val md5ChapterUrl = MD5Utils.md5Encode(chapterUrl)
val md5Key = MD5Utils.md5Encode(key)
if (value == null) {
FileUtils.delete(FileUtils.getPath(bookData, md5BookUrl, md5ChapterUrl, "$md5Key.txt"))
} else {
val valueFile =
FileUtils.createFileIfNotExist(bookData, md5BookUrl, md5ChapterUrl, "$md5Key.txt")
valueFile.writeText(value)
val bookUrlFile = File(FileUtils.getPath(bookData, md5BookUrl, "bookUrl.txt"))
if (!bookUrlFile.exists()) {
bookUrlFile.writeText(bookUrl)
}
}
}
fun getChapterVariable(bookUrl: String, chapterUrl: String, key: String): String? {
val md5BookUrl = MD5Utils.md5Encode(bookUrl)
val md5ChapterUrl = MD5Utils.md5Encode(chapterUrl)
val md5Key = MD5Utils.md5Encode(key)
val file = File(FileUtils.getPath(bookData, md5BookUrl, md5ChapterUrl, "$md5Key.txt"))
if (file.exists()) {
return file.readText()
}
return null
}
fun putRssVariable(origin: String, link: String, key: String, value: String?) {
val md5Origin = MD5Utils.md5Encode(origin)
val md5Link = MD5Utils.md5Encode(link)
val md5Key = MD5Utils.md5Encode(key)
val filePath = FileUtils.getPath(rssData, md5Origin, md5Link, "$md5Key.txt")
if (value == null) {
FileUtils.delete(filePath)
} else {
val valueFile = FileUtils.createFileIfNotExist(filePath)
valueFile.writeText(value)
val originFile = File(FileUtils.getPath(rssData, md5Origin, "origin.txt"))
if (!originFile.exists()) {
originFile.writeText(origin)
}
val linFile = File(FileUtils.getPath(rssData, md5Origin, md5Link, "origin.txt"))
if (!linFile.exists()) {
linFile.writeText(link)
}
}
}
fun getRssVariable(origin: String, link: String, key: String): String? {
val md5Origin = MD5Utils.md5Encode(origin)
val md5Link = MD5Utils.md5Encode(link)
val md5Key = MD5Utils.md5Encode(key)
val filePath = FileUtils.getPath(rssData, md5Origin, md5Link, "$md5Key.txt")
val file = File(filePath)
if (file.exists()) {
return file.readText()
}
return null
}
}
@@ -105,11 +105,11 @@ object ReadBookConfig {
Coroutine.async {
synchronized(this) {
GSON.toJson(configList).let {
FileUtils.deleteFile(configFilePath)
FileUtils.delete(configFilePath)
FileUtils.createFileIfNotExist(configFilePath).writeText(it)
}
GSON.toJson(shareConfig).let {
FileUtils.deleteFile(shareConfigFilePath)
FileUtils.delete(shareConfigFilePath)
FileUtils.createFileIfNotExist(shareConfigFilePath).writeText(it)
}
}
@@ -370,11 +370,11 @@ object ReadBookConfig {
return kotlin.runCatching {
withContext(IO) {
val configZipPath = FileUtils.getPath(appCtx.externalCache, "readConfig.zip")
FileUtils.deleteFile(configZipPath)
FileUtils.delete(configZipPath)
val zipFile = FileUtils.createFileIfNotExist(configZipPath)
zipFile.writeBytes(byteArray)
val configDirPath = FileUtils.getPath(appCtx.externalCache, "readConfig")
FileUtils.deleteFile(configDirPath)
FileUtils.delete(configDirPath)