From e1c1f426688ec7c1133f54b3e5952485d0e22807 Mon Sep 17 00:00:00 2001 From: beepbeat Date: Tue, 8 Aug 2017 17:40:13 +0200 Subject: [PATCH] Stuff! --- src/ConfigHandler.kt | 17 ++++++++++------- src/HexChatLogHandler.kt | 5 ++++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/ConfigHandler.kt b/src/ConfigHandler.kt index bd2a832..80d243a 100644 --- a/src/ConfigHandler.kt +++ b/src/ConfigHandler.kt @@ -1,13 +1,15 @@ import org.apache.commons.io.IOUtils import java.io.File import java.io.PrintWriter +import java.nio.charset.Charset val configFile = File("config") val config = Config() + class Config{ - var authkey : String = "" - var LogPath : String = "" - var ClientType : String = "" + var authkey: String = "" + var LogPath: String = "" + var ClientType: String = "" } @@ -16,14 +18,15 @@ fun initConfig(){ } fun readConfig(){ - val lines : MutableList = IOUtils.readLines(configFile.inputStream()) as MutableList + val lines : MutableList = IOUtils.readLines(configFile.inputStream(), Charset.defaultCharset()) for (str in lines){ if (str.trim().toLowerCase().startsWith("authkey: ")){ config.authkey = str.trim().toLowerCase().split("authkey: ")[1]} if (str.trim().toLowerCase().startsWith("logpath: ")){ config.LogPath = str.trim().toLowerCase().split("logpath: ")[1]} - if (str.trim().toLowerCase().startsWith("cleinttype: ")){ - config.ClientType = str.trim().toLowerCase().split("clienttype: ")[1]} + if (str.trim().toLowerCase().startsWith("clienttype: ")){ + config.ClientType = str.trim().toLowerCase().split("clienttype: ")[1] + } } } @@ -34,7 +37,7 @@ fun saveConfig(){ tmp.add("authkey: " + config.authkey) tmp.add("logpath: " + config.LogPath) tmp.add("clienttype: " + config.ClientType) - IOUtils.writeLines(tmp, null, stream) + IOUtils.writeLines(tmp, null, stream, Charset.defaultCharset()) stream.flush() stream.close() } diff --git a/src/HexChatLogHandler.kt b/src/HexChatLogHandler.kt index 31f1a94..9b38e1c 100644 --- a/src/HexChatLogHandler.kt +++ b/src/HexChatLogHandler.kt @@ -22,7 +22,7 @@ class listener : TailerListenerAdapter(){ override fun handle(l: String?) { var valid : Boolean = false supportedClients.values().forEach {if (it.toString() == config.ClientType){valid = true} } - if (config.ClientType.isNullOrBlank()) throw IllegalStateException("empty clienttype") + if (config.ClientType.isNullOrBlank()) config.ClientType = "hexchat" //throw IllegalStateException("empty clienttype") if (!valid) throw IllegalStateException("clientType not supported") this.javaClass.getMethod(config.ClientType.toLowerCase(), String::class.java).invoke(this, l) } @@ -227,6 +227,9 @@ class listener : TailerListenerAdapter(){ if (valid){ret.add(res); break} } } + if (ret.isEmpty()){ + return Rescue("", System(""), "", -1, "", false) + } return ret[0] }