Config generates in a specified path

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

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();
}
}