99 lines
3.6 KiB
C#
99 lines
3.6 KiB
C#
namespace Explorer.Domain;
|
|
|
|
public sealed record FileClassification(FileCategory Category, string Reason);
|
|
|
|
public sealed record OrganizePreviewRow(
|
|
string Name,
|
|
string Category,
|
|
string Action,
|
|
string? Destination,
|
|
string? Detail);
|
|
|
|
public sealed class OrganizeDestinations
|
|
{
|
|
public string Pictures { get; set; } = "";
|
|
public string Videos { get; set; } = "";
|
|
public string Audio { get; set; } = "";
|
|
public string Documents { get; set; } = "";
|
|
public string Installers { get; set; } = "";
|
|
public string Archives { get; set; } = "";
|
|
public string Development { get; set; } = "";
|
|
|
|
public string? For(FileCategory category)
|
|
=> category switch
|
|
{
|
|
FileCategory.Photos => EmptyToNull(Pictures),
|
|
FileCategory.Video => EmptyToNull(Videos),
|
|
FileCategory.Audio => EmptyToNull(Audio),
|
|
FileCategory.Documents => EmptyToNull(Documents),
|
|
FileCategory.Installer => EmptyToNull(Installers),
|
|
FileCategory.Archive => EmptyToNull(Archives),
|
|
FileCategory.CodeRepository => EmptyToNull(Development),
|
|
_ => null
|
|
};
|
|
|
|
public static string Label(FileCategory category)
|
|
=> category switch
|
|
{
|
|
FileCategory.Photos => "Photos",
|
|
FileCategory.Video => "Video",
|
|
FileCategory.Audio => "Audio",
|
|
FileCategory.Documents => "Documents",
|
|
FileCategory.CodeRepository => "Code repository",
|
|
FileCategory.Installer => "Installer",
|
|
FileCategory.Backup => "Backup",
|
|
FileCategory.Archive => "Archive",
|
|
FileCategory.SystemData => "System data",
|
|
FileCategory.BuildOutput => "Build output",
|
|
_ => "Unknown"
|
|
};
|
|
|
|
public static bool TryParse(string? value, out FileCategory category)
|
|
{
|
|
category = FileCategory.Unknown;
|
|
if (string.IsNullOrWhiteSpace(value))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var key = value.Trim().Replace(" ", "", StringComparison.Ordinal).Replace("_", "", StringComparison.Ordinal);
|
|
if (Enum.TryParse(key, ignoreCase: true, out category) && category != FileCategory.Unknown)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
category = key.ToLowerInvariant() switch
|
|
{
|
|
"photo" or "photos" or "image" or "images" or "picture" or "pictures" => FileCategory.Photos,
|
|
"video" or "videos" or "movie" or "movies" => FileCategory.Video,
|
|
"audio" or "music" or "sound" => FileCategory.Audio,
|
|
"doc" or "docs" or "document" or "documents" => FileCategory.Documents,
|
|
"code" or "repo" or "repository" or "git" or "development" => FileCategory.CodeRepository,
|
|
"installer" or "installers" or "setup" => FileCategory.Installer,
|
|
"backup" or "backups" => FileCategory.Backup,
|
|
"archive" or "archives" or "zip" => FileCategory.Archive,
|
|
"system" or "systemdata" => FileCategory.SystemData,
|
|
"build" or "buildoutput" => FileCategory.BuildOutput,
|
|
"unknown" => FileCategory.Unknown,
|
|
_ => (FileCategory)(-1)
|
|
};
|
|
return (int)category >= 0;
|
|
}
|
|
|
|
public static readonly FileCategory[] UserChoices =
|
|
[
|
|
FileCategory.Photos,
|
|
FileCategory.Video,
|
|
FileCategory.Audio,
|
|
FileCategory.Documents,
|
|
FileCategory.Installer,
|
|
FileCategory.Archive,
|
|
FileCategory.Backup,
|
|
FileCategory.CodeRepository,
|
|
FileCategory.Unknown
|
|
];
|
|
|
|
private static string? EmptyToNull(string value)
|
|
=> string.IsNullOrWhiteSpace(value) ? null : value.Trim();
|
|
}
|