/// <summary> /// Attempts to return a stream to a file from Blizzard's CDN /// </summary> /// <param name="cdnpath">CDN file path excluding the host</param> /// <returns></returns> public async Task <Stream> OpenStream(string cdnpath, long from = -1, long to = -1) { // used as a 404 check if (await GetContentLength(cdnpath) == -1) { return(null); } foreach (var host in GetHosts()) { HttpWebRequest req = WebRequest.CreateHttp("http://" + host + "/" + cdnpath); if (from != -1 && to != -1 && to > from) { req.AddRange(from, to); } try { using var resp = (HttpWebResponse) await req.GetResponseAsync().ConfigureAwait(false); using var stream = resp.GetResponseStream(); using var respStream = ApplyDecryption ? Armadillo.Decrypt(cdnpath, stream) : stream; var resultStream = new MemoryStream((int)resp.ContentLength); await respStream.CopyToAsync(resultStream).ConfigureAwait(false); resultStream.Position = 0; return(resultStream); } catch (WebException) { } } return(null); }
/// <summary> /// Attempts to return a stream to a file from Blizzard's CDN /// </summary> /// <param name="cdnpath">CDN file path excluding the host</param> /// <returns></returns> public async Task <Stream> OpenStream(string cdnpath) { // used as a 404 check if (await GetContentLength(cdnpath) == -1) { return(null); } foreach (var host in GetHosts()) { HttpWebRequest req = WebRequest.CreateHttp("http://" + host + "/" + cdnpath); try { using (var resp = (HttpWebResponse)await req.GetResponseAsync().ConfigureAwait(false)) { var respStream = resp.GetResponseStream(); return(ApplyDecryption ? Armadillo.Decrypt(cdnpath, respStream) : respStream); } } catch (WebException) { } } return(null); }