Exemple #1
0
        public void OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
        {
            OnBeforeDownloadFired?.Invoke(this, downloadItem);

            if (!callback.IsDisposed)
            {
                using (callback)
                {
                    callback.Continue(downloadItem.SuggestedFileName, showDialog: true);
                }
            }
        }
Exemple #2
0
        public void OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem,
                                     IBeforeDownloadCallback callback)
        {
            Log.Information("Download triggered for item '{name}'", downloadItem.SuggestedFileName);

            OnBeforeDownloadFired?.Invoke(this, downloadItem);

            if (callback.IsDisposed)
            {
                return;
            }

            using (callback)
                callback.Continue(downloadItem.SuggestedFileName, true);
        }
Exemple #3
0
        void IDownloadHandler.OnBeforeDownload(IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
        {
            OnBeforeDownloadFired?.Invoke(this, downloadItem);

            string pathUser     = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
            string pathDownload = System.IO.Path.Combine(pathUser, "Downloads", downloadItem.SuggestedFileName);

            if (!callback.IsDisposed)
            {
                using (callback)
                {
                    callback.Continue(pathDownload, showDialog: true);
                }
            }
        }
Exemple #4
0
        public void OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
        {
            OnBeforeDownloadFired?.Invoke(this, downloadItem);

            if (!callback.IsDisposed)
            {
                using (callback)
                {
                    callback.Continue(downloadItem.SuggestedFileName, showDialog: false);
                }
                //     Console.WriteLine(downloadItem.SuggestedFileName);
                filename = downloadItem.SuggestedFileName;
                //System.Diagnostics.Process.Start(downloadItem.SuggestedFileName);
            }
        }
        public void OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem,
                                     IBeforeDownloadCallback callback)
        {
            OnBeforeDownloadFired?.Invoke(this, downloadItem);

            if (callback.IsDisposed)
            {
                return;
            }
            var downloadPath = string.IsNullOrEmpty(_saveToDirectory)
                ? downloadItem.SuggestedFileName
                : _saveToDirectory + "\\" + downloadItem.SuggestedFileName;
            var showDialog = string.IsNullOrEmpty(_saveToDirectory);

            callback.Continue(downloadPath, showDialog);
        }
Exemple #6
0
        public void OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
        {
            OnBeforeDownloadFired?.Invoke(this, downloadItem);

            if (!callback.IsDisposed)
            {
                using (callback)
                {
                    //callback.Continue(downloadItem.SuggestedFileName, showDialog: true);
                    string livelyDir = Path.Combine(Directory.GetParent(Directory.GetParent(Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory).ToString()).ToString()).ToString(), "tmpdata");
                    Directory.CreateDirectory(Path.Combine(livelyDir, "wpdownloads"));
                    livelyDir = Path.Combine(livelyDir, "wpdownloads");

                    callback.Continue(Path.Combine(livelyDir, downloadItem.SuggestedFileName), showDialog: false);
                }
            }
        }
        public void OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
        {
            OnBeforeDownloadFired?.Invoke(this, downloadItem);

            if (!callback.IsDisposed)
            {
                using (callback)
                {
                    string filename = Path.Combine(_baseFolder, downloadItem.SuggestedFileName);
                    if (File.Exists(filename))
                    {
                        filename = Path.Combine(_baseFolder, Guid.NewGuid().ToString("N") + "__" + downloadItem.SuggestedFileName);
                    }
                    callback.Continue(filename, showDialog: false);
                }
            }
        }
Exemple #8
0
        public void OnBeforeDownload(IWebBrowser chromiumWebBrowser,
                                     IBrowser browser,
                                     DownloadItem downloadItem,
                                     IBeforeDownloadCallback callback)
        {
            OnBeforeDownloadFired?.Invoke(this, downloadItem);

            if (callback.IsDisposed)
            {
                return;
            }

            using (callback)
            {
                //Log.Print("Before Download: " + downloadItem.SuggestedFileName);
                callback.Continue(downloadItem.SuggestedFileName, showDialog: false);
            }
        }
Exemple #9
0
        public void OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
        {
            Preferences pref = new Preferences();

            if (pref.DownloadFolder != null)
            {
                downloadItem.SuggestedFileName = Path.Combine(pref.DownloadFolder, downloadItem.SuggestedFileName);
            }

            OnBeforeDownloadFired?.Invoke(this, downloadItem);

            if (!callback.IsDisposed)
            {
                using (callback)
                {
                    callback.Continue(downloadItem.SuggestedFileName, showDialog: true);
                }
            }
        }
Exemple #10
0
        /// <summary>
        /// 下载之前(一个下载任务 只会执行一次,从这里获取 downloadItem.SuggestedFileName)
        /// </summary>
        public void OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
        {
            OnBeforeDownloadFired?.Invoke(this, new BeforeDownloadEventArgs
            {
                downloadItem = downloadItem, // DownloadItem 用来获取下载任务信息至关重要
                callback     = callback
            });

            // 下载前显示对话框
            string downloadPath = @"";

            if (!callback.IsDisposed)
            {
                using (callback)
                {
                    callback.Continue(downloadPath + downloadItem.SuggestedFileName, showDialog: true);
                }
            }
        }
        public void OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
        {
            IsCancelled = false;
            OnBeforeDownloadFired?.Invoke(this, downloadItem);

            if (!callback.IsDisposed)
            {
                using (callback)
                {
                    var saveas   = false;
                    var path     = "";
                    var filename = "";

                    var suggestedFileName = Uri.UnescapeDataString(downloadItem.SuggestedFileName);

                    saveas            = suggestedFileName.StartsWith("saveas:", StringComparison.OrdinalIgnoreCase);
                    suggestedFileName = suggestedFileName.Substring(suggestedFileName.IndexOf(':') + 1);

                    if (!Path.IsPathRooted(suggestedFileName))
                    {
                        suggestedFileName = Path.Combine(_app.LastFileDialogDirectory ?? "", suggestedFileName);
                    }

                    if (!string.IsNullOrWhiteSpace(suggestedFileName))
                    {
                        path     = Path.GetFullPath(suggestedFileName);
                        filename = Path.GetFileName(path);
                    }

                    if (!saveas && File.Exists(path))
                    {
                        callback.Continue(path, showDialog: false);
                    }
                    else
                    {
                        var filter   = "All Files | *.*";
                        var ext      = Path.GetExtension(filename);
                        var fileType = Utils.GetFileType(ext);

                        if (!string.IsNullOrWhiteSpace(fileType))
                        {
                            filter = $"{fileType} | *{ext}|" + filter;
                        }

                        using (var saveFileDialog = new SaveFileDialog
                        {
                            InitialDirectory = string.IsNullOrWhiteSpace(path) ? "" : Path.GetDirectoryName(path),
                            FileName = filename,
                            Filter = filter,
                            Title = saveas ? Strings.Save_As : Strings.Save
                        })
                        {
                            if (saveFileDialog.ShowDialog() == DialogResult.OK && !string.IsNullOrWhiteSpace(saveFileDialog.FileName))
                            {
                                _app.LastFileDialogDirectory = Path.GetDirectoryName(saveFileDialog.FileName);
                                callback.Continue(saveFileDialog.FileName, showDialog: false);
                            }
                            else
                            {
                                IsCancelled = true;
                            }
                        }
                    }
                }
            }
        }