feat: Add Face Matcher functionality and related settings
- Implemented FilePathToBitmapConverter for image loading. - Enhanced DataModel with commands and properties for Face Matcher. - Created FaceMatcherResultItem model to store results. - Updated SettingsDto to include Face Matcher paths and tolerance. - Introduced PickerPreferenceService for managing folder paths. - Expanded AiSettingsViewModel to manage Face Matcher settings and results.
This commit is contained in:
parent
f57dc1edba
commit
c261557a29
10 changed files with 2041 additions and 192 deletions
93
imagecatalog/Services/PickerPreferenceService.cs
Normal file
93
imagecatalog/Services/PickerPreferenceService.cs
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
using Avalonia.Platform.Storage;
|
||||
using ImageCatalog;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ImageCatalog_2.Services;
|
||||
|
||||
public static class PickerPreferenceKeys
|
||||
{
|
||||
public const string SourceFolder = "Picker.SourceFolder.LastPath";
|
||||
public const string DestinationFolder = "Picker.DestinationFolder.LastPath";
|
||||
public const string LogoFile = "Picker.LogoFile.LastPath";
|
||||
public const string ModelsFolder = "Picker.ModelsFolder.LastPath";
|
||||
public const string CsvOutput = "Picker.CsvOutput.LastPath";
|
||||
public const string FaceExecutableFolder = "Picker.FaceExecutableFolder.LastPath";
|
||||
public const string FaceOutputFolder = "Picker.FaceOutputFolder.LastPath";
|
||||
public const string FaceMatcherExecutable = "Picker.FaceMatcherExecutable.LastPath";
|
||||
public const string FaceMatcherImage = "Picker.FaceMatcherImage.LastPath";
|
||||
public const string FaceMatcherEncodings = "Picker.FaceMatcherEncodings.LastPath";
|
||||
public const string FaceMatcherOutput = "Picker.FaceMatcherOutput.LastPath";
|
||||
public const string FaceMatcherLog = "Picker.FaceMatcherLog.LastPath";
|
||||
}
|
||||
|
||||
public sealed class PickerPreferenceService
|
||||
{
|
||||
private readonly ParametriSetup _userPreferences;
|
||||
|
||||
public PickerPreferenceService(ParametriSetup userPreferences)
|
||||
{
|
||||
_userPreferences = userPreferences;
|
||||
}
|
||||
|
||||
public async Task<IStorageFolder?> TryGetStartFolderAsync(IStorageProvider storageProvider, string preferenceKey, string? currentPath = null)
|
||||
{
|
||||
var startPath = GetPreferredStartDirectory(preferenceKey, currentPath);
|
||||
if (string.IsNullOrWhiteSpace(startPath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return await storageProvider.TryGetFolderFromPathAsync(new Uri(startPath)).ConfigureAwait(true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void RememberPath(string preferenceKey, string? selectedPath)
|
||||
{
|
||||
var directory = TryGetExistingDirectory(selectedPath);
|
||||
if (string.IsNullOrWhiteSpace(directory))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_userPreferences.AggiornaParametro(preferenceKey, directory);
|
||||
_userPreferences.SalvaParametriSetup();
|
||||
}
|
||||
|
||||
private string? GetPreferredStartDirectory(string preferenceKey, string? currentPath)
|
||||
{
|
||||
var storedPath = _userPreferences.LeggiParametroString(preferenceKey);
|
||||
return TryGetExistingDirectory(storedPath) ?? TryGetExistingDirectory(currentPath);
|
||||
}
|
||||
|
||||
private static string? TryGetExistingDirectory(string? path)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(path))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var normalizedPath = path.Trim().Trim('"');
|
||||
if (Directory.Exists(normalizedPath))
|
||||
{
|
||||
return normalizedPath;
|
||||
}
|
||||
|
||||
if (File.Exists(normalizedPath))
|
||||
{
|
||||
return Path.GetDirectoryName(normalizedPath);
|
||||
}
|
||||
|
||||
var containingDirectory = Path.GetDirectoryName(normalizedPath);
|
||||
return !string.IsNullOrWhiteSpace(containingDirectory) && Directory.Exists(containingDirectory)
|
||||
? containingDirectory
|
||||
: null;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue