Skip to content

Commit

Permalink
8.7
Browse files Browse the repository at this point in the history
Folder cache for subfolders fix
  • Loading branch information
tonikelope committed Oct 26, 2023
1 parent af6ee90 commit 1610b3b
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 23 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>8.6</version>
<version>8.7</version>
<packaging>jar</packaging>
<repositories>
<repository>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ public class FileGrabberDialog extends javax.swing.JDialog {
private int _last_selected_index;
private List<File> _drag_drop_files;

@Override
public void dispose() {
file_tree.setModel(null);
super.dispose();
}

public JCheckBox getPriority_checkbox() {
return priority_checkbox;
}
Expand Down
28 changes: 17 additions & 11 deletions src/main/java/com/tonikelope/megabasterd/FolderLinkDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public class FolderLinkDialog extends javax.swing.JDialog {

private volatile boolean exit = false;

@Override
public void dispose() {
file_tree.setModel(null);
super.dispose();
}

public List<HashMap> getDownload_links() {
return Collections.unmodifiableList(_download_links);
}
Expand Down Expand Up @@ -430,6 +436,17 @@ private int _loadMegaDirTree() {

String folder_id = findFirstRegex("#F!([^!]+)", _link, 1);

String subfolder_id = null;

if (folder_id.contains("@")) {

String[] fids = folder_id.split("@");

folder_id = fids[0];

subfolder_id = fids[1];
}

int r = -1;

if (ma.existsCachedFolderNodes(folder_id)) {
Expand All @@ -443,17 +460,6 @@ private int _loadMegaDirTree() {
});
}

String subfolder_id = null;

if (folder_id.contains("@")) {

String[] fids = folder_id.split("@");

folder_id = fids[0];

subfolder_id = fids[1];
}

String folder_key = findFirstRegex("#F![^!]+!(.+)", _link, 1);

folder_nodes = ma.getFolderNodes(folder_id, folder_key, node_bar, (r == 0));
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/com/tonikelope/megabasterd/MainPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
*/
public final class MainPanel {

public static final String VERSION = "8.6";
public static final String VERSION = "8.7";
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 @@ -393,11 +393,6 @@ public MainPanel() {

resumeUploads();

/* NOT REQUIRED
if (MegaAPI.API_KEY == null && JOptionPane.showConfirmDialog(this._view, LabelTranslatorSingleton.getInstance().translate("WARNING: USING MEGA API WITHOUT API KEY MAY VIOLATE ITS TERM OF USE.\n\nYOU SHOULD GET A KEY -> https://mega.nz/sdk (and set it in MegaBasterd ADVANCED SETTINGS).\n\nCREATE API KEY NOW?"), "MEGA API KEY ERROR", JOptionPane.ERROR_MESSAGE) == 0) {
openBrowserURL("https://mega.nz/sdk");
}*/
}

public static Boolean getResume_uploads() {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/tonikelope/megabasterd/MainPanelView.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ public final class MainPanelView extends javax.swing.JFrame {

private final MainPanel _main_panel;

private static volatile MainPanelView INSTANCE = null;

public static MainPanelView getINSTANCE() {
return INSTANCE;
}

public JMenuItem getMerge_file_menu() {
return merge_file_menu;
}
Expand Down Expand Up @@ -539,6 +545,7 @@ private void changeToNormal() {
pack();
});

INSTANCE = this;
}

/**
Expand Down
32 changes: 27 additions & 5 deletions src/main/java/com/tonikelope/megabasterd/MegaAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.zip.GZIPInputStream;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLException;
import javax.swing.JOptionPane;
import javax.swing.JProgressBar;

/**
Expand Down Expand Up @@ -1232,8 +1233,14 @@ public ArrayList<String> GENERATE_N_LINKS(Set<String> links) {

String[] folder_parts = entry.getKey().split(":");

int r = -1;

if (existsCachedFolderNodes(folder_parts[0])) {
r = JOptionPane.showConfirmDialog(MainPanelView.getINSTANCE(), "Do you want to use FOLDER [" + folder_parts[0] + "] CACHED VERSION?\n\n(It could speed up the loading of very large folders)", "FOLDER CACHE", JOptionPane.YES_NO_OPTION);
}

try {
nlinks.addAll(getNLinksFromFolder(folder_parts[0], folder_parts[1], entry.getValue()));
nlinks.addAll(getNLinksFromFolder(folder_parts[0], folder_parts[1], entry.getValue(), (r == 0)));
} catch (Exception ex) {
Logger.getLogger(MegaAPI.class.getName()).log(Level.SEVERE, null, ex);
}
Expand All @@ -1244,15 +1251,30 @@ public ArrayList<String> GENERATE_N_LINKS(Set<String> links) {

}

public ArrayList<String> getNLinksFromFolder(String folder_id, String folder_key, ArrayList<String> file_ids) throws Exception {
public ArrayList<String> getNLinksFromFolder(String folder_id, String folder_key, ArrayList<String> file_ids, boolean cache) throws Exception {

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

String request = "[{\"a\":\"f\", \"c\":\"1\", \"r\":\"1\", \"ca\":\"1\"}]";
String res = null;

URL url_api = new URL(API_URL + "/cs?id=" + String.valueOf(_seqno) + "&n=" + folder_id);
if (cache) {
res = getCachedFolderNodes(folder_id);
}

String res = RAW_REQUEST(request, url_api);
if (res == null) {

String request = "[{\"a\":\"f\", \"c\":\"1\", \"r\":\"1\", \"ca\":\"1\"}]";

URL url_api = new URL(API_URL + "/cs?id=" + String.valueOf(_seqno) + "&n=" + folder_id);

res = RAW_REQUEST(request, url_api);

if (res != null) {
writeCachedFolderNodes(folder_id, res);
}
}

LOG.log(Level.INFO, "MEGA FOLDER {0} JSON FILE TREE SIZE -> {1}", new Object[]{folder_id, MiscTools.formatBytes((long) res.length())});

if (res != null) {

Expand Down
Binary file modified src/main/resources/images/mbasterd_screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1610b3b

Please sign in to comment.