From 29449b8c14498e4816571b387a5f875f8411ca67 Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Wed, 27 Mar 2024 19:59:21 +0300 Subject: [PATCH] sync: better storage access for resources (fixes #3086) (#3315) Co-authored-by: dogi --- app/build.gradle | 4 ++-- .../org/ole/planet/myplanet/utilities/FileUtils.kt | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index d395454ace..ae97ee58fa 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1450 - versionName "0.14.50" + versionCode 1451 + versionName "0.14.51" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/utilities/FileUtils.kt b/app/src/main/java/org/ole/planet/myplanet/utilities/FileUtils.kt index d2b5d6d6b7..aa1fdbba76 100644 --- a/app/src/main/java/org/ole/planet/myplanet/utilities/FileUtils.kt +++ b/app/src/main/java/org/ole/planet/myplanet/utilities/FileUtils.kt @@ -57,30 +57,29 @@ object FileUtils { } private fun createFilePath(folder: String, filename: String): File { - val directory = File(folder) + val directory = File(MainApplication.context.getExternalFilesDir(null), folder) if (!directory.exists()) { try { if (!directory.mkdirs()) { - throw IOException("Failed to create directory: " + directory.absolutePath) + throw IOException("Failed to create directory: ${directory.absolutePath}") } } catch (e: IOException) { e.printStackTrace() - throw RuntimeException("Failed to create directory: " + directory.absolutePath, e) + throw RuntimeException("Failed to create directory: ${directory.absolutePath}", e) } } - Utilities.log("Return file $folder/$filename") return File(directory, filename) } @JvmStatic fun getSDPathFromUrl(url: String?): File { - return createFilePath(SD_PATH + "/" + getIdFromUrl(url), getFileNameFromUrl(url)) + return createFilePath("/ole/" + getIdFromUrl(url), getFileNameFromUrl(url)) } @JvmStatic fun checkFileExist(url: String?): Boolean { if (url.isNullOrEmpty()) return false - val f = createFilePath(SD_PATH + "/" + getIdFromUrl(url), getFileNameFromUrl(url)) + val f = getSDPathFromUrl(url) return f.exists() }