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