CORPRIV-661: Refactor code for guaranteeing a .zip extension.

This commit is contained in:
Chris Rankin 2017-02-20 15:49:13 +00:00
parent 0f73b68d39
commit 31843bbac8

View File

@ -34,11 +34,7 @@ class ProfileController : Controller() {
}
fun saveProfile(): Boolean {
var target = chooser.showSaveDialog(null) ?: return false
if (target.extension.isEmpty()) {
target = File(target.parent, target.name + ".zip")
}
val target = forceExtension(chooser.showSaveDialog(null) ?: return false, ".zip")
log.info("Save profile as: $target")
val configs = nodeController.activeNodes
@ -54,6 +50,10 @@ class ProfileController : Controller() {
return true
}
private fun forceExtension(target: File, ext: String): File {
return if (target.extension.isEmpty()) File(target.parent, target.name + ext) else target
}
fun openProfile(): List<NodeConfig>? {
val chosen = chooser.showOpenDialog(null) ?: return null
log.info("Selected profile: $chosen")