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:
@@ -343,6 +343,8 @@ public sealed class Saves
|
||||
var dst = Path.GetFullPath(to).TrimEnd('\\', '/');
|
||||
ctx.Require(dst);
|
||||
if (TriforceContext.SamePath(src, dst)) throw new InvalidOperationException("That is the same save folder.");
|
||||
// ((Triforce, 11-26) one inside the other: the copy would copy itself without end, or replace the folder it reads)
|
||||
if (TriforceContext.Inside(src, dst) || TriforceContext.Inside(dst, src)) throw new InvalidOperationException("One of those save folders is inside the other.");
|
||||
var locking = ctx.Env("TRIFORCE_SAVE_LOCK") != "0";
|
||||
using var dstLock = locking ? SaveLock.Take(dst) : null;
|
||||
using var srcLock = locking && !string.Equals(SaveLock.PathOf(src), SaveLock.PathOf(dst), StringComparison.OrdinalIgnoreCase) ? SaveLock.Take(src) : null;
|
||||
@@ -350,15 +352,27 @@ public sealed class Saves
|
||||
Partial.Recover(dst);
|
||||
var staged = partial.Stage(src, dst);
|
||||
string? backup = null;
|
||||
var safe = string.Concat(label.Select(c => Path.GetInvalidFileNameChars().Contains(c) || c == ' ' ? '-' : c));
|
||||
var stamp = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
|
||||
try
|
||||
{
|
||||
if (Directory.Exists(dst) && Directory.EnumerateFileSystemEntries(dst).Any())
|
||||
{
|
||||
var safe = string.Concat(label.Select(c => Path.GetInvalidFileNameChars().Contains(c) || c == ' ' ? '-' : c));
|
||||
backup = Path.Combine(backupRoot, DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + "_" + safe);
|
||||
backup = Path.Combine(backupRoot, stamp + "_" + safe);
|
||||
ctx.Require(backup);
|
||||
Directory.CreateDirectory(backup);
|
||||
CopyTree(dst, backup);
|
||||
}
|
||||
// ((Triforce, 11-26) into Triforce: a finished commit still waiting (save-tx\<uid>\ready-n) is the newest save, the one
|
||||
// the game would load next, and it is taken away below. It is backed up too, as a save of its own)
|
||||
if (WaitingCommit(dst) is { } waiting)
|
||||
{
|
||||
var newest = Path.Combine(backupRoot, stamp + "_" + safe + "-newest");
|
||||
ctx.Require(newest);
|
||||
Directory.CreateDirectory(newest);
|
||||
CopyTree(waiting, newest);
|
||||
backup ??= newest;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@@ -373,6 +387,20 @@ public sealed class Saves
|
||||
return backup;
|
||||
}
|
||||
|
||||
/// <summary>The newest finished commit waiting beside a Triforce save folder (save-tx\<uid>\ready-n), or null.</summary>
|
||||
static string? WaitingCommit(string save)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (TriforceTx(save) is not { } tx || !Directory.Exists(tx)) return null;
|
||||
return Directory.GetDirectories(tx, "ready-*")
|
||||
.Select(d => (Dir: d, M: Regex.Match(Path.GetFileName(d), @"^ready-(\d{1,9})$")))
|
||||
.Where(r => r.M.Success && IsSaveSet(r.Dir))
|
||||
.OrderByDescending(r => long.Parse(r.M.Groups[1].Value)).FirstOrDefault().Dir;
|
||||
}
|
||||
catch (Exception e) when (e is IOException || e is UnauthorizedAccessException) { return null; }
|
||||
}
|
||||
|
||||
static void CopyTree(string from, string to)
|
||||
{
|
||||
Directory.CreateDirectory(to);
|
||||
|
||||
Reference in New Issue
Block a user