|
|
@ -9,6 +9,8 @@ import io.legado.app.help.ReadBookConfig |
|
|
|
import io.legado.app.utils.DocumentUtils |
|
|
|
import io.legado.app.utils.DocumentUtils |
|
|
|
import io.legado.app.utils.FileUtils |
|
|
|
import io.legado.app.utils.FileUtils |
|
|
|
import io.legado.app.utils.GSON |
|
|
|
import io.legado.app.utils.GSON |
|
|
|
|
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
|
|
|
|
|
import kotlinx.coroutines.withContext |
|
|
|
import org.jetbrains.anko.defaultSharedPreferences |
|
|
|
import org.jetbrains.anko.defaultSharedPreferences |
|
|
|
import java.io.File |
|
|
|
import java.io.File |
|
|
|
|
|
|
|
|
|
|
@ -41,60 +43,64 @@ object Backup { |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun backup(context: Context, uri: Uri?) { |
|
|
|
suspend fun backup(context: Context, uri: Uri?) { |
|
|
|
App.db.bookDao().allBooks.let { |
|
|
|
withContext(IO) { |
|
|
|
if (it.isNotEmpty()) { |
|
|
|
App.db.bookDao().allBooks.let { |
|
|
|
val json = GSON.toJson(it) |
|
|
|
if (it.isNotEmpty()) { |
|
|
|
FileHelp.getFile(backupPath + File.separator + "bookshelf.json").writeText(json) |
|
|
|
val json = GSON.toJson(it) |
|
|
|
|
|
|
|
FileHelp.getFile(backupPath + File.separator + "bookshelf.json").writeText(json) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
App.db.bookGroupDao().all().let { |
|
|
|
App.db.bookGroupDao().all().let { |
|
|
|
if (it.isNotEmpty()) { |
|
|
|
if (it.isNotEmpty()) { |
|
|
|
val json = GSON.toJson(it) |
|
|
|
val json = GSON.toJson(it) |
|
|
|
FileHelp.getFile(backupPath + File.separator + "bookGroup.json").writeText(json) |
|
|
|
FileHelp.getFile(backupPath + File.separator + "bookGroup.json").writeText(json) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
App.db.bookSourceDao().all.let { |
|
|
|
App.db.bookSourceDao().all.let { |
|
|
|
if (it.isNotEmpty()) { |
|
|
|
if (it.isNotEmpty()) { |
|
|
|
val json = GSON.toJson(it) |
|
|
|
val json = GSON.toJson(it) |
|
|
|
FileHelp.getFile(backupPath + File.separator + "bookSource.json") |
|
|
|
FileHelp.getFile(backupPath + File.separator + "bookSource.json").writeText(json) |
|
|
|
.writeText(json) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
App.db.rssSourceDao().all.let { |
|
|
|
App.db.rssSourceDao().all.let { |
|
|
|
if (it.isNotEmpty()) { |
|
|
|
if (it.isNotEmpty()) { |
|
|
|
val json = GSON.toJson(it) |
|
|
|
val json = GSON.toJson(it) |
|
|
|
FileHelp.getFile(backupPath + File.separator + "rssSource.json").writeText(json) |
|
|
|
FileHelp.getFile(backupPath + File.separator + "rssSource.json").writeText(json) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
App.db.replaceRuleDao().all.let { |
|
|
|
App.db.replaceRuleDao().all.let { |
|
|
|
if (it.isNotEmpty()) { |
|
|
|
if (it.isNotEmpty()) { |
|
|
|
val json = GSON.toJson(it) |
|
|
|
val json = GSON.toJson(it) |
|
|
|
FileHelp.getFile(backupPath + File.separator + "replaceRule.json") |
|
|
|
FileHelp.getFile(backupPath + File.separator + "replaceRule.json").writeText(json) |
|
|
|
.writeText(json) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
GSON.toJson(ReadBookConfig.configList)?.let { |
|
|
|
GSON.toJson(ReadBookConfig.configList)?.let { |
|
|
|
FileHelp.getFile(backupPath + File.separator + ReadBookConfig.readConfigFileName) |
|
|
|
FileHelp.getFile(backupPath + File.separator + ReadBookConfig.readConfigFileName) |
|
|
|
.writeText(it) |
|
|
|
.writeText(it) |
|
|
|
} |
|
|
|
} |
|
|
|
Preferences.getSharedPreferences(App.INSTANCE, backupPath, "config")?.let { sp -> |
|
|
|
Preferences.getSharedPreferences(App.INSTANCE, backupPath, "config")?.let { sp -> |
|
|
|
val edit = sp.edit() |
|
|
|
val edit = sp.edit() |
|
|
|
App.INSTANCE.defaultSharedPreferences.all.map { |
|
|
|
App.INSTANCE.defaultSharedPreferences.all.map { |
|
|
|
when (val value = it.value) { |
|
|
|
when (val value = it.value) { |
|
|
|
is Int -> edit.putInt(it.key, value) |
|
|
|
is Int -> edit.putInt(it.key, value) |
|
|
|
is Boolean -> edit.putBoolean(it.key, value) |
|
|
|
is Boolean -> edit.putBoolean(it.key, value) |
|
|
|
is Long -> edit.putLong(it.key, value) |
|
|
|
is Long -> edit.putLong(it.key, value) |
|
|
|
is Float -> edit.putFloat(it.key, value) |
|
|
|
is Float -> edit.putFloat(it.key, value) |
|
|
|
is String -> edit.putString(it.key, value) |
|
|
|
is String -> edit.putString(it.key, value) |
|
|
|
else -> Unit |
|
|
|
else -> Unit |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
edit.commit() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
WebDavHelp.backUpWebDav(backupPath) |
|
|
|
|
|
|
|
if (uri != null) { |
|
|
|
|
|
|
|
copyBackup(context, uri) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
copyBackup() |
|
|
|
} |
|
|
|
} |
|
|
|
edit.commit() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
WebDavHelp.backUpWebDav(backupPath) |
|
|
|
|
|
|
|
if (uri != null) { |
|
|
|
|
|
|
|
copyBackup(context, uri) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
copyBackup() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|