attempt to not overwrite settings file

This commit is contained in:
Finnley Somdahl 2024-02-02 09:33:55 -06:00
parent 9358f86d43
commit cd96b6ab06

View file

@ -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? { 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 { return try {
val gson = Gson() val gson = Gson()
val json = gson.toJson(map) val json = gson.toJson(map)
file.writeText(json) file.writeText(json)
scanFile(file.absolutePath, context) 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 file
} catch (e: Exception) { } catch (e: Exception) {
snackString("Failed to save settings: ${e.localizedMessage}") snackString("Failed to save settings: ${e.localizedMessage}")