Exemple #1
0
        private void DownloadManagerDownloadAdding(object sender, CancelDownloadEventArgs e)
        {
            if (e.DownloadItem.SaveTargets == null)
            {
                return;
            }

            var fi = new FileInfo(e.DownloadItem.SaveTargets[0]);

            var drive1 = Path.GetPathRoot(e.DownloadItem.SaveTargets[0]);

            // here we should check for free space,
            if (!string.IsNullOrEmpty(drive1) && FileHelper.GetFreeSpace(fi.DirectoryName) < e.DownloadItem.Magnet.Size)
            {
                throw new NoFreeSpaceException(drive1);
            }

            if (string.IsNullOrEmpty(drive1))
            {
                return;
            }

            // lets check for file size restriction
            var driveInfo1  = new DriveInfo(drive1);
            var fileSystem1 = driveInfo1.DriveFormat;

            if (fileSystem1 == "FAT32")
            {
                // maximum file size is 4 Gb
                if (e.DownloadItem.Magnet.Size > 4L * 1024 * 1024 * 1024)
                {
                    throw new FileTooBigException(4L * 1024 * 1024 * 1024, e.DownloadItem.Magnet.Size);
                }
            }

            if (fileSystem1 == "NTFS")
            {
                // maximum file size is 16 Tb - 64 Kb
                if (e.DownloadItem.Magnet.Size > 16L * 1024 * 1024 * 1024 * 1024 - 64 * 1024)
                {
                    throw new FileTooBigException(16L * 1024 * 1024 * 1024 * 1024 - 64 * 1024,
                                                  e.DownloadItem.Magnet.Size);
                }
            }

            if (Settings.InstantAllocate)
            {
                var path    = e.DownloadItem.SaveTargets[0];
                var dirInfo = new DirectoryInfo(Path.GetDirectoryName(path));
                if (!dirInfo.Exists)
                {
                    dirInfo.Create();
                }
                FileHelper.AllocateFile(path, e.DownloadItem.Magnet.Size);
            }
        }
Exemple #2
0
        protected virtual bool OnDownloadAdding(DownloadItem di)
        {
            if (DownloadAdding == null)
            {
                return(true);
            }
            var e = new CancelDownloadEventArgs {
                DownloadItem = di
            };
            var handler = DownloadAdding;

            if (handler != null)
            {
                handler(this, e);
            }
            return(!e.Cancel);
        }