Skip to content

Commit

Permalink
7.41
Browse files Browse the repository at this point in the history
Changes:

#307

#299

Fix EMPTY SUBFOLDERS AND EMPTY FILES
  • Loading branch information
tonikelope committed Jun 13, 2021
1 parent e503ee5 commit dbc4af5
Show file tree
Hide file tree
Showing 9 changed files with 276 additions and 200 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.40</version>
<version>7.41</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
Expand Down
336 changes: 176 additions & 160 deletions src/main/java/com/tonikelope/megabasterd/Download.java

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions src/main/java/com/tonikelope/megabasterd/FolderLinkDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,27 @@ private void _genDownloadLiks() {

_total_space += (long) download_link.get("filesize");

_download_links.add(download_link);
} else if (node.isLeaf() && node != root) {
String path = "";

Object[] object_path = node.getUserObjectPath();

for (Object p : object_path) {

path += File.separator + ((Map<String, Object>) p).get("name");
}

path = path.replaceAll("^/+", "").replaceAll("^\\+", "").trim();

HashMap<String, Object> download_link = new HashMap<>();

download_link.put("url", "*");

download_link.put("filename", cleanFilePath(path));

download_link.put("type", ((HashMap<String, Object>) node.getUserObject()).get("type"));

_download_links.add(download_link);
}
}
Expand Down
32 changes: 15 additions & 17 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.40";
public static final String VERSION = "7.41";
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 All @@ -76,7 +76,7 @@ public final class MainPanel {
public static final String DEFAULT_USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0";
public static final String ICON_FILE = "/images/pica_roja_big.png";
public static final ExecutorService THREAD_POOL = newCachedThreadPool();
private static Boolean _app_image;
public static volatile String MEGABASTERD_HOME_DIR = System.getProperty("user.home");
private static String _proxy_host;
private static int _proxy_port;
private static boolean _use_proxy;
Expand All @@ -101,12 +101,8 @@ public static void main(String args[]) {
UIDefaults defaults = UIManager.getLookAndFeelDefaults();
defaults.put("nimbusOrange", defaults.get("nimbusFocus"));

_app_image = false;

if (args.length > 0) {

_app_image = args[0].equals("appimage");

if (args.length > 1) {
try {
Logger.getLogger(MainPanel.class.getName()).log(Level.INFO, "{0} Waiting {1} seconds before start...", new Object[]{Thread.currentThread().getName(), args[1]});
Expand All @@ -118,6 +114,12 @@ public static void main(String args[]) {

}

File f = new File(getCurrentJarParentPath() + "/.megabasterd_portable");

if (f.exists()) {
MEGABASTERD_HOME_DIR = f.getParentFile().getAbsolutePath();
}

final MainPanel main_panel = new MainPanel();

invokeLater(() -> {
Expand All @@ -133,10 +135,6 @@ public static String getRun_command_path() {
return _run_command_path;
}

public static Boolean getApp_image() {
return _app_image;
}

public static String getFont() {
return _font;
}
Expand Down Expand Up @@ -257,7 +255,7 @@ public MainPanel() {
PrintStream fileOut;

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

System.setOut(fileOut);
System.setErr(fileOut);
Expand Down Expand Up @@ -970,7 +968,7 @@ public void byebyenow(boolean restart, boolean delete_db) {

if (delete_db) {

File db_file = new File(System.getProperty("user.home") + "/.megabasterd" + MainPanel.VERSION + "/" + SqliteSingleton.SQLITE_FILE);
File db_file = new File(MainPanel.MEGABASTERD_HOME_DIR + "/.megabasterd" + MainPanel.VERSION + "/" + SqliteSingleton.SQLITE_FILE);

db_file.delete();

Expand All @@ -995,11 +993,11 @@ private void _check_old_version() {

try {

if (!new File(System.getProperty("user.home") + "/.megabasterd" + MainPanel.VERSION + "/.old_version_check").exists()) {
if (!new File(MainPanel.MEGABASTERD_HOME_DIR + "/.megabasterd" + MainPanel.VERSION + "/.old_version_check").exists()) {

new File(System.getProperty("user.home") + "/.megabasterd" + MainPanel.VERSION + "/.old_version_check").createNewFile();
new File(MainPanel.MEGABASTERD_HOME_DIR + "/.megabasterd" + MainPanel.VERSION + "/.old_version_check").createNewFile();

File directory = new File(System.getProperty("user.home"));
File directory = new File(MainPanel.MEGABASTERD_HOME_DIR);

String version_major = findFirstRegex("([0-9]+)\\.[0-9]+$", VERSION, 1);

Expand All @@ -1011,7 +1009,7 @@ private void _check_old_version() {

String old_version = "0.0";

File old_backups_dir = new File(System.getProperty("user.home") + "/.megabasterd_old_backups");
File old_backups_dir = new File(MainPanel.MEGABASTERD_HOME_DIR + "/.megabasterd_old_backups");

if (!old_backups_dir.exists()) {
old_backups_dir.mkdir();
Expand Down Expand Up @@ -1059,7 +1057,7 @@ private void _check_old_version() {
options[0]);

if (n == 1) {
Files.copy(Paths.get(System.getProperty("user.home") + "/.megabasterd_old_backups/.megabasterd" + old_version + "/" + SqliteSingleton.SQLITE_FILE), Paths.get(System.getProperty("user.home") + "/.megabasterd" + MainPanel.VERSION + "/" + SqliteSingleton.SQLITE_FILE), StandardCopyOption.REPLACE_EXISTING);
Files.copy(Paths.get(MainPanel.MEGABASTERD_HOME_DIR + "/.megabasterd_old_backups/.megabasterd" + old_version + "/" + SqliteSingleton.SQLITE_FILE), Paths.get(MainPanel.MEGABASTERD_HOME_DIR + "/.megabasterd" + MainPanel.VERSION + "/" + SqliteSingleton.SQLITE_FILE), StandardCopyOption.REPLACE_EXISTING);

JOptionPane.showMessageDialog(getView(), LabelTranslatorSingleton.getInstance().translate("MegaBasterd will restart"), LabelTranslatorSingleton.getInstance().translate("Restart required"), JOptionPane.WARNING_MESSAGE);

Expand Down
35 changes: 31 additions & 4 deletions src/main/java/com/tonikelope/megabasterd/MainPanelView.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ private void _new_upload_dialog(FileGrabberDialog dialog) {

if (dialog.getUpload_log_checkbox().isSelected()) {

File upload_log = new File(System.getProperty("user.home") + "/megabasterd_upload_" + parent_node + ".log");
File upload_log = new File(MainPanel.MEGABASTERD_HOME_DIR + "/megabasterd_upload_" + parent_node + ".log");
upload_log.createNewFile();

FileWriter fr;
Expand Down Expand Up @@ -1036,11 +1036,38 @@ private void new_download_menuActionPerformed(java.awt.event.ActionEvent evt) {/

if (!getMain_panel().getDownload_manager().getTransference_preprocess_global_queue().isEmpty()) {

download = new Download(getMain_panel(), ma, (String) folder_link.get("url"), dl_path, (String) folder_link.get("filename"), (String) folder_link.get("filekey"), (long) folder_link.get("filesize"), null, null, getMain_panel().isUse_slots_down(), false, getMain_panel().isUse_custom_chunks_dir() ? getMain_panel().getCustom_chunks_dir() : null, dialog.getPriority_checkbox().isSelected());
if (!((String) folder_link.get("url")).equals("*")) {

getMain_panel().getDownload_manager().getTransference_provision_queue().add(download);
download = new Download(getMain_panel(), ma, (String) folder_link.get("url"), dl_path, (String) folder_link.get("filename"), (String) folder_link.get("filekey"), (long) folder_link.get("filesize"), null, null, getMain_panel().isUse_slots_down(), false, getMain_panel().isUse_custom_chunks_dir() ? getMain_panel().getCustom_chunks_dir() : null, dialog.getPriority_checkbox().isSelected());

getMain_panel().getDownload_manager().secureNotify();
getMain_panel().getDownload_manager().getTransference_provision_queue().add(download);

getMain_panel().getDownload_manager().secureNotify();

} else {
//Directorio vacío
String filename = dl_path + "/" + (String) folder_link.get("filename");

File file = new File(filename);

if (file.getParent() != null) {
File path = new File(file.getParent());

path.mkdirs();
}

if (((int) folder_link.get("type")) == 1) {

file.mkdir();

} else {
try {
file.createNewFile();
} catch (IOException ex) {
Logger.getLogger(MainPanelView.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
} else {
break;
}
Expand Down
42 changes: 28 additions & 14 deletions src/main/java/com/tonikelope/megabasterd/MiscTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.net.MalformedURLException;
import java.net.Proxy;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.ByteBuffer;
Expand All @@ -37,6 +38,7 @@
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.security.CodeSource;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DecimalFormat;
Expand Down Expand Up @@ -1145,27 +1147,39 @@ public static byte[] recReverseArray(byte[] arr, int start, int end) {
}
}

public static void restartApplication() {
public static String getCurrentJarParentPath() {
try {
CodeSource codeSource = MainPanel.class.getProtectionDomain().getCodeSource();

if (!MainPanel.getApp_image()) {
File jarFile = new File(codeSource.getLocation().toURI().getPath());

StringBuilder cmd = new StringBuilder();
return jarFile.getParentFile().getAbsolutePath();

cmd.append(System.getProperty("java.home")).append(File.separator).append("bin").append(File.separator).append("java ");
} catch (URISyntaxException ex) {
Logger.getLogger(MiscTools.class.getName()).log(Level.SEVERE, null, ex);
}

ManagementFactory.getRuntimeMXBean().getInputArguments().forEach((jvmArg) -> {
cmd.append(jvmArg).append(" ");
});
return null;
}

cmd.append("-cp ").append(ManagementFactory.getRuntimeMXBean().getClassPath()).append(" ");
public static void restartApplication() {

cmd.append(MainPanel.class.getName()).append(" native 1");
StringBuilder cmd = new StringBuilder();

try {
Runtime.getRuntime().exec(cmd.toString());
} catch (IOException ex) {
Logger.getLogger(MiscTools.class.getName()).log(Level.SEVERE, ex.getMessage());
}
cmd.append(System.getProperty("java.home")).append(File.separator).append("bin").append(File.separator).append("java ");

ManagementFactory.getRuntimeMXBean().getInputArguments().forEach((jvmArg) -> {
cmd.append(jvmArg).append(" ");
});

cmd.append("-cp ").append(ManagementFactory.getRuntimeMXBean().getClassPath()).append(" ");

cmd.append(MainPanel.class.getName()).append(" native 1");

try {
Runtime.getRuntime().exec(cmd.toString());
} catch (IOException ex) {
Logger.getLogger(MiscTools.class.getName()).log(Level.SEVERE, ex.getMessage());
}

System.exit(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public SettingsDialog(MainPanelView parent, boolean modal) {

String default_download_dir = DBTools.selectSettingValue("default_down_dir");

default_download_dir = Paths.get(default_download_dir == null ? System.getProperty("user.home") : default_download_dir).toAbsolutePath().normalize().toString();
default_download_dir = Paths.get(default_download_dir == null ? MainPanel.MEGABASTERD_HOME_DIR : default_download_dir).toAbsolutePath().normalize().toString();

_download_path = default_download_dir;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/tonikelope/megabasterd/SqliteSingleton.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private SqliteSingleton() {

_connections_map = new ConcurrentHashMap();

File database_path = new File(System.getProperty("user.home") + "/.megabasterd" + MainPanel.VERSION);
File database_path = new File(MainPanel.MEGABASTERD_HOME_DIR + "/.megabasterd" + MainPanel.VERSION);

database_path.mkdirs();
}
Expand All @@ -44,7 +44,7 @@ public Connection getConn() {

Class.forName("org.sqlite.JDBC");

conn = DriverManager.getConnection("jdbc:sqlite:" + System.getProperty("user.home") + "/.megabasterd" + MainPanel.VERSION + "/" + SQLITE_FILE + "?journal_mode=WAL&synchronous=OFF&journal_size_limit=500");
conn = DriverManager.getConnection("jdbc:sqlite:" + MainPanel.MEGABASTERD_HOME_DIR + "/.megabasterd" + MainPanel.VERSION + "/" + SQLITE_FILE + "?journal_mode=WAL&synchronous=OFF&journal_size_limit=500");

_connections_map.put(Thread.currentThread(), conn);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/tonikelope/megabasterd/Upload.java
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ public void run() {

synchronized (this.getMain_panel().getUpload_manager().getLog_file_lock()) {

File upload_log = new File(System.getProperty("user.home") + "/megabasterd_upload_" + _root_node + ".log");
File upload_log = new File(MainPanel.MEGABASTERD_HOME_DIR + "/megabasterd_upload_" + _root_node + ".log");

if (upload_log.exists()) {

Expand Down

0 comments on commit dbc4af5

Please sign in to comment.