|
|
@ -22,40 +22,36 @@ import kotlinx.coroutines.withContext |
|
|
|
import splitties.init.appCtx |
|
|
|
import splitties.init.appCtx |
|
|
|
import java.io.File |
|
|
|
import java.io.File |
|
|
|
import java.io.FileInputStream |
|
|
|
import java.io.FileInputStream |
|
|
|
|
|
|
|
import java.io.FileOutputStream |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
object Restore { |
|
|
|
object Restore { |
|
|
|
|
|
|
|
|
|
|
|
suspend fun restore(context: Context, path: String) { |
|
|
|
suspend fun restore(context: Context, path: String) { |
|
|
|
withContext(IO) { |
|
|
|
kotlin.runCatching { |
|
|
|
if (path.isContentScheme()) { |
|
|
|
if (path.isContentScheme()) { |
|
|
|
DocumentFile.fromTreeUri(context, Uri.parse(path))?.listFiles()?.forEach { doc -> |
|
|
|
DocumentFile.fromTreeUri(context, Uri.parse(path))?.listFiles()?.forEach { doc -> |
|
|
|
for (fileName in Backup.backupFileNames) { |
|
|
|
if (Backup.backupFileNames.contains(doc.name)) { |
|
|
|
if (doc.name == fileName) { |
|
|
|
context.contentResolver.openInputStream(doc.uri)?.use { inputStream -> |
|
|
|
DocumentUtils.readText(context, doc.uri).let { |
|
|
|
val file = File("${Backup.backupPath}${File.separator}${doc.name}") |
|
|
|
FileUtils.createFileIfNotExist("${Backup.backupPath}${File.separator}$fileName") |
|
|
|
FileOutputStream(file).use { outputStream -> |
|
|
|
.writeText(it) |
|
|
|
inputStream.copyTo(outputStream) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
try { |
|
|
|
val dir = File(path) |
|
|
|
val file = File(path) |
|
|
|
|
|
|
|
for (fileName in Backup.backupFileNames) { |
|
|
|
for (fileName in Backup.backupFileNames) { |
|
|
|
file.getFile(fileName).let { |
|
|
|
val file = dir.getFile(fileName) |
|
|
|
if (it.exists()) { |
|
|
|
if (file.exists()) { |
|
|
|
it.copyTo( |
|
|
|
val target = File("${Backup.backupPath}${File.separator}$fileName") |
|
|
|
FileUtils.createFileIfNotExist("${Backup.backupPath}${File.separator}$fileName"), |
|
|
|
file.copyTo(target, true) |
|
|
|
true |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} catch (e: Exception) { |
|
|
|
|
|
|
|
e.printOnDebug() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}.onFailure { |
|
|
|
|
|
|
|
AppLog.put("", it) |
|
|
|
} |
|
|
|
} |
|
|
|
restoreDatabase() |
|
|
|
restoreDatabase() |
|
|
|
restoreConfig() |
|
|
|
restoreConfig() |
|
|
@ -129,7 +125,7 @@ object Restore { |
|
|
|
ThemeConfig.upConfig() |
|
|
|
ThemeConfig.upConfig() |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (e: Exception) { |
|
|
|
} catch (e: Exception) { |
|
|
|
e.printOnDebug() |
|
|
|
AppLog.put("恢复主题出错\n${e.localizedMessage}", e) |
|
|
|
} |
|
|
|
} |
|
|
|
if (!BackupConfig.ignoreReadConfig) { |
|
|
|
if (!BackupConfig.ignoreReadConfig) { |
|
|
|
//恢复阅读界面配置 |
|
|
|
//恢复阅读界面配置 |
|
|
@ -142,7 +138,7 @@ object Restore { |
|
|
|
ReadBookConfig.initConfigs() |
|
|
|
ReadBookConfig.initConfigs() |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (e: Exception) { |
|
|
|
} catch (e: Exception) { |
|
|
|
e.printOnDebug() |
|
|
|
AppLog.put("恢复阅读界面出错\n${e.localizedMessage}", e) |
|
|
|
} |
|
|
|
} |
|
|
|
try { |
|
|
|
try { |
|
|
|
val file = |
|
|
|
val file = |
|
|
@ -153,7 +149,7 @@ object Restore { |
|
|
|
ReadBookConfig.initShareConfig() |
|
|
|
ReadBookConfig.initShareConfig() |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (e: Exception) { |
|
|
|
} catch (e: Exception) { |
|
|
|
e.printOnDebug() |
|
|
|
AppLog.put("恢复阅读界面出错\n${e.localizedMessage}", e) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
Preferences.getSharedPreferences(appCtx, path, "config")?.all?.let { map -> |
|
|
|
Preferences.getSharedPreferences(appCtx, path, "config")?.all?.let { map -> |
|
|
|