Advertisement
Blockhead7360

DMS Launcher Code - upd Jun 28 2017

Jun 28th, 2017
862
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 54.78 KB | None | 0 0
  1. //Updated Jun 28 2017
  2.  
  3. //This program involves me being dumb and putting 97% of my code in one class
  4.  
  5. package com.blockhead7360.dms.program;
  6.  
  7. import java.awt.Container;
  8. import java.awt.Desktop;
  9. import java.awt.Dimension;
  10. import java.awt.Font;
  11. import java.awt.HeadlessException;
  12. import java.awt.Insets;
  13. import java.awt.Rectangle;
  14. import java.awt.event.ActionEvent;
  15. import java.awt.event.ActionListener;
  16. import java.awt.image.BufferedImage;
  17. import java.io.BufferedOutputStream;
  18. import java.io.BufferedReader;
  19. import java.io.File;
  20. import java.io.FileInputStream;
  21. import java.io.FileNotFoundException;
  22. import java.io.FileOutputStream;
  23. import java.io.IOException;
  24. import java.io.InputStream;
  25. import java.io.InputStreamReader;
  26. import java.io.OutputStream;
  27. import java.io.PrintStream;
  28. import java.io.PrintWriter;
  29. import java.io.StringWriter;
  30. import java.net.HttpURLConnection;
  31. import java.net.MalformedURLException;
  32. import java.net.SocketException;
  33. import java.net.URISyntaxException;
  34. import java.net.URL;
  35. import java.nio.file.Files;
  36. import java.nio.file.OpenOption;
  37. import java.nio.file.StandardOpenOption;
  38. import java.text.SimpleDateFormat;
  39. import java.util.ArrayList;
  40. import java.util.Date;
  41. import java.util.List;
  42. import java.util.Properties;
  43. import java.util.regex.Matcher;
  44.  
  45. import javax.imageio.ImageIO;
  46. import javax.mail.Authenticator;
  47. import javax.mail.Message;
  48. import javax.mail.MessagingException;
  49. import javax.mail.PasswordAuthentication;
  50. import javax.mail.Session;
  51. import javax.mail.Transport;
  52. import javax.mail.internet.InternetAddress;
  53. import javax.mail.internet.MimeMessage;
  54. import javax.swing.ImageIcon;
  55. import javax.swing.JButton;
  56. import javax.swing.JFileChooser;
  57. import javax.swing.JFrame;
  58. import javax.swing.JLabel;
  59. import javax.swing.JOptionPane;
  60. import javax.swing.JScrollPane;
  61. import javax.swing.JTextArea;
  62. import javax.swing.SwingWorker;
  63. import javax.swing.text.DefaultCaret;
  64.  
  65. import org.apache.commons.net.ftp.FTP;
  66. import org.apache.commons.net.ftp.FTPClient;
  67. import org.apache.commons.net.ftp.FTPFile;
  68.  
  69. public class DMSLauncher {
  70.     static String thisVer = "1.4.0.3";
  71.     static String oldVer = "";
  72.     static String content;
  73.     static String splitKey;
  74.     static JTextArea changelog;
  75.     static JTextArea console;
  76.     static JButton update;
  77.     static JButton manage;
  78.     static JButton ramAllocation;
  79.  
  80.     //static JButton webSave;
  81.     static JButton resetWorkspace;
  82.     //static JTextField webField;
  83.     //static List<InstallFile> fileinstalls;
  84.     //static String ver;
  85.     //static String verser;
  86.     static String prgmUpdateTo;
  87.     static String prgmDownload;
  88.     static String prgmPath;
  89.     static JLabel updatetext;
  90.     static JFrame frame;
  91.     static JFrame frameu;
  92.     static String clientPath;
  93.     static String web;
  94.     //static List<String> logHistory;
  95.     //static List<String> fileHistory;
  96.     static String fontType;
  97.     static String fontType2;
  98.     //static List<String> deleteIfExist;
  99.     //static Map<String, String> installMods;
  100.     static String changelogstr;
  101.     static String imageUrl = "http://www.blockhead7360.com/uploads/5/0/1/9/50198061/dilans-modded-server-ii_1_orig.png";
  102.  
  103.     static List<String> delete, install;
  104.  
  105.     static FTPClient client;
  106.  
  107.  
  108.     static String baseMinecraft;
  109.     static String baseminecraftWindows;
  110.     static String password;
  111.     static String igi;
  112.  
  113.     static String host = "modded.blockhead7360.com";
  114.     static int port = 21;
  115.     static String user = "Blockhead7360.26120";
  116.     static String pass = "***************"; //HA I WOULD NEVER TELL YOU PEOPLE THE FTP PASSWORD
  117.  
  118.     public static void saveFile(URL url, String file)
  119.             throws IOException
  120.     {
  121.         InputStream in = url.openStream();
  122.         FileOutputStream fos = new FileOutputStream(new File(file));
  123.  
  124.         int length = -1;
  125.         byte[] buffer = new byte[4096];
  126.         while ((length = in.read(buffer)) > -1) {
  127.             fos.write(buffer, 0, length);
  128.         }
  129.         fos.close();
  130.         in.close();
  131.     }
  132.  
  133.     /*public static JsonObject authMinecraft(String username, String pass){
  134.         String result = "";
  135.         try {
  136.             result = AuthMinecraft.httpRequest(new URL("https://authserver.mojang.com/authenticate"), AuthMinecraft.MakeJSONRequest(username, pass));
  137.         } catch (MalformedURLException e) {
  138.             crashReport(e);
  139.         } catch (Exception e) {
  140.             crashReport(e);
  141.         }
  142.        
  143.         //{"accessToken":"e026bc59c67644639b8b8893d9a87976","clientToken":"8eaa5aab20b44dccae26fd3d32d04327","selectedProfile":{"id":"472d43365da741eb9c0493e489a70419","name":"Blockhead7360"},"availableProfiles":[{"id":"472d43365da741eb9c0493e489a70419","name":"Blockhead7360"}]}
  144.         JsonReader reader = Json.createReader(new StringReader(result));
  145.        
  146.         JsonObject info = reader.readObject();
  147.         reader.close();
  148.        
  149.         return info;
  150.        
  151.     }*/
  152.    
  153.     public static void saveFileProgress(URL url, String file)
  154.             throws IOException
  155.     {
  156.  
  157.         InputStream in = url.openStream();
  158.         FileOutputStream fos = new FileOutputStream(new File(file));
  159.         HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection();
  160.         long filesize = httpConnection.getContentLengthLong();
  161.         long downloaded = 0;
  162.         console.append("Downloaded " + (downloaded / 1000000) + " MB / " + (filesize/1000000) + " MB");
  163.         int length = -1;
  164.         byte[] buffer = new byte[4096];
  165.         while ((length = in.read(buffer)) > -1) {
  166.  
  167.             console.setText(console.getText().replaceAll("Downloaded " + (downloaded/1000000) + " MB", "Downloaded " + ((downloaded + length)/1000000) + " MB"));
  168.             downloaded += length;
  169.  
  170.             fos.write(buffer, 0, length);
  171.         }
  172.         fos.close();
  173.         in.close();
  174.     }
  175.  
  176.     public static boolean isWindows(){
  177.         return !(System.getProperty("os.name").contains("mac") || System.getProperty("os.name").contains("Mac"));
  178.     }
  179.  
  180.     public DMSLauncher(String consoles)
  181.     {
  182.  
  183.         /*UnZipper zipper = new UnZipper();
  184.         try {
  185.             zipper.unzip("/Users/dilan/Desktop/Test.zip", "/Users/dilan/Desktop/Inside");
  186.         } catch (IOException e1) {
  187.             e1.printStackTrace();
  188.         }*/
  189.        
  190.  
  191.  
  192.                
  193.         if (!isWindows()){
  194.             fontType = "monaco";
  195.             splitKey = "/";
  196.         }
  197.         else {
  198.             fontType = "consolas";
  199.             splitKey = "\\\\";
  200.         }
  201.         basepath = (new File(new JFileChooser().getFileSystemView().getDefaultDirectory(), "Documents" + splitKey + "DMSUpdater")).getPath();
  202.         fontType2 = fontType;
  203.        
  204.        
  205.         JFrame framex = new JFrame("DMSLauncher is starting...");
  206.         framex.setMinimumSize(new Dimension(500, 100));
  207.         framex.setPreferredSize(new Dimension(500, 100));
  208.         framex.setMaximumSize(new Dimension(500, 100));
  209.         framex.setDefaultCloseOperation(0);
  210.         framex.setLocationRelativeTo(null);
  211.         framex.setResizable(false);
  212.         Container panex = new Container();
  213.         framex.setLayout(null);
  214.         panex.setLayout(null);
  215.         JLabel labelx = new JLabel("DMSLauncher v" + thisVer + " is loading. Please wait...", 0);
  216.         labelx.setFont(new Font(fontType, 1, 16));
  217.         labelx.setBounds(new Rectangle(0, -20, 500, 100));
  218.         panex.add(labelx);
  219.  
  220.         JLabel creditx = new JLabel("Created by Dilan Nair - http://blockhead7360.com", 0);
  221.         creditx.setFont(new Font("arial", 2, 12));
  222.         creditx.setBounds(new Rectangle(0, 40, 500, 40));
  223.         panex.add(creditx);
  224.  
  225.         framex.setContentPane(panex);
  226.         framex.setVisible(true);
  227.  
  228.         boolean pause = true;
  229.         long old = System.currentTimeMillis();
  230.         while (pause) {
  231.             if (System.currentTimeMillis() - old > 1000L) {
  232.                 pause = false;
  233.             }
  234.         }
  235.  
  236.  
  237.         clientPath = "";
  238.         web = "";
  239.         changelogstr = "";
  240.  
  241.         console = new JTextArea(consoles);
  242.  
  243.         loadFolder();
  244.         //deleteOldVersion();
  245.         pause = true;
  246.         old = System.currentTimeMillis();
  247.         while (pause) {
  248.             if (System.currentTimeMillis() - old > 1000L) {
  249.                 pause = false;
  250.             }
  251.         }
  252.         readScript();
  253.         setupScript();
  254.         loadFrame();
  255.         framex.setVisible(false);
  256.         framex.dispose();
  257.         try
  258.         {
  259.             checkForUpdates();
  260.         }
  261.         catch (MalformedURLException e)
  262.         {
  263.             crashReport(e);
  264.             return;
  265.         }
  266.         catch (IOException e)
  267.         {
  268.             crashReport(e);
  269.             return;
  270.         }
  271.     }
  272.  
  273.     public static void deleteOldVersion()
  274.     {
  275.         if (oldVer.equals(thisVer)) {
  276.             return;
  277.         }
  278.         File dir = new File(prgmPath);
  279.         if (dir.exists())
  280.         {
  281.             File[] arrayOfFile;
  282.             int j = (arrayOfFile = dir.listFiles()).length;
  283.             for (int i = 0; i < j; i++)
  284.             {
  285.                 File f = arrayOfFile[i];
  286.  
  287.                 if (f.getName().equalsIgnoreCase("DMS Launcher " + oldVer + ".jar")) {
  288.                     f.delete();
  289.                 }
  290.             }
  291.         }
  292.     }
  293.  
  294.     public static void main(String[] args)
  295.     {
  296.         new DMSLauncher("");
  297.     }
  298.  
  299.     public static void setupScript()
  300.     {
  301.  
  302.     }
  303.  
  304.  
  305.     public static void clearFile(File file)
  306.     {
  307.         try
  308.         {
  309.             PrintWriter writer = new PrintWriter(file);
  310.             writer.close();
  311.         }
  312.         catch (FileNotFoundException e)
  313.         {
  314.             crashReport(e);
  315.             return;
  316.         }
  317.     }
  318.  
  319.     /*public static void setPath()
  320.     {
  321.  
  322.         boolean cont = false;
  323.  
  324.         File parent = null;
  325.  
  326.  
  327.         if ((new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Documents" + splitKey + "Curse")).exists()){
  328.             if ((new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Documents" + splitKey + "Curse" + splitKey + "Minecraft" + splitKey + "Instances")).exists()){
  329.                 cont = true;
  330.                 parent = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Documents" + splitKey + "Curse" + splitKey + "Minecraft" + splitKey + "Instances");
  331.             }
  332.         }
  333.         if ((new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Curse")).exists()){
  334.             if ((new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Curse" + splitKey + "Minecraft" + splitKey + "Instances")).exists()){
  335.                 cont = true;
  336.                 parent = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Curse" + splitKey + "Minecraft" + splitKey + "Instances");
  337.             }
  338.         }
  339.  
  340.         if (cont){
  341.  
  342.             List<Object> options = new ArrayList<Object>();
  343.  
  344.  
  345.             for (File f : parent.listFiles()){
  346.                 if (f.isDirectory()){
  347.                     options.add(f.getName());
  348.                 }
  349.             }
  350.  
  351.             Object s = JOptionPane.showInputDialog(frame, "Select an installed mod pack from below...", "Automatic Path Setter", JOptionPane.QUESTION_MESSAGE, null, options.toArray(), options.get(0));
  352.  
  353.             if (s == null){
  354.                 return;
  355.             }
  356.  
  357.  
  358.         }
  359.  
  360.         if (!cont){
  361.             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");
  362.             if (i == JOptionPane.NO_OPTION){
  363.                 return;
  364.             }
  365.         }
  366.  
  367.  
  368.  
  369.         String key;
  370.         if ((System.getProperty("os.name").contains("mac")) || (System.getProperty("os.name").contains("Mac"))) {
  371.             key = "/";
  372.         } else {
  373.             key = "\\\\";
  374.         }
  375.         JFileChooser fc = new JFileChooser();
  376.         fc.setCurrentDirectory(new File(clientPath));
  377.         fc.setFileSelectionMode(1);
  378.         fc.setDialogTitle("Find and select the mods folder for the mod pack");
  379.         int val = fc.showDialog(frame, "Set Path");
  380.         if (val == 0)
  381.         {
  382.             File file = fc.getSelectedFile();
  383.             if (file.getPath().split(key)[(file.getPath().split(key).length - 1)].equals(file.getPath().split(key)[(file.getPath().split(key).length - 2)]))
  384.             {
  385.                 String[] paths = file.getPath().split(key);
  386.                 int length = paths.length;
  387.                 paths[(length - 1)] = "";
  388.                 String path = "";
  389.                 String[] arrayOfString1;
  390.                 int j = (arrayOfString1 = paths).length;
  391.                 for (int i = 0; i < j; i++)
  392.                 {
  393.                     String x = arrayOfString1[i];
  394.                     path = path + key + x;
  395.                 }
  396.                 if (path.startsWith(key + key)) {
  397.                     path = path.replaceFirst(key, "");
  398.                 }
  399.                 if (path.endsWith(key))
  400.                 {
  401.                     int l = path.length();
  402.                     path = path.substring(0, l - 1);
  403.                 }
  404.                 file = new File(path);
  405.             }
  406.             File pathFile = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Documents" + splitKey + "DMSUpdater", "path.txt");
  407.             try
  408.             {
  409.                 clearFile(pathFile);
  410.                 Files.write(pathFile.toPath(), file.getPath().getBytes(), new OpenOption[] { StandardOpenOption.CREATE });
  411.             }
  412.             catch (IOException e1)
  413.             {
  414.                 crashReport(e1);           
  415.                 return;
  416.             }
  417.             clientPath = file.getPath().toString();
  418.             console.append("\n\nMods directory changed: \n" + clientPath);
  419.  
  420.             loadInstallFiles();
  421.         }
  422.     }
  423.      */
  424.     public static void checkForUpdates()
  425.             throws MalformedURLException, IOException
  426.     {
  427.         URL home = new URL("http://blockhead7360.com/dmsucheckforupdates");
  428.         BufferedReader in2 = new BufferedReader(new InputStreamReader(home.openStream()));
  429.  
  430.         List<String> list2 = new ArrayList<String>();
  431.         String str2;
  432.         while ((str2 = in2.readLine()) != null)
  433.         {
  434.             list2.add(str2);
  435.         }
  436.         in2.close();
  437.         String content2 = list2.toString().split("iiStartProgramii-")[1].split("iiEndProgramii")[0];
  438.  
  439.         URL find = new URL(content2);
  440.         BufferedReader in = new BufferedReader(new InputStreamReader(find.openStream()));
  441.  
  442.         List<String> list = new ArrayList<String>();
  443.         String str;
  444.         while ((str = in.readLine()) != null)
  445.         {
  446.             list.add(str);
  447.         }
  448.         in.close();
  449.  
  450.         String content = list.toString().split("iiStartProgramii-")[1].split("iiEndProgramii")[0];
  451.  
  452.         String verload = content.split("iiVersionii-")[1].split("iiStopii-")[0];
  453.  
  454.         String changelogload = content.split("iiChangelogii-")[1].split("iiStopii-")[0];
  455.         changelogload = changelogload.replaceAll("iiNLii", "\n");
  456.  
  457.         String downloadload = content.split("iiDownloadii-")[1].split("iiStopii-")[0];
  458.         if (!thisVer.equals(verload))
  459.         {
  460.             frameu = new JFrame("DMSLauncher program update available!");
  461.  
  462.             frameu.setPreferredSize(new Dimension(400, 600));
  463.             frameu.setMaximumSize(new Dimension(400, 600));
  464.             frameu.setMinimumSize(new Dimension(400, 600));
  465.             frameu.setDefaultCloseOperation(2);
  466.             frameu.setResizable(false);
  467.             frameu.setLocationRelativeTo(null);
  468.             Container pane = new Container();
  469.             frameu.setLayout(null);
  470.  
  471.             JLabel label = new JLabel("A new version of DMSLauncher is available!", 0);
  472.             label.setFont(new Font("arial", 1, 18));
  473.             label.setBounds(new Rectangle(0, 10, 400, 30));
  474.             pane.add(label);
  475.  
  476.             JTextArea area = new JTextArea();
  477.  
  478.             area.setFont(new Font(fontType, 0, 14));
  479.             area.setEditable(false);
  480.             area.setText(changelogload);
  481.             JScrollPane scroll = new JScrollPane(area);
  482.             scroll.setBounds(new Rectangle(10, 55, 380, 470));
  483.             pane.add(scroll);
  484.  
  485.             JButton button = new JButton("Update this program to v" + verload);
  486.             button.setFont(new Font(fontType, 0, 12));
  487.             button.setBounds(new Rectangle(50, 530, 300, 35));
  488.             prgmUpdateTo = verload;
  489.             prgmDownload = downloadload;
  490.             button.addActionListener(new ActionListener()
  491.             {
  492.                 public void actionPerformed(ActionEvent e)
  493.                 {
  494.                     SwingWorker<String, String> worker2 = new SwingWorker<String, String>()
  495.                     {
  496.                         protected String doInBackground()
  497.                         {
  498.                             DMSLauncher.updateProgram();
  499.                             return null;
  500.                         }
  501.                     };
  502.                     worker2.execute();
  503.                 }
  504.             });
  505.             pane.add(button);
  506.  
  507.             frameu.setContentPane(pane);
  508.             frameu.setVisible(true);
  509.         }
  510.     }
  511.  
  512.     public static void updateProgram()
  513.     {
  514.         frameu.setVisible(false);
  515.         frameu.dispose();
  516.  
  517.         frame.setVisible(false);
  518.         frame.dispose();
  519.  
  520.         JFrame updating = new JFrame("Updating DMSLauncher to v" + prgmUpdateTo);
  521.         updating.setPreferredSize(new Dimension(400, 100));
  522.         updating.setMaximumSize(new Dimension(400, 100));
  523.         updating.setMinimumSize(new Dimension(400, 100));
  524.         updating.setDefaultCloseOperation(0);
  525.         updating.setResizable(false);
  526.         updating.setLocationRelativeTo(null);
  527.         Container pane = new Container();
  528.         updating.setLayout(null);
  529.  
  530.         JLabel label = new JLabel("Downloading new version...", 0);
  531.         label.setFont(new Font("arial", 1, 18));
  532.         label.setBounds(new Rectangle(0, 20, 400, 40));
  533.         pane.add(label);
  534.  
  535.         updating.setContentPane(pane);
  536.         updating.setVisible(true);
  537.  
  538.         boolean pause = true;
  539.         long old = System.currentTimeMillis();
  540.         while (pause) {
  541.             if (System.currentTimeMillis() - old > 1000L) {
  542.                 pause = false;
  543.             }
  544.         }
  545.         try
  546.         {
  547.             saveFile(new URL(prgmDownload), prgmPath + splitKey + "DMS Launcher " + prgmUpdateTo + ".jar");
  548.         }
  549.         catch (MalformedURLException e)
  550.         {
  551.             crashReport(e);        
  552.             return;
  553.         }
  554.         catch (IOException e)
  555.         {
  556.             crashReport(e);
  557.             return;
  558.         }
  559.         boolean pausex = true;
  560.         long oldx = System.currentTimeMillis();
  561.         while (pausex) {
  562.             if (System.currentTimeMillis() - oldx > 1000L) {
  563.                 pausex = false;
  564.             }
  565.         }
  566.         try
  567.         {
  568.             Desktop.getDesktop().open(new File(prgmPath + splitKey + "DMS Launcher " + prgmUpdateTo + ".jar"));
  569.         }
  570.         catch (IOException e)
  571.         {
  572.             crashReport(e);
  573.             return;
  574.         }
  575.         System.exit(0);
  576.     }
  577.  
  578.     public static void readScript()
  579.     {
  580.         URL home = null;
  581.         BufferedReader in;
  582.  
  583.         try
  584.         {
  585.             home = new URL("http://blockhead7360.com/" + web);
  586.         }
  587.         catch (MalformedURLException ex)
  588.         {
  589.             crashReport(ex);
  590.             return;
  591.         }
  592.         try
  593.         {
  594.             in = new BufferedReader(new InputStreamReader(home.openStream()));
  595.         }
  596.         catch (IOException ex)
  597.         {
  598.             crashReport(ex);
  599.             return;
  600.         }
  601.         List<String> list = new ArrayList<String>();
  602.         try
  603.         {
  604.             String str;
  605.             while ((str = in.readLine()) != null)
  606.             {
  607.                 list.add(str);
  608.             }
  609.         }
  610.         catch (IOException e)
  611.         {
  612.             crashReport(e);
  613.         }
  614.         try
  615.         {
  616.             in.close();
  617.         }
  618.         catch (IOException e)
  619.         {
  620.             crashReport(e);
  621.         }
  622.  
  623.         String content2 = list.toString().split("iiStartScriptii-")[1].split("iiEndScriptii")[0];
  624.  
  625.         URL home2 = null;
  626.         try
  627.         {
  628.             home2 = new URL(content2);
  629.         }
  630.         catch (MalformedURLException ex)
  631.         {
  632.             crashReport(ex);
  633.             return;
  634.         }
  635.         BufferedReader in2 = null;
  636.         try
  637.         {
  638.             in2 = new BufferedReader(new InputStreamReader(home2.openStream()));
  639.         }
  640.         catch (IOException ex)
  641.         {
  642.             crashReport(ex);
  643.         }
  644.         List<String> list2 = new ArrayList<String>();
  645.         try
  646.         {
  647.             String str2;
  648.             while ((str2 = in2.readLine()) != null)
  649.             {
  650.                 list2.add(str2);
  651.             }
  652.         }
  653.         catch (IOException e)
  654.         {
  655.             crashReport(e);
  656.         }
  657.         try
  658.         {
  659.             in2.close();
  660.         }
  661.         catch (IOException e)
  662.         {
  663.             crashReport(e);
  664.         }
  665.         content = list2.toString().split("iiStartScriptii-")[1].split("iiEndScriptii")[0];
  666.  
  667.         String changelogload = content.split("iiChangelogii-")[1].split("iiStopii-")[0];
  668.         changelogstr = changelogload.replaceAll("iiNLii", "\n");
  669.  
  670.         String passwordload = content.split("iiTypeii-")[1].split("iiStopii-")[0];
  671.         password = passwordload.replaceAll("*^*^*^*^*^", "*^*^*^*^*^").replaceAll("*^*^*^*^*^", "*^*^*^*^*^");
  672.         //HA I WOULD NEVER TELL YOU PEOPLE HOW TO DECODE THE MANAGE SERVER PASSWORD
  673.  
  674.         String baseminecraftload = content.split("iiBaseMinecraftii-")[1].split("iiStopii-")[0];
  675.         baseMinecraft = baseminecraftload;
  676.  
  677.         String baseminecraftwinload = content.split("iiBaseMinecraftWinii-")[1].split("iiStopii-")[0];
  678.         baseminecraftWindows = baseminecraftwinload;
  679.        
  680.         String igiload = content.split("iiIGIii-")[1].split("iiStopii-")[0];
  681.         igi = igiload;
  682.  
  683.     }
  684.  
  685.     public static void reconnectFTP(){
  686.         try {
  687.             if (client == null){
  688.                 client = new FTPClient();
  689.             }
  690.             client.connect(host, port);
  691.             client.login(user, pass);
  692.             client.enterLocalPassiveMode();
  693.             client.setFileType(FTP.BINARY_FILE_TYPE);
  694.         } catch (SocketException e) {
  695.             crashReport(e);
  696.         } catch (IOException e) {
  697.             crashReport(e);
  698.         }
  699.  
  700.     }
  701.  
  702.     public static void checkUpdatesFromFTP(){
  703.  
  704.         disableFrame();
  705.         updatetext.setText("Checking for updates...");
  706.  
  707.         FTPClient ftpclient = new FTPClient();
  708.  
  709.         try{
  710.  
  711.             console.append("Connecting to FTP server...\n\n");
  712.             ftpclient.connect(host, port);
  713.             console.append("Logging in to FTP server...\n\n");
  714.             ftpclient.login(user, pass);
  715.             console.append("Connected!\n\n\n");
  716.             ftpclient.enterLocalPassiveMode();
  717.             ftpclient.setFileType(FTP.BINARY_FILE_TYPE);
  718.  
  719.             client = ftpclient;
  720.  
  721.             ftpclient.changeWorkingDirectory("/DMSLauncher");
  722.  
  723.             FTPFile[] away = ftpclient.listFiles();
  724.  
  725.             File[] home = (new File(basepath, "Game/mods")).listFiles();
  726.  
  727.  
  728.             List<String> client = new ArrayList<String>();
  729.             List<String> server = new ArrayList<String>();
  730.  
  731.             console.append("Checking for updates...\n\n");
  732.  
  733.             for (File f : home){
  734.                 if (!f.getName().contains("DS_Store")){
  735.                     client.add(f.getName());
  736.                 }
  737.             }
  738.  
  739.             for (FTPFile f : away){
  740.                 if (!f.getName().contains("DS_Store")){
  741.                     server.add(f.getName());
  742.                 }
  743.             }
  744.  
  745.             updatetext.setText(" ");
  746.             enableFrame();
  747.  
  748.             if (client.size() != server.size()){
  749.                 console.append("An update is available.\n\n");
  750.                 summaryAndConfirmUpdate(client, server);
  751.  
  752.             }else{
  753.                 console.append("No update available.\n\n");
  754.                 play();
  755.  
  756.             }
  757.  
  758.  
  759.  
  760.  
  761.         }catch(IOException ex){
  762.             crashReport(ex);
  763.         }
  764.  
  765.  
  766.     }
  767.  
  768.  
  769.     public static void appendConsole(String txt)
  770.     {
  771.         console.append(txt);
  772.     }
  773.  
  774.    
  775.    
  776.    
  777.  
  778.     static Exception exinfo;
  779.  
  780.  
  781.    
  782.  
  783.     static URL sfp_url;
  784.     static String sfp_file;
  785.  
  786.    
  787.  
  788.     public static void play(){
  789.         /*UnZipper unzip = new UnZipper();
  790.         try {
  791.             unzip.unzip("/Users/dilan/Desktop/MCFiles.zip", "/Users/dilan/Desktop/Extracted");
  792.         } catch (IOException e) {
  793.             e.printStackTrace();
  794.         }
  795.  
  796.         pause();*/
  797.  
  798.         SwingWorker<String, String> worker6 = new SwingWorker<String, String>(){
  799.  
  800.             protected String doInBackground(){
  801.                 playGo();
  802.                 return null;
  803.             }
  804.  
  805.         };
  806.        
  807.         worker6.execute();
  808.  
  809.  
  810.     }
  811.  
  812.    
  813.     public static void playGo(){
  814.        
  815.         console.append("\nRefreshing InGameInfo.xml...\n\n");
  816.        
  817.  
  818.        
  819.        
  820.         try {
  821.             saveFile(new URL(igi), new File(basepath, "Game/config/InGameInfo.xml").getPath());
  822.         } catch (MalformedURLException e1) {
  823.             crashReport(e1);
  824.         } catch (IOException e1) {
  825.             crashReport(e1);
  826.         }
  827.        
  828.         console.append("\nOpening Minecraft launcher...");
  829.  
  830.        
  831.         if (!isWindows()){
  832.             try {
  833.  
  834.                 Runtime.getRuntime().exec("chmod +x " + basepath + "/Game/runMC.command");
  835.                 pause(500L);
  836.                 Desktop.getDesktop().open(new File(basepath, "Game/runMC.command"));
  837.             } catch (IOException e) {
  838.                 crashReport(e);
  839.             }
  840.         }else{
  841.             try{
  842.                 Desktop.getDesktop().open(new File(basepath, "Game/runMC.bat"));
  843.             }catch(IOException e){
  844.                 crashReport(e);
  845.             }
  846.         }
  847.        
  848.         pause(1000L);
  849.         //System.exit(0);
  850.     }
  851.  
  852.     public static void pause(long ms){
  853.         boolean pause = true;
  854.         long old = System.currentTimeMillis();
  855.         while (pause) {
  856.             if (System.currentTimeMillis() - old > ms) {
  857.                 pause = false;
  858.             }
  859.         }
  860.     }
  861.  
  862.  
  863.  
  864.     public static void update()
  865.     {
  866.         //webField.setEditable(false);
  867.         //webSave.setEnabled(false);
  868.         disableFrame();
  869.         updatetext.setText("Updating modded client...");
  870.  
  871.         console.append("\n\nUpdating client mods to match\nwith server\'s client selection...\n\n\n");
  872.  
  873.         for (String s : delete){
  874.             File file = new File(new File(basepath, "Game/mods"), s);
  875.             if (file.exists()){
  876.                 file.delete();
  877.                 console.append("Deleted file:\n" + s + "\n\n");
  878.                 pause(250L);
  879.             }
  880.         }
  881.  
  882.         for (String s : install){
  883.  
  884.             console.append("Downloading file:\n" + s + "\n");
  885.             File file = new File(new File(basepath, "Game/mods"), s);
  886.  
  887.  
  888.             try {
  889.                 client.changeWorkingDirectory("/DMSLauncher");
  890.             } catch (IOException e) {
  891.                 crashReport(e);
  892.             }
  893.  
  894.  
  895.             try {
  896.                 OutputStream os = new BufferedOutputStream(new FileOutputStream(file));
  897.                 InputStream is = client.retrieveFileStream(s);
  898.                 byte[] bytes = new byte[4096];
  899.                 int byteread = -1;
  900.                 while ((byteread = is.read(bytes)) != -1){
  901.                     os.write(bytes, 0, byteread);
  902.                 }
  903.                 boolean success = client.completePendingCommand();
  904.                 if (success){
  905.                     console.append("Complete!\n\n");
  906.                 }
  907.                 os.close();
  908.                 is.close();
  909.  
  910.             } catch (FileNotFoundException e) {
  911.                 crashReport(e);
  912.             } catch (IOException e) {
  913.                 crashReport(e);
  914.             }
  915.  
  916.  
  917.         }
  918.  
  919.  
  920.  
  921.  
  922.         enableFrame();
  923.         updatetext.setText(" ");
  924.  
  925.         console.append("\n\n\nUpdate is complete!\n\n");
  926.         pause(1000L);
  927.         play();
  928.     }
  929.  
  930.     static String basepath;
  931.  
  932.     public static void loadFolder()
  933.     {
  934.  
  935.         web = "script";
  936.  
  937.         File base_folder = new File(new JFileChooser().getFileSystemView().getDefaultDirectory(), "Documents" + splitKey + "DMSUpdater");
  938.         if (!base_folder.exists()) {
  939.             base_folder.mkdirs();
  940.         }
  941.         File prgmVerFile = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Documents" + splitKey + "DMSUpdater", "prgm.txt");
  942.         if (prgmVerFile.exists())
  943.         {
  944.             List<String> lines = null;
  945.             try
  946.             {
  947.                 lines = Files.readAllLines(prgmVerFile.toPath());
  948.             }
  949.             catch (IOException e)
  950.             {
  951.                 crashReport(e);
  952.             }
  953.             oldVer = (String)lines.get(0);
  954.         }
  955.         if (!prgmVerFile.exists()) {
  956.             try
  957.             {
  958.                 prgmVerFile.createNewFile();
  959.             }
  960.             catch (IOException e)
  961.             {
  962.                 crashReport(e);
  963.                 return;
  964.             }
  965.         }
  966.         String contentx1 = thisVer;
  967.         try
  968.         {
  969.             clearFile(prgmVerFile);
  970.             Files.write(prgmVerFile.toPath(), contentx1.getBytes(), new OpenOption[] { StandardOpenOption.CREATE });
  971.         }
  972.         catch (IOException e)
  973.         {
  974.             crashReport(e);
  975.         }
  976.  
  977.  
  978.  
  979.  
  980.  
  981.         File locationFile = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + splitKey + "Documents" + splitKey + "DMSUpdater", "programlocation.txt");
  982.         if (!locationFile.exists()) {
  983.             try
  984.             {
  985.                 locationFile.createNewFile();
  986.             }
  987.             catch (IOException e)
  988.             {
  989.                 crashReport(e);
  990.             }
  991.         }
  992.         try
  993.         {
  994.             String content = DMSLauncher.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
  995.  
  996.             /*String[] contents = content.split(splitKey);
  997.             int length = contents.length;
  998.             contents[(length - 1)] = "";
  999.             content = "";
  1000.             String[] arrayOfString1;
  1001.             int j = (arrayOfString1 = contents).length;
  1002.             for (int i = 0; i < j; i++)
  1003.             {
  1004.                 String x = arrayOfString1[i];
  1005.                 content = content + splitKey + x;
  1006.             }
  1007.             if (content.startsWith(splitKey + splitKey)) {
  1008.                 content = content.replaceFirst(splitKey, "");
  1009.             }
  1010.             if (content.endsWith(splitKey))
  1011.             {
  1012.                 int l = content.length();
  1013.                 content = content.substring(0, l - 1);
  1014.             }*/
  1015.             /*clearFile(locationFile);
  1016.             String[] ss = content.split(splitKey);
  1017.             String l = "";
  1018.             for (int i = 0; i < ss.length - 1; i++){
  1019.  
  1020.                 l += ss[i] + (i == ss.length - 2 ? "" : splitKey);
  1021.             }
  1022.              */
  1023.  
  1024.             content = content.replaceAll("/DMS Launcher " + thisVer + ".jar", "");
  1025.             clearFile(locationFile);
  1026.             Files.write(locationFile.toPath(), content.getBytes(), new OpenOption[] { StandardOpenOption.CREATE });
  1027.  
  1028.             prgmPath = content;
  1029.         }
  1030.         catch (URISyntaxException e)
  1031.         {
  1032.             crashReport(e);
  1033.         }
  1034.         catch (IOException e)
  1035.         {
  1036.             crashReport(e);
  1037.         }
  1038.     }
  1039.  
  1040.  
  1041.     public static List<List<String>> updateNotes(List<String> clientFiles, List<String> serverFiles){
  1042.  
  1043.         List<String> deleteMods = new ArrayList<String>();
  1044.  
  1045.         for (String s : clientFiles){
  1046.             if (!serverFiles.contains(s)){
  1047.                 deleteMods.add(s);
  1048.             }
  1049.         }
  1050.  
  1051.         List<String> installMods = new ArrayList<String>();
  1052.  
  1053.         for (String s : serverFiles){
  1054.             if (!clientFiles.contains(s)){
  1055.                 installMods.add(s);
  1056.             }
  1057.         }
  1058.  
  1059.         List<List<String>> list = new ArrayList<List<String>>();
  1060.  
  1061.         list.add(deleteMods);
  1062.         list.add(installMods);
  1063.  
  1064.         return list;
  1065.  
  1066.  
  1067.     }
  1068.  
  1069.     public static void summaryAndConfirmUpdate(List<String> clientFiles, List<String> serverFiles){
  1070.         {
  1071.             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");
  1072.             if (result == 0)
  1073.             {
  1074.                 List<List<String>> mods = updateNotes(clientFiles, serverFiles);
  1075.                 delete = mods.get(0);
  1076.                 install = mods.get(1);
  1077.  
  1078.                 SwingWorker<String, String> worker = new SwingWorker<String, String>()
  1079.                 {
  1080.                     protected String doInBackground()
  1081.                     {
  1082.                         DMSLauncher.update();
  1083.                         return null;
  1084.                     }
  1085.                 };
  1086.                 worker.execute();
  1087.                 return;
  1088.             }
  1089.             if (result == 1)
  1090.             {
  1091.                     JFrame framex = new JFrame("Update Process Summary");
  1092.                     framex.setMinimumSize(new Dimension(600, 600));
  1093.                     framex.setPreferredSize(new Dimension(600, 600));
  1094.                     framex.setMaximumSize(new Dimension(600, 600));
  1095.                     framex.setDefaultCloseOperation(2);
  1096.                     framex.setLocationRelativeTo(frame);
  1097.                     framex.setResizable(false);
  1098.                     Container panex = new Container();
  1099.                     framex.setLayout(null);
  1100.                     panex.setLayout(null);
  1101.                     JLabel labelx = new JLabel("Installation Summary", 0);
  1102.                     labelx.setFont(new Font(fontType, 1, 16));
  1103.                     labelx.setBounds(new Rectangle(0, -40, 600, 100));
  1104.                     panex.add(labelx);
  1105.  
  1106.                     JTextArea area = new JTextArea();
  1107.  
  1108.                     String sm = "";
  1109.  
  1110.                     sm += "The following mods will be installed or deleted to match\n";
  1111.                     sm += "your mods folder with the server\'s client selection...\n\n";
  1112.                     sm += "Files to be deleted:\n";
  1113.  
  1114.                     int index = 1;
  1115.                     List<List<String>> mods = updateNotes(clientFiles, serverFiles);
  1116.                     for (String s : mods.get(0)){
  1117.                         sm += index + ". " + s + "\n";
  1118.                         index++;
  1119.                     }
  1120.                     sm += "\nFiles to be downloaded:\n";
  1121.  
  1122.                     index = 1;
  1123.  
  1124.                     for (String s : mods.get(1)){
  1125.                         sm += index + ". " + s + "\n";
  1126.                         index++;
  1127.                     }
  1128.  
  1129.                     area.setFont(new Font(fontType, 0, 14));
  1130.                     area.setEditable(false);
  1131.                     area.setText(sm);
  1132.                     JScrollPane scroll = new JScrollPane(area);
  1133.                     scroll.setBounds(new Rectangle(50, 30, 500, 500));
  1134.                     panex.add(scroll);
  1135.  
  1136.                     JButton buttonx = new JButton("Close");
  1137.                     buttonx.setFont(new Font("arial", 1, 14));
  1138.                     buttonx.setBounds(new Rectangle(225, 540, 150, 30));
  1139.                     buttonx.addActionListener(new ActionListener()
  1140.                     {
  1141.                         public void actionPerformed(ActionEvent e)
  1142.                         {
  1143.                             framex.setVisible(false);
  1144.                             framex.dispose();
  1145.  
  1146.                             DMSLauncher.summaryAndConfirmUpdate(clientFiles, serverFiles);
  1147.                         }
  1148.                     });
  1149.                     panex.add(buttonx);
  1150.                     framex.setContentPane(panex);
  1151.                     framex.setVisible(true);
  1152.  
  1153.             }
  1154.             if (result == 2) {
  1155.                 play();
  1156.             }
  1157.         }
  1158.     }
  1159.  
  1160.     public static void crashReport(Exception e){
  1161.         exinfo = e;
  1162.         SwingWorker<String, String> worker3 = new SwingWorker<String, String>(){
  1163.  
  1164.             protected String doInBackground(){
  1165.                 crashReportGo(exinfo);
  1166.                 return null;
  1167.             }
  1168.  
  1169.         };
  1170.         worker3.execute();
  1171.     }
  1172.  
  1173.     public static void crashReportGo(Exception e){
  1174.         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");
  1175.         if (x == JOptionPane.YES_OPTION){
  1176.             String s = JOptionPane.showInputDialog(frame, "Please enter your name", "Report to Dilan", JOptionPane.QUESTION_MESSAGE);
  1177.  
  1178.             JFrame sending = new JFrame("Sending email to support@blockhead7360.com");
  1179.             sending.setPreferredSize(new Dimension(400, 100));
  1180.             sending.setMaximumSize(new Dimension(400, 100));
  1181.             sending.setMinimumSize(new Dimension(400, 100));
  1182.             sending.setDefaultCloseOperation(0);
  1183.             sending.setResizable(false);
  1184.             sending.setLocationRelativeTo(null);
  1185.             Container pane = new Container();
  1186.             sending.setLayout(null);
  1187.  
  1188.             JLabel label = new JLabel("Reporting error...", 0);
  1189.             label.setFont(new Font("arial", 1, 18));
  1190.             label.setBounds(new Rectangle(0, 20, 400, 40));
  1191.             pane.add(label);
  1192.  
  1193.             sending.setContentPane(pane);
  1194.             sending.setVisible(true);
  1195.  
  1196.             String to = "support@blockhead7360.com";
  1197.             String from = "dmsupdater@blockhead7360.com";
  1198.  
  1199.             Properties properties = System.getProperties();
  1200.             properties.setProperty("mail.smtp.host", "smtp.zoho.com");
  1201.             properties.setProperty("mail.smtp.user", from);
  1202.             properties.setProperty("mail.smtp.pass", "*********");//NOT TELLING!!!!
  1203.             properties.setProperty("mail.smtp.port", "465");
  1204.             properties.setProperty("mail.smtp.auth", "true");
  1205.             properties.put("mail.smtp.socketFactory.port", "465");
  1206.             properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
  1207.             properties.put("mail.smtp.socketFactory.fallback", "false");
  1208.  
  1209.             Session session = Session.getDefaultInstance(properties, new Authenticator(){
  1210.                 public PasswordAuthentication getPasswordAuthentication(){
  1211.                     return new PasswordAuthentication("dmsupdater@blockhead7360.com", "*********");
  1212.                 }
  1213.             });
  1214.  
  1215.             try{
  1216.  
  1217.                 Message message = new MimeMessage(session);
  1218.                 message.setFrom(new InternetAddress(from));
  1219.                 message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
  1220.                 message.setSubject("Automatic DMSLauncher Error Report - " + s);
  1221.                 StringWriter sw = new StringWriter();
  1222.                 PrintWriter pw = new PrintWriter(sw);
  1223.                 e.printStackTrace(pw);
  1224.                 pw.close();
  1225.                 String j = sw.toString();
  1226.                 sw.close();
  1227.                 message.setText(j);
  1228.  
  1229.                 Transport transport = session.getTransport("smtp");
  1230.  
  1231.                 transport.connect("smtp.zoho.com", 465, "dmsupdater@blockhead7360.com", "*********");
  1232.                 transport.sendMessage(message, message.getAllRecipients());
  1233.                 transport.close();
  1234.                 sending.setVisible(false);
  1235.                 sending.dispose();
  1236.                 JOptionPane.showMessageDialog(frame, "Successfully reported this error.", "Sent Email", JOptionPane.INFORMATION_MESSAGE);
  1237.  
  1238.  
  1239.             } catch (MessagingException | IOException e1){
  1240.                 JOptionPane.showMessageDialog(frame, "Unable to send email report. The stack trace will save to file instead.", "Error Sending Email", JOptionPane.ERROR_MESSAGE);
  1241.                 File dir = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + DMSLauncher.splitKey + "Documents" + DMSLauncher.splitKey + "DMSUpdater", "stacktrace");
  1242.                 if (!dir.exists()){
  1243.                     dir.mkdirs();
  1244.                 }
  1245.                 Date date = new Date();
  1246.                 SimpleDateFormat format = new SimpleDateFormat("HH-mm-ss-MM-dd-yyyy");
  1247.                 File fx = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + DMSLauncher.splitKey + "Documents" + DMSLauncher.splitKey + "DMSUpdater" + splitKey + "stacktrace", format.format(date) + ".txt");
  1248.                 PrintStream ps = null;
  1249.                 try {
  1250.                     ps = new PrintStream(fx);
  1251.                 } catch (FileNotFoundException e1x) {
  1252.                     JOptionPane.showMessageDialog(frame, "Unable to save the stack trace to a file.", "Today is not a good day", JOptionPane.ERROR_MESSAGE);
  1253.                     return;
  1254.                 }
  1255.                 e1.printStackTrace(ps);
  1256.                 ps.close();
  1257.  
  1258.  
  1259.                 JOptionPane.showMessageDialog(frame, "The stack trace has been saved to \n" + fx.getPath(), "Stack Trace Saved to File", JOptionPane.ERROR_MESSAGE);
  1260.                 return;
  1261.             }
  1262.             return;
  1263.  
  1264.  
  1265.         }
  1266.         if (x == JOptionPane.NO_OPTION){
  1267.             File dir = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + DMSLauncher.splitKey + "Documents" + DMSLauncher.splitKey + "DMSUpdater", "stacktrace");
  1268.             if (!dir.exists()){
  1269.                 dir.mkdirs();
  1270.             }
  1271.             Date date = new Date();
  1272.             SimpleDateFormat format = new SimpleDateFormat("HH-mm-ss-MM-dd-yyyy");
  1273.             File fx = new File(new JFileChooser().getFileSystemView().getDefaultDirectory().toString() + DMSLauncher.splitKey + "Documents" + DMSLauncher.splitKey + "DMSUpdater" + splitKey + "stacktrace", format.format(date) + ".txt");
  1274.             PrintStream ps = null;
  1275.             try {
  1276.                 ps = new PrintStream(fx);
  1277.             } catch (FileNotFoundException e1) {
  1278.                 JOptionPane.showMessageDialog(frame, "Unable to save the stack trace to a file.", "Today is not a good day", JOptionPane.ERROR_MESSAGE);
  1279.                 return;
  1280.             }
  1281.             e.printStackTrace(ps);
  1282.             ps.close();
  1283.  
  1284.  
  1285.             JOptionPane.showMessageDialog(frame, "The stack trace has been saved to \n" + fx.getPath(), "Stack Trace Saved to File", JOptionPane.ERROR_MESSAGE);
  1286.             return;
  1287.         }
  1288.         if (x == JOptionPane.CANCEL_OPTION) { }
  1289.     }
  1290.  
  1291.  
  1292.     public static void manage(boolean wrong, boolean skipPass){
  1293.         String s = "";
  1294.         if (!skipPass)
  1295.             s = JOptionPane.showInputDialog(frame, (wrong ? "Incorrect password! Please try again..." : "Enter the administration password..."), "Manage Server", JOptionPane.QUESTION_MESSAGE);
  1296.         if (s == null) return;
  1297.         if (s.equals(password) || skipPass){
  1298.  
  1299.             int result = JOptionPane.showOptionDialog(frame, "Upload to or delete from server?", "Manage Server", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[] {"Upload File", "Delete File", "Done"}, "Done");
  1300.             if (result == 2) {}
  1301.             if (result == 0){
  1302.                 JFileChooser fc = new JFileChooser();
  1303.                 fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
  1304.                 fc.setDialogTitle("Select file to upload...");
  1305.                 int val = fc.showDialog(frame, "Upload to FTP");
  1306.                 if (val == JFileChooser.APPROVE_OPTION){
  1307.                     File local = fc.getSelectedFile();
  1308.                     if (local.isDirectory()){
  1309.                         JOptionPane.showMessageDialog(frame, "The file cannot be a folder.", "Manage Server", JOptionPane.ERROR_MESSAGE);
  1310.                         manage(false, true);
  1311.                         return;
  1312.                     }
  1313.                     int res = JOptionPane.showOptionDialog(frame, "Would you like to upload this file to the server-side mods folder also?", "Manage Server", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[] {"Yes", "No"}, "Yes");
  1314.  
  1315.                     try {
  1316.  
  1317.                         if (res == 0){
  1318.                             if (client == null || !client.isConnected()){
  1319.                                 reconnectFTP();
  1320.                             }
  1321.  
  1322.                             client.changeWorkingDirectory("/mods");
  1323.                             InputStream is = new FileInputStream(local);
  1324.                             OutputStream os = client.storeFileStream(local.getName());
  1325.                             byte[] bytes = new byte[4096];
  1326.                             int read = 0;
  1327.  
  1328.                             while ((read = is.read(bytes)) != -1){
  1329.                                 os.write(bytes, 0, read);
  1330.                             }
  1331.                             is.close();
  1332.                             os.close();
  1333.  
  1334.                             client.completePendingCommand();
  1335.  
  1336.  
  1337.  
  1338.                         }
  1339.                         if (client == null || !client.isConnected()){
  1340.                             reconnectFTP();
  1341.                         }
  1342.  
  1343.                         client.changeWorkingDirectory("/DMSLauncher");
  1344.                         InputStream is = new FileInputStream(local);
  1345.                         OutputStream os = client.storeFileStream(local.getName());
  1346.                         byte[] bytes = new byte[4096];
  1347.                         int read = 0;
  1348.  
  1349.                         while ((read = is.read(bytes)) != -1){
  1350.                             os.write(bytes, 0, read);
  1351.                         }
  1352.                         is.close();
  1353.                         os.close();
  1354.  
  1355.                         client.completePendingCommand();
  1356.  
  1357.                         JOptionPane.showMessageDialog(frame, "Successfully uploaded " + local.getName() + " to the FTP server.", "Manage Server", JOptionPane.INFORMATION_MESSAGE);
  1358.  
  1359.                     } catch (IOException e) {
  1360.                         crashReport(e);
  1361.                     }
  1362.  
  1363.                     manage(false, true);
  1364.                     return;
  1365.                 }
  1366.             }
  1367.             if (result == 1){
  1368.                 int res = JOptionPane.showOptionDialog(frame, "Delete from server\'s client selection or server-side selection?", "Manage Server", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[] {"Client", "Server"}, "Client");
  1369.                 if (res == 0){
  1370.                     if (client == null || !client.isConnected()){
  1371.                         reconnectFTP();
  1372.                     }
  1373.  
  1374.                     try {
  1375.                         client.changeWorkingDirectory("/DMSLauncher");
  1376.                     } catch (IOException e) {
  1377.                         crashReport(e);
  1378.                     }
  1379.  
  1380.                     try {
  1381.                         String sm = JOptionPane.showInputDialog(frame, "Input the file name to delete...", "Delete File - Client", JOptionPane.QUESTION_MESSAGE);
  1382.                        
  1383.                         if (sm == null){
  1384.                             manage(false, true);
  1385.                             return;
  1386.                         }
  1387.                        
  1388.                         List<String> list = new ArrayList<String>();
  1389.                         for (FTPFile ftp : client.listFiles()){
  1390.                             list.add(ftp.getName());
  1391.                         }
  1392.                        
  1393.                         if (!list.contains(sm)){
  1394.                             JOptionPane.showMessageDialog(frame, "Invalid file name. Please try again...", "Manage Server", JOptionPane.ERROR_MESSAGE);
  1395.                             manage(false, true);
  1396.                             return;
  1397.                         }
  1398.  
  1399.                         client.deleteFile(sm);
  1400.  
  1401.                         JOptionPane.showMessageDialog(frame, "Deleted " + sm + " from the server\'s client selection.", "Manage Server", JOptionPane.INFORMATION_MESSAGE);
  1402.  
  1403.  
  1404.                     } catch (HeadlessException e) {
  1405.                         crashReport(e);
  1406.                     } catch (IOException e) {
  1407.                         crashReport(e);
  1408.                     }
  1409.  
  1410.                     manage(false, true);
  1411.                     return;
  1412.                 }
  1413.                 if (res == 1){
  1414.                     if (client == null || !client.isConnected()){
  1415.                         reconnectFTP();
  1416.                     }
  1417.  
  1418.                     try {
  1419.                         client.changeWorkingDirectory("/mods");
  1420.                     } catch (IOException e) {
  1421.                         crashReport(e);
  1422.                     }
  1423.  
  1424.                     try {
  1425.                         String sm = JOptionPane.showInputDialog(frame, "Input the file name to delete...", "Delete File - Server", JOptionPane.QUESTION_MESSAGE);
  1426.  
  1427.                         if (sm == null){
  1428.                             manage(false, true);
  1429.                             return;
  1430.                         }
  1431.                        
  1432.                         List<String> list = new ArrayList<String>();
  1433.                         for (FTPFile ftp : client.listFiles()){
  1434.                             list.add(ftp.getName());
  1435.                         }
  1436.                        
  1437.                         if (!list.contains(sm)){
  1438.                             JOptionPane.showMessageDialog(frame, "Invalid file name. Please try again...", "Manage Server", JOptionPane.ERROR_MESSAGE);
  1439.                             manage(false, true);
  1440.                             return;
  1441.                         }
  1442.  
  1443.                         client.deleteFile(sm);
  1444.  
  1445.                         JOptionPane.showMessageDialog(frame, "Deleted " + sm + " from the server side selection.", "Manage Server", JOptionPane.INFORMATION_MESSAGE);
  1446.  
  1447.  
  1448.                     } catch (HeadlessException e) {
  1449.                         crashReport(e);
  1450.                     } catch (IOException e) {
  1451.                         crashReport(e);
  1452.                     }
  1453.  
  1454.                     manage(false, true);
  1455.                     return;
  1456.                 }
  1457.             }
  1458.  
  1459.  
  1460.         }else{
  1461.             manage(true, false);
  1462.             return;
  1463.         }
  1464.         return;
  1465.     }
  1466.  
  1467.     public static void disableFrame(){
  1468.         update.setEnabled(false);
  1469.         manage.setEnabled(false);
  1470.         resetWorkspace.setEnabled(false);
  1471.         ramAllocation.setEnabled(false);
  1472.     }
  1473.  
  1474.     public static void enableFrame(){
  1475.         update.setEnabled(true);
  1476.         manage.setEnabled(true);
  1477.         resetWorkspace.setEnabled(true);
  1478.         ramAllocation.setEnabled(true);
  1479.     }
  1480.  
  1481.     public static void install(){
  1482.  
  1483.         disableFrame();
  1484.         updatetext.setText("Installing modded minecraft...");
  1485.  
  1486.         console.append("\n\nStarting installation...\n\n");
  1487.         if (isWindows()){
  1488.             console.append("Downloading file from " + baseminecraftWindows + "...\n");
  1489.         }
  1490.         else{
  1491.             console.append("Downloading file from " + baseMinecraft + "...\n");
  1492.         }
  1493.  
  1494.  
  1495.  
  1496.         try {
  1497.             if (!isWindows()){
  1498.                 sfp_url = new URL(baseMinecraft);
  1499.                 sfp_file = new File(basepath, "DMSClientFiles.zip").getPath();
  1500.                 SwingWorker<String, String> worker8 = new SwingWorker<String, String>(){
  1501.  
  1502.                     protected String doInBackground(){
  1503.                         try {
  1504.                             saveFileProgress(sfp_url, sfp_file);
  1505.                            
  1506.                             install2();
  1507.                         } catch (IOException e) {
  1508.                             crashReport(e);
  1509.                         }
  1510.                         return null;
  1511.                     }
  1512.                 };
  1513.                 worker8.execute();
  1514.             }else{
  1515.                 sfp_url = new URL(baseminecraftWindows);
  1516.                 sfp_file = new File(basepath, "DMSClientFiles.zip").getPath();
  1517.                 SwingWorker<String, String> worker8 = new SwingWorker<String, String>(){
  1518.  
  1519.                     protected String doInBackground(){
  1520.                         try {
  1521.                             saveFileProgress(sfp_url, sfp_file);
  1522.                            
  1523.                             install2();
  1524.                         } catch (IOException e) {
  1525.                             crashReport(e);
  1526.                         }
  1527.                         return null;
  1528.                     }
  1529.                 };
  1530.                 worker8.execute();
  1531.             }
  1532.         } catch (MalformedURLException e) {
  1533.             crashReport(e);
  1534.         }
  1535.  
  1536.  
  1537.     }
  1538.    
  1539.     /*public static void auth(boolean wrong, boolean unable){
  1540.         JTextField usernameField = new JTextField(15);
  1541.         JPasswordField passField = new JPasswordField(15);
  1542.         JPanel panel = new JPanel();
  1543.         JLabel label;
  1544.         if (!unable)
  1545.             label = new JLabel((wrong ? "Invalid credentials. Please try again..." : "Log in to your Mojang account..."));
  1546.         else
  1547.             label = new JLabel("Unable to connect to authentication server!?");
  1548.         label.setFont(new Font("arial", Font.BOLD, 12));
  1549.         panel.add(label);
  1550.         panel.add(Box.createVerticalStrut(5));
  1551.         panel.add(new JLabel("Username/Email"));
  1552.         panel.add(usernameField);
  1553.         panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
  1554.         panel.add(new JLabel("Password"));
  1555.         panel.add(passField);
  1556.        
  1557.        
  1558.         int res = JOptionPane.showConfirmDialog(null, panel, "Minecraft Authentication", JOptionPane.OK_CANCEL_OPTION);
  1559.         if (res == JOptionPane.OK_OPTION){
  1560.  
  1561.             String pass = "";
  1562.             for (char c : passField.getPassword()){
  1563.                 pass += c;
  1564.             }
  1565.            
  1566.             JsonObject info = authMinecraft(usernameField.getText(), pass);
  1567.             if (info.containsKey("errorMessage")){
  1568.                 if (info.getString("errorMessage").contains("Invalid credentials")){
  1569.                     auth(true, false);
  1570.                     return;
  1571.                 }
  1572.             }
  1573.             else if (info.containsKey("accessToken")){
  1574.                
  1575.                 try {
  1576.  
  1577.                     JsonObject uuid = info.getJsonObject("selectedProfile");
  1578.                     List<String> lines = Files.readAllLines(new File(new File(basepath, "Game"), "launcher_profiles.json").toPath());
  1579.                     int size = lines.size();
  1580.                     for (int i = 0; i < size; i++){
  1581.                         if (lines.get(i).contains("DMSLAUNCHER-UUID")){
  1582.                            
  1583.                             lines.set(i, lines.get(i).replaceAll("DMSLAUNCHER-UUID", uuid.getString("id")));
  1584.                         }
  1585.                         if (lines.get(i).contains("DMSLAUNCHER-ACCESSTOKEN")){
  1586.                             lines.set(i, lines.get(i).replaceAll("DMSLAUNCHER-ACCESSTOKEN", info.getString("accessToken")));
  1587.                         }
  1588.                         if (lines.get(i).contains("DMSLAUNCHER-USERNAME")){
  1589.                             lines.set(i, lines.get(i).replaceAll("DMSLAUNCHER-USERNAME", uuid.getString("name")));
  1590.                         }
  1591.                         if (lines.get(i).contains("DMSLAUNCHER-EMAIL")){
  1592.                             lines.set(i, lines.get(i).replaceAll("DMSLAUNCHER-EMAIL", usernameField.getText()));
  1593.                         }
  1594.                         if (lines.get(i).contains("DMSLAUNCHER-CLIENTTOKEN")){
  1595.                             lines.set(i, lines.get(i).replaceAll("DMSLAUNCHER-CLIENTTOKEN", info.getString("clientToken")));
  1596.                         }
  1597.                     }
  1598.  
  1599.                    
  1600.                     clearFile(new File(new File(basepath, "Game"), "launcher_profiles.json"));
  1601.                     Files.write(new File(new File(basepath, "Game"), "launcher_profiles.json").toPath(), lines, StandardOpenOption.CREATE);
  1602.  
  1603.                 } catch (IOException e) {
  1604.                     crashReport(e);
  1605.                 }
  1606.                
  1607.             }else{
  1608.                 auth(false, true);
  1609.             }
  1610.            
  1611.            
  1612.         }else{
  1613.             auth(false, false);
  1614.             return;
  1615.         }
  1616.        
  1617.         return;
  1618.        
  1619.     }*/
  1620.  
  1621.     public static void install2(){
  1622.         pause(500L);
  1623.         console.append("\n\nUnzipping the zip file...\n\n");
  1624.         File dir = new File(basepath, "Game");
  1625.         if (!dir.exists()){
  1626.             dir.mkdir();
  1627.         }
  1628.         UnZipper uz = new UnZipper();
  1629.         try {
  1630.             uz.unzip(new File(basepath, "DMSClientFiles.zip").getPath(), new File(basepath, "Game").getPath());
  1631.         } catch (IOException e) {
  1632.             crashReport(e);
  1633.         }
  1634.  
  1635.         console.append("Editing launcher_profiles.json...\n\n");
  1636.  
  1637.  
  1638.        
  1639.         try {
  1640.  
  1641.  
  1642.             List<String> lines = Files.readAllLines(new File(new File(basepath, "Game"), "launcher_profiles.json").toPath());
  1643.             int index = -1;
  1644.             for (String s : lines){
  1645.                 index++;
  1646.                 if (s.contains("DMSLAUNCHER/GAMEDIRPATH")) break;
  1647.             }
  1648.  
  1649.             String k = lines.get(index);
  1650.             if (isWindows())
  1651.                
  1652.                 k = k.replace("DMSLAUNCHER/GAMEDIRPATH", new File(basepath, "Game").getPath().replaceAll(Matcher.quoteReplacement("\\"), Matcher.quoteReplacement("\\\\")));
  1653.             else
  1654.                 k = k.replaceAll("DMSLAUNCHER/GAMEDIRPATH", new File(basepath, "Game").getPath());
  1655.             lines.set(index, k);
  1656.             clearFile(new File(new File(basepath, "Game"), "launcher_profiles.json"));
  1657.             Files.write(new File(new File(basepath, "Game"), "launcher_profiles.json").toPath(), lines, StandardOpenOption.CREATE);
  1658.  
  1659.         } catch (IOException e) {
  1660.             crashReport(e);
  1661.         }
  1662.        
  1663.         /*console.append("Minecraft authentication is required...\n\n");
  1664.        
  1665.         auth(false, false);
  1666.        
  1667.         console.append("Used credentials to modify launcher_profiles.json\n\n");*/
  1668.  
  1669.         console.append("Creating run command file...\n\n");
  1670.         if (isWindows()){
  1671.  
  1672.             List<String> runcmd = new ArrayList<String>();
  1673.             String path = new File(basepath, "Game").getPath();
  1674.             runcmd.add("cd " + path);
  1675.             runcmd.add("MinecraftLauncher.exe --workDir " + path);
  1676.             runcmd.add("exit");
  1677.             try {
  1678.                 Files.write(new File(new File(basepath, "Game"), "runMC.bat").toPath(), runcmd, StandardOpenOption.CREATE);
  1679.             } catch (IOException e) {
  1680.                 crashReport(e);
  1681.             }
  1682.  
  1683.         }else{
  1684.  
  1685.             List<String> runcmd = new ArrayList<String>();
  1686.             String path = new File(basepath, "Game").getPath();
  1687.             runcmd.add("cd " + path);
  1688.             runcmd.add("chmod +x " + path + "/Minecraft.app/Contents/MacOS/launcher");
  1689.             runcmd.add("open Minecraft.app --args --workDir " + path);
  1690.             runcmd.add("exit");
  1691.             try {
  1692.                 Files.write(new File(new File(basepath, "Game"), "runMC.command").toPath(), runcmd, StandardOpenOption.CREATE);
  1693.             } catch (IOException e) {
  1694.                 crashReport(e);
  1695.             }
  1696.  
  1697.         }
  1698.  
  1699.  
  1700.         console.append("Minecraft modded installation complete!\n\n");
  1701.         update.setText("Play Minecraft");
  1702.  
  1703.         SwingWorker<String, String> worker4 = new SwingWorker<String, String>(){
  1704.  
  1705.             protected String doInBackground(){
  1706.                 checkUpdatesFromFTP();
  1707.                 return null;
  1708.             }
  1709.  
  1710.         };
  1711.        
  1712.         worker4.execute();
  1713.     }
  1714.  
  1715.     public static void ramAllocate(){
  1716.  
  1717.         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"};
  1718.  
  1719.         try {
  1720.  
  1721.  
  1722.             List<String> lines = Files.readAllLines(new File(new File(basepath, "Game"), "launcher_profiles.json").toPath());
  1723.             String j = "";
  1724.             String full = "";
  1725.             int i = -1;
  1726.             for (String s : lines){
  1727.                 i++;
  1728.                 if (s.contains("-Xmx")){
  1729.                     full = s;
  1730.                     j = s.split("-Xmx")[1].split("m")[0];              
  1731.                     break;
  1732.                 }
  1733.             }
  1734.  
  1735.             String s = (String) JOptionPane.showInputDialog(frame, "Select RAM dedication towards Minecraft...", "RAM Dedication", JOptionPane.QUESTION_MESSAGE, null, rams, j + " MB");
  1736.             lines.set(i, full.replace(j, s.replace(" MB", "")));
  1737.             clearFile(new File(new File(basepath, "Game"), "launcher_profiles.json"));
  1738.             Files.write(new File(new File(basepath, "Game"), "launcher_profiles.json").toPath(), lines, StandardOpenOption.WRITE);
  1739.             console.append("\n\nNow dedicating " + s + " of RAM to Minecraft.");
  1740.  
  1741.         } catch (IOException e) {
  1742.             crashReport(e);
  1743.         }
  1744.        
  1745.  
  1746.     }
  1747.  
  1748.     public static void loadFrame()
  1749.     {
  1750.         frame = new JFrame("Dilan's Modded Server - Launcher");
  1751.         frame.setMinimumSize(new Dimension(1000, 700));
  1752.         frame.setPreferredSize(new Dimension(1000, 700));
  1753.         frame.setMaximumSize(new Dimension(1000, 700));
  1754.         frame.setDefaultCloseOperation(3);
  1755.         frame.setLocationRelativeTo(null);
  1756.         frame.setResizable(false);
  1757.         Container pane = new Container();
  1758.         frame.setLayout(null);
  1759.         try
  1760.         {
  1761.             BufferedImage img = ImageIO.read(new URL(imageUrl));
  1762.             JLabel image = new JLabel(new ImageIcon(img));
  1763.             image.setBounds(0, -300, 1000, 700);
  1764.             pane.add(image);
  1765.         }
  1766.         catch (Exception ex)
  1767.         {
  1768.             crashReport(ex);
  1769.         }
  1770.         JLabel credits = new JLabel("Created by Dilan Nair - http://blockhead7360.com");
  1771.         credits.setFont(new Font("arial", 2, 12));
  1772.         credits.setBounds(new Rectangle(10, 75, 1000, 30));
  1773.         pane.add(credits);
  1774.  
  1775.         JLabel secret = new JLabel("© Manazir Industries");
  1776.         secret.setFont(new Font("arial", Font.PLAIN, 3));
  1777.         secret.setBounds(new Rectangle(1, 1, 40, 4));
  1778.         pane.add(secret);
  1779.  
  1780.         JLabel version = new JLabel("Program version: " + thisVer, 0);
  1781.         version.setFont(new Font(fontType, 1, 12));
  1782.         version.setBounds(new Rectangle(650, 70, 325, 30));
  1783.         pane.add(version);
  1784.  
  1785.         changelog = new JTextArea();
  1786.         changelog.setMargin(new Insets(20, 20, 20, 20));
  1787.         changelog.setBounds(new Rectangle(25, 100, 600, 478));
  1788.         changelog.setFont(new Font(fontType, 1, 18));
  1789.         changelog.setEditable(false);
  1790.         changelog.setText(changelogstr);
  1791.         changelog.setVisible(true);
  1792.         JScrollPane changelogpane = new JScrollPane(changelog);
  1793.         changelogpane.setBounds(new Rectangle(25, 100, 600, 478));
  1794.         pane.add(changelogpane);
  1795.  
  1796.         console.setMargin(new Insets(8, 8, 8, 8));
  1797.         console.setBounds(new Rectangle(650, 100, 325, 478));
  1798.         console.setFont(new Font(fontType, 2, 16));
  1799.         console.setEditable(false);
  1800.         console.setVisible(true);
  1801.         DefaultCaret caret = (DefaultCaret) console.getCaret();
  1802.         caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
  1803.         JScrollPane consolepane = new JScrollPane(console);
  1804.         consolepane.setBounds(new Rectangle(650, 100, 325, 478));
  1805.  
  1806.         pane.add(consolepane);
  1807.  
  1808.         if (!(new File(new File(basepath, "Game"), "launcher_profiles.json")).exists()){
  1809.             update = new JButton("Install and Play");
  1810.         }
  1811.         else update = new JButton("Play Minecraft");
  1812.  
  1813.         updatetext = new JLabel();
  1814.  
  1815.         updatetext.setText(" ");
  1816.         updatetext.setFont(new Font("arial", 1, 14));
  1817.         updatetext.setBounds(new Rectangle(520, 605, 500, 40));
  1818.         updatetext.setVisible(true);
  1819.         pane.add(updatetext);
  1820.  
  1821.         update.setBounds(new Rectangle(748, 600, 220, 50));
  1822.         update.setFont(new Font(fontType2, 0, 16));
  1823.         update.addActionListener(new ActionListener()
  1824.         {
  1825.             public void actionPerformed(ActionEvent e)
  1826.             {
  1827.                 /*if (DMSUpdater.clientPath.equals("BLANK"))
  1828.                 {
  1829.  
  1830.                     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");
  1831.                     if (i == 1) {
  1832.                         DMSUpdater.setPath();
  1833.                     }
  1834.                     return;
  1835.                 }*/
  1836.                 if (!(new File(new File(basepath, "Game"), "launcher_profiles.json")).exists()){
  1837.                     SwingWorker<String, String> worker5 = new SwingWorker<String, String>(){
  1838.  
  1839.                         protected String doInBackground(){
  1840.                             install();
  1841.                             return null;
  1842.                         }
  1843.  
  1844.                     };
  1845.                     worker5.execute();
  1846.                 }
  1847.                 else{
  1848.                     SwingWorker<String, String> worker4 = new SwingWorker<String, String>(){
  1849.  
  1850.                         protected String doInBackground(){
  1851.                             checkUpdatesFromFTP();
  1852.                             return null;
  1853.                         }
  1854.  
  1855.                     };
  1856.                    
  1857.                     worker4.execute();
  1858.                 }
  1859.             }
  1860.         });
  1861.         update.setVisible(true);
  1862.         pane.add(update);
  1863.  
  1864.         manage = new JButton("Manage Server");
  1865.         manage.setFont(new Font(fontType2, 0, 14));
  1866.         manage.setBounds(new Rectangle(10, 595, 220, 30));
  1867.         manage.addActionListener(new ActionListener(){
  1868.             public void actionPerformed(ActionEvent e){
  1869.                 manage(false, false);
  1870.             }
  1871.         });
  1872.  
  1873.         manage.setVisible(true);
  1874.         pane.add(manage);
  1875.  
  1876.  
  1877.         ramAllocation = new JButton("RAM Allocation");
  1878.         ramAllocation.setFont(new Font(fontType2, 0, 14));
  1879.         ramAllocation.setBounds(new Rectangle(240, 595, 220, 30));
  1880.         ramAllocation.addActionListener(new ActionListener(){
  1881.             public void actionPerformed(ActionEvent e){
  1882.                 SwingWorker<String, String> worker7 = new SwingWorker<String, String>(){
  1883.  
  1884.                     protected String doInBackground(){
  1885.                         ramAllocate();
  1886.                         return null;
  1887.                     }
  1888.  
  1889.                 };
  1890.                 worker7.execute();
  1891.             }
  1892.         });
  1893.         ramAllocation.setVisible(true);
  1894.         if (!(new File(new File(basepath, "Game"), "launcher_profiles.json")).exists()){
  1895.             ramAllocation.setEnabled(false);
  1896.         }else ramAllocation.setEnabled(true);
  1897.  
  1898.         pane.add(ramAllocation);
  1899.  
  1900.  
  1901.  
  1902.         resetWorkspace = new JButton("Reset Program Workspace");
  1903.         resetWorkspace.setFont(new Font(fontType2, 0, 14));
  1904.         resetWorkspace.setBounds(new Rectangle(10 + (220/2) + 5, 632, 220, 30));
  1905.         resetWorkspace.setVisible(true);
  1906.         resetWorkspace.addActionListener(new ActionListener()
  1907.         {
  1908.             public void actionPerformed(ActionEvent e)
  1909.             {
  1910.                 int x = JOptionPane.showOptionDialog(DMSLauncher.frame, "Are you sure you that you want to reset the program workspace?\nThis can cause problems if not done at the right time!\n\nYou will need to relaunch the program after this.", "Reset Program Workspace", 0, 3, null, new Object[] { "Reset!", "Cancel" }, "Cancel");
  1911.                 if (x == JOptionPane.YES_OPTION)
  1912.                 {
  1913.                     File f = new File(new JFileChooser().getFileSystemView().getDefaultDirectory(), "Documents" + DMSLauncher.splitKey + "DMSUpdater");
  1914.  
  1915.                     delete(f, false);
  1916.  
  1917.                     boolean pause = true;
  1918.                     long old = System.currentTimeMillis();
  1919.                     while (pause) {
  1920.                         if (System.currentTimeMillis() - old > 500L) {
  1921.                             pause = false;
  1922.                         }
  1923.                     }
  1924.                     DMSLauncher.frame.setVisible(false);
  1925.                     DMSLauncher.frame.dispose();
  1926.                     System.exit(0);
  1927.                 }
  1928.             }
  1929.         });
  1930.         pane.add(resetWorkspace);
  1931.  
  1932.         frame.setContentPane(pane);
  1933.         frame.setVisible(true);
  1934.     }
  1935.  
  1936.     public static void delete(File file, boolean deleteParentDir, String... except){
  1937.  
  1938.  
  1939.  
  1940.         for (File f : file.listFiles()){
  1941.             if (except.toString().contains(f.getName()));
  1942.             if (f.isDirectory()){
  1943.                 delete(f, true);
  1944.             }else{
  1945.                 f.delete();
  1946.             }
  1947.         }
  1948.  
  1949.         if (deleteParentDir){
  1950.             file.delete();
  1951.         }
  1952.     }
  1953.  
  1954. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement