Skip to content

Commit

Permalink
3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
tonikelope committed Mar 10, 2018
1 parent 0275115 commit e483527
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 150 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.tonikelope</groupId>
<artifactId>MegaBasterd</artifactId>
<version>3.3</version>
<version>3.4</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
Expand Down
47 changes: 24 additions & 23 deletions src/main/java/com/tonikelope/megabasterd/ChunkDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,24 +102,11 @@ public void run() {
String worker_url = null, current_proxy = null;;
boolean error = false, error509 = false;

while (!_exit && !_download.isStopped() && (error509 || conta_error < MAX_SLOT_ERROR || _download.getMain_panel().isUse_smart_proxy())) {
while (!_exit && !_download.isStopped() && (error509 || conta_error < MAX_SLOT_ERROR || MainPanel.isUse_smart_proxy())) {

if (httpclient == null || error || _download.getMain_panel().isUse_smart_proxy()) {
if (httpclient == null || error) {

if (error509 && _download.getMain_panel().isUse_smart_proxy() && !_download.getMain_panel().getProxy_manager().isEnabled()) {
_download.getMain_panel().getProxy_manager().setEnabled(true);
}

if (_download.getMain_panel().isUse_smart_proxy() && _download.getMain_panel().getProxy_manager().isEnabled() && !MainPanel.isUse_proxy()) {

if (error && current_proxy != null) {

Logger.getLogger(getClass().getName()).log(Level.WARNING, "{0} Worker [{1}]: excluding proxy -> {2}", new Object[]{Thread.currentThread().getName(), _id, current_proxy});

_download.getMain_panel().getProxy_manager().excludeProxy(current_proxy);
}

current_proxy = _download.getMain_panel().getProxy_manager().getRandomProxy();
if (error509 && MainPanel.isUse_smart_proxy() && !MainPanel.isUse_proxy()) {

if (httpclient != null) {
try {
Expand All @@ -129,19 +116,30 @@ public void run() {
}
}

if (error && current_proxy != null) {

Logger.getLogger(getClass().getName()).log(Level.WARNING, "{0} Worker [{1}]: excluding proxy -> {2}", new Object[]{Thread.currentThread().getName(), _id, current_proxy});

MainPanel.getProxy_manager().excludeProxy(current_proxy);
}

current_proxy = MainPanel.getProxy_manager().getRandomProxy();

if (current_proxy != null) {

httpclient = MiscTools.getApacheKissHttpClientSmartProxy(current_proxy);
getDownload().getMain_panel().getView().setSmartProxy(true);

} else {

httpclient = MiscTools.getApacheKissHttpClient();
_download.getMain_panel().getProxy_manager().setEnabled(false);
getDownload().getMain_panel().getView().setSmartProxy(false);
}

} else if (httpclient == null) {

httpclient = MiscTools.getApacheKissHttpClient();
getDownload().getMain_panel().getView().setSmartProxy(false);
}
}

Expand All @@ -156,12 +154,12 @@ public void run() {

error = false;

if (error509) {
error509 = false;

if (getDownload().isError509()) {
getDownload().getView().set509Error(false);
}

error509 = false;

try (CloseableHttpResponse httpresponse = httpclient.execute(httpget)) {

if (!_exit && !_download.isStopped()) {
Expand All @@ -179,7 +177,10 @@ public void run() {

error509 = true;

getDownload().getView().set509Error(true);
if (MainPanel.isUse_smart_proxy()) {
getDownload().getView().set509Error(true);
}

}

} else {
Expand Down Expand Up @@ -239,7 +240,7 @@ public void run() {

_download.getView().updateSlotsStatus();

if (!_download.getMain_panel().isUse_smart_proxy()) {
if (!MainPanel.isUse_smart_proxy()) {
Thread.sleep(getWaitTimeExpBackOff(conta_error) * 1000);
}

Expand Down Expand Up @@ -285,7 +286,7 @@ public void run() {

_download.getView().updateSlotsStatus();

if (!_download.getMain_panel().isUse_smart_proxy()) {
if (!MainPanel.isUse_smart_proxy()) {
Thread.sleep(getWaitTimeExpBackOff(conta_error) * 1000);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ public void run() {

private void use_mega_account_down_comboboxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_use_mega_account_down_comboboxItemStateChanged

if (_selected_item == null || !((String) use_mega_account_down_combobox.getSelectedItem()).equals(_selected_item)) {
if (_selected_item == null || !use_mega_account_down_combobox.getSelectedItem().equals(_selected_item)) {
_selected_item = (String) use_mega_account_down_combobox.getSelectedItem();

if (_main_panel.isUse_mega_account_down() && !"".equals(_selected_item)) {
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/com/tonikelope/megabasterd/MainPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
*/
public final class MainPanel {

public static final String VERSION = "3.3";
public static final String VERSION = "3.4";
public static final int THROTTLE_SLICE_SIZE = 16 * 1024;
public static final int DEFAULT_BYTE_BUFFER_SIZE = 16 * 1024;
public static final int STREAMER_PORT = 1337;
Expand All @@ -63,6 +63,9 @@ public final class MainPanel {
private static int _proxy_port;
private static Credentials _proxy_credentials;
private static boolean _use_proxy;
private static boolean _use_smart_proxy;
private static String _smart_proxy_url;
private static SmartMegaProxyManager _proxy_manager;

public static void main(String args[]) {

Expand All @@ -88,9 +91,6 @@ public void run() {
});
}

private volatile boolean _use_smart_proxy;
private volatile String _use_smart_proxy_url;
private volatile SmartMegaProxyManager _proxy_manager;
private volatile MainPanelView _view;
private final GlobalSpeedMeter _global_dl_speed, _global_up_speed;
private final DownloadManager _download_manager;
Expand Down Expand Up @@ -138,7 +138,7 @@ public MainPanel() {

_use_smart_proxy = false;

_use_smart_proxy_url = null;
_smart_proxy_url = null;

try {

Expand Down Expand Up @@ -211,7 +211,7 @@ public void run() {

if (_use_smart_proxy) {

_proxy_manager = new SmartMegaProxyManager(this, _use_smart_proxy_url);
_proxy_manager = new SmartMegaProxyManager(this, _smart_proxy_url);

THREAD_POOL.execute(_proxy_manager);
}
Expand Down Expand Up @@ -243,8 +243,8 @@ public float getZoom_factor() {
return _zoom_factor;
}

public void setProxy_manager(SmartMegaProxyManager _proxy_manager) {
this._proxy_manager = _proxy_manager;
public void setProxy_manager(SmartMegaProxyManager proxy_manager) {
_proxy_manager = proxy_manager;
}

public static String getProxy_host() {
Expand All @@ -263,15 +263,15 @@ public static boolean isUse_proxy() {
return _use_proxy;
}

public boolean isUse_smart_proxy() {
public static boolean isUse_smart_proxy() {
return _use_smart_proxy;
}

public String getUse_smart_proxy_url() {
return _use_smart_proxy_url;
public static String getUse_smart_proxy_url() {
return _smart_proxy_url;
}

public SmartMegaProxyManager getProxy_manager() {
public static SmartMegaProxyManager getProxy_manager() {
return _proxy_manager;
}

Expand Down Expand Up @@ -633,7 +633,7 @@ public void loadUserSettings() {

if (_use_smart_proxy) {

_use_smart_proxy_url = selectSettingValue("smart_proxy_url");
_smart_proxy_url = selectSettingValue("smart_proxy_url");
}
}

Expand Down
46 changes: 36 additions & 10 deletions src/main/java/com/tonikelope/megabasterd/MainPanelView.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
public final class MainPanelView extends javax.swing.JFrame {

private final MainPanel _main_panel;
private volatile boolean _smart_proxy;

public JLabel getKiss_server_status() {
return kiss_server_status;
Expand Down Expand Up @@ -167,10 +168,35 @@ public void run() {

}

public void setSmartProxy(boolean enabled) {

if (_smart_proxy != enabled) {
swingInvoke(
new Runnable() {
@Override
public void run() {

if (!_main_panel.isLimit_download_speed()) {
_smart_proxy = enabled;

if (enabled) {
getGlobal_speed_down_label().setForeground(Color.BLACK);
} else {
getGlobal_speed_down_label().setForeground(new Color(0, 128, 255));
}
}

}
});
}
}

public MainPanelView(MainPanel main_panel) {

_main_panel = main_panel;

_smart_proxy = false;

initComponents();

updateFonts(getRootPane(), DEFAULT_FONT, _main_panel.getZoom_factor());
Expand Down Expand Up @@ -812,24 +838,24 @@ private void settings_menuActionPerformed(java.awt.event.ActionEvent evt) {//GEN
_main_panel.setMega_proxy_server(null);
}

if (this.getMain_panel().isUse_smart_proxy()) {
if (MainPanel.isUse_smart_proxy()) {

if (this.getMain_panel().getProxy_manager() == null) {
if (MainPanel.getProxy_manager() == null) {

this.getMain_panel().setProxy_manager(new SmartMegaProxyManager(this.getMain_panel(), this.getMain_panel().getUse_smart_proxy_url()));
this.getMain_panel().setProxy_manager(new SmartMegaProxyManager(this.getMain_panel(), MainPanel.getUse_smart_proxy_url()));

THREAD_POOL.execute(this.getMain_panel().getProxy_manager());
THREAD_POOL.execute(MainPanel.getProxy_manager());

} else if (!this.getMain_panel().getProxy_manager().getProxy_list_url().equals(this.getMain_panel().getUse_smart_proxy_url())) {
this.getMain_panel().getProxy_manager().setProxy_list_url(this.getMain_panel().getUse_smart_proxy_url());
} else if (!MainPanel.getProxy_manager().getProxy_list_url().equals(MainPanel.getUse_smart_proxy_url())) {
MainPanel.getProxy_manager().setProxy_list_url(MainPanel.getUse_smart_proxy_url());
}

} else if (this.getMain_panel().getProxy_manager() != null) {
} else if (MainPanel.getProxy_manager() != null) {

this.getMain_panel().getProxy_manager().setExit(true);
MainPanel.getProxy_manager().setExit(true);

synchronized (this.getMain_panel().getProxy_manager().getRefresh_lock()) {
this.getMain_panel().getProxy_manager().getRefresh_lock().notify();
synchronized (MainPanel.getProxy_manager().getRefresh_lock()) {
MainPanel.getProxy_manager().getRefresh_lock().notify();
}

this.getMain_panel().setProxy_manager(null);
Expand Down
Loading

0 comments on commit e483527

Please sign in to comment.