Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //DMS stands for Dilan's Modded Server lololol
- package com.blockhead7360.dms.program;
- import java.awt.Container;
- import java.awt.Desktop;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.HeadlessException;
- import java.awt.Image;
- import java.awt.Insets;
- import java.awt.Rectangle;
- import java.awt.Toolkit;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.WindowAdapter;
- import java.awt.event.WindowEvent;
- import java.awt.image.BufferedImage;
- import java.io.BufferedOutputStream;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.io.OutputStream;
- import java.io.PrintStream;
- import java.io.PrintWriter;
- import java.io.StringWriter;
- import java.net.HttpURLConnection;
- import java.net.MalformedURLException;
- import java.net.SocketException;
- import java.net.URI;
- import java.net.URISyntaxException;
- import java.net.URL;
- import java.net.UnknownHostException;
- import java.nio.file.Files;
- import java.nio.file.OpenOption;
- import java.nio.file.StandardOpenOption;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.Properties;
- import java.util.Random;
- import java.util.concurrent.Executors;
- import java.util.concurrent.ScheduledExecutorService;
- import java.util.concurrent.TimeUnit;
- import java.util.regex.Matcher;
- import java.util.zip.ZipEntry;
- import java.util.zip.ZipInputStream;
- import javax.imageio.ImageIO;
- import javax.mail.Authenticator;
- import javax.mail.Message;
- import javax.mail.MessagingException;
- import javax.mail.PasswordAuthentication;
- import javax.mail.Session;
- import javax.mail.Transport;
- import javax.mail.internet.InternetAddress;
- import javax.mail.internet.MimeMessage;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import javax.swing.JCheckBox;
- import javax.swing.JFileChooser;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JPanel;
- import javax.swing.JScrollPane;
- import javax.swing.JTabbedPane;
- import javax.swing.JTextArea;
- import javax.swing.JTextField;
- import javax.swing.SwingWorker;
- import javax.swing.event.ChangeEvent;
- import javax.swing.event.ChangeListener;
- import javax.swing.filechooser.FileFilter;
- import javax.swing.text.DefaultCaret;
- import org.apache.commons.net.ftp.FTP;
- import org.apache.commons.net.ftp.FTPClient;
- import org.apache.commons.net.ftp.FTPFile;
- import com.blockhead7360.dilanapi.Dialog;
- import com.blockhead7360.dilanapi.DilanAPI;
- import com.blockhead7360.dilanapi.Enums.WMLoc;
- import com.blockhead7360.dms.program.manageserver.passwordencoder.DMSLauncherPasswordEncoder;
- /*
- *
- * DMS IS DEAD! Probably won't update this program anymore.
- * EDIT: never mind I just did
- *
- * Project Description (pd upd Aug 11 2017, pd upd Aug 22 2017, pd upd Oct 23 2017):
- *
- *
- * PRE NOTICE: I was going to have this as a very small program but now it's a bit larger
- * and the code is really all over the place and unorganized (and also in 1 class idk why I did this)
- *
- * Many pieces of this code aren't being used and many pieces are repeated because I was really really lazy when I
- * started making this.
- *
- *
- * You see, I play Minecraft.
- *
- * Not only that, but MODDED Minecraft (and I have a private server).
- *
- * On top of that, I decided to make a Java Executable that launches Minecraft and syncs the mods
- * directory from the Minecraft modded client with the global directory on an FTP connection. Simple way
- * of saying that when I want to update, add, or remove a mod on my server, when other clients press Play in the launcher (java exec)
- * it'll automatically sync the mods from the FTP to the client and run peacefully.
- *
- * Java features:
- *
- * - Java Swing user interface
- *
- *
- *
- *
- * - Internet connection support! yay
- * - Reads raw text and "extracts" it idk
- * - FTP access
- * - Download files from Dropbox
- *
- * - File Transfer Protocol support with the help of apache commons net
- * - Download files to sync local folder
- * - Upload files for Manage Server feature
- * - CHAT FEATURE WOO
- *
- * - File modification (duh) but very basic and easy
- * - Delete files
- * - Write files
- * - Read files
- * lol
- * - Command Bash and Bat edit and execution
- * - Running Minecraft
- *
- *
- *
- * - Crash Report Email with javax.mail
- * - If an error is thrown (catch from a try block), either save stacktrace to a file or
- * EMAIL IT TO ME WOOOOOOOO MAGIC
- *
- *
- *
- * - Auto Program Updater
- * - Check for program updates
- * - Automatically update program to latest version.
- * - On Windows, it downloads the new version, executes it, and the new version deletes the old version.
- * - On Mac, an external updater (DMSLauncherUpdater.jar) that is saved when the program is first downlaoded
- * is run so the internal file within DMSLauncher.app can be changed)
- *
- * - Password letter to specific random picked number encoder (not really a big thing)
- *
- * And a bunch more
- *
- *
- *
- *
- * Launcher features:
- *
- *
- * - Installs full Minecraft modded client as from my Dropbox (around 497MB on Mac, around 512MB on Windows)
- * - Execute Minecraft launcher
- * - RAM Allocation changing
- * - Mods folder sync
- * - Up to date InGameInfo.xml
- * - Easy to navigate GUI (but very plain)
- * - Manage server to modify files on the FTP from the program (fast)
- * - Auto program updater
- * - Auto mods updater
- * - Show mods update summary
- * - Play without updating
- * - Play with updating
- * - Chat feature
- *
- *
- * ---------- NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE ----------
- *
- * Much if this program may be formatted weirdly because when all my computer data was lost (when I got it repaired),
- * I used JD-GUI to decompile my jar file to get all this code back. When I lost my data, I lost this entire program.
- * Thank god for the JD-GUI program thing that I found online to convert my .class files into .java files (from decompiling the jar).
- *
- * Examples of formatted weirdly:
- *
- * public void example()
- * { <------ WHAT IS THIS I DONT EVEN MAKE METHODS LIKE THAT
- *
- * }
- *
- * public void example() { <---- I PUT THE CURLY BRACKET OVER HERE (curly bracket, brace, whatever)
- *
- *
- * }
- *
- * All of this is made by myself fancy am i right yes i am right
- * Except for the fact that this is very unorganized and half of it isn't even being used
- *
- */
- public class DMSLauncher {
- /* TODO
- *
- * - Add java swing progress bar to loading screen
- * - Offline feature maybe
- * - Resizable feature maybe
- * - Make it so chat history files are encoded or cannot be edited
- *
- *
- *
- * Add to Changelog
- *
- * - Add online control thing (turning off update button from online etc)
- *
- *
- *
- */
- static String thisVer = "1.6.0.4";
- static String oldVer = "";
- static String content;
- static String splitKey;
- static JTextArea changelog;
- static JTextArea console;
- static JButton update;
- static JButton manage;
- static JButton ramAllocation;
- static Container cont;
- static JTabbedPane tabs;
- static JLabel updlabel;
- //static JButton webSave;
- //static JTextField webField;
- //static List<InstallFile> fileinstalls;
- //static String ver;
- //static String verser;
- static String prgmUpdateTo;
- static String prgmDownload;
- static String prgmPath;
- static JLabel updatetext;
- static JFrame frame;
- static JFrame frameu;
- static JFrame framex;
- static JTextArea chatBox;
- static JTextField chatField;
- static JButton chatSend;
- static JLabel chatSending;
- static boolean chatVisible = false;
- static String clientPath;
- static String web;
- //static List<String> logHistory;
- //static List<String> fileHistory;
- static String fontType;
- static String fontType2;
- //static List<String> deleteIfExist;
- //static Map<String, String> installMods;
- static String changelogstr;
- static String imageUrl = "https://i.imgur.com/OtOShOj.png";
- static List<String> delete, install;
- static FTPClient client;
- static Map<String, String> remotesettings = new HashMap<String, String>();
- static String baseMinecraft;
- static String baseminecraftWindows;
- static String password;
- static String igi;
- //static String host = "modded.blockhead7360.com";
- static String host = "ftp.drivehq.com";
- static int port = 21;
- //static String user = "Blockhead7360.26120";
- //static String pass = "NOT TELLING";
- static String emailpass = "NOT TELLING";
- static String user = "DilanFTP";
- static String pass = "NOT TELLING";
- static String chat_user;
- static List<String> currentChatHist;
- static List<String> totalChatHist;
- public static void saveFile(URL url, String file)
- throws IOException
- {
- InputStream in = url.openStream();
- FileOutputStream fos = new FileOutputStream(new File(file));
- int length = -1;
- byte[] buffer = new byte[4096];
- while ((length = in.read(buffer)) > -1) {
- fos.write(buffer, 0, length);
- }
- fos.close();
- in.close();
- }
- /*public static JsonObject authMinecraft(String username, String pass){
- String result = "";
- try {
- result = AuthMinecraft.httpRequest(new URL("https://authserver.mojang.com/authenticate"), AuthMinecraft.MakeJSONRequest(username, pass));
- } catch (MalformedURLException e) {
- crashReport(e);
- } catch (Exception e) {
- crashReport(e);
- }
- //{"accessToken":"e026bc59c67644639b8b8893d9a87976","clientToken":"8eaa5aab20b44dccae26fd3d32d04327","selectedProfile":{"id":"472d43365da741eb9c0493e489a70419","name":"Blockhead7360"},"availableProfiles":[{"id":"472d43365da741eb9c0493e489a70419","name":"Blockhead7360"}]}
- JsonReader reader = Json.createReader(new StringReader(result));
- JsonObject info = reader.readObject();
- reader.close();
- return info;
- }*/
- public static boolean isInternetThere()
- {
- try {
- URL url = new URL("http://www.google.com");
- HttpURLConnection urlConnect = (HttpURLConnection)url.openConnection();
- urlConnect.getContent();
- } catch (UnknownHostException e) {
- return false;
- }
- catch (IOException e) {
- return false;
- }
- return true;
- }
- public static void saveFileProgress(URL url, String file)
- throws IOException
- {
- InputStream in = url.openStream();
- FileOutputStream fos = new FileOutputStream(new File(file));
- HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection();
- long filesize = httpConnection.getContentLengthLong();
- long downloaded = 0;
- console.append("Downloaded " + (downloaded / 1000000) + " MB / " + (filesize/1000000) + " MB");
- int length = -1;
- byte[] buffer = new byte[4096];
- while ((length = in.read(buffer)) > -1) {
- console.setText(console.getText().replaceAll("Downloaded " + (downloaded/1000000) + " MB", "Downloaded " + ((downloaded + length)/1000000) + " MB"));
- downloaded += length;
- fos.write(buffer, 0, length);
- }
- fos.close();
- in.close();
- }
- public static boolean isWindows(){
- return !(System.getProperty("os.name").contains("mac") || System.getProperty("os.name").contains("Mac"));
- }
- static boolean manage_cont = false;
- public static void beginStart(){
- framex = new JFrame("DMSLauncher is starting...");
- framex.setMinimumSize(new Dimension(500, 100));
- framex.setPreferredSize(new Dimension(500, 100));
- framex.setMaximumSize(new Dimension(500, 100));
- framex.setDefaultCloseOperation(0);
- framex.setLocationRelativeTo(null);
- framex.setResizable(false);
- Container panex = new Container();
- framex.setLayout(null);
- panex.setLayout(null);
- JLabel labelx = new JLabel("DMSLauncher v" + thisVer + " is loading. Please wait...", 0);
- labelx.setFont(new Font(fontType, 1, 16));
- labelx.setBounds(new Rectangle(0, -30, 500, 100));
- panex.add(labelx);
- JLabel creditx = new JLabel("Created by Dilan Nair - http://blockhead7360.com", 0);
- creditx.setFont(new Font("arial", 2, 12));
- creditx.setBounds(new Rectangle(0, 30, 500, 40));
- panex.add(creditx);
- JLabel extrainfox = new JLabel("Some files will need to be downloaded.", 0);
- extrainfox.setFont(new Font("arial", Font.BOLD, 12));
- extrainfox.setBounds(new Rectangle(0, 45, 500, 40));
- if (!new File(basepath, "DMSLauncherUpdater.jar").exists()){
- panex.add(extrainfox);
- }
- framex.setContentPane(panex);
- framex.setVisible(true);
- }
- public DMSLauncher(String consoles)
- {
- /*UnZipper zipper = new UnZipper();
- try {
- zipper.unzip("/Users/dilan/Desktop/Test.zip", "/Users/dilan/Desktop/Inside");
- } catch (IOException e1) {
- e1.printStackTrace();
- }*/
- if (!isInternetThere()) {
- int val = JOptionPane.showOptionDialog(null, "Looks like you do not have internet connection!\nWithout internet, the DMSLauncher\'s update, chat, and server modification features cannot be used.\n\nHowever, you can run the modded client offline without checking for updates.\nPress your enter key (or click \'Play Offline\') to run the modded client offline or click on \'Cancel\' to shut down the DMSLauncher.", "No Internet Connection", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE, null, new Object[] {"Play Offline", "Cancel"}, "Play Offline");
- if (val == 0) {
- playNoInternet();
- }else {
- System.exit(0);
- }
- return;
- }
- cont = new Container();
- tabs = new JTabbedPane();
- tabs.setBounds(new Rectangle(0, 100, 1000, 580));
- tabs.addChangeListener(new ChangeListener() {
- @Override
- public void stateChanged(ChangeEvent e) {
- if (tabs.getSelectedIndex() != 1) {
- chatVisible = false;
- }else {
- chatVisible = true;
- }
- if (tabs.getSelectedIndex() == 3 && manage_cont) {
- manage_cont = false;
- return;
- }
- if (tabs.getSelectedIndex() == 3 && !manage_cont) {
- tabs.setSelectedIndex(0);
- manage(false, false);
- return;
- }
- if (tabs.getSelectedIndex() == 1 && remotesettings.containsKey("DisableChat")) {
- tabs.setSelectedIndex(0);
- canUseFeature("DisableChat");
- return;
- }
- }
- });
- if (!isWindows()){
- fontType = "monaco";
- splitKey = "/";
- }
- else {
- fontType = "consolas";
- splitKey = "\\\\";
- }
- basepath = (new File(new JFileChooser().getFileSystemView().getDefaultDirectory(), "Documents" + splitKey + "DMSUpdater")).getPath();
- fontType2 = fontType;
- beginStart();
- client = new FTPClient();
- pause(1000L);
- clientPath = "";
- web = "";
- changelogstr = "";
- console = new JTextArea(consoles);
- loadFolder();
- deleteOldVersion();
- pause(1000L);
- readScript();
- setupScript();
- loadFrame();
- setupChat();
- startThread();
- settings();
- prepareManage();
- finishFrame();
- framex.setVisible(false);
- framex.dispose();
- try
- {
- checkForUpdates();
- }
- catch (MalformedURLException e)
- {
- crashReport(e);
- return;
- }
- catch (IOException e)
- {
- crashReport(e);
- return;
- }
- }
- public static void deleteOldVersion()
- {
- if (oldVer.equals(thisVer)) {
- return;
- }
- File dir = new File(program_jar.getPath());
- if (dir.exists())
- {
- File[] arrayOfFile;
- int j = (arrayOfFile = dir.listFiles()).length;
- for (int i = 0; i < j; i++)
- {
- File f = arrayOfFile[i];
- if (f.getName().startsWith("DMS Launcher " + oldVer) && f.getName().endsWith(".jar")) {
- f.delete();
- }
- }
- }
- }
- public static void main(String[] args)
- {
- new DMSLauncher("");
- }
- public static void setupScript()
- {
- }
- public static void clearFile(File file)
- {
- try
- {
- PrintWriter writer = new PrintWriter(file);
- writer.close();
- }
- catch (FileNotFoundException e)
- {
- crashReport(e);
- return;
- }
- }
- /*public static void setPath()
- {
- boolean cont = false;
- File parent = null;
- if ((new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Documents" + splitKey + "Curse")).exists()){
- if ((new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Documents" + splitKey + "Curse" + splitKey + "Minecraft" + splitKey + "Instances")).exists()){
- cont = true;
- parent = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Documents" + splitKey + "Curse" + splitKey + "Minecraft" + splitKey + "Instances");
- }
- }
- if ((new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Curse")).exists()){
- if ((new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Curse" + splitKey + "Minecraft" + splitKey + "Instances")).exists()){
- cont = true;
- parent = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Curse" + splitKey + "Minecraft" + splitKey + "Instances");
- }
- }
- if (cont){
- List<Object> options = new ArrayList<Object>();
- for (File f : parent.listFiles()){
- if (f.isDirectory()){
- options.add(f.getName());
- }
- }
- Object s = JOptionPane.showInputDialog(frame, "Select an installed mod pack from below...", "Automatic Path Setter", JOptionPane.QUESTION_MESSAGE, null, options.toArray(), options.get(0));
- if (s == null){
- return;
- }
- }
- if (!cont){
- int i = JOptionPane.showOptionDialog(frame, "The Twitch app is not installed on this computer. You must manually set your mods folder.", "Automatic Path Setter", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, new Object[]{"Manually Set Folder", "Cancel"}, "Manually Set Folder");
- if (i == JOptionPane.NO_OPTION){
- return;
- }
- }
- String key;
- if ((System.getProperty("os.name").contains("mac")) || (System.getProperty("os.name").contains("Mac"))) {
- key = "/";
- } else {
- key = "\\\\";
- }
- JFileChooser fc = new JFileChooser();
- fc.setCurrentDirectory(new File(clientPath));
- fc.setFileSelectionMode(1);
- fc.setDialogTitle("Find and select the mods folder for the mod pack");
- int val = fc.showDialog(frame, "Set Path");
- if (val == 0)
- {
- File file = fc.getSelectedFile();
- if (file.getPath().split(key)[(file.getPath().split(key).length - 1)].equals(file.getPath().split(key)[(file.getPath().split(key).length - 2)]))
- {
- String[] paths = file.getPath().split(key);
- int length = paths.length;
- paths[(length - 1)] = "";
- String path = "";
- String[] arrayOfString1;
- int j = (arrayOfString1 = paths).length;
- for (int i = 0; i < j; i++)
- {
- String x = arrayOfString1[i];
- path = path + key + x;
- }
- if (path.startsWith(key + key)) {
- path = path.replaceFirst(key, "");
- }
- if (path.endsWith(key))
- {
- int l = path.length();
- path = path.substring(0, l - 1);
- }
- file = new File(path);
- }
- File pathFile = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Documents" + splitKey + "DMSUpdater", "path.txt");
- try
- {
- clearFile(pathFile);
- Files.write(pathFile.toPath(), file.getPath().getBytes(), new OpenOption[] { StandardOpenOption.CREATE });
- }
- catch (IOException e1)
- {
- crashReport(e1);
- return;
- }
- clientPath = file.getPath().toString();
- console.append("\n\nMods directory changed: \n" + clientPath);
- loadInstallFiles();
- }
- }
- */
- public static void checkForUpdates()
- throws MalformedURLException, IOException
- {
- URL home = new URL("http://blockhead7360.com/dmsucheckforupdates");
- BufferedReader in2 = new BufferedReader(new InputStreamReader(home.openStream()));
- List<String> list2 = new ArrayList<String>();
- String str2;
- while ((str2 = in2.readLine()) != null)
- {
- list2.add(str2);
- }
- in2.close();
- String content2 = list2.toString().split("iiStartProgramii-")[1].split("iiEndProgramii")[0];
- URL find = new URL(content2);
- BufferedReader in = new BufferedReader(new InputStreamReader(find.openStream()));
- List<String> list = new ArrayList<String>();
- String str;
- while ((str = in.readLine()) != null)
- {
- list.add(str);
- }
- in.close();
- String content = list.toString().split("iiStartProgramii-")[1].split("iiEndProgramii")[0];
- String verload = content.split("iiVersionii-")[1].split("iiStopii-")[0];
- String changelogload = content.split("iiChangelogii-")[1].split("iiStopii-")[0];
- changelogload = changelogload.replaceAll("iiNLii", "\n");
- String downloadload = content.split("iiDownloadii-")[1].split("iiStopii-")[0];
- if (!thisVer.equals(verload))
- {
- frameu = new JFrame("DMSLauncher program update available!");
- frameu.setPreferredSize(new Dimension(400, 600));
- frameu.setMaximumSize(new Dimension(400, 600));
- frameu.setMinimumSize(new Dimension(400, 600));
- frameu.setDefaultCloseOperation(2);
- frameu.setResizable(false);
- frameu.setLocationRelativeTo(null);
- Container pane = new Container();
- frameu.setLayout(null);
- JLabel label = new JLabel("A new version of DMSLauncher is available!", 0);
- label.setFont(new Font("arial", 1, 18));
- label.setBounds(new Rectangle(0, 10, 400, 30));
- pane.add(label);
- JTextArea area = new JTextArea();
- area.setFont(new Font(fontType, 0, 14));
- area.setEditable(false);
- area.setText(changelogload);
- JScrollPane scroll = new JScrollPane(area);
- scroll.setBounds(new Rectangle(10, 55, 380, 470));
- pane.add(scroll);
- JButton button = new JButton("Update this program to v" + verload);
- button.setFont(new Font(fontType, 0, 12));
- button.setBounds(new Rectangle(50, 530, 300, 35));
- prgmUpdateTo = verload;
- prgmDownload = downloadload;
- button.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- if (!isWindows())
- DMSLauncher.externalUpdateProgram();
- else{
- SwingWorker<String, String> worker2 = new SwingWorker<String, String>()
- {
- protected String doInBackground()
- {
- updateProgram();
- return null;
- }
- };
- worker2.execute();
- }
- }
- });
- pane.add(button);
- frameu.setContentPane(pane);
- frameu.setVisible(true);
- }
- }
- static File program_jar = new File(new JFileChooser().getFileSystemView().getDefaultDirectory(), "Documents/DMSUpdater/programjar");
- public static void externalUpdateProgram(){
- if (!isWindows()){
- try {
- Desktop.getDesktop().open(new File(basepath, "DMSLauncherUpdater.jar"));
- } catch (IOException e) {
- crashReport(e);
- }
- saveAndExit();
- return;
- }
- }
- public static void updateProgram()
- {
- frameu.setVisible(false);
- frameu.dispose();
- frame.setVisible(false);
- frame.dispose();
- JFrame updating = new JFrame("Updating DMSLauncher to v" + prgmUpdateTo);
- updating.setPreferredSize(new Dimension(400, 100));
- updating.setMaximumSize(new Dimension(400, 100));
- updating.setMinimumSize(new Dimension(400, 100));
- updating.setDefaultCloseOperation(0);
- updating.setResizable(false);
- updating.setLocationRelativeTo(null);
- Container pane = new Container();
- updating.setLayout(null);
- updlabel = new JLabel("Downloading new version...", 0);
- updlabel.setFont(new Font("arial", 1, 18));
- updlabel.setBounds(new Rectangle(0, 20, 400, 40));
- pane.add(updlabel);
- updating.setContentPane(pane);
- updating.setVisible(true);
- boolean pause = true;
- long old = System.currentTimeMillis();
- while (pause) {
- if (System.currentTimeMillis() - old > 1000L) {
- pause = false;
- }
- }
- try
- {
- saveFile(new URL(prgmDownload), program_jar + "/DMS Launcher " + prgmUpdateTo + ".jar");
- }
- catch (MalformedURLException e)
- {
- crashReport(e);
- return;
- }
- catch (IOException e)
- {
- crashReport(e);
- return;
- }
- boolean pausex = true;
- long oldx = System.currentTimeMillis();
- while (pausex) {
- if (System.currentTimeMillis() - oldx > 1000L) {
- pausex = false;
- }
- }
- try
- {
- Desktop.getDesktop().open(new File(program_jar + "/DMS Launcher " + prgmUpdateTo + ".jar"));
- }
- catch (IOException e)
- {
- crashReport(e);
- return;
- }
- saveAndExit();
- }
- public static void readScript()
- {
- URL home = null;
- BufferedReader in;
- try
- {
- home = new URL("http://blockhead7360.com/" + web);
- }
- catch (MalformedURLException ex)
- {
- crashReport(ex);
- return;
- }
- try
- {
- in = new BufferedReader(new InputStreamReader(home.openStream()));
- }
- catch (IOException ex)
- {
- crashReport(ex);
- return;
- }
- List<String> list = new ArrayList<String>();
- try
- {
- String str;
- while ((str = in.readLine()) != null)
- {
- list.add(str);
- }
- }
- catch (IOException e)
- {
- crashReport(e);
- }
- try
- {
- in.close();
- }
- catch (IOException e)
- {
- crashReport(e);
- }
- String content2 = list.toString().split("iiStartScriptii-")[1].split("iiEndScriptii")[0];
- URL home2 = null;
- try
- {
- home2 = new URL(content2);
- }
- catch (MalformedURLException ex)
- {
- crashReport(ex);
- return;
- }
- BufferedReader in2 = null;
- try
- {
- in2 = new BufferedReader(new InputStreamReader(home2.openStream()));
- }
- catch (IOException ex)
- {
- crashReport(ex);
- }
- List<String> list2 = new ArrayList<String>();
- try
- {
- String str2;
- while ((str2 = in2.readLine()) != null)
- {
- list2.add(str2);
- }
- }
- catch (IOException e)
- {
- crashReport(e);
- }
- try
- {
- in2.close();
- }
- catch (IOException e)
- {
- crashReport(e);
- }
- content = list2.toString().split("iiStartScriptii-")[1].split("iiEndScriptii")[0];
- String changelogload = content.split("iiChangelogii-")[1].split("iiStopii-")[0];
- changelogstr = changelogload.replaceAll("iiNLii", "\n");
- String passwordload = content.split("iiTypeii-")[1].split("iiStopii-")[0];
- password = DMSLauncherPasswordEncoder.decode(passwordload);
- String baseminecraftload = content.split("iiBaseMinecraftii-")[1].split("iiStopii-")[0];
- baseMinecraft = baseminecraftload;
- String baseminecraftwinload = content.split("iiBaseMinecraftWinii-")[1].split("iiStopii-")[0];
- baseminecraftWindows = baseminecraftwinload;
- if (content.contains("iiRemoteSettingsii")) {
- String remotesettingsload = content.split("iiRemoteSettingsii-")[1].split("iiStopii-")[0];
- if (remotesettingsload.contains("iiDiffSettingii")) {
- String[] rsload_split = remotesettingsload.split("iiDiffSettingii");
- for (String j : rsload_split) {
- String[] j_split = j.split("iiSii");
- remotesettings.put(j_split[0], j_split[1]);
- }
- }
- else {
- String[] j_split = remotesettingsload.split("iiSii");
- remotesettings.put(j_split[0], j_split[1]);
- }
- }
- String igiload = content.split("iiIGIii-")[1].split("iiStopii-")[0];
- igi = igiload;
- String updaterload = content.split("iiUpdaterii-")[1].split("iiStopii-")[0];
- if (!new File(basepath, "DMSLauncherUpdater.jar").exists()){
- try {
- saveFile(new URL(updaterload), new File(basepath, "DMSLauncherUpdater.jar").getPath());
- } catch (IOException e) {
- crashReport(e);
- }
- }
- }
- public static void reconnectFTP(){
- try {
- if (client == null){
- client = new FTPClient();
- }
- client.connect(host, port);
- client.login(user, pass);
- client.enterLocalPassiveMode();
- client.setFileType(FTP.BINARY_FILE_TYPE);
- } catch (SocketException e) {
- crashReport(e);
- } catch (IOException e) {
- crashReport(e);
- }
- }
- public static void checkUpdatesFromFTP(){
- disableFrame();
- updatetext.setText("Checking for updates...");
- FTPClient ftpclient = new FTPClient();
- try{
- console.append("Connecting to FTP server...\n\n");
- ftpclient.connect(host, port);
- console.append("Logging in to FTP server...\n\n");
- ftpclient.login(user, pass);
- console.append("Connected!\n\n\n");
- ftpclient.enterLocalPassiveMode();
- ftpclient.setFileType(FTP.BINARY_FILE_TYPE);
- client = ftpclient;
- ftpclient.changeWorkingDirectory("/DMSLauncher");
- FTPFile[] away = ftpclient.listFiles();
- File[] home = (new File(basepath, "Game/mods")).listFiles();
- List<String> client = new ArrayList<String>();
- List<String> server = new ArrayList<String>();
- console.append("Checking for updates...\n\n");
- for (File f : home){
- if (!f.getName().contains("DS_Store")){
- client.add(f.getName());
- }
- }
- for (FTPFile f : away){
- if (!f.getName().contains("DS_Store")){
- server.add(f.getName());
- }
- }
- updatetext.setText(" ");
- enableFrame();
- if (client.size() != server.size()){
- console.append("An update is available.\n\n");
- summaryAndConfirmUpdate(client, server);
- }else{
- console.append("No update available.\n\n");
- play();
- }
- }catch(IOException ex){
- crashReport(ex);
- }
- }
- public static void appendConsole(String txt)
- {
- console.append(txt);
- }
- static boolean inThreadedProcess = false;
- public static void startThread(){
- Runnable r = new Runnable(){
- public void run(){
- if (!inThreadedProcess){
- inThreadedProcess = true;
- if (!chat_user.equalsIgnoreCase("None") && !chat_user.equalsIgnoreCase("Not Logged In")){
- if (!client.isConnected()) reconnectFTP();
- try {
- client.changeWorkingDirectory("/DMSLauncherChat/" + chat_user);
- } catch (IOException e) {
- crashReport(e);
- }
- try {
- FTPFile[] unread = client.listFiles();
- if (unread.length >= 1){
- for (FTPFile f : unread){
- File temp1 = new File(basepath, "Chat/Connection");
- if (!temp1.exists()) temp1.mkdir();
- File temp2 = new File(basepath, "Chat/Connection/Download");
- if (!temp2.exists()) temp2.mkdir();
- OutputStream os = new BufferedOutputStream(new FileOutputStream(new File(basepath, "Chat/Connection/Download/reading.txt")));
- InputStream is = client.retrieveFileStream(f.getName());
- byte[] bytes = new byte[4096];
- int byteread = -1;
- while ((byteread = is.read(bytes)) != -1){
- os.write(bytes, 0, byteread);
- }
- client.completePendingCommand();
- os.close();
- is.close();
- String s = Files.readAllLines(new File(basepath, "Chat/Connection/Download/reading.txt").toPath()).get(0);
- pause(100L);
- client.deleteFile(f.getName());
- new File(basepath, "Chat/Connection/Download/reading.txt").delete();
- totalChatHist.add(s);
- SwingWorker<String, String> worker = new SwingWorker<String, String>(){
- protected String doInBackground(){
- chatBox.setText(fromListChat(totalChatHist));
- return null;
- }
- };
- worker.execute();
- }
- }
- } catch (FileNotFoundException e) {
- crashReport(e);
- } catch (IOException e) {
- return;
- }
- if (chatVisible){
- currentChatHist.clear();
- currentChatHist.addAll(totalChatHist);
- }
- int notification = totalChatHist.size() - currentChatHist.size();
- SwingWorker<String, String> worker = new SwingWorker<String, String>(){
- protected String doInBackground(){
- tabs.setTitleAt(1, (notification <= 0 ? "Chat" : "Chat (" + notification + ")"));
- return null;
- }
- };
- worker.execute();
- }
- inThreadedProcess = false;
- }
- }
- };
- ScheduledExecutorService ex = Executors.newSingleThreadScheduledExecutor();
- ex.scheduleAtFixedRate(r, 0, 3, TimeUnit.SECONDS);
- }
- static Exception exinfo;
- static URL sfp_url;
- static String sfp_file;
- public static void setupChat(){
- JPanel pane = new JPanel();
- pane.setLayout(null);
- chatBox = new JTextArea();
- chatBox.setMargin(new Insets(10, 10, 10, 10));
- chatBox.setBounds(new Rectangle(25, 25, 800-50, 400));
- chatBox.setFont(new Font(fontType, Font.PLAIN, 14));
- chatBox.setEditable(false);
- chatBox.setText(fromListChat(totalChatHist));
- chatBox.setCaretPosition(chatBox.getText().length());
- chatBox.setVisible(true);
- DefaultCaret caret = (DefaultCaret) chatBox.getCaret();
- caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
- JScrollPane chatBoxPane = new JScrollPane(chatBox);
- chatBoxPane.setBounds(new Rectangle(5, 5, 970, 480));
- pane.add(chatBoxPane);
- chatField = new JTextField();
- chatField.setBounds(new Rectangle(25+100, 495, 800-50, 30));
- chatField.setVisible(true);
- pane.add(chatField);
- chatSend = new JButton((chat_user.equalsIgnoreCase("None") ? "Log In" : "Send"));
- chatSend.setBounds(new Rectangle(1000-90-25, 495, 90, 30));
- chatSend.setToolTipText((chat_user.equalsIgnoreCase("None") ? "Enter your login ID in the text field and press enter or this button to log in." : "Enter a message in the text field and press enter or this button to send."));
- chatSend.setVisible(true);
- ActionListener al = new ActionListener(){
- public void actionPerformed(ActionEvent e){
- SwingWorker<String, String> worker = new SwingWorker<String, String>(){
- protected String doInBackground(){
- if (chatField.getText() == null || chatField.getText().isEmpty()){
- if (chat_user.equalsIgnoreCase("None")){
- JOptionPane.showMessageDialog(null, "Please provide your login ID to log in to the chat servers.", "Error Logging In", JOptionPane.ERROR_MESSAGE);
- return null;
- }
- return null;
- }
- if (chat_user.equalsIgnoreCase("None")){
- chatSending.setText("Logging in...");
- if (!client.isConnected()) reconnectFTP();
- try {
- client.changeWorkingDirectory("/DMSLauncherChat");
- FTPFile[] list = client.listDirectories();
- for (FTPFile f : list){
- if (f.getName().split("ii")[0].equalsIgnoreCase(chatField.getText())){
- chat_user = f.getName();
- File chatLoginFile = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Documents" + splitKey + "DMSUpdater" + splitKey + "Chat", "chatLogin.txt");
- clearFile(chatLoginFile);
- Files.write(chatLoginFile.toPath(), f.getName().getBytes(), new OpenOption[] { StandardOpenOption.CREATE });
- chatSending.setText("Logged in as " + chat_user.split("ii")[1]);
- chatField.setText("");
- return null;
- }
- }
- chatField.setText("");
- chatSending.setText("Not logged in");
- JOptionPane.showMessageDialog(null, "This login ID does not exist! Try again.", "Error Logging In", JOptionPane.ERROR_MESSAGE);
- return null;
- } catch (IOException e1) {
- crashReport(e1);
- }
- return null;
- }
- if (chatField.getText().startsWith("/")){
- String cmd = chatField.getText();
- if (cmd.equalsIgnoreCase("/help")){
- String s = "";
- List<String> list = new ArrayList<String>();
- list.add("NO COMMANDS YET. Idk if I really want to add this feature.");
- for (String x : list){
- s += x + "\n";
- }
- JOptionPane.showMessageDialog(null, "The following commands are available for use:\n\n" + s);
- chatField.setText("");
- return null;
- }
- chatField.setText("");
- JOptionPane.showMessageDialog(null, "Unknown command. Type \'/help\' for help.", "Unknown Command", JOptionPane.ERROR_MESSAGE);
- return null;
- }
- sendChat(chatField.getText());
- chatField.setText("");
- return null;
- }
- };
- worker.execute();
- }
- };
- chatSend.addActionListener(al);
- chatField.addActionListener(al);
- pane.add(chatSend);
- chatSending = new JLabel((chat_user.equalsIgnoreCase("None") ? "Not logged in" : "Logged in as " + chat_user.split("ii")[1]), 0);
- chatSending.setFont(new Font("arial", Font.BOLD, 12));
- chatSending.setBounds(new Rectangle(0, 495, 125, 30));
- pane.add(chatSending);
- tabs.addTab("Chat", null, pane, "Chat with other clients");
- }
- /*public static void chat(){
- chatFrame.setVisible(true);
- chatVisible = true;
- currentChatHist.clear();
- currentChatHist.addAll(totalChatHist);
- chat.setText("Chat");
- }*/
- public static String fromListChat(List<String> list){
- String s = "";
- for (String x : list){
- s += x + "\n\n";
- }
- return s;
- }
- public static String getRandomString(){
- String j = "abcdefghijklmnopqrstuvwxyz1234567890";
- String total = "";
- Random r = new Random();
- for (int i = 0; i < 32; i++){
- total += Character.toString(j.charAt(r.nextInt(36)));
- }
- return total;
- }
- static int sendError = 0;
- public static void sendChat(String message){
- if (message.isEmpty()) return;
- SwingWorker<String, String> worker = new SwingWorker<String, String>(){
- protected String doInBackground() {
- inThreadedProcess = true;
- if (!client.isConnected()) reconnectFTP();
- chatSending.setText("Sending...");
- chatField.setEnabled(false);
- chatSend.setEnabled(false);
- try {
- client.changeWorkingDirectory("/DMSLauncherChat");
- File temp1 = new File(basepath, "Chat/Connection");
- if (!temp1.exists()) temp1.mkdir();
- File temp2 = new File(basepath, "Chat/Connection/Upload");
- if (!temp2.exists()) temp2.mkdir();
- File f = new File(basepath, "Chat/Connection/Upload/writing.txt");
- if (!f.exists()) f.createNewFile();
- List<String> test = new ArrayList<String>();
- test.add((chat_user.split("ii")[1] + " > " + message));
- Files.write(f.toPath(), test, StandardOpenOption.CREATE);
- FTPFile[] dir = client.listDirectories();
- for (FTPFile fx : dir){
- if (fx.getName().equals(chat_user)) continue;
- client.changeWorkingDirectory("/DMSLauncherChat/" + fx.getName());
- InputStream is = new FileInputStream(f);
- OutputStream os = client.storeFileStream(getRandomString() + ".txt");
- byte[] bytes = new byte[4096];
- int read = 0;
- while ((read = is.read(bytes)) != -1){
- os.write(bytes, 0, read);
- }
- is.close();
- os.close();
- client.completePendingCommand();
- }
- new File(basepath, "Chat/Connection/Upload/writing.txt").delete();
- chatSending.setText("Logged in as " + chat_user.split("ii")[1]);
- chatField.setEnabled(true);
- chatSend.setEnabled(true);
- sendError = 0;
- } catch (FileNotFoundException e) {
- crashReport(e);
- } catch (IOException e) {
- chatSending.setText("FTP error!");
- pause(1000L);
- chatSending.setText("Trying again...");
- pause(1000L);
- if (sendError == 3){
- JOptionPane.showMessageDialog(null, "Your chat message was attempted to be sent 3 times, each resulting in an FTP error.\n\nPress \'Okay\' to report the error. You can try waiting for some time and then send the message again.", "Repeated FTP/IOException Error", JOptionPane.ERROR_MESSAGE);
- totalChatHist.add("(not sent) " + chat_user.split("ii")[1] + " > " + message);
- currentChatHist.clear();
- currentChatHist.addAll(totalChatHist);
- chatBox.setText(fromListChat(totalChatHist));
- inThreadedProcess = false;
- return null;
- }else{
- sendError++;
- sendChat(message);
- return null;
- }
- }
- totalChatHist.add(chat_user.split("ii")[1] + " > " + message);
- currentChatHist.clear();
- currentChatHist.addAll(totalChatHist);
- chatBox.setText(fromListChat(totalChatHist));
- inThreadedProcess = false;
- return null;
- }
- };
- worker.execute();
- }
- public static void play(){
- /*UnZipper unzip = new UnZipper();
- try {
- unzip.unzip("/Users/dilan/Desktop/MCFiles.zip", "/Users/dilan/Desktop/Extracted");
- } catch (IOException e) {
- e.printStackTrace();
- }
- pause();*/
- SwingWorker<String, String> worker6 = new SwingWorker<String, String>(){
- protected String doInBackground(){
- playGo();
- return null;
- }
- };
- worker6.execute();
- }
- public static void playNoInternet(){
- /*UnZipper unzip = new UnZipper();
- try {
- unzip.unzip("/Users/dilan/Desktop/MCFiles.zip", "/Users/dilan/Desktop/Extracted");
- } catch (IOException e) {
- e.printStackTrace();
- }
- pause();*/
- SwingWorker<String, String> worker6 = new SwingWorker<String, String>(){
- protected String doInBackground(){
- playWithoutInternet();
- return null;
- }
- };
- worker6.execute();
- }
- public static void playWithoutInternet(){
- if (new File(new File(basepath, "Game"), "runMC" + (isWindows() ? ".bat" : ".command")).exists()){
- new File(new File(basepath, "Game"), "runMC" + (isWindows() ? ".bat" : ".command")).delete();
- }
- if (isWindows()){
- List<String> runcmd = new ArrayList<String>();
- String path = new File(basepath, "Game").getPath();
- runcmd.add("cd " + path);
- runcmd.add("start \"\" MinecraftLauncher.exe --workDir " + path);
- runcmd.add("exit");
- try {
- new File(new File(basepath, "Game"), "runMC.bat").createNewFile();
- Files.write(new File(basepath, "Game/runMC.bat").toPath(), runcmd, StandardOpenOption.CREATE);
- } catch (IOException e) {
- crashReport(e);
- }
- }else{
- List<String> runcmd = new ArrayList<String>();
- String path = new File(basepath, "Game").getPath();
- runcmd.add("cd " + path);
- runcmd.add("chmod +x " + path + "/Minecraft.app/Contents/MacOS/launcher");
- runcmd.add("open Minecraft.app --args --workDir " + path);
- runcmd.add("osascript -e \"do shell script \\\"osascript -e \\\\\\\"tell application \\\\\\\\\\\\\\\"Terminal\\\\\\\\\\\\\\\" to quit\\\\\\\" &> /dev/null &\\\"\"; exit");
- try {
- Files.write(new File(basepath, "Game/runMC.command").toPath(), runcmd, StandardOpenOption.CREATE);
- } catch (IOException e) {
- crashReport(e);
- }
- }
- pause(500L);
- if (!isWindows()){
- try {
- Runtime.getRuntime().exec("chmod +x " + basepath + "/Game/runMC.command");
- pause(500L);
- Desktop.getDesktop().open(new File(basepath, "Game/runMC.command"));
- } catch (IOException e) {
- crashReport(e);
- }
- }else{
- try{
- Desktop.getDesktop().open(new File(basepath, "Game/runMC.bat"));
- }catch(IOException e){
- crashReport(e);
- }
- }
- pause(1000L);
- System.exit(0);
- }
- public static void playGo(){
- disableFrame();
- console.append("\nRefreshing InGameInfo.xml...\n\n");
- try {
- saveFile(new URL(igi), new File(basepath, "Game/config/InGameInfo.xml").getPath());
- } catch (MalformedURLException e1) {
- crashReport(e1);
- } catch (IOException e1) {
- crashReport(e1);
- }
- pause(500L);
- console.append("\nRefreshing runMC" + (isWindows() ? ".bat" : ".command") + "...\n\n");
- console.append("Creating run command file...\n\n");
- if (new File(new File(basepath, "Game"), "runMC" + (isWindows() ? ".bat" : ".command")).exists()){
- new File(new File(basepath, "Game"), "runMC" + (isWindows() ? ".bat" : ".command")).delete();
- }
- if (isWindows()){
- List<String> runcmd = new ArrayList<String>();
- String path = new File(basepath, "Game").getPath();
- runcmd.add("cd " + path);
- runcmd.add("start \"\" MinecraftLauncher.exe --workDir " + path);
- runcmd.add("exit");
- try {
- Files.write(new File(new File(basepath, "Game"), "runMC.bat").toPath(), runcmd, StandardOpenOption.CREATE);
- } catch (IOException e) {
- crashReport(e);
- }
- }else{
- List<String> runcmd = new ArrayList<String>();
- String path = new File(basepath, "Game").getPath();
- runcmd.add("cd " + path);
- runcmd.add("chmod +x " + path + "/Minecraft.app/Contents/MacOS/launcher");
- runcmd.add("open Minecraft.app --args --workDir " + path);
- runcmd.add("osascript -e \"do shell script \\\"osascript -e \\\\\\\"tell application \\\\\\\\\\\\\\\"Terminal\\\\\\\\\\\\\\\" to quit\\\\\\\" &> /dev/null &\\\"\"; exit");
- try {
- Files.write(new File(new File(basepath, "Game"), "runMC.command").toPath(), runcmd, StandardOpenOption.CREATE);
- } catch (IOException e) {
- crashReport(e);
- }
- }
- pause(500L);
- console.append("\nOpening Minecraft launcher...");
- if (!isWindows()){
- try {
- Runtime.getRuntime().exec("chmod +x " + basepath + "/Game/runMC.command");
- pause(500L);
- Desktop.getDesktop().open(new File(basepath, "Game/runMC.command"));
- } catch (IOException e) {
- crashReport(e);
- }
- }else{
- try{
- Desktop.getDesktop().open(new File(basepath, "Game/runMC.bat"));
- }catch(IOException e){
- crashReport(e);
- }
- }
- pause(1000L);
- saveAndExit();
- }
- public static void pause(long ms){
- boolean pause = true;
- long old = System.currentTimeMillis();
- while (pause) {
- if (System.currentTimeMillis() - old > ms) {
- pause = false;
- }
- }
- }
- public static void update()
- {
- //webField.setEditable(false);
- //webSave.setEnabled(false);
- disableFrame();
- updatetext.setText("Updating modded client...");
- console.append("\n\nUpdating client mods to match\nwith server\'s client selection...\n\n\n");
- for (String s : delete){
- File file = new File(new File(basepath, "Game/mods"), s);
- if (file.exists()){
- file.delete();
- console.append("Deleted file:\n" + s + "\n\n");
- pause(250L);
- }
- }
- for (String s : install){
- console.append("Downloading file:\n" + s + "\n");
- File file = new File(new File(basepath, "Game/mods"), s);
- try {
- client.changeWorkingDirectory("/DMSLauncher");
- } catch (IOException e) {
- crashReport(e);
- }
- try {
- OutputStream os = new BufferedOutputStream(new FileOutputStream(file));
- InputStream is = client.retrieveFileStream(s);
- byte[] bytes = new byte[4096];
- int byteread = -1;
- while ((byteread = is.read(bytes)) != -1){
- os.write(bytes, 0, byteread);
- }
- boolean success = client.completePendingCommand();
- if (success){
- console.append("Complete!\n\n");
- }
- os.close();
- is.close();
- } catch (FileNotFoundException e) {
- crashReport(e);
- } catch (IOException e) {
- crashReport(e);
- }
- }
- enableFrame();
- updatetext.setText(" ");
- console.append("\n\n\nUpdate is complete!\n\n");
- pause(1000L);
- play();
- }
- static String basepath;
- public static void loadFolder()
- {
- web = "script";
- File base_folder = new File(new JFileChooser().getFileSystemView().getDefaultDirectory(), "Documents" + splitKey + "DMSUpdater");
- if (!base_folder.exists()) {
- base_folder.mkdirs();
- }
- File prgmVerFile = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Documents" + splitKey + "DMSUpdater", "prgm.txt");
- if (prgmVerFile.exists())
- {
- List<String> lines = null;
- try
- {
- lines = Files.readAllLines(prgmVerFile.toPath());
- }
- catch (IOException e)
- {
- crashReport(e);
- }
- oldVer = (String)lines.get(0);
- }
- if (!prgmVerFile.exists()) {
- try
- {
- prgmVerFile.createNewFile();
- }
- catch (IOException e)
- {
- crashReport(e);
- return;
- }
- }
- String contentx1 = thisVer;
- try
- {
- clearFile(prgmVerFile);
- Files.write(prgmVerFile.toPath(), contentx1.getBytes(), new OpenOption[] { StandardOpenOption.CREATE });
- }
- catch (IOException e)
- {
- crashReport(e);
- }
- File chatfile = new File(basepath, "Chat");
- if (!chatfile.exists()) chatfile.mkdir();
- File chatLoginFile = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Documents" + splitKey + "DMSUpdater" + splitKey + "Chat", "chatLogin.txt");
- if (chatLoginFile.exists())
- {
- List<String> lines = null;
- try
- {
- lines = Files.readAllLines(chatLoginFile.toPath());
- }
- catch (IOException e)
- {
- crashReport(e);
- }
- chat_user = lines.get(0);
- }
- if (!chatLoginFile.exists()) {
- try
- {
- chatLoginFile.createNewFile();
- }
- catch (IOException e)
- {
- crashReport(e);
- return;
- }
- String contentx5 = "None";
- try
- {
- clearFile(chatLoginFile);
- Files.write(chatLoginFile.toPath(), contentx5.getBytes(), new OpenOption[] { StandardOpenOption.CREATE });
- }
- catch (IOException e)
- {
- crashReport(e);
- }
- chat_user = "None";
- }
- if (new File(basepath, "Chat/ftp.txt").exists())
- try {
- currentChatHist = Files.readAllLines(new File(basepath, "Chat/ftp.txt").toPath());
- totalChatHist = new ArrayList<String>();
- totalChatHist.addAll(currentChatHist);
- } catch (IOException e1) {
- crashReport(e1);
- }
- else{
- currentChatHist = new ArrayList<String>();
- totalChatHist = new ArrayList<String>();
- }
- /*File chatHistory = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Documents" + splitKey + "DMSUpdater", "chatHistory.txt");
- if (chatHistory.exists())
- {
- List<String> lines = null;
- try
- {
- lines = Files.readAllLines(chatHistory.toPath());
- }
- catch (IOException e)
- {
- crashReport(e);
- }
- currentChatHist = lines;
- }
- if (!chatHistory.exists()) {
- try
- {
- chatHistory.createNewFile();
- }
- catch (IOException e)
- {
- crashReport(e);
- return;
- }
- String contentx5 = "TOP OF HISTORY";
- try
- {
- clearFile(chatHistory);
- Files.write(chatHistory.toPath(), contentx5.getBytes(), new OpenOption[] { StandardOpenOption.CREATE });
- }
- catch (IOException e)
- {
- crashReport(e);
- }
- ArrayList<String> c = new ArrayList<String>();
- c.add("TOP OF HISTORY");
- currentChatHist = c;
- }*/
- File locationFile = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Documents" + splitKey + "DMSUpdater", "programlocation.txt");
- if (!locationFile.exists()) {
- try
- {
- locationFile.createNewFile();
- }
- catch (IOException e)
- {
- crashReport(e);
- }
- }
- try
- {
- String content = DMSLauncher.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
- /*String[] contents = content.split(splitKey);
- int length = contents.length;
- contents[(length - 1)] = "";
- content = "";
- String[] arrayOfString1;
- int j = (arrayOfString1 = contents).length;
- for (int i = 0; i < j; i++)
- {
- String x = arrayOfString1[i];
- content = content + splitKey + x;
- }
- if (content.startsWith(splitKey + splitKey)) {
- content = content.replaceFirst(splitKey, "");
- }
- if (content.endsWith(splitKey))
- {
- int l = content.length();
- content = content.substring(0, l - 1);
- }*/
- /*clearFile(locationFile);
- String[] ss = content.split(splitKey);
- String l = "";
- for (int i = 0; i < ss.length - 1; i++){
- l += ss[i] + (i == ss.length - 2 ? "" : splitKey);
- }
- */
- content = content.replace("/DMSLauncher.jar", "");
- clearFile(locationFile);
- Files.write(locationFile.toPath(), content.getBytes(), new OpenOption[] { StandardOpenOption.CREATE });
- prgmPath = content;
- }
- catch (URISyntaxException e)
- {
- crashReport(e);
- }
- catch (IOException e)
- {
- crashReport(e);
- }
- }
- public static List<List<String>> updateNotes(List<String> clientFiles, List<String> serverFiles){
- List<String> deleteMods = new ArrayList<String>();
- for (String s : clientFiles){
- if (!serverFiles.contains(s)){
- deleteMods.add(s);
- }
- }
- List<String> installMods = new ArrayList<String>();
- for (String s : serverFiles){
- if (!clientFiles.contains(s)){
- installMods.add(s);
- }
- }
- List<List<String>> list = new ArrayList<List<String>>();
- list.add(deleteMods);
- list.add(installMods);
- return list;
- }
- public static void summaryAndConfirmUpdate(List<String> clientFiles, List<String> serverFiles){
- {
- int result = JOptionPane.showOptionDialog(frame, "An update is available!", "Update Mod Selection", 1, 3, null, new String[] { "Update and Play", "View Update Summary", "Skip Update and Play" }, "Update and Play");
- if (result == 0)
- {
- List<List<String>> mods = updateNotes(clientFiles, serverFiles);
- delete = mods.get(0);
- install = mods.get(1);
- SwingWorker<String, String> worker = new SwingWorker<String, String>()
- {
- protected String doInBackground()
- {
- DMSLauncher.update();
- return null;
- }
- };
- worker.execute();
- return;
- }
- if (result == 1)
- {
- JFrame framex = new JFrame("Update Process Summary");
- framex.setMinimumSize(new Dimension(600, 600));
- framex.setPreferredSize(new Dimension(600, 600));
- framex.setMaximumSize(new Dimension(600, 600));
- framex.setDefaultCloseOperation(2);
- framex.setLocationRelativeTo(frame);
- framex.setResizable(false);
- Container panex = new Container();
- framex.setLayout(null);
- panex.setLayout(null);
- JLabel labelx = new JLabel("Installation Summary", 0);
- labelx.setFont(new Font(fontType, 1, 16));
- labelx.setBounds(new Rectangle(0, -40, 600, 100));
- panex.add(labelx);
- JTextArea area = new JTextArea();
- String sm = "";
- sm += "The following mods will be installed or deleted to match\n";
- sm += "your mods folder with the server\'s client selection...\n\n";
- sm += "Files to be deleted:\n";
- int index = 1;
- List<List<String>> mods = updateNotes(clientFiles, serverFiles);
- for (String s : mods.get(0)){
- sm += index + ". " + s + "\n";
- index++;
- }
- sm += "\nFiles to be downloaded:\n";
- index = 1;
- for (String s : mods.get(1)){
- sm += index + ". " + s + "\n";
- index++;
- }
- area.setFont(new Font(fontType, 0, 14));
- area.setEditable(false);
- area.setText(sm);
- JScrollPane scroll = new JScrollPane(area);
- scroll.setBounds(new Rectangle(50, 30, 500, 500));
- panex.add(scroll);
- JButton buttonx = new JButton("Close");
- buttonx.setFont(new Font("arial", 1, 14));
- buttonx.setBounds(new Rectangle(225, 540, 150, 30));
- buttonx.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- framex.setVisible(false);
- framex.dispose();
- DMSLauncher.summaryAndConfirmUpdate(clientFiles, serverFiles);
- }
- });
- panex.add(buttonx);
- framex.setContentPane(panex);
- framex.setVisible(true);
- }
- if (result == 2) {
- play();
- }
- }
- }
- public static void crashReport(Exception e){
- exinfo = e;
- SwingWorker<String, String> worker3 = new SwingWorker<String, String>(){
- protected String doInBackground(){
- crashReportGo(exinfo);
- return null;
- }
- };
- worker3.execute();
- }
- public static void crashReportGo(Exception e){
- StringWriter swx = new StringWriter();
- PrintWriter pwx = new PrintWriter(swx);
- e.printStackTrace(pwx);
- pwx.close();
- String jx = swx.toString();
- try {
- swx.close();
- } catch (IOException e2) {
- }
- if (jx.contains("UnknownHostException")){
- JOptionPane.showMessageDialog(frame, "You do not have internet connection! The program will now shut down.", "No Internet Connection", JOptionPane.ERROR_MESSAGE);
- saveAndExit();
- return;
- }
- int x = JOptionPane.showOptionDialog(frame, "An error has occurred. Would you like to report it?", "Uh oh!", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE, null, new Object[]{"Report to Dilan", "Save to File", "Close"}, "Report to Dilan");
- if (x == JOptionPane.YES_OPTION){
- String s = JOptionPane.showInputDialog(frame, "Please enter your name", "Report to Dilan", JOptionPane.QUESTION_MESSAGE);
- sending.setPreferredSize(new Dimension(400, 100));
- sending.setMaximumSize(new Dimension(400, 100));
- sending.setMinimumSize(new Dimension(400, 100));
- sending.setDefaultCloseOperation(0);
- sending.setResizable(false);
- sending.setLocationRelativeTo(null);
- Container pane = new Container();
- sending.setLayout(null);
- JLabel label = new JLabel("Reporting error...", 0);
- label.setFont(new Font("arial", 1, 18));
- label.setBounds(new Rectangle(0, 20, 400, 40));
- pane.add(label);
- sending.setContentPane(pane);
- sending.setVisible(true);
- Properties properties = System.getProperties();
- properties.setProperty("mail.smtp.host", "smtp.zoho.com");
- properties.setProperty("mail.smtp.user", from);
- properties.setProperty("mail.smtp.pass", emailpass);
- properties.setProperty("mail.smtp.port", "465");
- properties.setProperty("mail.smtp.auth", "true");
- properties.put("mail.smtp.socketFactory.port", "465");
- properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
- properties.put("mail.smtp.socketFactory.fallback", "false");
- Session session = Session.getDefaultInstance(properties, new Authenticator(){
- public PasswordAuthentication getPasswordAuthentication(){
- }
- });
- try{
- Message message = new MimeMessage(session);
- message.setFrom(new InternetAddress(from));
- message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
- message.setSubject("Automatic DMSLauncher Error Report - " + s);
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- e.printStackTrace(pw);
- pw.close();
- String j = sw.toString();
- sw.close();
- message.setText(j);
- Transport transport = session.getTransport("smtp");
- transport.sendMessage(message, message.getAllRecipients());
- transport.close();
- sending.setVisible(false);
- sending.dispose();
- JOptionPane.showMessageDialog(frame, "Successfully reported this error.", "Sent Email", JOptionPane.INFORMATION_MESSAGE);
- } catch (MessagingException | IOException e1){
- JOptionPane.showMessageDialog(frame, "Unable to send email report. The stack trace will save to file instead.", "Error Sending Email", JOptionPane.ERROR_MESSAGE);
- File dir = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + DMSLauncher.splitKey + "Documents" + DMSLauncher.splitKey + "DMSUpdater", "stacktrace");
- if (!dir.exists()){
- dir.mkdirs();
- }
- Date date = new Date();
- SimpleDateFormat format = new SimpleDateFormat("HH-mm-ss-MM-dd-yyyy");
- File fx = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + DMSLauncher.splitKey + "Documents" + DMSLauncher.splitKey + "DMSUpdater" + splitKey + "stacktrace", format.format(date) + ".txt");
- PrintStream ps = null;
- try {
- ps = new PrintStream(fx);
- } catch (FileNotFoundException e1x) {
- JOptionPane.showMessageDialog(frame, "Unable to save the stack trace to a file.", "Today is not a good day", JOptionPane.ERROR_MESSAGE);
- return;
- }
- e1.printStackTrace(ps);
- ps.close();
- JOptionPane.showMessageDialog(frame, "The stack trace has been saved to \n" + fx.getPath(), "Stack Trace Saved to File", JOptionPane.ERROR_MESSAGE);
- return;
- }
- return;
- }
- if (x == JOptionPane.NO_OPTION){
- File dir = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + DMSLauncher.splitKey + "Documents" + DMSLauncher.splitKey + "DMSUpdater", "stacktrace");
- if (!dir.exists()){
- dir.mkdirs();
- }
- Date date = new Date();
- SimpleDateFormat format = new SimpleDateFormat("HH-mm-ss-MM-dd-yyyy");
- File fx = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + DMSLauncher.splitKey + "Documents" + DMSLauncher.splitKey + "DMSUpdater" + splitKey + "stacktrace", format.format(date) + ".txt");
- PrintStream ps = null;
- try {
- ps = new PrintStream(fx);
- } catch (FileNotFoundException e1) {
- JOptionPane.showMessageDialog(frame, "Unable to save the stack trace to a file.", "Today is not a good day", JOptionPane.ERROR_MESSAGE);
- return;
- }
- e.printStackTrace(ps);
- ps.close();
- JOptionPane.showMessageDialog(frame, "The stack trace has been saved to \n" + fx.getPath(), "Stack Trace Saved to File", JOptionPane.ERROR_MESSAGE);
- return;
- }
- if (x == JOptionPane.CANCEL_OPTION) { }
- }
- public static void prepareManage() {
- JPanel pane = new JPanel();
- pane.setLayout(null);
- JLabel tip = new JLabel("Hover over buttons to see descriptions.", 0);
- tip.setBounds(new Rectangle(0, 10, 1000, 10));
- tip.setFont(new Font("arial", Font.ITALIC, 10));
- JButton deleteFromServerServer = new JButton("Delete Server Mod");
- deleteFromServerServer.setToolTipText("Delete a mod file from the server-side selection");
- deleteFromServerServer.setBounds(new Rectangle(20 + (((int) tabs.getBounds().getWidth() - 50)/2), 25+200+30, ((int) tabs.getBounds().getWidth() - 50)/2, 200-10));
- deleteFromServerServer.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- if (client == null || !client.isConnected()){
- reconnectFTP();
- }
- try {
- client.changeWorkingDirectory("/mods");
- } catch (IOException e1) {
- crashReport(e1);
- }
- try {
- String sm = JOptionPane.showInputDialog(frame, "Input the file name to delete...", "Delete File - Server", JOptionPane.QUESTION_MESSAGE);
- if (sm == null){
- return;
- }
- List<String> list = new ArrayList<String>();
- for (FTPFile ftp : client.listFiles()){
- list.add(ftp.getName());
- }
- if (!list.contains(sm)){
- JOptionPane.showMessageDialog(frame, "Invalid file name. Please try again...", "Manage Server", JOptionPane.ERROR_MESSAGE);
- return;
- }
- client.deleteFile(sm);
- JOptionPane.showMessageDialog(frame, "Deleted " + sm + " from the server side selection.", "Manage Server", JOptionPane.INFORMATION_MESSAGE);
- } catch (HeadlessException e1) {
- crashReport(e1);
- } catch (IOException e1) {
- crashReport(e1);
- }
- return;
- }
- });
- pane.add(deleteFromServerServer);
- JButton deleteFromServer = new JButton("Delete Client Mod");
- deleteFromServer.setToolTipText("Delete a mod file from the DMSLauncher client sync");
- deleteFromServer.setBounds(new Rectangle(10, 25+200+30, ((int) tabs.getBounds().getWidth() - 50)/2, 200-10));
- deleteFromServer.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- if (client == null || !client.isConnected()){
- reconnectFTP();
- }
- try {
- client.changeWorkingDirectory("/DMSLauncher");
- } catch (IOException e1) {
- crashReport(e1);
- }
- try {
- String sm = JOptionPane.showInputDialog(frame, "Input the file name to delete...", "Delete File - Client", JOptionPane.QUESTION_MESSAGE);
- if (sm == null){
- return;
- }
- List<String> list = new ArrayList<String>();
- for (FTPFile ftp : client.listFiles()){
- list.add(ftp.getName());
- }
- if (!list.contains(sm)){
- JOptionPane.showMessageDialog(frame, "Invalid file name. Please try again...", "Manage Server", JOptionPane.ERROR_MESSAGE);
- return;
- }
- client.deleteFile(sm);
- JOptionPane.showMessageDialog(frame, "Deleted " + sm + " from the server\'s client selection.", "Manage Server", JOptionPane.INFORMATION_MESSAGE);
- } catch (HeadlessException e1) {
- crashReport(e1);
- } catch (IOException e1) {
- crashReport(e1);
- }
- return;
- }
- });
- pane.add(deleteFromServer);
- JCheckBox serverSideAlso = new JCheckBox("Add to server-side mods also (requires server restart)");
- serverSideAlso.setBounds(new Rectangle(10, 10+210, (int) tabs.getBounds().getWidth() - 40, 25));
- JButton uploadToServer = new JButton("Upload Mod");
- uploadToServer.setToolTipText("Upload a mod file to the server for the DMSLauncher to read from (optional: server-side also).");
- uploadToServer.setBounds(new Rectangle(10, 25, (int) tabs.getBounds().getWidth() - 40, 200-10));
- uploadToServer.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- JFileChooser fc = new JFileChooser();
- fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
- fc.setDialogTitle("Select file to upload...");
- int val = fc.showDialog(frame, "Upload to FTP");
- if (val == JFileChooser.APPROVE_OPTION){
- File local = fc.getSelectedFile();
- if (local.isDirectory()){
- JOptionPane.showMessageDialog(frame, "The file cannot be a folder.", "Manage Server", JOptionPane.ERROR_MESSAGE);
- return;
- }
- try {
- if (serverSideAlso.isSelected()){
- if (client == null || !client.isConnected()){
- reconnectFTP();
- }
- client.changeWorkingDirectory("/mods");
- InputStream is = new FileInputStream(local);
- OutputStream os = client.storeFileStream(local.getName());
- byte[] bytes = new byte[4096];
- int read = 0;
- while ((read = is.read(bytes)) != -1){
- os.write(bytes, 0, read);
- }
- is.close();
- os.close();
- client.completePendingCommand();
- }
- if (client == null || !client.isConnected()){
- reconnectFTP();
- }
- client.changeWorkingDirectory("/DMSLauncher");
- InputStream is = new FileInputStream(local);
- OutputStream os = client.storeFileStream(local.getName());
- byte[] bytes = new byte[4096];
- int read = 0;
- while ((read = is.read(bytes)) != -1){
- os.write(bytes, 0, read);
- }
- is.close();
- os.close();
- client.completePendingCommand();
- JOptionPane.showMessageDialog(frame, "Successfully uploaded " + local.getName() + " to the FTP server " + (serverSideAlso.isSelected() ? "(both client and server)" : "(client only)"), "Manage Server", JOptionPane.INFORMATION_MESSAGE);
- } catch (IOException e1) {
- crashReport(e1);
- }
- }
- }
- });
- pane.add(serverSideAlso);
- pane.add(uploadToServer);
- pane.add(tip);
- tabs.addTab("Manage Server", null, pane, "Manage server files");
- }
- public static void manage(boolean wrong, boolean skipPass){
- String s = "";
- if (!skipPass)
- s = JOptionPane.showInputDialog(frame, (wrong ? "Incorrect password! Please try again..." : "Enter the administration password..."), "Manage Server", JOptionPane.QUESTION_MESSAGE);
- if (s == null) return;
- if (s.equals(password) || skipPass){
- manage_cont = true;
- tabs.setSelectedIndex(3);
- }else{
- manage(true, false);
- return;
- }
- return;
- }
- public static void disableFrame(){
- update.setEnabled(false);
- tabs.setEnabled(false);
- /*manage.setEnabled(false);
- settings.setEnabled(false);
- ramAllocation.setEnabled(false);
- chat.setEnabled(false);*/
- }
- public static void enableFrame(){
- tabs.setEnabled(true);
- update.setEnabled(true);
- /*manage.setEnabled(true);
- settings.setEnabled(true);
- ramAllocation.setEnabled(true);
- chat.setEnabled(true);*/
- }
- public static void install(){
- disableFrame();
- updatetext.setText("Installing modded minecraft...");
- console.append("\n\nStarting installation...\n\n");
- if (isWindows()){
- console.append("Downloading file from " + baseminecraftWindows + "...\n");
- }
- else{
- console.append("Downloading file from " + baseMinecraft + "...\n");
- }
- try {
- if (!isWindows()){
- sfp_url = new URL(baseMinecraft);
- sfp_file = new File(basepath, "DMSClientFiles.zip").getPath();
- SwingWorker<String, String> worker8 = new SwingWorker<String, String>(){
- protected String doInBackground(){
- try {
- saveFileProgress(sfp_url, sfp_file);
- install2();
- } catch (IOException e) {
- crashReport(e);
- }
- return null;
- }
- };
- worker8.execute();
- }else{
- sfp_url = new URL(baseminecraftWindows);
- sfp_file = new File(basepath, "DMSClientFiles.zip").getPath();
- SwingWorker<String, String> worker8 = new SwingWorker<String, String>(){
- protected String doInBackground(){
- try {
- saveFileProgress(sfp_url, sfp_file);
- install2();
- } catch (IOException e) {
- crashReport(e);
- }
- return null;
- }
- };
- worker8.execute();
- }
- } catch (MalformedURLException e) {
- crashReport(e);
- }
- }
- /*public static void auth(boolean wrong, boolean unable){
- JTextField usernameField = new JTextField(15);
- JPasswordField passField = new JPasswordField(15);
- JPanel panel = new JPanel();
- JLabel label;
- if (!unable)
- label = new JLabel((wrong ? "Invalid credentials. Please try again..." : "Log in to your Mojang account..."));
- else
- label = new JLabel("Unable to connect to authentication server!?");
- label.setFont(new Font("arial", Font.BOLD, 12));
- panel.add(label);
- panel.add(Box.createVerticalStrut(5));
- panel.add(new JLabel("Username/Email"));
- panel.add(usernameField);
- panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
- panel.add(new JLabel("Password"));
- panel.add(passField);
- int res = JOptionPane.showConfirmDialog(null, panel, "Minecraft Authentication", JOptionPane.OK_CANCEL_OPTION);
- if (res == JOptionPane.OK_OPTION){
- String pass = "";
- for (char c : passField.getPassword()){
- pass += c;
- }
- JsonObject info = authMinecraft(usernameField.getText(), pass);
- if (info.containsKey("errorMessage")){
- if (info.getString("errorMessage").contains("Invalid credentials")){
- auth(true, false);
- return;
- }
- }
- else if (info.containsKey("accessToken")){
- try {
- JsonObject uuid = info.getJsonObject("selectedProfile");
- List<String> lines = Files.readAllLines(new File(new File(basepath, "Game"), "launcher_profiles.json").toPath());
- int size = lines.size();
- for (int i = 0; i < size; i++){
- if (lines.get(i).contains("DMSLAUNCHER-UUID")){
- lines.set(i, lines.get(i).replaceAll("DMSLAUNCHER-UUID", uuid.getString("id")));
- }
- if (lines.get(i).contains("DMSLAUNCHER-ACCESSTOKEN")){
- lines.set(i, lines.get(i).replaceAll("DMSLAUNCHER-ACCESSTOKEN", info.getString("accessToken")));
- }
- if (lines.get(i).contains("DMSLAUNCHER-USERNAME")){
- lines.set(i, lines.get(i).replaceAll("DMSLAUNCHER-USERNAME", uuid.getString("name")));
- }
- if (lines.get(i).contains("DMSLAUNCHER-EMAIL")){
- lines.set(i, lines.get(i).replaceAll("DMSLAUNCHER-EMAIL", usernameField.getText()));
- }
- if (lines.get(i).contains("DMSLAUNCHER-CLIENTTOKEN")){
- lines.set(i, lines.get(i).replaceAll("DMSLAUNCHER-CLIENTTOKEN", info.getString("clientToken")));
- }
- }
- clearFile(new File(new File(basepath, "Game"), "launcher_profiles.json"));
- Files.write(new File(new File(basepath, "Game"), "launcher_profiles.json").toPath(), lines, StandardOpenOption.CREATE);
- } catch (IOException e) {
- crashReport(e);
- }
- }else{
- auth(false, true);
- }
- }else{
- auth(false, false);
- return;
- }
- return;
- }*/
- public static void install2(){
- pause(500L);
- console.append("\n\nUnzipping the zip file...\n\n");
- File dir = new File(basepath, "Game");
- if (!dir.exists()){
- dir.mkdir();
- }
- try {
- UnZipper.unzip(new File(basepath, "DMSClientFiles.zip").getPath(), new File(basepath, "Game").getPath());
- } catch (IOException e) {
- crashReport(e);
- }
- console.append("Editing launcher_profiles.json...\n\n");
- try {
- List<String> lines = Files.readAllLines(new File(new File(basepath, "Game"), "launcher_profiles.json").toPath());
- int index = -1;
- for (String s : lines){
- index++;
- if (s.contains("DMSLAUNCHER/GAMEDIRPATH")) break;
- }
- String k = lines.get(index);
- if (isWindows())
- k = k.replace("DMSLAUNCHER/GAMEDIRPATH", new File(basepath, "Game").getPath().replaceAll(Matcher.quoteReplacement("\\"), Matcher.quoteReplacement("\\\\")));
- else
- k = k.replaceAll("DMSLAUNCHER/GAMEDIRPATH", new File(basepath, "Game").getPath());
- lines.set(index, k);
- clearFile(new File(new File(basepath, "Game"), "launcher_profiles.json"));
- Files.write(new File(new File(basepath, "Game"), "launcher_profiles.json").toPath(), lines, StandardOpenOption.CREATE);
- } catch (IOException e) {
- crashReport(e);
- }
- /*console.append("Minecraft authentication is required...\n\n");
- auth(false, false);
- console.append("Used credentials to modify launcher_profiles.json\n\n");*/
- console.append("Minecraft modded installation complete!\n\n");
- update.setText("Play Minecraft");
- SwingWorker<String, String> worker4 = new SwingWorker<String, String>(){
- protected String doInBackground(){
- checkUpdatesFromFTP();
- return null;
- }
- };
- worker4.execute();
- }
- public static void ramAllocate(){
- String[] rams = new String[]{"2048 MB", "2304 MB", "2560 MB", "2816 MB", "3072 MB", "3328 MB", "3584 MB", "3840 MB", "4096 MB", "4352 MB", "4608 MB", "4864 MB", "5120 MB", "5376 MB", "5632 MB", "5888 MB", "6144 MB"};
- try {
- List<String> lines = Files.readAllLines(new File(new File(basepath, "Game"), "launcher_profiles.json").toPath());
- String j = "";
- String full = "";
- int i = -1;
- for (String s : lines){
- i++;
- if (s.contains("-Xmx")){
- full = s;
- j = s.split("-Xmx")[1].split("m")[0];
- break;
- }
- }
- String s = (String) JOptionPane.showInputDialog(frame, "Select RAM dedication towards Minecraft...", "RAM Dedication", JOptionPane.QUESTION_MESSAGE, null, rams, j + " MB");
- lines.set(i, full.replace(j, s.replace(" MB", "")));
- clearFile(new File(new File(basepath, "Game"), "launcher_profiles.json"));
- Files.write(new File(new File(basepath, "Game"), "launcher_profiles.json").toPath(), lines, StandardOpenOption.WRITE);
- console.append("\n\nNow dedicating " + s + " of RAM to Minecraft.");
- } catch (IOException e) {
- crashReport(e);
- }
- }
- static boolean onlyExitOnce = false;
- public static void saveAndExit(){
- onlyExitOnce = true;
- framex = new JFrame("DMSLauncher is closing...");
- framex.setMinimumSize(new Dimension(500, 100));
- framex.setPreferredSize(new Dimension(500, 100));
- framex.setMaximumSize(new Dimension(500, 100));
- framex.setDefaultCloseOperation(0);
- framex.setLocationRelativeTo(null);
- framex.setResizable(false);
- Container panex = new Container();
- framex.setLayout(null);
- panex.setLayout(null);
- JLabel labelx = new JLabel("DMSLauncher is quitting. Please wait...", 0);
- labelx.setFont(new Font(fontType, 1, 16));
- labelx.setBounds(new Rectangle(0, -10, 500, 100));
- panex.add(labelx);
- framex.setContentPane(panex);
- framex.setVisible(true);
- try {
- Files.write(new File(basepath, "Chat/ftp.txt").toPath(), currentChatHist, StandardOpenOption.CREATE);
- } catch (IOException e) {
- crashReport(e);
- }
- pause(100L);
- System.exit(0);
- }
- public static void settings(){
- JPanel pane = new JPanel();
- pane.setLayout(null);
- JLabel tip = new JLabel("Hover over buttons to see descriptions.", 0);
- tip.setBounds(new Rectangle(0, 10, 1000, 10));
- tip.setFont(new Font("arial", Font.ITALIC, 10));
- JLabel chatSectionTitle = new JLabel("Chat", 0);
- chatSectionTitle.setFont(new Font("arial", Font.BOLD, 18));
- chatSectionTitle.setBounds(new Rectangle(10, 50, 300, 20));
- pane.add(chatSectionTitle);
- JButton deleteChatHistory = new JButton("Save & Clear Chat History");
- deleteChatHistory.setToolTipText("Clear your current chat history and save it as recently deleted.");
- deleteChatHistory.setBounds(new Rectangle(10, 75, 300, 50));
- deleteChatHistory.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- new SW(){
- protected void I() {
- List<String> chatList = new ArrayList<String>();
- Date date = new Date();
- SimpleDateFormat format_infile = new SimpleDateFormat("HH:mm:ss MM/dd/yyyy");
- SimpleDateFormat format_outfile = new SimpleDateFormat("HH-mm-ss MM-dd-yyyy");
- chatList.add("//Chat history saved: " + format_infile.format(date));
- chatList.addAll(totalChatHist);
- File temp = new File(basepath, "Chat/History");
- if (!temp.exists()) temp.mkdir();
- chatBox.setText("");
- File f = new File(basepath, "Chat/History/" + format_outfile.format(date) + ".chathist");
- try {
- Files.write(f.toPath(), chatList, StandardOpenOption.CREATE);
- } catch (IOException e) {
- crashReport(e);
- }
- File currChat = new File(basepath, "Chat/ftp.txt");
- currChat.delete();
- try {
- new File(currChat.getPath()).createNewFile();
- } catch (IOException e) {
- crashReport(e);
- }
- totalChatHist.clear();
- currentChatHist.clear();
- Dialog.dialog("Successfully saved chat history to recently deleted and cleared the current chat area", "Settings Changed");
- }
- }.execute();
- }
- });
- pane.add(deleteChatHistory);
- JButton restoreChatHistory = new JButton("Restore Chat History");
- restoreChatHistory.setToolTipText("Restore chat area to a saved chat history file.");
- restoreChatHistory.setBounds(new Rectangle(10, 135, 300, 50));
- restoreChatHistory.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- JFileChooser fc = new JFileChooser();
- fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
- fc.setDialogTitle("Select chat history to restore");
- fc.setCurrentDirectory(new File(basepath, "Chat/History"));
- fc.setFileFilter(new FileFilter() {
- public boolean accept(File f) {
- return (f.getName().endsWith(".chathist") && !f.isDirectory());
- }
- public String getDescription() {
- return "DMSLauncher Chat History File";
- }
- });
- int val = fc.showDialog(frame, "Restore");
- if (val == JFileChooser.APPROVE_OPTION) {
- try {
- List<String> lines = Files.readAllLines(fc.getSelectedFile().toPath());
- totalChatHist.addAll(lines);
- currentChatHist.addAll(lines);
- new SW(){
- protected void I() {
- chatBox.setText(fromListChat(totalChatHist));
- }
- }.execute();
- } catch (IOException e1) {
- crashReport(e1);
- }
- Dialog.dialog("Successfully restored chat history to: " + fc.getSelectedFile().getName(), "Settings Changed");
- }
- }
- });
- pane.add(restoreChatHistory);
- JButton logoutChat = new JButton("Logout");
- logoutChat.setToolTipText("Remove your current DMSLauncher chat ID from this program (you can log in again at any time).");
- logoutChat.setBounds(new Rectangle(10, 195, 300, 50));
- logoutChat.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- new SW() {
- protected void I() {
- chat_user = "None";
- File f = new File(basepath, "Chat/chatLogin.txt");
- f.delete();
- chatSending.setText("Not logged in");
- Dialog.dialog("Successfully logged out of chat", "Settings Changed");
- }
- }.execute();
- }
- });
- pane.add(logoutChat);
- JLabel moreComingSoon = new JLabel("MORE SETTINGS COMING SOON PROBABLY", 0);
- moreComingSoon.setBounds(new Rectangle(350, 200, 600, 100));
- moreComingSoon.setFont(new Font("arial", Font.BOLD, 24));
- pane.add(moreComingSoon);
- JButton credit = new JButton("DMSLauncher Information");
- credit.setToolTipText("View creator information, program code, and more...");
- credit.setBounds(new Rectangle((int) tabs.getBounds().getWidth()/2 - (500/2), (int) tabs.getBounds().getHeight()-100, 500, 50));
- credit.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- int val = JOptionPane.showOptionDialog(frame, "DMSLauncher v" + thisVer + " by Dilan Nair", "DMSLauncher", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, new Object[] {"View Code", "http://blockhead7360.com", "Close"}, "Close");
- if (val == 0) {
- try {
- Desktop.getDesktop().browse(new URI("https://pastebin.com/PRfcq6Xg"));
- } catch (IOException e1) {
- crashReport(e1);
- } catch (URISyntaxException e1) {
- crashReport(e1);
- }
- }
- if (val == 1) {
- try {
- Desktop.getDesktop().browse(new URI("https://blockhead7360.com"));
- } catch (IOException e1) {
- crashReport(e1);
- } catch (URISyntaxException e1) {
- crashReport(e1);
- }
- }
- }
- });
- pane.add(credit);
- pane.add(tip);
- tabs.addTab("Settings", null, pane, "Change program and game settings");
- }
- public static abstract class SW{
- protected abstract void I();
- public void execute(){
- SwingWorker<String, String> worker = new SwingWorker<String, String>(){
- protected String doInBackground() {
- I();
- return null;
- }
- };
- worker.execute();
- }
- }
- public static boolean canUseFeature(String feature) {
- if (remotesettings.containsKey(feature)) {
- Dialog.dialog("Sorry, but you cannot use this feature at this time.\n\nReason: " + remotesettings.get(feature), "This feature has been disabled remotely");
- return false;
- }
- return true;
- }
- public static void loadFrame()
- {
- frame = new JFrame("Dilan's Modded Server - Launcher");
- frame.setMinimumSize(new Dimension(1000, 700));
- frame.setSize(new Dimension(1000, 700));
- frame.setMaximumSize(new Dimension(1000, 700));
- frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
- frame.setLocationRelativeTo(null);
- frame.setResizable(false);
- frame.addWindowListener(new WindowAdapter(){
- public void windowClosing(WindowEvent event){
- SwingWorker<String, String> worker = new SwingWorker<String, String>(){
- protected String doInBackground(){
- if (!onlyExitOnce) saveAndExit();
- return null;
- }
- };
- worker.execute();
- }
- });
- JPanel pane = new JPanel();
- cont.setLayout(null);
- pane.setLayout(null);
- frame.setLayout(null);
- URL url = null;
- url = ClassLoader.getSystemResource("res/DMSLauncher.png");
- Toolkit kit = Toolkit.getDefaultToolkit();
- Image imgx = kit.createImage(url);
- frame.setIconImage(imgx);
- try
- {
- BufferedImage img = ImageIO.read(new URL(imageUrl));
- JLabel image = new JLabel(new ImageIcon(img));
- image.setBounds(0, -300, 1000, 700);
- cont.add(image);
- }
- catch (Exception ex)
- {
- crashReport(ex);
- }
- JLabel credits = new JLabel("Created by Dilan Nair - http://blockhead7360.com");
- credits.setFont(new Font("arial", 2, 12));
- credits.setBounds(new Rectangle(10, 75, 1000, 30));
- cont.add(credits);
- JLabel secret = new JLabel("© Manazir Industries");
- secret.setFont(new Font("arial", Font.PLAIN, 3));
- secret.setBounds(new Rectangle(1, 1, 40, 4));
- cont.add(secret);
- JLabel version = new JLabel("Program version: " + thisVer, 0);
- version.setFont(new Font(fontType, 1, 12));
- version.setBounds(new Rectangle(650, 70, 325, 30));
- cont.add(version);
- cont.add(DilanAPI.watermark(1000, 700, WMLoc.TOP_RIGHT));
- changelog = new JTextArea();
- changelog.setMargin(new Insets(20, 20, 20, 20));
- changelog.setBounds(new Rectangle(25, 5, 600, 450));
- changelog.setFont(new Font(fontType, 1, 18));
- changelog.setEditable(false);
- changelog.setText(changelogstr);
- changelog.setVisible(true);
- JScrollPane changelogpane = new JScrollPane(changelog);
- changelogpane.setBounds(new Rectangle(25, 5, 600, 450));
- pane.add(changelogpane);
- console.setMargin(new Insets(8, 8, 8, 8));
- console.setBounds(new Rectangle(650, 5, 325, 450));
- console.setFont(new Font(fontType, 2, 16));
- console.setEditable(false);
- console.setVisible(true);
- DefaultCaret caret = (DefaultCaret) console.getCaret();
- caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
- JScrollPane consolepane = new JScrollPane(console);
- consolepane.setBounds(new Rectangle(650, 5, 325, 450));
- pane.add(consolepane);
- boolean inst = false;
- if (!(new File(new File(basepath, "Game"), "launcher_profiles.json")).exists()){
- update = new JButton("Install and Play");
- inst = true;
- }
- else update = new JButton("Play Minecraft");
- updatetext = new JLabel();
- updatetext.setText(" ");
- updatetext.setFont(new Font("arial", 1, 14));
- updatetext.setBounds(new Rectangle(520, 470, 500, 40));
- updatetext.setVisible(true);
- pane.add(updatetext);
- update.setBounds(new Rectangle(748, 468, 220, 50));
- update.setFont(new Font(fontType2, 0, 16));
- update.setToolTipText((inst ? "Install the modded Minecraft client and start the game." : "Check for updates and start the game."));
- update.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- /*if (DMSUpdater.clientPath.equals("BLANK"))
- {
- int i = JOptionPane.showOptionDialog(DMSUpdater.frame, "A mods folder location was not set!", "Set your mods folder!", 0, 2, null, new Object[] { "Okay", "Set path" }, "Set path");
- if (i == 1) {
- DMSUpdater.setPath();
- }
- return;
- }*/
- if (!canUseFeature("DisableUpdateButton")) return;
- if (!(new File(new File(basepath, "Game"), "launcher_profiles.json")).exists()){
- SwingWorker<String, String> worker5 = new SwingWorker<String, String>(){
- protected String doInBackground(){
- install();
- return null;
- }
- };
- worker5.execute();
- }
- else{
- SwingWorker<String, String> worker4 = new SwingWorker<String, String>(){
- protected String doInBackground(){
- checkUpdatesFromFTP();
- return null;
- }
- };
- worker4.execute();
- }
- }
- });
- update.setVisible(true);
- pane.add(update);
- manage = new JButton("Manage Server");
- manage.setFont(new Font(fontType2, 0, 14));
- manage.setBounds(new Rectangle(10, 595, 220, 30));
- manage.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- manage(false, false);
- }
- });
- manage.setVisible(true);
- //pane.add(manage);
- //update.setBounds(new Rectangle(748, 468, 220, 50));
- ramAllocation = new JButton("RAM Allocation");
- ramAllocation.setFont(new Font(fontType2, 0, 14));
- ramAllocation.setBounds(new Rectangle(240, 478, 220, 30));
- ramAllocation.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- SwingWorker<String, String> worker7 = new SwingWorker<String, String>(){
- protected String doInBackground(){
- ramAllocate();
- return null;
- }
- };
- worker7.execute();
- }
- });
- ramAllocation.setVisible(true);
- if (!(new File(new File(basepath, "Game"), "launcher_profiles.json")).exists()){
- ramAllocation.setEnabled(false);
- }else ramAllocation.setEnabled(true);
- pane.add(ramAllocation);
- tabs.addTab("Play", null, pane, "View the changelog and console - Play the game");
- }
- public static void finishFrame(){
- cont.add(tabs);
- frame.setContentPane(cont);
- frame.setVisible(true);
- }
- public static void delete(File file, boolean deleteParentDir, String... except){
- for (File f : file.listFiles()){
- if (f.getName().contains("programjar")) continue;
- if (except.toString().contains(f.getName()));
- if (f.isDirectory()){
- delete(f, true);
- }else{
- f.delete();
- }
- }
- if (deleteParentDir){
- file.delete();
- }
- }
- public static class UnZipper {
- /* I DID NOT MAKE THIS I GOT THIS OFF THE INTERNET */
- /**
- * Size of the buffer to read/write data
- */
- private static final int BUFFER_SIZE = 4096;
- /**
- * Extracts a zip file specified by the zipFilePath to a directory specified by
- * destDirectory (will be created if does not exists)
- * @param zipFilePath
- * @param destDirectory
- * @throws IOException
- */
- public static void unzip(String zipFilePath, String destDirectory) throws IOException {
- File destDir = new File(destDirectory);
- if (!destDir.exists()) {
- destDir.mkdir();
- }
- ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath));
- ZipEntry entry = zipIn.getNextEntry();
- // iterates over entries in the zip file
- while (entry != null) {
- String filePath = destDirectory + File.separator + entry.getName();
- if (!entry.isDirectory()) {
- // if the entry is a file, extracts it
- extractFile(zipIn, filePath);
- } else {
- // if the entry is a directory, make the directory
- File dir = new File(filePath);
- dir.mkdir();
- }
- zipIn.closeEntry();
- entry = zipIn.getNextEntry();
- }
- zipIn.close();
- }
- /**
- * Extracts a zip entry (file entry)
- * @param zipIn
- * @param filePath
- * @throws IOException
- */
- private static void extractFile(ZipInputStream zipIn, String filePath) throws IOException {
- BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath));
- byte[] bytesIn = new byte[BUFFER_SIZE];
- int read = 0;
- while ((read = zipIn.read(bytesIn)) != -1) {
- bos.write(bytesIn, 0, read);
- }
- bos.close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment