1
0
Fork 1
mirror of https://gitlab.com/mangadex-pub/mangadex_at_home.git synced 2024-01-19 02:48:37 +00:00
mangadex_at_home/src/main/kotlin/mdnet/Main.kt

125 lines
5.2 KiB
Kotlin
Raw Normal View History

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
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
2021-02-11 21:54:21 +00:00
import java.lang.IllegalArgumentException
import java.nio.file.Files
2021-01-24 04:55:11 +00:00
import java.nio.file.Path
2021-02-11 21:54:21 +00:00
fun main(args: Array<String>) {
CommandLine(Main()).execute(*args)
2020-08-11 19:12:01 +00:00
}
@CommandLine.Command(name = "java -jar <jar>", usageHelpWidth = 120, version = ["Client Version ${BuildInfo.VERSION} (Build ${Constants.CLIENT_BUILD})"])
2021-02-11 21:54:21 +00:00
class Main : Runnable {
2021-02-12 00:10:06 +00:00
@field:CommandLine.Option(names = ["-s", "--settings"], defaultValue = ".\${sys:file.separator}settings.yaml", paramLabel = "<settings>", description = ["the settings file (default: \${DEFAULT-VALUE})"])
2021-02-11 21:54:21 +00:00
lateinit var settingsFile: File
2021-02-12 00:10:06 +00:00
@field:CommandLine.Option(names = ["-d", "--database"], defaultValue = ".\${sys:file.separator}", paramLabel = "<settings>", description = ["the database folder (default: \${DEFAULT-VALUE})"])
2021-02-11 21:54:21 +00:00
lateinit var databaseFolder: Path
2021-02-12 00:10:06 +00:00
@field:CommandLine.Option(names = ["-c", "--cache"], defaultValue = ".\${sys:file.separator}images", paramLabel = "<settings>", description = ["the cache folder (default: \${DEFAULT-VALUE})"])
2021-02-11 21:54:21 +00:00
lateinit var cacheFolder: Path
2020-08-11 19:12:01 +00:00
@field:CommandLine.Option(names = ["-h", "--help"], usageHelp = true, description = ["show this help message and exit"])
2021-02-11 21:54:21 +00:00
var helpRequested: Boolean = false
2020-08-11 19:12:01 +00:00
@field:CommandLine.Option(names = ["-v", "--version"], versionHelp = true, description = ["show the version message and exit"])
var versionRequested: Boolean = false
2021-02-11 21:54:21 +00:00
2020-08-11 19:12:01 +00:00
override fun run() {
println(
2020-07-04 19:00:59 +00:00
"Mangadex@Home Client Version ${BuildInfo.VERSION} (Build ${Constants.CLIENT_BUILD}) initializing"
)
2020-06-22 17:02:36 +00:00
println()
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()
)
2021-02-11 21:54:21 +00:00
if (!Files.isDirectory(databaseFolder) || Files.isRegularFile(databaseFolder.resolveSibling(databaseFolder.fileName.toString() + ".mv.db"))) {
println()
println()
println(
"""the --database option now takes in the folder with the database file!
|(it previously took in the path to the file without any extensions)
|if you are using docker update your docker mount settings!
|if you are not, manually move update your --database args!
|note: the database file itself should be named metadata.{extension}
|where {extension} can be `.db` or `.mv.db`
2021-03-02 18:22:24 +00:00
|
|If this is your first time seeing this message, please check out the support
|channel as things HAVE changed. Failure to do so WILL require
|a cache wipe.
2021-02-11 21:54:21 +00:00
""".trimMargin()
)
println()
println()
throw IllegalArgumentException()
}
2021-02-13 03:07:36 +00:00
if (Files.isRegularFile(databaseFolder)) {
2021-02-11 21:54:21 +00:00
throw IllegalArgumentException("Database folder $databaseFolder must be a directory")
}
2021-02-13 03:07:36 +00:00
if (Files.isRegularFile(cacheFolder)) {
2021-02-12 00:10:06 +00:00
throw IllegalArgumentException("Cache folder $cacheFolder must be a directory")
2021-02-11 21:54:21 +00:00
}
val client = MangaDexClient(settingsFile, databaseFolder, cacheFolder)
2021-01-24 04:55:11 +00:00
val hook = Thread {
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-02-11 21:54:21 +00:00
LOGGER.error(e) { "Failure when starting main loop" }
2021-01-24 04:55:11 +00:00
Runtime.getRuntime().removeShutdownHook(
hook
)
hook.run()
throw e
}
}
2021-02-11 21:54:21 +00:00
companion object {
private val LOGGER = LoggerFactory.getLogger(Main::class.java)
}
}