mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-29 04:18:49 -04:00
Triforce v0.8.5
A Randomizer page in the launcher, a new title screen with Mods and Save Select tabs, scaling changes applied in game, the Jabu-Jabu bars fixed, renderer frame-time work and the brightness-flash fix, and fixes from the 0.8.4 reports.
This commit is contained in:
@@ -38,9 +38,14 @@ public sealed class Downloader
|
||||
response.Headers.ETag is { IsWeak: false } tag ? tag.ToString()
|
||||
: response.Content.Headers.LastModified is { } changed ? changed.UtcDateTime.ToString("r") : "";
|
||||
|
||||
/// <summary>url to file, with progress. size is what the release lists for it, 0 when it lists none.</summary>
|
||||
public async Task ToFileAsync(HttpClient http, string url, string file, long size, Action<DownloadProgress>? progress, CancellationToken token)
|
||||
/// <summary>url to file, with progress. size is what the release lists for it, 0 when it lists none. most: when size is 0, the
|
||||
/// most the file may be (0: no limit); a server that offers or sends more is refused and nothing is kept. Only https.</summary>
|
||||
public async Task ToFileAsync(HttpClient http, string url, string file, long size, Action<DownloadProgress>? progress, CancellationToken token, long most = 0)
|
||||
{
|
||||
// ((Triforce, 11-26) an address from a release feed or GameBanana's answer that is not https is not fetched: only the size
|
||||
// was checked after it, which anyone on the way could match. A test's own server (http://127.0.0.1) in test runs only)
|
||||
if (!url.StartsWith("https://", StringComparison.OrdinalIgnoreCase) && !(ctx.TestRoot != null && url.StartsWith("http://127.0.0.1", StringComparison.Ordinal)))
|
||||
throw new IOException("Not downloaded: " + Path.GetFileName(file) + " is offered over an address that is not https (" + url + ").");
|
||||
var name = Path.GetFileName(file);
|
||||
var part = file + ".part";
|
||||
var note = part + ".of";
|
||||
@@ -103,6 +108,11 @@ public sealed class Downloader
|
||||
Forget();
|
||||
throw new IOException("The server offers " + other + " bytes as " + name + ", and the release lists " + size + ". Nothing was downloaded.");
|
||||
}
|
||||
if (size <= 0 && most > 0 && told is { } offered && offered > most)
|
||||
{
|
||||
Forget();
|
||||
throw new IOException("The server offers " + Mb(offered) + " MB as " + name + ", more than the " + Mb(most) + " MB it can be. Nothing was downloaded.");
|
||||
}
|
||||
var total = size > 0 ? size : told ?? 0;
|
||||
if (total > 0 && ctx.SpaceProblem(name, total - have, file) is { } none) throw new NoRoomException(none);
|
||||
if (have == 0)
|
||||
@@ -139,7 +149,7 @@ public sealed class Downloader
|
||||
await to.WriteAsync(buffer.AsMemory(0, n), CancellationToken.None).ConfigureAwait(false);
|
||||
have += n;
|
||||
// (a server that sends more than the file would fill the disk)
|
||||
if (total > 0 && have > total) { tooMuch = true; break; }
|
||||
if (total > 0 && have > total || size <= 0 && most > 0 && have > most) { tooMuch = true; break; }
|
||||
if (DateTime.UtcNow - shown > TimeSpan.FromMilliseconds(150))
|
||||
{
|
||||
shown = DateTime.UtcNow;
|
||||
@@ -161,7 +171,7 @@ public sealed class Downloader
|
||||
if (tooMuch)
|
||||
{
|
||||
Forget();
|
||||
throw new IOException("The server sent more than the " + total + " bytes of " + name + ". Nothing of it was kept.");
|
||||
throw new IOException("The server sent more than the " + (total > 0 ? total : most) + " bytes of " + name + ". Nothing of it was kept.");
|
||||
}
|
||||
if (total > 0 && have < total)
|
||||
throw new CutOffException("The download of " + name + " ended early, after " + Mb(have) + " of " + Mb(total) + " MB. Try again: it goes on from there.");
|
||||
@@ -188,6 +198,22 @@ public sealed class Downloader
|
||||
Say(1, have, have);
|
||||
}
|
||||
|
||||
/// <summary>((Triforce, 11-26) A text answer (JSON) read whole, but no more than max bytes once unpacked: a compressed answer
|
||||
/// of a few KB could unpack to gigabytes in ReadAsStringAsync. UTF-8, as the JSON answers are.</summary>
|
||||
public static async Task<string> TextAsync(HttpContent content, int max, CancellationToken token)
|
||||
{
|
||||
if (content.Headers.ContentLength is { } n && n > max) throw new IOException("The server's answer is " + n + " bytes, more than the " + max + " it can be.");
|
||||
await using var s = await content.ReadAsStreamAsync(token).ConfigureAwait(false);
|
||||
using var m = new MemoryStream();
|
||||
var buffer = new byte[81920];
|
||||
for (int read; (read = await s.ReadAsync(buffer, token).ConfigureAwait(false)) > 0;)
|
||||
{
|
||||
m.Write(buffer, 0, read);
|
||||
if (m.Length > max) throw new IOException("The server's answer is more than the " + max + " bytes it can be.");
|
||||
}
|
||||
return System.Text.Encoding.UTF8.GetString(m.GetBuffer(), 0, (int)m.Length);
|
||||
}
|
||||
|
||||
/// <summary>The HttpClient every release request goes through: no overall timeout (a 300 MB download takes what it takes; the
|
||||
/// release check has its own 20 s), the launcher's User-Agent (old Shell.cs Http).</summary>
|
||||
public static HttpClient CreateHttp()
|
||||
|
||||
@@ -7,7 +7,9 @@ namespace Triforce.Logic;
|
||||
/// moved aside as <name>.old and removed after (a folder), and moved back when the new one cannot go in.</summary>
|
||||
public sealed class Partial
|
||||
{
|
||||
public const string Suffix = ".partial", Aside = ".old";
|
||||
// ((Triforce, 11-26) names only the launcher makes: with ".partial" and ".old", a copy into a save folder removed a folder the
|
||||
// player had named "<save>.old" beside it, their own backup)
|
||||
public const string Suffix = ".triforce-partial", Aside = ".triforce-old";
|
||||
readonly IPlatform platform;
|
||||
public Partial(IPlatform platform) { this.platform = platform; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user