develop #1
10 changed files with 104 additions and 72 deletions
commit
fc0598e2fb
|
|
@ -12,6 +12,7 @@ public sealed class LiteCatalogViewModel : ViewModelBase
|
|||
private readonly ILogger<LiteCatalogViewModel> _logger;
|
||||
private CatalogLiteConfiguration? _configuration;
|
||||
private CancellationTokenSource? _processingTokenSource;
|
||||
private string _configurationPath = string.Empty;
|
||||
private string _sourcePath = string.Empty;
|
||||
private string _destinationPath = string.Empty;
|
||||
private string _processingStatus = "Caricamento configurazione incorporata...";
|
||||
|
|
@ -52,6 +53,16 @@ public sealed class LiteCatalogViewModel : ViewModelBase
|
|||
public AsyncCommand StartProcessingCommand { get; }
|
||||
public AsyncCommand StopProcessingCommand { get; }
|
||||
|
||||
public string ConfigurationPath
|
||||
{
|
||||
get => _configurationPath;
|
||||
private set
|
||||
{
|
||||
_configurationPath = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public string SourcePath
|
||||
{
|
||||
get => _sourcePath;
|
||||
|
|
@ -172,6 +183,7 @@ public sealed class LiteCatalogViewModel : ViewModelBase
|
|||
var configuration = _configurationLoader.LoadEmbedded(_picSettings);
|
||||
|
||||
_configuration = configuration;
|
||||
ConfigurationPath = configuration.FilePath;
|
||||
SourcePath = configuration.SourcePath;
|
||||
DestinationPath = configuration.DestinationPath;
|
||||
NotifyPropertyChanged(nameof(HorizontalText));
|
||||
|
|
|
|||
|
|
@ -8,8 +8,16 @@
|
|||
Height="560"
|
||||
MinWidth="640"
|
||||
MinHeight="500">
|
||||
<Grid Margin="16" RowDefinitions="Auto,Auto,*,Auto" RowSpacing="12">
|
||||
<Grid ColumnDefinitions="150,*,104,72" ColumnSpacing="10">
|
||||
<Grid Margin="16" RowDefinitions="Auto,Auto,Auto,Auto,*,Auto" RowSpacing="12">
|
||||
<Grid ColumnDefinitions="150,*" ColumnSpacing="10">
|
||||
<TextBlock Text="Configurazione" VerticalAlignment="Center" FontWeight="SemiBold" />
|
||||
<TextBox Grid.Column="1"
|
||||
Text="{Binding ConfigurationPath}"
|
||||
IsReadOnly="True"
|
||||
Watermark="Configurazione incorporata" />
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Row="1" ColumnDefinitions="150,*,116" ColumnSpacing="10">
|
||||
<TextBlock Text="Sorgente" VerticalAlignment="Center" FontWeight="SemiBold" />
|
||||
<TextBox Grid.Column="1" Text="{Binding SourcePath, Mode=TwoWay}" Watermark="Cartella sorgente" />
|
||||
<Button Grid.Column="2" Command="{Binding SelectSourceFolderCommand}" ToolTip.Tip="Seleziona cartella sorgente">
|
||||
|
|
@ -18,15 +26,9 @@
|
|||
<TextBlock Text="Scegli" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Grid.Column="3" Click="OpenSourcePath_Click" ToolTip.Tip="Apri cartella sorgente in Esplora file">
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Spacing="6">
|
||||
<iconPacks:PackIconMaterial Kind="Folder" Width="16" Height="16" />
|
||||
<TextBlock Text="Apri" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Row="1" ColumnDefinitions="150,*,104,72" ColumnSpacing="10">
|
||||
<Grid Grid.Row="2" ColumnDefinitions="150,*,116" ColumnSpacing="10">
|
||||
<TextBlock Text="Destinazione" VerticalAlignment="Center" FontWeight="SemiBold" />
|
||||
<TextBox Grid.Column="1" Text="{Binding DestinationPath, Mode=TwoWay}" Watermark="Cartella destinazione" />
|
||||
<Button Grid.Column="2" Command="{Binding SelectDestinationFolderCommand}" ToolTip.Tip="Seleziona cartella destinazione">
|
||||
|
|
@ -35,15 +37,9 @@
|
|||
<TextBlock Text="Scegli" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Grid.Column="3" Click="OpenDestinationPath_Click" ToolTip.Tip="Apri cartella destinazione in Esplora file">
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Spacing="6">
|
||||
<iconPacks:PackIconMaterial Kind="Folder" Width="16" Height="16" />
|
||||
<TextBlock Text="Apri" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
</Grid>
|
||||
|
||||
<Border Grid.Row="2"
|
||||
<Border Grid.Row="3"
|
||||
Background="{DynamicResource PanelBackgroundBrush}"
|
||||
BorderBrush="{DynamicResource BorderMutedBrush}"
|
||||
BorderThickness="1"
|
||||
|
|
@ -68,7 +64,7 @@
|
|||
</Grid>
|
||||
</Border>
|
||||
|
||||
<Border Grid.Row="3"
|
||||
<Border Grid.Row="4"
|
||||
Background="{DynamicResource PanelBackgroundBrush}"
|
||||
BorderBrush="{DynamicResource BorderMutedBrush}"
|
||||
BorderThickness="1"
|
||||
|
|
@ -89,7 +85,7 @@
|
|||
</Grid>
|
||||
</Border>
|
||||
|
||||
<StackPanel Grid.Row="4" Orientation="Horizontal" HorizontalAlignment="Right" Spacing="10">
|
||||
<StackPanel Grid.Row="5" Orientation="Horizontal" HorizontalAlignment="Right" Spacing="10">
|
||||
<Button Command="{Binding StartProcessingCommand}" MinWidth="112" ToolTip.Tip="Avvia elaborazione">
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Spacing="7">
|
||||
<iconPacks:PackIconMaterial Kind="PlayCircleOutline" Width="16" Height="16" Foreground="{DynamicResource AccentBrush}" />
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@ using Avalonia.Controls;
|
|||
using Avalonia.Platform.Storage;
|
||||
using Avalonia.Threading;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace CatalogLite;
|
||||
|
||||
|
|
@ -55,16 +53,6 @@ public partial class MainWindow : Window
|
|||
}
|
||||
}
|
||||
|
||||
private void OpenSourcePath_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||
{
|
||||
OpenInExplorer(_viewModel.SourcePath);
|
||||
}
|
||||
|
||||
private void OpenDestinationPath_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||
{
|
||||
OpenInExplorer(_viewModel.DestinationPath);
|
||||
}
|
||||
|
||||
private async void OnShowMessageRequested(object? sender, LiteMessageEventArgs e)
|
||||
{
|
||||
await ShowMessageDialogAsync(e.Title, e.Message);
|
||||
|
|
@ -108,46 +96,4 @@ public partial class MainWindow : Window
|
|||
closeButton.Click += (_, _) => dialog.Close();
|
||||
await dialog.ShowDialog(this);
|
||||
}
|
||||
|
||||
private static void OpenInExplorer(string? path)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(path))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var normalizedPath = path.Trim().Trim('"');
|
||||
|
||||
try
|
||||
{
|
||||
if (File.Exists(normalizedPath))
|
||||
{
|
||||
Process.Start("explorer.exe", $"/select,\"{normalizedPath}\"");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Directory.Exists(normalizedPath))
|
||||
{
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = normalizedPath,
|
||||
UseShellExecute = true
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
var containingDirectory = Path.GetDirectoryName(normalizedPath);
|
||||
if (!string.IsNullOrWhiteSpace(containingDirectory) && Directory.Exists(containingDirectory))
|
||||
{
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = containingDirectory,
|
||||
UseShellExecute = true
|
||||
});
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Formats.Jpeg;
|
||||
using SixLabors.ImageSharp.Metadata.Profiles.Exif;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using MaddoShared.ImageSharpTests.Helpers;
|
||||
using Shouldly;
|
||||
|
|
@ -40,5 +43,57 @@ namespace MaddoShared.ImageSharpTests.Tests
|
|||
outImg.Width.ShouldBe(800);
|
||||
outImg.Height.ShouldBe(600);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task RemoveExifData_StripsExifProfileWhenEnabledAndPreservesItWhenDisabled()
|
||||
{
|
||||
using var ws = new TempWorkspace();
|
||||
var preserveInputPath = CreateJpegWithExifMake(ws.SourceDir.FullName, "preserve.jpg");
|
||||
var stripInputPath = CreateJpegWithExifMake(ws.SourceDir.FullName, "strip.jpg");
|
||||
|
||||
var preserveSettings = CreatorFactory.CreateDefaultPicSettings();
|
||||
preserveSettings.RemoveExifData = false;
|
||||
var preserveCreator = CreatorFactory.CreateImageCreator(preserveSettings);
|
||||
var preserveState = new MaddoShared.ImageState
|
||||
{
|
||||
WorkFile = new FileInfo(preserveInputPath),
|
||||
DestDir = ws.DestDir
|
||||
};
|
||||
await preserveCreator.CreateImageAsync(preserveState, null);
|
||||
|
||||
var stripSettings = CreatorFactory.CreateDefaultPicSettings();
|
||||
stripSettings.RemoveExifData = true;
|
||||
stripSettings.CreaMiniature = true;
|
||||
var stripCreator = CreatorFactory.CreateImageCreator(stripSettings);
|
||||
var stripState = new MaddoShared.ImageState
|
||||
{
|
||||
WorkFile = new FileInfo(stripInputPath),
|
||||
DestDir = ws.DestDir
|
||||
};
|
||||
await stripCreator.CreateImageAsync(stripState, null);
|
||||
|
||||
using var preservedOutput = Image.Load<Rgba32>(Path.Combine(ws.DestDir.FullName, preserveState.NomeFileBig));
|
||||
var preservedExif = preservedOutput.Metadata.ExifProfile;
|
||||
preservedExif.ShouldNotBeNull();
|
||||
preservedExif.TryGetValue(ExifTag.Make, out var make).ShouldBeTrue();
|
||||
make!.Value.ShouldBe("Test camera");
|
||||
|
||||
using var strippedOutput = Image.Load<Rgba32>(Path.Combine(ws.DestDir.FullName, stripState.NomeFileBig));
|
||||
strippedOutput.Metadata.ExifProfile.ShouldBeNull();
|
||||
|
||||
using var strippedThumbnail = Image.Load<Rgba32>(Path.Combine(ws.DestDir.FullName, stripState.NomeFileSmall));
|
||||
strippedThumbnail.Metadata.ExifProfile.ShouldBeNull();
|
||||
}
|
||||
|
||||
private static string CreateJpegWithExifMake(string directory, string fileName)
|
||||
{
|
||||
var path = TestImageFactory.CreateSolidJpeg(directory, fileName, 160, 120, new Rgba32(200, 200, 200, 255));
|
||||
using var image = Image.Load<Rgba32>(path);
|
||||
var exifProfile = new ExifProfile();
|
||||
exifProfile.SetValue(ExifTag.Make, "Test camera");
|
||||
image.Metadata.ExifProfile = exifProfile;
|
||||
image.Save(path, new JpegEncoder { Quality = 90 });
|
||||
return path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,6 +116,11 @@ public class ImageCreatorImageSharp : IImageCreator
|
|||
_logger?.LogDebug(ex, "[ImageSharp] Failed to clear EXIF orientation on working image");
|
||||
}
|
||||
|
||||
if (_picSettings.RemoveExifData)
|
||||
{
|
||||
working.Metadata.ExifProfile = null;
|
||||
}
|
||||
|
||||
// Ensure DataFoto is set (extracted earlier) so time-based text is available
|
||||
imgState.DataFoto = imgState.CreationDate ?? DateTime.Now;
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ public class PicSettings
|
|||
public bool UsaTempoGaraTestoApplicare { get; set; }
|
||||
public bool UsaRotazioneAutomatica { get; set; }
|
||||
public bool UsaForzaJpg { get; set; }
|
||||
public bool RemoveExifData { get; set; }
|
||||
public int LarghezzaSmall { get; set; }
|
||||
public int AltezzaSmall { get; set; }
|
||||
public bool CreaMiniature { get; set; }
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
<CheckBox Content="Aggiorna sottodirectory" IsChecked="{Binding UpdateSubdirectories}" />
|
||||
<CheckBox Content="Crea sottocartelle" IsChecked="{Binding CreateSubfolders}" />
|
||||
<CheckBox Content="Sovrascrivi immagini" IsChecked="{Binding OverwriteImages}" />
|
||||
<CheckBox Content="Rimuovi dati EXIF" IsChecked="{Binding RemoveExifData}" />
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock Text="Elaborazione" FontWeight="Bold" />
|
||||
|
|
|
|||
|
|
@ -1012,6 +1012,17 @@ namespace ImageCatalog_2
|
|||
}
|
||||
}
|
||||
|
||||
private bool _removeExifData;
|
||||
public bool RemoveExifData
|
||||
{
|
||||
get => _removeExifData;
|
||||
set
|
||||
{
|
||||
_removeExifData = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private bool _updateSubdirectories;
|
||||
public bool UpdateSubdirectories
|
||||
{
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ public class DataModelMappingProfile : Profile
|
|||
// Boolean flags
|
||||
.ForMember(dest => dest.UsaRotazioneAutomatica, opt => opt.MapFrom(src => src.AutomaticRotation))
|
||||
.ForMember(dest => dest.UsaForzaJpg, opt => opt.MapFrom(src => src.ForceJpeg))
|
||||
.ForMember(dest => dest.RemoveExifData, opt => opt.MapFrom(src => src.RemoveExifData))
|
||||
.ForMember(dest => dest.TestoNome, opt => opt.MapFrom(src => src.ShowPhotoNumber))
|
||||
.ForMember(dest => dest.NomeData, opt => opt.MapFrom(src => src.ShowDate))
|
||||
.ForMember(dest => dest.UsaOrarioTestoApplicare, opt => opt.MapFrom(src => src.AddTime))
|
||||
|
|
|
|||
|
|
@ -197,6 +197,10 @@ namespace ImageCatalog_2.Models
|
|||
[XmlElement("GeneraleForzaJpg")]
|
||||
public bool ForceJpeg { get; set; }
|
||||
|
||||
[JsonPropertyName("RemoveExifData")]
|
||||
[XmlElement("GeneraleRimuoviExif")]
|
||||
public bool RemoveExifData { get; set; }
|
||||
|
||||
[JsonPropertyName("AutomaticRotation")]
|
||||
[XmlElement("GeneraleRotazioneAutomatica")]
|
||||
public bool AutomaticRotation { get; set; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue