Exemplo n.º 1
0
        public Watcher(string host, string token, string path, DownloadTool tool, Form1 form)
        {
            this.Host  = host;
            this.Token = token;
            this._tool = tool;
            this._path = path;
            this._form = form;

            _httpClientHandler = new HttpClientHandler();
            try
            {
                _httpClient = new HttpClient(_httpClientHandler)
                {
                    BaseAddress = new Uri(this.Host.StartsWith("http") ? this.Host : String.Format("http://{0}", this.Host))
                };
                ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
                ServicePointManager.Expect100Continue = true;
                ServicePointManager.SecurityProtocol  = SecurityProtocolType.Tls12;
            }
            catch (Exception)
            {
                throw;
            }

            _thread = new Thread(CheckThread);
            _mre    = new ManualResetEvent(false);
        }
Exemplo n.º 2
0
        private async Task DownloadOneNuget(ComposeSettings settings, NugetInfo n, string fileName)
        {
            var dl      = new DownloadTool(_progressFn);
            var url     = $"https://www.nuget.org/api/v2/package/{n.Name}/{n.Version}";
            var dstFile = Path.Combine(settings.TmpDownloadPath, fileName);

            if (File.Exists(dstFile) == false)
            {
                await dl.DownloadFileAsync(url, dstFile);
            }
        }
Exemplo n.º 3
0
 public void InitOther()
 {
     try
     {
         if (tool == null)
         {
             tool = new QBittorrent(Settings.Default.DownHost, int.Parse(Settings.Default.DownPort), Settings.Default.DownUser, Settings.Default.DownPass);
         }
         watcher = new Watcher(Settings.Default.ServerAddress, Settings.Default.Token, Settings.Default.DownPath, tool, this);
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         this.ShowNotification(System.Windows.Forms.ToolTipIcon.Error, " 新番订阅", ex.Message);
     }
 }
Exemplo n.º 4
0
        void work(Object obj)
        {
            AsynObj asycObj = (AsynObj)obj;
            string  content = DownloadTool.GetHtml(asycObj.Url, true, Common.CreateHttpWebRequest(asycObj.Url));

            DlTool.SaveFile(content, asycObj.Path);
            MatchCollection torrentMatch = torrentLinkRegex.Matches(content);

            if (torrentMatch.Count > 0)
            {
                string[] strs           = torrentMatch[torrentMatch.Count - 1].Value.Split('"');
                string   url            = "http://taohuabt.info/" + strs[0].Replace("&amp", "");
                string   torrentContent = DownloadTool.GetHtml(url, true, Common.CreateHttpWebRequest(url));
                DlTool.SaveFile(torrentContent, asycObj.Path + ".htm");
            }
            else
            {
                Console.WriteLine("没有匹配 " + asycObj.Url);
            }
        }
Exemplo n.º 5
0
        public override void Download(object obj)
        {
            AsynObj o = (AsynObj)obj;


            string content = DownloadTool.GetHtml(o.Url, true, Common.CreateHttpWebRequest(o.Url));

            if (content != "")
            {
                //string[] contents = content.Split(new string[] { "<td align=\"center\">" }, StringSplitOptions.RemoveEmptyEntries);
                //content = contents[1];
                if (o.Path != null)
                {
                    DlTool.SaveFile(content, Path.Combine(o.Path, DlTool.ReplaceUrl(o.Url)) + ".htm");
                }
                ISinglePageDonwloader sgDl = new ThzSgDl();
                AsynObj asynObj            = new AsynObj();
                asynObj.Path    = o.Path;
                asynObj.Content = content;
                ThreadPool.QueueUserWorkItem(sgDl.Download, asynObj);
            }
        }
Exemplo n.º 6
0
        private async Task TestDownload(string purl, string targetFilename)
        {
            string tempDirectoryName = default;

            while (tempDirectoryName == default || File.Exists(tempDirectoryName))
            {
                tempDirectoryName = Path.GetRandomFileName();
            }

            var downloadTool = new DownloadTool();
            var packageUrl   = new PackageURL(purl);

            Assert.IsNotNull(packageUrl);

            Directory.CreateDirectory(tempDirectoryName);
            downloadTool.Download(packageUrl, tempDirectoryName).Wait();
            var fileMatchCount = Directory.EnumerateFiles(tempDirectoryName, targetFilename, SearchOption.AllDirectories).Count();

            try
            {
                Directory.Delete(tempDirectoryName, true);
            }
            catch (Exception)
            {
                foreach (var filename in Directory.EnumerateFileSystemEntries(tempDirectoryName, "*", SearchOption.AllDirectories))
                {
                    var fileInfo = new FileInfo(filename)
                    {
                        Attributes = FileAttributes.Normal
                    };
                }
                Directory.Delete(tempDirectoryName, true);
            }

            Assert.IsTrue(fileMatchCount > 0);
        }