This repository was archived by the owner on Oct 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPatchClientDownloader.cs
More file actions
68 lines (48 loc) · 2.35 KB
/
PatchClientDownloader.cs
File metadata and controls
68 lines (48 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using Serilog;
namespace Wizard.Application;
public sealed class PatchClientDownloader
{
private readonly HttpClient _httpClient;
public PatchClientDownloader(string wizard101Version)
{
_httpClient = new HttpClient();
_httpClient.BaseAddress =
new Uri($"http://versionak.us.wizard101.com/WizPatcher/V_{wizard101Version}/");
_httpClient.Timeout = TimeSpan.FromHours(12);
}
public async Task DownloadLatestFileListAsync(string filePath)
{
Directory.CreateDirectory(filePath);
Log.Information("PCD- Downloading LatestFileList {FilePath}", filePath);
var response =
await _httpClient.GetAsync("Windows/LatestFileList.bin", HttpCompletionOption.ResponseHeadersRead);
response.EnsureSuccessStatusCode();
await using var contentStream = await response.Content.ReadAsStreamAsync();
await using var fileStream = new FileStream(Path.Combine(filePath, "LatestFileList.bin"), FileMode.Create,
FileAccess.Write, FileShare.None, 8192, true);
await contentStream.CopyToAsync(fileStream);
}
public async Task<long> GetFileSizeAsync(string fileName)
{
Log.Information("PCD- Getting filesize for {FilePath}", fileName);
using var response =
await _httpClient.SendAsync(
new HttpRequestMessage(HttpMethod.Head, $"LatestBuild/Data/GameData/{fileName}"));
return response is { IsSuccessStatusCode: true, Content.Headers.ContentLength: not null }
? response.Content.Headers.ContentLength.Value
: 0;
}
public async Task DownloadFileAsync(string fileName, string filePath)
{
Directory.CreateDirectory(Path.Combine(filePath, Path.GetDirectoryName(fileName)!));
Log.Information("PCD- Downloading {FileName} to {FilePath}", fileName, filePath);
var response =
await _httpClient.GetAsync($"LatestBuild/Data/GameData/{fileName}",
HttpCompletionOption.ResponseHeadersRead);
response.EnsureSuccessStatusCode();
await using var contentStream = await response.Content.ReadAsStreamAsync();
await using var fileStream = new FileStream(Path.Combine(filePath, fileName), FileMode.Create,
FileAccess.Write, FileShare.None, 8192, true);
await contentStream.CopyToAsync(fileStream);
}
}