|
|
|
@ -52,7 +52,9 @@ object Backup : BackupRestore() { |
|
|
|
|
if (lastBackup + TimeUnit.DAYS.toMillis(1) < System.currentTimeMillis()) { |
|
|
|
|
Coroutine.async { |
|
|
|
|
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 { |
|
|
|
|
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()) |
|
|
|
|
withContext(IO) { |
|
|
|
|
FileUtils.deleteFile(backupPath) |
|
|
|
@ -105,12 +107,14 @@ object Backup : BackupRestore() { |
|
|
|
|
edit.commit() |
|
|
|
|
} |
|
|
|
|
AppWebDav.backUpWebDav(backupPath) |
|
|
|
|
if (path.isContentScheme()) { |
|
|
|
|
copyBackup(context, Uri.parse(path), isAuto) |
|
|
|
|
} else { |
|
|
|
|
if (path.isEmpty()) { |
|
|
|
|
when { |
|
|
|
|
path.isNullOrBlank() -> { |
|
|
|
|
copyBackup(context.getExternalFilesDir(null)!!, false) |
|
|
|
|
} else { |
|
|
|
|
} |
|
|
|
|
path.isContentScheme() -> { |
|
|
|
|
copyBackup(context, Uri.parse(path), isAuto) |
|
|
|
|
} |
|
|
|
|
else -> { |
|
|
|
|
copyBackup(File(path), isAuto) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|