Use properties to set rootDir so that ConfigManager can use it
This commit is contained in:
@@ -18,8 +18,6 @@ import java.io.File
|
|||||||
* Manages app config.
|
* Manages app config.
|
||||||
*/
|
*/
|
||||||
open class ConfigManager {
|
open class ConfigManager {
|
||||||
private val dataRoot by lazy { AppDirsFactory.getInstance().getUserDataDir("Tachidesk", null, null)!! }
|
|
||||||
|
|
||||||
private val generatedModules = mutableMapOf<Class<out ConfigModule>, ConfigModule>()
|
private val generatedModules = mutableMapOf<Class<out ConfigModule>, ConfigModule>()
|
||||||
val config by lazy { loadConfigs() }
|
val config by lazy { loadConfigs() }
|
||||||
|
|
||||||
@@ -27,8 +25,6 @@ open class ConfigManager {
|
|||||||
val loadedModules: Map<Class<out ConfigModule>, ConfigModule>
|
val loadedModules: Map<Class<out ConfigModule>, ConfigModule>
|
||||||
get() = generatedModules
|
get() = generatedModules
|
||||||
|
|
||||||
open val appConfigFile: String = "$dataRoot/server.conf"
|
|
||||||
|
|
||||||
val logger = KotlinLogging.logger {}
|
val logger = KotlinLogging.logger {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,8 +47,8 @@ open class ConfigManager {
|
|||||||
|
|
||||||
//Load user config
|
//Load user config
|
||||||
val userConfig =
|
val userConfig =
|
||||||
File(appConfigFile).let{
|
File(System.getProperty("ir.armor.tachidesk.rootDir"), "server.conf").let {
|
||||||
ConfigFactory.parseFile(it)
|
ConfigFactory.parseFile(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
val config = ConfigFactory.empty()
|
val config = ConfigFactory.empty()
|
||||||
@@ -69,7 +65,7 @@ open class ConfigManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun registerModule(module: ConfigModule) {
|
fun registerModule(module: ConfigModule) {
|
||||||
generatedModules.put(module.javaClass, module)
|
generatedModules[module.javaClass] = module
|
||||||
}
|
}
|
||||||
|
|
||||||
fun registerModules(vararg modules: ConfigModule) {
|
fun registerModules(vararg modules: ConfigModule) {
|
||||||
|
|||||||
@@ -37,19 +37,21 @@ class ApplicationDirs(
|
|||||||
val mangaRoot = "$dataRoot/manga"
|
val mangaRoot = "$dataRoot/manga"
|
||||||
}
|
}
|
||||||
|
|
||||||
val serverConfig: ServerConfig by DI.global.instance()
|
val serverConfig: ServerConfig by lazy { GlobalConfigManager.module() }
|
||||||
|
|
||||||
val systemTray by lazy { systemTray() }
|
val systemTray by lazy { systemTray() }
|
||||||
|
|
||||||
val androidCompat by lazy { AndroidCompat() }
|
val androidCompat by lazy { AndroidCompat() }
|
||||||
|
|
||||||
fun applicationSetup(rootDir: String? = null, config: Config = GlobalConfigManager.config) {
|
fun applicationSetup(rootDir: String? = null) {
|
||||||
val dirs = if (rootDir != null) {
|
val dirs = if (rootDir != null) {
|
||||||
ApplicationDirs(rootDir)
|
ApplicationDirs(rootDir)
|
||||||
} else {
|
} else {
|
||||||
ApplicationDirs()
|
ApplicationDirs()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
System.setProperty("ir.armor.tachidesk.rootDir", dirs.dataRoot)
|
||||||
|
|
||||||
// make dirs we need
|
// make dirs we need
|
||||||
listOf(
|
listOf(
|
||||||
dirs.dataRoot,
|
dirs.dataRoot,
|
||||||
@@ -60,10 +62,13 @@ fun applicationSetup(rootDir: String? = null, config: Config = GlobalConfigManag
|
|||||||
File(it).mkdirs()
|
File(it).mkdirs()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GlobalConfigManager.registerModule(
|
||||||
|
ServerConfig.register(GlobalConfigManager.config)
|
||||||
|
)
|
||||||
|
|
||||||
// Application dirs
|
// Application dirs
|
||||||
DI.global.addImport(DI.Module("Server") {
|
DI.global.addImport(DI.Module("Server") {
|
||||||
bind<ApplicationDirs>() with singleton { dirs }
|
bind<ApplicationDirs>() with singleton { dirs }
|
||||||
bind<ServerConfig>() with singleton { ServerConfig.register(config) }
|
|
||||||
})
|
})
|
||||||
// Load config API
|
// Load config API
|
||||||
DI.global.addImport(ConfigKodeinModule().create())
|
DI.global.addImport(ConfigKodeinModule().create())
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class TestExtensions {
|
|||||||
@BeforeAll
|
@BeforeAll
|
||||||
fun setup() {
|
fun setup() {
|
||||||
val dataRoot = File("tmp/TestDesk").absolutePath
|
val dataRoot = File("tmp/TestDesk").absolutePath
|
||||||
applicationSetup(dataRoot, loadConfigs(dataRoot))
|
applicationSetup(dataRoot)
|
||||||
setLoggingEnabled(false)
|
setLoggingEnabled(false)
|
||||||
runBlocking {
|
runBlocking {
|
||||||
extensions = getExtensionList()
|
extensions = getExtensionList()
|
||||||
|
|||||||
@@ -1,40 +1,8 @@
|
|||||||
package ir.armor.tachidesk
|
package ir.armor.tachidesk
|
||||||
|
|
||||||
import ch.qos.logback.classic.Level
|
import ch.qos.logback.classic.Level
|
||||||
import com.typesafe.config.Config
|
|
||||||
import com.typesafe.config.ConfigFactory
|
|
||||||
import com.typesafe.config.ConfigRenderOptions
|
|
||||||
import mu.KotlinLogging
|
import mu.KotlinLogging
|
||||||
import org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load configs
|
|
||||||
*/
|
|
||||||
fun loadConfigs(dataRoot: String): Config {
|
|
||||||
val logger = KotlinLogging.logger {}
|
|
||||||
//Load reference configs
|
|
||||||
val compatConfig = ConfigFactory.parseResources("compat-reference.conf")
|
|
||||||
val serverConfig = ConfigFactory.parseResources("server-reference.conf")
|
|
||||||
|
|
||||||
//Load user config
|
|
||||||
val userConfig =
|
|
||||||
File(dataRoot, "server.conf").let {
|
|
||||||
ConfigFactory.parseFile(it)
|
|
||||||
}
|
|
||||||
|
|
||||||
val config = ConfigFactory.empty()
|
|
||||||
.withFallback(userConfig)
|
|
||||||
.withFallback(compatConfig)
|
|
||||||
.withFallback(serverConfig)
|
|
||||||
.resolve()
|
|
||||||
|
|
||||||
logger.debug {
|
|
||||||
"Loaded config:\n" + config.root().render(ConfigRenderOptions.concise().setFormatted(true))
|
|
||||||
}
|
|
||||||
|
|
||||||
return config
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setLoggingEnabled(enabled: Boolean = true) {
|
fun setLoggingEnabled(enabled: Boolean = true) {
|
||||||
val logger = (KotlinLogging.logger(Logger.ROOT_LOGGER_NAME).underlyingLogger as ch.qos.logback.classic.Logger)
|
val logger = (KotlinLogging.logger(Logger.ROOT_LOGGER_NAME).underlyingLogger as ch.qos.logback.classic.Logger)
|
||||||
|
|||||||
Reference in New Issue
Block a user