public override void SetDownloader(DownloaderSettings settings)
        {
            if (State != DownloadState.Uninitialized)
            {
                return;
            }

            Message = new DownloaderMessage();
            Message.DownloaderType = Type;
            Message.DownloadSize   = 0;
            Message.FileName       = Path.GetFileNameWithoutExtension(settings.FileName);
            Message.Extention      = Path.GetExtension(settings.FileName);
            Message.FileSize       = null;
            Message.TempFilePath   = Path.Combine(
                Windows.Storage.ApplicationData.Current.LocalCacheFolder.Path,
                StorageTools.StorageManager.GetTemporaryName() + settings.FileName);
            Message.URL = settings.Url;
            State       = DownloadState.Prepared;
            return;
        }
示例#2
0
 public override void SetDownloader(DownloaderSettings settings)
 {
     if (State != DownloadState.Uninitialized)
     {
         return;
     }
     try
     {
         Message = new DownloaderMessage();
         Message.DownloaderType = Type;
         //设置文件信息
         Message.FileSize  = settings.Size;
         Message.URL       = settings.Url;
         Message.FileName  = Path.GetFileNameWithoutExtension(settings.FileName);
         Message.Extention = Path.GetExtension(settings.FileName);
         //安排线程
         Message.Threads.ArrangeThreads((long)Message.FileSize, settings.Threads <= 0 ? StorageTools.Settings.ThreadNumber : ((int)settings.Threads));
         //申请临时文件
         Message.TempFilePath = settings.FilePath;
         State = DownloadState.Prepared;
     }
     catch (Exception e) { HandleError(e, CurrentOperationCode); }
 }
示例#3
0
        public MediaDownloader(DownloaderSettings settings)
        {
            this.Settings = settings;
            this.BasePath = Environment.CurrentDirectory;

            this.CachePath    = Path.Combine(this.BasePath, ".cache");
            this.DownloadPath = Path.IsPathRooted(settings.Path) ? settings.Path : Path.Combine(this.BasePath, settings.Path);

            //this.Port = port;
            //this.Paths = new[]
            //{
            //    basePath,
            //    Path.Combine(basePath, "tcache"),
            //    Path.Combine(basePath, "Downloads"),
            //    Path.Combine(basePath, "tcache", "fastresume.data"),
            //    Path.Combine(basePath, "DhtNodes")
            //};

            //Console.CancelKeyPress += delegate { Shutdown().Wait(); };
            AppDomain.CurrentDomain.ProcessExit        += delegate { Shutdown().Wait(); };
            AppDomain.CurrentDomain.UnhandledException += delegate(object sender, UnhandledExceptionEventArgs e) { Shutdown().Wait(); };
            Thread.GetDomain().UnhandledException      += delegate(object sender, UnhandledExceptionEventArgs e) { Shutdown().Wait(); };

            try
            {
                var fastResumePath = Path.Combine(this.CachePath, "fastresume.data");
                FastResume = BEncodedValue.Decode <BEncodedDictionary>(File.ReadAllBytes(fastResumePath));
                File.Delete(fastResumePath);
            }
            catch
            {
                FastResume = new BEncodedDictionary();
            }

            InitializeClientEngine().Wait();
        }
示例#4
0
 private void LoadSettings()
 {
     settings = DownloaderSettings.Load();
 }
示例#5
0
 /// <summary>
 /// 使用链接重置下载器
 /// </summary>
 public abstract void SetDownloader(DownloaderSettings settings);