Config generates in a specified path

This commit is contained in:
Steven Tracey 2022-02-13 23:26:12 -05:00
parent 6a2986f45e
commit 3dae87396f
12 changed files with 132 additions and 98 deletions

1
.gitignore vendored
View File

@ -139,3 +139,4 @@ fabric.properties
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
config.yml

View File

@ -16,5 +16,10 @@
<option name="name" value="MavenRepo" />
<option name="url" value="https://repo.maven.apache.org/maven2/" />
</remote-repository>
<remote-repository>
<option name="id" value="maven" />
<option name="name" value="maven" />
<option name="url" value="https://jitpack.io" />
</remote-repository>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -1,55 +1,38 @@
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.10'
id 'org.beryx.jlink' version '2.24.1'
}
group 'tech.nevets.jaml'
version '1.0-SNAPSHOT'
version '0.1.0'
repositories {
mavenCentral()
maven {
url 'https://jitpack.io'
}
}
sourceCompatibility = '17'
targetCompatibility = '17'
sourceCompatibility = targetCompatibility = '17'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
application {
mainModule = 'tech.nevets.jaml.jaml'
mainClass = 'tech.nevets.jaml.jaml.JAML'
}
javafx {
version = '17.0.1'
modules = ['javafx.controls', 'javafx.fxml', 'javafx.web']
mainModule = 'tech.nevets.jaml'
mainClass = 'tech.nevets.jaml.JAML'
}
dependencies {
implementation('org.controlsfx:controlsfx:11.1.0')
implementation('com.dlsc.formsfx:formsfx-core:11.3.2') {
exclude(group: 'org.openjfx')
}
implementation('org.kordamp.ikonli:ikonli-javafx:12.2.0')
implementation('org.kordamp.bootstrapfx:bootstrapfx-core:0.4.0')
implementation('eu.hansolo:tilesfx:11.48') {
exclude(group: 'org.openjfx')
}
implementation 'me.carleslc.Simple-YAML:Simple-Yaml:1.7.3'
implementation 'com.google.code.gson:gson:2.9.0'
}
jlink {
imageZip = project.file("${buildDir}/distributions/app-${javafx.platform.classifier}.zip")
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'app'
jar {
manifest {
attributes(
'Main-Class': 'tech.nevets.jaml.JAML'
)
}
}
jlinkZip {
group = 'distribution'
}

4
config.yml Normal file
View File

@ -0,0 +1,4 @@
# If true, will print out all the messages
verbose: false
# Jaml version, don't change it!
version: 0.1.0

View File

@ -1,14 +0,0 @@
module tech.nevets.jaml.jaml {
requires javafx.controls;
requires javafx.fxml;
requires javafx.web;
requires org.controlsfx.controls;
requires com.dlsc.formsfx;
requires org.kordamp.ikonli.javafx;
requires org.kordamp.bootstrapfx.core;
requires eu.hansolo.tilesfx;
opens tech.nevets.jaml.jaml to javafx.fxml;
exports tech.nevets.jaml.jaml;
}

View File

@ -0,0 +1,43 @@
package tech.nevets.jaml;
import org.simpleyaml.configuration.file.YamlFile;
import java.io.IOException;
public class Config {
private static final YamlFile ymlFile = new YamlFile(JAML.path + "\\config.yml");
public static void loadConfig() {
try {
if (!ymlFile.exists()) {
System.out.println("Config file not found, creating new one...");
ymlFile.createNewFile(true);
System.out.println("Config file created!");
} else {
System.out.println("Loading Config file...");
ymlFile.loadWithComments();
System.out.println("Config file loaded!");
}
} catch (final Exception e) {
System.out.println("Error while loading config file!");
e.printStackTrace();
}
ymlFile.addDefault("launcher.path","default");
ymlFile.setComment("launcher.path","Path to JAML files\n" + "default: %appdata%\\.jaml\\");
ymlFile.addDefault("launcher.verbose", false);
ymlFile.setComment("launcher.verbose", "If true, will print out all the messages");
ymlFile.addDefault("launcher.version", "0.1.0");
ymlFile.setComment("launcher.version", "Jaml version, don't change it!");
try {
ymlFile.save();
} catch (IOException e) {
e.printStackTrace();
}
}
public static YamlFile getConfig() {
return ymlFile;
}
}

View File

@ -0,0 +1,37 @@
package tech.nevets.jaml;
import org.simpleyaml.configuration.file.YamlFile;
import java.nio.file.Path;
public class JAML {
public static YamlFile config;
public static Path path;
public static void main(String[] args) {
makeDir();
Config.loadConfig();
config = Config.getConfig();
}
private static void makeDir() {
if (config == null) {
path = Path.of(System.getenv("APPDATA") + "\\.jaml\\");
} else {
if (config.getString("launcher.path") == "default") {
path = Path.of(System.getenv("APPDATA") + "\\.jaml\\");
} else {
path = Path.of(config.getString("launcher.path"));
}
}
try {
if (!path.toFile().exists()) {
path.toFile().mkdirs();
}
} catch (Exception e) {
System.out.println("Invalid path, please check your config.yml and try again");
}
}
}

View File

@ -0,0 +1,22 @@
package tech.nevets.jaml;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.nio.file.Path;
public class Profiles {
public static void createProfile(String email, String hashedPassword, Path javaPath, Path gamePath, String version, Boolean onlineMode, String username) {
GsonBuilder builder = new GsonBuilder();
builder.setPrettyPrinting();
Gson gson = builder.create();
//TODO Create and save profiles
}
public static void loadProfile() {
//TODO Load Saved Profiles
}
}

View File

@ -1,14 +0,0 @@
package tech.nevets.jaml.jaml;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
public class Controller {
@FXML
private Label welcomeText;
@FXML
protected void onHelloButtonClick() {
welcomeText.setText("Welcome to JavaFX Application!");
}
}

View File

@ -1,23 +0,0 @@
package tech.nevets.jaml.jaml;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
public class JAML extends Application {
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(JAML.class.getResource("hello-view.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 320, 240);
stage.setTitle("Hello!");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}

View File

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.control.Button?>
<VBox alignment="CENTER" spacing="20.0" xmlns:fx="http://javafx.com/fxml"
fx:controller="tech.nevets.jaml.jaml.Controller">
<padding>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0"/>
</padding>
<Label fx:id="welcomeText"/>
<Button text="Hello!" onAction="#onHelloButtonClick"/>
</VBox>