Triforce v0.5.2

The new launcher (Windows and Linux: the game's own look, music and settings, saves and mods pages, smaller updates in parts), benchmark mode (Find my best settings: the game tours four places by itself and writes its results), Quit and Restart in the pause menu under Mods, Squadala! in the Mods menu, battle music above 60 fps, menu text, the controller in the menus with the game in the background, the whole GameBanana list, RX 580 and RX 5000/6000 shader fixes, the pipeline cache kept through an update, async present black flashes, and faster builds.
This commit is contained in:
ruckus7382sfgsgdf
2026-11-19 10:52:50 -06:00
parent a750a21025
commit fb26495475
167 changed files with 21552 additions and 293 deletions

View File

@@ -41,6 +41,11 @@ static class Program
public const string ReleaseApi = Home + "/api/v1/repos/triforce/downloads/releases?limit=1";
public const string SetupAsset = "TriforceSetup.exe";
public const string ToolsAsset = "Triforce-Tools.zip";
// ((Triforce, 11-18) the tools in two parts (setup/pack_tools.ps1): the base, which does not change from one release to the
// next (the compiler, Python, the libraries: 95 % of the zip), and the code, with the base's list (Tools.BaseList). An update
// fetches the code and keeps the base it has: 12 MB instead of 284. Triforce-Tools.zip stays for older Setups and a first install)
public const string ToolsCodeAsset = "Triforce-Tools-code.zip";
public const string ToolsBaseAsset = "Triforce-Tools-base.zip";
public const string AppName = "Triforce";
[STAThread]
@@ -373,6 +378,8 @@ sealed class Release
public string Tag = "";
public string? SetupUrl, ToolsUrl;
public long SetupSize, ToolsSize;
public string? ToolsCodeUrl, ToolsBaseUrl; // ((Triforce) the tools in parts, when the release has them: Tools.UnpackParts)
public long ToolsCodeSize, ToolsBaseSize;
/// The latest release (TRIFORCE_RELEASE_API overrides the address, for testing against a local copy)
public static async Task<Release> Latest(HttpClient http, CancellationToken token)
@@ -406,6 +413,8 @@ sealed class Release
var size = f.TryGetValue("size", out var s) && s != null ? Convert.ToInt64(s) : 0;
if (string.Equals(name, Program.SetupAsset, StringComparison.OrdinalIgnoreCase)) { r.SetupUrl = link; r.SetupSize = size; }
if (string.Equals(name, Program.ToolsAsset, StringComparison.OrdinalIgnoreCase)) { r.ToolsUrl = link; r.ToolsSize = size; }
if (string.Equals(name, Program.ToolsCodeAsset, StringComparison.OrdinalIgnoreCase)) { r.ToolsCodeUrl = link; r.ToolsCodeSize = size; }
if (string.Equals(name, Program.ToolsBaseAsset, StringComparison.OrdinalIgnoreCase)) { r.ToolsBaseUrl = link; r.ToolsBaseSize = size; }
}
return r;
}
@@ -501,6 +510,8 @@ sealed class Tools
}
}
File.WriteAllText(Path.Combine(part, "version.txt"), tag + "\n");
// ((Triforce) a whole zip's base is the one its list names: the next update keeps it without reading it again)
if (ReadBaseList(Path.Combine(part, BaseList)) is { } listed) File.WriteAllText(Path.Combine(part, BaseHave), listed.Id + "\n");
}
catch (Exception)
{
@@ -522,6 +533,169 @@ sealed class Tools
try { if (Directory.Exists(old)) Directory.Delete(old, true); } catch (Exception) { }
progress(1);
}
// ---- (Triforce, 11-18) the tools in two parts: the base kept from one release to the next ----
// setup/pack_tools.ps1 lists the base (the compiler, Python, the libraries: the folders that do not change between releases,
// 95 % of Triforce-Tools.zip) in tools/base.list, which the code part and the whole zip carry. An update of tools that hold
// that base fetches the code part alone (12 MB, not 284; at a release the download server's line was full and each player got
// 75 KB/s) and moves the base folders over from the tools there now. The base is the list's when every file it names is there
// with its size and SHA-256 (read once: base.have then remembers the list's id, and later updates check the sizes alone).
// Anything else (no tools, another base, a file changed or gone) fetches the base part as well.
public const string BaseList = "base.list", BaseHave = "base.have";
public sealed class Base
{
public string Id = ""; // (the SHA-256 of the list's dir and file lines)
public readonly System.Collections.Generic.List<string> Dirs = new();
public readonly System.Collections.Generic.List<(string Path, long Size, string Sha)> Files = new();
}
/// A base list's text: "triforce-tools-base 1", "id <sha256>", then "dir <name>" and "file <size> <sha256> <path>"
/// lines (tab-separated, paths with /). Null when it is not one
public static Base? ParseBaseList(string text)
{
var lines = text.Replace("\r", "").Split('\n');
if (lines.Length < 2 || lines[0].Trim() != "triforce-tools-base\t1") return null;
var b = new Base();
foreach (var line in lines.Skip(1))
{
var f = line.Split('\t');
if (f.Length == 2 && f[0] == "id") b.Id = f[1].Trim().ToLowerInvariant();
else if (f.Length == 2 && f[0] == "dir" && f[1].Length > 0 && Mods.Unsafe(f[1], true) == null && !f[1].Contains('/')) b.Dirs.Add(f[1]);
else if (f.Length == 4 && f[0] == "file" && long.TryParse(f[1], out var size) && f[2].Length == 64 && Mods.Unsafe(f[3], true) == null)
b.Files.Add((f[3], size, f[2].ToLowerInvariant()));
else if (line.Length > 0) return null; // (a line it does not know: another format, not guessed at)
}
return b.Id.Length == 64 && b.Dirs.Count > 0 && b.Files.Count > 0 ? b : null;
}
public static Base? ReadBaseList(string path)
{
try { return File.Exists(path) ? ParseBaseList(File.ReadAllText(path)) : null; } catch (Exception) { return null; }
}
/// The base list in a code (or whole) zip, null when it has none
public static Base? BaseListIn(string zip)
{
using var z = ZipFile.OpenRead(zip);
var e = z.Entries.FirstOrDefault(x => x.FullName.Replace('\\', '/') is var n && (n == "tools/" + BaseList || n == BaseList));
if (e == null) return null;
using var r = new StreamReader(e.Open());
return ParseBaseList(r.ReadToEnd());
}
/// Whether the tools in folder hold base b whole (progress: 0..1 while it reads the files). Remembers a match in base.have
public static bool HasBase(Base b, string folder, Action<double> progress)
{
foreach (var d in b.Dirs)
if (!Directory.Exists(Path.Combine(folder, d))) return false;
foreach (var f in b.Files) // (every file there, at its size: quick, and enough once base.have says the rest was read)
{
var fi = new FileInfo(Path.Combine(folder, f.Path));
if (!fi.Exists || fi.Length != f.Size) return false;
}
string? had = null;
try { had = File.Exists(Path.Combine(folder, BaseHave)) ? File.ReadAllText(Path.Combine(folder, BaseHave)).Trim() : null; } catch (Exception) { }
if (had == b.Id) return true;
long total = Math.Max(1, b.Files.Sum(f => f.Size)), done = 0;
using (var sha = System.Security.Cryptography.SHA256.Create())
foreach (var f in b.Files)
{
string got;
using (var s = File.OpenRead(Path.Combine(folder, f.Path))) got = string.Concat(sha.ComputeHash(s).Select(x => x.ToString("x2")));
if (got != f.Sha) return false;
done += f.Size;
progress((double)done / total);
}
try { File.WriteAllText(Path.Combine(folder, BaseHave), b.Id + "\n"); } catch (Exception) { }
return true;
}
/// The tools folder made again from a code zip and either a base zip (baseZip) or the base folders of the tools there now
/// (baseZip null: HasBase said they are b's). The old folder is replaced only once the new one is complete; what fails on
/// the way puts the base folders back where they were
public static void UnpackParts(string codeZip, string? baseZip, Base b, string tag, Action<double> progress)
{
var target = Folder;
var part = target + ".part";
if (Directory.Exists(part)) Directory.Delete(part, true);
var moved = new System.Collections.Generic.List<string>();
void PutBack()
{
foreach (var d in moved)
try { if (Directory.Exists(target) && !Directory.Exists(Path.Combine(target, d))) Directory.Move(Path.Combine(part, d), Path.Combine(target, d)); }
catch (Exception) { }
}
try
{
Directory.CreateDirectory(part);
Extract(codeZip, part, f => progress(baseZip == null ? f * 0.9 : f * 0.1));
if (baseZip != null) Extract(baseZip, part, f => progress(0.1 + f * 0.8));
else
foreach (var d in b.Dirs)
{
var into = Path.Combine(part, d);
if (Directory.Exists(into)) Directory.Delete(into, true); // (a code zip has none of them; never mixed)
Directory.Move(Path.Combine(target, d), into);
moved.Add(d);
}
foreach (var f in b.Files) // (the base whole in the new folder, whichever way it came)
{
var fi = new FileInfo(Path.Combine(part, f.Path));
if (!fi.Exists || fi.Length != f.Size) throw new InvalidDataException("The tools' base lacks " + f.Path + " (or it has another size): they were not changed.");
}
File.WriteAllText(Path.Combine(part, "version.txt"), tag + "\n");
File.WriteAllText(Path.Combine(part, BaseHave), b.Id + "\n");
}
catch (Exception)
{
PutBack();
try { if (Directory.Exists(part)) Directory.Delete(part, true); } catch (Exception) { }
throw;
}
var old = target + ".old";
if (Directory.Exists(old)) Directory.Delete(old, true);
if (Directory.Exists(target)) Directory.Move(target, old);
try { Directory.Move(part, target); }
catch (Exception)
{
try
{
if (!Directory.Exists(target) && Directory.Exists(old)) Directory.Move(old, target);
PutBack();
}
catch (Exception) { }
throw;
}
try { if (Directory.Exists(old)) Directory.Delete(old, true); } catch (Exception) { }
progress(1);
}
/// A tools zip's files into folder, every name checked before the first is written (as Unpack does: Mods.Unsafe)
static void Extract(string zip, string folder, Action<double> progress)
{
using var z = ZipFile.OpenRead(zip);
var bytes = z.Entries.Sum(e => e.Length) + z.Entries.Count * 4096L;
if (Space.Problem("the Triforce tools", bytes, Space.Free(folder), Space.Disk(folder)) is { } none) throw new NoRoomException(none);
var prefix = z.Entries.All(e => e.FullName.Replace('\\', '/').StartsWith("tools/", StringComparison.OrdinalIgnoreCase)) ? "tools/" : "";
foreach (var e in z.Entries)
{
var name = e.FullName.Replace('\\', '/').Substring(prefix.Length);
if (name.Length > 0 && Mods.Unsafe(name, true) is { } why)
throw new InvalidDataException("The tools' zip holds " + why + " (\"" + (name.Length > 120 ? name.Substring(0, 117) + "..." : name) + "\"): it was not unpacked.");
}
var full = Path.GetFullPath(folder) + Path.DirectorySeparatorChar;
for (var i = 0; i < z.Entries.Count; i++)
{
var e = z.Entries[i];
var name = e.FullName.Replace('\\', '/').Substring(prefix.Length);
if (name.Length == 0) continue;
var dest = Path.GetFullPath(Path.Combine(folder, name));
if (!dest.StartsWith(full, StringComparison.OrdinalIgnoreCase)) continue;
if (name.EndsWith("/")) { Directory.CreateDirectory(dest); continue; }
Directory.CreateDirectory(Path.GetDirectoryName(dest)!);
e.ExtractToFile(dest, true);
if ((i & 15) == 0) progress((double)i / z.Entries.Count);
}
}
}
/// nx2/make_game.py as a child process: its lines as they come, and how it ended.

View File

@@ -609,36 +609,44 @@ sealed partial class Shell
// unpacking, is not fetched again)
await Task.Run(Tools.Sweep);
long Length(string file) { try { return File.Exists(file) ? new FileInfo(file).Length : 0; } catch (Exception) { return 0; } }
var whole = release.ToolsSize > 0 && Length(zip) == release.ToolsSize;
var unpacked = release.ToolsSize * ToolsUnpackedTimes;
if (release.ToolsSize > 0 && Space.Problem("the Triforce tools (a download of " + (release.ToolsSize >> 20) + " MB that unpacks to about " + (unpacked >> 20) + " MB)",
(whole ? 0 : Math.Max(0, release.ToolsSize - Length(zip + ".part"))) + unpacked, Space.Free(cache), Space.Disk(cache)) is { } none)
throw new NoRoomException(none);
FetchProgress(0, "");
if (!whole)
await Download.ToFile(http, release.ToolsUrl, zip, release.ToolsSize, (f, got) => Ui(() =>
{
FetchProgress(f, (got >> 20) + " / " + (release.ToolsSize >> 20) + " MB");
stage.Charge(Art.Ruby, f * 0.7);
}), token);
else Program.Log("tools " + release.Tag + ": the zip is here already, whole (" + release.ToolsSize + " bytes)");
FetchStep.Text = "Unpacking the tools";
FetchCancel.IsEnabled = false;
FetchProgress(0, "");
try { await Task.Run(() => Tools.Unpack(zip, release.Tag, f => Ui(() => { FetchProgress(f, ""); stage.Charge(Art.Ruby, 0.7 + f * 0.3); }))); }
catch (Exception e) when (e is not NoRoomException && !Space.Full(e))
// ((Triforce, 11-18) the tools in parts (Tools.UnpackParts): tools that are there and a release that has its code
// and base apart fetch the code alone, and the base only when the one there is not the release's. Otherwise, or when
// the code part carries no base list, the whole zip, as before)
var parts = have != null && release.ToolsCodeUrl != null && release.ToolsBaseUrl != null &&
await ToolsInParts(http, release, have, cache, token);
if (!parts)
{
// (a zip that does not unpack is fetched again at the next try, not tried again; one there was no room for is kept)
try { File.Delete(zip); } catch (Exception) { }
throw;
var whole = release.ToolsSize > 0 && Length(zip) == release.ToolsSize;
var unpacked = release.ToolsSize * ToolsUnpackedTimes;
if (release.ToolsSize > 0 && Space.Problem("the Triforce tools (a download of " + (release.ToolsSize >> 20) + " MB that unpacks to about " + (unpacked >> 20) + " MB)",
(whole ? 0 : Math.Max(0, release.ToolsSize - Length(zip + ".part"))) + unpacked, Space.Free(cache), Space.Disk(cache)) is { } none)
throw new NoRoomException(none);
FetchProgress(0, "");
if (!whole)
await Download.ToFile(http, release.ToolsUrl, zip, release.ToolsSize, (f, got) => Ui(() =>
{
FetchProgress(f, (got >> 20) + " / " + (release.ToolsSize >> 20) + " MB");
stage.Charge(Art.Ruby, f * 0.7);
}), token);
else Program.Log("tools " + release.Tag + ": the zip is here already, whole (" + release.ToolsSize + " bytes)");
FetchStep.Text = "Unpacking the tools";
FetchCancel.IsEnabled = false;
FetchProgress(0, "");
try { await Task.Run(() => Tools.Unpack(zip, release.Tag, f => Ui(() => { FetchProgress(f, ""); stage.Charge(Art.Ruby, 0.7 + f * 0.3); }))); }
catch (Exception e) when (e is not NoRoomException && !Space.Full(e))
{
// (a zip that does not unpack is fetched again at the next try, not tried again; one there was no room for is kept)
try { File.Delete(zip); } catch (Exception) { }
throw;
}
FetchCancel.IsEnabled = true;
// (the zip, and what downloads of other releases left there: parts nothing will go on from)
string[] leavings = { };
try { leavings = Directory.GetFiles(cache, "Triforce-Tools-*"); } catch (Exception) { }
foreach (var f in leavings)
try { File.Delete(f); } catch (Exception) { }
Program.Log("tools " + release.Tag + " unpacked into " + Tools.Folder);
}
FetchCancel.IsEnabled = true;
// (the zip, and what downloads of other releases left there: parts nothing will go on from)
string[] leavings = { };
try { leavings = Directory.GetFiles(cache, "Triforce-Tools-*"); } catch (Exception) { }
foreach (var f in leavings)
try { File.Delete(f); } catch (Exception) { }
Program.Log("tools " + release.Tag + " unpacked into " + Tools.Folder);
}
stage.Set(Art.Ruby, true);
fetch = null;
@@ -670,6 +678,71 @@ sealed partial class Shell
void Ui(Action a) => Window.Dispatcher.BeginInvoke(a);
/// ((Triforce, 11-18) Merge's tools in parts: the release's code zip, then its base zip only when the tools here do not hold
/// its base (Tools.HasBase), and the tools folder made again from them (Tools.UnpackParts). False: the code zip names no base
/// (the whole zip is fetched instead, as before). Downloads through Guard.cs's Download, with the sizes the release lists
async Task<bool> ToolsInParts(HttpClient http, Release release, string have, string cache, CancellationToken token)
{
static long Length(string file) { try { return File.Exists(file) ? new FileInfo(file).Length : 0; } catch (Exception) { return 0; } }
var tag = string.Concat(release.Tag.Where(c => char.IsLetterOrDigit(c) || c == '.' || c == '-'));
var code = System.IO.Path.Combine(cache, "Triforce-Tools-code-" + tag + ".zip");
var baseZip = System.IO.Path.Combine(cache, "Triforce-Tools-base-" + tag + ".zip");
FetchState("Merging Triforce " + release.Tag,
"Triforce " + release.Tag + " replaces " + have + ". Downloading its new code (" + Math.Max(1, release.ToolsCodeSize >> 20) + " MB); the compiler and Python you have are kept.",
"Downloading the tools");
FetchProgress(0, "");
if (!(release.ToolsCodeSize > 0 && Length(code) == release.ToolsCodeSize))
await Download.ToFile(http, release.ToolsCodeUrl!, code, release.ToolsCodeSize, (f, got) => Ui(() =>
{
FetchProgress(f, (got >> 10) + " / " + (release.ToolsCodeSize >> 10) + " KB");
stage.Charge(Art.Ruby, f * 0.3);
}), token);
var b = await Task.Run(() => { try { return Tools.BaseListIn(code); } catch (Exception) { return null; } });
if (b == null)
{
Program.Log("tools " + release.Tag + ": the code part names no base: the whole zip instead");
try { File.Delete(code); } catch (Exception) { }
return false;
}
FetchStep.Text = "Checking the tools you have";
FetchProgress(0, "");
var keep = await Task.Run(() => { try { return Tools.HasBase(b, Tools.Folder, f => Ui(() => FetchProgress(f, ""))); } catch (Exception) { return false; } });
Program.Log("tools " + release.Tag + ": the base (" + b.Files.Count + " files) " + (keep ? "is the one here: kept" : "is not the one here: fetched"));
if (!keep)
{
FetchStep.Text = "Downloading the compiler and Python (" + (release.ToolsBaseSize >> 20) + " MB)";
var unpacked = release.ToolsBaseSize * ToolsUnpackedTimes;
if (release.ToolsBaseSize > 0 && Space.Problem("the Triforce tools (a download of " + (release.ToolsBaseSize >> 20) + " MB that unpacks to about " + (unpacked >> 20) + " MB)",
Math.Max(0, release.ToolsBaseSize - Length(baseZip + ".part")) + unpacked, Space.Free(cache), Space.Disk(cache)) is { } none)
throw new NoRoomException(none);
FetchProgress(0, "");
if (!(release.ToolsBaseSize > 0 && Length(baseZip) == release.ToolsBaseSize))
await Download.ToFile(http, release.ToolsBaseUrl!, baseZip, release.ToolsBaseSize, (f, got) => Ui(() =>
{
FetchProgress(f, (got >> 20) + " / " + (release.ToolsBaseSize >> 20) + " MB");
stage.Charge(Art.Ruby, 0.3 + f * 0.4);
}), token);
}
FetchStep.Text = "Unpacking the tools";
FetchCancel.IsEnabled = false;
FetchProgress(0, "");
try { await Task.Run(() => Tools.UnpackParts(code, keep ? null : baseZip, b, release.Tag, f => Ui(() => { FetchProgress(f, ""); stage.Charge(Art.Ruby, 0.7 + f * 0.3); }))); }
catch (Exception e) when (e is not NoRoomException && !Space.Full(e))
{
// (parts that do not unpack are fetched again at the next try, not tried again)
try { File.Delete(code); } catch (Exception) { }
try { File.Delete(baseZip); } catch (Exception) { }
throw;
}
FetchCancel.IsEnabled = true;
string[] leavings = { };
try { leavings = Directory.GetFiles(cache, "Triforce-Tools-*"); } catch (Exception) { }
foreach (var f in leavings)
try { File.Delete(f); } catch (Exception) { }
Program.Log("tools " + release.Tag + " unpacked into " + Tools.Folder + " from its parts (" + (keep ? "the base kept" : "the base fetched") + ")");
return true;
}
static string? BuiltVersion(string folder) =>
ReadValue(System.IO.Path.Combine(folder, "triforce_version.txt"), "version") ?? ReadValue(System.IO.Path.Combine(folder, "hookshot_version.txt"), "version");
@@ -942,6 +1015,17 @@ sealed partial class Shell
clock.Start();
// (NVIDIA DLSS chosen: its SDK fetched first, only what is missing, and built in; a build and an update alike)
var dlss = DlssChosen;
// ((Triforce, 11-18) #bug-tracker "Update & merge removes NVIDIA DLSS": an update keeps what the folder was built with, as
// it keeps FSR. A folder built with DLSS (its ngx\nvngx_dlss.dll) is updated with it whatever the stored choice says (a
// player's builds had DLSS, yet every Update & merge ran without it and the update took the folder's DLSS away), and the
// choice is stored again. The tick still decides for a new build)
var updated = args.IndexOf("--update") is var ui && ui >= 0 && ui + 1 < args.Count ? args[ui + 1].Trim('"') : null;
if (!dlss && updated != null && File.Exists(System.IO.Path.Combine(updated, "ngx", "nvngx_dlss.dll")))
{
dlss = true;
Install.Set("Dlss", "1");
Program.Log("update: the folder was built with NVIDIA DLSS (ngx\\nvngx_dlss.dll): updated with it");
}
if (dlss && !args.Contains("--fetch-ngx-sdk")) args.AddRange(new[] { "--fetch-ngx-sdk", "--accept-nvidia-license" });
// (11-15: AMD FSR 4 in every build: its code is built in and AMD's two signed libraries (MIT license) are fetched
// from AMD's repository and put beside the game: nx2/make_game.py --fsr, scripts/fsr_sdk.py. The Upscaler row offers

View File

@@ -1,4 +1,6 @@
# Packs Triforce-Tools.zip, the release asset Triforce Setup downloads: a "tools" folder with everything a build needs.
# ((Triforce, 11-18) and the same in two parts, Triforce-Tools-code.zip and Triforce-Tools-base.zip, with tools/base.list:
# an update fetches the code part alone and keeps the base it has. Publish all three)
# powershell -File setup\pack_tools.ps1 -Tag v1.0.0 [-Deps D:\src\release\triforce-deps] [-Out setup\out\release]
# From this checkout: nx2, host, gpu, scripts, third_party (tracked files, as they are on disk), the speed profile in work\.
# From -Deps (not in git, too big or binary): python\ (with lz4 numpy capstone unicorn zstandard), cpm\ (Vulkan headers, FFmpeg),
@@ -108,18 +110,51 @@ $e = ResEntry 14 1 $group.ToArray() 0x1030; $res.Write($e, 0, $e.Length)
# 4. the release name, read by nx2/version.py and Triforce Setup
Set-Content (Join-Path $tools 'version.txt') $Tag -Encoding ASCII
# 5. zip (tools/... inside)
$zip = Join-Path $Out 'Triforce-Tools.zip'
if (Test-Path $zip) { Remove-Item $zip }
Add-Type -AssemblyName System.IO.Compression, System.IO.Compression.FileSystem
# (entries written one by one: Windows PowerShell's CreateFromDirectory names them with backslashes)
$fs = [IO.File]::Open($zip, 'CreateNew')
$archive = New-Object IO.Compression.ZipArchive $fs, ([IO.Compression.ZipArchiveMode]::Create)
$base = (Resolve-Path $stage).Path.TrimEnd('\') + '\'
foreach ($f in Get-ChildItem $tools -Recurse -File) {
$name = $f.FullName.Substring($base.Length).Replace('\', '/')
[void][IO.Compression.ZipFileExtensions]::CreateEntryFromFile($archive, $f.FullName, $name, [IO.Compression.CompressionLevel]::Optimal)
# 4b. ((Triforce, 11-18) the base list: the folders that do not change from one release to the next (the compiler, Python, the
# libraries; 95 % of the zip), each file with its size and SHA-256 (setup/Setup.cs Tools.ParseBaseList reads it). Triforce Setup
# then updates tools that hold this base with the code part alone (Triforce-Tools-code.zip, 12 MB) and keeps the base it has;
# Triforce-Tools-base.zip only for tools that do not. third_party and assets hold tracked files, so they stay in the code)
$baseDirs = @('llvm-mingw', 'python', 'cpm', 'wgpu-native') | Where-Object { Test-Path (Join-Path $tools $_) }
$sha = [Security.Cryptography.SHA256]::Create()
$rows = New-Object Collections.Generic.List[string]
$toolsRoot = (Resolve-Path $tools).Path.TrimEnd('\') + '\'
foreach ($d in $baseDirs) {
foreach ($f in Get-ChildItem (Join-Path $tools $d) -Recurse -File) {
$rel = $f.FullName.Substring($toolsRoot.Length).Replace('\', '/')
$s = [IO.File]::OpenRead($f.FullName)
try { $h = -join ($sha.ComputeHash($s) | ForEach-Object { $_.ToString('x2') }) } finally { $s.Dispose() }
$rows.Add("file`t$($f.Length)`t$h`t$rel")
}
}
$archive.Dispose(); $fs.Dispose()
$rows.Sort([StringComparer]::Ordinal)
$body = (($baseDirs | ForEach-Object { "dir`t$_" }) + $rows) -join "`n"
$body += "`n"
$id = -join ($sha.ComputeHash([Text.Encoding]::UTF8.GetBytes($body)) | ForEach-Object { $_.ToString('x2') })
[IO.File]::WriteAllText((Join-Path $tools 'base.list'), "triforce-tools-base`t1`nid`t$id`n" + $body, (New-Object Text.UTF8Encoding $false))
"base: $($baseDirs -join ', '): $($rows.Count) files, id $($id.Substring(0, 12))"
# 5. the zips (tools/... inside): the whole one (older Setups, a first install), the code part and the base part
Add-Type -AssemblyName System.IO.Compression, System.IO.Compression.FileSystem
$base = (Resolve-Path $stage).Path.TrimEnd('\') + '\'
$all = Get-ChildItem $tools -Recurse -File
function Test-InBase($f) {
$rel = $f.FullName.Substring($toolsRoot.Length)
foreach ($d in $baseDirs) { if ($rel.StartsWith($d + '\', [StringComparison]::OrdinalIgnoreCase)) { return $true } }
return $false
}
function Write-ToolsZip([string]$zip, $files) {
if (Test-Path $zip) { Remove-Item $zip }
# (entries written one by one: Windows PowerShell's CreateFromDirectory names them with backslashes)
$fs = [IO.File]::Open($zip, 'CreateNew')
$archive = New-Object IO.Compression.ZipArchive $fs, ([IO.Compression.ZipArchiveMode]::Create)
foreach ($f in $files) {
$name = $f.FullName.Substring($base.Length).Replace('\', '/')
[void][IO.Compression.ZipFileExtensions]::CreateEntryFromFile($archive, $f.FullName, $name, [IO.Compression.CompressionLevel]::Optimal)
}
$archive.Dispose(); $fs.Dispose()
"packed $zip ({0:N1} MB)" -f ((Get-Item $zip).Length / 1MB)
}
Write-ToolsZip (Join-Path $Out 'Triforce-Tools.zip') $all
Write-ToolsZip (Join-Path $Out 'Triforce-Tools-code.zip') ($all | Where-Object { -not (Test-InBase $_) })
Write-ToolsZip (Join-Path $Out 'Triforce-Tools-base.zip') ($all | Where-Object { Test-InBase $_ })
Remove-Item -Recurse -Force $stage
"packed $zip ({0:N0} MB)" -f ((Get-Item $zip).Length / 1MB)