-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unfinished: Downloader rework Part I
- Loading branch information
Showing
10 changed files
with
445 additions
and
451 deletions.
There are no files selected for viewing
366 changes: 18 additions & 348 deletions
366
RuneScapeCacheTools/Cache/Downloader/DownloaderCache.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
RuneScapeCacheTools/Cache/Downloader/HttpFileDownloader.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System.IO; | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using Villermen.RuneScapeCacheTools.Cache.Files; | ||
using Villermen.RuneScapeCacheTools.Cache.RuneTek5; | ||
using Villermen.RuneScapeCacheTools.Exceptions; | ||
using Villermen.RuneScapeCacheTools.Extensions; | ||
|
||
namespace Villermen.RuneScapeCacheTools.Cache.Downloader | ||
{ | ||
public class HttpFileDownloader : IFileDownloader | ||
{ | ||
private readonly string _baseUrl; | ||
|
||
public HttpFileDownloader(string baseUrl = "http://content.runescape.com") | ||
{ | ||
this._baseUrl = baseUrl; | ||
} | ||
|
||
public async Task<BinaryFile> DownloadFileAsync(Index index, int fileId, CacheFileInfo fileInfo) | ||
{ | ||
var webRequest = WebRequest.CreateHttp($"{this._baseUrl}/ms?m=0&a={(int)index}&g={fileId}&c={fileInfo.Crc}&v={fileInfo.Version}"); | ||
|
||
using (var response = (HttpWebResponse)await webRequest.GetResponseAsync()) | ||
{ | ||
if (response.StatusCode != HttpStatusCode.OK) | ||
{ | ||
throw new DownloaderException($"HTTP interface responded with status code: {response.StatusCode}."); | ||
} | ||
|
||
if (response.ContentLength != fileInfo.CompressedSize - 2) | ||
{ | ||
throw new DownloaderException($"Downloaded file size {response.ContentLength} does not match expected {fileInfo.CompressedSize - 2}."); | ||
} | ||
|
||
var dataStream = new MemoryStream(); | ||
var dataWriter = new BinaryWriter(dataStream); | ||
|
||
var responseReader = new BinaryReader(response.GetResponseStream()); | ||
dataWriter.Write(responseReader.ReadBytes((int)response.ContentLength)); | ||
|
||
// Append version | ||
dataWriter.WriteUInt16BigEndian((ushort)fileInfo.Version); | ||
|
||
return RuneTek5FileDecoder.DecodeFile(dataStream.ToArray(), fileInfo); | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Threading.Tasks; | ||
using Villermen.RuneScapeCacheTools.Cache.Files; | ||
|
||
namespace Villermen.RuneScapeCacheTools.Cache.Downloader | ||
{ | ||
public interface IFileDownloader | ||
{ | ||
Task<BinaryFile> DownloadFileAsync(Index index, int fileId, CacheFileInfo fileInfo); | ||
} | ||
} |
Oops, something went wrong.