コード例 #1
0
ファイル: DownloadHandler.cs プロジェクト: Cossa6/truffle
        public void OnBeforeDownload(IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
        {
            if (!callback.IsDisposed) {
                using (callback) {
                    string directory = Properties.Settings.Default.StorageLocation + (GlobalVariables.CurrentUnitCode != "" ? GlobalVariables.CurrentUnitCode + "/" : "");
                    Directory.CreateDirectory(directory);

                    string filename = directory + downloadItem.SuggestedFileName;
                    if (!File.Exists(filename)) {
                        callback.Continue(filename, showDialog: false);
                        ++GlobalVariables.FilesDownloaded;

                        BlackboardFile f = new BlackboardFile(downloadItem.SuggestedFileName, downloadItem.Url);
                        f.RawURL = GlobalVariables.CurrentUrl;
                        f.FirstDownloaded = DateTime.Now;
                        f.LastDownloaded = DateTime.Now;
                        f.TimesDownloaded = 1;
                        f.LocalPath = filename;

                        //We know the unit we want exists in GlobalVariables.Units because it was created before the download started, back in Crawler.cs
                        GlobalVariables.Units.First(u => u.Name == GlobalVariables.CurrentUnitCode).Files.Add(f);
                    }
                    else {
                        //FUTURE FEATURE: Allow files to be marked for redownloading.
                        ++GlobalVariables.FilesSkipped;
                    }

                    if (DownloadHandled != null)
                        DownloadHandled(new object(), new EventArgs());
                }
            }
        }
コード例 #2
0
ファイル: DownloadHandler.cs プロジェクト: xrogzu/truffle
        public void OnBeforeDownload(IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
        {
            if (!callback.IsDisposed)
            {
                using (callback) {
                    string directory = Properties.Settings.Default.StorageLocation + (GlobalVariables.CurrentUnitCode != "" ? GlobalVariables.CurrentUnitCode + "/" : "");
                    Directory.CreateDirectory(directory);

                    string filename = directory + downloadItem.SuggestedFileName;
                    if (!File.Exists(filename))
                    {
                        callback.Continue(filename, showDialog: false);
                        ++GlobalVariables.FilesDownloaded;

                        BlackboardFile f = new BlackboardFile(downloadItem.SuggestedFileName, downloadItem.Url);
                        f.RawURL          = GlobalVariables.CurrentUrl;
                        f.FirstDownloaded = DateTime.Now;
                        f.LastDownloaded  = DateTime.Now;
                        f.TimesDownloaded = 1;
                        f.LocalPath       = filename;

                        //We know the unit we want exists in GlobalVariables.Units because it was created before the download started, back in Crawler.cs
                        GlobalVariables.Units.First(u => u.Name == GlobalVariables.CurrentUnitCode).Files.Add(f);
                    }
                    else
                    {
                        //FUTURE FEATURE: Allow files to be marked for redownloading.
                        ++GlobalVariables.FilesSkipped;
                    }

                    if (DownloadHandled != null)
                    {
                        DownloadHandled(new object(), new EventArgs());
                    }
                }
            }
        }