예제 #1
0
        private bool DownloadWorker(HttpClientEx hc, ImageInfomation e, int uriIndex)
        {
            using (var req = new HttpRequestMessage(HttpMethod.Get, e.ImageUri[uriIndex]))
            {
                req.Headers.Referrer = this.Uri;

                using (var res = hc.SendAsync(req).Exec())
                {
                    if ((int)res.StatusCode / 100 != 2)
                    {
                        return(false);
                    }

                    e.TempStream.SetLength(0);
                    using (var fileWriter = new StreamWithNotify(e.TempStream, count => Interlocked.Add(ref this.m_downloaded, count)))
                        res.Content.CopyToAsync(fileWriter).Wait();
                }

                e.TempStream.Flush();

                e.TempStream.Position = 0;
                e.Extension           = Signatures.GetExtension(e.TempStream);

                if (e.Extension == null)
                {
                    return(false);
                }

                // 이미지 암호화 푸는 작업
                this.m_decryptor.Decrypt(e.TempStream);
            }

            this.IncrementProgress();
            return(true);
        }
예제 #2
0
        private async Task <bool> DownloadWorker(HttpClientEx hc, ImageInfomation e, Uri uri, CancellationToken cancellationToken)
        {
            using (var req = new HttpRequestMessage(HttpMethod.Get, uri))
            {
                req.Headers.Referrer = this.Uri;

                using (var res = await hc.SendAsync(req, HttpCompletionOption.ResponseHeadersRead, cancellationToken))
                {
                    if ((int)res.StatusCode / 100 != 2)
                    {
                        return(false);
                    }

                    if (res.Headers.Server.FirstOrDefault()?.ToString()?.Contains("ddos-guard") ?? false)
                    {
                        return(false);
                    }

                    using (var stream = await res.Content.ReadAsStreamAsync())
                    {
                        e.TempStream.SetLength(0);
                        using (var fileWriter = new StreamWithNotify(e.TempStream, count => Interlocked.Add(ref this.m_downloaded, count)))
                        {
                            await stream.CopyToAsync(fileWriter, 4096, cancellationToken);
                        }
                    }
                }

                e.TempStream.Flush();

                e.TempStream.Position = 0;
                e.Extension           = Signatures.GetExtension(e.TempStream);

                if (e.Extension == null)
                {
                    return(false);
                }

                // 이미지 암호화 푸는 작업
                this.m_decryptor.Decrypt(e.TempStream);
            }

            this.IncrementProgress();
            return(true);
        }