diff --git a/out/artifacts/proxy/Proxy Auto.lnk b/out/artifacts/proxy/Proxy Auto.lnk new file mode 100644 index 0000000..6e4d22c Binary files /dev/null and b/out/artifacts/proxy/Proxy Auto.lnk differ diff --git a/out/artifacts/proxy/Run Auto.cmd b/out/artifacts/proxy/Run Auto.cmd new file mode 100644 index 0000000..ad039fe --- /dev/null +++ b/out/artifacts/proxy/Run Auto.cmd @@ -0,0 +1,4 @@ +@echo off +cls +start /B javaw -jar proxy.jar "http://proxy.mcs.br:8080/array.dll?Get.Routing.Script" +exit \ No newline at end of file diff --git a/out/artifacts/proxy/proxy.jar b/out/artifacts/proxy/proxy.jar index 49113c8..e15c7e2 100644 Binary files a/out/artifacts/proxy/proxy.jar and b/out/artifacts/proxy/proxy.jar differ diff --git a/out/production/proxy/org/proxy/Main.class b/out/production/proxy/org/proxy/Main.class index 1493a6d..1899d7a 100644 Binary files a/out/production/proxy/org/proxy/Main.class and b/out/production/proxy/org/proxy/Main.class differ diff --git a/src/org/proxy/Main.java b/src/org/proxy/Main.java index d9d08b5..7719de8 100644 --- a/src/org/proxy/Main.java +++ b/src/org/proxy/Main.java @@ -11,8 +11,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.Scanner; - -import static java.awt.Component.LEFT_ALIGNMENT; import static javax.swing.JOptionPane.showMessageDialog; import static org.dhaverdLogs.DhaverdLogs.*; import static org.proxy.loadConfig.*; @@ -57,6 +55,30 @@ public class Main { currentProxyPub = getCurrentProxy(); setLog("Proxy Checker", "Current proxy: " + currentProxyPub, true, false); systemTray(); + if (args.length != 0){ + setProxyOnLaunch(args[0]); + updateIcon(); + } + } + + public static void setProxyOnLaunch(String proxyStr) throws IOException, InterruptedException { + setLog("Setting proxy on launch", "Proxy will be set on: " + proxyStr, true, false); + closeThread(); + currentThread = new Thread(() -> { + while(true){ + try { + currentProxyPub = getCurrentProxy(); + if (!currentProxyPub.equals(proxyStr)) setProxy(proxyStr); + Image icon = Toolkit.getDefaultToolkit().getImage("res" + osSeparator + "icon on blue.png"); + trayIcon.setImage(icon); + updateIcon(); + Thread.sleep(repeatTime); + } catch (InterruptedException | IOException ex) { + exeptionActions( "Set proxy: " + proxyStr, ex); + } + } + }); + currentThread.start(); } public static String getCurrentProxy() throws InterruptedException, IOException { @@ -136,12 +158,6 @@ public class Main { newProps.add("\t\t\"" + proxy + "\","); } } - /* - setLog("Add new proxy function", "New proxy list:", true, false); - for (String prop : newProps) { - setLog("Add new proxy function", prop, false, true); - } - */ FileWriter writer = new FileWriter(config, false); for (String prop : newProps) { writer.write(prop + "\n"); @@ -250,9 +266,7 @@ public class Main { //close button JButton closeButton = new JButton("Close"); - closeButton.addActionListener(al -> { - frame.dispose(); - }); + closeButton.addActionListener(al -> frame.dispose()); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridx = 2; gbc.gridy = 1; @@ -316,9 +330,7 @@ public class Main { mainPanel.add(deleteButton, gbc); JButton closeButton = new JButton("Close"); gbc.gridx = 1; - closeButton.addActionListener(al -> { - frame.dispose(); - }); + closeButton.addActionListener(al -> frame.dispose()); mainPanel.add(closeButton, gbc); frame.getContentPane().add(mainPanel); frame.pack(); @@ -355,12 +367,6 @@ public class Main { newProps.add(prop); } } - /* - setLog("Add new proxy function", "New proxy list:", true, false); - for (String prop : newProps) { - setLog("Add new proxy function", prop, false, true); - } - */ FileWriter writer = new FileWriter(config, false); for (String prop : newProps) { writer.write(prop + "\n"); @@ -381,8 +387,7 @@ public class Main { currentThread = new Thread(() -> { while(true){ try { - currentProxyPub = getCurrentProxy(); - trayIcon.setToolTip("Current proxy: " + currentProxyPub); + updateIcon(); Thread.sleep(repeatTime); } catch (InterruptedException | IOException ex) { exeptionActions("Stop Listener", ex); @@ -392,6 +397,12 @@ public class Main { currentThread.start(); }; } + + public static void updateIcon() throws IOException, InterruptedException { + currentProxyPub = getCurrentProxy(); + trayIcon.setToolTip("Current proxy: " + currentProxyPub); + } + public static void closeThread(){ if (currentThread != null){ currentThread.stop(); @@ -409,8 +420,7 @@ public class Main { if (!currentProxyPub.equals(proxyStr)) setProxy(proxyStr); Image icon = Toolkit.getDefaultToolkit().getImage("res" + osSeparator + "icon on blue.png"); trayIcon.setImage(icon); - currentProxyPub = getCurrentProxy(); - trayIcon.setToolTip("Current proxy: " + currentProxyPub); + updateIcon(); Thread.sleep(repeatTime); } catch (InterruptedException | IOException ex) { exeptionActions( "Set proxy: " + proxyStr, ex);