[go: nahoru, domu]

Skip to content

Commit

Permalink
Fix file not found error of relative path of voice package
Browse files Browse the repository at this point in the history
  • Loading branch information
izhangzhihao committed Jul 23, 2020
1 parent dbc277b commit 1f64343
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
12 changes: 12 additions & 0 deletions src/main/kotlin/com/github/izhangzhihao/rainbow/fart/FileUtil.kt
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class RainbowFartTypedHandler(originalHandler: TypedActionHandler) : TypedAction
private fun playVoice(voices: List<String>) {
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())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -44,8 +45,8 @@ class ResourcesLoader : StartupActivity {
val contributes: List<Contribute> =
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<Contributes>(contText).contributes
} else {
val contText = ResourcesLoader::class.java.getResource("/build-in-voice-chinese/contributes.json").readText()
Expand Down Expand Up @@ -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<String>,
val author: String, val gender: String, val locale: String = "zh", val contributes: List<Contribute>?)
val version: String = "1.0.0", val description: String, val languages: List<String>,
val author: String = "No one", val gender: String, val locale: String = "zh", val contributes: List<Contribute>?)

data class Contribute(val keywords: List<String>, val voices: List<String>)

Expand Down

0 comments on commit 1f64343

Please sign in to comment.