Skip to content

Commit

Permalink
fix: fixed crash caused by old presets created with version 1.4.2 or …
Browse files Browse the repository at this point in the history
…older
  • Loading branch information
timschneeb committed Mar 19, 2023
1 parent 6ca51d4 commit a76b09a
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import me.timschneeberger.rootlessjamesdsp.preference.FileLibraryPreference
import me.timschneeberger.rootlessjamesdsp.utils.extensions.ContextExtensions.sendLocalBroadcast
import timber.log.Timber
import java.io.File
import java.io.FileNotFoundException
import java.io.FileReader
import java.io.IOException
import java.lang.NumberFormatException

abstract class JamesDspBaseEngine(val context: Context, val callbacks: JamesDspWrapper.JamesDspCallbacks? = null) : AutoCloseable {
Expand Down Expand Up @@ -169,9 +171,9 @@ abstract class JamesDspBaseEngine(val context: Context, val callbacks: JamesDspW
return true /* non-critical */
}

return FileReader(fullPath).use {
return safeFileReader(fullPath)?.use {
setVdcInternal(enable, it.readText())
}
} ?: false
}

fun setConvolver(enable: Boolean, impulseResponsePath: String, optimizationMode: Int, waveEditStr: String): Boolean
Expand Down Expand Up @@ -259,12 +261,21 @@ abstract class JamesDspBaseEngine(val context: Context, val callbacks: JamesDspW
return setLiveprogInternal(false, "", "")
}

return FileReader(fullPath).use {
return safeFileReader(fullPath)?.use {
val name = File(fullPath).name
setLiveprogInternal(enable, name, it.readText())
}
} ?: false
}

private fun safeFileReader(path: String) =
try { FileReader(path) }
catch (ex: FileNotFoundException) {
/* Exception may occur when old presets created with version <1.4.3 are swapped
between root, rootless, debug, or release builds due to path name differences. */
Timber.w(ex)
null
}

// Effect config
abstract fun setOutputControl(threshold: Float, release: Float, postGain: Float): Boolean
abstract fun setCompressor(enable: Boolean, maxAttack: Float, maxRelease: Float, adaptSpeed: Float): Boolean
Expand Down

0 comments on commit a76b09a

Please sign in to comment.