diff --git a/src/main/kotlin/com/github/izhangzhihao/rainbow/fart/FileUtil.kt b/src/main/kotlin/com/github/izhangzhihao/rainbow/fart/FileUtil.kt new file mode 100644 index 0000000..994a916 --- /dev/null +++ b/src/main/kotlin/com/github/izhangzhihao/rainbow/fart/FileUtil.kt @@ -0,0 +1,12 @@ +package com.github.izhangzhihao.rainbow.fart + +import java.io.File + +fun resolvePath(path: String): File { + return if (path.startsWith("~")) { + val home = System.getProperty("user.home") + File(home + path.removePrefix("~")) + } else { + File(path) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/github/izhangzhihao/rainbow/fart/RainbowFartTypedHandler.kt b/src/main/kotlin/com/github/izhangzhihao/rainbow/fart/RainbowFartTypedHandler.kt index 91eaea8..e11d714 100644 --- a/src/main/kotlin/com/github/izhangzhihao/rainbow/fart/RainbowFartTypedHandler.kt +++ b/src/main/kotlin/com/github/izhangzhihao/rainbow/fart/RainbowFartTypedHandler.kt @@ -55,7 +55,7 @@ class RainbowFartTypedHandler(originalHandler: TypedActionHandler) : TypedAction private fun playVoice(voices: List) { val mp3Stream = if (RainbowFartSettings.instance.customVoicePackage != "") { - File(RainbowFartSettings.instance.customVoicePackage + File.separator + voices.random()).inputStream() + resolvePath(RainbowFartSettings.instance.customVoicePackage + File.separator + voices.random()).inputStream() } else { FartTypedHandler::class.java.getResourceAsStream("/build-in-voice-chinese/" + voices.random()) } diff --git a/src/main/kotlin/com/github/izhangzhihao/rainbow/fart/ResourcesLoader.kt b/src/main/kotlin/com/github/izhangzhihao/rainbow/fart/ResourcesLoader.kt index b679737..d54d6a3 100644 --- a/src/main/kotlin/com/github/izhangzhihao/rainbow/fart/ResourcesLoader.kt +++ b/src/main/kotlin/com/github/izhangzhihao/rainbow/fart/ResourcesLoader.kt @@ -28,9 +28,10 @@ class ResourcesLoader : StartupActivity { } else { RainbowFartSettings.isAppliedApplicationLevel = true } + val customVoicePackage = RainbowFartSettings.instance.customVoicePackage val current = - if (RainbowFartSettings.instance.customVoicePackage != "") { - File(RainbowFartSettings.instance.customVoicePackage + File.separator + "manifest.json").readText() + if (customVoicePackage != "") { + resolvePath(customVoicePackage + File.separator + "manifest.json").readText() } else { ResourcesLoader::class.java.getResource("/build-in-voice-chinese/manifest.json").readText() } @@ -44,8 +45,8 @@ class ResourcesLoader : StartupActivity { val contributes: List = if (manifest.contributes != null) { manifest.contributes - } else if (RainbowFartSettings.instance.customVoicePackage != "") { - val contText = File(RainbowFartSettings.instance.customVoicePackage + File.separator + "contributes.json").readText() + } else if (customVoicePackage != "") { + val contText = resolvePath(customVoicePackage + File.separator + "contributes.json").readText() mapper.readValue(contText).contributes } else { val contText = ResourcesLoader::class.java.getResource("/build-in-voice-chinese/contributes.json").readText() @@ -126,8 +127,8 @@ class ResourcesLoader : StartupActivity { data class Manifest(val name: String, @JsonProperty("display-name") val displayName: String, val avatar: String, @JsonProperty("avatar-dark") val avatarDark: String?, - val version: String?, val description: String, val languages: List, - val author: String, val gender: String, val locale: String = "zh", val contributes: List?) + val version: String = "1.0.0", val description: String, val languages: List, + val author: String = "No one", val gender: String, val locale: String = "zh", val contributes: List?) data class Contribute(val keywords: List, val voices: List)