mirror of
https://github.com/tonikelope/megabasterd.git
synced 2025-04-29 22:24:32 +02:00
8.6
Folder tree cache (optional) while MegaBasterd is running in order to speed up very (VEEEERY) big file folders.
This commit is contained in:
parent
acc52fdae0
commit
af6ee90df0
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.tonikelope</groupId>
|
<groupId>com.tonikelope</groupId>
|
||||||
<artifactId>MegaBasterd</artifactId>
|
<artifactId>MegaBasterd</artifactId>
|
||||||
<version>8.5</version>
|
<version>8.6</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
|
@ -430,6 +430,19 @@ public class FolderLinkDialog extends javax.swing.JDialog {
|
|||||||
|
|
||||||
String folder_id = findFirstRegex("#F!([^!]+)", _link, 1);
|
String folder_id = findFirstRegex("#F!([^!]+)", _link, 1);
|
||||||
|
|
||||||
|
int r = -1;
|
||||||
|
|
||||||
|
if (ma.existsCachedFolderNodes(folder_id)) {
|
||||||
|
r = JOptionPane.showConfirmDialog(this, "Do you want to use FOLDER CACHED VERSION?\n\n(It could speed up the loading of very large folders)", "FOLDER CACHE", JOptionPane.YES_NO_OPTION);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (r == 0) {
|
||||||
|
MiscTools.GUIRun(() -> {
|
||||||
|
folder_link_label.setText(_link + " (CACHED VERSION)");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
String subfolder_id = null;
|
String subfolder_id = null;
|
||||||
|
|
||||||
if (folder_id.contains("@")) {
|
if (folder_id.contains("@")) {
|
||||||
@ -443,7 +456,7 @@ public class FolderLinkDialog extends javax.swing.JDialog {
|
|||||||
|
|
||||||
String folder_key = findFirstRegex("#F![^!]+!(.+)", _link, 1);
|
String folder_key = findFirstRegex("#F![^!]+!(.+)", _link, 1);
|
||||||
|
|
||||||
folder_nodes = ma.getFolderNodes(folder_id, folder_key, node_bar);
|
folder_nodes = ma.getFolderNodes(folder_id, folder_key, node_bar, (r == 0));
|
||||||
|
|
||||||
MegaMutableTreeNode root = null;
|
MegaMutableTreeNode root = null;
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ import javax.swing.UIManager;
|
|||||||
*/
|
*/
|
||||||
public final class MainPanel {
|
public final class MainPanel {
|
||||||
|
|
||||||
public static final String VERSION = "8.5";
|
public static final String VERSION = "8.6";
|
||||||
public static final boolean FORCE_SMART_PROXY = false; //TRUE FOR DEBUGING SMART PROXY
|
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 THROTTLE_SLICE_SIZE = 16 * 1024;
|
||||||
public static final int DEFAULT_BYTE_BUFFER_SIZE = 16 * 1024;
|
public static final int DEFAULT_BYTE_BUFFER_SIZE = 16 * 1024;
|
||||||
@ -924,6 +924,8 @@ public final class MainPanel {
|
|||||||
|
|
||||||
public void byebyenow(boolean restart) {
|
public void byebyenow(boolean restart) {
|
||||||
|
|
||||||
|
MiscTools.purgeFolderCache();
|
||||||
|
|
||||||
synchronized (DBTools.class) {
|
synchronized (DBTools.class) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -26,6 +26,7 @@ import java.net.MalformedURLException;
|
|||||||
import java.net.Proxy;
|
import java.net.Proxy;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -1049,15 +1050,62 @@ public class MegaAPI implements Serializable {
|
|||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<String, Object> getFolderNodes(String folder_id, String folder_key, JProgressBar bar) throws Exception {
|
public boolean existsCachedFolderNodes(String folder_id) {
|
||||||
|
return Files.exists(Path.of(System.getProperty("java.io.tmpdir") + File.separator + "megabasterd_folder_cache_" + folder_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getCachedFolderNodes(String folder_id) {
|
||||||
|
|
||||||
|
String file_path = System.getProperty("java.io.tmpdir") + File.separator + "megabasterd_folder_cache_" + folder_id;
|
||||||
|
|
||||||
|
if (Files.exists(Path.of(file_path))) {
|
||||||
|
|
||||||
|
LOG.log(Level.INFO, "MEGA FOLDER {0} USING CACHED JSON FILE TREE", new Object[]{folder_id});
|
||||||
|
|
||||||
|
try {
|
||||||
|
return Files.readString(Path.of(file_path));
|
||||||
|
} catch (IOException ex) {
|
||||||
|
Logger.getLogger(MegaAPI.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeCachedFolderNodes(String folder_id, String res) {
|
||||||
|
String file_path = System.getProperty("java.io.tmpdir") + File.separator + "megabasterd_folder_cache_" + folder_id;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Files.writeString(Path.of(file_path), res);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
Logger.getLogger(MegaAPI.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<String, Object> getFolderNodes(String folder_id, String folder_key, JProgressBar bar, boolean cache) throws Exception {
|
||||||
|
|
||||||
HashMap<String, Object> folder_nodes = null;
|
HashMap<String, Object> folder_nodes = null;
|
||||||
|
|
||||||
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) {
|
if (res != null) {
|
||||||
|
|
||||||
|
@ -156,6 +156,17 @@ public class MiscTools {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void purgeFolderCache() {
|
||||||
|
File directory = new File(System.getProperty("java.io.tmpdir"));
|
||||||
|
|
||||||
|
for (File f : directory.listFiles()) {
|
||||||
|
if (f.isFile() && f.getName().startsWith("megabasterd_folder_cache_")) {
|
||||||
|
f.delete();
|
||||||
|
Logger.getLogger(MiscTools.class.getName()).log(Level.INFO, "REMOVING FOLDER CACHE FILE {0}", f.getAbsolutePath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void containerSetEnabled(Container panel, boolean enabled) {
|
public static void containerSetEnabled(Container panel, boolean enabled) {
|
||||||
|
|
||||||
for (Component cp : panel.getComponents()) {
|
for (Component cp : panel.getComponents()) {
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 205 KiB After Width: | Height: | Size: 207 KiB |
Loading…
x
Reference in New Issue
Block a user