Error toasts showed the exception's own message, often technical English from .NET or the OS, under a translated title. The editor's failed save, a job posted to the server from the Library, and the card check or delete after an import now say why in one catalog sentence: what the server answered or that it does not answer, that the card left, is locked or a file could not be read, and the archive causes of ArchiveFailures for a local save. The details stay in the log. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
64 lines
3.2 KiB
C#
64 lines
3.2 KiB
C#
using System.IO;
|
|
using System.Net.Http;
|
|
using Titano.Core.Archiving;
|
|
using Titano.Core.Import;
|
|
using Titano.Core.Localization;
|
|
using Titano.Data;
|
|
using Titano.Protocol.Client;
|
|
|
|
namespace Titano.App.Import;
|
|
|
|
/// <summary>
|
|
/// What the Import screen says when an import or its plan stops (BRIEF §0.2 rule 6: one sentence saying what
|
|
/// happened): a localized sentence chosen by cause. The exception's own text, which may hold full paths or several
|
|
/// sentences, goes to the tooltip and the log only.
|
|
/// </summary>
|
|
public static class ImportFailures
|
|
{
|
|
private const int DiskFull = unchecked((int)0x80070070);
|
|
private const int HandleDiskFull = unchecked((int)0x80070027);
|
|
private const int WriteProtect = unchecked((int)0x80070013);
|
|
|
|
/// <param name="source">The card or folder as the Devices list names it.</param>
|
|
public static string Import(Exception ex, string source) => ex switch
|
|
{
|
|
ImportSourceUnavailableException => Loc.L("Import.Failed.SourceGone", source),
|
|
IOException { HResult: DiskFull or HandleDiskFull } => Loc.L("Import.Failed.Full"),
|
|
UnauthorizedAccessException => Loc.L("Import.Failed.Access"),
|
|
TitanoApiException or HttpRequestException or UntrustedCertificateException => Loc.L("Import.Failed.Server"),
|
|
_ => Loc.L("Import.Failed.Other"),
|
|
};
|
|
|
|
/// <summary>Why the card or folder could not be planned.</summary>
|
|
public static string Plan(Exception ex, string source) => ex switch
|
|
{
|
|
DirectoryNotFoundException or DriveNotFoundException or ImportSourceUnavailableException => Loc.L("Import.Failed.SourceGone", source),
|
|
IOException or UnauthorizedAccessException => Loc.L("Import.Status.Unreadable", source),
|
|
_ => Loc.L("Import.Status.PlanError"),
|
|
};
|
|
|
|
/// <summary>Why the check of a card (every card file and its archive copy hashed again) stopped.</summary>
|
|
/// <param name="root">Where the card is mounted: a card that left explains any read failure.</param>
|
|
public static string Check(Exception ex, string source, string root) => ex switch
|
|
{
|
|
_ when CardGone(ex, root) => Loc.L("Import.Failed.SourceGone", source),
|
|
ArchiveOfflineException => ex.Message,
|
|
DatabaseException => Loc.L("Archive.Failed.Index"),
|
|
IOException or UnauthorizedAccessException => Loc.L("Import.Failed.CheckRead"),
|
|
_ => Loc.L("Errors.Unexpected"),
|
|
};
|
|
|
|
/// <summary>Why deleting verified photos from a card stopped.</summary>
|
|
/// <param name="root">Where the card is mounted: a card that left explains any write failure.</param>
|
|
public static string Erase(Exception ex, string source, string root) => ex switch
|
|
{
|
|
_ when CardGone(ex, root) => Loc.L("Import.Failed.SourceGone", source),
|
|
// A locked card (write-protect switch) or photos the camera marked protected (read-only).
|
|
IOException { HResult: WriteProtect } or UnauthorizedAccessException => Loc.L("Import.Failed.CardLocked", source),
|
|
_ => Loc.L("Errors.Unexpected"),
|
|
};
|
|
|
|
private static bool CardGone(Exception ex, string root) =>
|
|
ex is DirectoryNotFoundException or DriveNotFoundException or ImportSourceUnavailableException || !Directory.Exists(root);
|
|
}
|