Blockhead7360

DMS Launcher Code - upd Oct 23 2017

Aug 11th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 89.35 KB | None | 0 0
  1. //DMS stands for Dilan's Modded Server lololol
  2.  
  3. package com.blockhead7360.dms.program;
  4.  
  5. import java.awt.Container;
  6. import java.awt.Desktop;
  7. import java.awt.Dimension;
  8. import java.awt.Font;
  9. import java.awt.HeadlessException;
  10. import java.awt.Image;
  11. import java.awt.Insets;
  12. import java.awt.Rectangle;
  13. import java.awt.Toolkit;
  14. import java.awt.event.ActionEvent;
  15. import java.awt.event.ActionListener;
  16. import java.awt.event.WindowAdapter;
  17. import java.awt.event.WindowEvent;
  18. import java.awt.image.BufferedImage;
  19. import java.io.BufferedOutputStream;
  20. import java.io.BufferedReader;
  21. import java.io.File;
  22. import java.io.FileInputStream;
  23. import java.io.FileNotFoundException;
  24. import java.io.FileOutputStream;
  25. import java.io.IOException;
  26. import java.io.InputStream;
  27. import java.io.InputStreamReader;
  28. import java.io.OutputStream;
  29. import java.io.PrintStream;
  30. import java.io.PrintWriter;
  31. import java.io.StringWriter;
  32. import java.net.HttpURLConnection;
  33. import java.net.MalformedURLException;
  34. import java.net.SocketException;
  35. import java.net.URI;
  36. import java.net.URISyntaxException;
  37. import java.net.URL;
  38. import java.net.UnknownHostException;
  39. import java.nio.file.Files;
  40. import java.nio.file.OpenOption;
  41. import java.nio.file.StandardOpenOption;
  42. import java.text.SimpleDateFormat;
  43. import java.util.ArrayList;
  44. import java.util.Date;
  45. import java.util.HashMap;
  46. import java.util.List;
  47. import java.util.Map;
  48. import java.util.Properties;
  49. import java.util.Random;
  50. import java.util.concurrent.Executors;
  51. import java.util.concurrent.ScheduledExecutorService;
  52. import java.util.concurrent.TimeUnit;
  53. import java.util.regex.Matcher;
  54. import java.util.zip.ZipEntry;
  55. import java.util.zip.ZipInputStream;
  56.  
  57. import javax.imageio.ImageIO;
  58. import javax.mail.Authenticator;
  59. import javax.mail.Message;
  60. import javax.mail.MessagingException;
  61. import javax.mail.PasswordAuthentication;
  62. import javax.mail.Session;
  63. import javax.mail.Transport;
  64. import javax.mail.internet.InternetAddress;
  65. import javax.mail.internet.MimeMessage;
  66. import javax.swing.ImageIcon;
  67. import javax.swing.JButton;
  68. import javax.swing.JCheckBox;
  69. import javax.swing.JFileChooser;
  70. import javax.swing.JFrame;
  71. import javax.swing.JLabel;
  72. import javax.swing.JOptionPane;
  73. import javax.swing.JPanel;
  74. import javax.swing.JScrollPane;
  75. import javax.swing.JTabbedPane;
  76. import javax.swing.JTextArea;
  77. import javax.swing.JTextField;
  78. import javax.swing.SwingWorker;
  79. import javax.swing.event.ChangeEvent;
  80. import javax.swing.event.ChangeListener;
  81. import javax.swing.filechooser.FileFilter;
  82. import javax.swing.text.DefaultCaret;
  83.  
  84. import org.apache.commons.net.ftp.FTP;
  85. import org.apache.commons.net.ftp.FTPClient;
  86. import org.apache.commons.net.ftp.FTPFile;
  87.  
  88. import com.blockhead7360.dilanapi.Dialog;
  89. import com.blockhead7360.dilanapi.DilanAPI;
  90. import com.blockhead7360.dilanapi.Enums.WMLoc;
  91. import com.blockhead7360.dms.program.manageserver.passwordencoder.DMSLauncherPasswordEncoder;
  92.  
  93.  
  94. /*
  95.  *
  96.  * DMS IS DEAD! Probably won't update this program anymore.
  97.  * EDIT: never mind I just did
  98.  *
  99.  * Project Description (pd upd Aug 11 2017, pd upd Aug 22 2017, pd upd Oct 23 2017):
  100.  *
  101.  *
  102.  * PRE NOTICE: I was going to have this as a very small program but now it's a bit larger
  103.  * and the code is really all over the place and unorganized (and also in 1 class idk why I did this)
  104.  *
  105.  * Many pieces of this code aren't being used and many pieces are repeated because I was really really lazy when I
  106.  * started making this.
  107.  *
  108.  *
  109.  * You see, I play Minecraft.
  110.  *
  111.  * Not only that, but MODDED Minecraft (and I have a private server).
  112.  *
  113.  * On top of that, I decided to make a Java Executable that launches Minecraft and syncs the mods
  114.  * directory from the Minecraft modded client with the global directory on an FTP connection. Simple way
  115.  * 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)
  116.  * it'll automatically sync the mods from the FTP to the client and run peacefully.
  117.  *
  118.  * Java features:
  119.  *
  120.  * - Java Swing user interface
  121.  *
  122.  *
  123.  *
  124.  *
  125.  * - Internet connection support! yay
  126.  *      - Reads raw text and "extracts" it idk
  127.  *      - FTP access
  128.  *      - Download files from Dropbox
  129.  *
  130.  * - File Transfer Protocol support with the help of apache commons net
  131.  *      - Download files to sync local folder
  132.  *      - Upload files for Manage Server feature
  133.  *      - CHAT FEATURE WOO
  134.  *
  135.  * - File modification (duh) but very basic and easy
  136.  *      - Delete files
  137.  *      - Write files
  138.  *      - Read files
  139.  *      lol
  140.  * - Command Bash and Bat edit and execution
  141.  *      - Running Minecraft
  142.  *
  143.  *
  144.  *
  145.  * - Crash Report Email with javax.mail
  146.  *      - If an error is thrown (catch from a try block), either save stacktrace to a file or
  147.  *          EMAIL IT TO ME WOOOOOOOO MAGIC
  148.  *
  149.  *
  150.  *
  151.  * - Auto Program Updater
  152.  *      - Check for program updates
  153.  *      - Automatically update program to latest version.
  154.  *      - On Windows, it downloads the new version, executes it, and the new version deletes the old version.
  155.  *      - On Mac, an external updater (DMSLauncherUpdater.jar) that is saved when the program is first downlaoded
  156.  *          is run so the internal file within DMSLauncher.app can be changed)
  157.  *
  158.  * - Password letter to specific random picked number encoder (not really a big thing)
  159.  *
  160.  * And a bunch more
  161.  *
  162.  *
  163.  *
  164.  *
  165.  * Launcher features:
  166.  *
  167.  *
  168.  * - Installs full Minecraft modded client as from my Dropbox (around 497MB on Mac, around 512MB on Windows)
  169.  * - Execute Minecraft launcher
  170.  * - RAM Allocation changing
  171.  * - Mods folder sync
  172.  * - Up to date InGameInfo.xml
  173.  * - Easy to navigate GUI (but very plain)
  174.  * - Manage server to modify files on the FTP from the program (fast)
  175.  * - Auto program updater
  176.  * - Auto mods updater
  177.  * - Show mods update summary
  178.  * - Play without updating
  179.  * - Play with updating
  180.  * - Chat feature
  181.  *
  182.  *
  183.  * ---------- NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE ----------
  184.  *
  185.  * Much if this program may be formatted weirdly because when all my computer data was lost (when I got it repaired),
  186.  * 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.
  187.  * Thank god for the JD-GUI program thing that I found online to convert my .class files into .java files (from decompiling the jar).
  188.  *
  189.  * Examples of formatted weirdly:
  190.  *
  191.  * public void example()
  192.  * { <------ WHAT IS THIS I DONT EVEN MAKE METHODS LIKE THAT
  193.  *
  194.  * }
  195.  *
  196.  * public void example() { <---- I PUT THE CURLY BRACKET OVER HERE (curly bracket, brace, whatever)
  197.  *
  198.  *
  199.  * }
  200.  *
  201.  * All of this is made by myself fancy am i right yes i am right
  202.  * Except for the fact that this is very unorganized and half of it isn't even being used
  203.  *
  204.  */
  205.  
  206. public class DMSLauncher {
  207.  
  208.  
  209.     /* TODO
  210.      *
  211.      * - Add java swing progress bar to loading screen
  212.      * - Offline feature maybe
  213.      * - Resizable feature maybe
  214.      * - Make it so chat history files are encoded or cannot be edited
  215.      *
  216.      *
  217.      *
  218.      * Add to Changelog
  219.      *
  220.      * - Add online control thing (turning off update button from online etc)
  221.      *
  222.      *
  223.      *
  224.      */
  225.  
  226.  
  227.     static String thisVer = "1.6.0.4";
  228.     static String oldVer = "";
  229.     static String content;
  230.     static String splitKey;
  231.     static JTextArea changelog;
  232.     static JTextArea console;
  233.     static JButton update;
  234.     static JButton manage;
  235.     static JButton ramAllocation;
  236.     static Container cont;
  237.     static JTabbedPane tabs;
  238.  
  239.  
  240.     static JLabel updlabel;
  241.  
  242.     //static JButton webSave;
  243.     //static JTextField webField;
  244.     //static List<InstallFile> fileinstalls;
  245.     //static String ver;
  246.     //static String verser;
  247.     static String prgmUpdateTo;
  248.     static String prgmDownload;
  249.     static String prgmPath;
  250.     static JLabel updatetext;
  251.     static JFrame frame;
  252.     static JFrame frameu;
  253.     static JFrame framex;
  254.  
  255.     static JTextArea chatBox;
  256.     static JTextField chatField;
  257.     static JButton chatSend;
  258.     static JLabel chatSending;
  259.     static boolean chatVisible = false;
  260.  
  261.  
  262.     static String clientPath;
  263.     static String web;
  264.     //static List<String> logHistory;
  265.     //static List<String> fileHistory;
  266.     static String fontType;
  267.     static String fontType2;
  268.     //static List<String> deleteIfExist;
  269.     //static Map<String, String> installMods;
  270.     static String changelogstr;
  271.     static String imageUrl = "https://i.imgur.com/OtOShOj.png";
  272.  
  273.     static List<String> delete, install;
  274.  
  275.     static FTPClient client;
  276.  
  277.     static Map<String, String> remotesettings = new HashMap<String, String>();
  278.  
  279.  
  280.     static String baseMinecraft;
  281.     static String baseminecraftWindows;
  282.     static String password;
  283.     static String igi;
  284.  
  285.     //static String host = "modded.blockhead7360.com";
  286.     static String host = "ftp.drivehq.com";
  287.     static int port = 21;
  288.     //static String user = "Blockhead7360.26120";
  289.     //static String pass = "NOT TELLING";
  290.     static String emailpass = "NOT TELLING";
  291.     static String user = "DilanFTP";
  292.     static String pass = "NOT TELLING";
  293.  
  294.     static String chat_user;
  295.  
  296.     static List<String> currentChatHist;
  297.     static List<String> totalChatHist;
  298.  
  299.     public static void saveFile(URL url, String file)
  300.             throws IOException
  301.     {
  302.         InputStream in = url.openStream();
  303.         FileOutputStream fos = new FileOutputStream(new File(file));
  304.  
  305.         int length = -1;
  306.         byte[] buffer = new byte[4096];
  307.         while ((length = in.read(buffer)) > -1) {
  308.             fos.write(buffer, 0, length);
  309.         }
  310.         fos.close();
  311.         in.close();
  312.     }
  313.  
  314.     /*public static JsonObject authMinecraft(String username, String pass){
  315.         String result = "";
  316.         try {
  317.             result = AuthMinecraft.httpRequest(new URL("https://authserver.mojang.com/authenticate"), AuthMinecraft.MakeJSONRequest(username, pass));
  318.         } catch (MalformedURLException e) {
  319.             crashReport(e);
  320.         } catch (Exception e) {
  321.             crashReport(e);
  322.         }
  323.  
  324.         //{"accessToken":"e026bc59c67644639b8b8893d9a87976","clientToken":"8eaa5aab20b44dccae26fd3d32d04327","selectedProfile":{"id":"472d43365da741eb9c0493e489a70419","name":"Blockhead7360"},"availableProfiles":[{"id":"472d43365da741eb9c0493e489a70419","name":"Blockhead7360"}]}
  325.         JsonReader reader = Json.createReader(new StringReader(result));
  326.  
  327.         JsonObject info = reader.readObject();
  328.         reader.close();
  329.  
  330.         return info;
  331.  
  332.     }*/
  333.  
  334.     public static boolean isInternetThere()
  335.     {
  336.         try {
  337.             URL url = new URL("http://www.google.com");
  338.  
  339.             HttpURLConnection urlConnect = (HttpURLConnection)url.openConnection();
  340.  
  341.  
  342.             urlConnect.getContent();
  343.  
  344.         } catch (UnknownHostException e) {
  345.             return false;
  346.         }
  347.         catch (IOException e) {
  348.             return false;
  349.         }
  350.         return true;
  351.     }
  352.    
  353.     public static void saveFileProgress(URL url, String file)
  354.             throws IOException
  355.     {
  356.  
  357.         InputStream in = url.openStream();
  358.         FileOutputStream fos = new FileOutputStream(new File(file));
  359.         HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection();
  360.         long filesize = httpConnection.getContentLengthLong();
  361.         long downloaded = 0;
  362.         console.append("Downloaded " + (downloaded / 1000000) + " MB / " + (filesize/1000000) + " MB");
  363.         int length = -1;
  364.         byte[] buffer = new byte[4096];
  365.         while ((length = in.read(buffer)) > -1) {
  366.  
  367.             console.setText(console.getText().replaceAll("Downloaded " + (downloaded/1000000) + " MB", "Downloaded " + ((downloaded + length)/1000000) + " MB"));
  368.             downloaded += length;
  369.  
  370.             fos.write(buffer, 0, length);
  371.         }
  372.         fos.close();
  373.         in.close();
  374.     }
  375.  
  376.     public static boolean isWindows(){
  377.         return !(System.getProperty("os.name").contains("mac") || System.getProperty("os.name").contains("Mac"));
  378.     }
  379.  
  380.     static boolean manage_cont = false;
  381.    
  382.     public static void beginStart(){
  383.         framex = new JFrame("DMSLauncher is starting...");
  384.         framex.setMinimumSize(new Dimension(500, 100));
  385.         framex.setPreferredSize(new Dimension(500, 100));
  386.         framex.setMaximumSize(new Dimension(500, 100));
  387.         framex.setDefaultCloseOperation(0);
  388.         framex.setLocationRelativeTo(null);
  389.         framex.setResizable(false);
  390.         Container panex = new Container();
  391.         framex.setLayout(null);
  392.         panex.setLayout(null);
  393.         JLabel labelx = new JLabel("DMSLauncher v" + thisVer + " is loading. Please wait...", 0);
  394.         labelx.setFont(new Font(fontType, 1, 16));
  395.         labelx.setBounds(new Rectangle(0, -30, 500, 100));
  396.         panex.add(labelx);
  397.  
  398.         JLabel creditx = new JLabel("Created by Dilan Nair - http://blockhead7360.com", 0);
  399.         creditx.setFont(new Font("arial", 2, 12));
  400.         creditx.setBounds(new Rectangle(0, 30, 500, 40));
  401.         panex.add(creditx);
  402.  
  403.         JLabel extrainfox = new JLabel("Some files will need to be downloaded.", 0);
  404.         extrainfox.setFont(new Font("arial", Font.BOLD, 12));
  405.         extrainfox.setBounds(new Rectangle(0, 45, 500, 40));
  406.         if (!new File(basepath, "DMSLauncherUpdater.jar").exists()){
  407.             panex.add(extrainfox);
  408.         }
  409.  
  410.  
  411.         framex.setContentPane(panex);
  412.         framex.setVisible(true);
  413.     }
  414.  
  415.  
  416.  
  417.     public DMSLauncher(String consoles)
  418.     {
  419.  
  420.         /*UnZipper zipper = new UnZipper();
  421.         try {
  422.             zipper.unzip("/Users/dilan/Desktop/Test.zip", "/Users/dilan/Desktop/Inside");
  423.         } catch (IOException e1) {
  424.             e1.printStackTrace();
  425.         }*/
  426.  
  427.        
  428.         if (!isInternetThere()) {
  429.             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");
  430.             if (val == 0) {
  431.                 playNoInternet();
  432.             }else {
  433.                 System.exit(0);
  434.             }
  435.            
  436.             return;
  437.         }
  438.  
  439.         cont = new Container();
  440.         tabs = new JTabbedPane();
  441.         tabs.setBounds(new Rectangle(0, 100, 1000, 580));
  442.         tabs.addChangeListener(new ChangeListener() {
  443.  
  444.             @Override
  445.             public void stateChanged(ChangeEvent e) {
  446.                 if (tabs.getSelectedIndex() != 1) {
  447.                     chatVisible = false;
  448.                 }else {
  449.                     chatVisible = true;
  450.                 }
  451.                 if (tabs.getSelectedIndex() == 3 && manage_cont) {
  452.                     manage_cont = false;
  453.                     return;
  454.                 }
  455.                 if (tabs.getSelectedIndex() == 3 && !manage_cont) {
  456.                     tabs.setSelectedIndex(0);
  457.                     manage(false, false);
  458.                     return;
  459.                 }
  460.                 if (tabs.getSelectedIndex() == 1 && remotesettings.containsKey("DisableChat")) {
  461.                     tabs.setSelectedIndex(0);
  462.                     canUseFeature("DisableChat");
  463.                     return;
  464.                 }
  465.                
  466.  
  467.             }
  468.  
  469.         });
  470.  
  471.         if (!isWindows()){
  472.             fontType = "monaco";
  473.             splitKey = "/";
  474.         }
  475.         else {
  476.             fontType = "consolas";
  477.             splitKey = "\\\\";
  478.         }
  479.         basepath = (new File(new JFileChooser().getFileSystemView().getDefaultDirectory(), "Documents" + splitKey + "DMSUpdater")).getPath();
  480.         fontType2 = fontType;
  481.  
  482.  
  483.         beginStart();
  484.  
  485.         client = new FTPClient();
  486.  
  487.         pause(1000L);
  488.  
  489.         clientPath = "";
  490.         web = "";
  491.         changelogstr = "";
  492.  
  493.         console = new JTextArea(consoles);
  494.  
  495.         loadFolder();
  496.         deleteOldVersion();
  497.  
  498.         pause(1000L);
  499.  
  500.         readScript();
  501.         setupScript();
  502.  
  503.         loadFrame();
  504.  
  505.  
  506.  
  507.         setupChat();
  508.         startThread();
  509.         settings();
  510.         prepareManage();
  511.  
  512.  
  513.         finishFrame();
  514.         framex.setVisible(false);
  515.         framex.dispose();
  516.  
  517.         try
  518.         {
  519.             checkForUpdates();
  520.         }
  521.         catch (MalformedURLException e)
  522.         {
  523.             crashReport(e);
  524.             return;
  525.         }
  526.         catch (IOException e)
  527.         {
  528.             crashReport(e);
  529.             return;
  530.         }
  531.     }
  532.  
  533.     public static void deleteOldVersion()
  534.     {
  535.         if (oldVer.equals(thisVer)) {
  536.             return;
  537.         }
  538.         File dir = new File(program_jar.getPath());
  539.         if (dir.exists())
  540.         {
  541.             File[] arrayOfFile;
  542.             int j = (arrayOfFile = dir.listFiles()).length;
  543.             for (int i = 0; i < j; i++)
  544.             {
  545.                 File f = arrayOfFile[i];
  546.  
  547.                 if (f.getName().startsWith("DMS Launcher " + oldVer) && f.getName().endsWith(".jar")) {
  548.                     f.delete();
  549.                 }
  550.             }
  551.         }
  552.     }
  553.  
  554.     public static void main(String[] args)
  555.     {
  556.         new DMSLauncher("");
  557.     }
  558.  
  559.     public static void setupScript()
  560.     {
  561.  
  562.     }
  563.  
  564.  
  565.     public static void clearFile(File file)
  566.     {
  567.         try
  568.         {
  569.             PrintWriter writer = new PrintWriter(file);
  570.             writer.close();
  571.         }
  572.         catch (FileNotFoundException e)
  573.         {
  574.             crashReport(e);
  575.             return;
  576.         }
  577.     }
  578.  
  579.     /*public static void setPath()
  580.     {
  581.  
  582.         boolean cont = false;
  583.  
  584.         File parent = null;
  585.  
  586.  
  587.         if ((new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Documents" + splitKey + "Curse")).exists()){
  588.             if ((new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Documents" + splitKey + "Curse" + splitKey + "Minecraft" + splitKey + "Instances")).exists()){
  589.                 cont = true;
  590.                 parent = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Documents" + splitKey + "Curse" + splitKey + "Minecraft" + splitKey + "Instances");
  591.             }
  592.         }
  593.         if ((new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Curse")).exists()){
  594.             if ((new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Curse" + splitKey + "Minecraft" + splitKey + "Instances")).exists()){
  595.                 cont = true;
  596.                 parent = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Curse" + splitKey + "Minecraft" + splitKey + "Instances");
  597.             }
  598.         }
  599.  
  600.         if (cont){
  601.  
  602.             List<Object> options = new ArrayList<Object>();
  603.  
  604.  
  605.             for (File f : parent.listFiles()){
  606.                 if (f.isDirectory()){
  607.                     options.add(f.getName());
  608.                 }
  609.             }
  610.  
  611.             Object s = JOptionPane.showInputDialog(frame, "Select an installed mod pack from below...", "Automatic Path Setter", JOptionPane.QUESTION_MESSAGE, null, options.toArray(), options.get(0));
  612.  
  613.             if (s == null){
  614.                 return;
  615.             }
  616.  
  617.  
  618.         }
  619.  
  620.         if (!cont){
  621.             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");
  622.             if (i == JOptionPane.NO_OPTION){
  623.                 return;
  624.             }
  625.         }
  626.  
  627.  
  628.  
  629.         String key;
  630.         if ((System.getProperty("os.name").contains("mac")) || (System.getProperty("os.name").contains("Mac"))) {
  631.             key = "/";
  632.         } else {
  633.             key = "\\\\";
  634.         }
  635.         JFileChooser fc = new JFileChooser();
  636.         fc.setCurrentDirectory(new File(clientPath));
  637.         fc.setFileSelectionMode(1);
  638.         fc.setDialogTitle("Find and select the mods folder for the mod pack");
  639.         int val = fc.showDialog(frame, "Set Path");
  640.         if (val == 0)
  641.         {
  642.             File file = fc.getSelectedFile();
  643.             if (file.getPath().split(key)[(file.getPath().split(key).length - 1)].equals(file.getPath().split(key)[(file.getPath().split(key).length - 2)]))
  644.             {
  645.                 String[] paths = file.getPath().split(key);
  646.                 int length = paths.length;
  647.                 paths[(length - 1)] = "";
  648.                 String path = "";
  649.                 String[] arrayOfString1;
  650.                 int j = (arrayOfString1 = paths).length;
  651.                 for (int i = 0; i < j; i++)
  652.                 {
  653.                     String x = arrayOfString1[i];
  654.                     path = path + key + x;
  655.                 }
  656.                 if (path.startsWith(key + key)) {
  657.                     path = path.replaceFirst(key, "");
  658.                 }
  659.                 if (path.endsWith(key))
  660.                 {
  661.                     int l = path.length();
  662.                     path = path.substring(0, l - 1);
  663.                 }
  664.                 file = new File(path);
  665.             }
  666.             File pathFile = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Documents" + splitKey + "DMSUpdater", "path.txt");
  667.             try
  668.             {
  669.                 clearFile(pathFile);
  670.                 Files.write(pathFile.toPath(), file.getPath().getBytes(), new OpenOption[] { StandardOpenOption.CREATE });
  671.             }
  672.             catch (IOException e1)
  673.             {
  674.                 crashReport(e1);           
  675.                 return;
  676.             }
  677.             clientPath = file.getPath().toString();
  678.             console.append("\n\nMods directory changed: \n" + clientPath);
  679.  
  680.             loadInstallFiles();
  681.         }
  682.     }
  683.      */
  684.     public static void checkForUpdates()
  685.             throws MalformedURLException, IOException
  686.     {
  687.         URL home = new URL("http://blockhead7360.com/dmsucheckforupdates");
  688.         BufferedReader in2 = new BufferedReader(new InputStreamReader(home.openStream()));
  689.  
  690.         List<String> list2 = new ArrayList<String>();
  691.         String str2;
  692.         while ((str2 = in2.readLine()) != null)
  693.         {
  694.             list2.add(str2);
  695.         }
  696.         in2.close();
  697.         String content2 = list2.toString().split("iiStartProgramii-")[1].split("iiEndProgramii")[0];
  698.  
  699.         URL find = new URL(content2);
  700.         BufferedReader in = new BufferedReader(new InputStreamReader(find.openStream()));
  701.  
  702.         List<String> list = new ArrayList<String>();
  703.         String str;
  704.         while ((str = in.readLine()) != null)
  705.         {
  706.             list.add(str);
  707.         }
  708.         in.close();
  709.  
  710.         String content = list.toString().split("iiStartProgramii-")[1].split("iiEndProgramii")[0];
  711.  
  712.         String verload = content.split("iiVersionii-")[1].split("iiStopii-")[0];
  713.  
  714.         String changelogload = content.split("iiChangelogii-")[1].split("iiStopii-")[0];
  715.         changelogload = changelogload.replaceAll("iiNLii", "\n");
  716.  
  717.         String downloadload = content.split("iiDownloadii-")[1].split("iiStopii-")[0];
  718.         if (!thisVer.equals(verload))
  719.         {
  720.             frameu = new JFrame("DMSLauncher program update available!");
  721.  
  722.             frameu.setPreferredSize(new Dimension(400, 600));
  723.             frameu.setMaximumSize(new Dimension(400, 600));
  724.             frameu.setMinimumSize(new Dimension(400, 600));
  725.             frameu.setDefaultCloseOperation(2);
  726.             frameu.setResizable(false);
  727.             frameu.setLocationRelativeTo(null);
  728.             Container pane = new Container();
  729.             frameu.setLayout(null);
  730.  
  731.             JLabel label = new JLabel("A new version of DMSLauncher is available!", 0);
  732.             label.setFont(new Font("arial", 1, 18));
  733.             label.setBounds(new Rectangle(0, 10, 400, 30));
  734.             pane.add(label);
  735.  
  736.             JTextArea area = new JTextArea();
  737.  
  738.             area.setFont(new Font(fontType, 0, 14));
  739.             area.setEditable(false);
  740.             area.setText(changelogload);
  741.             JScrollPane scroll = new JScrollPane(area);
  742.             scroll.setBounds(new Rectangle(10, 55, 380, 470));
  743.             pane.add(scroll);
  744.  
  745.             JButton button = new JButton("Update this program to v" + verload);
  746.             button.setFont(new Font(fontType, 0, 12));
  747.             button.setBounds(new Rectangle(50, 530, 300, 35));
  748.             prgmUpdateTo = verload;
  749.             prgmDownload = downloadload;
  750.             button.addActionListener(new ActionListener()
  751.             {
  752.                 public void actionPerformed(ActionEvent e)
  753.                 {
  754.                     if (!isWindows())
  755.                         DMSLauncher.externalUpdateProgram();
  756.                     else{
  757.                         SwingWorker<String, String> worker2 = new SwingWorker<String, String>()
  758.                         {
  759.                             protected String doInBackground()
  760.                             {
  761.                                 updateProgram();
  762.                                 return null;
  763.                             }
  764.                         };
  765.                         worker2.execute();
  766.                     }
  767.                 }
  768.             });
  769.             pane.add(button);
  770.  
  771.             frameu.setContentPane(pane);
  772.             frameu.setVisible(true);
  773.         }
  774.     }
  775.  
  776.     static File program_jar = new File(new JFileChooser().getFileSystemView().getDefaultDirectory(), "Documents/DMSUpdater/programjar");
  777.  
  778.  
  779.  
  780.     public static void externalUpdateProgram(){
  781.         if (!isWindows()){
  782.             try {
  783.                 Desktop.getDesktop().open(new File(basepath, "DMSLauncherUpdater.jar"));
  784.             } catch (IOException e) {
  785.                 crashReport(e);
  786.             }
  787.             saveAndExit();
  788.  
  789.             return;
  790.         }
  791.     }
  792.  
  793.  
  794.     public static void updateProgram()
  795.     {
  796.  
  797.         frameu.setVisible(false);
  798.         frameu.dispose();
  799.  
  800.         frame.setVisible(false);
  801.         frame.dispose();
  802.  
  803.         JFrame updating = new JFrame("Updating DMSLauncher to v" + prgmUpdateTo);
  804.         updating.setPreferredSize(new Dimension(400, 100));
  805.         updating.setMaximumSize(new Dimension(400, 100));
  806.         updating.setMinimumSize(new Dimension(400, 100));
  807.         updating.setDefaultCloseOperation(0);
  808.         updating.setResizable(false);
  809.         updating.setLocationRelativeTo(null);
  810.         Container pane = new Container();
  811.         updating.setLayout(null);
  812.  
  813.         updlabel = new JLabel("Downloading new version...", 0);
  814.         updlabel.setFont(new Font("arial", 1, 18));
  815.         updlabel.setBounds(new Rectangle(0, 20, 400, 40));
  816.         pane.add(updlabel);
  817.  
  818.         updating.setContentPane(pane);
  819.         updating.setVisible(true);
  820.  
  821.         boolean pause = true;
  822.         long old = System.currentTimeMillis();
  823.         while (pause) {
  824.             if (System.currentTimeMillis() - old > 1000L) {
  825.                 pause = false;
  826.             }
  827.         }
  828.         try
  829.         {
  830.             saveFile(new URL(prgmDownload), program_jar + "/DMS Launcher " + prgmUpdateTo + ".jar");
  831.         }
  832.         catch (MalformedURLException e)
  833.         {
  834.             crashReport(e);        
  835.             return;
  836.         }
  837.         catch (IOException e)
  838.         {
  839.             crashReport(e);
  840.             return;
  841.         }
  842.         boolean pausex = true;
  843.         long oldx = System.currentTimeMillis();
  844.         while (pausex) {
  845.             if (System.currentTimeMillis() - oldx > 1000L) {
  846.                 pausex = false;
  847.             }
  848.         }
  849.         try
  850.         {
  851.             Desktop.getDesktop().open(new File(program_jar + "/DMS Launcher " + prgmUpdateTo + ".jar"));
  852.         }
  853.         catch (IOException e)
  854.         {
  855.             crashReport(e);
  856.             return;
  857.         }
  858.         saveAndExit();
  859.     }
  860.  
  861.     public static void readScript()
  862.     {
  863.         URL home = null;
  864.         BufferedReader in;
  865.  
  866.         try
  867.         {
  868.             home = new URL("http://blockhead7360.com/" + web);
  869.         }
  870.         catch (MalformedURLException ex)
  871.         {
  872.             crashReport(ex);
  873.             return;
  874.         }
  875.         try
  876.         {
  877.             in = new BufferedReader(new InputStreamReader(home.openStream()));
  878.         }
  879.         catch (IOException ex)
  880.         {
  881.             crashReport(ex);
  882.             return;
  883.         }
  884.         List<String> list = new ArrayList<String>();
  885.         try
  886.         {
  887.             String str;
  888.             while ((str = in.readLine()) != null)
  889.             {
  890.                 list.add(str);
  891.             }
  892.         }
  893.         catch (IOException e)
  894.         {
  895.             crashReport(e);
  896.         }
  897.         try
  898.         {
  899.             in.close();
  900.         }
  901.         catch (IOException e)
  902.         {
  903.             crashReport(e);
  904.         }
  905.  
  906.         String content2 = list.toString().split("iiStartScriptii-")[1].split("iiEndScriptii")[0];
  907.  
  908.         URL home2 = null;
  909.         try
  910.         {
  911.             home2 = new URL(content2);
  912.         }
  913.         catch (MalformedURLException ex)
  914.         {
  915.             crashReport(ex);
  916.             return;
  917.         }
  918.         BufferedReader in2 = null;
  919.         try
  920.         {
  921.             in2 = new BufferedReader(new InputStreamReader(home2.openStream()));
  922.         }
  923.         catch (IOException ex)
  924.         {
  925.             crashReport(ex);
  926.         }
  927.         List<String> list2 = new ArrayList<String>();
  928.         try
  929.         {
  930.             String str2;
  931.             while ((str2 = in2.readLine()) != null)
  932.             {
  933.                 list2.add(str2);
  934.             }
  935.         }
  936.         catch (IOException e)
  937.         {
  938.             crashReport(e);
  939.         }
  940.         try
  941.         {
  942.             in2.close();
  943.         }
  944.         catch (IOException e)
  945.         {
  946.             crashReport(e);
  947.         }
  948.         content = list2.toString().split("iiStartScriptii-")[1].split("iiEndScriptii")[0];
  949.  
  950.         String changelogload = content.split("iiChangelogii-")[1].split("iiStopii-")[0];
  951.         changelogstr = changelogload.replaceAll("iiNLii", "\n");
  952.  
  953.         String passwordload = content.split("iiTypeii-")[1].split("iiStopii-")[0];
  954.         password = DMSLauncherPasswordEncoder.decode(passwordload);
  955.  
  956.         String baseminecraftload = content.split("iiBaseMinecraftii-")[1].split("iiStopii-")[0];
  957.         baseMinecraft = baseminecraftload;
  958.  
  959.         String baseminecraftwinload = content.split("iiBaseMinecraftWinii-")[1].split("iiStopii-")[0];
  960.         baseminecraftWindows = baseminecraftwinload;
  961.  
  962.         if (content.contains("iiRemoteSettingsii")) {
  963.             String remotesettingsload = content.split("iiRemoteSettingsii-")[1].split("iiStopii-")[0];
  964.             if (remotesettingsload.contains("iiDiffSettingii")) {
  965.                 String[] rsload_split = remotesettingsload.split("iiDiffSettingii");
  966.                 for (String j : rsload_split) {
  967.                     String[] j_split = j.split("iiSii");
  968.                     remotesettings.put(j_split[0], j_split[1]);
  969.                 }
  970.             }
  971.             else {
  972.                 String[] j_split = remotesettingsload.split("iiSii");
  973.                 remotesettings.put(j_split[0], j_split[1]);
  974.             }
  975.         }
  976.  
  977.         String igiload = content.split("iiIGIii-")[1].split("iiStopii-")[0];
  978.         igi = igiload;
  979.  
  980.         String updaterload = content.split("iiUpdaterii-")[1].split("iiStopii-")[0];
  981.         if (!new File(basepath, "DMSLauncherUpdater.jar").exists()){
  982.             try {
  983.                 saveFile(new URL(updaterload), new File(basepath, "DMSLauncherUpdater.jar").getPath());
  984.             } catch (IOException e) {
  985.                 crashReport(e);
  986.             }
  987.         }
  988.  
  989.     }
  990.  
  991.     public static void reconnectFTP(){
  992.         try {
  993.             if (client == null){
  994.                 client = new FTPClient();
  995.             }
  996.             client.connect(host, port);
  997.             client.login(user, pass);
  998.             client.enterLocalPassiveMode();
  999.             client.setFileType(FTP.BINARY_FILE_TYPE);
  1000.         } catch (SocketException e) {
  1001.             crashReport(e);
  1002.         } catch (IOException e) {
  1003.             crashReport(e);
  1004.         }
  1005.  
  1006.     }
  1007.  
  1008.     public static void checkUpdatesFromFTP(){
  1009.  
  1010.         disableFrame();
  1011.         updatetext.setText("Checking for updates...");
  1012.  
  1013.         FTPClient ftpclient = new FTPClient();
  1014.  
  1015.         try{
  1016.  
  1017.             console.append("Connecting to FTP server...\n\n");
  1018.             ftpclient.connect(host, port);
  1019.             console.append("Logging in to FTP server...\n\n");
  1020.             ftpclient.login(user, pass);
  1021.             console.append("Connected!\n\n\n");
  1022.             ftpclient.enterLocalPassiveMode();
  1023.             ftpclient.setFileType(FTP.BINARY_FILE_TYPE);
  1024.  
  1025.             client = ftpclient;
  1026.  
  1027.             ftpclient.changeWorkingDirectory("/DMSLauncher");
  1028.  
  1029.             FTPFile[] away = ftpclient.listFiles();
  1030.  
  1031.             File[] home = (new File(basepath, "Game/mods")).listFiles();
  1032.  
  1033.  
  1034.             List<String> client = new ArrayList<String>();
  1035.             List<String> server = new ArrayList<String>();
  1036.  
  1037.             console.append("Checking for updates...\n\n");
  1038.  
  1039.             for (File f : home){
  1040.                 if (!f.getName().contains("DS_Store")){
  1041.                     client.add(f.getName());
  1042.                 }
  1043.             }
  1044.  
  1045.             for (FTPFile f : away){
  1046.                 if (!f.getName().contains("DS_Store")){
  1047.                     server.add(f.getName());
  1048.                 }
  1049.             }
  1050.  
  1051.             updatetext.setText(" ");
  1052.             enableFrame();
  1053.  
  1054.             if (client.size() != server.size()){
  1055.                 console.append("An update is available.\n\n");
  1056.                 summaryAndConfirmUpdate(client, server);
  1057.  
  1058.             }else{
  1059.                 console.append("No update available.\n\n");
  1060.                 play();
  1061.  
  1062.             }
  1063.  
  1064.  
  1065.  
  1066.  
  1067.         }catch(IOException ex){
  1068.             crashReport(ex);
  1069.         }
  1070.  
  1071.  
  1072.     }
  1073.  
  1074.  
  1075.     public static void appendConsole(String txt)
  1076.     {
  1077.         console.append(txt);
  1078.     }
  1079.  
  1080.  
  1081.  
  1082.     static boolean inThreadedProcess = false;
  1083.  
  1084.     public static void startThread(){
  1085.  
  1086.         Runnable r = new Runnable(){
  1087.             public void run(){
  1088.                 if (!inThreadedProcess){
  1089.                     inThreadedProcess = true;
  1090.                     if (!chat_user.equalsIgnoreCase("None") && !chat_user.equalsIgnoreCase("Not Logged In")){
  1091.  
  1092.                         if (!client.isConnected()) reconnectFTP();
  1093.                         try {
  1094.                             client.changeWorkingDirectory("/DMSLauncherChat/" + chat_user);
  1095.                         } catch (IOException e) {
  1096.                             crashReport(e);
  1097.                         }
  1098.  
  1099.  
  1100.                         try {
  1101.  
  1102.  
  1103.                             FTPFile[] unread = client.listFiles();
  1104.                             if (unread.length >= 1){
  1105.  
  1106.                                 for (FTPFile f : unread){
  1107.                                     File temp1 = new File(basepath, "Chat/Connection");
  1108.                                     if (!temp1.exists()) temp1.mkdir();
  1109.                                     File temp2 = new File(basepath, "Chat/Connection/Download");
  1110.                                     if (!temp2.exists()) temp2.mkdir();
  1111.  
  1112.                                     OutputStream os = new BufferedOutputStream(new FileOutputStream(new File(basepath, "Chat/Connection/Download/reading.txt")));
  1113.                                     InputStream is = client.retrieveFileStream(f.getName());
  1114.                                     byte[] bytes = new byte[4096];
  1115.                                     int byteread = -1;
  1116.                                     while ((byteread = is.read(bytes)) != -1){
  1117.                                         os.write(bytes, 0, byteread);
  1118.                                     }
  1119.                                     client.completePendingCommand();
  1120.                                     os.close();
  1121.                                     is.close();
  1122.  
  1123.  
  1124.                                     String s = Files.readAllLines(new File(basepath, "Chat/Connection/Download/reading.txt").toPath()).get(0);
  1125.  
  1126.                                     pause(100L);
  1127.                                     client.deleteFile(f.getName());
  1128.                                     new File(basepath, "Chat/Connection/Download/reading.txt").delete();
  1129.  
  1130.                                     totalChatHist.add(s);
  1131.  
  1132.                                     SwingWorker<String, String> worker = new SwingWorker<String, String>(){
  1133.  
  1134.                                         protected String doInBackground(){
  1135.  
  1136.                                             chatBox.setText(fromListChat(totalChatHist));
  1137.  
  1138.                                             return null;
  1139.                                         }
  1140.  
  1141.                                     };
  1142.                                     worker.execute();
  1143.  
  1144.  
  1145.                                 }
  1146.  
  1147.  
  1148.  
  1149.  
  1150.                             }
  1151.  
  1152.  
  1153.                         } catch (FileNotFoundException e) {
  1154.                             crashReport(e);
  1155.                         } catch (IOException e) {
  1156.                             return;
  1157.                         }
  1158.  
  1159.                         if (chatVisible){
  1160.                             currentChatHist.clear();
  1161.                             currentChatHist.addAll(totalChatHist);
  1162.                         }
  1163.  
  1164.                         int notification = totalChatHist.size() - currentChatHist.size();
  1165.  
  1166.                         SwingWorker<String, String> worker = new SwingWorker<String, String>(){
  1167.  
  1168.                             protected String doInBackground(){
  1169.                                 tabs.setTitleAt(1, (notification <= 0 ? "Chat" : "Chat (" + notification + ")"));
  1170.                                 return null;
  1171.                             }
  1172.  
  1173.                         };
  1174.                         worker.execute();
  1175.  
  1176.  
  1177.                     }
  1178.  
  1179.                     inThreadedProcess = false;
  1180.  
  1181.                 }
  1182.             }
  1183.         };
  1184.  
  1185.         ScheduledExecutorService ex = Executors.newSingleThreadScheduledExecutor();
  1186.         ex.scheduleAtFixedRate(r, 0, 3, TimeUnit.SECONDS);
  1187.  
  1188.     }
  1189.  
  1190.  
  1191.     static Exception exinfo;
  1192.  
  1193.  
  1194.  
  1195.  
  1196.     static URL sfp_url;
  1197.     static String sfp_file;
  1198.  
  1199.  
  1200.  
  1201.     public static void setupChat(){
  1202.  
  1203.         JPanel pane = new JPanel();
  1204.         pane.setLayout(null);
  1205.  
  1206.         chatBox = new JTextArea();
  1207.         chatBox.setMargin(new Insets(10, 10, 10, 10));
  1208.         chatBox.setBounds(new Rectangle(25, 25, 800-50, 400));
  1209.         chatBox.setFont(new Font(fontType, Font.PLAIN, 14));
  1210.         chatBox.setEditable(false);
  1211.         chatBox.setText(fromListChat(totalChatHist));
  1212.         chatBox.setCaretPosition(chatBox.getText().length());
  1213.         chatBox.setVisible(true);
  1214.         DefaultCaret caret = (DefaultCaret) chatBox.getCaret();
  1215.         caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
  1216.         JScrollPane chatBoxPane = new JScrollPane(chatBox);
  1217.         chatBoxPane.setBounds(new Rectangle(5, 5, 970, 480));
  1218.         pane.add(chatBoxPane);
  1219.  
  1220.         chatField = new JTextField();
  1221.         chatField.setBounds(new Rectangle(25+100, 495, 800-50, 30));
  1222.         chatField.setVisible(true);
  1223.         pane.add(chatField);
  1224.  
  1225.         chatSend = new JButton((chat_user.equalsIgnoreCase("None") ? "Log In" : "Send"));
  1226.         chatSend.setBounds(new Rectangle(1000-90-25, 495, 90, 30));
  1227.         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."));
  1228.         chatSend.setVisible(true);
  1229.  
  1230.         ActionListener al = new ActionListener(){
  1231.             public void actionPerformed(ActionEvent e){
  1232.                 SwingWorker<String, String> worker = new SwingWorker<String, String>(){
  1233.  
  1234.                     protected String doInBackground(){
  1235.                         if (chatField.getText() == null || chatField.getText().isEmpty()){
  1236.                             if (chat_user.equalsIgnoreCase("None")){
  1237.                                 JOptionPane.showMessageDialog(null, "Please provide your login ID to log in to the chat servers.", "Error Logging In", JOptionPane.ERROR_MESSAGE);
  1238.                                 return null;
  1239.                             }
  1240.                             return null;
  1241.                         }
  1242.                         if (chat_user.equalsIgnoreCase("None")){
  1243.                             chatSending.setText("Logging in...");
  1244.                             if (!client.isConnected()) reconnectFTP();
  1245.                             try {
  1246.  
  1247.                                 client.changeWorkingDirectory("/DMSLauncherChat");
  1248.  
  1249.                                 FTPFile[] list = client.listDirectories();
  1250.                                 for (FTPFile f : list){
  1251.                                     if (f.getName().split("ii")[0].equalsIgnoreCase(chatField.getText())){
  1252.                                         chat_user = f.getName();
  1253.  
  1254.                                         File chatLoginFile = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Documents" + splitKey + "DMSUpdater" + splitKey + "Chat", "chatLogin.txt");
  1255.                                         clearFile(chatLoginFile);
  1256.                                         Files.write(chatLoginFile.toPath(), f.getName().getBytes(), new OpenOption[] { StandardOpenOption.CREATE });
  1257.                                         chatSending.setText("Logged in as " + chat_user.split("ii")[1]);
  1258.                                         chatField.setText("");
  1259.                                         return null;
  1260.                                     }
  1261.                                 }
  1262.  
  1263.                                 chatField.setText("");
  1264.                                 chatSending.setText("Not logged in");
  1265.                                 JOptionPane.showMessageDialog(null, "This login ID does not exist! Try again.", "Error Logging In", JOptionPane.ERROR_MESSAGE);
  1266.                                 return null;
  1267.  
  1268.                             } catch (IOException e1) {
  1269.                                 crashReport(e1);
  1270.                             }
  1271.                             return null;
  1272.  
  1273.                         }
  1274.  
  1275.                         if (chatField.getText().startsWith("/")){
  1276.                             String cmd = chatField.getText();
  1277.                             if (cmd.equalsIgnoreCase("/help")){
  1278.                                 String s = "";
  1279.  
  1280.                                 List<String> list = new ArrayList<String>();
  1281.                                 list.add("NO COMMANDS YET. Idk if I really want to add this feature.");
  1282.  
  1283.                                 for (String x : list){
  1284.                                     s += x + "\n";
  1285.                                 }
  1286.                                 JOptionPane.showMessageDialog(null, "The following commands are available for use:\n\n" + s);
  1287.                                 chatField.setText("");
  1288.                                 return null;
  1289.                             }
  1290.                             chatField.setText("");
  1291.  
  1292.                             JOptionPane.showMessageDialog(null, "Unknown command. Type \'/help\' for help.", "Unknown Command", JOptionPane.ERROR_MESSAGE);
  1293.                             return null;
  1294.                         }
  1295.                         sendChat(chatField.getText());
  1296.                         chatField.setText("");
  1297.                         return null;
  1298.                     }
  1299.                 };
  1300.                 worker.execute();
  1301.             }
  1302.         };
  1303.         chatSend.addActionListener(al);
  1304.         chatField.addActionListener(al);
  1305.  
  1306.         pane.add(chatSend);
  1307.  
  1308.         chatSending = new JLabel((chat_user.equalsIgnoreCase("None") ? "Not logged in" : "Logged in as " + chat_user.split("ii")[1]), 0);
  1309.         chatSending.setFont(new Font("arial", Font.BOLD, 12));
  1310.         chatSending.setBounds(new Rectangle(0, 495, 125, 30));
  1311.         pane.add(chatSending);
  1312.  
  1313.         tabs.addTab("Chat", null, pane, "Chat with other clients");
  1314.  
  1315.     }
  1316.  
  1317.     /*public static void chat(){
  1318.         chatFrame.setVisible(true);
  1319.         chatVisible = true;
  1320.         currentChatHist.clear();
  1321.         currentChatHist.addAll(totalChatHist);
  1322.         chat.setText("Chat");
  1323.     }*/
  1324.  
  1325.     public static String fromListChat(List<String> list){
  1326.         String s = "";
  1327.         for (String x : list){
  1328.             s += x + "\n\n";
  1329.         }
  1330.         return s;
  1331.     }
  1332.  
  1333.     public static String getRandomString(){
  1334.         String j = "abcdefghijklmnopqrstuvwxyz1234567890";
  1335.         String total = "";
  1336.  
  1337.  
  1338.         Random r = new Random();
  1339.  
  1340.         for (int i = 0; i < 32; i++){
  1341.             total += Character.toString(j.charAt(r.nextInt(36)));
  1342.         }
  1343.         return total;
  1344.     }
  1345.  
  1346.     static int sendError = 0;
  1347.  
  1348.     public static void sendChat(String message){
  1349.  
  1350.         if (message.isEmpty()) return;
  1351.  
  1352.         SwingWorker<String, String> worker = new SwingWorker<String, String>(){
  1353.  
  1354.  
  1355.             protected String doInBackground() {
  1356.  
  1357.                 inThreadedProcess = true;
  1358.  
  1359.                 if (!client.isConnected()) reconnectFTP();
  1360.  
  1361.  
  1362.                 chatSending.setText("Sending...");
  1363.                 chatField.setEnabled(false);
  1364.                 chatSend.setEnabled(false);
  1365.  
  1366.                
  1367.  
  1368.                 try {
  1369.                     client.changeWorkingDirectory("/DMSLauncherChat");
  1370.  
  1371.                     File temp1 = new File(basepath, "Chat/Connection");
  1372.                     if (!temp1.exists()) temp1.mkdir();
  1373.                     File temp2 = new File(basepath, "Chat/Connection/Upload");
  1374.                     if (!temp2.exists()) temp2.mkdir();
  1375.  
  1376.                     File f = new File(basepath, "Chat/Connection/Upload/writing.txt");
  1377.                     if (!f.exists()) f.createNewFile();
  1378.                     List<String> test = new ArrayList<String>();
  1379.                     test.add((chat_user.split("ii")[1] + " > " + message));
  1380.                     Files.write(f.toPath(), test, StandardOpenOption.CREATE);
  1381.  
  1382.                     FTPFile[] dir = client.listDirectories();
  1383.  
  1384.                     for (FTPFile fx : dir){
  1385.                         if (fx.getName().equals(chat_user)) continue;
  1386.                         client.changeWorkingDirectory("/DMSLauncherChat/" + fx.getName());
  1387.                         InputStream is = new FileInputStream(f);
  1388.                         OutputStream os = client.storeFileStream(getRandomString() + ".txt");
  1389.                         byte[] bytes = new byte[4096];
  1390.                         int read = 0;
  1391.  
  1392.                         while ((read = is.read(bytes)) != -1){
  1393.                             os.write(bytes, 0, read);
  1394.                         }
  1395.                         is.close();
  1396.                         os.close();
  1397.  
  1398.                         client.completePendingCommand();
  1399.  
  1400.  
  1401.                     }
  1402.  
  1403.                     new File(basepath, "Chat/Connection/Upload/writing.txt").delete();
  1404.  
  1405.                     chatSending.setText("Logged in as " + chat_user.split("ii")[1]);
  1406.                     chatField.setEnabled(true);
  1407.                     chatSend.setEnabled(true);
  1408.                     sendError = 0;
  1409.  
  1410.                 } catch (FileNotFoundException e) {
  1411.                     crashReport(e);
  1412.                 } catch (IOException e) {
  1413.                     chatSending.setText("FTP error!");
  1414.                     pause(1000L);
  1415.                     chatSending.setText("Trying again...");
  1416.                     pause(1000L);
  1417.                     if (sendError == 3){
  1418.                         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);
  1419.  
  1420.                         totalChatHist.add("(not sent) " + chat_user.split("ii")[1] + " > " + message);
  1421.                         currentChatHist.clear();
  1422.                         currentChatHist.addAll(totalChatHist);
  1423.                         chatBox.setText(fromListChat(totalChatHist));
  1424.  
  1425.                         inThreadedProcess = false;
  1426.                         return null;
  1427.                     }else{
  1428.                         sendError++;
  1429.                         sendChat(message);
  1430.                         return null;
  1431.                     }
  1432.  
  1433.                 }
  1434.  
  1435.                 totalChatHist.add(chat_user.split("ii")[1] + " > " + message);
  1436.                 currentChatHist.clear();
  1437.                 currentChatHist.addAll(totalChatHist);
  1438.                 chatBox.setText(fromListChat(totalChatHist));
  1439.  
  1440.  
  1441.                 inThreadedProcess = false;
  1442.  
  1443.                 return null;
  1444.             }
  1445.  
  1446.         };
  1447.         worker.execute();
  1448.     }
  1449.  
  1450.     public static void play(){
  1451.         /*UnZipper unzip = new UnZipper();
  1452.         try {
  1453.             unzip.unzip("/Users/dilan/Desktop/MCFiles.zip", "/Users/dilan/Desktop/Extracted");
  1454.         } catch (IOException e) {
  1455.             e.printStackTrace();
  1456.         }
  1457.  
  1458.         pause();*/
  1459.  
  1460.         SwingWorker<String, String> worker6 = new SwingWorker<String, String>(){
  1461.  
  1462.             protected String doInBackground(){
  1463.                 playGo();
  1464.                 return null;
  1465.             }
  1466.  
  1467.         };
  1468.  
  1469.         worker6.execute();
  1470.  
  1471.  
  1472.     }
  1473.     public static void playNoInternet(){
  1474.         /*UnZipper unzip = new UnZipper();
  1475.         try {
  1476.             unzip.unzip("/Users/dilan/Desktop/MCFiles.zip", "/Users/dilan/Desktop/Extracted");
  1477.         } catch (IOException e) {
  1478.             e.printStackTrace();
  1479.         }
  1480.  
  1481.         pause();*/
  1482.  
  1483.         SwingWorker<String, String> worker6 = new SwingWorker<String, String>(){
  1484.  
  1485.             protected String doInBackground(){
  1486.                 playWithoutInternet();
  1487.                 return null;
  1488.             }
  1489.  
  1490.         };
  1491.  
  1492.         worker6.execute();
  1493.  
  1494.  
  1495.     }
  1496.  
  1497.     public static void playWithoutInternet(){
  1498.  
  1499.         if (new File(new File(basepath, "Game"), "runMC" + (isWindows() ? ".bat" : ".command")).exists()){
  1500.             new File(new File(basepath, "Game"), "runMC" + (isWindows() ? ".bat" : ".command")).delete();
  1501.         }
  1502.  
  1503.         if (isWindows()){
  1504.  
  1505.             List<String> runcmd = new ArrayList<String>();
  1506.             String path = new File(basepath, "Game").getPath();
  1507.             runcmd.add("cd " + path);
  1508.             runcmd.add("start \"\" MinecraftLauncher.exe --workDir " + path);
  1509.             runcmd.add("exit");
  1510.             try {
  1511.                 new File(new File(basepath, "Game"), "runMC.bat").createNewFile();
  1512.  
  1513.                 Files.write(new File(basepath, "Game/runMC.bat").toPath(), runcmd, StandardOpenOption.CREATE);
  1514.             } catch (IOException e) {
  1515.                 crashReport(e);
  1516.             }
  1517.  
  1518.         }else{
  1519.  
  1520.             List<String> runcmd = new ArrayList<String>();
  1521.             String path = new File(basepath, "Game").getPath();
  1522.             runcmd.add("cd " + path);
  1523.             runcmd.add("chmod +x " + path + "/Minecraft.app/Contents/MacOS/launcher");
  1524.             runcmd.add("open Minecraft.app --args --workDir " + path);
  1525.             runcmd.add("osascript -e \"do shell script \\\"osascript -e \\\\\\\"tell application \\\\\\\\\\\\\\\"Terminal\\\\\\\\\\\\\\\" to quit\\\\\\\" &> /dev/null &\\\"\"; exit");
  1526.             try {
  1527.                 Files.write(new File(basepath, "Game/runMC.command").toPath(), runcmd, StandardOpenOption.CREATE);
  1528.             } catch (IOException e) {
  1529.                 crashReport(e);
  1530.             }
  1531.  
  1532.         }
  1533.  
  1534.         pause(500L);
  1535.  
  1536.  
  1537.         if (!isWindows()){
  1538.             try {
  1539.  
  1540.                 Runtime.getRuntime().exec("chmod +x " + basepath + "/Game/runMC.command");
  1541.                 pause(500L);
  1542.                 Desktop.getDesktop().open(new File(basepath, "Game/runMC.command"));
  1543.             } catch (IOException e) {
  1544.                 crashReport(e);
  1545.             }
  1546.         }else{
  1547.             try{
  1548.                 Desktop.getDesktop().open(new File(basepath, "Game/runMC.bat"));
  1549.             }catch(IOException e){
  1550.                 crashReport(e);
  1551.             }
  1552.         }
  1553.  
  1554.         pause(1000L);
  1555.         System.exit(0);
  1556.     }
  1557.    
  1558.  
  1559.     public static void playGo(){
  1560.  
  1561.         disableFrame();
  1562.  
  1563.         console.append("\nRefreshing InGameInfo.xml...\n\n");
  1564.  
  1565.  
  1566.  
  1567.  
  1568.         try {
  1569.             saveFile(new URL(igi), new File(basepath, "Game/config/InGameInfo.xml").getPath());
  1570.         } catch (MalformedURLException e1) {
  1571.             crashReport(e1);
  1572.         } catch (IOException e1) {
  1573.             crashReport(e1);
  1574.         }
  1575.  
  1576.         pause(500L);
  1577.  
  1578.         console.append("\nRefreshing runMC" + (isWindows() ? ".bat" : ".command") + "...\n\n");
  1579.  
  1580.         console.append("Creating run command file...\n\n");
  1581.  
  1582.         if (new File(new File(basepath, "Game"), "runMC" + (isWindows() ? ".bat" : ".command")).exists()){
  1583.             new File(new File(basepath, "Game"), "runMC" + (isWindows() ? ".bat" : ".command")).delete();
  1584.         }
  1585.  
  1586.         if (isWindows()){
  1587.  
  1588.             List<String> runcmd = new ArrayList<String>();
  1589.             String path = new File(basepath, "Game").getPath();
  1590.             runcmd.add("cd " + path);
  1591.             runcmd.add("start \"\" MinecraftLauncher.exe --workDir " + path);
  1592.             runcmd.add("exit");
  1593.             try {
  1594.                 Files.write(new File(new File(basepath, "Game"), "runMC.bat").toPath(), runcmd, StandardOpenOption.CREATE);
  1595.             } catch (IOException e) {
  1596.                 crashReport(e);
  1597.             }
  1598.  
  1599.         }else{
  1600.  
  1601.             List<String> runcmd = new ArrayList<String>();
  1602.             String path = new File(basepath, "Game").getPath();
  1603.             runcmd.add("cd " + path);
  1604.             runcmd.add("chmod +x " + path + "/Minecraft.app/Contents/MacOS/launcher");
  1605.             runcmd.add("open Minecraft.app --args --workDir " + path);
  1606.             runcmd.add("osascript -e \"do shell script \\\"osascript -e \\\\\\\"tell application \\\\\\\\\\\\\\\"Terminal\\\\\\\\\\\\\\\" to quit\\\\\\\" &> /dev/null &\\\"\"; exit");
  1607.             try {
  1608.                 Files.write(new File(new File(basepath, "Game"), "runMC.command").toPath(), runcmd, StandardOpenOption.CREATE);
  1609.             } catch (IOException e) {
  1610.                 crashReport(e);
  1611.             }
  1612.  
  1613.         }
  1614.  
  1615.         pause(500L);
  1616.  
  1617.         console.append("\nOpening Minecraft launcher...");
  1618.  
  1619.  
  1620.         if (!isWindows()){
  1621.             try {
  1622.  
  1623.                 Runtime.getRuntime().exec("chmod +x " + basepath + "/Game/runMC.command");
  1624.                 pause(500L);
  1625.                 Desktop.getDesktop().open(new File(basepath, "Game/runMC.command"));
  1626.             } catch (IOException e) {
  1627.                 crashReport(e);
  1628.             }
  1629.         }else{
  1630.             try{
  1631.                 Desktop.getDesktop().open(new File(basepath, "Game/runMC.bat"));
  1632.             }catch(IOException e){
  1633.                 crashReport(e);
  1634.             }
  1635.         }
  1636.  
  1637.         pause(1000L);
  1638.         saveAndExit();
  1639.     }
  1640.  
  1641.     public static void pause(long ms){
  1642.         boolean pause = true;
  1643.         long old = System.currentTimeMillis();
  1644.         while (pause) {
  1645.             if (System.currentTimeMillis() - old > ms) {
  1646.                 pause = false;
  1647.             }
  1648.         }
  1649.     }
  1650.  
  1651.  
  1652.  
  1653.     public static void update()
  1654.     {
  1655.         //webField.setEditable(false);
  1656.         //webSave.setEnabled(false);
  1657.         disableFrame();
  1658.         updatetext.setText("Updating modded client...");
  1659.  
  1660.         console.append("\n\nUpdating client mods to match\nwith server\'s client selection...\n\n\n");
  1661.  
  1662.         for (String s : delete){
  1663.             File file = new File(new File(basepath, "Game/mods"), s);
  1664.             if (file.exists()){
  1665.                 file.delete();
  1666.                 console.append("Deleted file:\n" + s + "\n\n");
  1667.                 pause(250L);
  1668.             }
  1669.         }
  1670.  
  1671.         for (String s : install){
  1672.  
  1673.             console.append("Downloading file:\n" + s + "\n");
  1674.             File file = new File(new File(basepath, "Game/mods"), s);
  1675.  
  1676.  
  1677.             try {
  1678.                 client.changeWorkingDirectory("/DMSLauncher");
  1679.             } catch (IOException e) {
  1680.                 crashReport(e);
  1681.             }
  1682.  
  1683.  
  1684.             try {
  1685.                 OutputStream os = new BufferedOutputStream(new FileOutputStream(file));
  1686.                 InputStream is = client.retrieveFileStream(s);
  1687.                 byte[] bytes = new byte[4096];
  1688.                 int byteread = -1;
  1689.                 while ((byteread = is.read(bytes)) != -1){
  1690.                     os.write(bytes, 0, byteread);
  1691.                 }
  1692.                 boolean success = client.completePendingCommand();
  1693.                 if (success){
  1694.                     console.append("Complete!\n\n");
  1695.                 }
  1696.                 os.close();
  1697.                 is.close();
  1698.  
  1699.             } catch (FileNotFoundException e) {
  1700.                 crashReport(e);
  1701.             } catch (IOException e) {
  1702.                 crashReport(e);
  1703.             }
  1704.  
  1705.  
  1706.         }
  1707.  
  1708.  
  1709.  
  1710.  
  1711.         enableFrame();
  1712.         updatetext.setText(" ");
  1713.  
  1714.         console.append("\n\n\nUpdate is complete!\n\n");
  1715.         pause(1000L);
  1716.         play();
  1717.     }
  1718.  
  1719.     static String basepath;
  1720.  
  1721.     public static void loadFolder()
  1722.     {
  1723.  
  1724.         web = "script";
  1725.  
  1726.         File base_folder = new File(new JFileChooser().getFileSystemView().getDefaultDirectory(), "Documents" + splitKey + "DMSUpdater");
  1727.         if (!base_folder.exists()) {
  1728.             base_folder.mkdirs();
  1729.         }
  1730.         File prgmVerFile = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Documents" + splitKey + "DMSUpdater", "prgm.txt");
  1731.         if (prgmVerFile.exists())
  1732.         {
  1733.             List<String> lines = null;
  1734.             try
  1735.             {
  1736.                 lines = Files.readAllLines(prgmVerFile.toPath());
  1737.             }
  1738.             catch (IOException e)
  1739.             {
  1740.                 crashReport(e);
  1741.             }
  1742.             oldVer = (String)lines.get(0);
  1743.         }
  1744.         if (!prgmVerFile.exists()) {
  1745.             try
  1746.             {
  1747.                 prgmVerFile.createNewFile();
  1748.             }
  1749.             catch (IOException e)
  1750.             {
  1751.                 crashReport(e);
  1752.                 return;
  1753.             }
  1754.         }
  1755.         String contentx1 = thisVer;
  1756.         try
  1757.         {
  1758.             clearFile(prgmVerFile);
  1759.             Files.write(prgmVerFile.toPath(), contentx1.getBytes(), new OpenOption[] { StandardOpenOption.CREATE });
  1760.         }
  1761.         catch (IOException e)
  1762.         {
  1763.             crashReport(e);
  1764.         }
  1765.         File chatfile = new File(basepath, "Chat");
  1766.         if (!chatfile.exists()) chatfile.mkdir();
  1767.  
  1768.         File chatLoginFile = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Documents" + splitKey + "DMSUpdater" + splitKey + "Chat", "chatLogin.txt");
  1769.         if (chatLoginFile.exists())
  1770.         {
  1771.             List<String> lines = null;
  1772.             try
  1773.             {
  1774.                 lines = Files.readAllLines(chatLoginFile.toPath());
  1775.             }
  1776.             catch (IOException e)
  1777.             {
  1778.                 crashReport(e);
  1779.             }
  1780.             chat_user = lines.get(0);
  1781.         }
  1782.         if (!chatLoginFile.exists()) {
  1783.             try
  1784.             {
  1785.                 chatLoginFile.createNewFile();
  1786.             }
  1787.             catch (IOException e)
  1788.             {
  1789.                 crashReport(e);
  1790.                 return;
  1791.             }
  1792.  
  1793.             String contentx5 = "None";
  1794.  
  1795.             try
  1796.             {
  1797.                 clearFile(chatLoginFile);
  1798.                 Files.write(chatLoginFile.toPath(), contentx5.getBytes(), new OpenOption[] { StandardOpenOption.CREATE });
  1799.             }
  1800.             catch (IOException e)
  1801.             {
  1802.                 crashReport(e);
  1803.             }
  1804.             chat_user = "None";
  1805.         }
  1806.  
  1807.  
  1808.  
  1809.         if (new File(basepath, "Chat/ftp.txt").exists())
  1810.             try {
  1811.                 currentChatHist = Files.readAllLines(new File(basepath, "Chat/ftp.txt").toPath());
  1812.                 totalChatHist = new ArrayList<String>();
  1813.                 totalChatHist.addAll(currentChatHist);
  1814.             } catch (IOException e1) {
  1815.                 crashReport(e1);
  1816.             }
  1817.         else{
  1818.             currentChatHist = new ArrayList<String>();
  1819.             totalChatHist = new ArrayList<String>();
  1820.         }
  1821.  
  1822.  
  1823.         /*File chatHistory = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Documents" + splitKey + "DMSUpdater", "chatHistory.txt");
  1824.         if (chatHistory.exists())
  1825.         {
  1826.             List<String> lines = null;
  1827.             try
  1828.             {
  1829.                 lines = Files.readAllLines(chatHistory.toPath());
  1830.             }
  1831.             catch (IOException e)
  1832.             {
  1833.                 crashReport(e);
  1834.             }
  1835.             currentChatHist = lines;
  1836.         }
  1837.         if (!chatHistory.exists()) {
  1838.             try
  1839.             {
  1840.                 chatHistory.createNewFile();
  1841.             }
  1842.             catch (IOException e)
  1843.             {
  1844.                 crashReport(e);
  1845.                 return;
  1846.             }
  1847.  
  1848.             String contentx5 = "TOP OF HISTORY";
  1849.  
  1850.             try
  1851.             {
  1852.                 clearFile(chatHistory);
  1853.                 Files.write(chatHistory.toPath(), contentx5.getBytes(), new OpenOption[] { StandardOpenOption.CREATE });
  1854.             }
  1855.             catch (IOException e)
  1856.             {
  1857.                 crashReport(e);
  1858.             }
  1859.             ArrayList<String> c = new ArrayList<String>();
  1860.             c.add("TOP OF HISTORY");
  1861.             currentChatHist = c;
  1862.         }*/
  1863.  
  1864.         File locationFile = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Documents" + splitKey + "DMSUpdater", "programlocation.txt");
  1865.         if (!locationFile.exists()) {
  1866.             try
  1867.             {
  1868.                 locationFile.createNewFile();
  1869.             }
  1870.             catch (IOException e)
  1871.             {
  1872.                 crashReport(e);
  1873.             }
  1874.         }
  1875.         try
  1876.         {
  1877.             String content = DMSLauncher.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
  1878.  
  1879.             /*String[] contents = content.split(splitKey);
  1880.             int length = contents.length;
  1881.             contents[(length - 1)] = "";
  1882.             content = "";
  1883.             String[] arrayOfString1;
  1884.             int j = (arrayOfString1 = contents).length;
  1885.             for (int i = 0; i < j; i++)
  1886.             {
  1887.                 String x = arrayOfString1[i];
  1888.                 content = content + splitKey + x;
  1889.             }
  1890.             if (content.startsWith(splitKey + splitKey)) {
  1891.                 content = content.replaceFirst(splitKey, "");
  1892.             }
  1893.             if (content.endsWith(splitKey))
  1894.             {
  1895.                 int l = content.length();
  1896.                 content = content.substring(0, l - 1);
  1897.             }*/
  1898.             /*clearFile(locationFile);
  1899.             String[] ss = content.split(splitKey);
  1900.             String l = "";
  1901.             for (int i = 0; i < ss.length - 1; i++){
  1902.  
  1903.                 l += ss[i] + (i == ss.length - 2 ? "" : splitKey);
  1904.             }
  1905.              */
  1906.  
  1907.             content = content.replace("/DMSLauncher.jar", "");
  1908.             clearFile(locationFile);
  1909.             Files.write(locationFile.toPath(), content.getBytes(), new OpenOption[] { StandardOpenOption.CREATE });
  1910.  
  1911.             prgmPath = content;
  1912.         }
  1913.         catch (URISyntaxException e)
  1914.         {
  1915.             crashReport(e);
  1916.         }
  1917.         catch (IOException e)
  1918.         {
  1919.             crashReport(e);
  1920.         }
  1921.     }
  1922.  
  1923.  
  1924.     public static List<List<String>> updateNotes(List<String> clientFiles, List<String> serverFiles){
  1925.  
  1926.         List<String> deleteMods = new ArrayList<String>();
  1927.  
  1928.         for (String s : clientFiles){
  1929.             if (!serverFiles.contains(s)){
  1930.                 deleteMods.add(s);
  1931.             }
  1932.         }
  1933.  
  1934.         List<String> installMods = new ArrayList<String>();
  1935.  
  1936.         for (String s : serverFiles){
  1937.             if (!clientFiles.contains(s)){
  1938.                 installMods.add(s);
  1939.             }
  1940.         }
  1941.  
  1942.         List<List<String>> list = new ArrayList<List<String>>();
  1943.  
  1944.         list.add(deleteMods);
  1945.         list.add(installMods);
  1946.  
  1947.         return list;
  1948.  
  1949.  
  1950.     }
  1951.  
  1952.     public static void summaryAndConfirmUpdate(List<String> clientFiles, List<String> serverFiles){
  1953.         {
  1954.             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");
  1955.             if (result == 0)
  1956.             {
  1957.                 List<List<String>> mods = updateNotes(clientFiles, serverFiles);
  1958.                 delete = mods.get(0);
  1959.                 install = mods.get(1);
  1960.  
  1961.                 SwingWorker<String, String> worker = new SwingWorker<String, String>()
  1962.                 {
  1963.                     protected String doInBackground()
  1964.                     {
  1965.                         DMSLauncher.update();
  1966.                         return null;
  1967.                     }
  1968.                 };
  1969.                 worker.execute();
  1970.                 return;
  1971.             }
  1972.             if (result == 1)
  1973.             {
  1974.                 JFrame framex = new JFrame("Update Process Summary");
  1975.                 framex.setMinimumSize(new Dimension(600, 600));
  1976.                 framex.setPreferredSize(new Dimension(600, 600));
  1977.                 framex.setMaximumSize(new Dimension(600, 600));
  1978.                 framex.setDefaultCloseOperation(2);
  1979.                 framex.setLocationRelativeTo(frame);
  1980.                 framex.setResizable(false);
  1981.                 Container panex = new Container();
  1982.                 framex.setLayout(null);
  1983.                 panex.setLayout(null);
  1984.                 JLabel labelx = new JLabel("Installation Summary", 0);
  1985.                 labelx.setFont(new Font(fontType, 1, 16));
  1986.                 labelx.setBounds(new Rectangle(0, -40, 600, 100));
  1987.                 panex.add(labelx);
  1988.  
  1989.                 JTextArea area = new JTextArea();
  1990.  
  1991.                 String sm = "";
  1992.  
  1993.                 sm += "The following mods will be installed or deleted to match\n";
  1994.                 sm += "your mods folder with the server\'s client selection...\n\n";
  1995.                 sm += "Files to be deleted:\n";
  1996.  
  1997.                 int index = 1;
  1998.                 List<List<String>> mods = updateNotes(clientFiles, serverFiles);
  1999.                 for (String s : mods.get(0)){
  2000.                     sm += index + ". " + s + "\n";
  2001.                     index++;
  2002.                 }
  2003.                 sm += "\nFiles to be downloaded:\n";
  2004.  
  2005.                 index = 1;
  2006.  
  2007.                 for (String s : mods.get(1)){
  2008.                     sm += index + ". " + s + "\n";
  2009.                     index++;
  2010.                 }
  2011.  
  2012.                 area.setFont(new Font(fontType, 0, 14));
  2013.                 area.setEditable(false);
  2014.                 area.setText(sm);
  2015.                 JScrollPane scroll = new JScrollPane(area);
  2016.                 scroll.setBounds(new Rectangle(50, 30, 500, 500));
  2017.                 panex.add(scroll);
  2018.  
  2019.                 JButton buttonx = new JButton("Close");
  2020.                 buttonx.setFont(new Font("arial", 1, 14));
  2021.                 buttonx.setBounds(new Rectangle(225, 540, 150, 30));
  2022.                 buttonx.addActionListener(new ActionListener()
  2023.                 {
  2024.                     public void actionPerformed(ActionEvent e)
  2025.                     {
  2026.                         framex.setVisible(false);
  2027.                         framex.dispose();
  2028.  
  2029.                         DMSLauncher.summaryAndConfirmUpdate(clientFiles, serverFiles);
  2030.                     }
  2031.                 });
  2032.                 panex.add(buttonx);
  2033.                 framex.setContentPane(panex);
  2034.                 framex.setVisible(true);
  2035.  
  2036.             }
  2037.             if (result == 2) {
  2038.                 play();
  2039.             }
  2040.         }
  2041.     }
  2042.  
  2043.     public static void crashReport(Exception e){
  2044.         exinfo = e;
  2045.         SwingWorker<String, String> worker3 = new SwingWorker<String, String>(){
  2046.  
  2047.             protected String doInBackground(){
  2048.                 crashReportGo(exinfo);
  2049.                 return null;
  2050.             }
  2051.  
  2052.         };
  2053.         worker3.execute();
  2054.     }
  2055.  
  2056.     public static void crashReportGo(Exception e){
  2057.         StringWriter swx = new StringWriter();
  2058.         PrintWriter pwx = new PrintWriter(swx);
  2059.         e.printStackTrace(pwx);
  2060.         pwx.close();
  2061.         String jx = swx.toString();
  2062.         try {
  2063.             swx.close();
  2064.         } catch (IOException e2) {
  2065.  
  2066.         }
  2067.  
  2068.         if (jx.contains("UnknownHostException")){
  2069.             JOptionPane.showMessageDialog(frame, "You do not have internet connection! The program will now shut down.", "No Internet Connection", JOptionPane.ERROR_MESSAGE);
  2070.             saveAndExit();
  2071.             return;
  2072.         }
  2073.  
  2074.  
  2075.         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");
  2076.         if (x == JOptionPane.YES_OPTION){
  2077.             String s = JOptionPane.showInputDialog(frame, "Please enter your name", "Report to Dilan", JOptionPane.QUESTION_MESSAGE);
  2078.  
  2079.             JFrame sending = new JFrame("Sending email to [email protected]");
  2080.             sending.setPreferredSize(new Dimension(400, 100));
  2081.             sending.setMaximumSize(new Dimension(400, 100));
  2082.             sending.setMinimumSize(new Dimension(400, 100));
  2083.             sending.setDefaultCloseOperation(0);
  2084.             sending.setResizable(false);
  2085.             sending.setLocationRelativeTo(null);
  2086.             Container pane = new Container();
  2087.             sending.setLayout(null);
  2088.  
  2089.             JLabel label = new JLabel("Reporting error...", 0);
  2090.             label.setFont(new Font("arial", 1, 18));
  2091.             label.setBounds(new Rectangle(0, 20, 400, 40));
  2092.             pane.add(label);
  2093.  
  2094.             sending.setContentPane(pane);
  2095.             sending.setVisible(true);
  2096.  
  2097.             String to = "[email protected]";
  2098.             String from = "[email protected]";
  2099.  
  2100.             Properties properties = System.getProperties();
  2101.             properties.setProperty("mail.smtp.host", "smtp.zoho.com");
  2102.             properties.setProperty("mail.smtp.user", from);
  2103.             properties.setProperty("mail.smtp.pass", emailpass);
  2104.             properties.setProperty("mail.smtp.port", "465");
  2105.             properties.setProperty("mail.smtp.auth", "true");
  2106.             properties.put("mail.smtp.socketFactory.port", "465");
  2107.             properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
  2108.             properties.put("mail.smtp.socketFactory.fallback", "false");
  2109.  
  2110.             Session session = Session.getDefaultInstance(properties, new Authenticator(){
  2111.                 public PasswordAuthentication getPasswordAuthentication(){
  2112.                     return new PasswordAuthentication("[email protected]", emailpass);
  2113.                 }
  2114.             });
  2115.  
  2116.             try{
  2117.  
  2118.                 Message message = new MimeMessage(session);
  2119.                 message.setFrom(new InternetAddress(from));
  2120.                 message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
  2121.                 message.setSubject("Automatic DMSLauncher Error Report - " + s);
  2122.                 StringWriter sw = new StringWriter();
  2123.                 PrintWriter pw = new PrintWriter(sw);
  2124.                 e.printStackTrace(pw);
  2125.                 pw.close();
  2126.                 String j = sw.toString();
  2127.                 sw.close();
  2128.                 message.setText(j);
  2129.  
  2130.                 Transport transport = session.getTransport("smtp");
  2131.  
  2132.                 transport.connect("smtp.zoho.com", 465, "[email protected]", emailpass);
  2133.                 transport.sendMessage(message, message.getAllRecipients());
  2134.                 transport.close();
  2135.                 sending.setVisible(false);
  2136.                 sending.dispose();
  2137.                 JOptionPane.showMessageDialog(frame, "Successfully reported this error.", "Sent Email", JOptionPane.INFORMATION_MESSAGE);
  2138.  
  2139.  
  2140.             } catch (MessagingException | IOException e1){
  2141.                 JOptionPane.showMessageDialog(frame, "Unable to send email report. The stack trace will save to file instead.", "Error Sending Email", JOptionPane.ERROR_MESSAGE);
  2142.                 File dir = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + DMSLauncher.splitKey + "Documents" + DMSLauncher.splitKey + "DMSUpdater", "stacktrace");
  2143.                 if (!dir.exists()){
  2144.                     dir.mkdirs();
  2145.                 }
  2146.                 Date date = new Date();
  2147.                 SimpleDateFormat format = new SimpleDateFormat("HH-mm-ss-MM-dd-yyyy");
  2148.                 File fx = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + DMSLauncher.splitKey + "Documents" + DMSLauncher.splitKey + "DMSUpdater" + splitKey + "stacktrace", format.format(date) + ".txt");
  2149.                 PrintStream ps = null;
  2150.                 try {
  2151.                     ps = new PrintStream(fx);
  2152.                 } catch (FileNotFoundException e1x) {
  2153.                     JOptionPane.showMessageDialog(frame, "Unable to save the stack trace to a file.", "Today is not a good day", JOptionPane.ERROR_MESSAGE);
  2154.                     return;
  2155.                 }
  2156.                 e1.printStackTrace(ps);
  2157.                 ps.close();
  2158.  
  2159.  
  2160.                 JOptionPane.showMessageDialog(frame, "The stack trace has been saved to \n" + fx.getPath(), "Stack Trace Saved to File", JOptionPane.ERROR_MESSAGE);
  2161.                 return;
  2162.             }
  2163.             return;
  2164.  
  2165.  
  2166.         }
  2167.         if (x == JOptionPane.NO_OPTION){
  2168.             File dir = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + DMSLauncher.splitKey + "Documents" + DMSLauncher.splitKey + "DMSUpdater", "stacktrace");
  2169.             if (!dir.exists()){
  2170.                 dir.mkdirs();
  2171.             }
  2172.             Date date = new Date();
  2173.             SimpleDateFormat format = new SimpleDateFormat("HH-mm-ss-MM-dd-yyyy");
  2174.             File fx = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + DMSLauncher.splitKey + "Documents" + DMSLauncher.splitKey + "DMSUpdater" + splitKey + "stacktrace", format.format(date) + ".txt");
  2175.             PrintStream ps = null;
  2176.             try {
  2177.                 ps = new PrintStream(fx);
  2178.             } catch (FileNotFoundException e1) {
  2179.                 JOptionPane.showMessageDialog(frame, "Unable to save the stack trace to a file.", "Today is not a good day", JOptionPane.ERROR_MESSAGE);
  2180.                 return;
  2181.             }
  2182.             e.printStackTrace(ps);
  2183.             ps.close();
  2184.  
  2185.  
  2186.             JOptionPane.showMessageDialog(frame, "The stack trace has been saved to \n" + fx.getPath(), "Stack Trace Saved to File", JOptionPane.ERROR_MESSAGE);
  2187.             return;
  2188.         }
  2189.         if (x == JOptionPane.CANCEL_OPTION) { }
  2190.     }
  2191.  
  2192.  
  2193.  
  2194.     public static void prepareManage() {
  2195.         JPanel pane = new JPanel();
  2196.         pane.setLayout(null);
  2197.  
  2198.         JLabel tip = new JLabel("Hover over buttons to see descriptions.", 0);
  2199.         tip.setBounds(new Rectangle(0, 10, 1000, 10));
  2200.         tip.setFont(new Font("arial", Font.ITALIC, 10));
  2201.  
  2202.         JButton deleteFromServerServer = new JButton("Delete Server Mod");
  2203.         deleteFromServerServer.setToolTipText("Delete a mod file from the server-side selection");
  2204.         deleteFromServerServer.setBounds(new Rectangle(20 + (((int) tabs.getBounds().getWidth() - 50)/2), 25+200+30, ((int) tabs.getBounds().getWidth() - 50)/2, 200-10));
  2205.         deleteFromServerServer.addActionListener(new ActionListener() {
  2206.             public void actionPerformed(ActionEvent e) {
  2207.                     if (client == null || !client.isConnected()){
  2208.                         reconnectFTP();
  2209.                     }
  2210.  
  2211.                     try {
  2212.                         client.changeWorkingDirectory("/mods");
  2213.                     } catch (IOException e1) {
  2214.                         crashReport(e1);
  2215.                     }
  2216.  
  2217.                     try {
  2218.                         String sm = JOptionPane.showInputDialog(frame, "Input the file name to delete...", "Delete File - Server", JOptionPane.QUESTION_MESSAGE);
  2219.  
  2220.                         if (sm == null){
  2221.                             return;
  2222.                         }
  2223.  
  2224.                         List<String> list = new ArrayList<String>();
  2225.                         for (FTPFile ftp : client.listFiles()){
  2226.                             list.add(ftp.getName());
  2227.                         }
  2228.  
  2229.                         if (!list.contains(sm)){
  2230.                             JOptionPane.showMessageDialog(frame, "Invalid file name. Please try again...", "Manage Server", JOptionPane.ERROR_MESSAGE);
  2231.                             return;
  2232.                         }
  2233.  
  2234.                         client.deleteFile(sm);
  2235.  
  2236.                         JOptionPane.showMessageDialog(frame, "Deleted " + sm + " from the server side selection.", "Manage Server", JOptionPane.INFORMATION_MESSAGE);
  2237.  
  2238.  
  2239.                     } catch (HeadlessException e1) {
  2240.                         crashReport(e1);
  2241.                     } catch (IOException e1) {
  2242.                         crashReport(e1);
  2243.                     }
  2244.  
  2245.                     return;
  2246.                
  2247.             }
  2248.         });
  2249.         pane.add(deleteFromServerServer);
  2250.        
  2251.         JButton deleteFromServer = new JButton("Delete Client Mod");
  2252.         deleteFromServer.setToolTipText("Delete a mod file from the DMSLauncher client sync");
  2253.         deleteFromServer.setBounds(new Rectangle(10, 25+200+30, ((int) tabs.getBounds().getWidth() - 50)/2, 200-10));
  2254.         deleteFromServer.addActionListener(new ActionListener() {
  2255.             public void actionPerformed(ActionEvent e) {
  2256.                     if (client == null || !client.isConnected()){
  2257.                         reconnectFTP();
  2258.                     }
  2259.  
  2260.                     try {
  2261.  
  2262.                         client.changeWorkingDirectory("/DMSLauncher");
  2263.                     } catch (IOException e1) {
  2264.                         crashReport(e1);
  2265.                     }
  2266.  
  2267.                     try {
  2268.                         String sm = JOptionPane.showInputDialog(frame, "Input the file name to delete...", "Delete File - Client", JOptionPane.QUESTION_MESSAGE);
  2269.  
  2270.                         if (sm == null){
  2271.                             return;
  2272.                         }
  2273.  
  2274.                         List<String> list = new ArrayList<String>();
  2275.                         for (FTPFile ftp : client.listFiles()){
  2276.                             list.add(ftp.getName());
  2277.                         }
  2278.  
  2279.                         if (!list.contains(sm)){
  2280.                             JOptionPane.showMessageDialog(frame, "Invalid file name. Please try again...", "Manage Server", JOptionPane.ERROR_MESSAGE);
  2281.                             return;
  2282.                         }
  2283.  
  2284.                         client.deleteFile(sm);
  2285.  
  2286.                         JOptionPane.showMessageDialog(frame, "Deleted " + sm + " from the server\'s client selection.", "Manage Server", JOptionPane.INFORMATION_MESSAGE);
  2287.  
  2288.  
  2289.                     } catch (HeadlessException e1) {
  2290.                         crashReport(e1);
  2291.                     } catch (IOException e1) {
  2292.                         crashReport(e1);
  2293.                     }
  2294.                     return;
  2295.             }
  2296.  
  2297.         });
  2298.         pane.add(deleteFromServer);
  2299.  
  2300.  
  2301.         JCheckBox serverSideAlso = new JCheckBox("Add to server-side mods also (requires server restart)");
  2302.         serverSideAlso.setBounds(new Rectangle(10, 10+210, (int) tabs.getBounds().getWidth() - 40, 25));
  2303.         JButton uploadToServer = new JButton("Upload Mod");
  2304.         uploadToServer.setToolTipText("Upload a mod file to the server for the DMSLauncher to read from (optional: server-side also).");
  2305.         uploadToServer.setBounds(new Rectangle(10, 25, (int) tabs.getBounds().getWidth() - 40, 200-10));
  2306.         uploadToServer.addActionListener(new ActionListener() {
  2307.             public void actionPerformed(ActionEvent e) {
  2308.                 JFileChooser fc = new JFileChooser();
  2309.                 fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
  2310.                 fc.setDialogTitle("Select file to upload...");
  2311.                 int val = fc.showDialog(frame, "Upload to FTP");
  2312.                 if (val == JFileChooser.APPROVE_OPTION){
  2313.                     File local = fc.getSelectedFile();
  2314.                     if (local.isDirectory()){
  2315.                         JOptionPane.showMessageDialog(frame, "The file cannot be a folder.", "Manage Server", JOptionPane.ERROR_MESSAGE);
  2316.                         return;
  2317.                     }
  2318.  
  2319.                     try {
  2320.  
  2321.                         if (serverSideAlso.isSelected()){
  2322.                             if (client == null || !client.isConnected()){
  2323.                                 reconnectFTP();
  2324.                             }
  2325.  
  2326.                             client.changeWorkingDirectory("/mods");
  2327.                             InputStream is = new FileInputStream(local);
  2328.                             OutputStream os = client.storeFileStream(local.getName());
  2329.                             byte[] bytes = new byte[4096];
  2330.                             int read = 0;
  2331.  
  2332.                             while ((read = is.read(bytes)) != -1){
  2333.                                 os.write(bytes, 0, read);
  2334.                             }
  2335.                             is.close();
  2336.                             os.close();
  2337.  
  2338.                             client.completePendingCommand();
  2339.  
  2340.                         }
  2341.                         if (client == null || !client.isConnected()){
  2342.                             reconnectFTP();
  2343.                         }
  2344.  
  2345.                         client.changeWorkingDirectory("/DMSLauncher");
  2346.                         InputStream is = new FileInputStream(local);
  2347.                         OutputStream os = client.storeFileStream(local.getName());
  2348.                         byte[] bytes = new byte[4096];
  2349.                         int read = 0;
  2350.  
  2351.                         while ((read = is.read(bytes)) != -1){
  2352.                             os.write(bytes, 0, read);
  2353.                         }
  2354.                         is.close();
  2355.                         os.close();
  2356.  
  2357.                         client.completePendingCommand();
  2358.  
  2359.                         JOptionPane.showMessageDialog(frame, "Successfully uploaded " + local.getName() + " to the FTP server " + (serverSideAlso.isSelected() ? "(both client and server)" : "(client only)"), "Manage Server", JOptionPane.INFORMATION_MESSAGE);
  2360.  
  2361.                     } catch (IOException e1) {
  2362.                         crashReport(e1);
  2363.                     }
  2364.  
  2365.                 }
  2366.             }
  2367.         });
  2368.  
  2369.         pane.add(serverSideAlso);
  2370.         pane.add(uploadToServer);
  2371.  
  2372.         pane.add(tip);
  2373.  
  2374.         tabs.addTab("Manage Server", null, pane, "Manage server files");
  2375.  
  2376.  
  2377.     }
  2378.  
  2379.     public static void manage(boolean wrong, boolean skipPass){
  2380.         String s = "";
  2381.         if (!skipPass)
  2382.             s = JOptionPane.showInputDialog(frame, (wrong ? "Incorrect password! Please try again..." : "Enter the administration password..."), "Manage Server", JOptionPane.QUESTION_MESSAGE);
  2383.         if (s == null) return;
  2384.         if (s.equals(password) || skipPass){
  2385.             manage_cont = true;
  2386.             tabs.setSelectedIndex(3);
  2387.  
  2388.         }else{
  2389.             manage(true, false);
  2390.             return;
  2391.         }
  2392.         return;
  2393.     }
  2394.  
  2395.     public static void disableFrame(){
  2396.         update.setEnabled(false);
  2397.         tabs.setEnabled(false);
  2398.         /*manage.setEnabled(false);
  2399.         settings.setEnabled(false);
  2400.         ramAllocation.setEnabled(false);
  2401.         chat.setEnabled(false);*/
  2402.     }
  2403.  
  2404.     public static void enableFrame(){
  2405.         tabs.setEnabled(true);
  2406.         update.setEnabled(true);
  2407.         /*manage.setEnabled(true);
  2408.         settings.setEnabled(true);
  2409.         ramAllocation.setEnabled(true);
  2410.         chat.setEnabled(true);*/
  2411.     }
  2412.  
  2413.     public static void install(){
  2414.  
  2415.         disableFrame();
  2416.         updatetext.setText("Installing modded minecraft...");
  2417.  
  2418.         console.append("\n\nStarting installation...\n\n");
  2419.         if (isWindows()){
  2420.             console.append("Downloading file from " + baseminecraftWindows + "...\n");
  2421.         }
  2422.         else{
  2423.             console.append("Downloading file from " + baseMinecraft + "...\n");
  2424.         }
  2425.  
  2426.  
  2427.  
  2428.         try {
  2429.             if (!isWindows()){
  2430.                 sfp_url = new URL(baseMinecraft);
  2431.                 sfp_file = new File(basepath, "DMSClientFiles.zip").getPath();
  2432.                 SwingWorker<String, String> worker8 = new SwingWorker<String, String>(){
  2433.  
  2434.                     protected String doInBackground(){
  2435.                         try {
  2436.                             saveFileProgress(sfp_url, sfp_file);
  2437.  
  2438.                             install2();
  2439.                         } catch (IOException e) {
  2440.                             crashReport(e);
  2441.                         }
  2442.                         return null;
  2443.                     }
  2444.                 };
  2445.                 worker8.execute();
  2446.             }else{
  2447.                 sfp_url = new URL(baseminecraftWindows);
  2448.                 sfp_file = new File(basepath, "DMSClientFiles.zip").getPath();
  2449.                 SwingWorker<String, String> worker8 = new SwingWorker<String, String>(){
  2450.  
  2451.                     protected String doInBackground(){
  2452.                         try {
  2453.                             saveFileProgress(sfp_url, sfp_file);
  2454.  
  2455.                             install2();
  2456.                         } catch (IOException e) {
  2457.                             crashReport(e);
  2458.                         }
  2459.                         return null;
  2460.                     }
  2461.                 };
  2462.                 worker8.execute();
  2463.             }
  2464.         } catch (MalformedURLException e) {
  2465.             crashReport(e);
  2466.         }
  2467.  
  2468.  
  2469.     }
  2470.  
  2471.     /*public static void auth(boolean wrong, boolean unable){
  2472.         JTextField usernameField = new JTextField(15);
  2473.         JPasswordField passField = new JPasswordField(15);
  2474.         JPanel panel = new JPanel();
  2475.         JLabel label;
  2476.         if (!unable)
  2477.             label = new JLabel((wrong ? "Invalid credentials. Please try again..." : "Log in to your Mojang account..."));
  2478.         else
  2479.             label = new JLabel("Unable to connect to authentication server!?");
  2480.         label.setFont(new Font("arial", Font.BOLD, 12));
  2481.         panel.add(label);
  2482.         panel.add(Box.createVerticalStrut(5));
  2483.         panel.add(new JLabel("Username/Email"));
  2484.         panel.add(usernameField);
  2485.         panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
  2486.         panel.add(new JLabel("Password"));
  2487.         panel.add(passField);
  2488.  
  2489.  
  2490.         int res = JOptionPane.showConfirmDialog(null, panel, "Minecraft Authentication", JOptionPane.OK_CANCEL_OPTION);
  2491.         if (res == JOptionPane.OK_OPTION){
  2492.  
  2493.             String pass = "";
  2494.             for (char c : passField.getPassword()){
  2495.                 pass += c;
  2496.             }
  2497.  
  2498.             JsonObject info = authMinecraft(usernameField.getText(), pass);
  2499.             if (info.containsKey("errorMessage")){
  2500.                 if (info.getString("errorMessage").contains("Invalid credentials")){
  2501.                     auth(true, false);
  2502.                     return;
  2503.                 }
  2504.             }
  2505.             else if (info.containsKey("accessToken")){
  2506.  
  2507.                 try {
  2508.  
  2509.                     JsonObject uuid = info.getJsonObject("selectedProfile");
  2510.                     List<String> lines = Files.readAllLines(new File(new File(basepath, "Game"), "launcher_profiles.json").toPath());
  2511.                     int size = lines.size();
  2512.                     for (int i = 0; i < size; i++){
  2513.                         if (lines.get(i).contains("DMSLAUNCHER-UUID")){
  2514.  
  2515.                             lines.set(i, lines.get(i).replaceAll("DMSLAUNCHER-UUID", uuid.getString("id")));
  2516.                         }
  2517.                         if (lines.get(i).contains("DMSLAUNCHER-ACCESSTOKEN")){
  2518.                             lines.set(i, lines.get(i).replaceAll("DMSLAUNCHER-ACCESSTOKEN", info.getString("accessToken")));
  2519.                         }
  2520.                         if (lines.get(i).contains("DMSLAUNCHER-USERNAME")){
  2521.                             lines.set(i, lines.get(i).replaceAll("DMSLAUNCHER-USERNAME", uuid.getString("name")));
  2522.                         }
  2523.                         if (lines.get(i).contains("DMSLAUNCHER-EMAIL")){
  2524.                             lines.set(i, lines.get(i).replaceAll("DMSLAUNCHER-EMAIL", usernameField.getText()));
  2525.                         }
  2526.                         if (lines.get(i).contains("DMSLAUNCHER-CLIENTTOKEN")){
  2527.                             lines.set(i, lines.get(i).replaceAll("DMSLAUNCHER-CLIENTTOKEN", info.getString("clientToken")));
  2528.                         }
  2529.                     }
  2530.  
  2531.  
  2532.                     clearFile(new File(new File(basepath, "Game"), "launcher_profiles.json"));
  2533.                     Files.write(new File(new File(basepath, "Game"), "launcher_profiles.json").toPath(), lines, StandardOpenOption.CREATE);
  2534.  
  2535.                 } catch (IOException e) {
  2536.                     crashReport(e);
  2537.                 }
  2538.  
  2539.             }else{
  2540.                 auth(false, true);
  2541.             }
  2542.  
  2543.  
  2544.         }else{
  2545.             auth(false, false);
  2546.             return;
  2547.         }
  2548.  
  2549.         return;
  2550.  
  2551.     }*/
  2552.  
  2553.     public static void install2(){
  2554.         pause(500L);
  2555.         console.append("\n\nUnzipping the zip file...\n\n");
  2556.         File dir = new File(basepath, "Game");
  2557.         if (!dir.exists()){
  2558.             dir.mkdir();
  2559.         }
  2560.  
  2561.         try {
  2562.             UnZipper.unzip(new File(basepath, "DMSClientFiles.zip").getPath(), new File(basepath, "Game").getPath());
  2563.         } catch (IOException e) {
  2564.             crashReport(e);
  2565.         }
  2566.  
  2567.         console.append("Editing launcher_profiles.json...\n\n");
  2568.  
  2569.  
  2570.  
  2571.         try {
  2572.  
  2573.  
  2574.             List<String> lines = Files.readAllLines(new File(new File(basepath, "Game"), "launcher_profiles.json").toPath());
  2575.             int index = -1;
  2576.             for (String s : lines){
  2577.                 index++;
  2578.                 if (s.contains("DMSLAUNCHER/GAMEDIRPATH")) break;
  2579.             }
  2580.  
  2581.             String k = lines.get(index);
  2582.             if (isWindows())
  2583.  
  2584.                 k = k.replace("DMSLAUNCHER/GAMEDIRPATH", new File(basepath, "Game").getPath().replaceAll(Matcher.quoteReplacement("\\"), Matcher.quoteReplacement("\\\\")));
  2585.             else
  2586.                 k = k.replaceAll("DMSLAUNCHER/GAMEDIRPATH", new File(basepath, "Game").getPath());
  2587.             lines.set(index, k);
  2588.             clearFile(new File(new File(basepath, "Game"), "launcher_profiles.json"));
  2589.             Files.write(new File(new File(basepath, "Game"), "launcher_profiles.json").toPath(), lines, StandardOpenOption.CREATE);
  2590.  
  2591.         } catch (IOException e) {
  2592.             crashReport(e);
  2593.         }
  2594.  
  2595.         /*console.append("Minecraft authentication is required...\n\n");
  2596.  
  2597.         auth(false, false);
  2598.  
  2599.         console.append("Used credentials to modify launcher_profiles.json\n\n");*/
  2600.  
  2601.  
  2602.  
  2603.  
  2604.         console.append("Minecraft modded installation complete!\n\n");
  2605.         update.setText("Play Minecraft");
  2606.  
  2607.         SwingWorker<String, String> worker4 = new SwingWorker<String, String>(){
  2608.  
  2609.             protected String doInBackground(){
  2610.                 checkUpdatesFromFTP();
  2611.                 return null;
  2612.             }
  2613.  
  2614.         };
  2615.  
  2616.         worker4.execute();
  2617.     }
  2618.  
  2619.     public static void ramAllocate(){
  2620.  
  2621.         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"};
  2622.  
  2623.         try {
  2624.  
  2625.  
  2626.             List<String> lines = Files.readAllLines(new File(new File(basepath, "Game"), "launcher_profiles.json").toPath());
  2627.             String j = "";
  2628.             String full = "";
  2629.             int i = -1;
  2630.             for (String s : lines){
  2631.                 i++;
  2632.                 if (s.contains("-Xmx")){
  2633.                     full = s;
  2634.                     j = s.split("-Xmx")[1].split("m")[0];              
  2635.                     break;
  2636.                 }
  2637.             }
  2638.  
  2639.             String s = (String) JOptionPane.showInputDialog(frame, "Select RAM dedication towards Minecraft...", "RAM Dedication", JOptionPane.QUESTION_MESSAGE, null, rams, j + " MB");
  2640.             lines.set(i, full.replace(j, s.replace(" MB", "")));
  2641.             clearFile(new File(new File(basepath, "Game"), "launcher_profiles.json"));
  2642.             Files.write(new File(new File(basepath, "Game"), "launcher_profiles.json").toPath(), lines, StandardOpenOption.WRITE);
  2643.             console.append("\n\nNow dedicating " + s + " of RAM to Minecraft.");
  2644.  
  2645.         } catch (IOException e) {
  2646.             crashReport(e);
  2647.         }
  2648.  
  2649.  
  2650.     }
  2651.  
  2652.     static boolean onlyExitOnce = false;
  2653.  
  2654.     public static void saveAndExit(){
  2655.         onlyExitOnce = true;
  2656.         framex = new JFrame("DMSLauncher is closing...");
  2657.         framex.setMinimumSize(new Dimension(500, 100));
  2658.         framex.setPreferredSize(new Dimension(500, 100));
  2659.         framex.setMaximumSize(new Dimension(500, 100));
  2660.         framex.setDefaultCloseOperation(0);
  2661.         framex.setLocationRelativeTo(null);
  2662.         framex.setResizable(false);
  2663.         Container panex = new Container();
  2664.         framex.setLayout(null);
  2665.         panex.setLayout(null);
  2666.         JLabel labelx = new JLabel("DMSLauncher is quitting. Please wait...", 0);
  2667.         labelx.setFont(new Font(fontType, 1, 16));
  2668.         labelx.setBounds(new Rectangle(0, -10, 500, 100));
  2669.         panex.add(labelx);
  2670.         framex.setContentPane(panex);
  2671.         framex.setVisible(true);
  2672.  
  2673.  
  2674.         try {
  2675.             Files.write(new File(basepath, "Chat/ftp.txt").toPath(), currentChatHist, StandardOpenOption.CREATE);
  2676.         } catch (IOException e) {
  2677.             crashReport(e);
  2678.         }
  2679.  
  2680.         pause(100L);
  2681.  
  2682.         System.exit(0);
  2683.  
  2684.     }
  2685.  
  2686.  
  2687.     public static void settings(){
  2688.  
  2689.         JPanel pane = new JPanel();
  2690.         pane.setLayout(null);
  2691.  
  2692.         JLabel tip = new JLabel("Hover over buttons to see descriptions.", 0);
  2693.         tip.setBounds(new Rectangle(0, 10, 1000, 10));
  2694.         tip.setFont(new Font("arial", Font.ITALIC, 10));
  2695.  
  2696.         JLabel chatSectionTitle = new JLabel("Chat", 0);
  2697.         chatSectionTitle.setFont(new Font("arial", Font.BOLD, 18));
  2698.         chatSectionTitle.setBounds(new Rectangle(10, 50, 300, 20));
  2699.         pane.add(chatSectionTitle);
  2700.  
  2701.         JButton deleteChatHistory = new JButton("Save & Clear Chat History");
  2702.         deleteChatHistory.setToolTipText("Clear your current chat history and save it as recently deleted.");
  2703.         deleteChatHistory.setBounds(new Rectangle(10, 75, 300, 50));
  2704.         deleteChatHistory.addActionListener(new ActionListener(){
  2705.             public void actionPerformed(ActionEvent e){
  2706.  
  2707.                 new SW(){
  2708.  
  2709.                     protected void I() {
  2710.  
  2711.                         List<String> chatList = new ArrayList<String>();
  2712.                         Date date = new Date();
  2713.                         SimpleDateFormat format_infile = new SimpleDateFormat("HH:mm:ss MM/dd/yyyy");
  2714.                         SimpleDateFormat format_outfile = new SimpleDateFormat("HH-mm-ss MM-dd-yyyy");
  2715.                         chatList.add("//Chat history saved: " + format_infile.format(date));
  2716.                         chatList.addAll(totalChatHist);
  2717.                         File temp = new File(basepath, "Chat/History");
  2718.                         if (!temp.exists()) temp.mkdir();
  2719.  
  2720.                         chatBox.setText("");
  2721.  
  2722.                         File f = new File(basepath, "Chat/History/" + format_outfile.format(date) + ".chathist");
  2723.                         try {
  2724.                             Files.write(f.toPath(), chatList, StandardOpenOption.CREATE);
  2725.                         } catch (IOException e) {
  2726.                             crashReport(e);
  2727.                         }
  2728.  
  2729.  
  2730.                         File currChat = new File(basepath, "Chat/ftp.txt");
  2731.                         currChat.delete();
  2732.                         try {
  2733.                             new File(currChat.getPath()).createNewFile();
  2734.                         } catch (IOException e) {
  2735.                             crashReport(e);
  2736.                         }
  2737.  
  2738.                         totalChatHist.clear();
  2739.                         currentChatHist.clear();
  2740.  
  2741.                         Dialog.dialog("Successfully saved chat history to recently deleted and cleared the current chat area", "Settings Changed");
  2742.                     }
  2743.  
  2744.                 }.execute();
  2745.  
  2746.  
  2747.             }
  2748.         });
  2749.         pane.add(deleteChatHistory);
  2750.  
  2751.         JButton restoreChatHistory = new JButton("Restore Chat History");
  2752.         restoreChatHistory.setToolTipText("Restore chat area to a saved chat history file.");
  2753.         restoreChatHistory.setBounds(new Rectangle(10, 135, 300, 50));
  2754.         restoreChatHistory.addActionListener(new ActionListener() {
  2755.             public void actionPerformed(ActionEvent e) {
  2756.                 JFileChooser fc = new JFileChooser();
  2757.                 fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
  2758.                 fc.setDialogTitle("Select chat history to restore");
  2759.                 fc.setCurrentDirectory(new File(basepath, "Chat/History"));
  2760.                 fc.setFileFilter(new FileFilter() {
  2761.                     public boolean accept(File f) {
  2762.                         return (f.getName().endsWith(".chathist") && !f.isDirectory());
  2763.                     }
  2764.  
  2765.  
  2766.                     public String getDescription() {
  2767.                         return "DMSLauncher Chat History File";
  2768.                     }
  2769.                 });
  2770.                 int val = fc.showDialog(frame, "Restore");
  2771.                 if (val == JFileChooser.APPROVE_OPTION) {
  2772.                     try {
  2773.                         List<String> lines = Files.readAllLines(fc.getSelectedFile().toPath());
  2774.  
  2775.                         totalChatHist.addAll(lines);
  2776.                         currentChatHist.addAll(lines);
  2777.                         new SW(){
  2778.                             protected void I() {
  2779.                                 chatBox.setText(fromListChat(totalChatHist));
  2780.                             }
  2781.                         }.execute();
  2782.  
  2783.                     } catch (IOException e1) {
  2784.                         crashReport(e1);
  2785.                     }
  2786.                     Dialog.dialog("Successfully restored chat history to: " + fc.getSelectedFile().getName(), "Settings Changed");
  2787.  
  2788.                 }
  2789.  
  2790.             }
  2791.         });
  2792.         pane.add(restoreChatHistory);
  2793.  
  2794.         JButton logoutChat = new JButton("Logout");
  2795.         logoutChat.setToolTipText("Remove your current DMSLauncher chat ID from this program (you can log in again at any time).");
  2796.         logoutChat.setBounds(new Rectangle(10, 195, 300, 50));
  2797.         logoutChat.addActionListener(new ActionListener() {
  2798.             public void actionPerformed(ActionEvent e) {
  2799.  
  2800.                 new SW() {
  2801.                     protected void I() {
  2802.  
  2803.                         chat_user = "None";
  2804.                         File f = new File(basepath, "Chat/chatLogin.txt");
  2805.                         f.delete();
  2806.                         chatSending.setText("Not logged in");
  2807.                         Dialog.dialog("Successfully logged out of chat", "Settings Changed");
  2808.  
  2809.                     }
  2810.                 }.execute();
  2811.  
  2812.             }
  2813.         });
  2814.         pane.add(logoutChat);
  2815.  
  2816.  
  2817.  
  2818.         JLabel moreComingSoon = new JLabel("MORE SETTINGS COMING SOON PROBABLY", 0);
  2819.         moreComingSoon.setBounds(new Rectangle(350, 200, 600, 100));
  2820.         moreComingSoon.setFont(new Font("arial", Font.BOLD, 24));
  2821.         pane.add(moreComingSoon);
  2822.  
  2823.  
  2824.  
  2825.         JButton credit = new JButton("DMSLauncher Information");
  2826.         credit.setToolTipText("View creator information, program code, and more...");
  2827.         credit.setBounds(new Rectangle((int) tabs.getBounds().getWidth()/2 - (500/2), (int) tabs.getBounds().getHeight()-100, 500, 50));
  2828.         credit.addActionListener(new ActionListener() {
  2829.             public void actionPerformed(ActionEvent e) {
  2830.                 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");
  2831.                 if (val == 0) {
  2832.                     try {
  2833.                         Desktop.getDesktop().browse(new URI("https://pastebin.com/PRfcq6Xg"));
  2834.                     } catch (IOException e1) {
  2835.                         crashReport(e1);
  2836.                     } catch (URISyntaxException e1) {
  2837.                         crashReport(e1);
  2838.                     }
  2839.                 }
  2840.                 if (val == 1) {
  2841.                     try {
  2842.                         Desktop.getDesktop().browse(new URI("https://blockhead7360.com"));
  2843.                     } catch (IOException e1) {
  2844.                         crashReport(e1);
  2845.                     } catch (URISyntaxException e1) {
  2846.                         crashReport(e1);
  2847.                     }
  2848.                 }
  2849.             }
  2850.         });
  2851.  
  2852.  
  2853.  
  2854.         pane.add(credit);
  2855.         pane.add(tip);
  2856.  
  2857.  
  2858.         tabs.addTab("Settings", null, pane, "Change program and game settings");
  2859.  
  2860.  
  2861.     }
  2862.  
  2863.     public static abstract class SW{
  2864.  
  2865.  
  2866.         protected abstract void I();
  2867.  
  2868.         public void execute(){
  2869.             SwingWorker<String, String> worker = new SwingWorker<String, String>(){
  2870.  
  2871.                 protected String doInBackground() {
  2872.                     I();
  2873.                     return null;
  2874.                 }
  2875.  
  2876.             };
  2877.             worker.execute();
  2878.  
  2879.         }
  2880.     }
  2881.  
  2882.     public static boolean canUseFeature(String feature) {
  2883.         if (remotesettings.containsKey(feature)) {
  2884.             Dialog.dialog("Sorry, but you cannot use this feature at this time.\n\nReason: " + remotesettings.get(feature), "This feature has been disabled remotely");
  2885.             return false;
  2886.         }
  2887.         return true;
  2888.     }
  2889.  
  2890.     public static void loadFrame()
  2891.     {
  2892.         frame = new JFrame("Dilan's Modded Server - Launcher");
  2893.         frame.setMinimumSize(new Dimension(1000, 700));
  2894.         frame.setSize(new Dimension(1000, 700));
  2895.         frame.setMaximumSize(new Dimension(1000, 700));
  2896.         frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
  2897.         frame.setLocationRelativeTo(null);
  2898.         frame.setResizable(false);
  2899.  
  2900.         frame.addWindowListener(new WindowAdapter(){
  2901.  
  2902.             public void windowClosing(WindowEvent event){
  2903.                 SwingWorker<String, String> worker = new SwingWorker<String, String>(){
  2904.  
  2905.                     protected String doInBackground(){
  2906.                         if (!onlyExitOnce) saveAndExit();
  2907.                         return null;
  2908.                     }
  2909.  
  2910.                 };
  2911.                 worker.execute();
  2912.             }
  2913.  
  2914.         });
  2915.  
  2916.  
  2917.  
  2918.         JPanel pane = new JPanel();
  2919.         cont.setLayout(null);
  2920.         pane.setLayout(null);
  2921.         frame.setLayout(null);
  2922.  
  2923.         URL url = null;
  2924.         url = ClassLoader.getSystemResource("res/DMSLauncher.png");
  2925.         Toolkit kit = Toolkit.getDefaultToolkit();
  2926.         Image imgx = kit.createImage(url);
  2927.         frame.setIconImage(imgx);
  2928.  
  2929.         try
  2930.         {
  2931.             BufferedImage img = ImageIO.read(new URL(imageUrl));
  2932.             JLabel image = new JLabel(new ImageIcon(img));
  2933.             image.setBounds(0, -300, 1000, 700);
  2934.             cont.add(image);
  2935.         }
  2936.         catch (Exception ex)
  2937.         {
  2938.             crashReport(ex);
  2939.         }
  2940.         JLabel credits = new JLabel("Created by Dilan Nair - http://blockhead7360.com");
  2941.         credits.setFont(new Font("arial", 2, 12));
  2942.         credits.setBounds(new Rectangle(10, 75, 1000, 30));
  2943.         cont.add(credits);
  2944.  
  2945.         JLabel secret = new JLabel("© Manazir Industries");
  2946.         secret.setFont(new Font("arial", Font.PLAIN, 3));
  2947.         secret.setBounds(new Rectangle(1, 1, 40, 4));
  2948.         cont.add(secret);
  2949.  
  2950.         JLabel version = new JLabel("Program version: " + thisVer, 0);
  2951.         version.setFont(new Font(fontType, 1, 12));
  2952.         version.setBounds(new Rectangle(650, 70, 325, 30));
  2953.         cont.add(version);
  2954.  
  2955.         cont.add(DilanAPI.watermark(1000, 700, WMLoc.TOP_RIGHT));
  2956.  
  2957.         changelog = new JTextArea();
  2958.         changelog.setMargin(new Insets(20, 20, 20, 20));
  2959.         changelog.setBounds(new Rectangle(25, 5, 600, 450));
  2960.         changelog.setFont(new Font(fontType, 1, 18));
  2961.         changelog.setEditable(false);
  2962.         changelog.setText(changelogstr);
  2963.         changelog.setVisible(true);
  2964.         JScrollPane changelogpane = new JScrollPane(changelog);
  2965.         changelogpane.setBounds(new Rectangle(25, 5, 600, 450));
  2966.         pane.add(changelogpane);
  2967.  
  2968.         console.setMargin(new Insets(8, 8, 8, 8));
  2969.         console.setBounds(new Rectangle(650, 5, 325, 450));
  2970.         console.setFont(new Font(fontType, 2, 16));
  2971.         console.setEditable(false);
  2972.         console.setVisible(true);
  2973.         DefaultCaret caret = (DefaultCaret) console.getCaret();
  2974.         caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
  2975.         JScrollPane consolepane = new JScrollPane(console);
  2976.         consolepane.setBounds(new Rectangle(650, 5, 325, 450));
  2977.  
  2978.         pane.add(consolepane);
  2979.  
  2980.         boolean inst = false;
  2981.  
  2982.         if (!(new File(new File(basepath, "Game"), "launcher_profiles.json")).exists()){
  2983.             update = new JButton("Install and Play");
  2984.             inst = true;
  2985.         }
  2986.         else update = new JButton("Play Minecraft");
  2987.  
  2988.         updatetext = new JLabel();
  2989.  
  2990.         updatetext.setText(" ");
  2991.         updatetext.setFont(new Font("arial", 1, 14));
  2992.         updatetext.setBounds(new Rectangle(520, 470, 500, 40));
  2993.         updatetext.setVisible(true);
  2994.         pane.add(updatetext);
  2995.  
  2996.         update.setBounds(new Rectangle(748, 468, 220, 50));
  2997.         update.setFont(new Font(fontType2, 0, 16));
  2998.         update.setToolTipText((inst ? "Install the modded Minecraft client and start the game." : "Check for updates and start the game."));
  2999.         update.addActionListener(new ActionListener()
  3000.         {
  3001.             public void actionPerformed(ActionEvent e)
  3002.             {
  3003.                 /*if (DMSUpdater.clientPath.equals("BLANK"))
  3004.                 {
  3005.  
  3006.                     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");
  3007.                     if (i == 1) {
  3008.                         DMSUpdater.setPath();
  3009.                     }
  3010.                     return;
  3011.                 }*/
  3012.  
  3013.                 if (!canUseFeature("DisableUpdateButton")) return;
  3014.  
  3015.                 if (!(new File(new File(basepath, "Game"), "launcher_profiles.json")).exists()){
  3016.                     SwingWorker<String, String> worker5 = new SwingWorker<String, String>(){
  3017.  
  3018.                         protected String doInBackground(){
  3019.                             install();
  3020.                             return null;
  3021.                         }
  3022.  
  3023.                     };
  3024.                     worker5.execute();
  3025.                 }
  3026.                 else{
  3027.                     SwingWorker<String, String> worker4 = new SwingWorker<String, String>(){
  3028.  
  3029.                         protected String doInBackground(){
  3030.                             checkUpdatesFromFTP();
  3031.                             return null;
  3032.                         }
  3033.  
  3034.                     };
  3035.  
  3036.                     worker4.execute();
  3037.                 }
  3038.             }
  3039.         });
  3040.         update.setVisible(true);
  3041.         pane.add(update);
  3042.  
  3043.         manage = new JButton("Manage Server");
  3044.         manage.setFont(new Font(fontType2, 0, 14));
  3045.         manage.setBounds(new Rectangle(10, 595, 220, 30));
  3046.         manage.addActionListener(new ActionListener(){
  3047.             public void actionPerformed(ActionEvent e){
  3048.                 manage(false, false);
  3049.             }
  3050.         });
  3051.  
  3052.         manage.setVisible(true);
  3053.         //pane.add(manage);
  3054.  
  3055.         //update.setBounds(new Rectangle(748, 468, 220, 50));
  3056.  
  3057.         ramAllocation = new JButton("RAM Allocation");
  3058.         ramAllocation.setFont(new Font(fontType2, 0, 14));
  3059.         ramAllocation.setBounds(new Rectangle(240, 478, 220, 30));
  3060.         ramAllocation.addActionListener(new ActionListener(){
  3061.             public void actionPerformed(ActionEvent e){
  3062.                 SwingWorker<String, String> worker7 = new SwingWorker<String, String>(){
  3063.  
  3064.                     protected String doInBackground(){
  3065.                         ramAllocate();
  3066.                         return null;
  3067.                     }
  3068.  
  3069.                 };
  3070.                 worker7.execute();
  3071.             }
  3072.         });
  3073.         ramAllocation.setVisible(true);
  3074.         if (!(new File(new File(basepath, "Game"), "launcher_profiles.json")).exists()){
  3075.             ramAllocation.setEnabled(false);
  3076.         }else ramAllocation.setEnabled(true);
  3077.  
  3078.         pane.add(ramAllocation);
  3079.  
  3080.  
  3081.  
  3082.  
  3083.         tabs.addTab("Play", null, pane, "View the changelog and console - Play the game");
  3084.  
  3085.  
  3086.  
  3087.  
  3088.  
  3089.     }
  3090.  
  3091.     public static void finishFrame(){
  3092.         cont.add(tabs);
  3093.  
  3094.  
  3095.         frame.setContentPane(cont);
  3096.         frame.setVisible(true);
  3097.     }
  3098.  
  3099.     public static void delete(File file, boolean deleteParentDir, String... except){
  3100.  
  3101.  
  3102.  
  3103.         for (File f : file.listFiles()){
  3104.             if (f.getName().contains("programjar")) continue;
  3105.             if (except.toString().contains(f.getName()));
  3106.             if (f.isDirectory()){
  3107.                 delete(f, true);
  3108.             }else{
  3109.                 f.delete();
  3110.             }
  3111.         }
  3112.  
  3113.         if (deleteParentDir){
  3114.             file.delete();
  3115.         }
  3116.     }
  3117.  
  3118.     public static class UnZipper {
  3119.  
  3120.         /* I DID NOT MAKE THIS I GOT THIS OFF THE INTERNET */
  3121.         /**
  3122.          * Size of the buffer to read/write data
  3123.          */
  3124.         private static final int BUFFER_SIZE = 4096;
  3125.         /**
  3126.          * Extracts a zip file specified by the zipFilePath to a directory specified by
  3127.          * destDirectory (will be created if does not exists)
  3128.          * @param zipFilePath
  3129.          * @param destDirectory
  3130.          * @throws IOException
  3131.          */
  3132.         public static void unzip(String zipFilePath, String destDirectory) throws IOException {
  3133.             File destDir = new File(destDirectory);
  3134.             if (!destDir.exists()) {
  3135.                 destDir.mkdir();
  3136.             }
  3137.             ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath));
  3138.             ZipEntry entry = zipIn.getNextEntry();
  3139.             // iterates over entries in the zip file
  3140.             while (entry != null) {
  3141.                 String filePath = destDirectory + File.separator + entry.getName();
  3142.                 if (!entry.isDirectory()) {
  3143.                     // if the entry is a file, extracts it
  3144.                     extractFile(zipIn, filePath);
  3145.                 } else {
  3146.                     // if the entry is a directory, make the directory
  3147.                     File dir = new File(filePath);
  3148.                     dir.mkdir();
  3149.                 }
  3150.                 zipIn.closeEntry();
  3151.                 entry = zipIn.getNextEntry();
  3152.             }
  3153.             zipIn.close();
  3154.         }
  3155.         /**
  3156.          * Extracts a zip entry (file entry)
  3157.          * @param zipIn
  3158.          * @param filePath
  3159.          * @throws IOException
  3160.          */
  3161.         private static void extractFile(ZipInputStream zipIn, String filePath) throws IOException {
  3162.             BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath));
  3163.             byte[] bytesIn = new byte[BUFFER_SIZE];
  3164.             int read = 0;
  3165.             while ((read = zipIn.read(bytesIn)) != -1) {
  3166.                 bos.write(bytesIn, 0, read);
  3167.             }
  3168.             bos.close();
  3169.         }
  3170.     }
  3171.  
  3172.  
  3173.  
  3174. }
Advertisement
Add Comment
Please, Sign In to add comment