JAML/src/main/java/tech/nevets/jaml/JAML.java
2022-03-06 22:51:28 -05:00

108 lines
3.1 KiB
Java

package tech.nevets.jaml;
import net.arikia.dev.drpc.DiscordRPC;
import org.apache.commons.io.FileUtils;
import org.simpleyaml.configuration.file.YamlFile;
import tech.nevets.jaml.gui.GuiHandler;
import tech.nevets.jaml.util.VersionFetcher;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
public class JAML {
public static YamlFile config = Config.CONFIG;
public static Path path;
public static GuiHandler guiHandler;
public static Profile activeProfile;
public static void main(String[] args) {
DiscordRP.start();
makeDirs();
Config.loadConfig();
DiscordRP.update("", "");
guiHandler = new GuiHandler();
Launch.main(new String[]{});
// try {
// System.out.println(VersionFetcher.getLatestVersion("release"));
// } catch (IOException e) {
// e.printStackTrace();
// }
try {
activeProfile = Profiles.loadProfile(config.getString("launcher.default-profile"));
} catch (IOException e) {
System.out.println("Unable to load default profile: " + e.getMessage());
}
}
private static void makeDirs() {
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");
}
try {
Path profilePath = Path.of(path + "\\profiles\\");
if (!profilePath.toFile().exists()) {
profilePath.toFile().mkdirs();
}
} catch (Exception e) {
e.printStackTrace();
}
try {
Path profilePath = Path.of(path + "\\assets\\");
if (!profilePath.toFile().exists()) {
profilePath.toFile().mkdirs();
}
} catch (Exception e) {
e.printStackTrace();
}
try {
Path dataPath = Path.of(path + "\\data\\");
if (!dataPath.toFile().exists()) {
dataPath.toFile().mkdirs();
}
} catch (Exception e) {
e.printStackTrace();
}
try {
copyAssets();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void copyAssets() throws IOException, URISyntaxException {
URL resource = JAML.class.getResource("/assets/");
File assets = Paths.get(resource.toURI()).toFile();
if (!Path.of(path + "\\data\\").toFile().exists()) {
FileUtils.copyDirectory(assets, new File(path + "\\assets\\"));
}
}
}