Skip to content

Commit

Permalink
Remove buildtemplates and refactor project
Browse files Browse the repository at this point in the history
  • Loading branch information
leosarra committed Oct 19, 2019
1 parent 64362cd commit c3a8bc1
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 193 deletions.
14 changes: 5 additions & 9 deletions src/chooser/DirChooser.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package chooser;

import framework.Operations;
import helpers.LauncherHelper;
import updater.CoreUpdater;

import javax.swing.*;

import java.awt.Toolkit;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;
import java.util.logging.Level;
Expand All @@ -24,7 +20,7 @@ public class DirChooser {

public void execute() {
//Functor pattern
Operations.LogSetup(log,false);
LauncherHelper.LogSetup(log,false);
if (!fired) {
boolean found = false;
fired = true;
Expand Down Expand Up @@ -59,7 +55,7 @@ public void execute() {
System.exit(0);
}
}
Operations.closeLogHandlers(log);
LauncherHelper.closeLogHandlers(log);
}
}

Expand All @@ -80,10 +76,10 @@ public boolean isFired() {

public void changePathProp(String path){
Properties prop = new Properties();
Operations.loadProp(prop,"gw2_launcher.cfg");
LauncherHelper.loadProp(prop,"gw2_launcher.cfg");
OutputStream output= null;
prop.put("path", path);
Operations.saveProp(prop,"gw2_launcher.cfg");
LauncherHelper.saveProp(prop,"gw2_launcher.cfg");

}
}
58 changes: 18 additions & 40 deletions src/frame/CoreFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ public class CoreFrame extends JFrame{
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 JButton arc= new JButton("Install ArcDPS");
public JButton btempl= new JButton("Install Buildtemplates");
public JTextField arg_string=new JTextField(20);
private JButton arc= new JButton("Install ArcDPS");
private String path_string;
private JButton me= new JButton("?");
private String mode;
Expand Down Expand Up @@ -60,15 +59,11 @@ public CoreFrame(String dir){
startwithout.setActionCommand("without");
background.setActionCommand("background");
arc.setActionCommand("arc");
btempl.setActionCommand("btempl_install");


//Create MyActionListener
MyActionListener mal= new MyActionListener(path_string,this);

//Add Listeners
arc.addActionListener(mal);
btempl.addActionListener(mal);
startwith.addActionListener(mal);
startwithout.addActionListener(mal);
background.addActionListener(mal);
Expand All @@ -89,7 +84,6 @@ public CoreFrame(String dir){
sel.add(status);
sel2.add(path);
install.add(arc);
install.add(btempl);
top.add(sel2);
top.add(sel);
mid.setLayout(new BorderLayout(0, 0));
Expand Down Expand Up @@ -130,39 +124,23 @@ public CoreFrame(String dir){

public void setMode(String mode) {
this.mode=mode;
if (mode.equals("none")) {
arc.setText("Install ArcDPS");
status.setText("- ArcDPS is not installed");
status.setForeground(Color.RED);
btempl.setText("Install Buildtemplates");
btempl.setEnabled(false);
startwith.setEnabled(false);
autostart.setEnabled(false);
background.setEnabled(false);
}
else if (mode.equals("both")) {
arc.setText("Remove ArcDPS");
File templates= new File(path_string+"\\bin64\\d3d9_arcdps_buildtemplates.dll");
if(templates.exists()) {
btempl.setText("Remove Buildtemplates");
btempl.setActionCommand("btempl_remove");
}
else btempl.setText("Install Buildtemplates");

}
else if (mode.equals("arc_only")) {
arc.setText("Remove ArcDPS");
File templates= new File(path_string+"\\bin64\\d3d9_arcdps_buildtemplates.dll");
if (templates.exists()) {
btempl.setText("Remove Buildtemplates");
btempl.setActionCommand("btempl_remove");
}
else btempl.setText("Install Buildtemplates");
}

else {
arc.setText("Install ArcDPS");
}
switch (mode) {
case "none":
arc.setText("Install ArcDPS");
status.setText("- ArcDPS is not installed");
status.setForeground(Color.RED);
startwith.setEnabled(false);
autostart.setEnabled(false);
background.setEnabled(false);
break;
case "both":
case "arc_only":
arc.setText("Remove ArcDPS");
break;
default:
arc.setText("Install ArcDPS");
break;
}
}


Expand Down
35 changes: 15 additions & 20 deletions src/frame/FastFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public class FastFrame extends JFrame{
private JCheckBox autostart= new JCheckBox("Start with these settings each time");
public JTextField arg_string=new JTextField(20);
private String path_string;
public JButton arc= new JButton("Install ArcDPS");
public JButton bgdm= new JButton("Install BGDM");
private JButton arc= new JButton("Install ArcDPS");
private String mode;


Expand Down Expand Up @@ -68,22 +67,18 @@ public FastFrame(String dir, boolean hide){

public void setMode(String mode) {
this.mode=mode;
if (mode.equals("none")) {
arc.setText("Install ArcDPS");
status.setText("- ArcDPS is not installed");
status.setForeground(Color.RED);
}
else if (mode.equals("both")) {
arc.setText("Remove ArcDPS");
File templates= new File(path_string+"\\bin64\\d3d9_arcdps_buildtemplates.dll");

}
else if (mode.equals("arc_only")) {
arc.setText("Remove ArcDPS");
File templates= new File(path_string+"\\bin64\\d3d9_arcdps_buildtemplates.dll");
}

else {
arc.setText("Install ArcDPS");
}
switch (mode) {
case "none":
arc.setText("Install ArcDPS");
status.setText("- ArcDPS is not installed");
status.setForeground(Color.RED);
break;
case "both":
case "arc_only":
arc.setText("Remove ArcDPS");
break;
default:
arc.setText("Install ArcDPS");
break;
}
}}
89 changes: 21 additions & 68 deletions src/framework/Operations.java → src/helpers/LauncherHelper.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package framework;
package helpers;

import java.awt.Color;
import java.io.*;
Expand All @@ -17,9 +17,9 @@
import launcher.Main;


public class Operations {
public class LauncherHelper {
private static final boolean DEBUG = false;
static Logger log = Logger.getLogger( Main.class.getName() );
private static Logger log = Logger.getLogger( Main.class.getName() );


public static void LogSetup(Logger log, boolean operations) {
Expand Down Expand Up @@ -87,8 +87,8 @@ public static synchronized void installArc(CoreFrame cf, String path) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Operations.downloadINI(cf,path); //.ini is required for the first install
Operations.updateDll(cf,path); //placeholder swapped with the last version of the dll
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 {
Expand All @@ -107,12 +107,12 @@ public static synchronized void installArc(CoreFrame cf, String path) {
}

public static synchronized void installLoaderReshade(String path) {
Operations.LogSetup(log,true);
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/x64/reshade_loader/d3d9_chainload.dll"),download, 10000, 10000);
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) {
Expand All @@ -121,13 +121,13 @@ public static synchronized void installLoaderReshade(String path) {
e.printStackTrace();
}
}
Operations.closeLogHandlers(log);
LauncherHelper.closeLogHandlers(log);

}

//Delete d3d9.dll of Arc
public static synchronized void removeArc(CoreFrame cf, String path) {
Operations.LogSetup(log,true);
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");
Expand All @@ -149,13 +149,13 @@ public static synchronized void removeArc(CoreFrame cf, String path) {
cf.setMode("none");
cf.status.setText("- ArcDPS not installed");
cf.status.setForeground(Color.RED);
Operations.closeLogHandlers(log);
LauncherHelper.closeLogHandlers(log);


}

public static synchronized void removeArcSetting(CoreFrame cf, String path) {
Operations.LogSetup(log,true);
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");
Expand All @@ -172,7 +172,7 @@ public static synchronized void removeArcSetting(CoreFrame cf, String path) {


log.log( Level.INFO, "Everything went smooth [removeArcSetting]");
Operations.closeLogHandlers(log);
LauncherHelper.closeLogHandlers(log);


}
Expand All @@ -185,7 +185,7 @@ public static synchronized void removeReshadeLoader(String path) {
}

public static synchronized void downloadINI(CoreFrame cf, String path){
Operations.LogSetup(log,true);
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");
Expand All @@ -195,67 +195,27 @@ public static synchronized void downloadINI(CoreFrame cf, String path){
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");
}
Operations.closeLogHandlers(log);
}


//method used to download the Buildtemplates' dll
public static synchronized int installBTempl(CoreFrame cf, String path){
Operations.LogSetup(log,true);
File btempl=new File(path+"\\bin64\\d3d9_arcdps_buildtemplates.dll");
if (btempl.exists()) btempl.delete(); //Delete existing ini file to prevent an exception
log.log( Level.INFO,"Downloading Buildtemplates dll");
try {
//Download default configuration from the website
FileUtils.copyURLToFile(new URL("http://www.deltaconnected.com/arcdps/x64/buildtemplates/d3d9_arcdps_buildtemplates.dll"),btempl, 10000, 10000);
log.log( Level.INFO,"Buildtemplates funcionality installed successfully");
cf.btempl.setText("Remove Buildtemplates");
//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 Buildtemplates dll");
return -1;
}
Operations.closeLogHandlers(log);
return 0;
}


//method used to remove the buildtemplates' dll
public static synchronized int removeBTempl(CoreFrame cf, String path){
Operations.LogSetup(log,true);
File btempl=new File(path+"\\bin64\\d3d9_arcdps_buildtemplates.dll");
if (btempl.exists()) btempl.delete(); //Delete existing dll
log.log( Level.INFO,"Buildtemplates dll removed");
Operations.closeLogHandlers(log);
return 0;
LauncherHelper.closeLogHandlers(log);
}


//used to update arcDPS
public static synchronized void updateDll(CoreFrame cf, String path){
Operations.LogSetup(log,true);
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

fis = new FileInputStream(dll);
byte data[] = new byte[0];
data = org.apache.commons.codec.digest.DigestUtils.md5(fis);
char md5Chars[] = Hex.encodeHex(data);
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();
Expand Down Expand Up @@ -283,12 +243,7 @@ public static synchronized void updateDll(CoreFrame cf, String path){
cf.status.setText("- ArcDPS updated");
cf.status.setForeground(new Color(0,102,51));
File btempl=new File(path+"\\bin64\\d3d9_arcdps_buildtemplates.dll");
if (btempl.exists()) {
Operations.closeLogHandlers(log);
Operations.installBTempl(cf, path);
Operations.LogSetup(log,true);
}

if (btempl.exists()) btempl.delete();
}

else { //Same checksum means that the user has the most recent version of ArcDPS
Expand All @@ -315,10 +270,8 @@ public static synchronized void updateDll(CoreFrame cf, String path){
cf.status.setForeground(Color.RED);
log.log( Level.SEVERE,"IOException when downloading dll");
}

Operations.closeLogHandlers(log);
Operations.installLoaderReshade(path);

LauncherHelper.closeLogHandlers(log);
LauncherHelper.installLoaderReshade(path);
}


Expand Down
Loading

0 comments on commit c3a8bc1

Please sign in to comment.