|
|
@ -3,12 +3,12 @@ package io.legado.app.help.storage |
|
|
|
import android.content.Context |
|
|
|
import android.content.Context |
|
|
|
import android.net.Uri |
|
|
|
import android.net.Uri |
|
|
|
import android.util.Log |
|
|
|
import android.util.Log |
|
|
|
|
|
|
|
import androidx.documentfile.provider.DocumentFile |
|
|
|
import com.jayway.jsonpath.Configuration |
|
|
|
import com.jayway.jsonpath.Configuration |
|
|
|
import com.jayway.jsonpath.JsonPath |
|
|
|
import com.jayway.jsonpath.JsonPath |
|
|
|
import com.jayway.jsonpath.Option |
|
|
|
import com.jayway.jsonpath.Option |
|
|
|
import com.jayway.jsonpath.ParseContext |
|
|
|
import com.jayway.jsonpath.ParseContext |
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.R |
|
|
|
|
|
|
|
import io.legado.app.constant.AppConst |
|
|
|
import io.legado.app.constant.AppConst |
|
|
|
import io.legado.app.data.entities.* |
|
|
|
import io.legado.app.data.entities.* |
|
|
|
import io.legado.app.help.FileHelp |
|
|
|
import io.legado.app.help.FileHelp |
|
|
@ -20,9 +20,7 @@ import kotlinx.coroutines.GlobalScope |
|
|
|
import kotlinx.coroutines.launch |
|
|
|
import kotlinx.coroutines.launch |
|
|
|
import kotlinx.coroutines.withContext |
|
|
|
import kotlinx.coroutines.withContext |
|
|
|
import org.jetbrains.anko.defaultSharedPreferences |
|
|
|
import org.jetbrains.anko.defaultSharedPreferences |
|
|
|
import org.jetbrains.anko.doAsync |
|
|
|
|
|
|
|
import org.jetbrains.anko.toast |
|
|
|
import org.jetbrains.anko.toast |
|
|
|
import org.jetbrains.anko.uiThread |
|
|
|
|
|
|
|
import java.io.File |
|
|
|
import java.io.File |
|
|
|
|
|
|
|
|
|
|
|
object Restore { |
|
|
|
object Restore { |
|
|
@ -34,12 +32,24 @@ object Restore { |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun restore(context: Context, uri: Uri) { |
|
|
|
suspend fun restore(context: Context, uri: Uri) { |
|
|
|
|
|
|
|
withContext(IO) { |
|
|
|
|
|
|
|
DocumentFile.fromTreeUri(context, uri)?.listFiles()?.forEach { doc -> |
|
|
|
|
|
|
|
for (fileName in Backup.backupFileNames) { |
|
|
|
|
|
|
|
if (doc.name == fileName) { |
|
|
|
|
|
|
|
DocumentUtils.readText(context, doc.uri)?.let { |
|
|
|
|
|
|
|
FileHelp.getFile(Backup.backupPath + File.separator + fileName) |
|
|
|
|
|
|
|
.writeText(it) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
restore(Backup.defaultPath) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun restore(path: String = Backup.defaultPath) { |
|
|
|
suspend fun restore(path: String) { |
|
|
|
doAsync { |
|
|
|
withContext(IO) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
val file = FileHelp.getFile(path + File.separator + "bookshelf.json") |
|
|
|
val file = FileHelp.getFile(path + File.separator + "bookshelf.json") |
|
|
|
val json = file.readText() |
|
|
|
val json = file.readText() |
|
|
@ -109,7 +119,6 @@ object Restore { |
|
|
|
} |
|
|
|
} |
|
|
|
edit.commit() |
|
|
|
edit.commit() |
|
|
|
} |
|
|
|
} |
|
|
|
uiThread { App.INSTANCE.toast(R.string.restore_success) } |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|