|
|
@ -1,18 +1,45 @@ |
|
|
|
package io.legado.app.help.storage |
|
|
|
package io.legado.app.help.storage |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity |
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.App |
|
|
|
|
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.help.FileHelp |
|
|
|
import io.legado.app.help.FileHelp |
|
|
|
|
|
|
|
import io.legado.app.help.permission.Permissions |
|
|
|
|
|
|
|
import io.legado.app.help.permission.PermissionsCompat |
|
|
|
|
|
|
|
import io.legado.app.utils.FileUtils |
|
|
|
import io.legado.app.utils.GSON |
|
|
|
import io.legado.app.utils.GSON |
|
|
|
import java.io.File |
|
|
|
import java.io.File |
|
|
|
|
|
|
|
|
|
|
|
object Backup { |
|
|
|
object Backup { |
|
|
|
|
|
|
|
|
|
|
|
fun backup() { |
|
|
|
fun backup(activity: AppCompatActivity) { |
|
|
|
|
|
|
|
PermissionsCompat.Builder(activity) |
|
|
|
|
|
|
|
.addPermissions(*Permissions.Group.STORAGE) |
|
|
|
|
|
|
|
.rationale(R.string.tip_perm_request_storage) |
|
|
|
|
|
|
|
.onGranted { |
|
|
|
|
|
|
|
val path = |
|
|
|
|
|
|
|
FileUtils.getSdCardPath() + File.separator + "YueDu" + File.separator + "legadoBackUp" |
|
|
|
|
|
|
|
backupBookshelf(path) |
|
|
|
|
|
|
|
backupBookSource(path) |
|
|
|
|
|
|
|
backupRssSource(path) |
|
|
|
|
|
|
|
backupReplaceRule(path) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
.request() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun autoBackup() { |
|
|
|
fun autoBackup(activity: AppCompatActivity) { |
|
|
|
|
|
|
|
PermissionsCompat.Builder(activity) |
|
|
|
|
|
|
|
.addPermissions(*Permissions.Group.STORAGE) |
|
|
|
|
|
|
|
.rationale(R.string.tip_perm_request_storage) |
|
|
|
|
|
|
|
.onGranted { |
|
|
|
|
|
|
|
val path = |
|
|
|
|
|
|
|
FileUtils.getSdCardPath() + File.separator + "YueDu" + File.separator + "legadoBackUp" |
|
|
|
|
|
|
|
backupBookshelf(path) |
|
|
|
|
|
|
|
backupBookSource(path) |
|
|
|
|
|
|
|
backupRssSource(path) |
|
|
|
|
|
|
|
backupReplaceRule(path) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
.request() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun backupBookshelf(path: String) { |
|
|
|
private fun backupBookshelf(path: String) { |
|
|
@ -27,7 +54,7 @@ object Backup { |
|
|
|
file.writeText(json) |
|
|
|
file.writeText(json) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun backupCssSource(path: String) { |
|
|
|
private fun backupRssSource(path: String) { |
|
|
|
val json = GSON.toJson(App.db.rssSourceDao().all) |
|
|
|
val json = GSON.toJson(App.db.rssSourceDao().all) |
|
|
|
val file = FileHelp.getFile(path + File.separator + "cssSource.json") |
|
|
|
val file = FileHelp.getFile(path + File.separator + "cssSource.json") |
|
|
|
file.writeText(json) |
|
|
|
file.writeText(json) |
|
|
|