From d5fd7b80b93d12b1beee17ee5ddfcc3ee426357f Mon Sep 17 00:00:00 2001 From: Leonardo Sarra Date: Sat, 19 Oct 2019 23:25:21 +0200 Subject: [PATCH] Reformat code --- src/chooser/DirChooser.java | 47 ++-- src/frame/CoreFrame.java | 118 ++++---- src/frame/FastFrame.java | 59 ++-- src/helpers/LauncherHelper.java | 417 ++++++++++++++-------------- src/launcher/Main.java | 133 +++++---- src/listeners/MyActionListener.java | 129 +++++---- src/listeners/MyMouseListener.java | 5 +- src/updater/CoreUpdater.java | 143 +++++----- src/updater/FastUpdater.java | 271 +++++++++--------- src/updater/UpdateNotifier.java | 112 ++++---- 10 files changed, 698 insertions(+), 736 deletions(-) diff --git a/src/chooser/DirChooser.java b/src/chooser/DirChooser.java index 130342d..f532ac6 100644 --- a/src/chooser/DirChooser.java +++ b/src/chooser/DirChooser.java @@ -13,21 +13,21 @@ import java.util.logging.Logger; public class DirChooser { - private JFileChooser f=new JFileChooser(); - private boolean cancel=false; - private boolean fired=false; - private static Logger log = Logger.getLogger( CoreUpdater.class.getName() ); - + private JFileChooser f = new JFileChooser(); + private boolean cancel = false; + private boolean fired = false; + private static Logger log = Logger.getLogger(CoreUpdater.class.getName()); + public void execute() { - //Functor pattern - LauncherHelper.LogSetup(log,false); + //Functor pattern + LauncherHelper.LogSetup(log, false); if (!fired) { boolean found = false; - fired = true; + fired = true; f.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); f.setDialogTitle("Select Guild Wars 2 directory"); //Workaround to add an icon in the JFileChooser dialog - JFrame icon= new JFrame(); + JFrame icon = new JFrame(); icon.setLocationRelativeTo(null); icon.setUndecorated(true); icon.setVisible(true); @@ -36,17 +36,17 @@ public void execute() { //Loop until "Cancel" is pressed or a valid directory is selected while (!found) { //int input = f.showDialog(icon, "Select"); - int input = f.showDialog(icon, "Select"); + int input = f.showDialog(icon, "Select"); if (input == JFileChooser.APPROVE_OPTION) { File file = f.getSelectedFile(); - + boolean check = DirChooser.validDir(file.getAbsolutePath()); if (check) { found = true; - log.log( Level.INFO,"Valid dir selected: "+file.getAbsolutePath()); + log.log(Level.INFO, "Valid dir selected: " + file.getAbsolutePath()); changePathProp(file.getAbsolutePath()); } else { - log.log( Level.INFO,"Invalid dir selected: "+file.getAbsolutePath()); + log.log(Level.INFO, "Invalid dir selected: " + file.getAbsolutePath()); JOptionPane.showMessageDialog(null, "Executable not found. Please select a valid directory", "Directory not valid", JOptionPane.ERROR_MESSAGE); } @@ -61,25 +61,30 @@ public void execute() { //Check if a given path is a valid path for GW2 - public static boolean validDir(String path){ - boolean result=new File(path+"\\Gw2-64.exe").exists(); + public static boolean validDir(String path) { + boolean result = new File(path + "\\Gw2-64.exe").exists(); return result; } + //setter and getter required for the functor pattern - public boolean getCancel() { return cancel;} + public boolean getCancel() { + return cancel; + } - public JFileChooser getJFileChooser() { return f;} + public JFileChooser getJFileChooser() { + return f; + } public boolean isFired() { return fired; } - public void changePathProp(String path){ + public void changePathProp(String path) { Properties prop = new Properties(); - LauncherHelper.loadProp(prop,"gw2_launcher.cfg"); - OutputStream output= null; + LauncherHelper.loadProp(prop, "gw2_launcher.cfg"); + OutputStream output = null; prop.put("path", path); - LauncherHelper.saveProp(prop,"gw2_launcher.cfg"); + LauncherHelper.saveProp(prop, "gw2_launcher.cfg"); } } diff --git a/src/frame/CoreFrame.java b/src/frame/CoreFrame.java index 9b17045..a00122f 100644 --- a/src/frame/CoreFrame.java +++ b/src/frame/CoreFrame.java @@ -1,67 +1,67 @@ package frame; import javax.swing.*; + import listeners.MyActionListener; import listeners.MyMouseListener; + import java.awt.*; import java.io.File; -public class CoreFrame extends JFrame{ +public class CoreFrame extends JFrame { /** - * - */ - private static final long serialVersionUID = 1L; - public JButton startwith= new JButton("Run with ArcDPS"); - private JButton startwithout= new JButton("Run only Gw2"); - public JLabel status = new JLabel ("- Updater is starting..."); - - private JLabel path= new JLabel("- Guild Wars 2 executable found"); - private JLabel arg=new JLabel("Arguments: "); - public JCheckBox autostart= new JCheckBox("Start with these settings each time (Fast-start)"); - public JCheckBox background= new JCheckBox("Hide the GUI when fast-start is enabled "); - public JTextField arg_string=new JTextField(20); - private JButton arc= new JButton("Install ArcDPS"); + * + */ + private static final long serialVersionUID = 1L; + public JButton startwith = new JButton("Run with ArcDPS"); + private JButton startwithout = new JButton("Run only Gw2"); + public JLabel status = new JLabel("- Updater is starting..."); + + private JLabel path = new JLabel("- Guild Wars 2 executable found"); + private JLabel arg = new JLabel("Arguments: "); + public JCheckBox autostart = new JCheckBox("Start with these settings each time (Fast-start)"); + public JCheckBox background = new JCheckBox("Hide the GUI when fast-start is enabled "); + public JTextField arg_string = new JTextField(20); + private JButton arc = new JButton("Install ArcDPS"); private String path_string; - private JButton me= new JButton("?"); + private JButton me = new JButton("?"); private String mode; + public CoreFrame(String dir) { + super("Guild Wars 2 Launcher"); + path_string = dir; - - public CoreFrame(String dir){ - super("Guild Wars 2 Launcher"); - path_string=dir; - this.setIconImage(Toolkit.getDefaultToolkit(). - getImage(CoreFrame.class.getResource("/gw2_64_1-1.png"))); - - + getImage(CoreFrame.class.getResource("/gw2_64_1-1.png"))); + + //Settings of the CoreFrame object - this.setSize(345,381); + this.setSize(345, 381); this.setVisible(true); - getContentPane().setLayout(new GridLayout(1,2)); + getContentPane().setLayout(new GridLayout(1, 2)); this.setResizable(true); this.setLocationRelativeTo(null); this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setResizable(false); - - + + //Default settings for some elements of the CoreFrame arg_string.setText("Example: -autologin, -noaudio, -bmp "); arg_string.setForeground(Color.GRAY); - status.setForeground(new Color(204,102,0)); - arg_string.setSize(3,5); - path.setForeground(new Color(0,102,51)); - + status.setForeground(new Color(204, 102, 0)); + arg_string.setSize(3, 5); + path.setForeground(new Color(0, 102, 51)); + //Setting up the action commands to be used by the listeners startwith.setActionCommand("with"); startwithout.setActionCommand("without"); background.setActionCommand("background"); arc.setActionCommand("arc"); //Create MyActionListener - MyActionListener mal= new MyActionListener(path_string,this); - + MyActionListener mal = new MyActionListener(path_string, this); + //Add Listeners arc.addActionListener(mal); startwith.addActionListener(mal); @@ -70,17 +70,17 @@ public CoreFrame(String dir){ arg_string.addMouseListener(new MyMouseListener(this)); //Creation of multiple JPanel - JPanel top =new JPanel (new GridLayout(2,1)); + JPanel top = new JPanel(new GridLayout(2, 1)); JPanel bot = new JPanel(new FlowLayout()); - JPanel mid= new JPanel(); - JPanel sel=new JPanel((new FlowLayout(FlowLayout.LEADING))); - JPanel sel2=new JPanel((new FlowLayout(FlowLayout.LEADING))); - JPanel install=new JPanel(new FlowLayout()); - JPanel settings=new JPanel(new GridLayout(5,1)); - JPanel main1 =new JPanel (new BorderLayout()); - JPanel about= new JPanel(new BorderLayout()); - - + JPanel mid = new JPanel(); + JPanel sel = new JPanel((new FlowLayout(FlowLayout.LEADING))); + JPanel sel2 = new JPanel((new FlowLayout(FlowLayout.LEADING))); + JPanel install = new JPanel(new FlowLayout()); + JPanel settings = new JPanel(new GridLayout(5, 1)); + JPanel main1 = new JPanel(new BorderLayout()); + JPanel about = new JPanel(new BorderLayout()); + + sel.add(status); sel2.add(path); install.add(arc); @@ -96,34 +96,30 @@ public CoreFrame(String dir){ bot.add(startwith); bot.add(startwithout); mid.add(about, BorderLayout.SOUTH); - about.add(me,BorderLayout.EAST); - + about.add(me, BorderLayout.EAST); + - main1.add(top,BorderLayout.NORTH); - main1.add(bot,BorderLayout.SOUTH); - main1.add(mid,BorderLayout.CENTER); + main1.add(top, BorderLayout.NORTH); + main1.add(bot, BorderLayout.SOUTH); + main1.add(mid, BorderLayout.CENTER); getContentPane().add(main1); - + //Creating borders install.setBorder(BorderFactory.createTitledBorder("Setup")); top.setBorder(BorderFactory.createTitledBorder("Status")); settings.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("Settings"), - BorderFactory.createEmptyBorder(5,5,5,5))); + BorderFactory.createEmptyBorder(5, 5, 5, 5))); me.setActionCommand("me"); me.addActionListener(mal); - - - - - + } - + public void setMode(String mode) { - this.mode=mode; + this.mode = mode; switch (mode) { case "none": arc.setText("Install ArcDPS"); @@ -142,9 +138,11 @@ public void setMode(String mode) { break; } } - - - public String getMode() { return mode;} + + + public String getMode() { + return mode; + } } diff --git a/src/frame/FastFrame.java b/src/frame/FastFrame.java index 6691f35..c29bb84 100644 --- a/src/frame/FastFrame.java +++ b/src/frame/FastFrame.java @@ -3,70 +3,64 @@ import javax.swing.*; - import java.awt.*; import java.io.File; @SuppressWarnings("serial") -public class FastFrame extends JFrame{ - - - private JButton startwith= new JButton("Run with ArcDPS"); - private JButton startwithout= new JButton("Run only GW2 "); - public JLabel status = new JLabel ("- Updater is starting..."); - private JLabel path= new JLabel("- Guild Wars 2 executable found"); - private JLabel arg=new JLabel("Arguments: "); - private JCheckBox autostart= new JCheckBox("Start with these settings each time"); - public JTextField arg_string=new JTextField(20); - private String path_string; - private JButton arc= new JButton("Install ArcDPS"); - private String mode; +public class FastFrame extends JFrame { - - + private JButton startwith = new JButton("Run with ArcDPS"); + private JButton startwithout = new JButton("Run only GW2 "); + public JLabel status = new JLabel("- Updater is starting..."); + private JLabel path = new JLabel("- Guild Wars 2 executable found"); + private JLabel arg = new JLabel("Arguments: "); + private JCheckBox autostart = new JCheckBox("Start with these settings each time"); + public JTextField arg_string = new JTextField(20); + private String path_string; + private JButton arc = new JButton("Install ArcDPS"); + private String mode; - - public FastFrame(String dir, boolean hide){ + public FastFrame(String dir, boolean hide) { super("Guild Wars 2 Launcher"); //Settings of the FastFrame object - + this.setIconImage(Toolkit.getDefaultToolkit(). - getImage(CoreFrame.class.getResource("/img/gw2_64_1-1.png"))); + getImage(CoreFrame.class.getResource("/img/gw2_64_1-1.png"))); this.setLocationRelativeTo(null); this.setDefaultCloseOperation(EXIT_ON_CLOSE); - this.setSize(310,160); + this.setSize(310, 160); this.setResizable(false); - + if (!hide) { - this.setVisible(true); //if background option is selected the frame will not show up + this.setVisible(true); //if background option is selected the frame will not show up } - + //JPanel setup - JPanel grid=new JPanel(new GridLayout(2,1)); + JPanel grid = new JPanel(new GridLayout(2, 1)); grid.setBorder(BorderFactory.createTitledBorder("Status")); - + //Color setup status.setForeground(Color.orange); path.setForeground(new Color(0, 102, 51)); - + //Add elements to the JPanel and FastFrame getContentPane().add(grid); grid.add(path); grid.add(status); + } + public String getMode() { + return mode; } - - public String getMode() { return mode;} - public void setMode(String mode) { - this.mode=mode; + this.mode = mode; switch (mode) { case "none": arc.setText("Install ArcDPS"); @@ -81,4 +75,5 @@ public void setMode(String mode) { arc.setText("Install ArcDPS"); break; } - }} + } +} diff --git a/src/helpers/LauncherHelper.java b/src/helpers/LauncherHelper.java index 7f3c382..7befd44 100644 --- a/src/helpers/LauncherHelper.java +++ b/src/helpers/LauncherHelper.java @@ -10,6 +10,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import java.util.logging.SimpleFormatter; + import org.apache.commons.codec.binary.Hex; import org.apache.commons.io.FileUtils; @@ -18,219 +19,217 @@ public class LauncherHelper { - private static final boolean DEBUG = false; - private static Logger log = Logger.getLogger( Main.class.getName() ); - - - public static void LogSetup(Logger log, boolean operations) { - if (DEBUG) { - FileHandler fh = null; - try { - if (operations) fh = new FileHandler("gw2_launcher_log_op.txt", true); - else fh = new FileHandler("gw2_launcher_log.txt", true); - } catch (SecurityException | IOException e1) { - e1.printStackTrace(); - } - SimpleFormatter sf = new SimpleFormatter(); - fh.setFormatter(sf); - log.addHandler(fh); - log.setLevel(Level.ALL); - } - } - - public static void closeLogHandlers(Logger log) { - if (DEBUG) { - for (Handler e: log.getHandlers()) { - e.close(); - } - } - } - - public static void cleanOldLogger() { - if (DEBUG) { - File fl=new File("gw2_launcher_log.txt"); - File fl2=new File("gw2_launcher_log_op.txt"); - if (fl.exists()) fl.delete(); - if (fl2.exists()) fl2.delete(); - } - - - } - - public static Properties loadProp(Properties prop, String path){ - InputStream input= null; - try { - input = new FileInputStream(path); - //Import settings - prop.load(input); - input.close(); - } catch (IOException e) { - e.printStackTrace(); - } - return prop; - } - - public static void saveProp(Properties prop, String path){ - try { - OutputStream output = new FileOutputStream("gw2_launcher.cfg"); - prop.store(output, "Config file for GW2 Launcher"); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public static synchronized void installArc(CoreFrame cf, String path) { - File dll=new File(path+"\\bin64\\d3d9.dll"); - try { - dll.createNewFile(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - LauncherHelper.downloadINI(cf,path); //.ini is required for the first install - LauncherHelper.updateDll(cf,path); //placeholder swapped with the last version of the dll - File backup = new File(path+"\\bin64\\d3d9_old.dll"); - if (backup.exists()) backup.delete(); - try { - Files.copy(dll.toPath(), backup.toPath()); - } catch (IOException e) { - e.printStackTrace(); - } + private static final boolean DEBUG = false; + private static Logger log = Logger.getLogger(Main.class.getName()); + + + public static void LogSetup(Logger log, boolean operations) { + if (DEBUG) { + FileHandler fh = null; + try { + if (operations) fh = new FileHandler("gw2_launcher_log_op.txt", true); + else fh = new FileHandler("gw2_launcher_log.txt", true); + } catch (SecurityException | IOException e1) { + e1.printStackTrace(); + } + SimpleFormatter sf = new SimpleFormatter(); + fh.setFormatter(sf); + log.addHandler(fh); + log.setLevel(Level.ALL); + } + } + + public static void closeLogHandlers(Logger log) { + if (DEBUG) { + for (Handler e : log.getHandlers()) { + e.close(); + } + } + } + + public static void cleanOldLogger() { + if (DEBUG) { + File fl = new File("gw2_launcher_log.txt"); + File fl2 = new File("gw2_launcher_log_op.txt"); + if (fl.exists()) fl.delete(); + if (fl2.exists()) fl2.delete(); + } + + + } + + public static Properties loadProp(Properties prop, String path) { + InputStream input = null; + try { + input = new FileInputStream(path); + //Import settings + prop.load(input); + input.close(); + } catch (IOException e) { + e.printStackTrace(); + } + return prop; + } + + public static void saveProp(Properties prop, String path) { + try { + OutputStream output = new FileOutputStream("gw2_launcher.cfg"); + prop.store(output, "Config file for GW2 Launcher"); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static synchronized void installArc(CoreFrame cf, String path) { + File dll = new File(path + "\\bin64\\d3d9.dll"); + try { + dll.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + } + LauncherHelper.downloadINI(cf, path); //.ini is required for the first install + LauncherHelper.updateDll(cf, path); //placeholder swapped with the last version of the dll + File backup = new File(path + "\\bin64\\d3d9_old.dll"); + if (backup.exists()) backup.delete(); + try { + Files.copy(dll.toPath(), backup.toPath()); + } catch (IOException e) { + e.printStackTrace(); + } //Change status and color of JLabel status //log.log( Level.INFO,"ArcDPS installed succesfully"); cf.setMode("arc_only"); - log.log( Level.INFO, "Arc Installed [InstallARC]"); - cf.status.setText("- ArcDPS was successfully installed "); - cf.status.setForeground(new Color(0,102,51)); - - - } - - public static synchronized void installLoaderReshade(String path) { - LauncherHelper.LogSetup(log,true); - log.log( Level.INFO, "Installing reshade support (loader) [installLoaderReshade]"); - File download = new File(path+"\\bin64\\d3d9_chainload.dll"); - if (!download.exists()) { - try { - FileUtils.copyURLToFile(new URL("http://www.deltaconnected.com/arcdps/reshade_loader/d3d9_chainload.dll"),download, 10000, 10000); - log.log( Level.INFO, "Everything went smooth [installBGDMwithArc]"); - - } catch (IOException e) { - // TODO Auto-generated catch block - log.log( Level.INFO, "IO/Zip Exception [installLoaderReshade]"); - e.printStackTrace(); - } - } - LauncherHelper.closeLogHandlers(log); - - } - - //Delete d3d9.dll of Arc - public static synchronized void removeArc(CoreFrame cf, String path) { - LauncherHelper.LogSetup(log,true); - log.log( Level.INFO, "Removing arc [removeArc]"); - File dll=new File(path+"\\bin64\\d3d9.dll"); - File dll_old=new File(path+"\\bin64\\d3d9_old.dll"); - File dll_disabled=new File(path+"\\bin64\\d3d9_disabled.dll"); - File reshadeLoader = new File(path+"\\bin64\\d3d9_chainload.dll"); - File btempl= new File(path+"\\bin64\\d3d9_arcdps_buildtemplates.dll"); - - if (dll.exists()) { - dll.delete(); - } - if (dll_old.exists()) { - dll_old.delete(); - } - if (dll_disabled.exists()) dll_disabled.delete(); - if (reshadeLoader.exists()) reshadeLoader.delete(); - if (btempl.exists()) btempl.delete(); - - log.log( Level.INFO, "Everything went smooth [removeArc]"); - cf.setMode("none"); - cf.status.setText("- ArcDPS not installed"); - cf.status.setForeground(Color.RED); - LauncherHelper.closeLogHandlers(log); - - - } - - public static synchronized void removeArcSetting(CoreFrame cf, String path) { - LauncherHelper.LogSetup(log,true); - log.log( Level.INFO, "Removing arc settings [removeArcSetting]"); - File ini= new File(path+"\\bin64\\arcdps.ini"); - File directory=new File(path+"\\addons\\arcdps"); - if (ini.exists()) ini.delete(); - - if (directory.exists()) { - try { - FileUtils.deleteDirectory(directory); - } catch (IOException e) { - log.log( Level.SEVERE, "Error while removing directory [removeArcSetting]"); - e.printStackTrace(); - } - } - - - log.log( Level.INFO, "Everything went smooth [removeArcSetting]"); - LauncherHelper.closeLogHandlers(log); - - - } - - public static synchronized void removeReshadeLoader(String path) { - File reshadeLoader = new File(path+"\\bin64\\d3d9_chainload.dll"); - if (reshadeLoader.exists()) reshadeLoader.delete(); - - - } - - public static synchronized void downloadINI(CoreFrame cf, String path){ - LauncherHelper.LogSetup(log,true); - File ini=new File(path+"\\bin64\\arcdps.ini"); - if (ini.exists()) ini.delete(); //Delete existing ini file to prevent an exception - log.log( Level.INFO,"Downloading configuration file"); - try { - //Download default configuration from the website - FileUtils.copyURLToFile(new URL("http://www.deltaconnected.com/arcdps/x64/arcdps.ini"),ini, 10000, 10000); - log.log( Level.INFO,"archdps.ini installed successfully"); - //Exceptions if something goes wrong (Connection/IO) - } catch (IOException e) { - e.printStackTrace(); - cf.status.setText("- Cannot connect to the update server"); + log.log(Level.INFO, "Arc Installed [InstallARC]"); + cf.status.setText("- ArcDPS was successfully installed "); + cf.status.setForeground(new Color(0, 102, 51)); + + + } + + public static synchronized void installLoaderReshade(String path) { + LauncherHelper.LogSetup(log, true); + log.log(Level.INFO, "Installing reshade support (loader) [installLoaderReshade]"); + File download = new File(path + "\\bin64\\d3d9_chainload.dll"); + if (!download.exists()) { + try { + FileUtils.copyURLToFile(new URL("http://www.deltaconnected.com/arcdps/reshade_loader/d3d9_chainload.dll"), download, 10000, 10000); + log.log(Level.INFO, "Everything went smooth [installBGDMwithArc]"); + + } catch (IOException e) { + log.log(Level.INFO, "IO/Zip Exception [installLoaderReshade]"); + e.printStackTrace(); + } + } + LauncherHelper.closeLogHandlers(log); + + } + + //Delete d3d9.dll of Arc + public static synchronized void removeArc(CoreFrame cf, String path) { + LauncherHelper.LogSetup(log, true); + log.log(Level.INFO, "Removing arc [removeArc]"); + File dll = new File(path + "\\bin64\\d3d9.dll"); + File dll_old = new File(path + "\\bin64\\d3d9_old.dll"); + File dll_disabled = new File(path + "\\bin64\\d3d9_disabled.dll"); + File reshadeLoader = new File(path + "\\bin64\\d3d9_chainload.dll"); + File btempl = new File(path + "\\bin64\\d3d9_arcdps_buildtemplates.dll"); + + if (dll.exists()) { + dll.delete(); + } + if (dll_old.exists()) { + dll_old.delete(); + } + if (dll_disabled.exists()) dll_disabled.delete(); + if (reshadeLoader.exists()) reshadeLoader.delete(); + if (btempl.exists()) btempl.delete(); + + log.log(Level.INFO, "Everything went smooth [removeArc]"); + cf.setMode("none"); + cf.status.setText("- ArcDPS not installed"); + cf.status.setForeground(Color.RED); + LauncherHelper.closeLogHandlers(log); + + + } + + public static synchronized void removeArcSetting(CoreFrame cf, String path) { + LauncherHelper.LogSetup(log, true); + log.log(Level.INFO, "Removing arc settings [removeArcSetting]"); + File ini = new File(path + "\\bin64\\arcdps.ini"); + File directory = new File(path + "\\addons\\arcdps"); + if (ini.exists()) ini.delete(); + + if (directory.exists()) { + try { + FileUtils.deleteDirectory(directory); + } catch (IOException e) { + log.log(Level.SEVERE, "Error while removing directory [removeArcSetting]"); + e.printStackTrace(); + } + } + + + log.log(Level.INFO, "Everything went smooth [removeArcSetting]"); + LauncherHelper.closeLogHandlers(log); + + + } + + public static synchronized void removeReshadeLoader(String path) { + File reshadeLoader = new File(path + "\\bin64\\d3d9_chainload.dll"); + if (reshadeLoader.exists()) reshadeLoader.delete(); + + + } + + public static synchronized void downloadINI(CoreFrame cf, String path) { + LauncherHelper.LogSetup(log, true); + File ini = new File(path + "\\bin64\\arcdps.ini"); + if (ini.exists()) ini.delete(); //Delete existing ini file to prevent an exception + log.log(Level.INFO, "Downloading configuration file"); + try { + //Download default configuration from the website + FileUtils.copyURLToFile(new URL("http://www.deltaconnected.com/arcdps/x64/arcdps.ini"), ini, 10000, 10000); + log.log(Level.INFO, "archdps.ini installed successfully"); + //Exceptions if something goes wrong (Connection/IO) + } catch (IOException e) { + e.printStackTrace(); + cf.status.setText("- Cannot connect to the update server"); cf.status.setForeground(Color.RED); - log.log( Level.SEVERE,"IOException when downloading ini"); - } - LauncherHelper.closeLogHandlers(log); + log.log(Level.SEVERE, "IOException when downloading ini"); + } + LauncherHelper.closeLogHandlers(log); } - - //used to update arcDPS - public static synchronized void updateDll(CoreFrame cf, String path){ - LauncherHelper.LogSetup(log,true); - File dll=new File(path+"\\bin64\\d3d9.dll"); + + //used to update arcDPS + public static synchronized void updateDll(CoreFrame cf, String path) { + LauncherHelper.LogSetup(log, true); + File dll = new File(path + "\\bin64\\d3d9.dll"); FileInputStream fis = null; String md5_new; String md5_old; try { - //Generate md5 file of the dll installed in the system using some external libraries + //Generate md5 file of the dll installed in the system using some external libraries fis = new FileInputStream(dll); byte[] data = org.apache.commons.codec.digest.DigestUtils.md5(fis); char[] md5Chars = Hex.encodeHex(data); md5_old = String.valueOf(md5Chars); //md5 of the dll fis.close(); - File md5_download= new File(path+"\\bin64\\arcdps.dll.md5sum"); //Path of the md5 that is going to be downloaded + File md5_download = new File(path + "\\bin64\\arcdps.dll.md5sum"); //Path of the md5 that is going to be downloaded //Download the md5 of the last version of ArcDPS from the website - FileUtils.copyURLToFile(new URL("http://www.deltaconnected.com/arcdps/x64/d3d9.dll.md5sum"),md5_download, 10000, 10000); + FileUtils.copyURLToFile(new URL("http://www.deltaconnected.com/arcdps/x64/d3d9.dll.md5sum"), md5_download, 10000, 10000); //Keep the relevant part of the md5 - log.log( Level.INFO,"Md5 downloaded"); - md5_new=FileUtils.readFileToString(md5_download,"UTF-8").substring(0, FileUtils.readFileToString(md5_download,"UTF-8").indexOf(" ")); - log.log( Level.INFO,"Old md5: "+md5_old); - log.log( Level.INFO,"New md5: "+md5_new); - - if(!md5_old.equals(md5_new)){ //Different checksum means that a new version must be downloaded - log.log( Level.INFO,"New version available"); - File backup = new File(path+"\\bin64\\d3d9_old.dll"); + log.log(Level.INFO, "Md5 downloaded"); + md5_new = FileUtils.readFileToString(md5_download, "UTF-8").substring(0, FileUtils.readFileToString(md5_download, "UTF-8").indexOf(" ")); + log.log(Level.INFO, "Old md5: " + md5_old); + log.log(Level.INFO, "New md5: " + md5_new); + + if (!md5_old.equals(md5_new)) { //Different checksum means that a new version must be downloaded + log.log(Level.INFO, "New version available"); + File backup = new File(path + "\\bin64\\d3d9_old.dll"); if (backup.exists()) backup.delete(); //delete old backup to prevent an exception //Create backup copy Files.copy(dll.toPath(), backup.toPath()); @@ -239,46 +238,36 @@ public static synchronized void updateDll(CoreFrame cf, String path){ //Change text of the JLabel status cf.status.setText("- Downloading new version..."); //Download new dll - FileUtils.copyURLToFile(new URL("http://www.deltaconnected.com/arcdps/x64/d3d9.dll"),dll, 10000, 10000); + FileUtils.copyURLToFile(new URL("http://www.deltaconnected.com/arcdps/x64/d3d9.dll"), dll, 10000, 10000); cf.status.setText("- ArcDPS updated"); - cf.status.setForeground(new Color(0,102,51)); - File btempl=new File(path+"\\bin64\\d3d9_arcdps_buildtemplates.dll"); + cf.status.setForeground(new Color(0, 102, 51)); + File btempl = new File(path + "\\bin64\\d3d9_arcdps_buildtemplates.dll"); if (btempl.exists()) btempl.delete(); - } - - else { //Same checksum means that the user has the most recent version of ArcDPS - log.log( Level.INFO,"ArcDPS already updated"); + } else { //Same checksum means that the user has the most recent version of ArcDPS + log.log(Level.INFO, "ArcDPS already updated"); cf.status.setText("- ArcDPS is already updated"); cf.status.setForeground(new Color(0, 102, 51)); } //Delete downloaded md5 - log.log( Level.INFO,"Removing downloaded md5"); + log.log(Level.INFO, "Removing downloaded md5"); md5_download.delete(); - - - //Exceptions if something goes wrong (Connection/IO) + //Exceptions if something goes wrong (Connection/IO) } catch (FileNotFoundException e) { e.printStackTrace(); cf.status.setText(" Cannot connect to the update server"); cf.status.setForeground(Color.RED); - log.log( Level.SEVERE,"FileNotFoundException when downloading dll"); + log.log(Level.SEVERE, "FileNotFoundException when downloading dll"); } catch (IOException e) { e.printStackTrace(); cf.status.setText(" Cannot connect to the update server"); cf.status.setForeground(Color.RED); - log.log( Level.SEVERE,"IOException when downloading dll"); + log.log(Level.SEVERE, "IOException when downloading dll"); } LauncherHelper.closeLogHandlers(log); LauncherHelper.installLoaderReshade(path); } - - - - - - } diff --git a/src/launcher/Main.java b/src/launcher/Main.java index 749c1eb..0f776b8 100644 --- a/src/launcher/Main.java +++ b/src/launcher/Main.java @@ -16,19 +16,19 @@ import javax.swing.UnsupportedLookAndFeelException; public class Main { - private static final String username="LithiumSR"; - private static final String repoName="gw2_launcher"; - private static final String version="1.0.7"; + private static final String username = "LithiumSR"; + private static final String repoName = "gw2_launcher"; + private static final String version = "1.0.7"; public static void main(String[] args) throws InterruptedException { - - //Create Logger - Logger log = Logger.getLogger( Main.class.getName() ); - LauncherHelper.cleanOldLogger(); - LauncherHelper.LogSetup(log,false); - - //Create configuration file if it doesn't exist already - File config= new File("gw2_launcher.cfg"); + + //Create Logger + Logger log = Logger.getLogger(Main.class.getName()); + LauncherHelper.cleanOldLogger(); + LauncherHelper.LogSetup(log, false); + + //Create configuration file if it doesn't exist already + File config = new File("gw2_launcher.cfg"); if (!config.exists()) try { config.createNewFile(); } catch (IOException e) { @@ -36,96 +36,95 @@ public static void main(String[] args) throws InterruptedException { } Properties prop = new Properties(); - LauncherHelper.loadProp(prop,"gw2_launcher.cfg"); + LauncherHelper.loadProp(prop, "gw2_launcher.cfg"); //Change look and feel try { - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - } catch (ClassNotFoundException | InstantiationException | IllegalAccessException - | UnsupportedLookAndFeelException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - Thread pj_updater= new Thread(new UpdateNotifier(version,repoName,username)); + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException + | UnsupportedLookAndFeelException e) { + e.printStackTrace(); + } + Thread pj_updater = new Thread(new UpdateNotifier(version, repoName, username)); pj_updater.start(); - if ((prop.getProperty("faststart","no").equals("yes"))) { - pj_updater.join(); + if ((prop.getProperty("faststart", "no").equals("yes"))) { + pj_updater.join(); } - String currentDir=new File(".").getAbsolutePath(); + String currentDir = new File(".").getAbsolutePath(); //If the path contained in the settings is valid and faststart is not enabled use CoreFrame - if (DirChooser.validDir(prop.getProperty("path")) && !prop.getProperty("faststart","no").equals("yes")) { - log.log( Level.INFO, "Found path, no autostart"); + if (DirChooser.validDir(prop.getProperty("path")) && !prop.getProperty("faststart", "no").equals("yes")) { + log.log(Level.INFO, "Found path, no autostart"); CoreFrame gui = new CoreFrame(prop.getProperty("path")); //Import saved args to the CoreFrame - gui.arg_string.setText(prop.getProperty("args","Example: -autologin, -noaudio, -bmp ")); - if(gui.arg_string.getText().equals("")) gui.arg_string.setText("Example: -autologin, -noaudio, -bmp "); - gui.setMode(prop.getProperty("mode","none")); + gui.arg_string.setText(prop.getProperty("args", "Example: -autologin, -noaudio, -bmp ")); + if (gui.arg_string.getText().equals("")) gui.arg_string.setText("Example: -autologin, -noaudio, -bmp "); + gui.setMode(prop.getProperty("mode", "none")); LauncherHelper.closeLogHandlers(log); - if (!prop.getProperty("mode","none").equals("none")) { - Thread t1 = new Thread(new CoreUpdater(gui, prop.getProperty("path"))); - t1.start(); + if (!prop.getProperty("mode", "none").equals("none")) { + Thread t1 = new Thread(new CoreUpdater(gui, prop.getProperty("path"))); + t1.start(); } } //Else if the path contained in the settings is valid and faststart is enabled use FastFrame - else if (DirChooser.validDir(prop.getProperty("path")) && prop.getProperty("faststart","no").equals("yes")){ - log.log( Level.INFO, "Found path, yes autostart"); - FastFrame gui=null; - - //Check if background option was previously selected. FastFrame changes accordingly - if(prop.getProperty("background","no").equals("yes")) { - log.log( Level.INFO, "Hide Fastframe is selected"); - gui=new FastFrame(prop.getProperty("path"),true); - gui.setMode(prop.getProperty("mode")); - } - else { - log.log( Level.INFO, "Hide Fastframe is not selected"); - gui=new FastFrame(prop.getProperty("path"),false); - gui.setMode(prop.getProperty("mode")); + else if (DirChooser.validDir(prop.getProperty("path")) && prop.getProperty("faststart", "no").equals("yes")) { + log.log(Level.INFO, "Found path, yes autostart"); + FastFrame gui = null; + + //Check if background option was previously selected. FastFrame changes accordingly + if (prop.getProperty("background", "no").equals("yes")) { + log.log(Level.INFO, "Hide Fastframe is selected"); + gui = new FastFrame(prop.getProperty("path"), true); + gui.setMode(prop.getProperty("mode")); + } else { + log.log(Level.INFO, "Hide Fastframe is not selected"); + gui = new FastFrame(prop.getProperty("path"), false); + gui.setMode(prop.getProperty("mode")); } - //Import saved args to the CoreFrame - gui.arg_string.setText(prop.getProperty("args","Example: -autologin, -noaudio, -bmp")); - if(gui.arg_string.getText().equals("")) gui.arg_string.setText("Example: -autologin, -noaudio, -bmp "); + //Import saved args to the CoreFrame + gui.arg_string.setText(prop.getProperty("args", "Example: -autologin, -noaudio, -bmp")); + if (gui.arg_string.getText().equals("")) gui.arg_string.setText("Example: -autologin, -noaudio, -bmp "); //Updater thread is created. If ("type".equals("yes") is yes it means that the preferred option for execution is "Run with ArcDPS" //otherwise is "Run only GW2" ("type".equals("no"). //Type is one of the settings contained in gw2_launcher.cfg LauncherHelper.closeLogHandlers(log); - Thread t1=null; - if (prop.getProperty("useAddons","yes").equals("yes")) { t1= new Thread(new FastUpdater(gui,prop.getProperty("path"),true));} - else t1= new Thread(new FastUpdater(gui,prop.getProperty("path"),false)); + Thread t1 = null; + if (prop.getProperty("useAddons", "yes").equals("yes")) { + t1 = new Thread(new FastUpdater(gui, prop.getProperty("path"), true)); + } else t1 = new Thread(new FastUpdater(gui, prop.getProperty("path"), false)); t1.start(); } //Else If currentDir is valid we don't need to use the JFileChooser - else if (DirChooser.validDir(currentDir)){ - log.log( Level.INFO, "Path not found, no autostart, but valid current dir"); - LauncherHelper.removeReshadeLoader(currentDir); + else if (DirChooser.validDir(currentDir)) { + log.log(Level.INFO, "Path not found, no autostart, but valid current dir"); + LauncherHelper.removeReshadeLoader(currentDir); CoreFrame gui = new CoreFrame(currentDir); - gui.setMode(prop.getProperty("mode","none")); - log.log(Level.INFO, "mode: "+prop.getProperty("mode")); + gui.setMode(prop.getProperty("mode", "none")); + log.log(Level.INFO, "mode: " + prop.getProperty("mode")); LauncherHelper.closeLogHandlers(log); - if (!prop.getProperty("mode","none").equals("none")) { - Thread t1 = new Thread(new CoreUpdater(gui, currentDir)); + if (!prop.getProperty("mode", "none").equals("none")) { + Thread t1 = new Thread(new CoreUpdater(gui, currentDir)); t1.start(); } - + } //JFileChooser is needed else { - log.log( Level.INFO, "FileChooser needed"); - LauncherHelper.closeLogHandlers(log); - DirChooser dir=new DirChooser(); + log.log(Level.INFO, "FileChooser needed"); + LauncherHelper.closeLogHandlers(log); + DirChooser dir = new DirChooser(); dir.execute(); - if(!dir.getCancel() && dir.isFired()) { - if (dir.getJFileChooser().getSelectedFile()==null) System.exit(0); - LauncherHelper.removeReshadeLoader(dir.getJFileChooser().getSelectedFile().getAbsolutePath()); + if (!dir.getCancel() && dir.isFired()) { + if (dir.getJFileChooser().getSelectedFile() == null) System.exit(0); + LauncherHelper.removeReshadeLoader(dir.getJFileChooser().getSelectedFile().getAbsolutePath()); CoreFrame gui = new CoreFrame(dir.getJFileChooser().getSelectedFile().getAbsolutePath()); - gui.setMode(prop.getProperty("mode","none")); - if (!prop.getProperty("mode","none").equals("none")) { - Thread t1 = new Thread(new CoreUpdater(gui, dir.getJFileChooser().getSelectedFile().getAbsolutePath())); + gui.setMode(prop.getProperty("mode", "none")); + if (!prop.getProperty("mode", "none").equals("none")) { + Thread t1 = new Thread(new CoreUpdater(gui, dir.getJFileChooser().getSelectedFile().getAbsolutePath())); t1.start(); } } diff --git a/src/listeners/MyActionListener.java b/src/listeners/MyActionListener.java index 1d5abd1..4e62615 100644 --- a/src/listeners/MyActionListener.java +++ b/src/listeners/MyActionListener.java @@ -3,6 +3,7 @@ import frame.CoreFrame; import helpers.LauncherHelper; import updater.CoreUpdater; + import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -15,61 +16,60 @@ public class MyActionListener implements ActionListener { private String path; private CoreFrame cf; - + //Constructor - public MyActionListener(String path, CoreFrame cf){ - this.path=path; - this.cf=cf; + public MyActionListener(String path, CoreFrame cf) { + this.path = path; + this.cf = cf; } public void actionPerformed(ActionEvent e) { - //if background checkbox is selected the autostart one will be selected automatically - if(e.getActionCommand().equals("arc")) { - - if(cf.getMode().equals("none")) { - LauncherHelper.installArc(cf, path); - saveConfig(true); - cf.startwith.setEnabled(true); - cf.autostart.setEnabled(true); - cf.background.setEnabled(true); - cf.startwith.setEnabled(true); - } - else { - int dialogButton=JOptionPane.YES_NO_OPTION; - int dialogResult=JOptionPane.showConfirmDialog(null,"Would you like to remove ArcDPS' settings files too? \n" - + "If you are going to install ArcDPS in the future press 'No'. ","Remove settings?",dialogButton); - if (dialogResult==JOptionPane.YES_OPTION){ - LauncherHelper.removeArcSetting(cf, path); - } - LauncherHelper.removeArc(cf, path); - saveConfig(true); - cf.startwith.setEnabled(false); - cf.autostart.setEnabled(false); - cf.background.setEnabled(false); - } - - - } - - if(e.getActionCommand().equals("background")){ - cf.autostart.setSelected(true); - - } - - //Show up "About me" Frame - if (e.getActionCommand().equals("me")){ - JOptionPane.showMessageDialog(null,"Check https://github.com/lithiumSR to stay updated", "About", JOptionPane.INFORMATION_MESSAGE); + //if background checkbox is selected the autostart one will be selected automatically + if (e.getActionCommand().equals("arc")) { + + if (cf.getMode().equals("none")) { + LauncherHelper.installArc(cf, path); + saveConfig(true); + cf.startwith.setEnabled(true); + cf.autostart.setEnabled(true); + cf.background.setEnabled(true); + cf.startwith.setEnabled(true); + } else { + int dialogButton = JOptionPane.YES_NO_OPTION; + int dialogResult = JOptionPane.showConfirmDialog(null, "Would you like to remove ArcDPS' settings files too? \n" + + "If you are going to install ArcDPS in the future press 'No'. ", "Remove settings?", dialogButton); + if (dialogResult == JOptionPane.YES_OPTION) { + LauncherHelper.removeArcSetting(cf, path); + } + LauncherHelper.removeArc(cf, path); + saveConfig(true); + cf.startwith.setEnabled(false); + cf.autostart.setEnabled(false); + cf.background.setEnabled(false); + } + + } - + + if (e.getActionCommand().equals("background")) { + cf.autostart.setSelected(true); + + } + + //Show up "About me" Frame + if (e.getActionCommand().equals("me")) { + JOptionPane.showMessageDialog(null, "Check https://github.com/lithiumSR to stay updated", "About", JOptionPane.INFORMATION_MESSAGE); + } + //"Run with archdps" button is pressed - if (e.getActionCommand().equals("with")){ + if (e.getActionCommand().equals("with")) { saveConfig(true); runGW2(); } - + //"Run only GW2" button is pressed - if (e.getActionCommand().equals("without")){ + if (e.getActionCommand().equals("without")) { saveConfig(false); //disable arcdps dll CoreUpdater.runWithoutDPS(path); @@ -80,40 +80,39 @@ public void actionPerformed(ActionEvent e) { } //Used to the save settings in "gw2_launcher.cfg" - private void saveConfig(boolean useAddons){ + private void saveConfig(boolean useAddons) { Properties prop = new Properties(); - OutputStream output= null; - prop.put("path",path); - LauncherHelper.loadProp(prop,"gw2_launcher.cfg"); - + OutputStream output = null; + prop.put("path", path); + LauncherHelper.loadProp(prop, "gw2_launcher.cfg"); + if (cf.autostart.isSelected()) { prop.put("faststart", "yes"); - } - else prop.put("faststart","no"); + } else prop.put("faststart", "no"); - if (useAddons) prop.put("useAddons","yes"); - else prop.put("useAddons","no"); + if (useAddons) prop.put("useAddons", "yes"); + else prop.put("useAddons", "no"); - if(cf.background.isSelected()) prop.put("background", "yes"); + if (cf.background.isSelected()) prop.put("background", "yes"); else prop.put("background", "no"); - + prop.put("mode", cf.getMode()); - - if(cf.arg_string.getText().contains("Example")) prop.put("args",""); - else prop.put("args",cf.arg_string.getText()); - LauncherHelper.saveProp(prop,"gw2_launcher.cfg"); + + if (cf.arg_string.getText().contains("Example")) prop.put("args", ""); + else prop.put("args", cf.arg_string.getText()); + LauncherHelper.saveProp(prop, "gw2_launcher.cfg"); } - + @SuppressWarnings("unused") //Create process Gw2-64.exe with some arguments - private void runGW2(){ + private void runGW2() { try { - if(cf.arg_string.getText().contains("Example")) cf.arg_string.setText(""); + if (cf.arg_string.getText().contains("Example")) cf.arg_string.setText(""); cf.dispose(); - List list= Arrays.asList(cf.arg_string.getText().split("\\s*,\\s*")); - LinkedList exe= new LinkedList<>(list); + List list = Arrays.asList(cf.arg_string.getText().split("\\s*,\\s*")); + LinkedList exe = new LinkedList<>(list); System.out.println(list); - exe.addFirst(path+"\\Gw2-64.exe"); + exe.addFirst(path + "\\Gw2-64.exe"); Process process = new ProcessBuilder(exe).start(); System.exit(0); } catch (IOException e1) { diff --git a/src/listeners/MyMouseListener.java b/src/listeners/MyMouseListener.java index 32b1d22..1c0ff71 100644 --- a/src/listeners/MyMouseListener.java +++ b/src/listeners/MyMouseListener.java @@ -8,7 +8,10 @@ public class MyMouseListener implements MouseListener { public CoreFrame cf; - public MyMouseListener(CoreFrame cf){ this.cf=cf;} + + public MyMouseListener(CoreFrame cf) { + this.cf = cf; + } //Used to reset the JTextField when clicked public void mouseClicked(MouseEvent e) { diff --git a/src/updater/CoreUpdater.java b/src/updater/CoreUpdater.java index d579098..0f1ba4c 100644 --- a/src/updater/CoreUpdater.java +++ b/src/updater/CoreUpdater.java @@ -2,6 +2,7 @@ import helpers.LauncherHelper; import frame.CoreFrame; + import javax.swing.*; import java.awt.*; import java.io.File; @@ -15,132 +16,120 @@ public class CoreUpdater implements Runnable { private CoreFrame cf; private String path; - private File dll; - private File old_dll; - private File disabled_dll; - private static Logger log = Logger.getLogger( CoreUpdater.class.getName() ); - - - public CoreUpdater(CoreFrame cf, String path){ - this.cf=cf; - this.path=path; - dll=new File(path+"\\bin64\\d3d9.dll"); //dll of ArcDPS or BGDM - old_dll= new File(path+"\\bin64\\d3d9_old.dll"); //backup dll of ArcDPS or BGDM - disabled_dll= new File(path+"\\bin64\\d3d9_disabled.dll"); //disabled dll of ArcDPS or BGDM - LauncherHelper.LogSetup(log,false); + private File dll; + private File old_dll; + private File disabled_dll; + private static Logger log = Logger.getLogger(CoreUpdater.class.getName()); + + + public CoreUpdater(CoreFrame cf, String path) { + this.cf = cf; + this.path = path; + dll = new File(path + "\\bin64\\d3d9.dll"); //dll of ArcDPS or BGDM + old_dll = new File(path + "\\bin64\\d3d9_old.dll"); //backup dll of ArcDPS or BGDM + disabled_dll = new File(path + "\\bin64\\d3d9_disabled.dll"); //disabled dll of ArcDPS or BGDM + LauncherHelper.LogSetup(log, false); } - + //run() from interface "Runnable" public void run() { - boolean check=dll.exists(); - File ini=new File(path+"\\bin64\\arcdps.ini"); //settings file of archdps. Needed to make ArcDPS works + boolean check = dll.exists(); + File ini = new File(path + "\\bin64\\arcdps.ini"); //settings file of archdps. Needed to make ArcDPS works - if (check){ + if (check) { //System.out.println("d3d9.dll exists"); - changeConfig("arc_only"); - log.log( Level.INFO,"d3d9.dll found"); - LauncherHelper.updateDll(cf,path); //if d3d9.dll exists check if update is needed + changeConfig("arc_only"); + log.log(Level.INFO, "d3d9.dll found"); + LauncherHelper.updateDll(cf, path); //if d3d9.dll exists check if update is needed - } - - else if (!check && disabled_dll.exists()){ - //If d3d9.dll is not detected but a disabled dll is found. Rename "disabled_d3d9.dll" and check for an update + } else if (!check && disabled_dll.exists()) { + //If d3d9.dll is not detected but a disabled dll is found. Rename "disabled_d3d9.dll" and check for an update try { - log.log( Level.INFO,"d3d9.dll not found but d3d9_disabled exists"); + log.log(Level.INFO, "d3d9.dll not found but d3d9_disabled exists"); Files.copy(disabled_dll.toPath(), dll.toPath()); disabled_dll.delete(); changeConfig("arc_only"); } catch (IOException e) { e.printStackTrace(); - //Change status and color of JLabel status + //Change status and color of JLabel status cf.status.setText("- Cannot restore ArcDPS"); cf.status.setForeground(Color.RED); } - LauncherHelper.updateDll(cf,path); //check for update just in case - } - - - else if (!check && old_dll.exists()){ - //If d3d9.dll is not detected but a backup is found. Rename the backup and check for an update - log.log( Level.INFO,"d3d9.dll not found but d3d9_old exists"); + LauncherHelper.updateDll(cf, path); //check for update just in case + } else if (!check && old_dll.exists()) { + //If d3d9.dll is not detected but a backup is found. Rename the backup and check for an update + log.log(Level.INFO, "d3d9.dll not found but d3d9_old exists"); try { Files.copy(old_dll.toPath(), dll.toPath()); old_dll.delete(); changeConfig("arc_only"); } catch (IOException e) { e.printStackTrace(); - //Change status and color of JLabel status + //Change status and color of JLabel status cf.status.setText("- Cannot connect to the update server"); cf.status.setForeground(Color.RED); } - - LauncherHelper.updateDll(cf,path); + + LauncherHelper.updateDll(cf, path); + + } else { + log.log(Level.INFO, "d3d9.dll, d3d9_old.dll, d3d9_disabled.dll not found"); + //if there is not d3d9.dll and no backup it means that ArcDPS or BGDM is not installed + cf.startwith.setEnabled(false); } - - - - else { - log.log( Level.INFO,"d3d9.dll, d3d9_old.dll, d3d9_disabled.dll not found"); - //if there is not d3d9.dll and no backup it means that ArcDPS or BGDM is not installed - cf.startwith.setEnabled(false); - - } - - - if(!ini.exists() && (cf.getMode().equals("arc_only"))) { //If ini file is not detected ask to the user if he would like to restore it with a default version from the website - int dialogButton = JOptionPane.YES_NO_OPTION; - log.log( Level.INFO,"archdps.ini not found"); - int dialogResult = JOptionPane.showConfirmDialog(null,"ArcDPS configuration file not found. Would you like to download a default configoration?","ArcDPS configuration file not detected",dialogButton); - if (dialogResult==JOptionPane.YES_OPTION){ - LauncherHelper.downloadINI(cf,path); //Method used to download the .ini - } - + + + if (!ini.exists() && (cf.getMode().equals("arc_only"))) { //If ini file is not detected ask to the user if he would like to restore it with a default version from the website + int dialogButton = JOptionPane.YES_NO_OPTION; + log.log(Level.INFO, "archdps.ini not found"); + int dialogResult = JOptionPane.showConfirmDialog(null, "ArcDPS configuration file not found. Would you like to download a default configoration?", "ArcDPS configuration file not detected", dialogButton); + if (dialogResult == JOptionPane.YES_OPTION) { + LauncherHelper.downloadINI(cf, path); //Method used to download the .ini + } + } - + LauncherHelper.closeLogHandlers(log); } - - public static void runWithoutDPS(String path){ - File dll= new File(path+"\\bin64\\d3d9.dll"); - if (dll.exists()){ - log.log( Level.INFO,"Disabling dll"); - File old = new File(path+"\\bin64\\d3d9_disabled.dll"); + + public static void runWithoutDPS(String path) { + File dll = new File(path + "\\bin64\\d3d9.dll"); + if (dll.exists()) { + log.log(Level.INFO, "Disabling dll"); + File old = new File(path + "\\bin64\\d3d9_disabled.dll"); if (old.exists()) old.delete(); //delete an older disabled dll to prevent an exception try { Files.copy(dll.toPath(), old.toPath()); //rename d3d9.dll to d3d9_disabled.dll - dll= new File(path+"\\bin64\\d3d9.dll"); + dll = new File(path + "\\bin64\\d3d9.dll"); dll.delete(); } catch (IOException e) { e.printStackTrace(); - log.log( Level.SEVERE,"IOException when disabling dll"); + log.log(Level.SEVERE, "IOException when disabling dll"); errorDialog(path); } } } //Error dialog needed for static methods - public static void errorDialog(String path){ + public static void errorDialog(String path) { int dialogButton = JOptionPane.YES_NO_OPTION; - int dialogResult = JOptionPane.showConfirmDialog(null,"Something went wrong. Check your internet connection. Would you like to run GW2 without ArcDPS?", - "Updater failed",dialogButton); - if (dialogResult==JOptionPane.YES_OPTION) { + int dialogResult = JOptionPane.showConfirmDialog(null, "Something went wrong. Check your internet connection. Would you like to run GW2 without ArcDPS?", + "Updater failed", dialogButton); + if (dialogResult == JOptionPane.YES_OPTION) { CoreUpdater.runWithoutDPS(path); } } - - public void changeConfig(String mode){ + + public void changeConfig(String mode) { Properties prop = new Properties(); - LauncherHelper.loadProp(prop,"gw2_launcher.cfg"); + LauncherHelper.loadProp(prop, "gw2_launcher.cfg"); prop.put("mode", mode); - LauncherHelper.saveProp(prop,"gw2_launcher.cfg"); + LauncherHelper.saveProp(prop, "gw2_launcher.cfg"); } - - - - - + + } diff --git a/src/updater/FastUpdater.java b/src/updater/FastUpdater.java index 4ae73a9..e63c20d 100644 --- a/src/updater/FastUpdater.java +++ b/src/updater/FastUpdater.java @@ -28,163 +28,154 @@ public class FastUpdater implements Runnable { private String md5_new; private FastFrame cf; private String path; - private File dll; - private File old_dll; - private File disabled_dll; + private File dll; + private File old_dll; + private File disabled_dll; private boolean type; //0 or 1 accordingly to "gw2_settings.cfg" - private static Logger log = Logger.getLogger( FastUpdater.class.getName() ); - - public FastUpdater(FastFrame cf, String path,boolean type){ - this.cf=cf; - this.path=path; - dll=new File(path+"\\bin64\\d3d9.dll"); //dll of ArcDPS - old_dll= new File(path+"\\bin64\\d3d9_old.dll"); //backup dll of ArcDPS - disabled_dll= new File(path+"\\bin64\\d3d9_disabled.dll"); //disabled dll of ArcDPS - this.type=type; - LauncherHelper.LogSetup(log,false); + private static Logger log = Logger.getLogger(FastUpdater.class.getName()); + + public FastUpdater(FastFrame cf, String path, boolean type) { + this.cf = cf; + this.path = path; + dll = new File(path + "\\bin64\\d3d9.dll"); //dll of ArcDPS + old_dll = new File(path + "\\bin64\\d3d9_old.dll"); //backup dll of ArcDPS + disabled_dll = new File(path + "\\bin64\\d3d9_disabled.dll"); //disabled dll of ArcDPS + this.type = type; + LauncherHelper.LogSetup(log, false); } public void run() { - boolean check=dll.exists(); - File ini=new File(path+"\\bin64\\arcdps.ini"); //settings file of archdps. Needed to make ArcDPS works + boolean check = dll.exists(); + File ini = new File(path + "\\bin64\\arcdps.ini"); //settings file of archdps. Needed to make ArcDPS works - if (check){ - //System.out.println("d3d9.dll exists"); - log.log( Level.INFO,"d3d9.dll found"); - updateDll(); //if d3d9.dll exists check if update is needed + if (check) { + //System.out.println("d3d9.dll exists"); + log.log(Level.INFO, "d3d9.dll found"); + updateDll(); //if d3d9.dll exists check if update is needed runGW2Fast(type); //Game is ready to be launched - } - - else if (!check && disabled_dll.exists()){ - //If d3d9.dll is not detected but a backup is found. Rename the backup and check for an update + } else if (!check && disabled_dll.exists()) { + //If d3d9.dll is not detected but a backup is found. Rename the backup and check for an update try { - log.log( Level.INFO,"d3d9.dll not found but d3d9_disabled exists"); + log.log(Level.INFO, "d3d9.dll not found but d3d9_disabled exists"); Files.copy(disabled_dll.toPath(), dll.toPath()); disabled_dll.delete(); } catch (IOException e) { e.printStackTrace(); - //Change status and color of JLabel status + //Change status and color of JLabel status cf.status.setText(" Cannot connect to the update server"); cf.status.setForeground(Color.RED); } updateDll(); //check for update just in case runGW2Fast(type); //Game is ready to be launched - } - - else if (!check && old_dll.exists()){ - //If d3d9.dll is not detected but a backup is found. Rename the backup and check for an update - log.log( Level.INFO,"d3d9.dll not found but d3d9_old exists"); - try { + } else if (!check && old_dll.exists()) { + //If d3d9.dll is not detected but a backup is found. Rename the backup and check for an update + log.log(Level.INFO, "d3d9.dll not found but d3d9_old exists"); + try { Files.copy(old_dll.toPath(), dll.toPath()); old_dll.delete(); } catch (IOException e) { e.printStackTrace(); - //Change status and color of JLabel status + //Change status and color of JLabel status cf.status.setText(" Cannot connect to the update server"); cf.status.setForeground(Color.RED); } - updateDll(); + updateDll(); runGW2Fast(type); //Game is ready to be launched - - } - - else if (!check && !old_dll.exists()){ - log.log( Level.INFO,"d3d9.dll, d3d9_old.dll, d3d9_disabled.dll not found"); - //if there is not d3d9.dll and no backup it means that ArcDPS is not installed + } else if (!check && !old_dll.exists()) { + log.log(Level.INFO, "d3d9.dll, d3d9_old.dll, d3d9_disabled.dll not found"); + //if there is not d3d9.dll and no backup it means that ArcDPS is not installed int dialogButton = JOptionPane.YES_NO_OPTION; //Ask to the user if he would like to install ArcDPS - int dialogResult=JOptionPane.showConfirmDialog(null,"ArcDPS not installed. Would you like to install ArcDPS?","ArcDPS not detected",dialogButton); - if (dialogResult==JOptionPane.YES_OPTION){ + int dialogResult = JOptionPane.showConfirmDialog(null, "ArcDPS not installed. Would you like to install ArcDPS?", "ArcDPS not detected", dialogButton); + if (dialogResult == JOptionPane.YES_OPTION) { try { dll.createNewFile(); //placeholder that is going to be updated by updateDll() } catch (IOException e) { - //Change status and color of JLabel status + //Change status and color of JLabel status e.printStackTrace(); cf.status.setText(" Cannot connect to the update server"); cf.status.setForeground(Color.RED); - log.log( Level.SEVERE,"IOException when creating placeholder"); + log.log(Level.SEVERE, "IOException when creating placeholder"); } downloadINI(); //.ini is required for the first install updateDll(); //placehold swapped with the last version of the dll changeConfig("arc_only"); //Change status and color of JLabel status - log.log( Level.INFO,"ArcDPS installed succesfully"); + log.log(Level.INFO, "ArcDPS installed succesfully"); cf.status.setText(" ArcDPS Installed succesfully"); - cf.status.setForeground(new Color(0,102,51)); + cf.status.setForeground(new Color(0, 102, 51)); runGW2Fast(type); - } - else { - log.log( Level.INFO,"User doens't want ArcDPS"); + } else { + log.log(Level.INFO, "User doens't want ArcDPS"); cf.status.setText(" ArcDPS not installed"); cf.status.setForeground(Color.RED); } } - - - if(!ini.exists()) { //If ini file is not detected ask to the user if he would like to restore it with a default version from the website - int dialogButton = JOptionPane.YES_NO_OPTION; - log.log( Level.INFO,"archdps.ini not found"); - int dialogResult=JOptionPane.showConfirmDialog(null,"ArcDPS configuration file not found. Would you like to download a default configoration?","ArcDPS configuration file not detected",dialogButton); - if (dialogResult==JOptionPane.YES_OPTION){ - downloadINI(); //Method used to download the .ini - } - + + + if (!ini.exists()) { //If ini file is not detected ask to the user if he would like to restore it with a default version from the website + int dialogButton = JOptionPane.YES_NO_OPTION; + log.log(Level.INFO, "archdps.ini not found"); + int dialogResult = JOptionPane.showConfirmDialog(null, "ArcDPS configuration file not found. Would you like to download a default configoration?", "ArcDPS configuration file not detected", dialogButton); + if (dialogResult == JOptionPane.YES_OPTION) { + downloadINI(); //Method used to download the .ini + } + } - + } - - public void downloadINI(){ - File ini=new File(path+"\\bin64\\arcdps.ini"); - if (ini.exists()) ini.delete(); //Delete existing ini file to prevent an exception - log.log( Level.INFO,"Downloading configuration file"); - try { - //Download default configuration from the website - FileUtils.copyURLToFile(new URL("http://www.deltaconnected.com/arcdps/x64/arcdps.ini"),ini, 10000, 10000); - log.log( Level.INFO,"archdps.ini installed successfully"); - //Exceptions if something goes wrong (Connection/IO) - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - cf.status.setText(" Cannot connect to the update server"); + + public void downloadINI() { + File ini = new File(path + "\\bin64\\arcdps.ini"); + if (ini.exists()) ini.delete(); //Delete existing ini file to prevent an exception + log.log(Level.INFO, "Downloading configuration file"); + try { + //Download default configuration from the website + FileUtils.copyURLToFile(new URL("http://www.deltaconnected.com/arcdps/x64/arcdps.ini"), ini, 10000, 10000); + log.log(Level.INFO, "archdps.ini installed successfully"); + //Exceptions if something goes wrong (Connection/IO) + } catch (IOException e) { + e.printStackTrace(); + cf.status.setText(" Cannot connect to the update server"); cf.status.setForeground(Color.RED); - log.log( Level.SEVERE,"IOException when downloading ini"); - } + log.log(Level.SEVERE, "IOException when downloading ini"); + } } - + @SuppressWarnings("deprecation") //Remove warning for a deprecated function - public void updateDll(){ + public void updateDll() { FileInputStream fis = null; try { - //Generate md5 file of the dll installed in the system using some external libraries - + //Generate md5 file of the dll installed in the system using some external libraries + fis = new FileInputStream(dll); byte data[] = new byte[0]; data = org.apache.commons.codec.digest.DigestUtils.md5(fis); char md5Chars[] = Hex.encodeHex(data); md5_old = String.valueOf(md5Chars); - File md5_download= new File(path+"\\bin64\\arcdps.dll.md5sum"); //Path of the md5 that is going to be downloaded + File md5_download = new File(path + "\\bin64\\arcdps.dll.md5sum"); //Path of the md5 that is going to be downloaded //Download the md5 of the last version of ArcDPS from the website - FileUtils.copyURLToFile(new URL("http://www.deltaconnected.com/arcdps/x64/d3d9.dll.md5sum"),md5_download, 10000, 10000); - log.log( Level.INFO,"Md5 downloaded"); - md5_new=FileUtils.readFileToString(md5_download).substring(0, FileUtils.readFileToString(md5_download).indexOf(" ")); - log.log( Level.INFO,"Old md5: "+md5_old); - log.log( Level.INFO,"New md5: "+md5_new); - - if(!md5_old.equals(md5_new)){ //Different checksum means that a new version must be downlaoded - log.log( Level.INFO,"New version available"); - - File backup = new File(path+"\\bin64\\d3d9_old.dll"); + FileUtils.copyURLToFile(new URL("http://www.deltaconnected.com/arcdps/x64/d3d9.dll.md5sum"), md5_download, 10000, 10000); + log.log(Level.INFO, "Md5 downloaded"); + md5_new = FileUtils.readFileToString(md5_download).substring(0, FileUtils.readFileToString(md5_download).indexOf(" ")); + log.log(Level.INFO, "Old md5: " + md5_old); + log.log(Level.INFO, "New md5: " + md5_new); + + if (!md5_old.equals(md5_new)) { //Different checksum means that a new version must be downlaoded + log.log(Level.INFO, "New version available"); + + File backup = new File(path + "\\bin64\\d3d9_old.dll"); if (backup.exists()) backup.delete(); //delete old backup to prevent an exception //Create backup copy Files.copy(dll.toPath(), backup.toPath()); @@ -193,31 +184,29 @@ public void updateDll(){ //Change text of the JLabel status cf.status.setText(" Downloading new version..."); //Download new dll - FileUtils.copyURLToFile(new URL("http://www.deltaconnected.com/arcdps/x64/d3d9.dll"),dll, 10000, 10000); + FileUtils.copyURLToFile(new URL("http://www.deltaconnected.com/arcdps/x64/d3d9.dll"), dll, 10000, 10000); cf.status.setText(" ArcDPS updated"); - cf.status.setForeground(new Color(0,102,51)); - } - - else { //Same checksum means that the user has the most recent version of ArcDPS - log.log( Level.INFO,"ArcDPS already updated"); + cf.status.setForeground(new Color(0, 102, 51)); + } else { //Same checksum means that the user has the most recent version of ArcDPS + log.log(Level.INFO, "ArcDPS already updated"); cf.status.setText("- ArcDPS is already updated"); cf.status.setForeground(new Color(0, 102, 51)); } - //Delete downloaded md5 now useless and close stream - log.log( Level.INFO,"Removing downloaded md5"); + //Delete downloaded md5 now useless and close stream + log.log(Level.INFO, "Removing downloaded md5"); md5_download.delete(); fis.close(); - - //Exceptions if something goes wrong (Connection/IO) + + //Exceptions if something goes wrong (Connection/IO) } catch (FileNotFoundException e) { e.printStackTrace(); cf.status.setText(" Cannot connect to the update server"); cf.status.setForeground(Color.RED); - log.log( Level.SEVERE,"IOException when downloading dll"); + log.log(Level.SEVERE, "IOException when downloading dll"); errorDialog(path); } catch (IOException e) { e.printStackTrace(); - log.log( Level.SEVERE,"IOException when downloading dll"); + log.log(Level.SEVERE, "IOException when downloading dll"); cf.status.setText(" Cannot connect to the update server"); cf.status.setForeground(Color.RED); errorDialog(path); @@ -226,75 +215,73 @@ public void updateDll(){ } - - @SuppressWarnings("unused") - public void runGW2Fast(boolean useAddons){ + public void runGW2Fast(boolean useAddons) { - if (useAddons==false) runWithoutDPS(path); //if type==0 ArcDPS' dll must be disabled + if (useAddons == false) runWithoutDPS(path); //if type==0 ArcDPS' dll must be disabled try { - log.log( Level.INFO,"Running Gw2. Fast mode"); - //Create process with some arguments - List list= Arrays.asList(cf.arg_string.getText().split("\\s*,\\s*")); - LinkedList exe= new LinkedList<>(list); - cf.dispose(); - log.log( Level.INFO,"Args: "+list); - exe.addFirst(path+"\\Gw2-64.exe"); - Process process = new ProcessBuilder(exe).start(); - System.exit(0); - } catch (IOException e1) { - log.log( Level.SEVERE,"Error while launching gw2"); - e1.printStackTrace(); - System.exit(1); - } + log.log(Level.INFO, "Running Gw2. Fast mode"); + //Create process with some arguments + List list = Arrays.asList(cf.arg_string.getText().split("\\s*,\\s*")); + LinkedList exe = new LinkedList<>(list); + cf.dispose(); + log.log(Level.INFO, "Args: " + list); + exe.addFirst(path + "\\Gw2-64.exe"); + Process process = new ProcessBuilder(exe).start(); + System.exit(0); + } catch (IOException e1) { + log.log(Level.SEVERE, "Error while launching gw2"); + e1.printStackTrace(); + System.exit(1); + } } - public static void runWithoutDPS(String path){ - File dll= new File(path+"\\bin64\\d3d9.dll"); - if (dll.exists()){ - log.log( Level.INFO,"Disabling dll"); - File old = new File(path+"\\bin64\\d3d9_disabled.dll"); + public static void runWithoutDPS(String path) { + File dll = new File(path + "\\bin64\\d3d9.dll"); + if (dll.exists()) { + log.log(Level.INFO, "Disabling dll"); + File old = new File(path + "\\bin64\\d3d9_disabled.dll"); if (old.exists()) old.delete(); //delete an older disabled dll to prevent an exception try { Files.copy(dll.toPath(), old.toPath()); //rename d3d9.dll to d3d9_disabled.dll - File dll_disabled= new File(path+"\\bin64\\d3d9.dll"); + File dll_disabled = new File(path + "\\bin64\\d3d9.dll"); dll_disabled.delete(); } catch (IOException e) { e.printStackTrace(); - log.log( Level.SEVERE,"IOException when disabling dll"); + log.log(Level.SEVERE, "IOException when disabling dll"); errorDialog(path); } } } //Error dialog needed for static methods - public static void errorDialog(String path){ + public static void errorDialog(String path) { int dialogButton = JOptionPane.YES_NO_OPTION; - int dialogResult=JOptionPane.showConfirmDialog(null,"Something went wrong. Check your internet connection. Would you like to run GW2 without ArcDPS?", - "Updater failed",dialogButton); - if (dialogResult==JOptionPane.YES_OPTION) { - log.log( Level.INFO,"Launching gw2 without Arc after error dialog"); + int dialogResult = JOptionPane.showConfirmDialog(null, "Something went wrong. Check your internet connection. Would you like to run GW2 without ArcDPS?", + "Updater failed", dialogButton); + if (dialogResult == JOptionPane.YES_OPTION) { + log.log(Level.INFO, "Launching gw2 without Arc after error dialog"); FastUpdater.runWithoutDPS(path); } } - - public void changeConfig(String mode){ + + public void changeConfig(String mode) { Properties prop = new Properties(); //Import settings FileInputStream input; - try { - input = new FileInputStream("gw2_launcher.cfg"); - prop.load(input); - input.close(); - } catch (IOException e1) { - e1.printStackTrace(); - } + try { + input = new FileInputStream("gw2_launcher.cfg"); + prop.load(input); + input.close(); + } catch (IOException e1) { + e1.printStackTrace(); + } prop.put("mode", mode); - LauncherHelper.saveProp(prop,"gw2_launcher.cfg"); + LauncherHelper.saveProp(prop, "gw2_launcher.cfg"); } diff --git a/src/updater/UpdateNotifier.java b/src/updater/UpdateNotifier.java index 1be36c4..5e89f11 100644 --- a/src/updater/UpdateNotifier.java +++ b/src/updater/UpdateNotifier.java @@ -8,6 +8,7 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; + import javax.swing.JOptionPane; import java.io.IOException; import java.net.URISyntaxException; @@ -16,71 +17,68 @@ import java.util.logging.Logger; public class UpdateNotifier implements Runnable { - private final String version; - private final String repoName; - private final String username; - - public UpdateNotifier(String version, String repoName, String username){ - this.version=version; - this.repoName=repoName; - this.username=username; - + private final String version; + private final String repoName; + private final String username; + + public UpdateNotifier(String version, String repoName, String username) { + this.version = version; + this.repoName = repoName; + this.username = username; + } @Override public void run() { Logger logger = Logger.getLogger("mis_update_notifier"); - String output= getJSONData(); - if (output!= null && output.startsWith("[")){ + String output = getJSONData(); + if (output != null && output.startsWith("[")) { JSONArray jarray; - try { - jarray = new JSONArray(output); - if (jarray.length()>0){ - JSONObject last_release=jarray.getJSONObject(0); - if (last_release.has("tag_name")){ - Semver sem = new Semver(last_release.getString("tag_name")); - //System.out.println(last_release.getString("tag_name")); - if (sem.isGreaterThan(version)) { - String URI="http://www.github.com/"+username+"/"+repoName+"/releases"; - logger.log(Level.SEVERE,"An update is avaiable. Please get the update at "+URI); - int dialogButton=JOptionPane.YES_NO_OPTION; - int dialogResult=JOptionPane.showConfirmDialog(null,"An update for the launcher is avaiable. Would you like to go to the download page?","An update is avaiable",dialogButton); - if (dialogResult==JOptionPane.YES_OPTION){ - try { - java.awt.Desktop.getDesktop().browse(new java.net.URI(URI)); - } catch (IOException | URISyntaxException e) { - e.printStackTrace(); - } - } - } - else logger.log(Level.INFO,"GW2_Launcher is updated"); - } - else logger.log(Level.WARNING,"Unable to find updates on Github"); - } - } catch (JSONException e) { - e.printStackTrace(); - } - } - else logger.log(Level.WARNING,"Unable to find updates on Github"); + try { + jarray = new JSONArray(output); + if (jarray.length() > 0) { + JSONObject last_release = jarray.getJSONObject(0); + if (last_release.has("tag_name")) { + Semver sem = new Semver(last_release.getString("tag_name")); + //System.out.println(last_release.getString("tag_name")); + if (sem.isGreaterThan(version)) { + String URI = "http://www.github.com/" + username + "/" + repoName + "/releases"; + logger.log(Level.SEVERE, "An update is avaiable. Please get the update at " + URI); + int dialogButton = JOptionPane.YES_NO_OPTION; + int dialogResult = JOptionPane.showConfirmDialog(null, "An update for the launcher is avaiable. Would you like to go to the download page?", "An update is avaiable", dialogButton); + if (dialogResult == JOptionPane.YES_OPTION) { + try { + java.awt.Desktop.getDesktop().browse(new java.net.URI(URI)); + } catch (IOException | URISyntaxException e) { + e.printStackTrace(); + } + } + } else logger.log(Level.INFO, "GW2_Launcher is updated"); + } else logger.log(Level.WARNING, "Unable to find updates on Github"); + } + } catch (JSONException e) { + e.printStackTrace(); + } + } else logger.log(Level.WARNING, "Unable to find updates on Github"); } - private String getJSONData(){ - Request req = new Request.Builder().url("https://api.github.com/repos/"+username+"/"+repoName+"/releases").header("Accept","application/json") - .header("Content-Type","application/json").build(); - OkHttpClient client = new OkHttpClient.Builder() - .connectTimeout(15, TimeUnit.SECONDS) - .readTimeout(10, TimeUnit.SECONDS).retryOnConnectionFailure(true) - .build(); - Response resp = null; - String body = null; - try { - resp = client.newCall(req).execute(); - if(resp.body()==null) return null; - body = resp.body().string(); - } catch (IOException e) { - e.printStackTrace(); - } - return body; + private String getJSONData() { + Request req = new Request.Builder().url("https://api.github.com/repos/" + username + "/" + repoName + "/releases").header("Accept", "application/json") + .header("Content-Type", "application/json").build(); + OkHttpClient client = new OkHttpClient.Builder() + .connectTimeout(15, TimeUnit.SECONDS) + .readTimeout(10, TimeUnit.SECONDS).retryOnConnectionFailure(true) + .build(); + Response resp = null; + String body = null; + try { + resp = client.newCall(req).execute(); + if (resp.body() == null) return null; + body = resp.body().string(); + } catch (IOException e) { + e.printStackTrace(); + } + return body; } }