native messaging for linux and mac
This commit is contained in:
parent
170dd232a1
commit
77755166ad
14
app/pom.xml
14
app/pom.xml
@ -37,6 +37,20 @@
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/net.java.dev.jna/jna -->
|
||||
<dependency>
|
||||
<groupId>net.java.dev.jna</groupId>
|
||||
<artifactId>jna</artifactId>
|
||||
<version>5.5.0</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/net.java.dev.jna/jna-platform -->
|
||||
<dependency>
|
||||
<groupId>net.java.dev.jna</groupId>
|
||||
<artifactId>jna-platform</artifactId>
|
||||
<version>5.5.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId>
|
||||
<version>3.8.1</version> <scope>test</scope> </dependency> -->
|
||||
</dependencies>
|
||||
|
@ -54,14 +54,14 @@ import xdman.util.FFmpegDownloader;
|
||||
import xdman.util.LinuxUtils;
|
||||
import xdman.util.Logger;
|
||||
import xdman.util.MacUtils;
|
||||
import xdman.util.NativeMessagingHostInstaller;
|
||||
import xdman.util.ParamUtils;
|
||||
import xdman.util.StringUtils;
|
||||
import xdman.util.UpdateChecker;
|
||||
import xdman.util.WinUtils;
|
||||
import xdman.util.XDMUtils;
|
||||
|
||||
public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
Comparator<String> {
|
||||
public class XDMApp implements DownloadListener, DownloadWindowListener, Comparator<String> {
|
||||
public static final String GLOBAL_LOCK_FILE = ".xdm-global-lock";
|
||||
public static final String APP_VERSION = "7.2.10";
|
||||
public static final String XDM_WINDOW_TITLE = "XDM 2020";
|
||||
@ -114,13 +114,12 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
}
|
||||
});
|
||||
if (Config.getInstance().isFirstRun()) {
|
||||
if (XDMUtils.detectOS() == XDMUtils.WINDOWS) {
|
||||
if (!XDMUtils.isAlreadyAutoStart()) {
|
||||
XDMUtils.addToStartup();
|
||||
}
|
||||
} else {
|
||||
if (XDMUtils.detectOS() != XDMUtils.WINDOWS) {
|
||||
XDMUtils.addToStartup();
|
||||
}
|
||||
NativeMessagingHostInstaller.installNativeMessagingHostForChrome();
|
||||
NativeMessagingHostInstaller.installNativeMessagingHostForFireFox();
|
||||
NativeMessagingHostInstaller.installNativeMessagingHostForChromium();
|
||||
}
|
||||
Logger.log("instance started.");
|
||||
}
|
||||
@ -251,16 +250,14 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
downloadWindows.remove(id);
|
||||
if (ent.isStartedByUser()) {
|
||||
if (Config.getInstance().showDownloadCompleteWindow()) {
|
||||
new DownloadCompleteWnd(ent.getFile(), getFolder(ent))
|
||||
.setVisible(true);
|
||||
new DownloadCompleteWnd(ent.getFile(), getFolder(ent)).setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
notifyListeners(null);
|
||||
saveDownloadList();
|
||||
if (Config.getInstance().isExecAntivir()) {
|
||||
if (!StringUtils.isNullOrEmptyOrBlank(
|
||||
Config.getInstance().getAntivirExe())) {
|
||||
if (!StringUtils.isNullOrEmptyOrBlank(Config.getInstance().getAntivirExe())) {
|
||||
execAntivir();
|
||||
}
|
||||
}
|
||||
@ -353,8 +350,7 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
ent.setSize(d.getSize());
|
||||
ent.setDownloaded(d.getDownloaded());
|
||||
ent.setProgress(d.getProgress());
|
||||
ent.setState(d.isAssembling() ? XDMConstants.ASSEMBLING
|
||||
: XDMConstants.DOWNLOADING);
|
||||
ent.setState(d.isAssembling() ? XDMConstants.ASSEMBLING : XDMConstants.DOWNLOADING);
|
||||
DownloadWindow wnd = downloadWindows.get(id);
|
||||
if (wnd != null) {
|
||||
wnd.update(d, ent.getFile());
|
||||
@ -437,32 +433,27 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
} else {
|
||||
String downloadFolderPath;
|
||||
if (Config.getInstance().isForceSingleFolder()) {
|
||||
downloadFolderPath = Config.getInstance()
|
||||
.getDownloadFolder();
|
||||
downloadFolderPath = Config.getInstance().getDownloadFolder();
|
||||
} else {
|
||||
var category = XDMUtils.findCategory(file);
|
||||
downloadFolderPath = XDMApp.getInstance()
|
||||
.getFolder(category);
|
||||
downloadFolderPath = XDMApp.getInstance().getFolder(category);
|
||||
}
|
||||
|
||||
if (parentPath != null) {
|
||||
folderPath = Paths.get(downloadFolderPath,
|
||||
parentPath.toString()).toString();
|
||||
folderPath = Paths.get(downloadFolderPath, parentPath.toString()).toString();
|
||||
} else {
|
||||
folderPath = downloadFolderPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (metadata != null && (Config.getInstance().isQuietMode()
|
||||
|| Config.getInstance().isDownloadAutoStart())) {
|
||||
createDownload(fileName, folderPath, metadata, true, "", 0,
|
||||
0);
|
||||
if (metadata != null
|
||||
&& (Config.getInstance().isQuietMode() || Config.getInstance().isDownloadAutoStart())) {
|
||||
createDownload(fileName, folderPath, metadata, true, "", 0, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
new NewDownloadWindow(metadata, fileName, folderPath)
|
||||
.setVisible(true);
|
||||
new NewDownloadWindow(metadata, fileName, folderPath).setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -477,9 +468,7 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
@Override
|
||||
public void run() {
|
||||
if (!XDMUtils.isFFmpegInstalled()) {
|
||||
if (JOptionPane.showConfirmDialog(null,
|
||||
StringResource
|
||||
.get("MSG_INSTALL_ADDITIONAL_COMPONENTS"),
|
||||
if (JOptionPane.showConfirmDialog(null, StringResource.get("MSG_INSTALL_ADDITIONAL_COMPONENTS"),
|
||||
StringResource.get("MSG_COMPONENT_TITLE"),
|
||||
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
|
||||
FFmpegDownloader fd = new FFmpegDownloader();
|
||||
@ -492,9 +481,8 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
});
|
||||
}
|
||||
|
||||
public void addMedia(final HttpMetadata metadata, final String file,
|
||||
final String info) {
|
||||
System.out.println("video notification: "+Config.getInstance().isShowVideoNotification());
|
||||
public void addMedia(final HttpMetadata metadata, final String file, final String info) {
|
||||
System.out.println("video notification: " + Config.getInstance().isShowVideoNotification());
|
||||
if (Config.getInstance().isShowVideoNotification()) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
@ -520,9 +508,8 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
}
|
||||
}
|
||||
|
||||
public void createDownload(String file, String folder,
|
||||
HttpMetadata metadata, boolean now, String queueId, int formatIndex,
|
||||
int streamIndex) {
|
||||
public void createDownload(String file, String folder, HttpMetadata metadata, boolean now, String queueId,
|
||||
int formatIndex, int streamIndex) {
|
||||
metadata.save();
|
||||
DownloadEntry ent = new DownloadEntry();
|
||||
ent.setId(metadata.getId());
|
||||
@ -540,8 +527,7 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
if (!now) {
|
||||
DownloadQueue q = qMgr.getQueueById(queueId);
|
||||
if (q != null && q.isRunning()) {
|
||||
Logger.log(
|
||||
"Queue is running, if no pending download pickup next available download");
|
||||
Logger.log("Queue is running, if no pending download pickup next available download");
|
||||
q.next();
|
||||
}
|
||||
}
|
||||
@ -552,11 +538,9 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
}
|
||||
|
||||
// could be new or resume
|
||||
private void startDownload(String id, HttpMetadata metadata,
|
||||
DownloadEntry ent, int streams) {
|
||||
private void startDownload(String id, HttpMetadata metadata, DownloadEntry ent, int streams) {
|
||||
if (!checkAndBufferRequests(id)) {
|
||||
Logger.log("starting " + id + " with: " + metadata + " is dash: "
|
||||
+ (metadata instanceof DashMetadata));
|
||||
Logger.log("starting " + id + " with: " + metadata + " is dash: " + (metadata instanceof DashMetadata));
|
||||
Downloader d = null;
|
||||
|
||||
if (metadata instanceof DashMetadata) {
|
||||
@ -577,13 +561,11 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
}
|
||||
if (metadata instanceof HlsMetadata) {
|
||||
Logger.log("Hls download created");
|
||||
d = new HlsDownloader(id, ent.getTempFolder(),
|
||||
(HlsMetadata) metadata);
|
||||
d = new HlsDownloader(id, ent.getTempFolder(), (HlsMetadata) metadata);
|
||||
}
|
||||
if (metadata instanceof HdsMetadata) {
|
||||
Logger.log("Hds download created");
|
||||
d = new HdsDownloader(id, ent.getTempFolder(),
|
||||
(HdsMetadata) metadata);
|
||||
d = new HdsDownloader(id, ent.getTempFolder(), (HdsMetadata) metadata);
|
||||
}
|
||||
if (d == null) {
|
||||
if (metadata.getType() == XDMConstants.FTP) {
|
||||
@ -599,15 +581,13 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
ent.setState(XDMConstants.DOWNLOADING);
|
||||
d.start();
|
||||
|
||||
if (!Config.getInstance().isQuietMode()
|
||||
&& Config.getInstance().showDownloadWindow()) {
|
||||
if (!Config.getInstance().isQuietMode() && Config.getInstance().showDownloadWindow()) {
|
||||
DownloadWindow wnd = new DownloadWindow(id, this);
|
||||
downloadWindows.put(id, wnd);
|
||||
wnd.setVisible(true);
|
||||
}
|
||||
} else {
|
||||
Logger.log(
|
||||
id + ": Maximum download limit reached, queueing request");
|
||||
Logger.log(id + ": Maximum download limit reached, queueing request");
|
||||
}
|
||||
}
|
||||
|
||||
@ -622,13 +602,11 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
public void resumeDownload(String id, boolean startedByUser) {
|
||||
DownloadEntry ent = downloads.get(id);
|
||||
ent.setStartedByUser(startedByUser);
|
||||
if (ent.getState() == XDMConstants.PAUSED
|
||||
|| ent.getState() == XDMConstants.FAILED) {
|
||||
if (ent.getState() == XDMConstants.PAUSED || ent.getState() == XDMConstants.FAILED) {
|
||||
if (!checkAndBufferRequests(id)) {
|
||||
ent.setState(XDMConstants.DOWNLOADING);
|
||||
HttpMetadata metadata = HttpMetadata.load(id);
|
||||
if (!Config.getInstance().isQuietMode()
|
||||
&& Config.getInstance().showDownloadWindow()
|
||||
if (!Config.getInstance().isQuietMode() && Config.getInstance().showDownloadWindow()
|
||||
&& ent.isStartedByUser()) {
|
||||
DownloadWindow wnd = new DownloadWindow(id, this);
|
||||
downloadWindows.put(id, wnd);
|
||||
@ -637,8 +615,7 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
Downloader d = null;
|
||||
if (metadata instanceof DashMetadata) {
|
||||
DashMetadata dm = (DashMetadata) metadata;
|
||||
Logger.log("Dash download- url1: " + dm.getUrl() + " url2: "
|
||||
+ dm.getUrl2());
|
||||
Logger.log("Dash download- url1: " + dm.getUrl() + " url2: " + dm.getUrl2());
|
||||
d = new DashDownloader(id, ent.getTempFolder(), dm);
|
||||
}
|
||||
if (metadata instanceof HlsMetadata) {
|
||||
@ -654,11 +631,9 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
if (d == null) {
|
||||
Logger.log("normal download");
|
||||
if (metadata.getType() == XDMConstants.FTP) {
|
||||
d = new FtpDownloader(id, ent.getTempFolder(),
|
||||
metadata);
|
||||
d = new FtpDownloader(id, ent.getTempFolder(), metadata);
|
||||
} else {
|
||||
d = new HttpDownloader(id, ent.getTempFolder(),
|
||||
metadata);
|
||||
d = new HttpDownloader(id, ent.getTempFolder(), metadata);
|
||||
}
|
||||
}
|
||||
downloaders.put(id, d);
|
||||
@ -667,8 +642,7 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
d.resume();
|
||||
|
||||
} else {
|
||||
Logger.log(id
|
||||
+ ": Maximum download limit reached, queueing request");
|
||||
Logger.log(id + ": Maximum download limit reached, queueing request");
|
||||
}
|
||||
notifyListeners(null);
|
||||
}
|
||||
@ -676,8 +650,7 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
|
||||
public void restartDownload(String id) {
|
||||
DownloadEntry ent = downloads.get(id);
|
||||
if (ent.getState() == XDMConstants.PAUSED
|
||||
|| ent.getState() == XDMConstants.FAILED
|
||||
if (ent.getState() == XDMConstants.PAUSED || ent.getState() == XDMConstants.FAILED
|
||||
|| ent.getState() == XDMConstants.FINISHED) {
|
||||
ent.setState(XDMConstants.PAUSED);
|
||||
clearData(ent);
|
||||
@ -709,19 +682,15 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
return downloads.get(id);
|
||||
}
|
||||
|
||||
public ArrayList<String> getDownloadList(int category, int state,
|
||||
String searchText, String queueId) {
|
||||
public ArrayList<String> getDownloadList(int category, int state, String searchText, String queueId) {
|
||||
ArrayList<String> idList = new ArrayList<String>();
|
||||
Iterator<String> keyIterator = downloads.keySet().iterator();
|
||||
while (keyIterator.hasNext()) {
|
||||
String key = keyIterator.next();
|
||||
DownloadEntry ent = downloads.get(key);
|
||||
if (state == XDMConstants.ALL
|
||||
|| state == (ent.getState() == XDMConstants.FINISHED
|
||||
? XDMConstants.FINISHED
|
||||
: XDMConstants.UNFINISHED)) {
|
||||
if (category == XDMConstants.ALL
|
||||
|| category == ent.getCategory()) {
|
||||
if (state == XDMConstants.ALL || state == (ent.getState() == XDMConstants.FINISHED ? XDMConstants.FINISHED
|
||||
: XDMConstants.UNFINISHED)) {
|
||||
if (category == XDMConstants.ALL || category == ent.getCategory()) {
|
||||
boolean matched = false;
|
||||
if (!"ALL".equals(queueId)) {
|
||||
if (queueId != null) {
|
||||
@ -808,8 +777,7 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
}
|
||||
|
||||
private void loadDownloadList() {
|
||||
File file = new File(Config.getInstance().getDataFolder(),
|
||||
"downloads.txt");
|
||||
File file = new File(Config.getInstance().getDataFolder(), "downloads.txt");
|
||||
loadDownloadList(file);
|
||||
}
|
||||
|
||||
@ -817,11 +785,10 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat(
|
||||
"yyyy-MM-dd HH:mm:ss");
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
// BufferedReader reader = null;
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(
|
||||
new FileInputStream(file), Charset.forName("UTF-8")))) {
|
||||
try (BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8")))) {
|
||||
// reader = new BufferedReader(new InputStreamReader(new
|
||||
// FileInputStream(file),
|
||||
// Charset.forName("UTF-8")));
|
||||
@ -831,8 +798,7 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
}
|
||||
int count = Integer.parseInt(line.trim());
|
||||
for (int i = 0; i < count; i++) {
|
||||
int fieldCount = Integer
|
||||
.parseInt(XDMUtils.readLineSafe(reader).trim());
|
||||
int fieldCount = Integer.parseInt(XDMUtils.readLineSafe(reader).trim());
|
||||
DownloadEntry ent = new DownloadEntry();
|
||||
for (int j = 0; j < fieldCount; j++) {
|
||||
String ln = reader.readLine();
|
||||
@ -854,8 +820,7 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
}
|
||||
if (key.equals("state")) {
|
||||
int state = Integer.parseInt(val);
|
||||
ent.setState(state == XDMConstants.FINISHED ? state
|
||||
: XDMConstants.PAUSED);
|
||||
ent.setState(state == XDMConstants.FINISHED ? state : XDMConstants.PAUSED);
|
||||
}
|
||||
if (key.equals("folder")) {
|
||||
ent.setFolder(val);
|
||||
@ -893,20 +858,17 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
}
|
||||
|
||||
private void saveDownloadList() {
|
||||
File file = new File(Config.getInstance().getDataFolder(),
|
||||
"downloads.txt");
|
||||
File file = new File(Config.getInstance().getDataFolder(), "downloads.txt");
|
||||
saveDownloadList(file);
|
||||
}
|
||||
|
||||
public void saveDownloadList(File file) {
|
||||
int count = downloads.size();
|
||||
BufferedWriter writer = null;
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat(
|
||||
"yyyy-MM-dd HH:mm:ss");
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String newLine = System.getProperty("line.separator");
|
||||
try {
|
||||
writer = new BufferedWriter(new OutputStreamWriter(
|
||||
new FileOutputStream(file), Charset.forName("UTF-8")));
|
||||
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), Charset.forName("UTF-8")));
|
||||
writer.write(count + "");
|
||||
writer.newLine();
|
||||
Iterator<String> keyIterator = downloads.keySet().iterator();
|
||||
@ -927,8 +889,7 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
sb.append("folder: " + ent.getFolder() + newLine);
|
||||
c++;
|
||||
}
|
||||
sb.append("date: " + dateFormat.format(new Date(ent.getDate()))
|
||||
+ newLine);
|
||||
sb.append("date: " + dateFormat.format(new Date(ent.getDate())) + newLine);
|
||||
c++;
|
||||
sb.append("downloaded: " + ent.getDownloaded() + newLine);
|
||||
c++;
|
||||
@ -944,8 +905,7 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
sb.append("queueid: " + ent.getQueueId() + newLine);
|
||||
c++;
|
||||
}
|
||||
sb.append(
|
||||
"formatIndex: " + ent.getOutputFormatIndex() + newLine);
|
||||
sb.append("formatIndex: " + ent.getOutputFormatIndex() + newLine);
|
||||
c++;
|
||||
writer.write(c + newLine);
|
||||
writer.write(sb.toString());
|
||||
@ -977,8 +937,7 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
String key = keyIterator.next();
|
||||
DownloadEntry ent = downloads.get(key);
|
||||
int state = ent.getState();
|
||||
if (state == XDMConstants.FINISHED || state == XDMConstants.PAUSED
|
||||
|| state == XDMConstants.FAILED)
|
||||
if (state == XDMConstants.FINISHED || state == XDMConstants.PAUSED || state == XDMConstants.FAILED)
|
||||
continue;
|
||||
count++;
|
||||
}
|
||||
@ -987,10 +946,8 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
|
||||
private synchronized boolean checkAndBufferRequests(String id) {
|
||||
int actCount = getActiveDownloadCount();
|
||||
if (Config.getInstance().getMaxDownloads() > 0
|
||||
&& actCount >= Config.getInstance().getMaxDownloads()) {
|
||||
Logger.log("active: " + actCount + " max: "
|
||||
+ Config.getInstance().getMaxDownloads());
|
||||
if (Config.getInstance().getMaxDownloads() > 0 && actCount >= Config.getInstance().getMaxDownloads()) {
|
||||
Logger.log("active: " + actCount + " max: " + Config.getInstance().getMaxDownloads());
|
||||
if (!pendingDownloads.contains(id)) {
|
||||
pendingDownloads.add(id);
|
||||
}
|
||||
@ -1023,8 +980,7 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
int maxDownloadCount = Config.getInstance().getMaxDownloads();
|
||||
List<String> tobeStartedIds = new ArrayList<String>();
|
||||
if (maxDownloadCount - activeCount > 0) {
|
||||
for (int i = 0; i < Math.min(maxDownloadCount,
|
||||
pendingDownloads.size()); i++) {
|
||||
for (int i = 0; i < Math.min(maxDownloadCount, pendingDownloads.size()); i++) {
|
||||
String ent = pendingDownloads.get(i);
|
||||
tobeStartedIds.add(ent);
|
||||
}
|
||||
@ -1112,8 +1068,7 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
if (pendingDownloads.size() != 0) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < QueueManager.getInstance().getQueueList()
|
||||
.size(); i++) {
|
||||
for (int i = 0; i < QueueManager.getInstance().getQueueList().size(); i++) {
|
||||
DownloadQueue q = QueueManager.getInstance().getQueueList().get(i);
|
||||
if (q.hasPendingItems()) {
|
||||
return false;
|
||||
@ -1140,8 +1095,7 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
String id = ids.get(i);
|
||||
DownloadEntry ent = getEntry(id);
|
||||
if (ent != null) {
|
||||
if (ent.getState() == XDMConstants.FINISHED
|
||||
|| ent.getState() == XDMConstants.PAUSED
|
||||
if (ent.getState() == XDMConstants.FINISHED || ent.getState() == XDMConstants.PAUSED
|
||||
|| ent.getState() == XDMConstants.FAILED) {
|
||||
this.downloads.remove(id);
|
||||
if (pendingDownloads.contains(id)) {
|
||||
@ -1186,8 +1140,7 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
deleted = df.delete();
|
||||
Logger.log("Deleted tmp folder " + id + " " + deleted);
|
||||
if (outfile) {
|
||||
File f = new File(XDMApp.getInstance().getFolder(ent),
|
||||
ent.getFile());
|
||||
File f = new File(XDMApp.getInstance().getFolder(ent), ent.getFile());
|
||||
f.delete();
|
||||
}
|
||||
}
|
||||
@ -1245,8 +1198,7 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
if (proxy) {
|
||||
Config.getInstance().setProxyUser(pauth.getUserName());
|
||||
if (pauth.getPassword() != null) {
|
||||
Config.getInstance()
|
||||
.setProxyPass(new String(pauth.getPassword()));
|
||||
Config.getInstance().setProxyPass(new String(pauth.getPassword()));
|
||||
}
|
||||
} else {
|
||||
Logger.log("saving password for: " + msg);
|
||||
@ -1269,33 +1221,27 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
obj[3] = StringResource.get("DESC_PASS");
|
||||
obj[4] = pass;
|
||||
|
||||
if (JOptionPane.showOptionDialog(null, obj,
|
||||
StringResource.get("PROMPT_CRED"), JOptionPane.OK_CANCEL_OPTION,
|
||||
JOptionPane.PLAIN_MESSAGE, null, null,
|
||||
null) == JOptionPane.OK_OPTION) {
|
||||
PasswordAuthentication pauth = new PasswordAuthentication(
|
||||
user.getText(), pass.getPassword());
|
||||
if (JOptionPane.showOptionDialog(null, obj, StringResource.get("PROMPT_CRED"), JOptionPane.OK_CANCEL_OPTION,
|
||||
JOptionPane.PLAIN_MESSAGE, null, null, null) == JOptionPane.OK_OPTION) {
|
||||
PasswordAuthentication pauth = new PasswordAuthentication(user.getText(), pass.getPassword());
|
||||
return pauth;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void execCmd() {
|
||||
if (!StringUtils
|
||||
.isNullOrEmptyOrBlank(Config.getInstance().getCustomCmd())) {
|
||||
if (!StringUtils.isNullOrEmptyOrBlank(Config.getInstance().getCustomCmd())) {
|
||||
XDMUtils.exec(Config.getInstance().getCustomCmd());
|
||||
}
|
||||
}
|
||||
|
||||
private void execAntivir() {
|
||||
XDMUtils.exec(Config.getInstance().getAntivirExe() + " "
|
||||
+ (Config.getInstance().getAntivirCmd() == null ? ""
|
||||
: Config.getInstance().getAntivirCmd()));
|
||||
+ (Config.getInstance().getAntivirCmd() == null ? "" : Config.getInstance().getAntivirCmd()));
|
||||
}
|
||||
|
||||
private void updateFileName(DownloadEntry ent) {
|
||||
if (Config.getInstance()
|
||||
.getDuplicateAction() == XDMConstants.DUP_ACT_OVERWRITE) {
|
||||
if (Config.getInstance().getDuplicateAction() == XDMConstants.DUP_ACT_OVERWRITE) {
|
||||
return;
|
||||
}
|
||||
Logger.log("checking for same named file on disk...");
|
||||
@ -1316,8 +1262,7 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
f = new File(outputFolder, f2 + "_" + c + ext);
|
||||
c++;
|
||||
}
|
||||
Logger.log("Updating file name- old: " + ent.getFile() + " new: "
|
||||
+ f.getName());
|
||||
Logger.log("Updating file name- old: " + ent.getFile() + " new: " + f.getName());
|
||||
ent.setFile(f.getName());
|
||||
}
|
||||
|
||||
@ -1399,16 +1344,13 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
|
||||
public void openPreview(String id) {
|
||||
DownloadEntry ent = XDMApp.getInstance().getEntry(id);
|
||||
if (ent != null && (ent.getCategory() == XDMConstants.VIDEO
|
||||
|| ent.getCategory() == XDMConstants.MUSIC)) {
|
||||
if (ent != null && (ent.getCategory() == XDMConstants.VIDEO || ent.getCategory() == XDMConstants.MUSIC)) {
|
||||
if (XDMUtils.isFFmpegInstalled()) {
|
||||
XDMApp.getInstance().openPreviewPlayer(id);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null,
|
||||
StringResource.get("LBL_COMPONENT_MISSING"));
|
||||
JOptionPane.showMessageDialog(null, StringResource.get("LBL_COMPONENT_MISSING"));
|
||||
}
|
||||
} else if (JOptionPane.showConfirmDialog(null,
|
||||
StringResource.get("LBL_NOT_A_VIDEO"), "Preview",
|
||||
} else if (JOptionPane.showConfirmDialog(null, StringResource.get("LBL_NOT_A_VIDEO"), "Preview",
|
||||
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
|
||||
XDMApp.getInstance().openTempFolder(id);
|
||||
}
|
||||
@ -1423,8 +1365,7 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
if (ent == null) {
|
||||
return;
|
||||
}
|
||||
if (ent.getState() == XDMConstants.FINISHED
|
||||
|| ent.getState() == XDMConstants.PAUSED
|
||||
if (ent.getState() == XDMConstants.FINISHED || ent.getState() == XDMConstants.PAUSED
|
||||
|| ent.getState() == XDMConstants.FAILED) {
|
||||
return;
|
||||
}
|
||||
@ -1444,4 +1385,8 @@ public class XDMApp implements DownloadListener, DownloadWindowListener,
|
||||
return itemList;
|
||||
}
|
||||
|
||||
public MainWindow getMainWindow() {
|
||||
return mainWindow;
|
||||
}
|
||||
|
||||
}
|
@ -62,6 +62,14 @@ public class MessageBox extends JPanel implements ActionListener {
|
||||
init();
|
||||
}
|
||||
|
||||
public static int show(XDMFrame parent, String msg) {
|
||||
return show(parent, "XDM", msg, MessageBox.OK_OPTION, MessageBox.OK);
|
||||
}
|
||||
|
||||
public static int show(XDMFrame parent, String title, String msg) {
|
||||
return show(parent, title, msg, MessageBox.OK_OPTION, MessageBox.OK);
|
||||
}
|
||||
|
||||
public static int show(XDMFrame parent, String title, String msg, int buttons, int defaultButton) {
|
||||
return show(parent, title, msg, buttons, defaultButton, null);
|
||||
}
|
||||
@ -115,7 +123,8 @@ public class MessageBox extends JPanel implements ActionListener {
|
||||
txtMessage.setLineWrap(true);
|
||||
txtMessage.setBackground(ColorResource.getDarkerBgColor());
|
||||
txtMessage.setForeground(Color.WHITE);
|
||||
txtMessage.setBorder(new EmptyBorder(new Insets(getScaledInt(10), getScaledInt(10), getScaledInt(10), getScaledInt(30))));
|
||||
txtMessage.setBorder(
|
||||
new EmptyBorder(new Insets(getScaledInt(10), getScaledInt(10), getScaledInt(10), getScaledInt(30))));
|
||||
txtMessage.setEditable(false);
|
||||
|
||||
setBackground(ColorResource.getDarkerBgColor());
|
||||
@ -141,8 +150,8 @@ public class MessageBox extends JPanel implements ActionListener {
|
||||
jsp.setBorder(null);
|
||||
|
||||
chkOption = new JCheckBox(StringResource.get("LBL_DELETE_FILE"));
|
||||
chkOption.setIcon(ImageResource.getIcon("unchecked.png",16,16));
|
||||
chkOption.setSelectedIcon(ImageResource.getIcon("checked.png",16,16));
|
||||
chkOption.setIcon(ImageResource.getIcon("unchecked.png", 16, 16));
|
||||
chkOption.setSelectedIcon(ImageResource.getIcon("checked.png", 16, 16));
|
||||
chkOption.setBounds(getScaledInt(15), getScaledInt(130), getScaledInt(320), getScaledInt(30));
|
||||
chkOption.setOpaque(false);
|
||||
chkOption.setFocusPainted(false);
|
||||
|
@ -64,6 +64,7 @@ import xdman.ui.res.StringResource;
|
||||
import xdman.util.BrowserLauncher;
|
||||
import xdman.util.DateTimeUtils;
|
||||
import xdman.util.Logger;
|
||||
import xdman.util.NativeMessagingHostInstaller;
|
||||
import xdman.util.StringUtils;
|
||||
import xdman.util.XDMUtils;
|
||||
|
||||
@ -231,7 +232,7 @@ public class SettingsPage extends JPanel implements ActionListener, ListSelectio
|
||||
y = getScaledInt(25);
|
||||
h = getScaledInt(40);
|
||||
|
||||
btnNav = new JLabel(ImageResource.getIcon("back.png",32,32));
|
||||
btnNav = new JLabel(ImageResource.getIcon("back.png", 32, 32));
|
||||
btnNav.setFont(FontResource.getBiggerFont());
|
||||
btnNav.setForeground(ColorResource.getSelectionColor());
|
||||
btnNav.setBounds(getScaledInt(15), y, getScaledInt(35), h);
|
||||
@ -864,6 +865,7 @@ public class SettingsPage extends JPanel implements ActionListener, ListSelectio
|
||||
}
|
||||
}
|
||||
if ("FF_INSTALL".equals(name)) {
|
||||
NativeMessagingHostInstaller.installNativeMessagingHostForFireFox();
|
||||
if (!BrowserLauncher.launchFirefox(ffAMOURL)) {
|
||||
String msg = String.format(StringResource.get("MSG_ADDON_DESC"), "Mozilla Firefox", ffAMOURL);
|
||||
showAddonUrl(ffAMOURL, msg);
|
||||
@ -879,6 +881,7 @@ public class SettingsPage extends JPanel implements ActionListener, ListSelectio
|
||||
XDMUtils.browseURL("https://sourceforge.net/p/xdman/blog/2018/01/xdm-integration-with-microsoft-edge/");
|
||||
}
|
||||
if ("CR_INSTALL".equals(name)) {
|
||||
NativeMessagingHostInstaller.installNativeMessagingHostForChrome();
|
||||
if (!BrowserLauncher.launchChrome(chromeWebStoreURL)) {
|
||||
String msg = String.format(StringResource.get("MSG_ADDON_DESC"), "Google Chrome",
|
||||
chromeWebStoreURL);
|
||||
@ -890,6 +893,7 @@ public class SettingsPage extends JPanel implements ActionListener, ListSelectio
|
||||
}
|
||||
}
|
||||
if ("CM_INSTALL".equals(name)) {
|
||||
NativeMessagingHostInstaller.installNativeMessagingHostForChromium();
|
||||
String msg = String.format(StringResource.get("MSG_ADDON_DESC"), "Chromium", chromeWebStoreURL);
|
||||
showAddonUrl(chromeWebStoreURL, msg);
|
||||
// MessageBox.show(parent,
|
||||
@ -898,6 +902,7 @@ public class SettingsPage extends JPanel implements ActionListener, ListSelectio
|
||||
// MessageBox.OK);
|
||||
}
|
||||
if ("VL_INSTALL".equals(name)) {
|
||||
NativeMessagingHostInstaller.installNativeMessagingHostForChrome();
|
||||
String msg = String.format(StringResource.get("MSG_ADDON_DESC"), "Vivaldi", chromeWebStoreURL);
|
||||
showAddonUrl(chromeWebStoreURL, msg);
|
||||
// MessageBox.show(parent,
|
||||
@ -906,6 +911,7 @@ public class SettingsPage extends JPanel implements ActionListener, ListSelectio
|
||||
// MessageBox.OK);
|
||||
}
|
||||
if ("OP_INSTALL".equals(name)) {
|
||||
NativeMessagingHostInstaller.installNativeMessagingHostForChrome();
|
||||
String msg = String.format(StringResource.get("MSG_ADDON_DESC"), "Opera", operaExtURL);
|
||||
showAddonUrl(operaExtURL, msg);
|
||||
// MessageBox.show(parent,
|
||||
@ -2142,8 +2148,8 @@ public class SettingsPage extends JPanel implements ActionListener, ListSelectio
|
||||
|
||||
private JRadioButton createRadioButton(String name, Font font) {
|
||||
JRadioButton chk = new JRadioButton(StringResource.get(name));
|
||||
chk.setIcon(ImageResource.getIcon("unchecked.png",16,16));
|
||||
chk.setSelectedIcon(ImageResource.getIcon("checked.png",16,16));
|
||||
chk.setIcon(ImageResource.getIcon("unchecked.png", 16, 16));
|
||||
chk.setSelectedIcon(ImageResource.getIcon("checked.png", 16, 16));
|
||||
chk.setOpaque(false);
|
||||
chk.setFocusPainted(false);
|
||||
chk.setForeground(Color.WHITE);
|
||||
|
146
app/src/main/java/xdman/util/NativeMessagingHostInstaller.java
Normal file
146
app/src/main/java/xdman/util/NativeMessagingHostInstaller.java
Normal file
@ -0,0 +1,146 @@
|
||||
package xdman.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import com.sun.jna.platform.win32.Advapi32Util;
|
||||
import com.sun.jna.platform.win32.WinReg;
|
||||
|
||||
import xdman.Config;
|
||||
import xdman.XDMApp;
|
||||
import xdman.ui.components.MessageBox;
|
||||
|
||||
public class NativeMessagingHostInstaller {
|
||||
private static final String CHROME_EXTENSION_IDS = String.join(",",
|
||||
"\"chrome-extension://danmljfachfhpbfikjgedlfifabhofcj/\"",
|
||||
"\"chrome-extension://dkckaoghoiffdbomfbbodbbgmhjblecj/\"");
|
||||
|
||||
private static final String FIREFOX_EXTENSION_IDS = String.join(",", "\"browser-mon@xdman.sourceforge.net\"");
|
||||
|
||||
private static final String CHROME_LINUX_LOCATION = "~/.config/google-chrome/NativeMessagingHosts",
|
||||
FIREFOX_LINUX_LOCATION = "~/.mozilla/native-messaging-hosts",
|
||||
CHROME_MAC_LOCATION = "~/Library/Application Support/Google/Chrome/NativeMessagingHosts",
|
||||
FIREFOX_MAC_LOCATION = "~/Library/Application Support/Mozilla/NativeMessagingHosts",
|
||||
CHROMIUM_LINUX_LOCATION = "~/.config/chromium/NativeMessagingHosts",
|
||||
CHROMIUM_MAC_LOCATION = "~/Library/Application Support/Chromium/NativeMessagingHosts";
|
||||
|
||||
public static final synchronized void installNativeMessagingHostForChrome() {
|
||||
installNativeMessagingHostForChrome(XDMUtils.detectOS(), false);
|
||||
}
|
||||
|
||||
public static final void installNativeMessagingHostForChromium() {
|
||||
installNativeMessagingHostForChrome(XDMUtils.detectOS(), true);
|
||||
}
|
||||
|
||||
public static final void installNativeMessagingHostForFireFox() {
|
||||
installNativeMessagingHostForFireFox(XDMUtils.detectOS());
|
||||
}
|
||||
|
||||
private static final void installNativeMessagingHostForChrome(int os, boolean chromium) {
|
||||
if (os == XDMUtils.WINDOWS) {
|
||||
if (!Advapi32Util.registryKeyExists(WinReg.HKEY_CURRENT_USER,
|
||||
"Software\\Google\\Chrome\\NativeMessagingHosts\\xdm_chrome.native_host")) {
|
||||
if (!Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER,
|
||||
"Software\\Google\\Chrome\\NativeMessagingHosts", "xdm_chrome.native_host")) {
|
||||
MessageBox.show(XDMApp.getInstance().getMainWindow(),
|
||||
"Error: Unable to register native messaging host");
|
||||
return;
|
||||
}
|
||||
}
|
||||
File manifestFile = new File(Config.getInstance().getDataFolder(), "xdm_chrome.native_host.json");
|
||||
File nativeHostFile = new File(XDMUtils.getJarFile().getParentFile(),
|
||||
System.getProperty("os.name").toLowerCase().contains("windows") ? "native_host.exe"
|
||||
: "native_host");
|
||||
createNativeManifest(manifestFile, nativeHostFile, BrowserType.Chrome);
|
||||
try {
|
||||
Advapi32Util.registrySetStringValue(WinReg.HKEY_CURRENT_USER,
|
||||
"Software\\Google\\Chrome\\NativeMessagingHosts\\xdm_chrome.native_host", null,
|
||||
manifestFile.getAbsolutePath());
|
||||
} catch (Exception e) {
|
||||
MessageBox.show(XDMApp.getInstance().getMainWindow(),
|
||||
"Error: Unable to register native messaging host");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
File manifestFile = new File(
|
||||
os == XDMUtils.MAC ? (chromium ? CHROMIUM_MAC_LOCATION : CHROME_MAC_LOCATION)
|
||||
: (chromium ? CHROMIUM_LINUX_LOCATION : CHROME_LINUX_LOCATION),
|
||||
"xdm_chrome.native_host.json");
|
||||
File nativeHostFile = new File(XDMUtils.getJarFile().getParentFile(),
|
||||
System.getProperty("os.name").toLowerCase().contains("windows") ? "native_host.exe"
|
||||
: "native_host");
|
||||
createNativeManifest(manifestFile, nativeHostFile, BrowserType.Chrome);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static final void installNativeMessagingHostForFireFox(int os) {
|
||||
if (os == XDMUtils.WINDOWS) {
|
||||
if (!Advapi32Util.registryKeyExists(WinReg.HKEY_CURRENT_USER,
|
||||
"Software\\Mozilla\\NativeMessagingHosts\\xdmff.native_host")) {
|
||||
if (!Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\Mozilla\\NativeMessagingHosts",
|
||||
"xdmff.native_host")) {
|
||||
MessageBox.show(XDMApp.getInstance().getMainWindow(),
|
||||
"Error: Unable to register native messaging host");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
File manifestFile = new File(Config.getInstance().getDataFolder(), "xdmff.native_host.json");
|
||||
File nativeHostFile = new File(XDMUtils.getJarFile().getParentFile(),
|
||||
System.getProperty("os.name").toLowerCase().contains("windows") ? "native_host.exe"
|
||||
: "native_host");
|
||||
createNativeManifest(manifestFile, nativeHostFile, BrowserType.Firefox);
|
||||
try {
|
||||
Advapi32Util.registrySetStringValue(WinReg.HKEY_CURRENT_USER,
|
||||
"Software\\Mozilla\\NativeMessagingHosts\\xdmff.native_host", null,
|
||||
manifestFile.getAbsolutePath());
|
||||
} catch (Exception e) {
|
||||
MessageBox.show(XDMApp.getInstance().getMainWindow(),
|
||||
"Error: Unable to register native messaging host");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
File manifestFile = new File(os == XDMUtils.MAC ? FIREFOX_MAC_LOCATION : FIREFOX_LINUX_LOCATION,
|
||||
"xdmff.native_host.json");
|
||||
File nativeHostFile = new File(XDMUtils.getJarFile().getParentFile(),
|
||||
System.getProperty("os.name").toLowerCase().contains("windows") ? "native_host.exe"
|
||||
: "native_host");
|
||||
createNativeManifest(manifestFile, nativeHostFile, BrowserType.Firefox);
|
||||
}
|
||||
}
|
||||
|
||||
private static final void createNativeManifest(File manifestFile, File nativeHostFile, BrowserType browserType) {
|
||||
try (OutputStream out = new FileOutputStream(manifestFile)) {
|
||||
String name, manifestKey, extension;
|
||||
if (browserType == BrowserType.Chrome || browserType == BrowserType.Chromium) {
|
||||
manifestKey = "\"allowed_origins\"";
|
||||
extension = CHROME_EXTENSION_IDS;
|
||||
name = "\"xdm_chrome.native_host\"";
|
||||
} else {
|
||||
manifestKey = "\"allowed_extensions\"";
|
||||
extension = FIREFOX_EXTENSION_IDS;
|
||||
name = "\"xdmff.native_host\"";
|
||||
}
|
||||
|
||||
String json = String.format(
|
||||
"{\n" + " \"name\": %s,\n"
|
||||
+ " \"description\": \"Native messaging host for Xtreme Download Manager\",\n"
|
||||
+ " \"path\": \"%s\",\n" + " \"type\": \"stdio\",\n" + " %s: [ %s ]\n" + "}",
|
||||
name, nativeHostFile.getAbsolutePath().replace("\\", "\\\\"), manifestKey, extension);
|
||||
|
||||
out.write(json.getBytes("utf-8"));
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public enum BrowserType {
|
||||
Chrome, Chromium, Firefox
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user