Skip to content

Commit

Permalink
attempt to not overwrite settings file
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelonion committed Feb 2, 2024
1 parent 9358f86 commit cd96b6a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/src/main/java/ani/dantotsu/Functions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -602,13 +602,19 @@ fun savePrefsToDownloads(title: String, map: Map<String, *>, context: Context) {
}

fun savePrefs(map: Map<String, *>, 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}")
Expand Down

0 comments on commit cd96b6a

Please sign in to comment.