Просмотр исходного кода

Merge branch 'gedoor:master' into rar7z

ag2s20150909 3 лет назад
Родитель
Сommit
4c65c1edfd
1 измененных файлов с 6 добавлено и 10 удалено
  1. 6 10
      app/src/main/java/io/legado/app/help/storage/Restore.kt

+ 6 - 10
app/src/main/java/io/legado/app/help/storage/Restore.kt

@@ -37,7 +37,7 @@ object Restore {
         kotlin.runCatching {
         kotlin.runCatching {
             FileUtils.delete(Backup.backupPath)
             FileUtils.delete(Backup.backupPath)
             if (uri.isContentScheme()) {
             if (uri.isContentScheme()) {
-                DocumentFile.fromTreeUri(context, uri)?.openInputStream()!!.use {
+                DocumentFile.fromSingleUri(context, uri)!!.openInputStream()!!.use {
                     ZipUtils.unZipToPath(it, Backup.backupPath)
                     ZipUtils.unZipToPath(it, Backup.backupPath)
                 }
                 }
             } else {
             } else {
@@ -127,8 +127,7 @@ object Restore {
     suspend fun restoreConfig(path: String = Backup.backupPath) {
     suspend fun restoreConfig(path: String = Backup.backupPath) {
         withContext(IO) {
         withContext(IO) {
             try {
             try {
-                val file =
-                    FileUtils.createFileIfNotExist("$path${File.separator}${DirectLinkUpload.ruleFileName}")
+                val file = File(path, DirectLinkUpload.ruleFileName)
                 if (file.exists()) {
                 if (file.exists()) {
                     val json = file.readText()
                     val json = file.readText()
                     ACache.get(cacheDir = false).put(DirectLinkUpload.ruleFileName, json)
                     ACache.get(cacheDir = false).put(DirectLinkUpload.ruleFileName, json)
@@ -137,8 +136,7 @@ object Restore {
                 AppLog.put("直链上传出错\n${e.localizedMessage}", e)
                 AppLog.put("直链上传出错\n${e.localizedMessage}", e)
             }
             }
             try {
             try {
-                val file =
-                    FileUtils.createFileIfNotExist("$path${File.separator}${ThemeConfig.configFileName}")
+                val file = File(path, ThemeConfig.configFileName)
                 if (file.exists()) {
                 if (file.exists()) {
                     FileUtils.delete(ThemeConfig.configFilePath)
                     FileUtils.delete(ThemeConfig.configFilePath)
                     file.copyTo(File(ThemeConfig.configFilePath))
                     file.copyTo(File(ThemeConfig.configFilePath))
@@ -150,8 +148,7 @@ object Restore {
             if (!BackupConfig.ignoreReadConfig) {
             if (!BackupConfig.ignoreReadConfig) {
                 //恢复阅读界面配置
                 //恢复阅读界面配置
                 try {
                 try {
-                    val file =
-                        FileUtils.createFileIfNotExist("$path${File.separator}${ReadBookConfig.configFileName}")
+                    val file = File(path, ReadBookConfig.configFileName)
                     if (file.exists()) {
                     if (file.exists()) {
                         FileUtils.delete(ReadBookConfig.configFilePath)
                         FileUtils.delete(ReadBookConfig.configFilePath)
                         file.copyTo(File(ReadBookConfig.configFilePath))
                         file.copyTo(File(ReadBookConfig.configFilePath))
@@ -161,8 +158,7 @@ object Restore {
                     AppLog.put("恢复阅读界面出错\n${e.localizedMessage}", e)
                     AppLog.put("恢复阅读界面出错\n${e.localizedMessage}", e)
                 }
                 }
                 try {
                 try {
-                    val file =
-                        FileUtils.createFileIfNotExist("$path${File.separator}${ReadBookConfig.shareConfigFileName}")
+                    val file = File(path, ReadBookConfig.shareConfigFileName)
                     if (file.exists()) {
                     if (file.exists()) {
                         FileUtils.delete(ReadBookConfig.shareConfigFilePath)
                         FileUtils.delete(ReadBookConfig.shareConfigFilePath)
                         file.copyTo(File(ReadBookConfig.shareConfigFilePath))
                         file.copyTo(File(ReadBookConfig.shareConfigFilePath))
@@ -207,7 +203,7 @@ object Restore {
 
 
     private inline fun <reified T> fileToListT(path: String, fileName: String): List<T>? {
     private inline fun <reified T> fileToListT(path: String, fileName: String): List<T>? {
         try {
         try {
-            val file = File(path + File.separator + fileName)
+            val file = File(path, fileName)
             if (file.exists()) {
             if (file.exists()) {
                 FileInputStream(file).use {
                 FileInputStream(file).use {
                     return GSON.fromJsonArray<T>(it).getOrThrow()
                     return GSON.fromJsonArray<T>(it).getOrThrow()