mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -40,6 +40,13 @@ object AppWebDav {
|
||||
return url
|
||||
}
|
||||
|
||||
private val backupFileName: String
|
||||
get() {
|
||||
val backupDate = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
|
||||
.format(Date(System.currentTimeMillis()))
|
||||
return "backup${backupDate}.zip"
|
||||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
suspend fun initWebDav(): Boolean {
|
||||
val account = appCtx.getPrefString(PreferKey.webDavAccount)
|
||||
@@ -105,6 +112,11 @@ object AppWebDav {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun hasBackUp(): Boolean {
|
||||
val url = "${rootWebDavUrl}${backupFileName}"
|
||||
return WebDav(url).exists()
|
||||
}
|
||||
|
||||
suspend fun backUpWebDav(path: String) {
|
||||
try {
|
||||
if (initWebDav() && NetworkUtils.isAvailable()) {
|
||||
@@ -114,9 +126,7 @@ object AppWebDav {
|
||||
}
|
||||
FileUtils.deleteFile(zipFilePath)
|
||||
if (ZipUtils.zipFiles(paths, zipFilePath)) {
|
||||
val backupDate = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
|
||||
.format(Date(System.currentTimeMillis()))
|
||||
val putUrl = "${rootWebDavUrl}backup${backupDate}.zip"
|
||||
val putUrl = "${rootWebDavUrl}${backupFileName}"
|
||||
WebDav(putUrl).upload(zipFilePath)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,9 @@ object Backup : BackupRestore() {
|
||||
val lastBackup = context.getPrefLong(PreferKey.lastBackup)
|
||||
if (lastBackup + TimeUnit.DAYS.toMillis(1) < System.currentTimeMillis()) {
|
||||
Coroutine.async {
|
||||
backup(context, context.getPrefString(PreferKey.backupPath) ?: "", true)
|
||||
if (!AppWebDav.hasBackUp()) {
|
||||
backup(context, context.getPrefString(PreferKey.backupPath) ?: "", true)
|
||||
}
|
||||
}.onError {
|
||||
AppLog.put("备份出错\n${it.localizedMessage}", it)
|
||||
appCtx.toastOnUi(appCtx.getString(R.string.autobackup_fail, it.localizedMessage))
|
||||
|
||||
@@ -49,7 +49,6 @@ class WebDav(urlStr: String) {
|
||||
val path get() = url.toString()
|
||||
var displayName: String? = null
|
||||
var size: Long = 0
|
||||
var exists = false
|
||||
var parent = ""
|
||||
var urlName = ""
|
||||
var contentType = ""
|
||||
@@ -141,6 +140,13 @@ class WebDav(urlStr: String) {
|
||||
return list
|
||||
}
|
||||
|
||||
suspend fun exists(): Boolean {
|
||||
val response = propFindResponse() ?: return false
|
||||
val document = Jsoup.parse(response)
|
||||
val elements = document.getElementsByTag("d:response")
|
||||
return elements.isNotEmpty()
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据自己的URL,在远程处创建对应的文件夹
|
||||
* @return 是否创建成功
|
||||
|
||||
Reference in New Issue
Block a user