Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.epicdream.launcher;
- import fr.epicdream.launcher.ui.LauncherFrame;
- import fr.epicdream.settings.GlobalSettings;
- import fr.epicdream.settings.LocalSettings;
- import fr.theshark34.openauth.AuthPoints;
- import fr.theshark34.openauth.AuthenticationException;
- import fr.theshark34.openauth.Authenticator;
- import fr.theshark34.openauth.model.AuthAgent;
- import fr.theshark34.openauth.model.response.AuthResponse;
- import fr.theshark34.openlauncherlib.LaunchException;
- import fr.theshark34.openlauncherlib.external.ExternalLaunchProfile;
- import fr.theshark34.openlauncherlib.external.ExternalLauncher;
- import fr.theshark34.openlauncherlib.minecraft.*;
- import fr.theshark34.supdate.BarAPI;
- import fr.theshark34.supdate.SUpdate;
- import fr.theshark34.supdate.application.integrated.FileDeleter;
- import javax.swing.*;
- import java.io.File;
- import java.util.Arrays;
- //import net.lingala.zip4j.exception.ZipException;
- //import net.lingala.zip4j.core.ZipFile;
- public final class Launcher
- {
- public static final GameVersion VERSION = new GameVersion("1.10.2", GameType.V1_8_HIGHER);
- public static final GameInfos INFOS = new GameInfos("EpicDream", VERSION, new GameTweak[]{GameTweak.FORGE});
- public static final File DIRECTORY = INFOS.getGameDir();
- public static final File CRASHS_DIR = new File(DIRECTORY, "crashlogs");
- public static LauncherFrame mainFrame;
- private static AuthInfos authinfos;
- public static void auth(String username, String password) throws AuthenticationException
- {
- if(LauncherFrame.passwordField.isVisible()) {
- Authenticator authenticator = new Authenticator(Authenticator.MOJANG_AUTH_URL, AuthPoints.NORMAL_AUTH_POINTS);
- AuthResponse response = authenticator.authenticate(AuthAgent.MINECRAFT, username, password, "");
- authinfos = new AuthInfos(response.getSelectedProfile().getName(), response.getAccessToken(), response.getSelectedProfile().getId());
- System.out.println("Auth");
- } else {
- authinfos = new AuthInfos(username, "sry", "nope");
- }
- }
- public static File getDir(String name)
- {
- String os = System.getProperty("os.name").toLowerCase();
- if (os.contains("win"))
- {
- return new File(System.getProperty("user.home") + "\\AppData\\Roaming\\" + name);
- }
- else
- {
- return os.contains("mac") ? new File(System.getProperty("user.home") + "/Library/Application Support/" + name) : new File(System.getProperty("user.home") + "/" + name);
- }
- }
- public static void update() throws Exception
- {
- mainFrame.getBar().setVisible(true);
- mainFrame.getPlay().setEnabled(false);
- mainFrame.getUsernameField().setEnabled(false);
- mainFrame.getPasswordField().setEnabled(false);
- mainFrame.getSettings().setEnabled(false);
- mainFrame.getBar().setValue(0);
- if (!DIRECTORY.exists())
- {
- DIRECTORY.mkdirs();
- }
- SUpdate su = new SUpdate(GlobalSettings.S_UPDATE_LINK.getValue(), DIRECTORY);
- su.getServerRequester().setRewriteEnabled(true);
- su.addApplication(new FileDeleter());
- Thread t = new Thread(() -> {
- int val;
- int max;
- while (true)
- {
- val = (int) (BarAPI.getNumberOfTotalDownloadedBytes() / 1000);
- max = (int) (BarAPI.getNumberOfTotalBytesToDownload() / 1000);
- Launcher.mainFrame.getBar().setMaximum(max);
- Launcher.mainFrame.getBar().setValue(val);
- }
- });
- t.start();
- su.start();
- t.interrupt();
- mainFrame.getBar().setVisible(false);
- }
- public static void launch(String username, String password) throws LaunchException
- {
- System.out.println("Online");
- ExternalLaunchProfile profile = MinecraftLauncher.createExternalProfile(INFOS, GameFolder.BASIC, authinfos);
- profile.getVmArgs().addAll(Arrays.asList(LocalSettings.getRamArg() + "", LocalSettings.JVM_ARGS.getValue()));
- profile.getArgs().addAll(Arrays.asList(LocalSettings.MC_ARGS.getValue()));
- ExternalLauncher launcher = new ExternalLauncher(profile);
- LocalSettings.USERNAME.setValue(LocalSettings.KEEP_USERNAME.getValue() ? username : "");
- LocalSettings.PASSWORD.setValue(LocalSettings.KEEP_USERNAME.getValue() ? password : "");
- LocalSettings.PROPERTIES.save();
- Process p = launcher.launch();
- if (!LocalSettings.KEEP_OPEN.getValue())
- {
- System.exit(0);
- }
- try
- {
- Thread.sleep(5000L);
- p.waitFor();
- }
- catch (InterruptedException e)
- {
- e.printStackTrace();
- }
- if (!p.isAlive())
- {
- mainFrame.getPlay().setEnabled(true);
- mainFrame.getUsernameField().setEnabled(true);
- mainFrame.getSettings().setEnabled(true);
- mainFrame.getPasswordField().setEnabled(true);
- }
- }
- public static void play(String username, String password)
- {
- if (username.replaceAll(" ", "").length() == 0 | password.replaceAll(" ", "").length() == 0)
- {
- JOptionPane.showMessageDialog(mainFrame, "Erreur veuillez entrer un pseudo valide et/ou un mot de passe valide.", "Erreur", JOptionPane.ERROR_MESSAGE);
- return;
- }
- new Thread(() -> {
- try
- {
- Launcher.update();
- }
- catch (Exception e)
- {
- try
- {
- Launcher.launch(username, password);
- }
- catch (LaunchException a)
- {
- JOptionPane.showMessageDialog(mainFrame, "Impossible d'effectuer la mise à jour, merci de nous joindre le code d'erreur suivant : Chocolat", "Erreur", JOptionPane.ERROR_MESSAGE);
- a.printStackTrace();
- }
- }
- try
- {
- Launcher.launch(username, password);
- }
- catch (LaunchException l)
- {
- JOptionPane.showMessageDialog(mainFrame, "Impossible de demarrer le jeu, merci de nous joindre le code d'erreur suivant : M&N's", "Erreur", JOptionPane.ERROR_MESSAGE);
- l.printStackTrace();
- }
- }).start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement