Skip to content

Commit

Permalink
7.31
Browse files Browse the repository at this point in the history
#278

-ADVANCED SETTINGS -> DEBUG FILE (default unselected)

#269

- PROVISION THREAD POOL (MAX 50)
- Transfers starts immediately
  • Loading branch information
tonikelope committed Dec 12, 2020
1 parent 033fc36 commit bf2a997
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 84 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>7.30</version>
<version>7.31</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/com/tonikelope/megabasterd/BoundedExecutor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (C) 2020 tonikelope
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.tonikelope.megabasterd;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.Semaphore;

/**
*
* @author tonikelope
*/
public class BoundedExecutor {

private final ExecutorService exec;
private final Semaphore semaphore;

public BoundedExecutor(ExecutorService exec, int bound) {
this.exec = exec;
this.semaphore = new Semaphore(bound);
}

public void submitTask(final Runnable command)
throws InterruptedException {

semaphore.acquire();
try {
exec.execute(new Runnable() {
public void run() {
try {
command.run();
} finally {
semaphore.release();
}
}
});
} catch (RejectedExecutionException e) {

semaphore.release();

}

}
}
44 changes: 28 additions & 16 deletions src/main/java/com/tonikelope/megabasterd/MainPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
*/
public final class MainPanel {

public static final String VERSION = "7.30";
public static final String VERSION = "7.31";
public static final boolean FORCE_SMART_PROXY = false; //TRUE FOR DEBUGING SMART PROXY
public static final int THROTTLE_SLICE_SIZE = 16 * 1024;
public static final int DEFAULT_BYTE_BUFFER_SIZE = 16 * 1024;
Expand Down Expand Up @@ -101,20 +101,6 @@ public static void main(String args[]) {
UIDefaults defaults = UIManager.getLookAndFeelDefaults();
defaults.put("nimbusOrange", defaults.get("nimbusFocus"));

PrintStream fileOut;

try {
fileOut = new PrintStream(new FileOutputStream(System.getProperty("user.home") + "/.MEGABASTERD_DEBUG.log"));

System.setOut(fileOut);
System.setErr(fileOut);

} catch (FileNotFoundException ex) {
Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, null, ex);
}

System.out.println(System.getProperty("os.name") + "" + System.getProperty("java.vm.name") + " " + System.getProperty("java.version") + " " + System.getProperty("java.home"));

_app_image = false;

if (args.length > 0) {
Expand Down Expand Up @@ -201,7 +187,7 @@ public static SmartMegaProxyManager getProxy_manager() {
private final UploadManager _upload_manager;
private final StreamThrottlerSupervisor _stream_supervisor;
private int _max_dl, _max_ul, _default_slots_down, _default_slots_up, _max_dl_speed, _max_up_speed;
private boolean _use_slots_down, _limit_download_speed, _limit_upload_speed, _use_mega_account_down, _init_paused;
private boolean _use_slots_down, _limit_download_speed, _limit_upload_speed, _use_mega_account_down, _init_paused, _debug_file;
private String _mega_account_down;
private String _default_download_path;
private boolean _use_custom_chunks_dir;
Expand Down Expand Up @@ -266,6 +252,23 @@ public MainPanel() {

loadUserSettings();

if (_debug_file) {

PrintStream fileOut;

try {
fileOut = new PrintStream(new FileOutputStream(System.getProperty("user.home") + "/.MEGABASTERD_DEBUG.log"));

System.setOut(fileOut);
System.setErr(fileOut);

} catch (FileNotFoundException ex) {
Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, null, ex);
}
}

System.out.println(System.getProperty("os.name") + "" + System.getProperty("java.vm.name") + " " + System.getProperty("java.version") + " " + System.getProperty("java.home"));

UIManager.put("OptionPane.messageFont", GUI_FONT.deriveFont(15f * getZoom_factor()));

UIManager.put("OptionPane.buttonFont", GUI_FONT.deriveFont(15f * getZoom_factor()));
Expand Down Expand Up @@ -857,6 +860,15 @@ public void loadUserSettings() {
if (_language == null) {
_language = DEFAULT_LANGUAGE;
}

String debug_file = selectSettingValue("debug_file");

if (debug_file != null) {
_debug_file = debug_file.equals("yes");
} else {
_debug_file = false;
}

}

public static synchronized void run_external_command() {
Expand Down
52 changes: 26 additions & 26 deletions src/main/java/com/tonikelope/megabasterd/MiscTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -790,41 +790,41 @@ public static String extractMegaLinksFromString(String data) {
data = extensionURL2NormalLink(data);
}

ArrayList<String> links = new ArrayList<>();
String url_decoded;
try {
url_decoded = URLDecoder.decode(data, "UTF-8");
} catch (Exception ex) {
url_decoded = data;
}
ArrayList<String> base64_chunks = findAllRegex("[A-Za-z0-9+/_-]+=*", url_decoded, 0);
if (!base64_chunks.isEmpty()) {

ArrayList<String> links = new ArrayList<>();

ArrayList<String> base64_chunks = findAllRegex("[A-Za-z0-9+/_-]+=*", URLDecoder.decode(data, "UTF-8"), 0);

if (!base64_chunks.isEmpty()) {

for (String chunk : base64_chunks) {
for (String chunk : base64_chunks) {

try {
try {

String clean_data = MiscTools.newMegaLinks2Legacy(new String(Base64.getDecoder().decode(chunk)));
String clean_data = MiscTools.newMegaLinks2Legacy(new String(Base64.getDecoder().decode(chunk)));

String decoded = MiscTools.findFirstRegex("(?:https?|mega)://[^\r\n]+(#[^\r\n!]*?)?![^\r\n!]+![^\\?\r\n]+", clean_data, 0);
String decoded = MiscTools.findFirstRegex("(?:https?|mega)://[^\r\n]+(#[^\r\n!]*?)?![^\r\n!]+![^\\?\r\n]+", clean_data, 0);

if (decoded != null) {
links.add(decoded);
}
if (decoded != null) {
links.add(decoded);
}

} catch (Exception e) {
};
}
} catch (Exception e) {
};
}

String clean_data = MiscTools.newMegaLinks2Legacy(URLDecoder.decode(data, "UTF-8"));

links.addAll(findAllRegex("(?:https?|mega)://[^\r\n]+(#[^\r\n!]*?)?![^\r\n!]+![^\\?\r\n]+", clean_data, 0));

links.addAll(findAllRegex("mega://e(n|l)c[^\r\n]+", clean_data, 0));

res = links.stream().map((s) -> s + "\n").reduce(res, String::concat);
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(MiscTools.class.getName()).log(Level.SEVERE, ex.getMessage());
}
try {
url_decoded = URLDecoder.decode(data, "UTF-8");
} catch (Exception ex) {
url_decoded = data;
}
String clean_data = MiscTools.newMegaLinks2Legacy(url_decoded);
links.addAll(findAllRegex("(?:https?|mega)://[^\r\n]+(#[^\r\n!]*?)?![^\r\n!]+![^\\?\r\n]+", clean_data, 0));
links.addAll(findAllRegex("mega://e(n|l)c[^\r\n]+", clean_data, 0));
res = links.stream().map((s) -> s + "\n").reduce(res, String::concat);
}

return res.trim();
Expand Down
34 changes: 25 additions & 9 deletions src/main/java/com/tonikelope/megabasterd/SettingsDialog.form
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="panel_tabs" pref="474" max="32767" attributes="0"/>
<Component id="panel_tabs" pref="805" max="32767" attributes="0"/>
<EmptySpace min="-2" pref="18" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Group type="103" groupAlignment="3" attributes="0">
Expand Down Expand Up @@ -799,7 +799,7 @@
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="mega_accounts_scrollpane" pref="89" max="32767" attributes="0"/>
<Component id="mega_accounts_scrollpane" pref="254" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="remove_mega_account_button" alignment="3" min="-2" max="-2" attributes="0"/>
Expand All @@ -808,7 +808,7 @@
<EmptySpace max="-2" attributes="0"/>
<Component id="elc_accounts_label" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="elc_accounts_scrollpane" pref="89" max="32767" attributes="0"/>
<Component id="elc_accounts_scrollpane" pref="255" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="remove_elc_account_button" alignment="3" min="-2" max="-2" attributes="0"/>
Expand Down Expand Up @@ -1047,10 +1047,9 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Component id="run_command_textbox" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jSeparator15" alignment="1" max="32767" attributes="0"/>
<Component id="jSeparator12" alignment="1" max="32767" attributes="0"/>
<Component id="jSeparator1" alignment="0" max="32767" attributes="0"/>
Expand Down Expand Up @@ -1083,9 +1082,11 @@
<Component id="jButton1" max="32767" attributes="0"/>
</Group>
</Group>
<Component id="run_command_textbox" alignment="1" max="32767" attributes="0"/>
<Component id="proxy_panel" alignment="0" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="1" attributes="0">
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="debug_file_checkbox" min="-2" max="-2" attributes="0"/>
<Component id="start_frozen_checkbox" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="custom_chunks_dir_checkbox" alignment="0" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
Expand All @@ -1102,6 +1103,7 @@
</Group>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
<Component id="jSeparator2" alignment="0" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
Expand Down Expand Up @@ -1144,6 +1146,10 @@
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="jSeparator15" min="-2" pref="8" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="debug_file_checkbox" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="jSeparator2" min="-2" pref="10" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="run_command_checkbox" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="run_command_test_button" alignment="3" min="-2" max="-2" attributes="0"/>
Expand All @@ -1154,7 +1160,7 @@
<Component id="proxy_panel" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="rec_zoom_label" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<EmptySpace min="-2" pref="34" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
Expand Down Expand Up @@ -1565,6 +1571,16 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="run_command_test_buttonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JCheckBox" name="debug_file_checkbox">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Dialog" size="18" style="1"/>
</Property>
<Property name="text" type="java.lang.String" value="Save debug info to file"/>
</Properties>
</Component>
<Component class="javax.swing.JSeparator" name="jSeparator2">
</Component>
</SubComponents>
</Container>
</SubComponents>
Expand Down
Loading

0 comments on commit bf2a997

Please sign in to comment.