fix(workspace): newer-format editor stays usable; media learn the home's photo names
A pull onto a newer Chronos's settings made the editor throw: ProjectHistory.Replace rebased every undo and redo snapshot through ProjectMerge, which refuses to merge a newer format when both sides changed, so any non-empty undo stack broke the reload after a sync that had succeeded. Replace now drops the steps instead when either side (or a step) is of a newer format: the project is shown read-only and undo never brings back values from before the newer settings. The media learnt the home's hashes and conversion aliases only inside a replay, so a status or Save version before that compared a SHA-named base with photo-named media and read a false Modified or saved a version that only re-keyed photos. Now: - ProjectContent.SameChoices also compares the texts as placed on the frames, hashed or not (Bound), so status and commit without a home agree with the base; - a status asked of the home teaches the media its names (written under the lease, or when the lease is free), and so does a checkout of a project already here; - WorkspaceStatus.MediaOutdated reports frames moved at the home, or names the media could not learn yet, and the project menu offers Update media for it (tooltip text updated in en and it). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8256b72913
commit
43b092bd5d
10 files changed
+321
-19
No files matched your search
@@ -69,6 +69,21 @@ public static class ProjectContent
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(portableJson);
|
||||
ArgumentNullException.ThrowIfNull(frames);
|
||||
return Renamed(portableJson, frames, hashedOnly: true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The portable text with each pending frame whose photo <paramref name="frames"/> hold named as the frame holding it is,
|
||||
/// hashed or not, which copy of it included: what the text places on these frames, read so to compare two texts only
|
||||
/// (<see cref="SameChoices"/>). Unlike <see cref="Rebind"/>, a SHA-256 the frames do not know yet (the photo hashed where
|
||||
/// the text was saved, not when the frames were copied) gives way to the frame's size and capture time, so a text saved
|
||||
/// on hashed frames and one saved on frames not hashed yet read alike. Always canonical.
|
||||
/// </summary>
|
||||
private static string Bound(string portableJson, FramePhotos frames) => Canonical(Renamed(portableJson, frames, hashedOnly: false));
|
||||
|
||||
/// <summary><see cref="Rebind"/> (<paramref name="hashedOnly"/>: only onto frames that are hashed), else <see cref="Bound"/>'s renaming.</summary>
|
||||
private static string Renamed(string portableJson, FramePhotos frames, bool hashedOnly)
|
||||
{
|
||||
if (frames.Count == 0 || !portableJson.Contains("pendingFrames", StringComparison.OrdinalIgnoreCase)) return portableJson;
|
||||
if (FormatOf(portableJson) > ProjectSettings.CurrentVersion) return portableJson;
|
||||
if (JsonNode.Parse(portableJson, new JsonNodeOptions { PropertyNameCaseInsensitive = true }) is not JsonObject project
|
||||
@@ -81,15 +96,17 @@ public static class ProjectContent
|
||||
DateTime? captured = entry["capturedAt"] is JsonValue t && t.TryGetValue<DateTime>(out var time) ? time : null;
|
||||
if (string.IsNullOrEmpty(sha) && (captured is null || size < 0)) continue;
|
||||
var occurrence = entry["occurrence"] is JsonValue o && o.TryGetValue<int>(out var n) && n > 0 ? n : 0;
|
||||
// Only a frame that is hashed names a photo better than the entry does.
|
||||
if (frames.IndexOf(new FramePhoto(sha, size, captured), occurrence) is not { } at || frames[at] is not { IsHashed: true } held) continue;
|
||||
// Only a frame that is hashed names a photo better than the entry does (to keep; to compare, any frame does).
|
||||
if (frames.IndexOf(new FramePhoto(sha, size, captured), occurrence) is not { } at || frames[at] is not { } held || (hashedOnly && !held.IsHashed)) continue;
|
||||
// The copy a placement looks for under the new name: among the frames holding that SHA-256, not those of that size and time.
|
||||
var copy = frames.Occurrence(at);
|
||||
var sameTime = held.CapturedAt is { } heldAt
|
||||
? captured is { } entryAt && FramePhoto.Millisecond(heldAt) == FramePhoto.Millisecond(entryAt)
|
||||
: captured is null;
|
||||
if (string.Equals(held.Sha256, sha, StringComparison.OrdinalIgnoreCase) && held.Size == size && sameTime && copy == occurrence) continue;
|
||||
entry["sha256"] = held.Sha256!.ToLowerInvariant();
|
||||
if (string.Equals(held.Sha256 ?? string.Empty, sha ?? string.Empty, StringComparison.OrdinalIgnoreCase) && held.Size == size && sameTime
|
||||
&& copy == occurrence) continue;
|
||||
if (held.IsHashed) entry["sha256"] = held.Sha256!.ToLowerInvariant();
|
||||
else entry.Remove("sha256");
|
||||
entry["size"] = held.Size;
|
||||
if (held.CapturedAt is { } heldTime) entry["capturedAt"] = heldTime;
|
||||
else entry.Remove("capturedAt");
|
||||
@@ -169,7 +186,9 @@ public static class ProjectContent
|
||||
|
||||
/// <summary>
|
||||
/// Whether two portable texts hold the same choices on the frames of <paramref name="frames"/>: the same text, or the
|
||||
/// same once their pending frames are named as the frames hold their photos now (<see cref="Rebind"/>).
|
||||
/// same once their pending frames are named as the frames hold their photos now (<see cref="Rebind"/>), or as the frame
|
||||
/// each lands on is named, hashed or not (<see cref="Bound"/>): a version saved where a photo was hashed after these
|
||||
/// frames were copied holds what a working state saved on them does, so it reads neither as a change nor as one to save.
|
||||
/// </summary>
|
||||
/// <exception cref="JsonException">A text is not a project object.</exception>
|
||||
public static bool SameChoices(string portable, string other, FramePhotos frames)
|
||||
@@ -177,7 +196,9 @@ public static class ProjectContent
|
||||
ArgumentNullException.ThrowIfNull(portable);
|
||||
ArgumentNullException.ThrowIfNull(other);
|
||||
ArgumentNullException.ThrowIfNull(frames);
|
||||
return portable == other || (frames.Count > 0 && Rebind(portable, frames) == Rebind(other, frames));
|
||||
if (portable == other) return true;
|
||||
if (frames.Count == 0) return false;
|
||||
return Rebind(portable, frames) == Rebind(other, frames) || (frames.HasUnhashed && Bound(portable, frames) == Bound(other, frames));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in new issue
Block a user