From d18f7ba9b1b308bbb1bc4b8ba4e7642dfc2f0578 Mon Sep 17 00:00:00 2001 From: aymanmostafa11 Date: Sun, 1 May 2022 06:58:00 +0200 Subject: [PATCH 1/3] Added showing multiple recent folders when choosing download location --- .gitignore | 2 + app/src/main/java/xdman/Config.java | 47 +++++++++++++++++++ .../ui/components/XDMFileSelectionPanel.java | 7 +-- 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index e7b3b83a..5c05d814 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ app/.classpath app/.project app/.settings/* app/target/* +.idea +app/xdman.iml \ No newline at end of file diff --git a/app/src/main/java/xdman/Config.java b/app/src/main/java/xdman/Config.java index 3ef66cec..9b6f96db 100644 --- a/app/src/main/java/xdman/Config.java +++ b/app/src/main/java/xdman/Config.java @@ -7,6 +7,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.ArrayDeque; import xdman.util.Logger; import xdman.util.StringUtils; @@ -54,6 +55,8 @@ public class Config { private boolean noTransparency; private boolean hideTray; private String lastFolder; + private final int maxRecentFoldersCount = 5; + private ArrayDeque recentFolders; private List listeners; private String queueIdFilter; private boolean showVideoListOnlyInBrowser; @@ -141,6 +144,7 @@ public void save() { if (lastFolder != null) { fw.write("lastFolder:" + this.lastFolder + newLine); } + writeRecentFoldersToFile(fw); fw.write("showVideoListOnlyInBrowser:" + this.showVideoListOnlyInBrowser + newLine); fw.write("zoomLevelIndex:" + this.zoomLevelIndex + newLine); @@ -277,6 +281,9 @@ public void load() { } else if (key.equals("zoomLevelIndex")) { this.zoomLevelIndex = Integer.parseInt(val); } + else if (key.equals("recentFolders")){ + readRecentFoldersFromFile(val); + } } } catch (Exception e) { Logger.log(e); @@ -356,6 +363,7 @@ private Config() { this.noTransparency = false; this.hideTray = true; this.listeners = new ArrayList<>(); + this.recentFolders = new ArrayDeque<>(); } @@ -368,6 +376,32 @@ public void createFolders() { getCategoryVideos(); } + private void writeRecentFoldersToFile(FileWriter fw) + { + if (recentFolders.isEmpty()) + return; + try + { + fw.write("recentFolders:"); + for (String recentFolder : recentFolders) + { + fw.write(recentFolder + ","); + } + fw.write("\n"); + } + catch (Exception e) + { + Logger.log(e); + } + + } + private void readRecentFoldersFromFile(String val) + { + String[] folders = val.split(","); + for (String folder: folders) + this.recentFolders.addLast(folder); + } + public static synchronized Config getInstance() { if (_config == null) { _config = new Config(); @@ -881,10 +915,23 @@ public String getLastFolder() { return lastFolder; } + public ArrayDeque getRecentFolders() + { + return recentFolders; + } + public void setLastFolder(String lastFolder) { this.lastFolder = lastFolder; + updateRecentFolders(lastFolder); } + private void updateRecentFolders(String lastFolder) + { + if (recentFolders.size() == maxRecentFoldersCount) + recentFolders.removeLast(); + + recentFolders.addFirst(lastFolder); + } public String getQueueIdFilter() { return queueIdFilter; } diff --git a/app/src/main/java/xdman/ui/components/XDMFileSelectionPanel.java b/app/src/main/java/xdman/ui/components/XDMFileSelectionPanel.java index 790f7e7b..c24baefc 100644 --- a/app/src/main/java/xdman/ui/components/XDMFileSelectionPanel.java +++ b/app/src/main/java/xdman/ui/components/XDMFileSelectionPanel.java @@ -92,9 +92,10 @@ private void initUI() { add(hbox, BorderLayout.EAST); pop = new JPopupMenu(); - if (!StringUtils.isNullOrEmptyOrBlank(Config.getInstance().getLastFolder())) { - pop.add(createMenuItem(Config.getInstance().getLastFolder())); - } + for (String recentFolder : Config.getInstance().getRecentFolders()) + { + pop.add(createMenuItem(recentFolder)); + } pop.add(createMenuItem(Config.getInstance().getDownloadFolder())); if (!Config.getInstance().isForceSingleFolder()) { pop.add(createMenuItem(Config.getInstance().getCategoryDocuments())); From 06114367a4302d75e2d2fcadd1f56f1fe3e16761 Mon Sep 17 00:00:00 2001 From: aymanmostafa11 Date: Tue, 3 May 2022 11:45:07 +0200 Subject: [PATCH 2/3] Fixed not grabbing downloads from AMD driver site --- app/src/main/java/xdman/XDMApp.java | 3 ++- .../downloaders/http/HttpDownloader.java | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/xdman/XDMApp.java b/app/src/main/java/xdman/XDMApp.java index 5ea793f5..ac763938 100644 --- a/app/src/main/java/xdman/XDMApp.java +++ b/app/src/main/java/xdman/XDMApp.java @@ -585,6 +585,7 @@ private void startDownload(String id, HttpMetadata metadata, DownloadEntry ent, if (metadata.getType() == XDMConstants.FTP) { d = new FtpDownloader(id, ent.getTempFolder(), metadata); } else { + HttpDownloader.injectReferrerHeaders(metadata); d = new HttpDownloader(id, ent.getTempFolder(), metadata); } } @@ -1402,4 +1403,4 @@ public ArrayList getVideoItemsList() { public MainWindow getMainWindow() { return mainWindow; } -} \ No newline at end of file +} diff --git a/app/src/main/java/xdman/downloaders/http/HttpDownloader.java b/app/src/main/java/xdman/downloaders/http/HttpDownloader.java index cfecea83..1e72a6c2 100644 --- a/app/src/main/java/xdman/downloaders/http/HttpDownloader.java +++ b/app/src/main/java/xdman/downloaders/http/HttpDownloader.java @@ -119,4 +119,27 @@ public HttpMetadata getMetadata() { return this.metadata; } + public static void injectReferrerHeaders(HttpMetadata metadata) + { + String referrer = getReferrer(metadata.getUrl()); + + if (StringUtils.isNullOrEmpty(referrer)) + return; + + var headers = metadata.getHeaders(); + headers.setValue("referer", referrer); + headers.setValue("origin", referrer); + metadata.setHeaders(headers); + + } + + // should contain different referrers of different sites + private static String getReferrer(String url) + { + if (url.contains("amd")) + return "https://www.amd.com/"; + + return null; + } + } From 7c82672d6d460cde7070c80bd2c538a43353909d Mon Sep 17 00:00:00 2001 From: aymanmostafa11 Date: Tue, 3 May 2022 12:07:48 +0200 Subject: [PATCH 3/3] Revert "Fixed not grabbing downloads from AMD driver site" This reverts commit 06114367a4302d75e2d2fcadd1f56f1fe3e16761. --- app/src/main/java/xdman/XDMApp.java | 3 +-- .../downloaders/http/HttpDownloader.java | 23 ------------------- 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/app/src/main/java/xdman/XDMApp.java b/app/src/main/java/xdman/XDMApp.java index ac763938..5ea793f5 100644 --- a/app/src/main/java/xdman/XDMApp.java +++ b/app/src/main/java/xdman/XDMApp.java @@ -585,7 +585,6 @@ private void startDownload(String id, HttpMetadata metadata, DownloadEntry ent, if (metadata.getType() == XDMConstants.FTP) { d = new FtpDownloader(id, ent.getTempFolder(), metadata); } else { - HttpDownloader.injectReferrerHeaders(metadata); d = new HttpDownloader(id, ent.getTempFolder(), metadata); } } @@ -1403,4 +1402,4 @@ public ArrayList getVideoItemsList() { public MainWindow getMainWindow() { return mainWindow; } -} +} \ No newline at end of file diff --git a/app/src/main/java/xdman/downloaders/http/HttpDownloader.java b/app/src/main/java/xdman/downloaders/http/HttpDownloader.java index 1e72a6c2..cfecea83 100644 --- a/app/src/main/java/xdman/downloaders/http/HttpDownloader.java +++ b/app/src/main/java/xdman/downloaders/http/HttpDownloader.java @@ -119,27 +119,4 @@ public HttpMetadata getMetadata() { return this.metadata; } - public static void injectReferrerHeaders(HttpMetadata metadata) - { - String referrer = getReferrer(metadata.getUrl()); - - if (StringUtils.isNullOrEmpty(referrer)) - return; - - var headers = metadata.getHeaders(); - headers.setValue("referer", referrer); - headers.setValue("origin", referrer); - metadata.setHeaders(headers); - - } - - // should contain different referrers of different sites - private static String getReferrer(String url) - { - if (url.contains("amd")) - return "https://www.amd.com/"; - - return null; - } - }