diff --git a/src/main/scala/ocelot/desktop/Settings.scala b/src/main/scala/ocelot/desktop/Settings.scala index d04b407..e0bcf29 100644 --- a/src/main/scala/ocelot/desktop/Settings.scala +++ b/src/main/scala/ocelot/desktop/Settings.scala @@ -5,11 +5,9 @@ import ocelot.desktop.Settings.ExtendedConfig import ocelot.desktop.util.{Logging, SettingsData} import org.apache.commons.lang3.SystemUtils -import java.io.InputStream import java.nio.charset.StandardCharsets import java.nio.file.{Files, Path} import java.util -import scala.io.{Codec, Source} class Settings(val config: Config) extends SettingsData { // TODO: refactor this mess (having to declare every field 3 times is extremely error-prone) @@ -137,39 +135,18 @@ object Settings extends Logging { def get: Settings = settings def load(path: Path): Unit = { - import java.lang.System.{lineSeparator => EOL} - if (Files.exists(path)) { - var stream: InputStream = null - try { - stream = Files.newInputStream(path) - val source = Source.fromInputStream(stream)(Codec.UTF8) - val plain = source.getLines().mkString("", EOL, EOL) - val config = ConfigFactory.parseString(plain) - settings = new Settings(config) - source.close() - + settings = new Settings(ConfigFactory.parseFile(path.toFile)) logger.info(s"Loaded Ocelot Desktop configuration from: $path") - return } catch { - case _: Throwable => - logger.info(s"Failed to parse $path, using default Ocelot Desktop configuration.") - } finally { - if (stream != null) - stream.close() + case t: Throwable => logger.error(s"Failed to parse $path!", t) } } - val defaults = { - val in = getClass.getResourceAsStream("/ocelot/desktop/ocelot.conf") - val config = Source.fromInputStream(in)(Codec.UTF8).getLines().mkString("", EOL, EOL) - in.close() - ConfigFactory.parseString(config) - } - - settings = new Settings(defaults) + logger.info(s"Using default Ocelot Desktop configuration...") + settings = new Settings(ConfigFactory.parseResources("/ocelot/desktop/ocelot.conf")) } def save(path: Path): Unit = {