using System; using System.Collections; using System.ComponentModel; using System.Globalization; using System.IO; using System.Net; using System.Reflection; using System.Runtime.CompilerServices; using System.Text; using System.Text.RegularExpressions; using System.Threading; namespace Megaget { public class WebClientEx { private const int TIMEOUT = 140000; public const int BUFFERSIZE = 4096; public WebHeaderCollection Headers; private HttpWebRequest m_HTTPRequest; private HttpWebResponse m_HTTPResponse; private CookieContainer m_CookieContainer; private AsyncCallback m_ResponseCallback; private string m_CompleteFilePath; private string m_FinalFilePath; private long m_StartPoint; private long FileSize; private Stream m_ResponseStream; private byte[] m_ReceiveBuffer; private long m_TotalReaded; public long m_SessionReceived; private FileStream m_File; private MemoryStream m_DataStream; private string m_Url; private bool m_IsFileDownload; private bool m_IsStringDownload; private bool m_IsDataDownload; private bool m_Cancelled; private object m_UserState; public double WaitTime; public event AsyncCompletedEventHandler DownloadFileCompleted { [MethodImpl(MethodImplOptions.Synchronized)] add { this.DownloadFileCompleted = (AsyncCompletedEventHandler)Delegate.Combine(this.DownloadFileCompleted, value); } [MethodImpl(MethodImplOptions.Synchronized)] remove { this.DownloadFileCompleted = (AsyncCompletedEventHandler)Delegate.Remove(this.DownloadFileCompleted, value); } } public event #=qlSvNlmnLrQc9cf_zVOihQwkhUIfhAKouKv_R5mYmdM_SjR0aRvK_At4iGEwVOp09 DownloadProgressChanged { [MethodImpl(MethodImplOptions.Synchronized)] add { this.DownloadProgressChanged = (#=qlSvNlmnLrQc9cf_zVOihQwkhUIfhAKouKv_R5mYmdM_SjR0aRvK_At4iGEwVOp09)Delegate.Combine(this.DownloadProgressChanged, value); } [MethodImpl(MethodImplOptions.Synchronized)] remove { this.DownloadProgressChanged = (#=qlSvNlmnLrQc9cf_zVOihQwkhUIfhAKouKv_R5mYmdM_SjR0aRvK_At4iGEwVOp09)Delegate.Remove(this.DownloadProgressChanged, value); } } public event #=qELCIqGuVSdqvx9rE1UX8cO10tHLj1skN6Z9y8qoS$aaItw4Uf7vWaNrZ9QG8f6MF DownloadStringCompleted { [MethodImpl(MethodImplOptions.Synchronized)] add { this.DownloadStringCompleted = (#=qELCIqGuVSdqvx9rE1UX8cO10tHLj1skN6Z9y8qoS$aaItw4Uf7vWaNrZ9QG8f6MF)Delegate.Combine(this.DownloadStringCompleted, value); } [MethodImpl(MethodImplOptions.Synchronized)] remove { this.DownloadStringCompleted = (#=qELCIqGuVSdqvx9rE1UX8cO10tHLj1skN6Z9y8qoS$aaItw4Uf7vWaNrZ9QG8f6MF)Delegate.Remove(this.DownloadStringCompleted, value); } } public event #=qlLXHYcOhB$gI0qq7D6JlFctRtGb7$AF0Bo8HdK9Iw4Phgm_jriBjfWH2POZlvENP DownloadDataCompleted { [MethodImpl(MethodImplOptions.Synchronized)] add { this.DownloadDataCompleted = (#=qlLXHYcOhB$gI0qq7D6JlFctRtGb7$AF0Bo8HdK9Iw4Phgm_jriBjfWH2POZlvENP)Delegate.Combine(this.DownloadDataCompleted, value); } [MethodImpl(MethodImplOptions.Synchronized)] remove { this.DownloadDataCompleted = (#=qlLXHYcOhB$gI0qq7D6JlFctRtGb7$AF0Bo8HdK9Iw4Phgm_jriBjfWH2POZlvENP)Delegate.Remove(this.DownloadDataCompleted, value); } } public CookieContainer Cookies { get { return this.m_CookieContainer; } set { this.m_CookieContainer = value; } } public string Url { get { if (this.m_HTTPRequest != null) { return this.m_HTTPRequest.RequestUri.ToString(); } return string.Empty; } } public WebHeaderCollection ResponseHeaders { get { if (this.m_HTTPResponse != null) { return this.m_HTTPResponse.Headers; } return null; } } public string ResponseLocation { get { if (this.m_HTTPResponse != null) { return this.m_HTTPResponse.ResponseUri.ToString(); } return string.Empty; } } public HttpStatusCode ResponseCode { get { if (this.m_HTTPResponse != null) { return this.m_HTTPResponse.StatusCode; } return HttpStatusCode.MultipleChoices; } } public WebClientEx() { this.WaitTime = 0.0; this.m_CookieContainer = new CookieContainer(); this.Headers = new WebHeaderCollection(); this.m_Cancelled = false; } public static string WebGet(string url, WebClientEx wc) { return wc.DownloadString(url); } public static string WebPost(string url, string data, WebClientEx wc) { return wc.UploadString(url, data); } public bool IsContentDisposition() { return this.m_HTTPResponse != null && this.m_HTTPResponse.Headers[#=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851805135)] != null && this.m_HTTPResponse.Headers[#=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851805135)].ToLower().Contains(#=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851805153)); } public string GetFileNameFromHeaders() { if (this.IsContentDisposition()) { string text = Downloader.MatchAndReplace(this.m_HTTPResponse.Headers[#=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851805135)], #=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851805076), #=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851805094)); if (text.Length > 0) { return text; } } string text2 = this.m_HTTPResponse.ResponseUri.ToString(); return text2.Substring(text2.LastIndexOf('/') + 1); } private void m_CopyCookies(string url, HttpWebRequest request) { try { Uri uri = new Uri(url); string text = string.Empty; if (uri.Host.Split(new char[] { '.' }).Length == 2) { text = #=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851807687) + uri.Host; } if (text.Length > 0) { IEnumerator enumerator = this.m_CookieContainer.GetCookies(new Uri(#=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804760) + text)).GetEnumerator(); try { while (enumerator.MoveNext()) { Cookie cookie = (Cookie)enumerator.Current; if (cookie.Domain.StartsWith(#=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851807687))) { string domain = cookie.Domain.Substring(1); this.m_CookieContainer.Add(new Cookie(cookie.Name, cookie.Value, cookie.Path, domain)); } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } } } catch { } request.CookieContainer = this.m_CookieContainer; } public bool isOK() { bool result; try { if (this.m_HTTPResponse.StatusCode > (HttpStatusCode)(-2) && this.m_HTTPResponse.StatusCode < HttpStatusCode.BadRequest) { result = true; } else { result = false; } } catch (object arg_55_0) { result = false; } return result; } public void CancelAsync() { try { if (this.m_HTTPRequest != null) { this.m_Cancelled = true; this.m_HTTPRequest.Abort(); } } catch (Exception arg_3F_0) { Exception exception = arg_3F_0; if (exception is OutOfMemoryException || exception is StackOverflowException || exception is ThreadAbortException) { throw; } } catch { } } public void AddCookie(string name, string value, string domain) { try { this.m_CookieContainer.Add(new Cookie(name, value, #=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851807711), domain)); } catch { } } public string GetCookieValue(string url, string name) { string result; try { CookieCollection cookies = this.m_CookieContainer.GetCookies(new Uri(url)); Cookie cookie = cookies[name]; if (cookie == null) { result = string.Empty; } else { result = cookie.Value; } } catch { result = string.Empty; } return result; } private string m_DecodeString(byte[] data) { UTF8Encoding uTF8Encoding = new UTF8Encoding(false, true); string result = string.Empty; try { result = uTF8Encoding.GetString(data); } catch (object arg_3B_0) { result = Encoding.Default.GetString(data); } return result; } public string DownloadString(string url) { byte[] data = this.DownloadData(url); return this.m_DecodeString(data); } public string DownloadStringNoRedirect(string url) { this.m_HTTPRequest = (HttpWebRequest)WebRequest.Create(url); this.m_CopyCookies(url, this.m_HTTPRequest); this.CopyHeadersTo(this.m_HTTPRequest); this.m_HTTPRequest.Method = #=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804743); this.m_HTTPRequest.KeepAlive = false; this.m_HTTPRequest.AllowAutoRedirect = false; this.m_HTTPRequest.ReadWriteTimeout = 140000; this.m_HTTPRequest.Timeout = 140000; this.m_HTTPResponse = (HttpWebResponse)this.m_HTTPRequest.GetResponse(); this.m_ResponseStream = this.m_HTTPResponse.GetResponseStream(); StreamReader streamReader = new StreamReader(this.m_ResponseStream, this.m_GuessDownloadEncoding(this.m_HTTPRequest)); string result = streamReader.ReadToEnd(); streamReader.Close(); this.m_HTTPResponse.Close(); return result; } public void OpenUrl(Uri url) { this.m_HTTPRequest = (HttpWebRequest)WebRequest.Create(url); this.m_CopyCookies(url.ToString(), this.m_HTTPRequest); this.CopyHeadersTo(this.m_HTTPRequest); this.m_HTTPRequest.Method = #=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804743); this.m_HTTPRequest.ReadWriteTimeout = 140000; this.m_HTTPRequest.Timeout = 140000; this.m_HTTPRequest.KeepAlive = false; this.m_HTTPResponse = (HttpWebResponse)this.m_HTTPRequest.GetResponse(); } public string ContinueGetHtml(bool cancel) { string result = string.Empty; if (cancel) { this.m_HTTPResponse.Close(); } else { result = this.ContinueGetHtml(); } return result; } public string ContinueGetHtml() { this.m_ResponseStream = this.m_HTTPResponse.GetResponseStream(); StreamReader streamReader = new StreamReader(this.m_ResponseStream, this.m_GuessDownloadEncoding(this.m_HTTPRequest)); string result = streamReader.ReadToEnd(); streamReader.Close(); this.m_ResponseStream.Close(); this.m_ResponseStream = null; this.m_HTTPResponse.Close(); return result; } private byte[] m_InternalDownloadData() { this.m_HTTPResponse = (HttpWebResponse)this.m_HTTPRequest.GetResponse(); this.m_ResponseStream = this.m_HTTPResponse.GetResponseStream(); MemoryStream memoryStream = new MemoryStream(); BinaryWriter binaryWriter = new BinaryWriter(memoryStream); int num = 0; int num2; do { byte[] array = new byte[2048]; num2 = this.m_ResponseStream.Read(array, 0, array.Length); if (num2 > 0) { binaryWriter.Write(array, 0, num2); num += num2; } } while (num2 > 0); memoryStream.Seek(0L, SeekOrigin.Begin); byte[] array2 = new byte[(int)((object)((IntPtr)memoryStream.Length))]; memoryStream.Read(array2, 0, (int)memoryStream.Length); memoryStream.Close(); this.m_HTTPResponse.Close(); this.m_ResponseStream.Close(); this.m_ResponseStream = null; return array2; } public byte[] DownloadData(string url) { this.m_HTTPRequest = (HttpWebRequest)WebRequest.Create(url); this.m_CopyCookies(url, this.m_HTTPRequest); this.CopyHeadersTo(this.m_HTTPRequest); this.m_HTTPRequest.Method = #=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804743); this.m_HTTPRequest.KeepAlive = false; this.m_HTTPRequest.ReadWriteTimeout = 140000; this.m_HTTPRequest.Timeout = 140000; return this.m_InternalDownloadData(); } public string UploadString(string url, string data) { this.m_HTTPRequest = (HttpWebRequest)WebRequest.Create(url); this.m_CopyCookies(url, this.m_HTTPRequest); this.CopyHeadersTo(this.m_HTTPRequest); this.m_HTTPRequest.Method = #=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804745); this.m_HTTPRequest.ReadWriteTimeout = 140000; this.m_HTTPRequest.Timeout = 140000; this.m_HTTPRequest.ServicePoint.Expect100Continue = false; if (this.m_HTTPRequest.Headers[HttpRequestHeader.Referer] == null && this.m_HTTPResponse != null && this.m_HTTPResponse.ResponseUri != null && this.m_HTTPResponse.ResponseUri.ToString().Length > 0) { this.m_HTTPRequest.Referer = this.m_HTTPResponse.ResponseUri.ToString(); } this.m_HTTPRequest.ContentType = #=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804798); byte[] bytes = Encoding.Default.GetBytes(data); Stream requestStream = this.m_HTTPRequest.GetRequestStream(); requestStream.Write(bytes, 0, bytes.Length); requestStream.Close(); byte[] data2 = this.m_InternalDownloadData(); return this.m_DecodeString(data2); } public string GetRedirection(string url) { this.m_HTTPRequest = (HttpWebRequest)WebRequest.Create(url); this.CopyHeadersTo(this.m_HTTPRequest); this.m_CopyCookies(url, this.m_HTTPRequest); this.m_HTTPRequest.AllowAutoRedirect = false; this.m_HTTPRequest.Method = #=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804743); this.m_HTTPRequest.KeepAlive = false; this.m_HTTPRequest.ReadWriteTimeout = 140000; this.m_HTTPRequest.Timeout = 140000; this.m_HTTPResponse = (HttpWebResponse)this.m_HTTPRequest.GetResponse(); string result = this.m_HTTPResponse.Headers.Get(#=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804678)); this.m_HTTPResponse.Close(); return result; } public void DownloadFileAsync(string url, long StartPoint, string completeFilePath) { Uri url2 = new Uri(url); this.DownloadFileAsync(url2, StartPoint, completeFilePath); } public void DownloadFilePostAsync(Uri url, long StartPoint, string completeFilePath, string data) { this.m_StartPoint = StartPoint; this.m_IsFileDownload = true; this.m_ReceiveBuffer = new byte[4096]; this.m_TotalReaded = 0L; this.m_SessionReceived = 0L; this.m_FinalFilePath = completeFilePath; this.m_CompleteFilePath = completeFilePath + #=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804683); this.m_HTTPRequest = (HttpWebRequest)WebRequest.Create(url); this.CopyHeadersTo(this.m_HTTPRequest); this.m_CopyCookies(url.ToString(), this.m_HTTPRequest); if (StartPoint >= 0L && File.Exists(this.m_CompleteFilePath)) { FileInfo fileInfo = new FileInfo(this.m_CompleteFilePath); this.m_StartPoint = fileInfo.Length; } if (this.m_StartPoint > 0L) { this.m_AddRange(this.m_StartPoint); } this.m_HTTPRequest.Method = #=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804745); this.m_HTTPRequest.ContentType = #=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804798); this.m_HTTPRequest.ServicePoint.Expect100Continue = false; this.m_HTTPRequest.KeepAlive = false; this.m_HTTPRequest.ReadWriteTimeout = 140000; this.m_HTTPRequest.Timeout = 140000; byte[] bytes = Encoding.Default.GetBytes(data); Stream requestStream = this.m_HTTPRequest.GetRequestStream(); requestStream.Write(bytes, 0, bytes.Length); requestStream.Close(); IAsyncResult asyncResult = this.m_HTTPRequest.BeginGetResponse(new AsyncCallback(this.m_OnResponse), null); ThreadPool.RegisterWaitForSingleObject(asyncResult.AsyncWaitHandle, new WaitOrTimerCallback(WebClientEx.TimeoutCallback), this.m_HTTPRequest, 140000, true); } public HttpStatusCode OpenDownloadPost(Uri url, long StartPoint, string completeFilePath, string data) { this.m_StartPoint = StartPoint; this.m_IsFileDownload = true; this.m_ReceiveBuffer = new byte[4096]; this.m_TotalReaded = 0L; this.m_SessionReceived = 0L; this.m_FinalFilePath = completeFilePath; this.m_CompleteFilePath = completeFilePath + #=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804683); this.m_HTTPRequest = (HttpWebRequest)WebRequest.Create(url); this.CopyHeadersTo(this.m_HTTPRequest); this.m_CopyCookies(url.ToString(), this.m_HTTPRequest); if (StartPoint >= 0L && File.Exists(this.m_CompleteFilePath)) { FileInfo fileInfo = new FileInfo(this.m_CompleteFilePath); this.m_StartPoint = fileInfo.Length; } if (this.m_StartPoint > 0L) { this.m_AddRange(this.m_StartPoint); } this.m_HTTPRequest.Method = #=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804745); this.m_HTTPRequest.ContentType = #=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804798); this.m_HTTPRequest.ServicePoint.Expect100Continue = false; this.m_HTTPRequest.KeepAlive = false; this.m_HTTPRequest.ReadWriteTimeout = 140000; this.m_HTTPRequest.Timeout = 140000; byte[] bytes = Encoding.Default.GetBytes(data); Stream requestStream = this.m_HTTPRequest.GetRequestStream(); requestStream.Write(bytes, 0, bytes.Length); requestStream.Close(); HttpStatusCode statusCode; try { this.m_HTTPResponse = (HttpWebResponse)this.m_HTTPRequest.GetResponse(); } catch (WebException arg_17F_0) { WebException webException = arg_17F_0; this.m_HTTPResponse = (HttpWebResponse)webException.Response; if (this.m_HTTPResponse != null) { statusCode = this.m_HTTPResponse.StatusCode; return statusCode; } this.m_AsyncError(webException); throw webException; } catch (Exception arg_1B7_0) { Exception exception = arg_1B7_0; this.m_AsyncError(exception); throw exception; } return this.m_HTTPResponse.StatusCode; return statusCode; } public void DownloadFileAsync(Uri url, long StartPoint, string completeFilePath) { this.m_StartPoint = StartPoint; this.m_IsFileDownload = true; this.m_ReceiveBuffer = new byte[4096]; this.m_TotalReaded = 0L; this.m_SessionReceived = 0L; this.m_FinalFilePath = completeFilePath; this.m_CompleteFilePath = completeFilePath + #=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804683); this.m_HTTPRequest = (HttpWebRequest)WebRequest.Create(url); this.CopyHeadersTo(this.m_HTTPRequest); this.m_CopyCookies(url.ToString(), this.m_HTTPRequest); if (File.Exists(this.m_CompleteFilePath)) { FileInfo fileInfo = new FileInfo(this.m_CompleteFilePath); this.m_StartPoint = fileInfo.Length; } if (this.m_StartPoint > 0L) { this.m_AddRange(this.m_StartPoint); } this.m_HTTPRequest.Method = #=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804743); this.m_HTTPRequest.KeepAlive = false; this.m_HTTPRequest.ReadWriteTimeout = 140000; this.m_HTTPRequest.Timeout = 140000; this.m_ResponseCallback = new AsyncCallback(this.m_OnResponse); IAsyncResult asyncResult = this.m_HTTPRequest.BeginGetResponse(this.m_ResponseCallback, null); ThreadPool.RegisterWaitForSingleObject(asyncResult.AsyncWaitHandle, new WaitOrTimerCallback(WebClientEx.TimeoutCallback), this.m_HTTPRequest, 140000, true); } public HttpStatusCode OpenDownload(Uri url, long StartPoint, string completeFilePath) { this.m_StartPoint = StartPoint; this.m_IsFileDownload = true; this.m_ReceiveBuffer = new byte[4096]; this.m_TotalReaded = 0L; this.m_SessionReceived = 0L; this.m_FinalFilePath = completeFilePath; this.m_CompleteFilePath = completeFilePath + #=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804683); this.m_HTTPRequest = (HttpWebRequest)WebRequest.Create(url); this.CopyHeadersTo(this.m_HTTPRequest); this.m_CopyCookies(url.ToString(), this.m_HTTPRequest); if (StartPoint >= 0L && File.Exists(this.m_CompleteFilePath)) { FileInfo fileInfo = new FileInfo(this.m_CompleteFilePath); this.m_StartPoint = fileInfo.Length; } if (this.m_StartPoint > 0L) { this.m_AddRange(this.m_StartPoint); } this.m_HTTPRequest.Method = #=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804743); this.m_HTTPRequest.KeepAlive = false; this.m_HTTPRequest.ReadWriteTimeout = 140000; this.m_HTTPRequest.Timeout = 140000; HttpStatusCode statusCode; try { this.m_HTTPResponse = (HttpWebResponse)this.m_HTTPRequest.GetResponse(); } catch (WebException arg_12B_0) { WebException webException = arg_12B_0; this.m_HTTPResponse = (HttpWebResponse)webException.Response; if (this.m_HTTPResponse != null) { statusCode = this.m_HTTPResponse.StatusCode; return statusCode; } this.m_AsyncError(webException); throw webException; } catch (Exception arg_162_0) { Exception exception = arg_162_0; this.m_AsyncError(exception); throw exception; } return this.m_HTTPResponse.StatusCode; return statusCode; } public void ContinueDownloadFile(bool cancel) { if (cancel) { this.m_HTTPResponse.Close(); return; } this.m_ProcessResponse(); } public void DownloadStringAsync(Uri url, object state) { this.m_UserState = state; this.DownloadStringAsync(url); } public void DownloadStringAsync(Uri url) { this.m_IsStringDownload = true; this.m_ReceiveBuffer = new byte[4096]; this.m_TotalReaded = 0L; this.m_SessionReceived = 0L; this.m_HTTPRequest = (HttpWebRequest)WebRequest.Create(url); this.CopyHeadersTo(this.m_HTTPRequest); this.m_CopyCookies(url.ToString(), this.m_HTTPRequest); if (this.m_StartPoint > 0L) { this.m_AddRange(this.m_StartPoint); } this.m_HTTPRequest.Method = #=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804743); this.m_HTTPRequest.ReadWriteTimeout = 140000; this.m_HTTPRequest.Timeout = 140000; IAsyncResult asyncResult = this.m_HTTPRequest.BeginGetResponse(new AsyncCallback(this.m_OnResponse), null); ThreadPool.RegisterWaitForSingleObject(asyncResult.AsyncWaitHandle, new WaitOrTimerCallback(WebClientEx.TimeoutCallback), this.m_HTTPRequest, 140000, true); } public void DownloadDataAsync(Uri url, object state) { this.m_UserState = state; this.DownloadDataAsync(url); } public void DownloadDataAsync(Uri url) { this.m_IsDataDownload = true; this.m_ReceiveBuffer = new byte[4096]; this.m_TotalReaded = 0L; this.m_SessionReceived = 0L; this.m_HTTPRequest = (HttpWebRequest)WebRequest.Create(url); this.CopyHeadersTo(this.m_HTTPRequest); this.m_CopyCookies(url.ToString(), this.m_HTTPRequest); this.m_HTTPRequest.Method = #=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804743); this.m_HTTPRequest.ReadWriteTimeout = 140000; this.m_HTTPRequest.Timeout = 140000; IAsyncResult asyncResult = this.m_HTTPRequest.BeginGetResponse(new AsyncCallback(this.m_OnResponse), null); ThreadPool.RegisterWaitForSingleObject(asyncResult.AsyncWaitHandle, new WaitOrTimerCallback(WebClientEx.TimeoutCallback), this.m_HTTPRequest, 140000, true); } private void m_ParseContentRange(string range) { Regex regex = new Regex(#=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804735)); Match match = regex.Match(range); if (match.Success) { long num = long.Parse(match.Result(#=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804918))); long num2 = long.Parse(match.Result(#=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804923))); this.FileSize = num2 - num; } } private void m_AsyncError(Exception e) { try { if (this.m_ResponseStream != null) { this.m_ResponseStream.Close(); this.m_ResponseStream = null; } if (this.m_HTTPRequest != null) { this.m_HTTPRequest.Abort(); } if (this.m_HTTPResponse != null) { this.m_HTTPResponse.Close(); } } catch { } if (this.m_IsFileDownload) { if (this.m_File != null) { try { this.m_File.Close(); } catch { } } if (this.DownloadFileCompleted != null) { this.DownloadFileCompleted(this, new AsyncCompletedEventArgs(e, this.m_Cancelled, this)); } this.m_Cancelled = false; return; } if (this.m_IsStringDownload) { if (this.DownloadStringCompleted != null) { this.DownloadStringCompleted(this, new #=qgdDUb37$8N8uOCfcJZrRJEviGP23Jgn3luxy_1kxcQN8THXu8DgFOyWWq20ga7lh(null, e, this.m_Cancelled, this.m_UserState)); } this.m_Cancelled = false; return; } if (this.m_IsDataDownload && this.DownloadDataCompleted != null) { #=qvOKTrDDIi$07IldXhFh95G7SYUSCpDLKs6LdxMarvkI3iVETb95XKjhr2xNdmo0e #=qHfBJJrKQKFC$RnwoTCSBaQ== = new #=qvOKTrDDIi$07IldXhFh95G7SYUSCpDLKs6LdxMarvkI3iVETb95XKjhr2xNdmo0e(null, e, this.m_Cancelled, this.m_UserState); this.DownloadDataCompleted(this, #=qHfBJJrKQKFC$RnwoTCSBaQ==); this.m_Cancelled = false; } } private void m_ProcessResponse() { try { bool flag = false; if (this.m_HTTPResponse.StatusCode == HttpStatusCode.PartialContent) { flag = true; this.m_TotalReaded += this.m_StartPoint; } this.FileSize = this.m_HTTPResponse.ContentLength; if (this.FileSize <= 0L) { string text = this.m_HTTPResponse.Headers[HttpResponseHeader.ContentRange]; if (text != null && text.Length > 0) { this.m_ParseContentRange(text); } } else { if (this.m_StartPoint > 0L && flag) { this.FileSize += this.m_StartPoint; } } if (this.FileSize <= 0L) { this.FileSize = 0L; } if (this.m_IsFileDownload) { string directoryName = Path.GetDirectoryName(this.m_CompleteFilePath); if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } if (flag && File.Exists(this.m_CompleteFilePath)) { this.m_File = new FileStream(this.m_CompleteFilePath, FileMode.Append, FileAccess.Write, FileShare.Read); } else { this.m_File = new FileStream(this.m_CompleteFilePath, FileMode.Create, FileAccess.ReadWrite, FileShare.Read); } #=qMGT9u9lKl46KbHHdehV$rg==.#=qfiCtdcdSJrt$SkFksdUMog==().#=qFbiR043zZxCuFunMt$bTcpP5m$Zo1UQDaCcAKIkR_xptUHTP50cETYhShV0qXm3U(this.m_CompleteFilePath); } if (this.m_IsStringDownload || this.m_IsDataDownload) { this.m_DataStream = new MemoryStream(); } this.m_ResponseStream = this.m_HTTPResponse.GetResponseStream(); IAsyncResult asyncResult = this.m_ResponseStream.BeginRead(this.m_ReceiveBuffer, 0, this.m_ReceiveBuffer.Length, new AsyncCallback(this.m_OnDataReceived), null); ThreadPool.RegisterWaitForSingleObject(asyncResult.AsyncWaitHandle, new WaitOrTimerCallback(WebClientEx.TimeoutCallback), this.m_HTTPRequest, 140000, true); } catch (Exception arg_1D6_0) { Exception e = arg_1D6_0; this.m_AsyncError(e); } } private void m_OnResponse(IAsyncResult asynchronousResult) { try { this.m_HTTPResponse = (HttpWebResponse)this.m_HTTPRequest.EndGetResponse(asynchronousResult); this.m_ProcessResponse(); } catch (Exception arg_3F_0) { Exception e = arg_3F_0; this.m_AsyncError(e); } } private void m_OnDataReceived(IAsyncResult asynchronousResult) { try { if (this.WaitTime > 0.0) { Thread.Sleep(TimeSpan.FromMilliseconds(this.WaitTime)); } int num = this.m_ResponseStream.EndRead(asynchronousResult); this.m_TotalReaded += (long)num; this.m_SessionReceived += (long)num; if (this.DownloadProgressChanged != null) { this.DownloadProgressChanged(this, new #=qupV9QhoRvQxijeiu6py$dGIVkskaneiwidgK8vCBvCvRpgxOV3ptYfJVm3W2El$L(this.m_TotalReaded, this.FileSize, this.m_SessionReceived)); } if (this.m_IsFileDownload) { this.m_File.Write(this.m_ReceiveBuffer, 0, num); } if (this.m_IsStringDownload || this.m_IsDataDownload) { this.m_DataStream.Write(this.m_ReceiveBuffer, 0, num); } if (num > 0) { IAsyncResult asyncResult = this.m_ResponseStream.BeginRead(this.m_ReceiveBuffer, 0, this.m_ReceiveBuffer.Length, new AsyncCallback(this.m_OnDataReceived), null); ThreadPool.RegisterWaitForSingleObject(asyncResult.AsyncWaitHandle, new WaitOrTimerCallback(WebClientEx.TimeoutCallback), this.m_HTTPRequest, 140000, true); } else { this.m_HTTPResponse.Close(); this.m_ResponseStream.Close(); this.m_ResponseStream = null; if (this.m_IsFileDownload) { this.m_Completefile(); } else { if (this.m_IsStringDownload) { string @string = this.m_GuessDownloadEncoding(this.m_HTTPRequest).GetString(this.m_DataStream.GetBuffer(), 0, (int)this.m_DataStream.Length); this.m_DataStream.Close(); this.m_DataStream = null; if (this.DownloadStringCompleted != null) { this.DownloadStringCompleted(this, new #=qgdDUb37$8N8uOCfcJZrRJEviGP23Jgn3luxy_1kxcQN8THXu8DgFOyWWq20ga7lh(@string, null, false, this.m_UserState)); this.m_UserState = null; } } else { if (this.m_IsDataDownload) { if (this.DownloadDataCompleted != null) { byte[] array = new byte[(int)((object)((IntPtr)this.m_DataStream.Length))]; this.m_DataStream.Seek(0L, SeekOrigin.Begin); this.m_DataStream.Read(array, 0, (int)this.m_DataStream.Length); #=qvOKTrDDIi$07IldXhFh95G7SYUSCpDLKs6LdxMarvkI3iVETb95XKjhr2xNdmo0e #=qHfBJJrKQKFC$RnwoTCSBaQ== = new #=qvOKTrDDIi$07IldXhFh95G7SYUSCpDLKs6LdxMarvkI3iVETb95XKjhr2xNdmo0e(array, null, false, this.m_UserState); this.DownloadDataCompleted(this, #=qHfBJJrKQKFC$RnwoTCSBaQ==); this.m_UserState = null; } this.m_DataStream.Close(); this.m_DataStream = null; } } } } } catch (Exception arg_294_0) { Exception e = arg_294_0; if (!this.m_Cancelled && this.m_IsFileDownload) { try { string text = this.m_HTTPResponse.Headers[HttpResponseHeader.ContentRange]; long num2 = -1L; if (text != null && text.Length > 0) { text = Downloader.MatchAndReplace(text, #=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804906), #=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804468)); if (text.Length > 0) { num2 = long.Parse(text); } } if (num2 == this.m_TotalReaded || this.m_SessionReceived == this.m_HTTPResponse.ContentLength) { this.m_Completefile(); return; } } catch { this.m_AsyncError(e); } } this.m_AsyncError(e); } } private void m_Completefile() { this.m_File.Close(); this.m_File = null; if (File.Exists(this.m_FinalFilePath)) { File.Delete(this.m_FinalFilePath); } File.Move(this.m_CompleteFilePath, this.m_FinalFilePath); if (this.DownloadFileCompleted != null) { this.DownloadFileCompleted(this, new AsyncCompletedEventArgs(null, false, this)); } } private Encoding m_GuessDownloadEncoding(WebRequest request) { Encoding result; try { string text = request.Headers[HttpRequestHeader.ContentType]; if (text == null) { result = Encoding.Default; return result; } string[] array = text.ToLower(CultureInfo.InvariantCulture).Split(new char[] { ';', '=', ' ' }); bool flag = false; string[] array2 = array; for (int i = 0; i < array2.Length; i++) { string text2 = array2[i]; if (text2 == #=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804805)) { flag = true; } else { if (flag) { result = Encoding.GetEncoding(text2); return result; } } } } catch (Exception arg_B4_0) { Exception exception = arg_B4_0; if (exception is ThreadAbortException || exception is StackOverflowException || exception is OutOfMemoryException) { throw; } } catch { } return Encoding.Default; return result; } private void CopyHeadersTo(WebRequest request) { if (this.Headers != null && request is HttpWebRequest) { string text = this.Headers[#=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804811)]; string text2 = this.Headers[#=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804858)]; string text3 = this.Headers[#=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804841)]; string text4 = this.Headers[#=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851805510)]; string text5 = this.Headers[#=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851805513)]; string text6 = this.Headers[#=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851809577)]; this.Headers.Remove(#=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804811)); this.Headers.Remove(#=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804858)); this.Headers.Remove(#=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851804841)); this.Headers.Remove(#=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851805510)); this.Headers.Remove(#=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851805513)); this.Headers.Remove(#=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851809577)); request.Headers = this.Headers; if (text != null && text.Length > 0) { ((HttpWebRequest)request).Accept = text; } if (text2 != null && text2.Length > 0) { ((HttpWebRequest)request).Connection = text2; } if (text3 != null && text3.Length > 0) { ((HttpWebRequest)request).ContentType = text3; } if (text4 != null && text4.Length > 0) { ((HttpWebRequest)request).Expect = text4; } if (text5 != null && text5.Length > 0) { ((HttpWebRequest)request).Referer = text5; } if (text6 != null && text6.Length > 0) { ((HttpWebRequest)request).UserAgent = text6; } } } private static void TimeoutCallback(object state, bool timedOut) { if (timedOut) { HttpWebRequest httpWebRequest = state as HttpWebRequest; if (httpWebRequest != null) { try { httpWebRequest.Abort(); } catch { } } } } public void Dispose() { } private void m_AddRange(long start) { if (start >= 2147483647L) { MethodInfo method = typeof(WebHeaderCollection).GetMethod(#=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851805567), BindingFlags.Instance | BindingFlags.NonPublic); string text = #=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851805458); string text2 = string.Format(#=q6agXXPacuhxFUQRBU2kIjDXlNY5o4HZ7i3gPOpY_uaJlWu8jFMhErz3DRXUOid4f.#=qLbLmXavFoaMnC2lVKdHqwA==(-1851805446), start); method.Invoke(this.m_HTTPRequest.Headers, new object[] { text, text2 }); return; } this.m_HTTPRequest.AddRange((int)start); } } }