2020-06-22 17:02:36 +00:00
|
|
|
/*
|
|
|
|
Mangadex@Home
|
|
|
|
Copyright (c) 2020, MangaDex Network
|
|
|
|
This file is part of MangaDex@Home.
|
|
|
|
|
|
|
|
MangaDex@Home is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
MangaDex@Home is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this MangaDex@Home. If not, see <http://www.gnu.org/licenses/>.
|
2021-01-25 02:25:49 +00:00
|
|
|
*/
|
2021-01-24 04:55:11 +00:00
|
|
|
package mdnet
|
2020-06-19 20:16:24 +00:00
|
|
|
|
2020-06-20 16:32:15 +00:00
|
|
|
import ch.qos.logback.classic.LoggerContext
|
2021-01-24 04:55:11 +00:00
|
|
|
import mdnet.logging.error
|
2020-07-02 16:06:32 +00:00
|
|
|
import org.slf4j.LoggerFactory
|
2020-08-11 19:12:01 +00:00
|
|
|
import picocli.CommandLine
|
2021-01-24 04:55:11 +00:00
|
|
|
import java.io.File
|
|
|
|
import java.nio.file.Path
|
|
|
|
import java.nio.file.Paths
|
|
|
|
import kotlin.system.exitProcess
|
2020-06-19 20:16:24 +00:00
|
|
|
|
|
|
|
object Main {
|
|
|
|
private val LOGGER = LoggerFactory.getLogger(Main::class.java)
|
|
|
|
|
|
|
|
@JvmStatic
|
|
|
|
fun main(args: Array<String>) {
|
2020-08-11 19:12:01 +00:00
|
|
|
CommandLine(ClientArgs()).execute(*args)
|
|
|
|
}
|
|
|
|
|
|
|
|
fun dieWithError(e: Throwable): Nothing {
|
2021-01-24 04:55:11 +00:00
|
|
|
LOGGER.error(e) { "Critical Error" }
|
2020-08-11 19:12:01 +00:00
|
|
|
(LoggerFactory.getILoggerFactory() as LoggerContext).stop()
|
|
|
|
exitProcess(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
fun dieWithError(error: String): Nothing {
|
|
|
|
LOGGER.error { "Critical Error: $error" }
|
|
|
|
|
|
|
|
(LoggerFactory.getILoggerFactory() as LoggerContext).stop()
|
|
|
|
exitProcess(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@CommandLine.Command(name = "java -jar <jar>", usageHelpWidth = 120, version = ["Client Version ${BuildInfo.VERSION} (Build ${Constants.CLIENT_BUILD})"])
|
2021-01-24 04:55:11 +00:00
|
|
|
class ClientArgs(
|
|
|
|
@field:CommandLine.Option(names = ["-s", "--settings"], defaultValue = "settings.yaml", paramLabel = "<settings>", description = ["the settings file (default: \${DEFAULT-VALUE})"])
|
|
|
|
var settingsFile: File = File("settings.yaml"),
|
|
|
|
@field:CommandLine.Option(names = ["-d", "--database"], defaultValue = ".\${sys:file.separator}metadata", paramLabel = "<settings>", description = ["the database file (default: \${DEFAULT-VALUE})"])
|
|
|
|
var databaseFile: File = File(".${File.separator}metadata"),
|
|
|
|
@field:CommandLine.Option(names = ["-c", "--cache"], defaultValue = "images", paramLabel = "<settings>", description = ["the cache folder (default: \${DEFAULT-VALUE})"])
|
|
|
|
var cacheFolder: Path = Paths.get("images"),
|
2020-08-11 19:12:01 +00:00
|
|
|
@field:CommandLine.Option(names = ["-h", "--help"], usageHelp = true, description = ["show this help message and exit"])
|
|
|
|
var helpRequested: Boolean = false,
|
|
|
|
@field:CommandLine.Option(names = ["-v", "--version"], versionHelp = true, description = ["show the version message and exit"])
|
|
|
|
var versionRequested: Boolean = false
|
|
|
|
) : Runnable {
|
|
|
|
override fun run() {
|
2020-06-19 20:16:24 +00:00
|
|
|
println(
|
2020-07-04 19:00:59 +00:00
|
|
|
"Mangadex@Home Client Version ${BuildInfo.VERSION} (Build ${Constants.CLIENT_BUILD}) initializing"
|
2020-06-19 20:16:24 +00:00
|
|
|
)
|
2020-06-22 17:02:36 +00:00
|
|
|
println()
|
2020-06-19 20:16:24 +00:00
|
|
|
println("Copyright (c) 2020, MangaDex Network")
|
2021-01-24 04:55:11 +00:00
|
|
|
println(
|
|
|
|
"""
|
2020-06-22 17:02:36 +00:00
|
|
|
Mangadex@Home is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2020-06-22 17:09:11 +00:00
|
|
|
|
2020-06-22 17:02:36 +00:00
|
|
|
Mangadex@Home is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2020-06-22 17:09:11 +00:00
|
|
|
|
2020-06-22 17:02:36 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Mangadex@Home. If not, see <https://www.gnu.org/licenses/>.
|
2021-01-24 04:55:11 +00:00
|
|
|
""".trimIndent()
|
|
|
|
)
|
2020-06-19 20:16:24 +00:00
|
|
|
|
2020-08-11 19:12:01 +00:00
|
|
|
val client = MangaDexClient(settingsFile, databaseFile, cacheFolder)
|
2021-01-24 04:55:11 +00:00
|
|
|
val hook = Thread {
|
2020-08-11 16:47:04 +00:00
|
|
|
client.shutdown()
|
|
|
|
(LoggerFactory.getILoggerFactory() as LoggerContext).stop()
|
2021-01-24 04:55:11 +00:00
|
|
|
}
|
|
|
|
Runtime.getRuntime().addShutdownHook(
|
|
|
|
hook
|
|
|
|
)
|
|
|
|
|
|
|
|
try {
|
|
|
|
client.runLoop()
|
2021-01-28 13:50:13 +00:00
|
|
|
} catch (e: Throwable) {
|
2021-01-24 04:55:11 +00:00
|
|
|
Runtime.getRuntime().removeShutdownHook(
|
|
|
|
hook
|
|
|
|
)
|
|
|
|
hook.run()
|
|
|
|
throw e
|
|
|
|
}
|
2020-06-19 20:16:24 +00:00
|
|
|
}
|
|
|
|
}
|