4
0
Fork 0
mirror of https://github.com/Anvilcraft/modpacktools synced 2024-11-17 23:41:55 +01:00

config is not relative to working dir instead of jar file

This commit is contained in:
LordMZTE 2020-07-28 13:55:48 +02:00
parent 3fa8924c35
commit ecaa9333c7
3 changed files with 5 additions and 19 deletions

View file

@ -29,7 +29,7 @@ class CommandLoader(private val pkg: String) {
@JvmStatic
@Throws(ConfigMissingException::class, ModpackJsonMissingException::class)
fun ICommand.runStatic(args: Array<out String>): CommandReturn {
if(this.needsConfig && !CONFIG.configExists())
if(this.needsConfig && !CONFIG.exists)
throw ConfigMissingException()
if(this.needsModpackjson && MPJH.asWrapper == null)

View file

@ -15,7 +15,7 @@ object Init : ICommand {
override val needsModpackjson: Boolean = false
override fun execute(args: Array<out String>): CommandReturn {
if(CONFIG.configExists())
if(CONFIG.exists)
return fail("Config exists")
CONFIG.copyConfig()
return success("Config Created")

View file

@ -4,21 +4,7 @@ import org.apache.commons.io.FileUtils
import java.io.File
class Config(val configName: String) {
val jarLocation by lazy {
//Get the Location of the jarfile
var file = File(
this::class.java
.protectionDomain
.codeSource
.location
.toURI()
)
//Ensure That JAR_LOCATION is the jarfile's directory and not the file itself
if(file.isFile)
file = file.parentFile
file
}
val configLocation by lazy {File(jarLocation, configName)}
val configLocation by lazy {File(configName)}
val config by lazy {readConfig()}
/**
@ -27,7 +13,7 @@ class Config(val configName: String) {
* @return the Toml object of the config file
*/
private fun readConfig(): CustomToml {
return if(configExists()) {
return if(exists) {
//parse file to toml
CustomToml().read(configLocation) as CustomToml
//reads config from resources if no config file exists as a default value. commands that require the config still won't run without it
@ -39,7 +25,7 @@ class Config(val configName: String) {
*
* @return true if the config file exists
*/
fun configExists(): Boolean = configLocation.exists()
val exists: Boolean = configLocation.exists()
/**
* Copies the Config file from the resources into the tool's folder