Splash Screen and other stuff!
5
.gitignore
vendored
@ -146,4 +146,7 @@ src/test
|
||||
.classpath
|
||||
.project
|
||||
bin/
|
||||
.settings/
|
||||
.settings/
|
||||
!packr/packr-all-4.0.0.jar
|
||||
!packr/PackrConfig.json
|
||||
packr/
|
31
build.gradle
@ -1,6 +1,9 @@
|
||||
//import edu.sc.seis.launch4j.tasks.Launch4jLibraryTask
|
||||
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'com.github.johnrengelman.shadow' version '5.2.0'
|
||||
// id 'edu.sc.seis.launch4j' version '2.5.1'
|
||||
}
|
||||
|
||||
group 'tech.nevets.jaml'
|
||||
@ -36,4 +39,30 @@ shadowJar {
|
||||
'Main-Class': 'tech.nevets.jaml.JAML'
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//launch4j {
|
||||
// mainClassName = 'tech.nevets.jaml.JAML'
|
||||
// outfile = 'JAML.exe'
|
||||
// jarTask = project.tasks.shadowJar
|
||||
// fileDescription = 'Just Another Minecraft Launcher'
|
||||
//
|
||||
//}
|
||||
//
|
||||
//task Build(type: Launch4jLibraryTask) {
|
||||
// mainClassName = 'tech.nevets.jaml.JAML'
|
||||
// outfile = 'JAML.exe'
|
||||
// jarTask = project.tasks.shadowJar
|
||||
// fileDescription = 'Just Another Minecraft Launcher'
|
||||
// bundledJre64Bit = true
|
||||
// bundledJrePath = ''
|
||||
//}
|
||||
//
|
||||
//task winBuild(type: Launch4jLibraryTask) {
|
||||
// mainClassName = 'tech.nevets.jaml.JAML'
|
||||
// outfile = 'JAML.exe'
|
||||
// jarTask = project.tasks.shadowJar
|
||||
// fileDescription = 'Just Another Minecraft Launcher'
|
||||
// bundledJre64Bit = true
|
||||
// bundledJrePath = ''
|
||||
//}
|
15
packr/PackrConfig.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"platform": "windows64",
|
||||
"jdk": "https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.2%2B8/OpenJDK17U-jdk_x64_windows_hotspot_17.0.2_8.zip",
|
||||
"executable": "JAML",
|
||||
"jrePath": "",
|
||||
"mainclass": "tech.nevets.jaml.JAML",
|
||||
"vmargs": [
|
||||
"Xmx2G"
|
||||
],
|
||||
"resources": [
|
||||
"../src/main/resources"
|
||||
],
|
||||
"minimizejre": "soft",
|
||||
"output": "packr-out"
|
||||
}
|
BIN
packr/packr-all-4.0.0.jar
Normal file
@ -1,7 +1,6 @@
|
||||
package tech.nevets.jaml;
|
||||
|
||||
import tech.nevets.jaml.gui.GuiHandler;
|
||||
import tech.nevets.jaml.util.*;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
@ -10,12 +9,13 @@ public class JAML {
|
||||
public static GuiHandler guiHandler;
|
||||
|
||||
public static void main(String[] args) {
|
||||
//TODO Create logic to check for first launch without the use of config
|
||||
//TODO make guiHandler run first with the initial splash screen while backend is starting, then start homeGui when done. (Possibly multithreaded)
|
||||
|
||||
GuiHandler.startup();
|
||||
|
||||
DiscordRP.start();
|
||||
makeDirs();
|
||||
Config.loadConfig();
|
||||
ProfileUtils.getProfileList();
|
||||
ProfileUtils.getActiveProfile();
|
||||
LoaderUtils.getLoaders();
|
||||
|
||||
DiscordRP.update("", "");
|
||||
guiHandler = new GuiHandler();
|
||||
|
||||
@ -26,56 +26,4 @@ public class JAML {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
}
|
||||
|
||||
private static void makeDirs() {
|
||||
if (System.getenv("JAML_HOME") == null) {
|
||||
path = Path.of(System.getenv("APPDATA") + "\\.jaml\\");
|
||||
} else {
|
||||
path = Path.of(System.getenv("JAML_HOME"));
|
||||
}
|
||||
|
||||
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 {
|
||||
Path skinsPath = Path.of(path + "\\data\\skins\\");
|
||||
if (!skinsPath.toFile().exists()) {
|
||||
skinsPath.toFile().mkdirs();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
25
src/main/java/tech/nevets/jaml/auth/AuthRequests.java
Normal file
@ -0,0 +1,25 @@
|
||||
package tech.nevets.jaml.auth;
|
||||
|
||||
import tech.nevets.jaml.util.HttpUtils;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class AuthRequests {
|
||||
|
||||
public static void login() {
|
||||
String accountName = "account_name";
|
||||
String accountPassword = "password123";
|
||||
|
||||
try {
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
|
||||
String json = "{ \"agent\": { \"name\": \"Minecraft\", \"version\": 1 }, \"username\": \"" + accountName + "\", \"password\": \"" + accountPassword + "\" }";
|
||||
HttpUtils.post(new URI("https://authserver.mojang.com/authenticate"), headers, json);
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -4,9 +4,15 @@ import tech.nevets.jaml.Config;
|
||||
import tech.nevets.jaml.JAML;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class GuiHandler {
|
||||
|
||||
public static final int SCREEN_WIDTH = (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth();
|
||||
public static final int SCREEN_HEIGHT = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight();
|
||||
|
||||
private static StartupGui startupFrame;
|
||||
|
||||
public GuiHandler() {
|
||||
if (Config.getConfig().getBoolean("launcher.first-launch")) {
|
||||
FirstLaunchGui firstLaunchGui = new FirstLaunchGui();
|
||||
@ -14,16 +20,23 @@ public class GuiHandler {
|
||||
firstLaunchThread.start();
|
||||
}
|
||||
|
||||
startupFrame.dispose();
|
||||
|
||||
Thread homeGuiThread = new Thread(() -> {
|
||||
HomeGui frame = new HomeGui();
|
||||
frame.setTitle("JAML");
|
||||
frame.setIconImage(new ImageIcon(JAML.path + "\\assets\\icon.png").getImage());
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.setVisible(true);
|
||||
});
|
||||
homeGuiThread.start();
|
||||
|
||||
}
|
||||
|
||||
public static void startup() {
|
||||
startupFrame = new StartupGui();
|
||||
}
|
||||
|
||||
public void startNewProfileGui() {
|
||||
Thread newProfileGuiThread = new Thread(() -> {
|
||||
NewProfileGui frame = new NewProfileGui();
|
||||
|
@ -1,6 +1,9 @@
|
||||
package tech.nevets.jaml.gui;
|
||||
|
||||
import tech.nevets.jaml.JAML;
|
||||
import tech.nevets.jaml.gui.panels.HomePanel;
|
||||
import tech.nevets.jaml.gui.panels.ProfilePanel;
|
||||
import tech.nevets.jaml.gui.panels.UsersPanel;
|
||||
import tech.nevets.jaml.listeners.RightClickListener;
|
||||
import tech.nevets.jaml.util.ImageUtils;
|
||||
import tech.nevets.jaml.util.ProfileUtils;
|
||||
@ -11,13 +14,14 @@ import javax.swing.border.EmptyBorder;
|
||||
public class HomeGui extends JFrame {
|
||||
|
||||
private JTabbedPane tabPanel;
|
||||
private JPanel homePanel;
|
||||
private JPanel userPanel;
|
||||
private JPanel profilePanel;
|
||||
private HomePanel homePanel;
|
||||
private ProfilePanel profilePanel;
|
||||
private UsersPanel userPanel;
|
||||
|
||||
|
||||
public HomeGui() {
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 1280, 720);
|
||||
setSize((int) (GuiHandler.SCREEN_WIDTH / 1.5), (int) (GuiHandler.SCREEN_HEIGHT / 1.5));
|
||||
SpringLayout springLayout = new SpringLayout();
|
||||
getContentPane().setLayout(springLayout);
|
||||
addMouseListener(new RightClickListener());
|
||||
@ -28,45 +32,18 @@ public class HomeGui extends JFrame {
|
||||
springLayout.putConstraint(SpringLayout.SOUTH, tabPanel, 720, SpringLayout.NORTH, getContentPane());
|
||||
springLayout.putConstraint(SpringLayout.EAST, tabPanel, 1280, SpringLayout.WEST, getContentPane());
|
||||
tabPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
//setContentPane(tabPanel);
|
||||
|
||||
|
||||
homePanel = new JPanel();
|
||||
homePanel = new HomePanel();
|
||||
tabPanel.add("Home", homePanel);
|
||||
getContentPane().add(tabPanel);
|
||||
|
||||
JButton newProfileButton = new JButton("Create New Profile");
|
||||
newProfileButton.setBounds(920, 601, 134, 36);
|
||||
newProfileButton.addActionListener(al -> {
|
||||
JAML.guiHandler.startNewProfileGui();
|
||||
});
|
||||
homePanel.add(newProfileButton);
|
||||
|
||||
JButton launchButton = new JButton("Launch");
|
||||
launchButton.setBounds(512, 619, 196, 51);
|
||||
homePanel.add(launchButton);
|
||||
|
||||
JComboBox activeProfileDropdown = new JComboBox(ProfileUtils.profileList);
|
||||
activeProfileDropdown.setBounds(858, 648, 196, 22);
|
||||
homePanel.add(activeProfileDropdown);
|
||||
|
||||
JButton reloadProfileButton = new JButton("Reload Profiles");
|
||||
reloadProfileButton.setBounds(800, 608, 106, 23);
|
||||
reloadProfileButton.addActionListener(al -> {
|
||||
ProfileUtils.getProfileList();
|
||||
activeProfileDropdown.removeAllItems();
|
||||
for (int i = 0; i < ProfileUtils.profileList.length; i++) {
|
||||
activeProfileDropdown.addItem(ProfileUtils.profileList[i]);
|
||||
}
|
||||
});
|
||||
homePanel.add(reloadProfileButton);
|
||||
|
||||
JLabel backgroundIcon = new JLabel("");
|
||||
backgroundIcon.setBounds(0, 25, 1264, 542);
|
||||
ImageIcon backgroundImg = new ImageIcon(JAML.path + "\\assets\\background.png");
|
||||
backgroundImg = ImageUtils.resizeIcon(backgroundImg, backgroundIcon.getWidth(), backgroundIcon.getHeight());
|
||||
backgroundIcon.setIcon(backgroundImg);
|
||||
homePanel.add(backgroundIcon);
|
||||
profilePanel = new ProfilePanel();
|
||||
tabPanel.add("Profiles", profilePanel);
|
||||
|
||||
userPanel = new UsersPanel();
|
||||
tabPanel.add("Users", userPanel);
|
||||
|
||||
getContentPane().add(tabPanel);
|
||||
|
||||
tabPanel.addMouseListener(new RightClickListener());
|
||||
|
||||
|
145
src/main/java/tech/nevets/jaml/gui/StartupGui.java
Normal file
@ -0,0 +1,145 @@
|
||||
package tech.nevets.jaml.gui;
|
||||
|
||||
import tech.nevets.jaml.Config;
|
||||
import tech.nevets.jaml.JAML;
|
||||
import tech.nevets.jaml.gui.panels.CustomProgressBarPanel;
|
||||
import tech.nevets.jaml.util.ImageUtils;
|
||||
import tech.nevets.jaml.util.LoaderUtils;
|
||||
import tech.nevets.jaml.util.ProfileUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class StartupGui extends JFrame {
|
||||
JPanel contentPane;
|
||||
|
||||
public StartupGui() {
|
||||
setUndecorated(true);
|
||||
setResizable(false);
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setSize(GuiHandler.SCREEN_WIDTH / 3, GuiHandler.SCREEN_HEIGHT / 3);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
setLocationRelativeTo(null);
|
||||
|
||||
int pbWidth = (int) (getWidth() / 1.1);
|
||||
int pbHeight = getHeight() / 24;
|
||||
int pbX = (getWidth() - pbWidth) / 2;
|
||||
int pbY = getHeight() - (pbHeight * 2);
|
||||
|
||||
JLabel progressBarOutline = new JLabel();
|
||||
progressBarOutline.setBounds(pbX, pbY - 10, pbWidth, pbHeight + 20);
|
||||
ImageIcon pgOutline = new ImageIcon(getClass().getClassLoader().getResource("assets/progressbaroutline.png"));
|
||||
pgOutline = ImageUtils.resizeIcon(pgOutline, pbWidth + 20, pbHeight);
|
||||
progressBarOutline.setIcon(pgOutline);
|
||||
contentPane.add(progressBarOutline);
|
||||
|
||||
CustomProgressBarPanel progressBar = new CustomProgressBarPanel(pbWidth, pbHeight);
|
||||
progressBar.setBounds(pbX, pbY, pbWidth, pbHeight);
|
||||
contentPane.add(progressBar);
|
||||
|
||||
JLabel splashIcon = new JLabel("");
|
||||
splashIcon.setSize(getWidth(), getHeight());
|
||||
ImageIcon backgroundImg = new ImageIcon(getClass().getClassLoader().getResource("assets/background.png"));
|
||||
backgroundImg = ImageUtils.resizeIcon(backgroundImg, splashIcon.getWidth(), splashIcon.getHeight());
|
||||
splashIcon.setIcon(backgroundImg);
|
||||
contentPane.add(splashIcon);
|
||||
|
||||
setVisible(true);
|
||||
|
||||
|
||||
progressBar.setProgress(0);
|
||||
makeDirs();
|
||||
smoothIncrease(progressBar, 20);
|
||||
Config.loadConfig();
|
||||
sleep();
|
||||
smoothIncrease(progressBar, 40);
|
||||
ProfileUtils.getProfileList();
|
||||
sleep();
|
||||
smoothIncrease(progressBar, 60);
|
||||
ProfileUtils.getActiveProfile();
|
||||
sleep();
|
||||
smoothIncrease(progressBar, 80);
|
||||
LoaderUtils.getLoaders();
|
||||
sleep();
|
||||
smoothIncrease(progressBar, 100);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static void sleep() {
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static void makeDirs() {
|
||||
if (System.getenv("JAML_HOME") == null) {
|
||||
JAML.path = Path.of(System.getenv("APPDATA") + "\\.jaml\\");
|
||||
} else {
|
||||
JAML.path = Path.of(System.getenv("JAML_HOME"));
|
||||
}
|
||||
|
||||
try {
|
||||
if (!JAML.path.toFile().exists()) {
|
||||
JAML.path.toFile().mkdirs();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Invalid path, please check your config.yml and try again");
|
||||
}
|
||||
|
||||
try {
|
||||
Path profilePath = Path.of(JAML.path + "\\profiles\\");
|
||||
if (!profilePath.toFile().exists()) {
|
||||
profilePath.toFile().mkdirs();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
Path profilePath = Path.of(JAML.path + "\\assets\\");
|
||||
if (!profilePath.toFile().exists()) {
|
||||
profilePath.toFile().mkdirs();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
Path dataPath = Path.of(JAML.path + "\\data\\");
|
||||
if (!dataPath.toFile().exists()) {
|
||||
dataPath.toFile().mkdirs();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
Path skinsPath = Path.of(JAML.path + "\\data\\skins\\");
|
||||
if (!skinsPath.toFile().exists()) {
|
||||
skinsPath.toFile().mkdirs();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void smoothIncrease(CustomProgressBarPanel pb, int to) {
|
||||
int i = pb.getProgress();
|
||||
while (i <= to) {
|
||||
pb.setProgress(i);
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
}
|
9
src/main/java/tech/nevets/jaml/gui/icons/Icons.java
Normal file
@ -0,0 +1,9 @@
|
||||
package tech.nevets.jaml.gui.icons;
|
||||
|
||||
import tech.nevets.jaml.JAML;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class Icons {
|
||||
public static final ImageIcon BUTTON = new ImageIcon(JAML.path + "\\assets\\icons\\button.png");
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package tech.nevets.jaml.gui.panels;
|
||||
|
||||
import tech.nevets.jaml.util.ImageUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class CustomProgressBarPanel extends JPanel {
|
||||
private int progress = 0;
|
||||
private int width;
|
||||
private int height;
|
||||
|
||||
public CustomProgressBarPanel(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
JLabel progressBar = new JLabel();
|
||||
progressBar.setSize(getWidth(), getHeight());
|
||||
ImageIcon image = new ImageIcon(getClass().getClassLoader().getResource("assets/progressbar.png"));
|
||||
image = ImageUtils.resizeIcon(image, width, height);
|
||||
progressBar.setIcon(image);
|
||||
add(progressBar);
|
||||
}
|
||||
|
||||
public int getProgress() {
|
||||
return progress;
|
||||
}
|
||||
|
||||
public void setProgress(int progress) {
|
||||
this.progress = progress;
|
||||
setSize(((progress * width) / 100), height);
|
||||
repaint();
|
||||
}
|
||||
}
|
46
src/main/java/tech/nevets/jaml/gui/panels/HomePanel.java
Normal file
@ -0,0 +1,46 @@
|
||||
package tech.nevets.jaml.gui.panels;
|
||||
|
||||
|
||||
import tech.nevets.jaml.JAML;
|
||||
import tech.nevets.jaml.util.ImageUtils;
|
||||
import tech.nevets.jaml.util.ProfileUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class HomePanel extends JPanel {
|
||||
public HomePanel() {
|
||||
JButton newProfileButton = new JButton("Create New Profile");
|
||||
newProfileButton.setBounds(920, 601, 134, 36);
|
||||
newProfileButton.addActionListener(al -> {
|
||||
JAML.guiHandler.startNewProfileGui();
|
||||
});
|
||||
add(newProfileButton);
|
||||
|
||||
JButton launchButton = new JButton("Launch");
|
||||
launchButton.setBounds(512, 619, 196, 51);
|
||||
//launchButton.setIcon(); //TODO Create nice looking buttons and apply them to project
|
||||
add(launchButton);
|
||||
|
||||
JComboBox activeProfileDropdown = new JComboBox(ProfileUtils.profileList);
|
||||
activeProfileDropdown.setBounds(858, 648, 196, 22);
|
||||
add(activeProfileDropdown);
|
||||
|
||||
JButton reloadProfileButton = new JButton("Reload Profiles");
|
||||
reloadProfileButton.setBounds(800, 608, 106, 23);
|
||||
reloadProfileButton.addActionListener(al -> {
|
||||
ProfileUtils.getProfileList();
|
||||
activeProfileDropdown.removeAllItems();
|
||||
for (int i = 0; i < ProfileUtils.profileList.length; i++) {
|
||||
activeProfileDropdown.addItem(ProfileUtils.profileList[i]);
|
||||
}
|
||||
});
|
||||
add(reloadProfileButton);
|
||||
|
||||
JLabel backgroundIcon = new JLabel("");
|
||||
backgroundIcon.setBounds(0, 25, 1264, 542);
|
||||
ImageIcon backgroundImg = new ImageIcon(JAML.path + "\\assets\\background.png");
|
||||
backgroundImg = ImageUtils.resizeIcon(backgroundImg, backgroundIcon.getWidth(), backgroundIcon.getHeight());
|
||||
backgroundIcon.setIcon(backgroundImg);
|
||||
add(backgroundIcon);
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package tech.nevets.jaml.gui.panels;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class ProfilePanel extends JPanel {
|
||||
public ProfilePanel() {
|
||||
|
||||
}
|
||||
}
|
10
src/main/java/tech/nevets/jaml/gui/panels/UsersPanel.java
Normal file
@ -0,0 +1,10 @@
|
||||
package tech.nevets.jaml.gui.panels;
|
||||
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class UsersPanel extends JPanel {
|
||||
public UsersPanel() {
|
||||
|
||||
}
|
||||
}
|
@ -1,35 +1,17 @@
|
||||
package tech.nevets.jaml.init;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import tech.nevets.jaml.Config;
|
||||
import tech.nevets.jaml.JAML;
|
||||
|
||||
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 FirstLaunch {
|
||||
public FirstLaunch() {
|
||||
try {
|
||||
copyAssets();
|
||||
} catch (IOException | URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//TODO Make this force login
|
||||
|
||||
System.out.println("First Launch!");
|
||||
|
||||
Config.setValue("launcher.first-launch", false);
|
||||
Config.saveConfig();
|
||||
}
|
||||
|
||||
public static void copyAssets() throws IOException, URISyntaxException {
|
||||
URL resource = JAML.class.getResource("/assets/");
|
||||
File assets = Paths.get(resource.toURI()).toFile();
|
||||
|
||||
if (!Path.of(JAML.path + "\\assets\\").toFile().exists()) {
|
||||
FileUtils.copyDirectory(assets, new File(JAML.path + "\\assets\\"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
79
src/main/java/tech/nevets/jaml/util/HttpUtils.java
Normal file
@ -0,0 +1,79 @@
|
||||
package tech.nevets.jaml.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URLEncoder;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
|
||||
public class HttpUtils {
|
||||
public static String get(URI uri, Map<String, String> headers) {
|
||||
try {
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()
|
||||
.GET()
|
||||
.uri(uri);
|
||||
for (Map.Entry<String, String> pair : headers.entrySet()) {
|
||||
requestBuilder.setHeader(pair.getKey(), pair.getValue());
|
||||
}
|
||||
HttpRequest request = requestBuilder.build();
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
return response.body();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String post(URI uri, Map<String, String> headers, String data) {
|
||||
try {
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()
|
||||
.POST(HttpRequest.BodyPublishers.ofString(data))
|
||||
.uri(uri);
|
||||
for (Map.Entry<String, String> pair : headers.entrySet()) {
|
||||
requestBuilder.setHeader(pair.getKey(), pair.getValue());
|
||||
}
|
||||
HttpRequest request = requestBuilder.build();
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
return response.body();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String post(URI uri, Map<String, String> headers, Map<String, String> data) {
|
||||
try {
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()
|
||||
.POST(buildBodyPubFromMap(data))
|
||||
.uri(uri);
|
||||
for (Map.Entry<String, String> pair : headers.entrySet()) {
|
||||
requestBuilder.setHeader(pair.getKey(), pair.getValue());
|
||||
}
|
||||
HttpRequest request = requestBuilder.build();
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
return response.body();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static HttpRequest.BodyPublisher buildBodyPubFromMap(Map<String, String> data) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (Map.Entry<String, String> pair : data.entrySet()) {
|
||||
if (builder.length() > 0) {
|
||||
builder.append("&");
|
||||
}
|
||||
builder.append(URLEncoder.encode(pair.getKey().toString(), StandardCharsets.UTF_8));
|
||||
builder.append("=");
|
||||
builder.append(URLEncoder.encode(pair.getValue().toString(), StandardCharsets.UTF_8));
|
||||
}
|
||||
return HttpRequest.BodyPublishers.ofString(builder.toString());
|
||||
}
|
||||
}
|
@ -6,9 +6,7 @@ import java.awt.*;
|
||||
public class ImageUtils {
|
||||
public static ImageIcon resizeIcon(ImageIcon icon, int width, int height) {
|
||||
Image image = icon.getImage();
|
||||
Image newImg = image.getScaledInstance(width, height, java.awt.Image.SCALE_SMOOTH);
|
||||
Image newImg = image.getScaledInstance(width, height, java.awt.Image.SCALE_SMOOTH);
|
||||
return new ImageIcon(newImg);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import tech.nevets.jaml.objects.Loader;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class LoaderUtils {
|
||||
@ -17,7 +18,7 @@ public class LoaderUtils {
|
||||
public static String[] getLoaders() {
|
||||
try {
|
||||
Gson gson = new Gson();
|
||||
File loadersFile = new File(JAML.path + "\\data\\loaders.json");
|
||||
File loadersFile = getLoadersList();
|
||||
JsonObject loadersJson = gson.fromJson(FileUtils.readFileToString(loadersFile, StandardCharsets.UTF_8), JsonObject.class);
|
||||
JsonArray loadersJsonArray = loadersJson.getAsJsonArray("loaders");
|
||||
Loader[] loadersArray = gson.fromJson(loadersJsonArray, Loader[].class);
|
||||
@ -35,4 +36,16 @@ public class LoaderUtils {
|
||||
return new String[]{"Vanilla", "Fabric", "Forge"}; // Fallback variable
|
||||
}
|
||||
}
|
||||
|
||||
private static File getLoadersList() {
|
||||
File loadersFile;
|
||||
try {
|
||||
loadersFile = new File(JAML.path + "\\data\\loaders.json");
|
||||
FileUtils.copyURLToFile(new URL("https://api.nevets.tech/jaml/loaders.json"), loadersFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
loadersFile = new File("");
|
||||
}
|
||||
return loadersFile;
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 538 KiB After Width: | Height: | Size: 1.5 MiB |
Before Width: | Height: | Size: 210 KiB After Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 210 KiB After Width: | Height: | Size: 148 KiB |
BIN
src/main/resources/assets/progressbar.png
Normal file
After Width: | Height: | Size: 41 KiB |
BIN
src/main/resources/assets/progressbaroutline.png
Normal file
After Width: | Height: | Size: 671 B |