commit backup restore

pull/55/head
ca1e 5 years ago
parent 302a561ed5
commit 4a12578339
  1. 20
      app/src/main/java/io/legado/app/help/storage/Backup.kt
  2. 13
      app/src/main/java/io/legado/app/help/storage/Restore.kt
  3. 7
      app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt
  4. 6
      app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt
  5. 35
      app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt
  6. 2
      app/src/main/res/values/arrays.xml
  7. 4
      app/src/main/res/xml/pref_config_web_dav.xml

@ -20,16 +20,14 @@ object Backup {
}
val legadoPath by lazy {
defaultPath + File.separator + "legadoBackUp"
FileUtils.getSdCardPath() + File.separator + "YueDu3.0"
}
val exportPath by lazy {
legadoPath + File.separator + "Export"
}
fun backup() {
doAsync {
val path = legadoPath
private fun pbackup(path :String = legadoPath){
backupBookshelf(path)
backupBookSource(path)
backupRssSource(path)
@ -37,6 +35,11 @@ object Backup {
backupReadConfig(path)
backupPreference(path)
WebDavHelp.backUpWebDav(path)
}
fun backup() {
doAsync {
pbackup()
uiThread {
App.INSTANCE.toast(R.string.backup_success)
}
@ -45,14 +48,7 @@ object Backup {
fun autoBackup() {
doAsync {
val path = legadoPath
backupBookshelf(path)
backupBookSource(path)
backupRssSource(path)
backupReplaceRule(path)
backupReadConfig(path)
backupPreference(path)
WebDavHelp.backUpWebDav(path)
pbackup()
}
}

@ -7,6 +7,7 @@ import com.jayway.jsonpath.JsonPath
import com.jayway.jsonpath.Option
import com.jayway.jsonpath.ParseContext
import io.legado.app.App
import io.legado.app.R
import io.legado.app.constant.AppConst
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookSource
@ -14,8 +15,6 @@ import io.legado.app.data.entities.ReplaceRule
import io.legado.app.data.entities.RssSource
import io.legado.app.help.FileHelp
import io.legado.app.help.ReadBookConfig
import io.legado.app.help.storage.Backup.defaultPath
import io.legado.app.help.storage.Backup.legadoPath
import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
@ -37,7 +36,7 @@ object Restore {
)
}
fun restore(path: String = legadoPath) {
fun restore(path: String = Backup.legadoPath) {
doAsync {
try {
val file = FileHelp.getFile(path + File.separator + "bookshelf.json")
@ -99,14 +98,14 @@ object Restore {
}
edit.commit()
}
uiThread { App.INSTANCE.toast("恢复完成") }
uiThread { App.INSTANCE.toast(R.string.restore_success) }
}
}
fun importYueDuData(context: Context) {
GlobalScope.launch(IO) {
try {// 导入书架
val shelfFile = FileHelp.getFile(defaultPath + File.separator + "myBookShelf.json")
val shelfFile = FileHelp.getFile(Backup.defaultPath + File.separator + "myBookShelf.json")
val books = mutableListOf<Book>()
val items: List<Map<String, Any>> = jsonPath.parse(shelfFile.readText()).read("$")
val existingBooks = App.db.bookDao().allBookUrls.toSet()
@ -156,7 +155,7 @@ object Restore {
try {// Book source
val sourceFile =
FileHelp.getFile(defaultPath + File.separator + "myBookSource.json")
FileHelp.getFile(Backup.defaultPath + File.separator + "myBookSource.json")
val bookSources = mutableListOf<BookSource>()
val items: List<Map<String, Any>> = jsonPath.parse(sourceFile.readText()).read("$")
for (item in items) {
@ -177,7 +176,7 @@ object Restore {
try {// Replace rules
val ruleFile =
FileHelp.getFile(defaultPath + File.separator + "myBookReplaceRule.json")
FileHelp.getFile(Backup.defaultPath + File.separator + "myBookReplaceRule.json")
val replaceRules = mutableListOf<ReplaceRule>()
val items: List<Map<String, Any>> = jsonPath.parse(ruleFile.readText()).read("$")
val existingRules = App.db.replaceRuleDao().all.map { it.pattern }.toSet()

@ -18,6 +18,9 @@ import kotlin.math.min
object WebDavHelp {
private val zipFilePath = FileHelp.getCachePath() + "/backup" + ".zip"
private val unzipFilesPath by lazy {
FileHelp.getCachePath()
}
private fun getWebDavUrl(): String? {
var url = App.INSTANCE.getPrefString("web_dav_url")
@ -73,8 +76,8 @@ object WebDavHelp {
getWebDavUrl()?.let {
val file = WebDav(it + "legado/" + name)
file.downloadTo(zipFilePath, true)
ZipUtils.unzipFile(zipFilePath, Backup.legadoPath)
Restore.restore()
ZipUtils.unzipFile(zipFilePath, unzipFilesPath)
Restore.restore(unzipFilesPath)
}
}
}

@ -61,8 +61,10 @@ class ConfigFragment : PreferenceFragmentCompat(),
initPath = getPreferenceString(PreferKey.downloadPath)
)
PreferKey.cleanCache -> {
LogUtils.d("xxx","cleancaches")
FileHelp.deleteFile(getPreferenceString(PreferKey.downloadPath))
getPreferenceString(PreferKey.downloadPath).let {
FileHelp.deleteFile(it)
FileHelp.getFolder(it)
}
toast("成功清理缓存")
}
}

@ -1,6 +1,5 @@
package io.legado.app.ui.config
import android.content.Context
import android.os.Build
import android.os.Bundle
import android.text.InputType
@ -106,7 +105,22 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference
WebDavHelp.showRestoreDialog(requireContext())
}
.request()
"import_old" -> needInstallApps { importOld() }
"import_old" -> needInstallApps {
alert(title = "导入") {
message = "是否导入旧版本数据"
yesButton {
PermissionsCompat.Builder(this@WebDavConfigFragment)
.addPermissions(*Permissions.Group.STORAGE)
.rationale(R.string.tip_perm_request_storage)
.onGranted {
Restore.importYueDuData(requireContext())
}
.request()
}
noButton {
}
}.show().applyTint()
}
}
return super.onPreferenceTreeClick(preference)
}
@ -133,21 +147,4 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference
callback()
}
}
private fun importOld() {
alert(title = "导入") {
message = "是否导入旧版本数据"
yesButton {
PermissionsCompat.Builder(this@WebDavConfigFragment)
.addPermissions(*Permissions.Group.STORAGE)
.rationale(R.string.tip_perm_request_storage)
.onGranted {
Restore.importYueDuData(requireContext())
}
.request()
}
noButton {
}
}.show().applyTint()
}
}

@ -40,7 +40,7 @@
<item>@string/layout_grid3</item>
<item>@string/layout_grid4</item>
<item>@string/layout_grid5</item>
<item>@string/layout_grid6</item>
<!-- <item>@string/layout_grid6</item>-->
</string-array>
<string-array name="indent">

@ -20,6 +20,8 @@
android:summary="@string/web_dav_pw_s"
app:iconSpaceReserved="false" />
<io.legado.app.lib.theme.prefs.ATEPreferenceCategory app:iconSpaceReserved="false">
<androidx.preference.Preference
android:key="web_dav_backup"
android:title="备份"
@ -35,4 +37,6 @@
android:title="导入旧版本数据"
app:iconSpaceReserved="false" />
</io.legado.app.lib.theme.prefs.ATEPreferenceCategory>
</androidx.preference.PreferenceScreen>
Loading…
Cancel
Save