public MinecraftBinJar GetMinecraftBinJar(CookieContainer cc = null) { // the URL to download the file from string sUrlToReadFileFrom = Location; // first, we need to get the exact size (in bytes) of the file we are downloading Uri url = new Uri(sUrlToReadFileFrom); System.Net.WebRequest req = System.Net.WebRequest.Create(url); if (cc != null && req is HttpWebRequest) { HttpWebRequest r = req as HttpWebRequest; r.CookieContainer = cc; } System.Net.WebResponse response = req.GetResponse(); // gets the size of the file in bytes Int64 iSize = response.ContentLength; // keeps track of the total bytes downloaded so we can update the progress bar //Int64 iRunningByteTotal = 0; MemoryStream streamLocal = new MemoryStream(); Stream streamRemote = response.GetResponseStream(); int iByteSize = 0; byte[] byteBuffer = new byte[iSize]; while ((iByteSize = streamRemote.Read(byteBuffer, 0, byteBuffer.Length)) > 0) { streamLocal.Write(byteBuffer, 0, iByteSize); } response.Close(); streamLocal.Position = 0; ZipFile sd = ZipFile.Read(streamLocal); MinecraftBinJar jar = new MinecraftBinJar(sd); return(jar); }
public MinecraftBinJar GetMinecraftBinJar(CookieContainer cc = null) { // the URL to download the file from string sUrlToReadFileFrom = Location; // first, we need to get the exact size (in bytes) of the file we are downloading Uri url = new Uri(sUrlToReadFileFrom); System.Net.WebRequest req = System.Net.WebRequest.Create(url); if (cc != null && req is HttpWebRequest) { HttpWebRequest r = req as HttpWebRequest; r.CookieContainer = cc; } System.Net.WebResponse response = req.GetResponse(); // gets the size of the file in bytes Int64 iSize = response.ContentLength; // keeps track of the total bytes downloaded so we can update the progress bar //Int64 iRunningByteTotal = 0; MemoryStream streamLocal = new MemoryStream(); Stream streamRemote = response.GetResponseStream(); int iByteSize = 0; byte[] byteBuffer = new byte[iSize]; while ((iByteSize = streamRemote.Read(byteBuffer, 0, byteBuffer.Length)) > 0) { streamLocal.Write(byteBuffer, 0, iByteSize); } response.Close(); streamLocal.Position = 0; ZipFile sd = ZipFile.Read(streamLocal); MinecraftBinJar jar = new MinecraftBinJar(sd); return jar; }