From cd96b6ab061c5327ae99e0de9327f430c727fbb4 Mon Sep 17 00:00:00 2001 From: Finnley Somdahl <87634197+rebelonion@users.noreply.github.com> Date: Fri, 2 Feb 2024 09:33:55 -0600 Subject: [PATCH] attempt to not overwrite settings file --- app/src/main/java/ani/dantotsu/Functions.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/ani/dantotsu/Functions.kt b/app/src/main/java/ani/dantotsu/Functions.kt index b9e5be2ab8..1e5d3ffcdf 100644 --- a/app/src/main/java/ani/dantotsu/Functions.kt +++ b/app/src/main/java/ani/dantotsu/Functions.kt @@ -602,13 +602,19 @@ fun savePrefsToDownloads(title: String, map: Map, context: Context) { } fun savePrefs(map: Map, path: String, title: String, context: Context): File? { - val file = File(path, "$title.ani") + var file = File(path, "$title.ani") + var counter = 1 + while (file.exists()) { + file = File(path, "${title}_${counter}.ani") + counter++ + } + return try { val gson = Gson() val json = gson.toJson(map) file.writeText(json) scanFile(file.absolutePath, context) - toast(String.format(context.getString(R.string.saved_to_path, path))) + toast(String.format(context.getString(R.string.saved_to_path, file.absolutePath))) file } catch (e: Exception) { snackString("Failed to save settings: ${e.localizedMessage}")