|
|
@ -52,7 +52,9 @@ object Backup : BackupRestore() { |
|
|
|
if (lastBackup + TimeUnit.DAYS.toMillis(1) < System.currentTimeMillis()) { |
|
|
|
if (lastBackup + TimeUnit.DAYS.toMillis(1) < System.currentTimeMillis()) { |
|
|
|
Coroutine.async { |
|
|
|
Coroutine.async { |
|
|
|
if (!AppWebDav.hasBackUp()) { |
|
|
|
if (!AppWebDav.hasBackUp()) { |
|
|
|
backup(context, context.getPrefString(PreferKey.backupPath) ?: "", true) |
|
|
|
backup(context, context.getPrefString(PreferKey.backupPath), true) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
context.putPrefLong(PreferKey.lastBackup, System.currentTimeMillis()) |
|
|
|
} |
|
|
|
} |
|
|
|
}.onError { |
|
|
|
}.onError { |
|
|
|
AppLog.put("备份出错\n${it.localizedMessage}", it) |
|
|
|
AppLog.put("备份出错\n${it.localizedMessage}", it) |
|
|
@ -61,7 +63,7 @@ object Backup : BackupRestore() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
suspend fun backup(context: Context, path: String, isAuto: Boolean = false) { |
|
|
|
suspend fun backup(context: Context, path: String?, isAuto: Boolean = false) { |
|
|
|
context.putPrefLong(PreferKey.lastBackup, System.currentTimeMillis()) |
|
|
|
context.putPrefLong(PreferKey.lastBackup, System.currentTimeMillis()) |
|
|
|
withContext(IO) { |
|
|
|
withContext(IO) { |
|
|
|
FileUtils.deleteFile(backupPath) |
|
|
|
FileUtils.deleteFile(backupPath) |
|
|
@ -105,12 +107,14 @@ object Backup : BackupRestore() { |
|
|
|
edit.commit() |
|
|
|
edit.commit() |
|
|
|
} |
|
|
|
} |
|
|
|
AppWebDav.backUpWebDav(backupPath) |
|
|
|
AppWebDav.backUpWebDav(backupPath) |
|
|
|
if (path.isContentScheme()) { |
|
|
|
when { |
|
|
|
copyBackup(context, Uri.parse(path), isAuto) |
|
|
|
path.isNullOrBlank() -> { |
|
|
|
} else { |
|
|
|
|
|
|
|
if (path.isEmpty()) { |
|
|
|
|
|
|
|
copyBackup(context.getExternalFilesDir(null)!!, false) |
|
|
|
copyBackup(context.getExternalFilesDir(null)!!, false) |
|
|
|
} else { |
|
|
|
} |
|
|
|
|
|
|
|
path.isContentScheme() -> { |
|
|
|
|
|
|
|
copyBackup(context, Uri.parse(path), isAuto) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else -> { |
|
|
|
copyBackup(File(path), isAuto) |
|
|
|
copyBackup(File(path), isAuto) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|