|
|
@ -15,7 +15,7 @@ import java.io.File |
|
|
|
|
|
|
|
|
|
|
|
object Backup { |
|
|
|
object Backup { |
|
|
|
|
|
|
|
|
|
|
|
val backupPath = App.INSTANCE.filesDir.absolutePath + File.separator + "backup" |
|
|
|
private val backupPath = App.INSTANCE.filesDir.absolutePath + File.separator + "backup" |
|
|
|
|
|
|
|
|
|
|
|
val defaultPath by lazy { |
|
|
|
val defaultPath by lazy { |
|
|
|
FileUtils.getSdCardPath() + File.separator + "YueDu" |
|
|
|
FileUtils.getSdCardPath() + File.separator + "YueDu" |
|
|
@ -29,6 +29,18 @@ object Backup { |
|
|
|
legadoPath + File.separator + "Export" |
|
|
|
legadoPath + File.separator + "Export" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val backupFileNames by lazy { |
|
|
|
|
|
|
|
arrayOf( |
|
|
|
|
|
|
|
"bookshelf.json", |
|
|
|
|
|
|
|
"bookGroup.json", |
|
|
|
|
|
|
|
"bookSource.json", |
|
|
|
|
|
|
|
"rssSource.json", |
|
|
|
|
|
|
|
"replaceRule.json", |
|
|
|
|
|
|
|
ReadBookConfig.readConfigFileName, |
|
|
|
|
|
|
|
"config.xml" |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun backup(context: Context, uri: Uri?) { |
|
|
|
fun backup(context: Context, uri: Uri?) { |
|
|
|
App.db.bookDao().allBooks.let { |
|
|
|
App.db.bookDao().allBooks.let { |
|
|
|
if (it.isNotEmpty()) { |
|
|
|
if (it.isNotEmpty()) { |
|
|
@ -81,21 +93,14 @@ object Backup { |
|
|
|
WebDavHelp.backUpWebDav(backupPath) |
|
|
|
WebDavHelp.backUpWebDav(backupPath) |
|
|
|
if (uri != null) { |
|
|
|
if (uri != null) { |
|
|
|
copyBackup(context, uri) |
|
|
|
copyBackup(context, uri) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
copyBackup() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun copyBackup(context: Context, uri: Uri) { |
|
|
|
private fun copyBackup(context: Context, uri: Uri) { |
|
|
|
DocumentFile.fromTreeUri(context, uri)?.let { treeDoc -> |
|
|
|
DocumentFile.fromTreeUri(context, uri)?.let { treeDoc -> |
|
|
|
val fileNames = arrayOf( |
|
|
|
for (fileName in backupFileNames) { |
|
|
|
"bookshelf.json", |
|
|
|
|
|
|
|
"bookGroup.json", |
|
|
|
|
|
|
|
"bookSource.json", |
|
|
|
|
|
|
|
"rssSource.json", |
|
|
|
|
|
|
|
"replaceRule.json", |
|
|
|
|
|
|
|
ReadBookConfig.readConfigFileName, |
|
|
|
|
|
|
|
"config.xml" |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
for (fileName in fileNames) { |
|
|
|
|
|
|
|
treeDoc.createFile("text/plain", fileName)?.let { doc -> |
|
|
|
treeDoc.createFile("text/plain", fileName)?.let { doc -> |
|
|
|
DocumentUtils.writeText( |
|
|
|
DocumentUtils.writeText( |
|
|
|
context, |
|
|
|
context, |
|
|
@ -107,4 +112,10 @@ object Backup { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun copyBackup() { |
|
|
|
|
|
|
|
for (fileName in backupFileNames) { |
|
|
|
|
|
|
|
FileHelp.getFile(backupPath + File.separator + "bookshelf.json") |
|
|
|
|
|
|
|
.copyTo(FileHelp.getFile(legadoPath + File.separator + "bookshelf.json")) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |