mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 14:07:46 +08:00
Added handling of Gecko.LauncherDialog.Download (#1548)
* Added handling of Gecko.LauncherDialog.Download Code lifted from https://stackoverflow.com/questions/27368791/how-to-handle-downloading-in-geckofx-29 This code addition addresses https://github.com/mRemoteNG/mRemoteNG/issues/1400 * updated changelog for #1400 * refractored launcher dialog method
This commit is contained in:
committed by
Faryan Rezagholi
parent
11199eabf3
commit
125330b695
@@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
## [Unreleased]
|
||||
### Added
|
||||
- #1512: Added option to close panel from right click menu
|
||||
- #1400: Added file download handling to HTTP(S) connections using Gecko
|
||||
- #826: Allow selecting RDP version to use when connecting
|
||||
### Changed
|
||||
- #1468: Improved mRemoteNG startup time
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using Gecko;
|
||||
using mRemoteNG.Tools;
|
||||
@@ -66,6 +67,7 @@ namespace mRemoteNG.Connection.Protocol.Http
|
||||
if (GeckoBrowser != null)
|
||||
{
|
||||
GeckoBrowser.DocumentTitleChanged += geckoBrowser_DocumentTitleChanged;
|
||||
LauncherDialog.Download += geckoBrowser_LauncherDialog_Download;
|
||||
GeckoBrowser.NSSError += CertEvent.GeckoBrowser_NSSError;
|
||||
}
|
||||
else
|
||||
@@ -267,6 +269,40 @@ namespace mRemoteNG.Connection.Protocol.Http
|
||||
}
|
||||
}
|
||||
|
||||
private void geckoBrowser_LauncherDialog_Download(object sender, Gecko.LauncherDialogEvent e)
|
||||
{
|
||||
var objTarget = Xpcom.CreateInstance<nsILocalFile>("@mozilla.org/file/local;1");
|
||||
using (var tmp = new nsAString(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\mremoteng.download"))
|
||||
{
|
||||
objTarget.InitWithPath(tmp);
|
||||
}
|
||||
|
||||
//Save file dialog
|
||||
var saveFileDialog = new SaveFileDialog
|
||||
{
|
||||
Filter = "All files (*.*)|*.*",
|
||||
FilterIndex = 2,
|
||||
RestoreDirectory = true,
|
||||
FileName = e.Filename
|
||||
};
|
||||
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
var source = IOService.CreateNsIUri(e.Url);
|
||||
var dest = IOService.CreateNsIUri(new Uri(saveFileDialog.FileName).AbsoluteUri);
|
||||
var t = (nsAStringBase)new nsAString(Path.GetFileName(saveFileDialog.FileName));
|
||||
var persist = Xpcom.CreateInstance<nsIWebBrowserPersist>("@mozilla.org/embedding/browser/nsWebBrowserPersist;1");
|
||||
var nst = Xpcom.CreateInstance<nsITransfer>("@mozilla.org/transfer;1");
|
||||
|
||||
nst.Init(source, dest, t, e.Mime, 0, null, persist, false);
|
||||
persist.SetPersistFlagsAttribute(2 | 32 | 16384);
|
||||
persist.SetProgressListenerAttribute(nst);
|
||||
persist.SaveURI(source, null, null, (uint)Gecko.nsIHttpChannelConsts.REFERRER_POLICY_NO_REFERRER, null, null, (nsISupports)dest, null);
|
||||
}
|
||||
|
||||
saveFileDialog.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Enums
|
||||
@@ -282,4 +318,4 @@ namespace mRemoteNG.Connection.Protocol.Http
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user