Fixed renamed file

This commit is contained in:
Pupil
2020-02-09 18:13:16 +09:00
parent e810abe33a
commit e551a40d08
5 changed files with 28 additions and 8 deletions

View File

@@ -150,7 +150,12 @@ class SettingsFragment :
"backup" -> {
File(ContextCompat.getDataDir(context), "favorites.json").copyTo(
context,
getDownloadDirectory(context).createFile("null", "favorites.json")!!
getDownloadDirectory(context).let {
if (it.findFile("favorites.json") != null)
it
else
it.createFile("null", "favorites.json")!!
}
)
Snackbar.make(this@SettingsFragment.listView, R.string.settings_backup_snackbar, Snackbar.LENGTH_LONG)

View File

@@ -206,7 +206,12 @@ class Cache(context: Context) : ContextWrapper(context) {
if (!Regex("""^[0-9]+.+$""").matches(name))
throw IllegalArgumentException("File name is not a number")
cache.createFile("null", name)?.writeBytes(this, data)
cache.let {
if (it.findFile(name) != null)
it
else
it.createFile("null", name)
}?.writeBytes(this, data)
}
fun moveToDownload(galleryID: Int) {

View File

@@ -104,12 +104,17 @@ fun DocumentFile.copyRecursively(
if (!exists())
throw Exception("The source file doesn't exist.")
if (this.isFile)
target.createFile("null", name!!)!!.writeBytes(
if (this.isFile) {
target.let {
if (it.findFile(name!!) != null)
it
else
createFile("null", name!!)!!
}.writeBytes(
context,
readBytes(context)
)
else if (this.isDirectory) {
} else if (this.isDirectory) {
target.createDirectory(name!!).also { newTarget ->
listFiles().forEach { child ->
child.copyRecursively(context, newTarget!!)

View File

@@ -146,7 +146,12 @@ fun checkUpdate(context: AppCompatActivity, force: Boolean = false) {
}
CoroutineScope(Dispatchers.IO).launch io@{
val target = getDownloadDirectory(context)?.createFile("null", "Pupil.apk")!!
val target = getDownloadDirectory(context).let {
if (it.findFile("Pupil.apk") != null)
it
else
it.createFile("null", "Pupil.apk")!!
}
try {
URL(url).download(context, target) { progress, fileSize ->