diff --git a/docs/decisioni.md b/docs/decisioni.md
index 8830afe..a11017b 100644
--- a/docs/decisioni.md
+++ b/docs/decisioni.md
@@ -681,3 +681,4 @@ Ogni scelta tecnica presa strada facendo, con data e motivo (specifica §15).
| 2026-12-04 | Tappa E5, **risposte di Alberto del 4 dicembre 2026 alle domande 48–55 di §16**, date prima del codice. 48: una copia fatta a mano rimasta «In pausa» resta di Alberto anche quando il giro di recupero trova di nuovo la cartella: la Dashboard dice «la cartella risponde di nuovo, riprendi quando vuoi» e riparte solo con «Riprendi» o «Riprova». 49: la copia automatica cede sempre il passo a importazione, ricostruzione, «Copia in…», «Riprendi», «Riconosci le copie già presenti», zip di fotogrammi e «Cerca i video fermi», e riparte da sola dopo; mai durante una sessione del motore, e se era già partita aspetta senza bloccare nulla. 50 (**non la proposta**): ogni giro di recupero, all'avvio e ogni ora, riprova tutti i «Non riuscito» delle copie automatiche, anche quelli che non possono cambiare (oltre 4 GB su FAT32, percorso troppo lungo): niente classe di errori permanenti, niente ritmo giornaliero; fra un giro e l'altro, i passaggi che partono dopo un salvataggio in libreria non li riprovano. 51 (**non la proposta**): «Riconosci le copie già presenti» come proposto (file dovuti non «Copiato», percorso dello schema e «nome (2)»…«(50)», forma di adesso e originale, lunghezza e poi SHA-256, nessun file scritto o tolto, fotogrammi solo se già registrati), ma un «Tolto» resta «Tolto» anche se il file è tornato identico: non adotta mai un file, o un fotogramma, la cui ultima copia in quella cartella è «Tolto»; «Superato» e «Non riuscito» sì. 52: spegnere «Automatica» ferma subito la copia automatica di quella cartella; i file già copiati restano, le copie a mano non si toccano. 53: «Interrompi» su una copia automatica ferma le copie automatiche fino al giro di recupero dopo (almeno un'ora), con «Riprendi ora»; dopo un riavvio ripartono all'avvio. 54: un lavoro per cartella due minuti dopo l'ultimo file salvato, e comunque al giro; «Copia automatica in … finita» in cronologia solo se ha copiato qualcosa o qualcosa non è riuscito. 55: allargare ciò che spetta a una cartella automatica non chiede di nuovo: vale la scelta dell'accensione, e la finestra, la conferma o l'avviso dice quanti file in più partiranno. **Letture** che il progetto della tappa ha fatto di tre punti che sembravano in contrasto: (a) la riga del 27/11 sulle copie rimaste «In corso» («si riprendono dalla Dashboard, mai da sole») vale per le copie fatte a mano; i lavori automatici riprendono da soli (§4.10, «il giro orario riprova»); (b) «alla prima accensione» della risposta 6 del 18/11 vuol dire a ogni passaggio da spenta ad accesa, come dicono già la riga del 26/11 («la prossima accensione chiede di nuovo»), §4.10 e §8.3; (c) nella riga del 26/11 su «Solo i nuovi», `media.downloaded_at` non è «l'ora della riga di `_febe.jsonl`» ma l'ora in cui Febe ha salvato il file in libreria, scaricato o importato (`MediaStore`, `ImportCopier`), che la ricostruzione rimette dalla riga: «nuovo» vuol dire salvato in libreria dopo l'accensione, anche un file arrivato in ritardo (righe del 28/11) | Le domande 48–55 sono le scelte che la tappa E5 non poteva prendere da sola (§16); le tre letture tolgono contraddizioni solo apparenti fra specifica, decisioni e schema, senza cambiare nulla di deciso. 50: Alberto preferisce il lavoro ripetuto e i resoconti con gli stessi errori a una classe di errori da tenere aggiornata; fuori dal giro i «Non riuscito» aspettano perché ogni lavoro finito risveglia la copia automatica, e un file che non riesce mai farebbe un lavoro ogni due minuti invece che ogni ora. 51: un «Tolto» è una scelta di Alberto, che un file rimesso nella cartella non deve annullare |
| 2026-12-04 | Tappa E5: la copia automatica prende il cancello dei lavori lunghi (`LongWorkGate`) con un **permesso che cede** (`TryEnterYielding`): esclude gli altri come ogni permesso, e la conversione della libreria la aspetta come aspetta le copie. Importazione, ricostruzione, zip di fotogrammi (e, con la tappa, «Copia in…», «Riprendi», «Riconosci») lo prendono con `EnterAsync` **prima del proprio lucchetto e prima di registrare qualcosa**: chi entra diventa subito il titolare, la copia automatica riceve l'ordine di fermarsi e si aspetta che lasci, in tempo reale, al più `YieldWait` = 15 s; passato il limite il lavoro è rifiutato con il messaggio della copia e la copia resta titolare finché non lascia. «Cerca i video fermi», che non prende permessi, la ferma con `CancelYielding` e aspetta come per ogni lavoro lungo. `TryEnter` sincrono resta e rifiuta anche un titolare che cede; `BusyFirm` (il titolare se non cede) decide i rifiuti anticipati, `Busy` resta per chi aspetta. La sonda del controllo delle cartelle è riservata come i file temporanei della scrittura sicura | Risposta 49 di Alberto (la copia automatica cede sempre il passo). Un'attesa bloccante dentro `TryEnter` sotto i lucchetti di chi chiama avrebbe bloccato le richieste e rischiato lo stallo con chi pubblica l'avanzamento; installare subito il nuovo titolare chiude la finestra in cui il lavoro automatico potrebbe ripartire. Il tempo reale è un limite di consegna, non una misura del motore (come l'attesa del salvataggio della conversione e la risposta della radice delle copie); lasciare la copia titolare dopo il limite evita di partire sopra una copia che, ferma su una condivisione caduta, potrebbe ancora scrivere. La riserva della sonda impedisce che la pulizia dei resti di un altro lavoro nella stessa cartella la tolga mentre è in uso |
| 2026-12-04 | Tappa E5, il servizio delle copie (`ExportService`): le partenze automatiche (`TryStartAutomaticAsync`, `TryResumeAutomaticAsync`) **non lanciano mai eccezioni perché Febe è occupata**: rispondono «occupato» (un lavoro, una sessione del motore, un cambio di cartella, un altro lavoro lungo), «niente da fare» (senza prendere il cancello, così la conversione della libreria non si ferma per nulla) o «ferme»; registrano solo i file da scrivere (niente «già copiato», «Tolto», «Superato»), un lavoro per cartella, e riprendono solo lavori automatici di cartelle ancora automatiche e non in pausa. Le partenze di Alberto («Copia in…», «Riprendi», «Controlla le copie», «Riprova») prendono il cancello con `EnterAsync` e aspettano che il lavoro automatico spostato abbia salvato i suoi stati (al più `StopWait` = 10 s, tempo reale). **I cambi di cartella passano da `ChangeDestinationAsync`**: le partenze automatiche stanno lontane dal primo momento, il lavoro automatico di quella cartella si ferma, poi il cambio, poi i lavori automatici di cartelle non più automatiche o tolte diventano «annullato»; un lavoro automatico non finito non blocca più il cambio di cartella né «Togli la cartella» (uno di Alberto sì). La copia stessa annulla un lavoro automatico la cui cartella non è più automatica, all'inizio e a ogni gruppo. **«Interrompi»** di una copia automatica ferma le copie automatiche per un'ora (`AutomaticHoldTime`), in memoria nel servizio; «Riprendi ora» toglie la sosta. Una cartella in pausa con un lavoro in pausa torna disponibile solo se il disco ha posto per il prossimo file più il margine; senza misura dello spazio la pausa si toglie come prima. «Copia automatica in … finita» solo se il lavoro ha copiato, adottato o non è riuscito qualcosa. Il segnale della copia automatica parte dal nucleo quando una cartella si accende, prende tipi in più, si toglie una cartella propria o si riaccende «Esporta questo account» (`ExportEnvironment.AutoSignal`), non dall'API. Un percorso troppo lungo dà la nota `PathTooLong`. La fine di Febe aspetta il lavoro al più `StopWait` | Risposte 48, 49, 50, 52, 53 e 54 di Alberto. Un rifiuto con eccezione non serve a chi riprova da solo a ogni passata; una partenza che non trova nulla non deve fermare la conversione. Serializzare i cambi nel nucleo chiude la finestra in cui la copia automatica potrebbe ripartire fra l'arresto e il salvataggio. La sosta sta nel servizio, che le partenze consultano, perché il servizio è l'unico punto da cui partono; in memoria come chiede la risposta 53. Riprendere una pausa per spazio senza posto la rimetterebbe subito in pausa. Il segnale nel nucleo vale per ogni via di salvataggio, non solo per l'API, e le prove lo osservano con un'istanza loro. Un limite in tempo reale alla chiusura evita che una lettura bloccata su una condivisione caduta tenga aperta Febe; il lavoro rimasto «in corso» diventa «interrotto» all'avvio dopo, come dopo un arresto improvviso |
+| 2026-12-04 | Tappa E5, «Riconosci le copie già presenti» (`ExportService.RecognizeAsync`, partenza di Alberto da una cartella): un lavoro di tipo «Riconosci», riprendibile, su ogni file dovuto alla cartella che non è «Copiato» (senza «da quando»; «Una copia sola» vale) e sui fotogrammi che hanno già una riga lì. Per ogni file Febe guarda il percorso dello schema e «nome (2)» … «nome (50)», nella forma che la cartella chiede adesso e come originale, ciascuna con la sua identità (una copia byte per byte si registra Intera/Originale); prima i percorsi, poi la lunghezza, poi lo SHA-256 (con la conversione rifatta solo se un file c'è), mai per dimensione o nome soltanto. Un file uguale si registra «Adottato»: la riga «Non riuscito» della stessa identità diventa la copia, una riga orfana si ricollega, una «Superato» con gli stessi byte torna «Copiato». **Un «Tolto» resta «Tolto»** anche se il file è tornato identico (non si guarda nemmeno; un lavoro ripreso dopo un «Tolto» lo salta). Un fotogramma si confronta con i byte che la sua riga ha registrato, altrimenti si ricava di nuovo dal video; i fotogrammi mai registrati non si cercano. Non scrive, non rinomina e non toglie file (neppure i `.part` lasciati da altri), una cartella che non risponde mette in pausa senza segnare nulla, e scrive solo il suo evento (`esportazione-riconosci`: «Riconosciute N copie già presenti in …», informazione quando nessuna). Il resoconto conta «Non c'è nella cartella» e «Nel percorso c'è un altro file»; solo il secondo è fra i problemi. Lo spazio libero non si chiede per un «Riconosci» in pausa | Risposta 51 di Alberto (b: come proposto, ma un «Tolto» resta «Tolto»). Provare prima i percorsi evita letture e conversioni dove non c'è nulla; ogni forma con la sua identità rispetta il vincolo fra variante e SHA-256 della copia; riusare la riga «Non riuscito» evita una seconda riga corrente. Contare «Non c'è» fra i problemi riempirebbe il resoconto di una cartella che non ha mai avuto copie. Una conversione fatta da codificatori più vecchi esce «diversa»: la copia successiva scrive il file accanto, con un nome libero, e quello che c'era resta |
diff --git a/src/Febe.Core/Export/ExportCopier.Recognize.cs b/src/Febe.Core/Export/ExportCopier.Recognize.cs
new file mode 100644
index 0000000..5c3a6cc
--- /dev/null
+++ b/src/Febe.Core/Export/ExportCopier.Recognize.cs
@@ -0,0 +1,396 @@
+using System.Security.Cryptography;
+using Febe.Core.Codecs.Images;
+using Febe.Core.Domain;
+using Febe.Core.Library;
+using Febe.Core.Library.Conversion;
+
+namespace Febe.Core.Export;
+
+///
+/// «Riconosci le copie già presenti» (tappa E5, D13; answer 51 of 4 December 2026): each item of a Recognize run is a due
+/// file of the destination that is not «Copiato», or a frame of it already recorded there. Febe looks at the path its
+/// naming scheme gives and at «nome (2)» … «nome (50)», in the form the destination asks now and as the original; a file
+/// is recognised by its length, then its SHA-256 (never by size or name alone), and recorded «Adottato». It never writes,
+/// renames or deletes a file: it only reads the destination (plus the usual probe). A «Tolto» stays «Tolto» even when its
+/// file came back identical: only «Copia di nuovo» copies it again.
+///
+public sealed partial class ExportCopier
+{
+ /// The highest number of «nome (n)» looked at after the planned name.
+ private const int RecognizeSiblings = 50;
+
+ /// One item of a Recognize run: the file itself () or one of its frames.
+ private async Task RecognizeItemAsync(RunContext x, ExportItem item, CancellationToken ct)
+ {
+ var check = await SourceAsync(x, item, ct).ConfigureAwait(false);
+ if (check.File is not { } library)
+ {
+ return await FinishAsync(item with { State = check.State, Note = check.Note, LastError = null }, check.Bytes, null).ConfigureAwait(false);
+ }
+
+ if (item.Variant == ExportVariant.Frame)
+ {
+ if (!string.Equals(item.SourceSha256, library.Sha256, StringComparison.Ordinal))
+ {
+ // The row was of a file the library no longer has: a frame of the new file was never recorded.
+ return await FinishAsync(item with { State = ExportItemState.Skipped, Note = ExportText.Notes.SourceChanged, LastError = null }, 0, null).ConfigureAwait(false);
+ }
+
+ return await RecognizeFrameAsync(x, item, library, ct).ConfigureAwait(false);
+ }
+
+ if (!string.Equals(item.SourceSha256, library.Sha256, StringComparison.Ordinal))
+ {
+ item = item with { SourceSha256 = library.Sha256 };
+ }
+
+ return await RecognizeFileAsync(x, item, library, ct).ConfigureAwait(false);
+ }
+
+ ///
+ /// A file in the form the destination asks now, then as it is: the paths first (with no file at any of them nothing is
+ /// hashed or converted), then the bytes. The newest row decides as in the plan: a copy there ends the item, a «Tolto»
+ /// stays «Tolto» (answer 51), «Una copia sola» is respected.
+ ///
+ private async Task RecognizeFileAsync(RunContext x, ExportItem item, LibraryFile library, CancellationToken ct)
+ {
+ var exports = _env.Storage.Exports;
+ var none = CancellationToken.None;
+ var destination = x.Destination;
+ var root = destination.RootPath;
+ var account = library.Account.Id;
+ var sha = library.Sha256;
+ var media = library.Media;
+
+ // What the plan saw may have changed since (a run resumed later): a copy there now ends the item, and one whose
+ // file is gone is «Tolto» as in any job (only once the root answered).
+ var copied = (await exports.ListCurrentCopiesAnyFormAsync(destination.Id, account, sha, ct).ConfigureAwait(false))
+ .Where(c => c.State == ExportCopyState.Copied)
+ .ToList();
+ if (copied.Count > 0)
+ {
+ var (present, gone) = await PresentCopyAsync(x, copied, ct).ConfigureAwait(false);
+ if (gone is not null)
+ {
+ return ItemResult.Paused(gone);
+ }
+
+ if (present is not null)
+ {
+ return await FinishAsync(item with { State = ExportItemState.AlreadyCopied, CopyId = present.Id, RelativePath = present.RelativePath, Note = null, LastError = null }, library.Bytes, present.RelativePath).ConfigureAwait(false);
+ }
+
+ foreach (var copy in copied)
+ {
+ await exports.UpdateCopyAsync(copy with { State = ExportCopyState.Removed, StateChangedAt = _env.Clock.Now }, none).ConfigureAwait(false);
+ }
+
+ return await FinishAsync(item with { State = ExportItemState.Skipped, Note = ExportText.Notes.Removed, CopyId = copied[0].Id, LastError = null }, library.Bytes, copied[0].RelativePath).ConfigureAwait(false);
+ }
+
+ // Answer 51: a file whose newest copy here is «Tolto» is never recognised, even if its file came back identical.
+ if (await exports.FindLatestCopyAnyFormAsync(destination.Id, account, sha, ct).ConfigureAwait(false) is { State: ExportCopyState.Removed } removed)
+ {
+ return await FinishAsync(item with { State = ExportItemState.Skipped, Note = ExportText.Notes.Removed, CopyId = removed.Id, LastError = null }, library.Bytes, removed.RelativePath).ConfigureAwait(false);
+ }
+
+ if (x.OneOnly
+ && await exports.FindCopiedElsewhereAsync(sha, account, ct).ConfigureAwait(false) is { RelativePath: { } elsewherePath } elsewhere
+ && await x.DestinationAsync(_env.Storage, elsewhere.DestinationId, ct).ConfigureAwait(false) is { IsRetired: false } where
+ && Exists(where.RootPath, elsewherePath))
+ {
+ return await FinishAsync(
+ item with { State = ExportItemState.AlreadyCopied, Note = ExportText.Notes.CopiedForAnotherAccount, CopyId = elsewhere.Id, LastError = null },
+ library.Bytes,
+ null).ConfigureAwait(false);
+ }
+
+ // The forms looked for, each with the files at its paths: the one asked now, then the original (copied by an older
+ // setting, or by hand). A form predicted as it is (same format, HEIC, raw…) is the original's.
+ var target = item.Variant == ExportVariant.Whole ? ExportFormat.Original : item.Format;
+ var forms = new List<(ExportFormat Format, IReadOnlyList Paths)>();
+ foreach (var asked in target == ExportFormat.Original ? new[] { ExportFormat.Original } : new[] { target, ExportFormat.Original })
+ {
+ var form = asked != ExportFormat.Original && ExportConversions.Predict(media.RelativePath!, media.Kind, asked) == ExportPrediction.Converted
+ ? asked
+ : ExportFormat.Original;
+ if (forms.Any(f => f.Format == form))
+ {
+ continue;
+ }
+
+ string planned;
+ try
+ {
+ planned = PlannedPath(x, library, form == ExportFormat.Original ? null : MediaConverter.ExtensionOf(form), null);
+ }
+ catch (PathTooLongException)
+ {
+ continue; // nothing of ours can be there
+ }
+
+ if (PresentNames(root, planned, null) is { Count: > 0 } paths)
+ {
+ forms.Add((form, paths));
+ }
+ }
+
+ if (forms.Count == 0)
+ {
+ return await NotFoundAsync(x, item, library.Bytes, ct).ConfigureAwait(false);
+ }
+
+ foreach (var (format, paths) in forms)
+ {
+ MediaConversionResult? conversion = null;
+ Output output;
+ if (format == ExportFormat.Original)
+ {
+ output = Output.Whole(library, []);
+ }
+ else
+ {
+ try
+ {
+ conversion = await ExportConversion.PrepareAsync(_env, library.Source, media, format, sha, ct).ConfigureAwait(false);
+ }
+ catch (ContentChangedException ex)
+ {
+ return await FinishAsync(item with { State = ExportItemState.Failed, Note = ExportText.Notes.SourceChanged, LastError = ex.Message }, library.Bytes, null).ConfigureAwait(false);
+ }
+ catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
+ {
+ return await FinishAsync(item with { State = ExportItemState.Failed, Note = null, LastError = ExportText.ErrorText(ex) }, library.Bytes, null).ConfigureAwait(false);
+ }
+
+ if (conversion.Variant == ExportVariant.Whole)
+ {
+ conversion.Dispose(); // kept as it is after all: the original's form looks for it
+ continue;
+ }
+
+ output = new Output(conversion.Variant, conversion.Format, null, conversion.Extension, null, conversion.Length, conversion.Sha256, conversion.Produce, conversion.Notes);
+ }
+
+ using (conversion)
+ {
+ // Each form has its own identity (engineering B7a): an original's bytes are recorded Whole/Original.
+ var identity = new ExportCopyIdentity(destination.Id, account, sha, output.Variant, output.Format, null);
+ var current = await exports.FindCurrentCopyAsync(identity, ct).ConfigureAwait(false);
+ var failed = current is { State: ExportCopyState.Failed } ? current : null;
+ var result = await TryAdoptAsync(x, item, new FileContext(library, identity), output, failed, paths, ExportItemState.Adopted, ct).ConfigureAwait(false);
+ if (result is not null)
+ {
+ if (result.State is ExportItemState.Adopted or ExportItemState.AlreadyCopied)
+ {
+ // A copy of the file is there now: the «Non riuscito» rows of its other forms have no use.
+ await exports.ClearFailedAsync(destination.Id, account, sha, identity, none).ConfigureAwait(false);
+ }
+
+ return result;
+ }
+ }
+ }
+
+ // The report shows the path where another file is (the first one looked at).
+ var different = forms[0].Paths[0];
+ return await FinishAsync(item with { State = ExportItemState.Skipped, Note = ExportText.Notes.Different, RelativePath = different, LastError = null }, library.Bytes, different).ConfigureAwait(false);
+ }
+
+ ///
+ /// A frame already recorded in the destination (its instant is known): at the path of its row, or the one «Questo
+ /// istante» or «Salva il fotogramma» gives. Its bytes are those its row recorded (an orphan, a «Superato»), or the
+ /// frame taken again from the video (a «Non riuscito» row has none).
+ ///
+ private async Task RecognizeFrameAsync(RunContext x, ExportItem item, LibraryFile library, CancellationToken ct)
+ {
+ var exports = _env.Storage.Exports;
+ var destination = x.Destination;
+ var root = destination.RootPath;
+ var at = item.FrameAt ?? TimeSpan.Zero;
+ var format = item.Format;
+ var identity = new ExportCopyIdentity(destination.Id, library.Account.Id, library.Sha256, ExportVariant.Frame, format, at);
+ var file = new FileContext(library with { Bytes = 0 }, identity);
+ var current = await exports.FindCurrentCopyAsync(identity, ct).ConfigureAwait(false);
+ if (current is { State: ExportCopyState.Copied })
+ {
+ var (present, gone) = await PresentCopyAsync(x, [current], ct).ConfigureAwait(false);
+ if (gone is not null)
+ {
+ return ItemResult.Paused(gone);
+ }
+
+ if (present is not null)
+ {
+ return await FinishAsync(item with { State = ExportItemState.AlreadyCopied, CopyId = present.Id, RelativePath = present.RelativePath, Note = null, LastError = null }, 0, present.RelativePath).ConfigureAwait(false);
+ }
+
+ await exports.UpdateCopyAsync(current with { State = ExportCopyState.Removed, StateChangedAt = _env.Clock.Now }, CancellationToken.None).ConfigureAwait(false);
+ return await FinishAsync(item with { State = ExportItemState.Skipped, Note = ExportText.Notes.Removed, CopyId = current.Id, LastError = null }, 0, current.RelativePath).ConfigureAwait(false);
+ }
+
+ if (current is null && await exports.FindLatestCopyAsync(identity, ct).ConfigureAwait(false) is { State: ExportCopyState.Removed } removed)
+ {
+ return await FinishAsync(item with { State = ExportItemState.Skipped, Note = ExportText.Notes.Removed, CopyId = removed.Id, LastError = null }, 0, removed.RelativePath).ConfigureAwait(false);
+ }
+
+ var failed = current is { State: ExportCopyState.Failed } ? current : null;
+ var extension = MediaConverter.ExtensionOf(format);
+ var paths = new List();
+ var seen = new HashSet(StringComparer.OrdinalIgnoreCase);
+ if (item.RelativePath is { } recorded && Exists(root, recorded) && seen.Add(recorded))
+ {
+ paths.Add(recorded);
+ }
+
+ foreach (var suffix in new[] { ExportFrames.Suffix(FrameMode.At, at, 0, 1), ExportFrames.SingleSuffix })
+ {
+ try
+ {
+ paths.AddRange(PresentNames(root, PlannedPath(x, library, extension, suffix), suffix).Where(seen.Add));
+ }
+ catch (PathTooLongException)
+ {
+ // That name does not fit: nothing of ours can be there.
+ }
+ }
+
+ if (paths.Count == 0)
+ {
+ return await NotFoundAsync(x, item, 0, ct).ConfigureAwait(false);
+ }
+
+ // The bytes a row of this very frame recorded at the path: compared without taking the frame again.
+ var others = new List();
+ foreach (var path in paths)
+ {
+ if (await exports.FindCopyByPathAsync(destination.Id, path, ct).ConfigureAwait(false) is { Variant: ExportVariant.Frame, CopySha256: { } copySha, Bytes: { } bytes } holder
+ && string.Equals(holder.SourceSha256, library.Sha256, StringComparison.Ordinal) && holder.Format == format && holder.FrameAt == at)
+ {
+ var known = new Output(ExportVariant.Frame, format, at, extension, null, bytes, copySha, null, []);
+ if (await TryAdoptAsync(x, item, file, known, failed, [path], ExportItemState.Adopted, ct).ConfigureAwait(false) is { } adopted)
+ {
+ return adopted;
+ }
+
+ continue; // another file at the row's path: the frame taken again could not be adopted there either
+ }
+
+ others.Add(path);
+ }
+
+ if (others.Count > 0)
+ {
+ if (await FrameOutputAsync(library, format, at, ct).ConfigureAwait(false) is not { } taken)
+ {
+ return await FinishAsync(item with { State = ExportItemState.Skipped, Note = ExportText.Notes.FrameNotAvailable, LastError = null }, 0, null).ConfigureAwait(false);
+ }
+
+ if (await TryAdoptAsync(x, item, file, taken, failed, others, ExportItemState.Adopted, ct).ConfigureAwait(false) is { } adopted)
+ {
+ return adopted;
+ }
+ }
+
+ return await FinishAsync(item with { State = ExportItemState.Skipped, Note = ExportText.Notes.Different, RelativePath = paths[0], LastError = null }, 0, paths[0]).ConfigureAwait(false);
+ }
+
+ ///
+ /// Nothing at the paths looked at: «Non c'è nella cartella», unless the root itself went away meanwhile (the run then
+ /// pauses and marks nothing).
+ ///
+ private async Task NotFoundAsync(RunContext x, ExportItem item, long bytes, CancellationToken ct)
+ {
+ if (!Directory.Exists(x.Destination.RootPath) && await ProbeAsync(x, ct).ConfigureAwait(false) is { } away)
+ {
+ return ItemResult.Paused(away);
+ }
+
+ return await FinishAsync(item with { State = ExportItemState.Skipped, Note = ExportText.Notes.NotFound, LastError = null }, bytes, null).ConfigureAwait(false);
+ }
+
+ ///
+ /// The files of the destination at and at its numbered names («nome (2)» … «nome (50)»,
+ /// numbered as the writer numbers them), these until the first one that is not there.
+ ///
+ private List PresentNames(string root, string planned, string? keepSuffix)
+ {
+ var found = new List();
+ for (var attempt = 1; attempt <= RecognizeSiblings; attempt++)
+ {
+ string name;
+ try
+ {
+ name = ExportPaths.NumberedName(root, planned, attempt, MaxPath, keepSuffix);
+ }
+ catch (PathTooLongException)
+ {
+ break;
+ }
+
+ if (Exists(root, name))
+ {
+ found.Add(name);
+ }
+ else if (attempt > 1)
+ {
+ break; // the writer takes the first free name: nothing of ours after it
+ }
+ }
+
+ return found;
+ }
+
+ ///
+ /// The frame of the library video at in , encoded as a copy encodes it
+ /// (no metadata); null when the video is not the one recorded, cannot be read, or shows no frame at that instant.
+ ///
+ private async Task