namespace AIStudio.Tools; /// /// Picks the folder which a picker for exactly one folder takes from the paths dropped onto it. /// public static class DroppedFolder { private static string TB(string fallbackEN) => PluginSystem.I18N.I.T(fallbackEN, typeof(DroppedFolder).Namespace, nameof(DroppedFolder)); /// /// Finds the first dropped path which leads to a folder. /// /// /// A picker carries exactly one folder, so a multi-selection cannot be honored as a whole. A /// dropped file is rejected instead of being taken as its parent folder. Everything a folder /// contains is processed, so guessing the parent of a mistakenly dropped file could pull in far /// more data than the user meant to hand over. /// /// The dropped paths, in the order the runtime delivered them. /// The path of the folder to take, or null when no dropped path leads to a folder. public static string? FirstUsable(IReadOnlyList paths) => paths.FirstOrDefault(Directory.Exists); /// /// Explains why none of the dropped paths could be used. /// /// The dropped paths. public static string WarningFor(IReadOnlyList paths) { // Naming the actual mistake beats a generic "that did not work". Dropping a file onto a // folder picker is the likeliest of them: if (paths.Any(File.Exists)) return TB("Please drop a folder, not a file."); return TB("The dropped folder could not be accessed. Please choose it with the folder chooser instead."); } }