From 69fdf01de3274b8346048479920fe3d0da3642b3 Mon Sep 17 00:00:00 2001 From: MaddoScientisto Date: Sat, 14 Feb 2026 22:18:56 +0100 Subject: [PATCH 01/80] Modernize versioning and display in app and build output - Switch to explicit "3.2.0" next-version in GitVersion.yml - Update NuGet packages and set assembly name to "ImageCatalog" - Add MSBuild target to rename published exe with year and version - Add AppVersion property to DataModel, set via IVersionProvider - Replace static version label with data-bound versionLabel in UI - Remove manual version label logic from MainForm - Update DI to inject IVersionProvider into DataModel - Ensures UI always shows correct version and builds are versioned --- GitVersion.yml | 2 +- imagecatalog/DataModel.cs | 15 ++++++- imagecatalog/ImageCatalog 2.csproj | 69 +++++++++++++++++++++++++++--- imagecatalog/MainForm.Designer.cs | 22 +++++----- imagecatalog/MainForm.cs | 5 +-- imagecatalog/Program.cs | 14 +++++- 6 files changed, 106 insertions(+), 21 deletions(-) diff --git a/GitVersion.yml b/GitVersion.yml index 05c2cf9..a3baf60 100644 --- a/GitVersion.yml +++ b/GitVersion.yml @@ -4,4 +4,4 @@ branches: {} ignore: sha: [] merge-message-formats: {} -next-version: "3.2" \ No newline at end of file +next-version: "3.2.0" \ No newline at end of file diff --git a/imagecatalog/DataModel.cs b/imagecatalog/DataModel.cs index 080ef24..02c7b76 100644 --- a/imagecatalog/DataModel.cs +++ b/imagecatalog/DataModel.cs @@ -45,7 +45,7 @@ namespace ImageCatalog_2 public DataModel(ITestService testService, ISettingsService settingsService, ImageCreationStuff imageCreationService, PicSettings picSettings, - IMapper mapper, ILogger logger) + IMapper mapper, ILogger logger, MaddoShared.IVersionProvider? versionProvider = null) { _service = testService; _logger = logger; @@ -53,6 +53,8 @@ namespace ImageCatalog_2 _imageCreationService = imageCreationService; _picSettings = picSettings; _mapper = mapper; + // Populate AppVersion from version provider when available + AppVersion = versionProvider?.GetVersionString() ?? string.Empty; TestCommand = new RelayCommand(Test); AsyncTestCommand = new AsyncCommand(TestAsync); @@ -1123,6 +1125,17 @@ namespace ImageCatalog_2 { await _settingsService.LoadSettingsAsync(filePath, this); } + + private string _appVersion = string.Empty; + public string AppVersion + { + get => _appVersion; + set + { + _appVersion = value; + NotifyPropertyChanged(); + } + } } } diff --git a/imagecatalog/ImageCatalog 2.csproj b/imagecatalog/ImageCatalog 2.csproj index 880dc53..079d003 100644 --- a/imagecatalog/ImageCatalog 2.csproj +++ b/imagecatalog/ImageCatalog 2.csproj @@ -10,7 +10,8 @@ 3.1.2.0 3.1.2 3.1.2 - ImageCatalog2025 + + ImageCatalog default Logo.ico @@ -40,10 +41,10 @@ - - - - + + + + all @@ -61,4 +62,62 @@ + + + + + <_PublishYear>$([System.DateTime]::Now.ToString("yyyy")) + + <_Ver>$(FileVersion) + <_Ver Condition="'$(_Ver)' == ''">$(AssemblyVersion) + + + <_VerSanitized>$([System.String]::Copy('$(_Ver)')) + <_VerSanitized>$([System.String]::Copy('$(_VerSanitized)').Replace('+', '.')) + <_VerSanitized>$([System.String]::Copy('$(_VerSanitized)').Replace(' ', '_')) + + <_NewExeNameBase>ImageCatalog.$(_PublishYear).$(_VerSanitized) + + + + + + + <_Candidate1>$(PublishDir)$(TargetFileName) + <_Candidate2>$(PublishDir)$(TargetName)$(TargetExt) + <_Candidate3>$(PublishDir)$(TargetName).exe + <_Candidate4>$(PublishDir)$(AssemblyName)$(TargetExt) + <_Candidate5>$(PublishDir)$(AssemblyName).exe + + + + + <_CandidateFound>$(_Candidate1) + + + <_CandidateFound>$(_Candidate2) + + + <_CandidateFound>$(_Candidate3) + + + <_CandidateFound>$(_Candidate4) + + + <_CandidateFound>$(_Candidate5) + + + + + <_FoundExt>$([System.IO.Path]::GetExtension('$(_CandidateFound)')) + <_DestExe>$(PublishDir)$(_NewExeNameBase)$(_FoundExt) + + + + + + + \ No newline at end of file diff --git a/imagecatalog/MainForm.Designer.cs b/imagecatalog/MainForm.Designer.cs index 0ee4e01..ed17967 100644 --- a/imagecatalog/MainForm.Designer.cs +++ b/imagecatalog/MainForm.Designer.cs @@ -171,7 +171,7 @@ namespace ImageCatalog Label29 = new Label(); Label30 = new Label(); PictureBox3 = new PictureBox(); - _Label27 = new Label(); + versionLabel = new Label(); _Button7 = new Button(); _Button5 = new Button(); Label20 = new Label(); @@ -1748,15 +1748,16 @@ namespace ImageCatalog PictureBox3.TabStop = false; PictureBox3.Visible = false; // - // _Label27 + // versionLabel // - _Label27.Location = new Point(1182, 873); - _Label27.Margin = new Padding(6, 0, 6, 0); - _Label27.Name = "_Label27"; - _Label27.Size = new Size(281, 47); - _Label27.TabIndex = 62; - _Label27.Text = "Versione 2.2 2021"; - _Label27.TextAlign = ContentAlignment.MiddleRight; + versionLabel.Location = new Point(1182, 873); + versionLabel.Margin = new Padding(6, 0, 6, 0); + versionLabel.Name = "versionLabel"; + versionLabel.Size = new Size(281, 47); + versionLabel.TabIndex = 62; + versionLabel.Text = "Versione 2.2 2021"; + versionLabel.TextAlign = ContentAlignment.MiddleRight; + versionLabel.DataBindings.Add(new Binding("Text", bindingSource1, "AppVersion", true)); // // _Button7 // @@ -1872,7 +1873,7 @@ namespace ImageCatalog Controls.Add(CheckBox22); Controls.Add(Label43); Controls.Add(TabControl1); - Controls.Add(_Label27); + Controls.Add(versionLabel); Controls.Add(_Button7); Controls.Add(_Button5); Controls.Add(Label20); @@ -1997,6 +1998,7 @@ namespace ImageCatalog internal Label Label41; internal TextBox TextBox31; internal TextBox TextBox30; + internal Label versionLabel; internal GroupBox GroupBox9; internal CheckBox CheckBox17; internal CheckBox CheckBox16; diff --git a/imagecatalog/MainForm.cs b/imagecatalog/MainForm.cs index 35f6658..d63af72 100644 --- a/imagecatalog/MainForm.cs +++ b/imagecatalog/MainForm.cs @@ -32,7 +32,7 @@ public partial class MainForm private readonly PicSettings _picSettings; public MainForm(DataModel model, ImageCreationStuff imageCreationStuff, PicSettings picSettings, - ParametriSetup parametriSetup, ILogger logger, IVersionProvider versionProvider) + ParametriSetup parametriSetup, ILogger logger) { Model = model; _parametriSetup = parametriSetup; @@ -55,8 +55,7 @@ public partial class MainForm btnOpenSourceFolder.Click += BtnOpenSourceFolder_Click; btnOpenDestFolder.Click += BtnOpenDestFolder_Click; - var versionString = versionProvider?.GetVersionString() ?? "0.0.0"; - _Label27.Text = $"Version: {versionString}"; + // Version label is data-bound to DataModel.AppVersion; DataModel is populated with the version via DI } protected void BindControls() diff --git a/imagecatalog/Program.cs b/imagecatalog/Program.cs index 6bf6acd..451afbd 100644 --- a/imagecatalog/Program.cs +++ b/imagecatalog/Program.cs @@ -87,7 +87,19 @@ static class Program services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(sp => + { + // Resolve optional version provider and pass to DataModel + var testService = sp.GetRequiredService(); + var settingsService = sp.GetRequiredService(); + var imageCreation = sp.GetRequiredService(); + var picSettings = sp.GetRequiredService(); + var mapper = sp.GetRequiredService(); + var logger = sp.GetRequiredService>(); + var versionProvider = sp.GetService(); + + return new DataModel(testService, settingsService, imageCreation, picSettings, mapper, logger, versionProvider); + }); services.AddTransient(); services.AddTransient(); From a00ab074c4d056b825445ead53f1034bdc9a4d88 Mon Sep 17 00:00:00 2001 From: MaddoScientisto Date: Sun, 15 Feb 2026 00:03:16 +0100 Subject: [PATCH 02/80] Prefer GitVersion values for assembly and publish versioning Enhance versioning by prioritizing GitVersion output for assembly, file, and informational versions. Add fallback MSBuild target to run GitVersion CLI in Visual Studio builds. Update publish rename logic to use FullSemVer and improve version normalization for artifact naming. --- imagecatalog/ImageCatalog 2.csproj | 32 ++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/imagecatalog/ImageCatalog 2.csproj b/imagecatalog/ImageCatalog 2.csproj index 079d003..e0acb4f 100644 --- a/imagecatalog/ImageCatalog 2.csproj +++ b/imagecatalog/ImageCatalog 2.csproj @@ -49,6 +49,17 @@ all + + + + + $(GitVersion_AssemblySemVer) + + $(GitVersion_FileVersion) + + $(GitVersion_FullSemVer) + True @@ -63,19 +74,32 @@ + + + + + + + + + <_PublishYear>$([System.DateTime]::Now.ToString("yyyy")) - - <_Ver>$(FileVersion) + + <_Ver Condition="'$(GitVersion_FullSemVer)' != ''">$(GitVersion_FullSemVer) + <_Ver Condition="'$(GitVersion_FullSemVer)' == ''">$(FileVersion) <_Ver Condition="'$(_Ver)' == ''">$(AssemblyVersion) - + <_VerSanitized>$([System.String]::Copy('$(_Ver)')) - <_VerSanitized>$([System.String]::Copy('$(_VerSanitized)').Replace('+', '.')) <_VerSanitized>$([System.String]::Copy('$(_VerSanitized)').Replace(' ', '_')) <_NewExeNameBase>ImageCatalog.$(_PublishYear).$(_VerSanitized) From e48c0d266bf56f6547aab50eaa12d29fb790d0e0 Mon Sep 17 00:00:00 2001 From: MaddoScientisto Date: Sun, 15 Feb 2026 00:14:04 +0100 Subject: [PATCH 03/80] Add IImageCreator abstraction and runtime provider selection Introduce IImageCreator interface for image creation, and update ImageCreatorSharp to implement it. Add ImageCreatorAlternate (adapter) and ImageCreatorMapper (runtime selector) classes. Extend PicSettings with ImageCreatorProvider to control backend selection. Update DI registrations and refactor ImageCreationStuff to depend on IImageCreator, enabling backend switching via configuration. --- MaddoShared/IImageCreator.cs | 9 +++++ MaddoShared/ImageCreationStuff.cs | 2 +- MaddoShared/ImageCreatorAlternate.cs | 25 ++++++++++++++ MaddoShared/ImageCreatorMapper.cs | 49 ++++++++++++++++++++++++++++ MaddoShared/ImageCreatorSharp.cs | 2 +- MaddoShared/PicSettings.cs | 2 ++ imagecatalog/Program.cs | 5 +++ 7 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 MaddoShared/IImageCreator.cs create mode 100644 MaddoShared/ImageCreatorAlternate.cs create mode 100644 MaddoShared/ImageCreatorMapper.cs diff --git a/MaddoShared/IImageCreator.cs b/MaddoShared/IImageCreator.cs new file mode 100644 index 0000000..6fd85a5 --- /dev/null +++ b/MaddoShared/IImageCreator.cs @@ -0,0 +1,9 @@ +using System.Drawing; +using System.Threading.Tasks; + +namespace MaddoShared; + +public interface IImageCreator +{ + Task CreateImageAsync(ImageState imgState, Image logo); +} diff --git a/MaddoShared/ImageCreationStuff.cs b/MaddoShared/ImageCreationStuff.cs index 7aef4d4..b688f3a 100644 --- a/MaddoShared/ImageCreationStuff.cs +++ b/MaddoShared/ImageCreationStuff.cs @@ -18,7 +18,7 @@ namespace MaddoShared public class ImageCreationStuff( ILogger logger, PicSettings picSettings, - ImageCreatorSharp imageCreatorService) + IImageCreator imageCreatorService) { public class Options { diff --git a/MaddoShared/ImageCreatorAlternate.cs b/MaddoShared/ImageCreatorAlternate.cs new file mode 100644 index 0000000..2c945e8 --- /dev/null +++ b/MaddoShared/ImageCreatorAlternate.cs @@ -0,0 +1,25 @@ +using System.Drawing; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; + +namespace MaddoShared; + +// Minimal alternate adapter that currently delegates to ImageCreatorSharp. +// Later this can be replaced with a different library implementation. +public class ImageCreatorAlternate : IImageCreator +{ + private readonly ImageCreatorSharp _inner; + private readonly ILogger _logger; + + public ImageCreatorAlternate(ImageCreatorSharp inner, ILogger logger) + { + _inner = inner; + _logger = logger; + } + + public Task CreateImageAsync(ImageState imgState, Image logo) + { + _logger.LogDebug("Using alternate image creator adapter"); + return _inner.CreateImageAsync(imgState, logo); + } +} diff --git a/MaddoShared/ImageCreatorMapper.cs b/MaddoShared/ImageCreatorMapper.cs new file mode 100644 index 0000000..8ee07cf --- /dev/null +++ b/MaddoShared/ImageCreatorMapper.cs @@ -0,0 +1,49 @@ +using System; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; + +namespace MaddoShared; + +/// +/// Dynamically resolves the concrete IImageCreator implementation at call time +/// based on current PicSettings.ImageCreatorProvider. +/// +public class ImageCreatorMapper : IImageCreator +{ + private readonly IServiceProvider _sp; + private readonly PicSettings _settings; + private readonly ILogger _logger; + + public ImageCreatorMapper(IServiceProvider sp, PicSettings settings, ILogger logger) + { + _sp = sp ?? throw new ArgumentNullException(nameof(sp)); + _settings = settings ?? throw new ArgumentNullException(nameof(settings)); + _logger = logger; + } + + public Task CreateImageAsync(ImageState imgState, System.Drawing.Image logo) + { + var provider = (_settings.ImageCreatorProvider ?? "Sharp").Trim(); + _logger?.LogDebug("Resolving IImageCreator for provider '{Provider}'", provider); + + return provider.Equals("ALTERNATE", StringComparison.OrdinalIgnoreCase) + ? ResolveAndCall(imgState, logo) + : ResolveAndCall(imgState, logo); + } + + private Task ResolveAndCall(ImageState imgState, System.Drawing.Image logo) where T : IImageCreator + { + // Resolve the concrete implementation and forward the call + var impl = (IImageCreator)_sp.GetService(typeof(T)); + if (impl is null) + { + _logger?.LogWarning("Requested image creator {Type} is not registered. Falling back to ImageCreatorSharp.", typeof(T).Name); + impl = (IImageCreator)_sp.GetService(typeof(ImageCreatorSharp)); + } + + if (impl is null) + throw new InvalidOperationException("No IImageCreator implementation is registered."); + + return impl.CreateImageAsync(imgState, logo); + } +} diff --git a/MaddoShared/ImageCreatorSharp.cs b/MaddoShared/ImageCreatorSharp.cs index 0fdb25e..cfd54e2 100644 --- a/MaddoShared/ImageCreatorSharp.cs +++ b/MaddoShared/ImageCreatorSharp.cs @@ -15,7 +15,7 @@ using SixLabors.ImageSharp.Metadata.Profiles.Exif; namespace MaddoShared; [SuppressMessage("Interoperability", "CA1416:Validate platform compatibility")] -public class ImageCreatorSharp(PicSettings picSettings, ILogger logger) +public class ImageCreatorSharp(PicSettings picSettings, ILogger logger) : IImageCreator { public async Task CreateImageAsync(ImageState imgState, Image logo) { diff --git a/MaddoShared/PicSettings.cs b/MaddoShared/PicSettings.cs index 7472b63..d16cf5f 100644 --- a/MaddoShared/PicSettings.cs +++ b/MaddoShared/PicSettings.cs @@ -66,4 +66,6 @@ public class PicSettings public bool FotoRuotaASinistra { get; set; } = false; public string TempMinText { get; set; } = string.Empty; public bool OverwriteFiles { get; set; } = false; + // Which image creator to use: "Sharp" for current implementation, "Alternate" for alternate library + public string ImageCreatorProvider { get; set; } = "Sharp"; } \ No newline at end of file diff --git a/imagecatalog/Program.cs b/imagecatalog/Program.cs index 451afbd..c14bca6 100644 --- a/imagecatalog/Program.cs +++ b/imagecatalog/Program.cs @@ -103,6 +103,11 @@ static class Program services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + // Register IImageCreator to be resolved via ImageCreatorMapper which selects concrete implementation at call time + services.AddTransient(sp => sp.GetRequiredService()); // Register a ParametriSetup singleton that persists user preferences in LocalApplicationData var userPrefsPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), From 63751af18da39c2a7055eb33d2ed858ea826d0c8 Mon Sep 17 00:00:00 2001 From: MaddoScientisto Date: Sun, 15 Feb 2026 01:03:26 +0100 Subject: [PATCH 04/80] Add selectable image library option and refactor processing Introduce UI option to choose between System.Graphics and ImageSharp for image processing. Update DataModel and MainForm for robust binding and synchronization. Rewrite ImageCreatorAlternate to use ImageSharp for core operations and GDI+ for overlays. Remove test buttons, add radio group for library selection. Update project dependencies to support new features and modernize image handling. --- .../MaddoShared.Benchmarks.csproj | 4 +- MaddoShared.Tests/MaddoShared.Tests.csproj | 4 +- MaddoShared/ImageCreatorAlternate.cs | 294 +++++++++++++++++- MaddoShared/MaddoShared.csproj | 10 +- imagecatalog/DataModel.cs | 44 +++ imagecatalog/MainForm.Designer.cs | 75 +++-- imagecatalog/MainForm.cs | 105 ++++++- 7 files changed, 474 insertions(+), 62 deletions(-) diff --git a/MaddoShared.Benchmarks/MaddoShared.Benchmarks.csproj b/MaddoShared.Benchmarks/MaddoShared.Benchmarks.csproj index 99dc727..7ce2437 100644 --- a/MaddoShared.Benchmarks/MaddoShared.Benchmarks.csproj +++ b/MaddoShared.Benchmarks/MaddoShared.Benchmarks.csproj @@ -10,8 +10,8 @@ - - + + diff --git a/MaddoShared.Tests/MaddoShared.Tests.csproj b/MaddoShared.Tests/MaddoShared.Tests.csproj index 0b2620b..c4a7299 100644 --- a/MaddoShared.Tests/MaddoShared.Tests.csproj +++ b/MaddoShared.Tests/MaddoShared.Tests.csproj @@ -17,8 +17,8 @@ - - + + diff --git a/MaddoShared/ImageCreatorAlternate.cs b/MaddoShared/ImageCreatorAlternate.cs index 2c945e8..9ff74ec 100644 --- a/MaddoShared/ImageCreatorAlternate.cs +++ b/MaddoShared/ImageCreatorAlternate.cs @@ -1,25 +1,301 @@ -using System.Drawing; +using System; +using System.IO; using System.Threading.Tasks; +using System.Drawing; using Microsoft.Extensions.Logging; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.Formats.Jpeg; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Metadata.Profiles.Exif; +using System.Linq; +using System.Drawing.Imaging; namespace MaddoShared; -// Minimal alternate adapter that currently delegates to ImageCreatorSharp. -// Later this can be replaced with a different library implementation. +/// +/// Image creator implemented using SixLabors.ImageSharp for core image operations. +/// This implementation focuses on loading, EXIF-orientation, resizing and saving. +/// It intentionally implements a minimal subset of the original functionality to +/// provide a safe and testable replacement. Additional features (text/logo drawing) +/// can be added later using ImageSharp.Drawing.Common and SixLabors.Fonts. +/// public class ImageCreatorAlternate : IImageCreator { - private readonly ImageCreatorSharp _inner; + private readonly PicSettings _picSettings; private readonly ILogger _logger; - public ImageCreatorAlternate(ImageCreatorSharp inner, ILogger logger) + public ImageCreatorAlternate(PicSettings picSettings, ILogger logger) { - _inner = inner; + _picSettings = picSettings ?? throw new ArgumentNullException(nameof(picSettings)); _logger = logger; } - public Task CreateImageAsync(ImageState imgState, Image logo) + public async Task CreateImageAsync(ImageState imgState, System.Drawing.Image logo) { - _logger.LogDebug("Using alternate image creator adapter"); - return _inner.CreateImageAsync(imgState, logo); + ArgumentNullException.ThrowIfNull(imgState); + + // Minimal preparation of names and settings normally done by ImageCreatorSharp.PrepareVariables + PrepareVariablesMinimal(imgState); + + try + { + _logger.LogInformation("[Alternate] Processing {File} -> {Dest}", imgState.WorkFile?.FullName, imgState.DestDir?.FullName); + + using var fs = File.OpenRead(imgState.WorkFile.FullName); + + // Load as Rgba32 for general operations + using var img = await SixLabors.ImageSharp.Image.LoadAsync(fs).ConfigureAwait(false); + + // Extract EXIF info (orientation and creation date) + ExtractExif(img, imgState); + + // Apply orientation + ApplyExifOrientation(img, imgState); + + // Determine output format + var forceJpg = _picSettings.UsaForzaJpg; + + // Compute big size + var bigSize = ComputeBigSize(img.Width, img.Height); + + // Resize big image if needed + using var imgBig = img.Clone(ctx => ctx.Resize(bigSize.Width, bigSize.Height)); + + // Ensure destination exists + imgState.DestDir?.Create(); + + var fileNameBig = System.IO.Path.Combine(imgState.DestDir.FullName, imgState.NomeFileBig); + + // Draw overlays (text/logo) onto big image via GDI+ and save + await DrawAndSaveWithGdiAsync(imgBig, fileNameBig, imgState, logo, _picSettings.JpegQuality, isThumbnail: false).ConfigureAwait(false); + + // Save big image with quality if JPEG + var extBig = System.IO.Path.GetExtension(imgState.NomeFileBig)?.ToLowerInvariant() ?? string.Empty; + var encoderBig = GetEncoderForExtension(extBig, _picSettings.JpegQuality); + await using (var outStream = System.IO.File.Open(fileNameBig, System.IO.FileMode.Create, System.IO.FileAccess.Write)) + { + await imgBig.SaveAsync(outStream, encoderBig, default).ConfigureAwait(false); + } + + // Create thumbnail if requested + if (_picSettings.CreaMiniature) + { + var smallSize = ComputeSmallSize(img.Width, img.Height); + using var imgSmall = img.Clone(ctx => ctx.Resize(smallSize.Width, smallSize.Height)); + + var fileNameSmall = System.IO.Path.Combine(imgState.DestDir.FullName, imgState.NomeFileSmall); + + // Draw overlays and save thumbnail via GDI+ + await DrawAndSaveWithGdiAsync(imgSmall, fileNameSmall, imgState, logo, _picSettings.JpegQualityMin, isThumbnail: true).ConfigureAwait(false); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "[Alternate] Error processing image {File}", imgState.WorkFile?.Name); + throw; + } + } + + + + // Thumbnail overlays are rendered by the GDI+ pass in DrawAndSaveWithGdiAsync to match original rendering. + + private static SixLabors.ImageSharp.Formats.IImageEncoder GetEncoderForExtension(string ext, long quality) + { + quality = Math.Clamp(quality, 1, 100); + return ext switch + { + ".png" => new SixLabors.ImageSharp.Formats.Png.PngEncoder(), + ".gif" => new SixLabors.ImageSharp.Formats.Gif.GifEncoder(), + _ => new JpegEncoder { Quality = (int)quality }, + }; + } + + private async Task DrawAndSaveWithGdiAsync(Image imgSharp, string outputPath, ImageState imgState, System.Drawing.Image logo, long quality, bool isThumbnail) + { + // Convert ImageSharp image to System.Drawing.Bitmap via MemoryStream PNG to preserve alpha + await using var ms = new MemoryStream(); + await imgSharp.SaveAsPngAsync(ms).ConfigureAwait(false); + ms.Seek(0, SeekOrigin.Begin); + + using var bmp = new Bitmap(ms); + using var g = Graphics.FromImage(bmp); + g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; + + // Prepare text + var text = isThumbnail ? imgState.TestoFirmaPiccola : imgState.TestoFirma; + if (string.IsNullOrEmpty(text) && _picSettings.TestoNome) + text = imgState.NomeFileBig; + + if (!string.IsNullOrEmpty(text)) + { + var fontSize = isThumbnail ? imgState.DimensioneStandardMiniatura : imgState.DimensioneStandard; + using var font = new System.Drawing.Font(_picSettings.IlFont ?? "Arial", Math.Max(6, fontSize)); + using var shadowBrush = new SolidBrush(System.Drawing.Color.FromArgb(imgState.AlphaScelta, 0, 0, 0)); + using var textBrush = new SolidBrush(System.Drawing.Color.FromArgb(imgState.AlphaScelta, _picSettings.FontColoreRGB)); + + var sf = new StringFormat { Alignment = StringAlignment.Center }; + var x = bmp.Width / 2f; + var y = isThumbnail ? bmp.Height - fontSize - 4 : bmp.Height - fontSize - (_picSettings.Margine); + + g.DrawString(text, font, shadowBrush, new System.Drawing.PointF(x + 1, y + 1), sf); + g.DrawString(text, font, textBrush, new System.Drawing.PointF(x, y), sf); + } + + // Draw logo if provided + if (logo != null && _picSettings.LogoAggiungi && File.Exists(_picSettings.LogoNomeFile)) + { + try + { + var target = new System.Drawing.Size(_picSettings.LogoLarghezza, _picSettings.LogoAltezza); + using var logoResized = new Bitmap(logo, target.Width, target.Height); + + int xPos = _picSettings.LogoPosizioneH?.ToUpperInvariant() == "DESTRA" ? bmp.Width - target.Width - _picSettings.Margine : _picSettings.Margine; + int yPos = _picSettings.LogoPosizioneV?.ToUpperInvariant() == "BASSO" ? bmp.Height - target.Height - _picSettings.Margine : _picSettings.Margine; + + var cm = new System.Drawing.Imaging.ColorMatrix { Matrix33 = (float)Math.Clamp((int.TryParse(_picSettings.LogoTrasparenza, out var lt) ? lt : 100) / 100.0, 0.0, 1.0) }; + var ia = new System.Drawing.Imaging.ImageAttributes(); + ia.SetColorMatrix(cm, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap); + + g.DrawImage(logoResized, new System.Drawing.Rectangle(xPos, yPos, target.Width, target.Height), 0, 0, target.Width, target.Height, GraphicsUnit.Pixel, ia); + } + catch (Exception ex) + { + _logger.LogError(ex, "[Alternate] Error drawing logo in GDI pass"); + } + } + + // Ensure directory + var dir = System.IO.Path.GetDirectoryName(outputPath); + if (!string.IsNullOrEmpty(dir)) Directory.CreateDirectory(dir); + + // Save with requested quality using GDI encoder + var encoder = GetEncoder(ImageFormat.Jpeg); + var myEncoder = System.Drawing.Imaging.Encoder.Quality; + using var encoderParams = new System.Drawing.Imaging.EncoderParameters(1); + encoderParams.Param[0] = new System.Drawing.Imaging.EncoderParameter(myEncoder, quality); + bmp.Save(outputPath, encoder, encoderParams); + } + + private static ImageCodecInfo GetEncoder(System.Drawing.Imaging.ImageFormat format) + { + var codecs = ImageCodecInfo.GetImageDecoders(); + foreach (var codec in codecs) + { + if (codec.FormatID == format.Guid) return codec; + } + return null; + } + + private void PrepareVariablesMinimal(ImageState imgState) + { + imgState.NomeFileBig = imgState.WorkFile.Name; + imgState.NomeFileSmall = (_picSettings.Suffisso ?? string.Empty) + imgState.WorkFile.Name; + imgState.DimensioneStandard = _picSettings.DimStandard; + imgState.DimensioneStandardMiniatura = _picSettings.DimStandardMiniatura; + + // sanitize + imgState.NomeFileBig = SanitizeFileName(imgState.NomeFileBig); + imgState.NomeFileSmall = SanitizeFileName(imgState.NomeFileSmall); + } + + private static string SanitizeFileName(string fileName) + { + if (string.IsNullOrEmpty(fileName)) return fileName; + var invalid = System.IO.Path.GetInvalidFileNameChars(); + var sb = new System.Text.StringBuilder(fileName.Length); + foreach (var ch in fileName) + sb.Append(Array.IndexOf(invalid, ch) >= 0 ? '_' : ch); + return sb.ToString(); + } + + private void ExtractExif(Image img, ImageState imgState) + { + imgState.Orientation = Orientations.TopLeft; + imgState.CreationDate = null; + + var profile = img.Metadata?.ExifProfile; + if (profile is null) return; + + IExifValue rotation = null; + var found = profile.TryGetValue(ExifTag.Orientation, out rotation); + if (found && rotation != null) + { + imgState.Orientation = (Orientations)Convert.ToInt32(rotation.Value); + } + + IExifValue date = null; + var creationFound = profile.TryGetValue(ExifTag.DateTimeOriginal, out date); + if (creationFound && date != null) + { + if (DateTime.TryParseExact(date.Value, "yyyy:MM:dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out var cr)) + { + imgState.CreationDate = cr; + } + else + { + imgState.CreationDate = null; + } + } + else + { + imgState.CreationDate = null; + } + } + + private void ApplyExifOrientation(Image img, ImageState imgState) + { + // Common EXIF orientations: 1=TopLeft, 3=BottomRight (rotate 180), 6=RightTop (rotate 90 CW), 8=LeftBottom (rotate 270 CW) + switch (imgState.Orientation) + { + case Orientations.RightTop: // 6 + img.Mutate(x => x.Rotate(RotateMode.Rotate90)); + break; + case Orientations.BottomRight: // 3 + img.Mutate(x => x.Rotate(RotateMode.Rotate180)); + break; + case Orientations.LftBottom: // 8 + img.Mutate(x => x.Rotate(RotateMode.Rotate270)); + break; + default: + break; + } + } + + private System.Drawing.Size ComputeBigSize(int width, int height) + { + // If original large size option requested, return original + // otherwise compute based on width/height limits from settings + return width > height + ? CalculateThumbnailSize(width, height, _picSettings.LarghezzaBig, "Larghezza") + : CalculateThumbnailSize(width, height, _picSettings.AltezzaBig, "Altezza"); + } + + private System.Drawing.Size ComputeSmallSize(int width, int height) + { + return width > height + ? CalculateThumbnailSize(width, height, _picSettings.LarghezzaSmall, "Larghezza") + : CalculateThumbnailSize(width, height, _picSettings.AltezzaSmall, "Altezza"); + } + + // Helper to access PicSettings values via instance _picSettings + + private static System.Drawing.Size CalculateThumbnailSize(int currentwidth, int currentheight, int maxPixel, string tipoSize) + { + double tempMultiplier; + if (string.Equals(tipoSize, "Larghezza", StringComparison.OrdinalIgnoreCase)) + tempMultiplier = maxPixel / (double)currentwidth; + else if (string.Equals(tipoSize, "Altezza", StringComparison.OrdinalIgnoreCase)) + tempMultiplier = maxPixel / (double)currentheight; + else if (currentheight > currentwidth) + tempMultiplier = maxPixel / (double)currentheight; + else + tempMultiplier = maxPixel / (double)currentwidth; + + var newSize = new System.Drawing.Size(Convert.ToInt32(currentwidth * tempMultiplier), Convert.ToInt32(currentheight * tempMultiplier)); + return newSize; } } + diff --git a/MaddoShared/MaddoShared.csproj b/MaddoShared/MaddoShared.csproj index e95dcf4..2bd6b04 100644 --- a/MaddoShared/MaddoShared.csproj +++ b/MaddoShared/MaddoShared.csproj @@ -14,12 +14,14 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + - + + + - + @@ -27,6 +29,6 @@ all - + \ No newline at end of file diff --git a/imagecatalog/DataModel.cs b/imagecatalog/DataModel.cs index 02c7b76..d59cb07 100644 --- a/imagecatalog/DataModel.cs +++ b/imagecatalog/DataModel.cs @@ -397,6 +397,50 @@ namespace ImageCatalog_2 } } + // Image library selection (UI radio buttons bind to the boolean helpers) + private string _imageLibrary = "System.Graphics"; + + /// + /// The selected image processing library. Possible values: "System.Graphics" or "ImageSharp". + /// This value is mirrored into PicSettings.ImageCreatorProvider so the runtime mapper picks the implementation. + /// + public string ImageLibrary + { + get => _imageLibrary; + set + { + if (_imageLibrary == value) return; + _imageLibrary = value; + // Reflect selection into PicSettings so mapper can resolve at runtime + _picSettings.ImageCreatorProvider = string.Equals(value, "ImageSharp", StringComparison.OrdinalIgnoreCase) + ? "ALTERNATE" + : "Sharp"; + NotifyPropertyChanged(); + NotifyPropertyChanged(nameof(UseSystemGraphics)); + NotifyPropertyChanged(nameof(UseImageSharp)); + } + } + + public bool UseSystemGraphics + { + get => string.Equals(ImageLibrary, "System.Graphics", StringComparison.OrdinalIgnoreCase); + set + { + if (value) ImageLibrary = "System.Graphics"; + NotifyPropertyChanged(); + } + } + + public bool UseImageSharp + { + get => string.Equals(ImageLibrary, "ImageSharp", StringComparison.OrdinalIgnoreCase); + set + { + if (value) ImageLibrary = "ImageSharp"; + NotifyPropertyChanged(); + } + } + // Folder division settings private int _filesPerFolder = 99; public int FilesPerFolder diff --git a/imagecatalog/MainForm.Designer.cs b/imagecatalog/MainForm.Designer.cs index ed17967..5865046 100644 --- a/imagecatalog/MainForm.Designer.cs +++ b/imagecatalog/MainForm.Designer.cs @@ -45,8 +45,6 @@ namespace ImageCatalog Label43 = new Label(); TabControl1 = new TabControl(); TabPage5 = new TabPage(); - button1 = new Button(); - btnTest = new Button(); GroupBox11 = new GroupBox(); numericUpDown2 = new NumericUpDown(); numericUpDown1 = new NumericUpDown(); @@ -183,6 +181,9 @@ namespace ImageCatalog _btnCreaCatalogoAsync = new Button(); timer1 = new System.Windows.Forms.Timer(components); dataModelBindingSource1 = new BindingSource(components); + groupBox12 = new GroupBox(); + rdbLibrary1 = new RadioButton(); + rdbLibrary2 = new RadioButton(); ((System.ComponentModel.ISupportInitialize)bindingSource1).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataModelBindingSource).BeginInit(); TabControl1.SuspendLayout(); @@ -211,6 +212,7 @@ namespace ImageCatalog ((System.ComponentModel.ISupportInitialize)_PictureBox1).BeginInit(); ((System.ComponentModel.ISupportInitialize)PictureBox3).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataModelBindingSource1).BeginInit(); + groupBox12.SuspendLayout(); SuspendLayout(); // // ProgressBar1 @@ -270,8 +272,7 @@ namespace ImageCatalog // // TabPage5 // - TabPage5.Controls.Add(button1); - TabPage5.Controls.Add(btnTest); + TabPage5.Controls.Add(groupBox12); TabPage5.Controls.Add(GroupBox11); TabPage5.Controls.Add(GroupBox3); TabPage5.Controls.Add(GroupBox8); @@ -285,28 +286,6 @@ namespace ImageCatalog TabPage5.Text = "Generale"; TabPage5.UseVisualStyleBackColor = true; // - // button1 - // - button1.DataBindings.Add(new Binding("Command", bindingSource1, "AsyncTestCommand", true)); - button1.Location = new Point(751, 720); - button1.Margin = new Padding(5); - button1.Name = "button1"; - button1.Size = new Size(141, 43); - button1.TabIndex = 50; - button1.Text = "Test Async"; - button1.UseVisualStyleBackColor = true; - // - // btnTest - // - btnTest.DataBindings.Add(new Binding("Command", bindingSource1, "TestCommand", true)); - btnTest.Location = new Point(487, 708); - btnTest.Margin = new Padding(5); - btnTest.Name = "btnTest"; - btnTest.Size = new Size(141, 43); - btnTest.TabIndex = 49; - btnTest.Text = "Test"; - btnTest.UseVisualStyleBackColor = true; - // // GroupBox11 // GroupBox11.Controls.Add(numericUpDown2); @@ -1750,6 +1729,7 @@ namespace ImageCatalog // // versionLabel // + versionLabel.DataBindings.Add(new Binding("Text", bindingSource1, "AppVersion", true)); versionLabel.Location = new Point(1182, 873); versionLabel.Margin = new Padding(6, 0, 6, 0); versionLabel.Name = "versionLabel"; @@ -1757,7 +1737,6 @@ namespace ImageCatalog versionLabel.TabIndex = 62; versionLabel.Text = "Versione 2.2 2021"; versionLabel.TextAlign = ContentAlignment.MiddleRight; - versionLabel.DataBindings.Add(new Binding("Text", bindingSource1, "AppVersion", true)); // // _Button7 // @@ -1863,6 +1842,41 @@ namespace ImageCatalog // dataModelBindingSource1.DataSource = typeof(ImageCatalog_2.DataModel); // + // groupBox12 + // + groupBox12.Controls.Add(rdbLibrary2); + groupBox12.Controls.Add(rdbLibrary1); + groupBox12.Location = new Point(405, 625); + groupBox12.Name = "groupBox12"; + groupBox12.Size = new Size(350, 175); + groupBox12.TabIndex = 49; + groupBox12.TabStop = false; + groupBox12.Text = "Libreria Manipolazione Grafica"; + // + // rdbLibrary1 + // + rdbLibrary1.AutoSize = true; + rdbLibrary1.Location = new Point(12, 37); + rdbLibrary1.Name = "rdbLibrary1"; + rdbLibrary1.Size = new Size(188, 34); + rdbLibrary1.TabIndex = 0; + rdbLibrary1.TabStop = true; + rdbLibrary1.Text = "System.Graphics"; + rdbLibrary1.DataBindings.Add(new Binding("Checked", bindingSource1, "UseSystemGraphics", true, DataSourceUpdateMode.OnPropertyChanged)); + rdbLibrary1.UseVisualStyleBackColor = true; + // + // rdbLibrary2 + // + rdbLibrary2.AutoSize = true; + rdbLibrary2.Location = new Point(12, 77); + rdbLibrary2.Name = "rdbLibrary2"; + rdbLibrary2.Size = new Size(149, 34); + rdbLibrary2.TabIndex = 1; + rdbLibrary2.TabStop = true; + rdbLibrary2.Text = "ImageSharp"; + rdbLibrary2.DataBindings.Add(new Binding("Checked", bindingSource1, "UseImageSharp", true, DataSourceUpdateMode.OnPropertyChanged)); + rdbLibrary2.UseVisualStyleBackColor = true; + // // MainForm // AutoScaleDimensions = new SizeF(12F, 30F); @@ -1929,6 +1943,8 @@ namespace ImageCatalog ((System.ComponentModel.ISupportInitialize)_PictureBox1).EndInit(); ((System.ComponentModel.ISupportInitialize)PictureBox3).EndInit(); ((System.ComponentModel.ISupportInitialize)dataModelBindingSource1).EndInit(); + groupBox12.ResumeLayout(false); + groupBox12.PerformLayout(); ResumeLayout(false); PerformLayout(); } @@ -2275,12 +2291,13 @@ namespace ImageCatalog private BindingSource dataModelBindingSource; private BindingSource dataModelBindingSource1; private BindingSource bindingSource1; - private Button btnTest; - private Button button1; private NumericUpDown numericUpDown1; private NumericUpDown numericUpDown2; private Button btnOpenDestFolder; private Button btnOpenSourceFolder; + private GroupBox groupBox12; + private RadioButton rdbLibrary2; + private RadioButton rdbLibrary1; internal Button btnCreaCatalogoAsync { diff --git a/imagecatalog/MainForm.cs b/imagecatalog/MainForm.cs index d63af72..79574a4 100644 --- a/imagecatalog/MainForm.cs +++ b/imagecatalog/MainForm.cs @@ -18,7 +18,6 @@ using ImageCatalog_2.Commands; using ImageCatalog_2.Services; using MaddoShared; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging; namespace ImageCatalog; @@ -30,6 +29,8 @@ public partial class MainForm private readonly ParametriSetup _parametriSetup; private readonly PicSettings _picSettings; + // Prevent re-entrant updates between UI events and model PropertyChanged handling + private bool _suppressRadioUpdates = false; public MainForm(DataModel model, ImageCreationStuff imageCreationStuff, PicSettings picSettings, ParametriSetup parametriSetup, ILogger logger) @@ -42,11 +43,44 @@ public partial class MainForm _logger.LogDebug("Start"); InitializeComponent(); - - // Set this form as the control for thread marshalling in the DataModel - Model.SetControl(this); - - BindControls(); + // Set this form as the control for thread marshalling in the DataModel + Model.SetControl(this); + + // Ensure the designer data bindings have a concrete DataSource immediately so + // that UI controls (radio buttons) reflect the ViewModel state and propagate + // user changes back to the ViewModel. + bindingSource1.DataSource = Model; + + BindControls(); + + // The designer originally bound the radio buttons to boolean helpers on the ViewModel. + // Those two separate bindings can fight with each other. Clear designer bindings and + // wire explicit Click handlers that update the single authoritative property + // `Model.ImageLibrary`. Also keep a PropertyChanged listener to reflect external + // changes back into the radio buttons. + rdbLibrary1.DataBindings.Clear(); + rdbLibrary2.DataBindings.Clear(); + + // Initialize radio state from model + rdbLibrary1.Checked = Model.UseSystemGraphics; + rdbLibrary2.Checked = Model.UseImageSharp; + + // Use Click handlers (not CheckedChanged) to avoid competing binding updates + rdbLibrary1.Click += (_, _) => + { + if (_suppressRadioUpdates) return; + if (Model.ImageLibrary != "System.Graphics") + Model.ImageLibrary = "System.Graphics"; + }; + rdbLibrary2.Click += (_, _) => + { + if (_suppressRadioUpdates) return; + if (Model.ImageLibrary != "ImageSharp") + Model.ImageLibrary = "ImageSharp"; + }; + + // Watch for model changes so we can reflect external updates + Model.PropertyChanged += Model_PropertyChanged; // Save user preferences on form close instead of immediately when dialogs are used this.FormClosing += MainForm_FormClosing; @@ -58,17 +92,56 @@ public partial class MainForm // Version label is data-bound to DataModel.AppVersion; DataModel is populated with the version via DI } - protected void BindControls() + private void RdbLibrary_CheckedChanged(object? sender, EventArgs e) { - // Bind buttons to ViewModel commands using command binding - _btnCreaCatalogoAsync.BindCommand(Model.ProcessImagesCommand); - button1.BindCommand(Model.ProcessImagesCommand); - _Button2.BindCommand(Model.SelectSourceFolderCommand); - _Button3.BindCommand(Model.SelectDestinationFolderCommand); - _Button4.BindCommand(Model.SelectLogoFileCommand); - _Button5.BindCommand(Model.SaveSettingsCommand); - _Button6.BindCommand(Model.LoadSettingsCommand); - _Button8.BindCommand(Model.SelectColorCommand); + // Keep behavior simple: when a radio button becomes checked, update the ViewModel + // so that the designer binding and PicSettings stay in sync. + if (sender is RadioButton rb && rb.Checked) + { + _logger?.LogDebug("Radio library changed: {RadioName}", rb.Name); + if (rb == rdbLibrary2) + { + Model.ImageLibrary = "ImageSharp"; + } + else if (rb == rdbLibrary1) + { + Model.ImageLibrary = "System.Graphics"; + } + } + } + + private void Model_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) + { + if (e.PropertyName is null) return; + if (e.PropertyName == nameof(Model.ImageLibrary) || e.PropertyName == nameof(Model.UseImageSharp) || e.PropertyName == nameof(Model.UseSystemGraphics)) + { + _logger?.LogDebug("Model property changed: {Property} => ImageLibrary={ImageLibrary}, PicSettings.Provider={Provider}", e.PropertyName, Model.ImageLibrary, _picSettings.ImageCreatorProvider); + + // Reflect authoritative model value into the radio buttons in a thread-safe, re-entrancy-safe way + try + { + _suppressRadioUpdates = true; + rdbLibrary1.Checked = Model.UseSystemGraphics; + rdbLibrary2.Checked = Model.UseImageSharp; + } + finally + { + _suppressRadioUpdates = false; + } + } + } + + protected void BindControls() + { + // Bind buttons to ViewModel commands using command binding + _btnCreaCatalogoAsync.BindCommand(Model.ProcessImagesCommand); + // Note: `button1` control does not exist in the designer. Use the primary create button only. + _Button2.BindCommand(Model.SelectSourceFolderCommand); + _Button3.BindCommand(Model.SelectDestinationFolderCommand); + _Button4.BindCommand(Model.SelectLogoFileCommand); + _Button5.BindCommand(Model.SaveSettingsCommand); + _Button6.BindCommand(Model.LoadSettingsCommand); + _Button8.BindCommand(Model.SelectColorCommand); // Subscribe to ViewModel events for UI dialogs (these need UI context) Model.SelectSourceFolderRequested += OnSelectSourceFolderRequested; From 8872080741e43cd2192125b4913957e46cce984b Mon Sep 17 00:00:00 2001 From: MaddoScientisto Date: Sun, 15 Feb 2026 11:13:23 +0100 Subject: [PATCH 05/80] Add color-key transparency support for logo overlays - Allow users to select a transparent color for logo images (watermarks) via UI (checkbox, color picker, preview). - Apply color-key transparency in both System.Drawing and ImageSharp backends: specified color in logo is made fully transparent. - Persist transparency settings in PicSettings and SettingsDto; bind to DataModel and UI controls. - Update logo preview to reflect transparency in real time. - Add option to select image processing library (System.Drawing or ImageSharp) in UI and settings. - Fix bug in SettingsService parameter loading for int/double/DateTime. - Fully integrate color-key transparency into image processing and settings serialization. --- MaddoShared/ImageCreatorAlternate.cs | 355 +++++++++++++++++++---- MaddoShared/ImageCreatorSharp.cs | 37 ++- MaddoShared/PicSettings.cs | 16 + imagecatalog/DataModel.cs | 30 ++ imagecatalog/MainForm.Designer.cs | 169 ++++++----- imagecatalog/MainForm.cs | 264 ++++++++++++++++- imagecatalog/MainForm.resx | 3 + imagecatalog/Models/SettingsDto.cs | 14 + imagecatalog/Services/SettingsService.cs | 6 +- 9 files changed, 729 insertions(+), 165 deletions(-) diff --git a/MaddoShared/ImageCreatorAlternate.cs b/MaddoShared/ImageCreatorAlternate.cs index 9ff74ec..8ddfbec 100644 --- a/MaddoShared/ImageCreatorAlternate.cs +++ b/MaddoShared/ImageCreatorAlternate.cs @@ -1,7 +1,7 @@ using System; using System.IO; using System.Threading.Tasks; -using System.Drawing; +// System.Drawing not required for ImageSharp-based drawing in this class using Microsoft.Extensions.Logging; using SixLabors.ImageSharp; using SixLabors.ImageSharp.Formats.Jpeg; @@ -10,7 +10,9 @@ using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Metadata.Profiles.Exif; using System.Linq; -using System.Drawing.Imaging; +using SixLabors.Fonts; +using SixLabors.ImageSharp.Drawing.Processing; +using SixLabors.ImageSharp.Drawing; namespace MaddoShared; @@ -68,17 +70,9 @@ public class ImageCreatorAlternate : IImageCreator var fileNameBig = System.IO.Path.Combine(imgState.DestDir.FullName, imgState.NomeFileBig); - // Draw overlays (text/logo) onto big image via GDI+ and save + // Draw overlays (text/logo) onto big image using ImageSharp and save await DrawAndSaveWithGdiAsync(imgBig, fileNameBig, imgState, logo, _picSettings.JpegQuality, isThumbnail: false).ConfigureAwait(false); - // Save big image with quality if JPEG - var extBig = System.IO.Path.GetExtension(imgState.NomeFileBig)?.ToLowerInvariant() ?? string.Empty; - var encoderBig = GetEncoderForExtension(extBig, _picSettings.JpegQuality); - await using (var outStream = System.IO.File.Open(fileNameBig, System.IO.FileMode.Create, System.IO.FileAccess.Write)) - { - await imgBig.SaveAsync(outStream, encoderBig, default).ConfigureAwait(false); - } - // Create thumbnail if requested if (_picSettings.CreaMiniature) { @@ -87,7 +81,7 @@ public class ImageCreatorAlternate : IImageCreator var fileNameSmall = System.IO.Path.Combine(imgState.DestDir.FullName, imgState.NomeFileSmall); - // Draw overlays and save thumbnail via GDI+ + // Draw overlays and save thumbnail via ImageSharp await DrawAndSaveWithGdiAsync(imgSmall, fileNameSmall, imgState, logo, _picSettings.JpegQualityMin, isThumbnail: true).ConfigureAwait(false); } } @@ -115,14 +109,28 @@ public class ImageCreatorAlternate : IImageCreator private async Task DrawAndSaveWithGdiAsync(Image imgSharp, string outputPath, ImageState imgState, System.Drawing.Image logo, long quality, bool isThumbnail) { - // Convert ImageSharp image to System.Drawing.Bitmap via MemoryStream PNG to preserve alpha - await using var ms = new MemoryStream(); - await imgSharp.SaveAsPngAsync(ms).ConfigureAwait(false); - ms.Seek(0, SeekOrigin.Begin); + // Use ImageSharp drawing APIs to render text and logos and save using ImageSharp encoders. + // Clone editable image so we don't mutate the original reference unexpectedly. + using var working = imgSharp.Clone(); - using var bmp = new Bitmap(ms); - using var g = Graphics.FromImage(bmp); - g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; + // Ensure DataFoto is set (extracted earlier) so time-based text is available + imgState.DataFoto = imgState.CreationDate ?? DateTime.Now; + + // Ensure thumbnail text is prepared similarly to ImageCreatorSharp logic + if (isThumbnail) + { + if (string.IsNullOrEmpty(imgState.TestoFirmaPiccola)) + { + if (_picSettings.TestoMin) + imgState.TestoFirmaPiccola = imgState.NomeFileBig; + else if (_picSettings.AggNumTempMin) + imgState.TestoFirmaPiccola = imgState.NomeFileBig + " "; + else if (_picSettings.UsaOrarioMiniatura) + imgState.TestoFirmaPiccola = imgState.DataFoto.ToShortTimeString(); + else + imgState.TestoFirmaPiccola ??= string.Empty; + } + } // Prepare text var text = isThumbnail ? imgState.TestoFirmaPiccola : imgState.TestoFirma; @@ -131,39 +139,251 @@ public class ImageCreatorAlternate : IImageCreator if (!string.IsNullOrEmpty(text)) { - var fontSize = isThumbnail ? imgState.DimensioneStandardMiniatura : imgState.DimensioneStandard; - using var font = new System.Drawing.Font(_picSettings.IlFont ?? "Arial", Math.Max(6, fontSize)); - using var shadowBrush = new SolidBrush(System.Drawing.Color.FromArgb(imgState.AlphaScelta, 0, 0, 0)); - using var textBrush = new SolidBrush(System.Drawing.Color.FromArgb(imgState.AlphaScelta, _picSettings.FontColoreRGB)); + // Choose target starting font size + var baseSize = isThumbnail ? imgState.DimensioneStandardMiniatura : imgState.DimensioneStandard; - var sf = new StringFormat { Alignment = StringAlignment.Center }; - var x = bmp.Width / 2f; - var y = isThumbnail ? bmp.Height - fontSize - 4 : bmp.Height - fontSize - (_picSettings.Margine); + // Create font with fallback + SixLabors.Fonts.Font font; + try + { + var fontName = _picSettings.IlFont ?? SixLabors.Fonts.SystemFonts.Collection.Families.First().Name; + font = SixLabors.Fonts.SystemFonts.CreateFont(fontName, Math.Max(6, baseSize)); + } + catch + { + font = SixLabors.Fonts.SystemFonts.CreateFont(SixLabors.Fonts.SystemFonts.Collection.Families.First().Name, Math.Max(6, baseSize)); + } - g.DrawString(text, font, shadowBrush, new System.Drawing.PointF(x + 1, y + 1), sf); - g.DrawString(text, font, textBrush, new System.Drawing.PointF(x, y), sf); + // Color with alpha + var textColor = SixLabors.ImageSharp.Color.Black; + try + { + var c = _picSettings.FontColoreRGB; + textColor = SixLabors.ImageSharp.Color.FromRgba(c.R, c.G, c.B, (byte)imgState.AlphaScelta); + } + catch + { + textColor = SixLabors.ImageSharp.Color.Black; + } + var shadowColor = SixLabors.ImageSharp.Color.FromRgba(0, 0, 0, (byte)imgState.AlphaScelta); + + // Find best font size so text fits image width (allow 95% width) and not exceed ~15% height + var maxTextWidth = working.Width * 0.95f; + var maxTextHeight = working.Height * 0.15f; + + var chosenSize = FindBestFontSize(text, font.Name, Math.Max(6, baseSize), maxTextWidth, maxTextHeight); + + // Use final font + var finalFont = SixLabors.Fonts.SystemFonts.CreateFont(font.Name, chosenSize); + if (!isThumbnail) imgState.DimensioneStandard = (int)Math.Round(chosenSize); + + // Approximate measured size since TextMeasurer/RendererOptions may not be available in this Fonts version + var approxWidth = finalFont.Size * text.Length * 0.6f; + var approxHeight = finalFont.Size * 1.0f; + + // Compute horizontal position based on alignment + float xCenterOfImg; + switch ((_picSettings.Allineamento ?? string.Empty).ToUpperInvariant()) + { + case "SINISTRA": + xCenterOfImg = Math.Min(_picSettings.Margine + (approxWidth / 2f), working.Width / 2f); + break; + case "DESTRA": + xCenterOfImg = Math.Max(working.Width - _picSettings.Margine - (approxWidth / 2f), working.Width / 2f); + break; + default: + xCenterOfImg = working.Width / 2f; + break; + } + + // Compute vertical position similar to ImageCreatorSharp behaviour + float originY; + var pos = (_picSettings.Posizione ?? string.Empty).ToUpperInvariant(); + if (pos == "ALTO") + { + originY = _picSettings.Margine; + } + else if (pos == "BASSO") + { + originY = (float)(working.Height - approxHeight - (working.Height * _picSettings.Margine / 100.0)); + } + else + { + originY = (working.Height - approxHeight) / 2f; + } + + // Compute origin X so the text is centered around xCenterOfImg + var originX = xCenterOfImg - approxWidth / 2f; + + // Clamp origin so text remains inside the image bounds + if (approxWidth > working.Width) + { + approxWidth = working.Width * 0.95f; + } + if (approxHeight > working.Height) + { + approxHeight = working.Height * 0.9f; + } + + originX = Math.Max(0, Math.Min(originX, working.Width - approxWidth)); + originY = Math.Max(0, Math.Min(originY, working.Height - approxHeight)); + + // Draw shadow then text + working.Mutate(ctx => + { + ctx.DrawText(text, finalFont, shadowColor, new SixLabors.ImageSharp.PointF(originX + 1, originY + 1)); + ctx.DrawText(text, finalFont, textColor, new SixLabors.ImageSharp.PointF(originX, originY)); + }); } // Draw logo if provided - if (logo != null && _picSettings.LogoAggiungi && File.Exists(_picSettings.LogoNomeFile)) + if (logo != null && _picSettings.LogoAggiungi) { try { - var target = new System.Drawing.Size(_picSettings.LogoLarghezza, _picSettings.LogoAltezza); - using var logoResized = new Bitmap(logo, target.Width, target.Height); + Image logoImg = null; - int xPos = _picSettings.LogoPosizioneH?.ToUpperInvariant() == "DESTRA" ? bmp.Width - target.Width - _picSettings.Margine : _picSettings.Margine; - int yPos = _picSettings.LogoPosizioneV?.ToUpperInvariant() == "BASSO" ? bmp.Height - target.Height - _picSettings.Margine : _picSettings.Margine; + // Prefer configured file if present, otherwise use the provided System.Drawing.Image instance + if (!string.IsNullOrEmpty(_picSettings.LogoNomeFile) && File.Exists(_picSettings.LogoNomeFile)) + { + using var logoStream = File.OpenRead(_picSettings.LogoNomeFile); + logoImg = await SixLabors.ImageSharp.Image.LoadAsync(logoStream).ConfigureAwait(false); + } + else + { + // Convert System.Drawing.Image to ImageSharp by saving to PNG in-memory to preserve alpha + await using var ms = new MemoryStream(); + logo.Save(ms, System.Drawing.Imaging.ImageFormat.Png); + ms.Seek(0, SeekOrigin.Begin); + logoImg = await SixLabors.ImageSharp.Image.LoadAsync(ms).ConfigureAwait(false); + } - var cm = new System.Drawing.Imaging.ColorMatrix { Matrix33 = (float)Math.Clamp((int.TryParse(_picSettings.LogoTrasparenza, out var lt) ? lt : 100) / 100.0, 0.0, 1.0) }; - var ia = new System.Drawing.Imaging.ImageAttributes(); - ia.SetColorMatrix(cm, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap); + var fotoLogoH = _picSettings.LogoAltezza; + var fotoLogoW = _picSettings.LogoLarghezza; - g.DrawImage(logoResized, new System.Drawing.Rectangle(xPos, yPos, target.Width, target.Height), 0, 0, target.Width, target.Height, GraphicsUnit.Pixel, ia); + // When rendering on thumbnails, limit logo size relative to the thumbnail dimensions + var effectiveMaxLogoWidth = fotoLogoW; + var effectiveMaxLogoHeight = fotoLogoH; + if (isThumbnail) + { + // Do not allow the logo to occupy more than ~30% of the thumbnail area + effectiveMaxLogoWidth = Math.Max(1, Math.Min(fotoLogoW, (int)(working.Width * 0.30))); + effectiveMaxLogoHeight = Math.Max(1, Math.Min(fotoLogoH, (int)(working.Height * 0.30))); + } + + // Compute new logo size preserving aspect ratio, but avoid upscaling the logo beyond its native size + var targetByWidth = CalculateThumbnailSize(logoImg.Width, logoImg.Height, effectiveMaxLogoWidth, "Larghezza"); + var targetByHeight = CalculateThumbnailSize(logoImg.Width, logoImg.Height, effectiveMaxLogoHeight, "Altezza"); + var nuovaSize = (targetByWidth.Width <= targetByHeight.Width) ? targetByWidth : targetByHeight; + + // Prevent upscaling: clamp to original logo size + if (nuovaSize.Width > logoImg.Width) nuovaSize.Width = logoImg.Width; + if (nuovaSize.Height > logoImg.Height) nuovaSize.Height = logoImg.Height; + + // Parse logo margin (may be percentage string like "10%") + var logoMargineStr = _picSettings.LogoMargine ?? string.Empty; + var inPercentualeL = logoMargineStr.Trim().EndsWith('%'); + var margineL = 0; + if (inPercentualeL) + { + var trimmed = logoMargineStr.Trim().TrimEnd('%'); + if (!int.TryParse(trimmed, out margineL)) margineL = 0; + } + else + { + if (!int.TryParse(logoMargineStr, out margineL)) margineL = 0; + } + var margineUsato = inPercentualeL ? Convert.ToInt32(working.Height * margineL / (double)100) : margineL; + + int xPosOfWm = 0; + int yPosOfWm = 0; + var logoH = (_picSettings.LogoPosizioneH ?? "NESSUNA").ToUpperInvariant(); + var logoV = (_picSettings.LogoPosizioneV ?? "NESSUNA").ToUpperInvariant(); + switch (logoH) + { + case "SINISTRA": + case "NESSUNA": + xPosOfWm = margineUsato; + break; + case "CENTRO": + xPosOfWm = Convert.ToInt32((working.Width - nuovaSize.Width) / (double)2); + break; + case "DESTRA": + xPosOfWm = ((working.Width - nuovaSize.Width) - margineUsato); + break; + } + + switch (logoV) + { + case "ALTO": + case "NESSUNA": + yPosOfWm = margineUsato; + break; + case "CENTRO": + yPosOfWm = Convert.ToInt32((working.Height - nuovaSize.Height) / (double)2); + break; + case "BASSO": + yPosOfWm = ((working.Height - nuovaSize.Height) - margineUsato); + break; + } + + var transparency = 1.0f; + if (int.TryParse(_picSettings.LogoTrasparenza, out var lt)) transparency = Math.Clamp(lt / 100f, 0f, 1f); + + // Resize logo to nuovaSize + logoImg.Mutate(x => x.Resize(nuovaSize.Width, nuovaSize.Height)); + + // If configured to use color-key transparency for non-PNG logos, replace the key color with transparent + if (_picSettings.UseTransparentColor && !string.IsNullOrEmpty(_picSettings.TransparentColor)) + { + try + { + var hex = _picSettings.TransparentColor.Trim(); + // Allow either #RRGGBB or RRGGBB + if (hex.StartsWith("#")) hex = hex.Substring(1); + if (hex.Length == 6) + { + var r = Convert.ToByte(hex.Substring(0, 2), 16); + var g = Convert.ToByte(hex.Substring(2, 2), 16); + var b = Convert.ToByte(hex.Substring(4, 2), 16); + var key = SixLabors.ImageSharp.Color.FromRgb(r, g, b); + + // Replace matching pixels (exact match) with transparent + logoImg.ProcessPixelRows(accessor => + { + for (int y = 0; y < accessor.Height; y++) + { + var row = accessor.GetRowSpan(y); + for (int x = 0; x < row.Length; x++) + { + var p = row[x]; + if (p.R == r && p.G == g && p.B == b) + { + row[x] = new Rgba32(p.R, p.G, p.B, 0); + } + } + } + }); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "[Alternate] Invalid transparent color setting {Color}", _picSettings.TransparentColor); + } + } + + // Ensure logo position keeps it inside the canvas (avoid clipping) + xPosOfWm = Math.Max(0, Math.Min(xPosOfWm, working.Width - nuovaSize.Width)); + yPosOfWm = Math.Max(0, Math.Min(yPosOfWm, working.Height - nuovaSize.Height)); + + // Draw logo with opacity + working.Mutate(ctx => ctx.DrawImage(logoImg, new SixLabors.ImageSharp.Point(xPosOfWm, yPosOfWm), (float)transparency)); + + logoImg.Dispose(); } catch (Exception ex) { - _logger.LogError(ex, "[Alternate] Error drawing logo in GDI pass"); + _logger.LogError(ex, "[Alternate] Error drawing logo in ImageSharp pass"); } } @@ -171,23 +391,14 @@ public class ImageCreatorAlternate : IImageCreator var dir = System.IO.Path.GetDirectoryName(outputPath); if (!string.IsNullOrEmpty(dir)) Directory.CreateDirectory(dir); - // Save with requested quality using GDI encoder - var encoder = GetEncoder(ImageFormat.Jpeg); - var myEncoder = System.Drawing.Imaging.Encoder.Quality; - using var encoderParams = new System.Drawing.Imaging.EncoderParameters(1); - encoderParams.Param[0] = new System.Drawing.Imaging.EncoderParameter(myEncoder, quality); - bmp.Save(outputPath, encoder, encoderParams); + // Save with requested quality using ImageSharp encoder + var ext = System.IO.Path.GetExtension(outputPath)?.ToLowerInvariant() ?? string.Empty; + var encoder = GetEncoderForExtension(ext, quality); + await using var outStream = System.IO.File.Open(outputPath, System.IO.FileMode.Create, System.IO.FileAccess.Write); + await working.SaveAsync(outStream, encoder).ConfigureAwait(false); } - private static ImageCodecInfo GetEncoder(System.Drawing.Imaging.ImageFormat format) - { - var codecs = ImageCodecInfo.GetImageDecoders(); - foreach (var codec in codecs) - { - if (codec.FormatID == format.Guid) return codec; - } - return null; - } + // Removed GDI encoder helper; ImageSharp encoders are used instead. private void PrepareVariablesMinimal(ImageState imgState) { @@ -196,6 +407,16 @@ public class ImageCreatorAlternate : IImageCreator imgState.DimensioneStandard = _picSettings.DimStandard; imgState.DimensioneStandardMiniatura = _picSettings.DimStandardMiniatura; + // basic text / transparency defaults used by drawing routines + // AlphaScelta mirrors ImageCreatorSharp behavior: compute from PicSettings.Trasparenza (0-100) + imgState.AlphaScelta = Convert.ToInt32((255 * (100 - _picSettings.Trasparenza) / (double)100)); + + // Set minimal text fields so text drawing has fallback values + imgState.TestoFirma ??= _picSettings.TestoFirmaStart ?? string.Empty; + imgState.TestoFirmaPiccola ??= string.Empty; + imgState.DataPartenzaI = _picSettings.DataPartenza; + imgState.TestoOrario = _picSettings.TestoOrario ?? string.Empty; + // sanitize imgState.NomeFileBig = SanitizeFileName(imgState.NomeFileBig); imgState.NomeFileSmall = SanitizeFileName(imgState.NomeFileSmall); @@ -297,5 +518,33 @@ public class ImageCreatorAlternate : IImageCreator var newSize = new System.Drawing.Size(Convert.ToInt32(currentwidth * tempMultiplier), Convert.ToInt32(currentheight * tempMultiplier)); return newSize; } + + private static float FindBestFontSize(string text, string fontName, int maxSize, float maxWidth, float maxHeight, int minSize = 6) + { + if (maxSize <= minSize) return Math.Max(minSize, maxSize); + + int low = minSize; + int high = Math.Max(minSize, maxSize); + int best = minSize; + + while (low <= high) + { + int mid = (low + high) / 2; + // Approximate measurement: width ~ size * chars * 0.6, height ~ size + var approxWidth = mid * text.Length * 0.6f; + var approxHeight = mid * 1.0f; + if (approxWidth <= maxWidth && approxHeight <= maxHeight) + { + best = mid; + low = mid + 1; // try larger + } + else + { + high = mid - 1; // too big + } + } + + return best; + } } diff --git a/MaddoShared/ImageCreatorSharp.cs b/MaddoShared/ImageCreatorSharp.cs index cfd54e2..e7fc59a 100644 --- a/MaddoShared/ImageCreatorSharp.cs +++ b/MaddoShared/ImageCreatorSharp.cs @@ -486,22 +486,37 @@ public class ImageCreatorSharp(PicSettings picSettings, ILogger TransparentColorHex; + set => TransparentColorHex = value; + } + + public bool UseTransparentColor + { + get => UseTransparentColorKey; + set => UseTransparentColorKey = value; + } public bool FotoGrandeDimOrigina { get; set; } public int AltezzaBig { get; set; } public int LarghezzaBig { get; set; } diff --git a/imagecatalog/DataModel.cs b/imagecatalog/DataModel.cs index d59cb07..6d90981 100644 --- a/imagecatalog/DataModel.cs +++ b/imagecatalog/DataModel.cs @@ -30,6 +30,7 @@ namespace ImageCatalog_2 public ICommand SaveSettingsCommand { get; } public ICommand LoadSettingsCommand { get; } public ICommand SelectColorCommand { get; } + public ICommand SelectTransparentColorCommand { get; } private readonly ITestService _service; private readonly ILogger _logger; @@ -67,6 +68,7 @@ namespace ImageCatalog_2 SaveSettingsCommand = new RelayCommand(SaveSettings); LoadSettingsCommand = new RelayCommand(LoadSettings); SelectColorCommand = new RelayCommand(SelectColor); + SelectTransparentColorCommand = new RelayCommand(SelectTransparentColor); // Load available fonts AvailableFonts = LoadAvailableFonts(); @@ -341,6 +343,28 @@ namespace ImageCatalog_2 } } + private string _transparentColor = "#FFFFFF"; + public string TransparentColor + { + get => _transparentColor; + set + { + _transparentColor = value; + NotifyPropertyChanged(); + } + } + + private bool _useTransparentColor; + public bool UseTransparentColor + { + get => _useTransparentColor; + set + { + _useTransparentColor = value; + NotifyPropertyChanged(); + } + } + // Logo/Watermark settings private string _logoFile = ""; public string LogoFile @@ -1129,6 +1153,7 @@ namespace ImageCatalog_2 public event EventHandler SelectColorRequested; // Request that the View shows a message to the user (message, caption, icon) public event EventHandler> ShowMessageRequested; + public event EventHandler SelectTransparentColorRequested; private void SelectSourceFolder(object parameter) { @@ -1160,6 +1185,11 @@ namespace ImageCatalog_2 SelectColorRequested?.Invoke(this, EventArgs.Empty); } + private void SelectTransparentColor(object parameter) + { + SelectTransparentColorRequested?.Invoke(this, EventArgs.Empty); + } + public async Task SaveSettingsToFileAsync(string filePath) { await _settingsService.SaveSettingsAsync(filePath, this); diff --git a/imagecatalog/MainForm.Designer.cs b/imagecatalog/MainForm.Designer.cs index 5865046..edb3bb1 100644 --- a/imagecatalog/MainForm.Designer.cs +++ b/imagecatalog/MainForm.Designer.cs @@ -45,6 +45,9 @@ namespace ImageCatalog Label43 = new Label(); TabControl1 = new TabControl(); TabPage5 = new TabPage(); + groupBox12 = new GroupBox(); + rdbLibrary2 = new RadioButton(); + rdbLibrary1 = new RadioButton(); GroupBox11 = new GroupBox(); numericUpDown2 = new NumericUpDown(); numericUpDown1 = new NumericUpDown(); @@ -150,7 +153,6 @@ namespace ImageCatalog CheckBox1 = new CheckBox(); TabPage4 = new TabPage(); GroupBox6 = new GroupBox(); - PictureBox2 = new PictureBox(); _PictureBox1 = new PictureBox(); ComboBox5 = new ComboBox(); ComboBox4 = new ComboBox(); @@ -167,8 +169,6 @@ namespace ImageCatalog _Button4 = new Button(); TextBox10 = new TextBox(); Label29 = new Label(); - Label30 = new Label(); - PictureBox3 = new PictureBox(); versionLabel = new Label(); _Button7 = new Button(); _Button5 = new Button(); @@ -181,13 +181,15 @@ namespace ImageCatalog _btnCreaCatalogoAsync = new Button(); timer1 = new System.Windows.Forms.Timer(components); dataModelBindingSource1 = new BindingSource(components); - groupBox12 = new GroupBox(); - rdbLibrary1 = new RadioButton(); - rdbLibrary2 = new RadioButton(); + PictureBox3 = new PictureBox(); + colorDialog1 = new ColorDialog(); + btnSetTransparency = new Button(); + chkUseTransparentColor = new CheckBox(); ((System.ComponentModel.ISupportInitialize)bindingSource1).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataModelBindingSource).BeginInit(); TabControl1.SuspendLayout(); TabPage5.SuspendLayout(); + groupBox12.SuspendLayout(); GroupBox11.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)numericUpDown2).BeginInit(); ((System.ComponentModel.ISupportInitialize)numericUpDown1).BeginInit(); @@ -208,11 +210,9 @@ namespace ImageCatalog Panel2.SuspendLayout(); TabPage4.SuspendLayout(); GroupBox6.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)PictureBox2).BeginInit(); ((System.ComponentModel.ISupportInitialize)_PictureBox1).BeginInit(); - ((System.ComponentModel.ISupportInitialize)PictureBox3).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataModelBindingSource1).BeginInit(); - groupBox12.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)PictureBox3).BeginInit(); SuspendLayout(); // // ProgressBar1 @@ -286,6 +286,41 @@ namespace ImageCatalog TabPage5.Text = "Generale"; TabPage5.UseVisualStyleBackColor = true; // + // groupBox12 + // + groupBox12.Controls.Add(rdbLibrary2); + groupBox12.Controls.Add(rdbLibrary1); + groupBox12.Location = new Point(405, 625); + groupBox12.Name = "groupBox12"; + groupBox12.Size = new Size(350, 175); + groupBox12.TabIndex = 49; + groupBox12.TabStop = false; + groupBox12.Text = "Libreria Manipolazione Grafica"; + // + // rdbLibrary2 + // + rdbLibrary2.AutoSize = true; + rdbLibrary2.DataBindings.Add(new Binding("Checked", bindingSource1, "UseImageSharp", true, DataSourceUpdateMode.OnPropertyChanged)); + rdbLibrary2.Location = new Point(12, 77); + rdbLibrary2.Name = "rdbLibrary2"; + rdbLibrary2.Size = new Size(149, 34); + rdbLibrary2.TabIndex = 1; + rdbLibrary2.TabStop = true; + rdbLibrary2.Text = "ImageSharp"; + rdbLibrary2.UseVisualStyleBackColor = true; + // + // rdbLibrary1 + // + rdbLibrary1.AutoSize = true; + rdbLibrary1.DataBindings.Add(new Binding("Checked", bindingSource1, "UseSystemGraphics", true, DataSourceUpdateMode.OnPropertyChanged)); + rdbLibrary1.Location = new Point(12, 37); + rdbLibrary1.Name = "rdbLibrary1"; + rdbLibrary1.Size = new Size(188, 34); + rdbLibrary1.TabIndex = 0; + rdbLibrary1.TabStop = true; + rdbLibrary1.Text = "System.Graphics"; + rdbLibrary1.UseVisualStyleBackColor = true; + // // GroupBox11 // GroupBox11.Controls.Add(numericUpDown2); @@ -1491,7 +1526,8 @@ namespace ImageCatalog // // GroupBox6 // - GroupBox6.Controls.Add(PictureBox2); + GroupBox6.Controls.Add(chkUseTransparentColor); + GroupBox6.Controls.Add(btnSetTransparency); GroupBox6.Controls.Add(_PictureBox1); GroupBox6.Controls.Add(ComboBox5); GroupBox6.Controls.Add(ComboBox4); @@ -1508,29 +1544,17 @@ namespace ImageCatalog GroupBox6.Controls.Add(_Button4); GroupBox6.Controls.Add(TextBox10); GroupBox6.Controls.Add(Label29); - GroupBox6.Controls.Add(Label30); GroupBox6.Controls.Add(PictureBox3); GroupBox6.ForeColor = Color.FromArgb(0, 0, 192); GroupBox6.Location = new Point(12, 13); GroupBox6.Margin = new Padding(6, 8, 6, 8); GroupBox6.Name = "GroupBox6"; GroupBox6.Padding = new Padding(6, 8, 6, 8); - GroupBox6.Size = new Size(991, 518); + GroupBox6.Size = new Size(991, 593); GroupBox6.TabIndex = 42; GroupBox6.TabStop = false; GroupBox6.Text = "Logo"; // - // PictureBox2 - // - PictureBox2.BorderStyle = BorderStyle.FixedSingle; - PictureBox2.Location = new Point(288, 442); - PictureBox2.Margin = new Padding(6, 8, 6, 8); - PictureBox2.Name = "PictureBox2"; - PictureBox2.Size = new Size(45, 53); - PictureBox2.TabIndex = 44; - PictureBox2.TabStop = false; - PictureBox2.Visible = false; - // // _PictureBox1 // _PictureBox1.Cursor = Cursors.Cross; @@ -1575,7 +1599,7 @@ namespace ImageCatalog // Label28 // Label28.ForeColor = Color.Black; - Label28.Location = new Point(34, 223); + Label28.Location = new Point(38, 222); Label28.Margin = new Padding(6, 0, 6, 0); Label28.Name = "Label28"; Label28.Size = new Size(240, 38); @@ -1587,7 +1611,7 @@ namespace ImageCatalog // CheckBox5.DataBindings.Add(new Binding("Checked", bindingSource1, "AddLogo", true, DataSourceUpdateMode.OnPropertyChanged)); CheckBox5.ForeColor = Color.Black; - CheckBox5.Location = new Point(0, 60); + CheckBox5.Location = new Point(12, 56); CheckBox5.Margin = new Padding(6, 8, 6, 8); CheckBox5.Name = "CheckBox5"; CheckBox5.Size = new Size(144, 47); @@ -1618,7 +1642,7 @@ namespace ImageCatalog // Label25.AutoSize = true; Label25.ForeColor = Color.Black; - Label25.Location = new Point(34, 387); + Label25.Location = new Point(39, 390); Label25.Margin = new Padding(6, 0, 6, 0); Label25.Name = "Label25"; Label25.Size = new Size(183, 30); @@ -1695,7 +1719,7 @@ namespace ImageCatalog // Label29.AutoSize = true; Label29.ForeColor = Color.Black; - Label29.Location = new Point(34, 339); + Label29.Location = new Point(38, 341); Label29.Margin = new Padding(6, 0, 6, 0); Label29.Name = "Label29"; Label29.Size = new Size(208, 30); @@ -1703,30 +1727,6 @@ namespace ImageCatalog Label29.Text = "Posizione orizzontale"; Label29.TextAlign = ContentAlignment.MiddleLeft; // - // Label30 - // - Label30.AutoSize = true; - Label30.ForeColor = Color.Black; - Label30.Location = new Point(38, 468); - Label30.Margin = new Padding(6, 0, 6, 0); - Label30.Name = "Label30"; - Label30.Size = new Size(184, 30); - Label30.TabIndex = 36; - Label30.Text = "Colore trasparente"; - Label30.TextAlign = ContentAlignment.MiddleLeft; - Label30.Visible = false; - // - // PictureBox3 - // - PictureBox3.BorderStyle = BorderStyle.FixedSingle; - PictureBox3.Location = new Point(432, 442); - PictureBox3.Margin = new Padding(6, 8, 6, 8); - PictureBox3.Name = "PictureBox3"; - PictureBox3.Size = new Size(45, 53); - PictureBox3.TabIndex = 44; - PictureBox3.TabStop = false; - PictureBox3.Visible = false; - // // versionLabel // versionLabel.DataBindings.Add(new Binding("Text", bindingSource1, "AppVersion", true)); @@ -1842,40 +1842,35 @@ namespace ImageCatalog // dataModelBindingSource1.DataSource = typeof(ImageCatalog_2.DataModel); // - // groupBox12 + // PictureBox3 // - groupBox12.Controls.Add(rdbLibrary2); - groupBox12.Controls.Add(rdbLibrary1); - groupBox12.Location = new Point(405, 625); - groupBox12.Name = "groupBox12"; - groupBox12.Size = new Size(350, 175); - groupBox12.TabIndex = 49; - groupBox12.TabStop = false; - groupBox12.Text = "Libreria Manipolazione Grafica"; + PictureBox3.BorderStyle = BorderStyle.FixedSingle; + PictureBox3.Location = new Point(432, 442); + PictureBox3.Margin = new Padding(6, 8, 6, 8); + PictureBox3.Name = "PictureBox3"; + PictureBox3.Size = new Size(45, 53); + PictureBox3.TabIndex = 44; + PictureBox3.TabStop = false; + PictureBox3.Visible = false; // - // rdbLibrary1 + // btnSetTransparency // - rdbLibrary1.AutoSize = true; - rdbLibrary1.Location = new Point(12, 37); - rdbLibrary1.Name = "rdbLibrary1"; - rdbLibrary1.Size = new Size(188, 34); - rdbLibrary1.TabIndex = 0; - rdbLibrary1.TabStop = true; - rdbLibrary1.Text = "System.Graphics"; - rdbLibrary1.DataBindings.Add(new Binding("Checked", bindingSource1, "UseSystemGraphics", true, DataSourceUpdateMode.OnPropertyChanged)); - rdbLibrary1.UseVisualStyleBackColor = true; + btnSetTransparency.Location = new Point(288, 455); + btnSetTransparency.Name = "btnSetTransparency"; + btnSetTransparency.Size = new Size(131, 40); + btnSetTransparency.TabIndex = 45; + btnSetTransparency.Text = "Imposta"; + btnSetTransparency.UseVisualStyleBackColor = true; // - // rdbLibrary2 + // chkUseTransparentColor // - rdbLibrary2.AutoSize = true; - rdbLibrary2.Location = new Point(12, 77); - rdbLibrary2.Name = "rdbLibrary2"; - rdbLibrary2.Size = new Size(149, 34); - rdbLibrary2.TabIndex = 1; - rdbLibrary2.TabStop = true; - rdbLibrary2.Text = "ImageSharp"; - rdbLibrary2.DataBindings.Add(new Binding("Checked", bindingSource1, "UseImageSharp", true, DataSourceUpdateMode.OnPropertyChanged)); - rdbLibrary2.UseVisualStyleBackColor = true; + chkUseTransparentColor.AutoSize = true; + chkUseTransparentColor.Location = new Point(39, 461); + chkUseTransparentColor.Name = "chkUseTransparentColor"; + chkUseTransparentColor.Size = new Size(210, 34); + chkUseTransparentColor.TabIndex = 46; + chkUseTransparentColor.Text = "Colore trasparente"; + chkUseTransparentColor.UseVisualStyleBackColor = true; // // MainForm // @@ -1905,6 +1900,8 @@ namespace ImageCatalog ((System.ComponentModel.ISupportInitialize)dataModelBindingSource).EndInit(); TabControl1.ResumeLayout(false); TabPage5.ResumeLayout(false); + groupBox12.ResumeLayout(false); + groupBox12.PerformLayout(); GroupBox11.ResumeLayout(false); GroupBox11.PerformLayout(); ((System.ComponentModel.ISupportInitialize)numericUpDown2).EndInit(); @@ -1939,12 +1936,9 @@ namespace ImageCatalog TabPage4.ResumeLayout(false); GroupBox6.ResumeLayout(false); GroupBox6.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)PictureBox2).EndInit(); ((System.ComponentModel.ISupportInitialize)_PictureBox1).EndInit(); - ((System.ComponentModel.ISupportInitialize)PictureBox3).EndInit(); ((System.ComponentModel.ISupportInitialize)dataModelBindingSource1).EndInit(); - groupBox12.ResumeLayout(false); - groupBox12.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)PictureBox3).EndInit(); ResumeLayout(false); PerformLayout(); } @@ -2145,7 +2139,6 @@ namespace ImageCatalog internal CheckBox CheckBox1; internal TabPage TabPage4; internal GroupBox GroupBox6; - internal PictureBox PictureBox2; private PictureBox _PictureBox1; internal PictureBox PictureBox1 @@ -2194,8 +2187,6 @@ namespace ImageCatalog internal TextBox TextBox10; internal Label Label29; - internal Label Label30; - internal PictureBox PictureBox3; private Label _Label27; internal Label Label27 @@ -2298,6 +2289,10 @@ namespace ImageCatalog private GroupBox groupBox12; private RadioButton rdbLibrary2; private RadioButton rdbLibrary1; + internal PictureBox PictureBox3; + private ColorDialog colorDialog1; + private Button btnSetTransparency; + private CheckBox chkUseTransparentColor; internal Button btnCreaCatalogoAsync { diff --git a/imagecatalog/MainForm.cs b/imagecatalog/MainForm.cs index 79574a4..684a60c 100644 --- a/imagecatalog/MainForm.cs +++ b/imagecatalog/MainForm.cs @@ -31,6 +31,7 @@ public partial class MainForm private readonly PicSettings _picSettings; // Prevent re-entrant updates between UI events and model PropertyChanged handling private bool _suppressRadioUpdates = false; + private bool _transparentDialogOpen = false; public MainForm(DataModel model, ImageCreationStuff imageCreationStuff, PicSettings picSettings, ParametriSetup parametriSetup, ILogger logger) @@ -89,9 +90,14 @@ public partial class MainForm btnOpenSourceFolder.Click += BtnOpenSourceFolder_Click; btnOpenDestFolder.Click += BtnOpenDestFolder_Click; + // Show currently selected color in small PictureBox3 + PictureBox3.BackColor = ColorTranslator.FromHtml(Model.TransparentColor); + // Version label is data-bound to DataModel.AppVersion; DataModel is populated with the version via DI } + + private void RdbLibrary_CheckedChanged(object? sender, EventArgs e) { // Keep behavior simple: when a radio button becomes checked, update the ViewModel @@ -142,6 +148,8 @@ public partial class MainForm _Button5.BindCommand(Model.SaveSettingsCommand); _Button6.BindCommand(Model.LoadSettingsCommand); _Button8.BindCommand(Model.SelectColorCommand); + // Bind the transparency chooser button/command + btnSetTransparency.BindCommand(Model.SelectTransparentColorCommand); // Subscribe to ViewModel events for UI dialogs (these need UI context) Model.SelectSourceFolderRequested += OnSelectSourceFolderRequested; @@ -150,10 +158,54 @@ public partial class MainForm Model.SaveSettingsRequested += OnSaveSettingsRequested; Model.LoadSettingsRequested += OnLoadSettingsRequested; Model.SelectColorRequested += OnSelectColorRequested; + Model.SelectTransparentColorRequested += OnSelectTransparentColorRequested; // Show message requests (from ViewModel validation) Model.ShowMessageRequested += OnShowMessageRequested; } + private void OnSelectTransparentColorRequested(object? sender, EventArgs e) + { + // Ensure UI thread + if (InvokeRequired) + { + Invoke(new Action(OnSelectTransparentColorRequested), sender, e as EventArgs ?? EventArgs.Empty); + return; + } + // Prevent re-entrancy: if the dialog is already open, ignore subsequent requests + if (_transparentDialogOpen) return; + + _transparentDialogOpen = true; + var dlg = new ColorDialog { AllowFullOpen = true }; + try + { + dlg.Color = ColorTranslator.FromHtml(Model.TransparentColor); + } + catch { } + try + { + if (dlg.ShowDialog() == DialogResult.OK) + { + Model.TransparentColor = ColorTranslator.ToHtml(dlg.Color); + PictureBox3.BackColor = dlg.Color; + + // Update preview if logo exists + if (!string.IsNullOrWhiteSpace(Model.LogoFile) && File.Exists(Model.LogoFile)) + { + UpdateLogoPictureBox(Model.LogoFile); + } + } + } + finally + { + _transparentDialogOpen = false; + } + } + + private void BtnSetTransparency_Click(object? sender, EventArgs e) + { + Model.SelectTransparentColorCommand.Execute(null); + } + private void OnShowMessageRequested(object? sender, Tuple args) { if (args is null) return; @@ -202,6 +254,64 @@ public partial class MainForm false, DataSourceUpdateMode.OnPropertyChanged)); Label10.DataBindings.Add(new Binding("Text", bindingSource1, nameof(Model.ProcessingStatus), false, DataSourceUpdateMode.OnPropertyChanged)); + + // Bind transparency model properties to UI + chkUseTransparentColor.DataBindings.Add(new Binding("Checked", bindingSource1, nameof(Model.UseTransparentColor), false, DataSourceUpdateMode.OnPropertyChanged)); + // Show currently selected color in PictureBox3 + PictureBox3.Visible = false; + if (!string.IsNullOrWhiteSpace(Model.TransparentColor)) + { + try + { + PictureBox3.BackColor = ColorTranslator.FromHtml(Model.TransparentColor); + PictureBox3.Visible = true; + } + catch + { + PictureBox3.Visible = false; + } + } + + // When logo file changes, update preview + Model.PropertyChanged += (s, e) => + { + if (e.PropertyName == nameof(Model.LogoFile) || e.PropertyName == nameof(Model.UseTransparentColor) || e.PropertyName == nameof(Model.TransparentColor)) + { + if (!string.IsNullOrWhiteSpace(Model.LogoFile) && System.IO.File.Exists(Model.LogoFile)) + { + UpdateLogoPictureBox(Model.LogoFile); + } + } + }; + + // Bind transparent color hex and show color in PictureBox3 + // Bind UseTransparentColor checkbox (designer control named CheckBox5 used for AddLogo earlier, add new binding control exists in designer) + // Use PictureBox3 to display color value + var colorBinding = new Binding("BackColor", bindingSource1, nameof(Model.TransparentColor), true, DataSourceUpdateMode.OnPropertyChanged); + colorBinding.Format += (s, e) => + { + try + { + e.Value = ColorTranslator.FromHtml(e.Value?.ToString() ?? "#FFFFFF"); + } + catch + { + e.Value = Color.White; + } + }; + PictureBox3.DataBindings.Add(colorBinding); + + // Bind checkbox for using color key transparency if such control exists (CheckBox5 was repurposed as AddLogo); create binding if available + try + { + // The designer has CheckBox5 for 'AddLogo'. We'll add a separate binding to a new control named CheckBoxUseTransparentColor if present. + var chk = this.Controls.Find("chkUseTransparentColor", true).FirstOrDefault() as CheckBox; + if (chk != null) + { + chk.DataBindings.Add(new Binding("Checked", bindingSource1, nameof(Model.UseTransparentColor), false, DataSourceUpdateMode.OnPropertyChanged)); + } + } + catch { } } @@ -212,6 +322,18 @@ public partial class MainForm SetDefaults(); _logger.LogInformation("Programma Avviato"); + // If settings were loaded before the form was shown, ensure the logo preview is updated + try + { + if (!string.IsNullOrWhiteSpace(Model.LogoFile) && File.Exists(Model.LogoFile)) + { + UpdateLogoPictureBox(Model.LogoFile); + } + } + catch (Exception ex) + { + _logger.LogDebug(ex, "Failed to load logo during form load"); + } } private string CalcTime(DateTime timeStart, DateTime timeStop, int numFoto) @@ -436,14 +558,50 @@ public partial class MainForm try { await Model.LoadSettingsFromFileAsync(openDialog.FileName); - + // Explicitly ensure UI is enabled after loading Model.UiEnabled = true; - - // Update logo preview if logo file exists - if (File.Exists(Model.LogoFile)) + + // If a logo path was stored in the settings, try to resolve and display it. + // The stored path may be absolute or relative to the settings file location. + try { - UpdateLogoPictureBox(Model.LogoFile); + var storedLogo = Model.LogoFile; + // Trim whitespace and surrounding quotes which may be present in saved settings + if (!string.IsNullOrWhiteSpace(storedLogo)) + { + storedLogo = storedLogo.Trim(); + storedLogo = storedLogo.Trim('"'); + } + if (!string.IsNullOrWhiteSpace(storedLogo)) + { + string resolved = storedLogo; + // If not rooted, try to resolve relative to the settings file folder + var settingsFolder = Path.GetDirectoryName(openDialog.FileName) ?? string.Empty; + if (!Path.IsPathRooted(resolved) && !string.IsNullOrWhiteSpace(settingsFolder)) + { + var candidate = Path.Combine(settingsFolder, resolved); + if (File.Exists(candidate)) resolved = candidate; + } + + // If rooted but file doesn't exist, try filename near settings file + if (!File.Exists(resolved) && !string.IsNullOrWhiteSpace(settingsFolder)) + { + var candidate2 = Path.Combine(settingsFolder, Path.GetFileName(resolved)); + if (File.Exists(candidate2)) resolved = candidate2; + } + + if (File.Exists(resolved)) + { + // Update the model so data-bound controls reflect the resolved absolute path + Model.LogoFile = resolved; + UpdateLogoPictureBox(resolved); + } + } + } + catch (Exception ex) + { + _logger.LogDebug(ex, "Error resolving logo path after loading settings"); } Text = "Image Catalog - " + Path.GetFileName(openDialog.FileName); @@ -519,17 +677,68 @@ public partial class MainForm { try { - PictureBox1.Image = Image.FromFile(logoPath); - if (PictureBox1.Image.Height >= PictureBox1.Image.Width) + // Load image via System.Drawing for preview so we can use MakeTransparent when requested + using var img = System.Drawing.Image.FromFile(logoPath); + + System.Drawing.Bitmap previewBmp; + // If using color-key transparency and a color is selected, apply MakeTransparent for preview + if (Model.UseTransparentColor && !string.IsNullOrWhiteSpace(Model.TransparentColor)) { - PictureBox1.Height = 160; - PictureBox1.Width = (int)(160 * PictureBox1.Image.Width / (double)PictureBox1.Image.Height); + try + { + var key = ColorTranslator.FromHtml(Model.TransparentColor); + previewBmp = new System.Drawing.Bitmap(img.Width, img.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); + using (var g = System.Drawing.Graphics.FromImage(previewBmp)) + { + g.Clear(System.Drawing.Color.Transparent); + g.DrawImage(img, 0, 0, img.Width, img.Height); + } + // Apply exact color-key transparency + previewBmp.MakeTransparent(key); + PictureBox3.BackColor = key; + PictureBox3.Visible = true; + } + catch + { + previewBmp = new System.Drawing.Bitmap(img); + } } else { - PictureBox1.Width = 160; - PictureBox1.Height = (int)(160 * PictureBox1.Image.Height / (double)PictureBox1.Image.Width); + previewBmp = new System.Drawing.Bitmap(img); } + + // Resize preview to fit into PictureBox1 while preserving aspect ratio + // Resize preview to fit into PictureBox1 while preserving aspect ratio + var boxW = PictureBox1.ClientSize.Width > 0 ? PictureBox1.ClientSize.Width : 449; + var boxH = PictureBox1.ClientSize.Height > 0 ? PictureBox1.ClientSize.Height : 369; + var ratio = Math.Min((double)boxW / previewBmp.Width, (double)boxH / previewBmp.Height); + var destW = Math.Max(1, (int)(previewBmp.Width * ratio)); + var destH = Math.Max(1, (int)(previewBmp.Height * ratio)); + var scaled = new System.Drawing.Bitmap(destW, destH, System.Drawing.Imaging.PixelFormat.Format32bppArgb); + using (var g = System.Drawing.Graphics.FromImage(scaled)) + { + g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; + g.Clear(System.Drawing.Color.Transparent); + // Center the image in the PictureBox + var offsetX = Math.Max(0, (boxW - destW) / 2); + var offsetY = Math.Max(0, (boxH - destH) / 2); + using var canvas = new System.Drawing.Bitmap(boxW, boxH, System.Drawing.Imaging.PixelFormat.Format32bppArgb); + using (var cg = System.Drawing.Graphics.FromImage(canvas)) + { + cg.Clear(System.Drawing.Color.Transparent); + cg.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; + cg.DrawImage(previewBmp, offsetX, offsetY, destW, destH); + } + g.DrawImage(canvas, 0, 0); + } + + // Set PictureBox1 image (dispose previous) + var old = PictureBox1.Image; + PictureBox1.SizeMode = PictureBoxSizeMode.CenterImage; + PictureBox1.Image = scaled; + old?.Dispose(); + previewBmp.Dispose(); } catch { @@ -537,6 +746,39 @@ public partial class MainForm } } + private void UpdateLogoPreviewWithColorKey(string logoPath, Color keyColor) + { + try + { + using var img = (Bitmap)Image.FromFile(logoPath); + // Create ARGB copy + var bmp = new Bitmap(img.Width, img.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); + using (var g = Graphics.FromImage(bmp)) + { + g.DrawImage(img, 0, 0, img.Width, img.Height); + } + + bmp.MakeTransparent(keyColor); + + // Resize to PictureBox1 size similar to previous logic + Bitmap finalBmp; + if (bmp.Height >= bmp.Width) + { + finalBmp = new Bitmap(bmp, new Size((int)(160 * bmp.Width / (double)bmp.Height), 160)); + } + else + { + finalBmp = new Bitmap(bmp, new Size(160, (int)(160 * bmp.Height / (double)bmp.Width))); + } + + PictureBox1.Image = finalBmp; + } + catch + { + // ignore preview failures + } + } + private void setLabel18Text(string text) { if (Label18.InvokeRequired) diff --git a/imagecatalog/MainForm.resx b/imagecatalog/MainForm.resx index a4e857a..fa95561 100644 --- a/imagecatalog/MainForm.resx +++ b/imagecatalog/MainForm.resx @@ -129,4 +129,7 @@ 349, 17 + + 802, 17 + \ No newline at end of file diff --git a/imagecatalog/Models/SettingsDto.cs b/imagecatalog/Models/SettingsDto.cs index 70896e0..e31eb2a 100644 --- a/imagecatalog/Models/SettingsDto.cs +++ b/imagecatalog/Models/SettingsDto.cs @@ -168,6 +168,20 @@ namespace ImageCatalog_2.Models [XmlElement("MarchioAggiungi")] public bool AddLogo { get; set; } + // Color-key transparency settings + [JsonPropertyName("TransparentColor")] + [XmlElement("ColoreTrasparente")] + public string TransparentColor { get; set; } = "#FFFFFF"; + + [JsonPropertyName("UseTransparentColor")] + [XmlElement("UsaColoreTrasparente")] + public bool UseTransparentColor { get; set; } = false; + + // Selected image processing library (e.g., "System.Graphics" or "ImageSharp") + [JsonPropertyName("ImageLibrary")] + [XmlElement("ImageLibrary")] + public string ImageLibrary { get; set; } = "System.Graphics"; + // Options [JsonPropertyName("ForceJpeg")] [XmlElement("GeneraleForzaJpg")] diff --git a/imagecatalog/Services/SettingsService.cs b/imagecatalog/Services/SettingsService.cs index 8a92333..272566f 100644 --- a/imagecatalog/Services/SettingsService.cs +++ b/imagecatalog/Services/SettingsService.cs @@ -85,15 +85,15 @@ namespace ImageCatalog_2.Services } else if (prop.PropertyType == typeof(int)) { - value = _parametriSetup.LeggiParametro(xmlName, (int)(prop.GetValue(loadedDto) ?? 0)); + value = fileParams.LeggiParametro(xmlName, (int)(prop.GetValue(loadedDto) ?? 0)); } else if (prop.PropertyType == typeof(double)) { - value = _parametriSetup.LeggiParametro(xmlName, (double)(prop.GetValue(loadedDto) ?? 0.0)); + value = fileParams.LeggiParametro(xmlName, (double)(prop.GetValue(loadedDto) ?? 0.0)); } else if (prop.PropertyType == typeof(DateTime)) { - var strValue = _parametriSetup.LeggiParametroString(xmlName); + var strValue = fileParams.LeggiParametroString(xmlName); if (DateTime.TryParse(strValue, out var dateValue)) { value = dateValue; From 10cc574acb15f58fc78ddb79cb93cdead03da1f5 Mon Sep 17 00:00:00 2001 From: MaddoScientisto Date: Sun, 15 Feb 2026 11:14:19 +0100 Subject: [PATCH 06/80] Add WPF UI alongside WinForms; improve cancellation logic Introduced MainWindow.xaml and code-behind for a modern WPF interface with tabbed settings. Enabled WPF in project file. Refactored startup to launch WPF or WinForms UI based on availability. Registered WPF MainWindow in DI. Improved DataModel cancellation to be synchronous and log exceptions. Minor logging and comment updates. App now supports both WPF and WinForms frontends. --- imagecatalog/DataModel.cs | 17 +- imagecatalog/ImageCatalog 2.csproj | 1 + imagecatalog/MainWindow.xaml | 244 +++++++++++++++++++++++++++++ imagecatalog/MainWindow.xaml.cs | 193 +++++++++++++++++++++++ imagecatalog/Program.cs | 35 ++++- 5 files changed, 482 insertions(+), 8 deletions(-) create mode 100644 imagecatalog/MainWindow.xaml create mode 100644 imagecatalog/MainWindow.xaml.cs diff --git a/imagecatalog/DataModel.cs b/imagecatalog/DataModel.cs index 6d90981..8091907 100644 --- a/imagecatalog/DataModel.cs +++ b/imagecatalog/DataModel.cs @@ -1132,13 +1132,26 @@ namespace ImageCatalog_2 { try { - await MainToken?.CancelAsync(); + var tokenSource = MainToken; + if (tokenSource is not null) + { + // Cancel synchronously and return to caller. Some CTSource implementations + // may provide async helpers but cancelling is immediate. + try + { + tokenSource.Cancel(); + } + catch (Exception ex) + { + _logger.LogWarning(ex, "Exception while cancelling token"); + } + } UiEnabled = true; } catch (Exception e) { - _logger.LogError(e.Message, "Error canceling the token"); + _logger.LogError(e, "Error canceling the token"); _logger.LogInformation("Ignora questo errore"); } } diff --git a/imagecatalog/ImageCatalog 2.csproj b/imagecatalog/ImageCatalog 2.csproj index e0acb4f..4563b31 100644 --- a/imagecatalog/ImageCatalog 2.csproj +++ b/imagecatalog/ImageCatalog 2.csproj @@ -5,6 +5,7 @@ enable enable true + true False 3.1.2.0 3.1.2.0 diff --git a/imagecatalog/MainWindow.xaml b/imagecatalog/MainWindow.xaml new file mode 100644 index 0000000..b2bd652 --- /dev/null +++ b/imagecatalog/MainWindow.xaml @@ -0,0 +1,244 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -75,8 +100,18 @@ - + @@ -122,7 +157,13 @@ - + + + + + + + @@ -142,7 +183,12 @@ @@ -162,7 +208,13 @@ - + + + + + + + @@ -190,7 +242,13 @@ - + + + + + + + @@ -219,12 +277,23 @@ - + + + + + + + - @@ -250,7 +319,13 @@ - + + + + + + + @@ -266,8 +341,18 @@ - + @@ -280,8 +365,18 @@ - + @@ -301,10 +396,30 @@ - + + + From 9007a27fb256b865331c99badfa73f6f71570c24 Mon Sep 17 00:00:00 2001 From: MaddoScientisto Date: Sat, 21 Feb 2026 16:49:13 +0100 Subject: [PATCH 26/80] Upgrade UI to MahApps.Metro with runtime theming Modernize WPF UI using MahApps.Metro: switch MainWindow to MetroWindow, add MetroTabControl/MetroTabItem, custom tab styles, and icon-based theme toggle. Move version display to window commands. Integrate MahApps resource dictionaries and ThemeManager for runtime theme switching. Update startup logic for proper theming. WinForms fallback retained. --- imagecatalog/ImageCatalog 2.csproj | 1 + imagecatalog/MainWindow.xaml | 134 ++++++++++++++++++++--------- imagecatalog/MainWindow.xaml.cs | 83 +++++++++++++++++- imagecatalog/Program.cs | 43 +++++++-- 4 files changed, 207 insertions(+), 54 deletions(-) diff --git a/imagecatalog/ImageCatalog 2.csproj b/imagecatalog/ImageCatalog 2.csproj index e4573cc..cbd865d 100644 --- a/imagecatalog/ImageCatalog 2.csproj +++ b/imagecatalog/ImageCatalog 2.csproj @@ -42,6 +42,7 @@ + diff --git a/imagecatalog/MainWindow.xaml b/imagecatalog/MainWindow.xaml index d8fec54..b423b4c 100644 --- a/imagecatalog/MainWindow.xaml +++ b/imagecatalog/MainWindow.xaml @@ -1,15 +1,18 @@ - - + Title="Image Catalog - WPF" Height="540" Width="800" + Background="{DynamicResource WindowBackgroundBrush}" Foreground="{DynamicResource ControlForegroundBrush}" + GlowBrush="{DynamicResource AccentBrush}"> + + @@ -38,8 +41,49 @@ + + + - + + + + + + + + @@ -54,14 +98,14 @@ - - - + + + - + @@ -155,15 +199,15 @@ - + - - + + - + @@ -206,15 +250,15 @@ - + - - + + - + @@ -240,15 +284,15 @@ - + - - + + - + @@ -275,15 +319,15 @@ - + - - + + - + @@ -317,15 +361,15 @@ - + - - + + - + @@ -388,14 +432,22 @@ - - + + - - - - + + + + + + + + + + + + @@ -248,6 +243,17 @@ + + + + + + + + + + + @@ -271,8 +277,6 @@ - - @@ -296,6 +300,7 @@ + @@ -353,6 +358,12 @@ + From d068b4b3e183d1fa38bddd611b0a28195d4da600 Mon Sep 17 00:00:00 2001 From: MaddoScientisto Date: Sat, 21 Feb 2026 17:27:16 +0100 Subject: [PATCH 28/80] Support UI selection via --wpf command-line argument Refactored Program.cs to accept command-line arguments and select between WinForms (default) and WPF UI based on the presence of --wpf. Removed old commented-out UI selection code. Updated launchSettings.json to provide separate profiles for WinForms and WPF launches. If WPF is requested but unavailable, the app falls back to WinForms. --- imagecatalog/Program.cs | 40 ++++++++++----------- imagecatalog/Properties/launchSettings.json | 11 ++++-- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/imagecatalog/Program.cs b/imagecatalog/Program.cs index b32c760..ba559a4 100644 --- a/imagecatalog/Program.cs +++ b/imagecatalog/Program.cs @@ -57,7 +57,7 @@ static class Program public static IServiceProvider ServiceProvider { get; private set; } [STAThread] - static void Main() + static void Main(string[] args) { Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); @@ -74,21 +74,14 @@ static class Program // Resolve WPF MainWindow when available, otherwise fall back to WinForms MainForm var serviceProvider = ServiceProvider; - // NOTE: By default the app will attempt to run the WPF window when available and fall back - // to the WinForms MainForm. If you want to force the WinForms UI for testing, uncomment - // the block below and comment out the WPF branch. - // ----------------------------------------------------------------------------- - // // Force WinForms UI (uncomment to enable) - //var mainForm = serviceProvider.GetRequiredService(); - //// If you want to set the DataModel explicitly on the WinForms form use the lines below - //// var mainViewModel = serviceProvider.GetRequiredService(); - //// mainForm.Model = mainViewModel; - //Application.Run(mainForm); - // ----------------------------------------------------------------------------- + // Determine UI based on command line. Default: WinForms. Use --wpf to explicitly request WPF. + bool useWpf = args is not null && Array.Exists(args, a => string.Equals(a, "--wpf", StringComparison.OrdinalIgnoreCase)); - // Create the WPF Application and merge MahApps resources BEFORE constructing the MainWindow - // so InitializeComponent sees the theme resources on first render. - var wpfApp = new System.Windows.Application(); + if (useWpf) + { + // Create the WPF Application and merge MahApps resources BEFORE constructing the MainWindow + // so InitializeComponent sees the theme resources on first render. + var wpfApp = new System.Windows.Application(); try { wpfApp.Resources.MergedDictionaries.Add(new System.Windows.ResourceDictionary { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml") }); @@ -111,15 +104,18 @@ static class Program // If resources fail to load (package not present at runtime), continue silently } - // Now resolve the WPF MainWindow so its constructor runs with the application resources available - var wpfMain = serviceProvider.GetService(typeof(ImageCatalog_2.MainWindow)) as ImageCatalog_2.MainWindow; - if (wpfMain is not null) - { - wpfApp.Run(wpfMain); - return; + // Now resolve the WPF MainWindow so its constructor runs with the application resources available + var wpfMain = serviceProvider.GetService(typeof(ImageCatalog_2.MainWindow)) as ImageCatalog_2.MainWindow; + if (wpfMain is not null) + { + wpfApp.Run(wpfMain); + return; + } + + // If WPF was requested but not available, fall back to WinForms. } - // Fallback to WinForms UI + // Default / fallback to WinForms UI var mainForm = serviceProvider.GetRequiredService(); System.Windows.Forms.Application.Run(mainForm); } diff --git a/imagecatalog/Properties/launchSettings.json b/imagecatalog/Properties/launchSettings.json index 641af8b..12da6a8 100644 --- a/imagecatalog/Properties/launchSettings.json +++ b/imagecatalog/Properties/launchSettings.json @@ -1,7 +1,12 @@ { "profiles": { - "Profile 1": { - "commandName": "Project" + "ImageCatalog (WinForms)": { + "commandName": "Project", + "commandLineArgs": "" + }, + "ImageCatalog (WPF)": { + "commandName": "Project", + "commandLineArgs": "--wpf" } } -} \ No newline at end of file +} From 900e8b6bf866f77cad8806d3df5260b3b6c15d4c Mon Sep 17 00:00:00 2001 From: MaddoScientisto Date: Sat, 21 Feb 2026 19:03:02 +0100 Subject: [PATCH 29/80] Update CI configuration and assembly information; remove log file and add logo image --- .gitlab-ci.yml | 12 ++- MaddoLibrary | 1 - MaddoShared/Properties/AssemblyInfo.cs | 6 +- imagecatalog/AssemblyInfo.cs | 4 +- imagecatalog/Logo.png | Bin 0 -> 317 bytes log.txt | 135 ------------------------- 6 files changed, 12 insertions(+), 146 deletions(-) delete mode 160000 MaddoLibrary create mode 100644 imagecatalog/Logo.png delete mode 100644 log.txt diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a7ae755..fee2f0b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -88,7 +88,7 @@ build_windows: } artifacts: paths: - - "**/bin/$BUILD_CONFIG/net10.0-windows/**" + - "imagecatalog/bin/$BUILD_CONFIG/net10.0-windows/**" expire_in: 1 hour # Publish and create GitLab Release when building a tag. This job expects a Windows runner with PowerShell and curl available. @@ -112,7 +112,7 @@ publish_release: $dotnetExe = 'dotnet' } - & $dotnetExe publish "imagecatalog\ImageCatalog 2.csproj" -c $env:BUILD_CONFIG -r win-x64 --self-contained false -o publish + & $dotnetExe publish "imagecatalog\ImageCatalog 2.csproj" -c $env:BUILD_CONFIG -f net10.0-windows -r win-x64 --self-contained false /p:PublishSingleFile=true /p:PublishReadyToRun=true -o publish Write-Host "Published to $(pwd)\\publish" # Configure private NuGet source from GitLab Packages using CI_JOB_TOKEN @@ -130,8 +130,10 @@ publish_release: Write-Host 'No credentials available; skipping private NuGet source configuration.' } - # Find first file in publish folder - $file = Get-ChildItem -Path publish -File | Select-Object -First 1; Write-Host "Uploading $($file.FullName)" + # Find the produced EXE in publish folder (fallback to first file if no exe found) + $file = Get-ChildItem -Path publish -Filter *.exe -File | Select-Object -First 1 + if (-not $file) { $file = Get-ChildItem -Path publish -File | Select-Object -First 1 } + Write-Host "Uploading $($file.FullName)" # Upload to GitLab project uploads API to get a public URL for the artifact $uploadUrl = "$env:CI_API_V4_URL/projects/$env:CI_PROJECT_ID/uploads" $formData = "file=@$($file.FullName)" @@ -145,7 +147,7 @@ publish_release: } artifacts: paths: - - publish/* + - publish/*.exe expire_in: 1 day only: - tags diff --git a/MaddoLibrary b/MaddoLibrary deleted file mode 160000 index 5987cc2..0000000 --- a/MaddoLibrary +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5987cc26521d839bf81bdaab19d101488294da19 diff --git a/MaddoShared/Properties/AssemblyInfo.cs b/MaddoShared/Properties/AssemblyInfo.cs index 52a601e..6af8d79 100644 --- a/MaddoShared/Properties/AssemblyInfo.cs +++ b/MaddoShared/Properties/AssemblyInfo.cs @@ -8,10 +8,10 @@ using System.Runtime.InteropServices; [assembly: AssemblyTitle("MaddoShared")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] +[assembly: AssemblyCompany("Maddo")] [assembly: AssemblyProduct("MaddoShared")] -[assembly: AssemblyCopyright("Copyright © 2021")] -[assembly: AssemblyTrademark("")] +[assembly: AssemblyCopyright("Copyright © 2021-2026")] +[assembly: AssemblyTrademark("Maddo")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible diff --git a/imagecatalog/AssemblyInfo.cs b/imagecatalog/AssemblyInfo.cs index 4767298..e5b467a 100644 --- a/imagecatalog/AssemblyInfo.cs +++ b/imagecatalog/AssemblyInfo.cs @@ -11,8 +11,8 @@ using System.Runtime.InteropServices; [assembly: AssemblyDescription("")] -[assembly: AssemblyCopyright("(C) 2002-08")] -[assembly: AssemblyTrademark("")] +[assembly: AssemblyCopyright("(C) 2012-2026")] +[assembly: AssemblyTrademark("Maddo")] [assembly: CLSCompliant(true)] // The following GUID is for the ID of the typelib if this project is exposed to COM diff --git a/imagecatalog/Logo.png b/imagecatalog/Logo.png new file mode 100644 index 0000000000000000000000000000000000000000..849b093e8a89ad92d3546ec2edc2dbc6299bbd0b GIT binary patch literal 317 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|zI(bjhFJ6_ zryO9qal_(YvT%E2{Qf$FLpOAGh@3pTr!DkP;4ZPe$v1&=j}L2oe*f3KT(*t-!_7Z$ z%b40MxX+~3_#H{r=;H3!IP>+fc%DkNIc~|uIj1ApfS~Pvxa>o{Ht7$Ih7Av67YiR| zKgPf|ZSQ%Bd!|;2H~v(vGdO(y^Ryqa2go+uS}R)TGVSKi!Pg#doDB>D22WQ% Jmvv4FO#tBnf_ne} literal 0 HcmV?d00001 diff --git a/log.txt b/log.txt deleted file mode 100644 index aa7e6df..0000000 --- a/log.txt +++ /dev/null @@ -1,135 +0,0 @@ -2021-03-06 10:04:44.068 +01:00 [INF] MSBuild registered from C:\Program Files\dotnet\sdk\5.0.200\ -2021-03-06 10:04:44.120 +01:00 [INF] Registered 1 extensions: - Default extension -2021-03-06 10:04:50.740 +01:00 [INF] Initializing upgrade step Select an entrypoint -2021-03-06 10:05:37.931 +01:00 [INF] Applying upgrade step Select an entrypoint -2021-03-06 10:05:56.095 +01:00 [INF] Upgrade step Select an entrypoint applied successfully -2021-03-06 10:05:59.578 +01:00 [INF] Initializing upgrade step Select project to upgrade -2021-03-06 10:06:53.914 +01:00 [INF] Applying upgrade step Select project to upgrade -2021-03-06 10:07:00.961 +01:00 [INF] Upgrade step Select project to upgrade applied successfully -2021-03-06 10:07:03.582 +01:00 [INF] Initializing upgrade step Back up project -2021-03-06 10:07:22.200 +01:00 [INF] Applying upgrade step Back up project -2021-03-06 10:07:26.114 +01:00 [INF] Backing up H:\dev\vs\Catalog\MaddoShared to H:\dev\vs\Catalog\MaddoShared.backup -2021-03-06 10:07:31.549 +01:00 [INF] Project backed up to H:\dev\vs\Catalog\MaddoShared.backup -2021-03-06 10:07:31.550 +01:00 [INF] Upgrade step Back up project applied successfully -2021-03-06 10:07:40.695 +01:00 [INF] Initializing upgrade step Convert project file to SDK style -2021-03-06 10:07:40.696 +01:00 [FTL] Try-Convert not found. This tool depends on the Try-Convert CLI tool. Please ensure that Try-Convert is installed and that the correct location for the tool is specified (in configuration, for example). https://github.com/dotnet/try-convert -2021-03-06 10:09:23.887 +01:00 [INF] Applying upgrade step Convert project file to SDK style -2021-03-06 10:09:23.889 +01:00 [INF] Converting project file format with try-convert -2021-03-06 10:09:27.336 +01:00 [INF] [try-convert] Conversion complete! -2021-03-06 10:09:27.915 +01:00 [INF] Project file converted successfully! The project may require additional changes to build successfully against the new .NET target. -2021-03-06 10:09:30.087 +01:00 [INF] Upgrade step Convert project file to SDK style applied successfully -2021-03-06 10:09:36.050 +01:00 [INF] Initializing upgrade step Update TFM -2021-03-06 10:09:48.944 +01:00 [INF] Applying upgrade step Update TFM -2021-03-06 10:09:54.879 +01:00 [INF] Upgrade step Update TFM applied successfully -2021-03-06 10:10:10.865 +01:00 [INF] Initializing upgrade step Update NuGet packages -2021-03-06 10:10:12.295 +01:00 [INF] Marking package System.Reflection.Metadata for removal because it appears to be a transitive dependency -2021-03-06 10:10:13.789 +01:00 [INF] Reference to .NET Upgrade Assistant analyzer package (Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers, version 0.2.212405) needs added -2021-03-06 10:10:15.101 +01:00 [INF] Adding Microsoft.Windows.Compatibility 5.0.2 -2021-03-06 10:10:15.104 +01:00 [INF] Packages to be removed: -System.Reflection.Metadata, Version=5.0.0 -2021-03-06 10:10:15.105 +01:00 [INF] Packages to be addded: -Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers, Version=0.2.212405 -Microsoft.Windows.Compatibility, Version=5.0.2 -2021-03-06 10:10:18.926 +01:00 [INF] Applying upgrade step Update NuGet packages -2021-03-06 10:10:18.932 +01:00 [INF] Removing outdated package reference: System.Reflection.Metadata, Version=5.0.0 -2021-03-06 10:10:18.935 +01:00 [INF] Adding package reference: Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers, Version=0.2.212405 -2021-03-06 10:10:18.937 +01:00 [INF] Adding package reference: Microsoft.Windows.Compatibility, Version=5.0.2 -2021-03-06 10:10:24.287 +01:00 [INF] Marking package System.Data.DataSetExtensions for removal because it appears to be a transitive dependency -2021-03-06 10:10:24.292 +01:00 [INF] Marking package System.Numerics.Vectors for removal because it appears to be a transitive dependency -2021-03-06 10:10:24.706 +01:00 [INF] Removing outdated package reference: System.Data.DataSetExtensions, Version=4.5.0 -2021-03-06 10:10:24.707 +01:00 [INF] Removing outdated package reference: System.Numerics.Vectors, Version=4.5.0 -2021-03-06 10:10:27.413 +01:00 [INF] Upgrade step Update NuGet packages applied successfully -2021-03-06 10:10:36.907 +01:00 [INF] Initializing upgrade step Add template files -2021-03-06 10:10:36.924 +01:00 [INF] 0 expected template items needed -2021-03-06 10:10:36.926 +01:00 [INF] Initializing upgrade step Upgrade app config files -2021-03-06 10:10:36.944 +01:00 [INF] Found 0 app settings for upgrade: -2021-03-06 10:10:36.950 +01:00 [INF] 0 web page namespace imports need upgraded: -2021-03-06 10:10:36.951 +01:00 [INF] Initializing upgrade step Update C# source -2021-03-06 10:10:38.659 +01:00 [INF] Initializing upgrade step Move to next project -2021-03-06 10:10:43.824 +01:00 [INF] Applying upgrade step Move to next project -2021-03-06 10:10:43.825 +01:00 [INF] Upgrade step Move to next project applied successfully -2021-03-06 10:11:07.545 +01:00 [INF] Initializing upgrade step Select project to upgrade -2021-03-06 10:11:10.510 +01:00 [INF] Applying upgrade step Select project to upgrade -2021-03-06 10:11:14.382 +01:00 [INF] Upgrade step Select project to upgrade applied successfully -2021-03-06 10:11:17.877 +01:00 [INF] Initializing upgrade step Back up project -2021-03-06 10:11:21.030 +01:00 [INF] Applying upgrade step Back up project -2021-03-06 10:11:22.810 +01:00 [INF] Backing up H:\dev\vs\Catalog\imagecatalog to H:\dev\vs\Catalog\imagecatalog.backup -2021-03-06 10:11:37.349 +01:00 [INF] Project backed up to H:\dev\vs\Catalog\imagecatalog.backup -2021-03-06 10:11:37.350 +01:00 [INF] Upgrade step Back up project applied successfully -2021-03-06 10:11:47.584 +01:00 [INF] Initializing upgrade step Convert project file to SDK style -2021-03-06 10:11:49.609 +01:00 [INF] Applying upgrade step Convert project file to SDK style -2021-03-06 10:11:49.610 +01:00 [INF] Converting project file format with try-convert -2021-03-06 10:11:52.238 +01:00 [INF] [try-convert] Conversion complete! -2021-03-06 10:11:52.666 +01:00 [INF] Project file converted successfully! The project may require additional changes to build successfully against the new .NET target. -2021-03-06 10:11:55.581 +01:00 [INF] Upgrade step Convert project file to SDK style applied successfully -2021-03-06 10:12:00.489 +01:00 [INF] Initializing upgrade step Update TFM -2021-03-06 10:12:03.093 +01:00 [INF] Applying upgrade step Update TFM -2021-03-06 10:12:06.038 +01:00 [INF] Upgrade step Update TFM applied successfully -2021-03-06 10:12:10.906 +01:00 [INF] Initializing upgrade step Update NuGet packages -2021-03-06 10:12:12.592 +01:00 [INF] Marking package Ben.Demystifier for removal because it appears to be a transitive dependency -2021-03-06 10:12:12.607 +01:00 [INF] Marking package System.Buffers for removal because it appears to be a transitive dependency -2021-03-06 10:12:12.624 +01:00 [INF] Marking package System.Collections.Immutable for removal because it appears to be a transitive dependency -2021-03-06 10:12:12.628 +01:00 [INF] Marking package System.Memory for removal because it appears to be a transitive dependency -2021-03-06 10:12:12.630 +01:00 [INF] Marking package System.Numerics.Vectors for removal because it appears to be a transitive dependency -2021-03-06 10:12:12.633 +01:00 [INF] Marking package System.Reflection.Metadata for removal because it appears to be a transitive dependency -2021-03-06 10:12:12.637 +01:00 [INF] Marking package System.Runtime.CompilerServices.Unsafe for removal because it appears to be a transitive dependency -2021-03-06 10:12:12.640 +01:00 [INF] Marking package System.Threading.Tasks.Extensions for removal because it appears to be a transitive dependency -2021-03-06 10:12:14.097 +01:00 [INF] Reference to .NET Upgrade Assistant analyzer package (Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers, version 0.2.212405) needs added -2021-03-06 10:12:14.104 +01:00 [INF] Packages to be removed: -Ben.Demystifier, Version=0.3.0 -System.Buffers, Version=4.5.1 -System.Collections.Immutable, Version=5.0.0 -System.Memory, Version=4.5.4 -System.Numerics.Vectors, Version=4.5.0 -System.Reflection.Metadata, Version=5.0.0 -System.Runtime.CompilerServices.Unsafe, Version=5.0.0 -System.Threading.Tasks.Extensions, Version=4.5.4 -2021-03-06 10:12:14.104 +01:00 [INF] Packages to be addded: -Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers, Version=0.2.212405 -2021-03-06 10:12:16.572 +01:00 [INF] Applying upgrade step Update NuGet packages -2021-03-06 10:12:16.573 +01:00 [INF] Removing outdated package reference: Ben.Demystifier, Version=0.3.0 -2021-03-06 10:12:16.573 +01:00 [INF] Removing outdated package reference: System.Buffers, Version=4.5.1 -2021-03-06 10:12:16.574 +01:00 [INF] Removing outdated package reference: System.Collections.Immutable, Version=5.0.0 -2021-03-06 10:12:16.575 +01:00 [INF] Removing outdated package reference: System.Memory, Version=4.5.4 -2021-03-06 10:12:16.576 +01:00 [INF] Removing outdated package reference: System.Numerics.Vectors, Version=4.5.0 -2021-03-06 10:12:16.578 +01:00 [INF] Removing outdated package reference: System.Reflection.Metadata, Version=5.0.0 -2021-03-06 10:12:16.578 +01:00 [INF] Removing outdated package reference: System.Runtime.CompilerServices.Unsafe, Version=5.0.0 -2021-03-06 10:12:16.580 +01:00 [INF] Removing outdated package reference: System.Threading.Tasks.Extensions, Version=4.5.4 -2021-03-06 10:12:16.581 +01:00 [INF] Adding package reference: Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers, Version=0.2.212405 -2021-03-06 10:12:19.366 +01:00 [INF] Upgrade step Update NuGet packages applied successfully -2021-03-06 10:12:35.849 +01:00 [INF] Initializing upgrade step Add template files -2021-03-06 10:12:35.850 +01:00 [INF] 0 expected template items needed -2021-03-06 10:12:35.851 +01:00 [INF] Initializing upgrade step Upgrade app config files -2021-03-06 10:12:35.852 +01:00 [INF] Found 0 app settings for upgrade: -2021-03-06 10:12:35.853 +01:00 [INF] system.diagnostics is not supported in .NET 5. See https://github.com/dotnet/runtime/issues/23937 for details. For now, it will be disabled. -2021-03-06 10:12:35.854 +01:00 [INF] 0 web page namespace imports need upgraded: -2021-03-06 10:12:40.725 +01:00 [INF] Applying upgrade step Disable unsupported configuration sections -2021-03-06 10:12:40.727 +01:00 [INF] system.diagnostics is not supported in .NET 5. See https://github.com/dotnet/runtime/issues/23937 for details. For now, it will be disabled. -2021-03-06 10:12:40.730 +01:00 [INF] Configuration file H:\dev\vs\Catalog\imagecatalog\app.config has been updated -2021-03-06 10:12:40.737 +01:00 [INF] Upgrade step Disable unsupported configuration sections applied successfully -2021-03-06 10:12:40.739 +01:00 [INF] Applying upgrade step Upgrade app config files -2021-03-06 10:12:40.740 +01:00 [INF] Upgrade step Upgrade app config files applied successfully -2021-03-06 10:12:43.598 +01:00 [INF] Initializing upgrade step Update C# source -2021-03-06 10:12:44.173 +01:00 [INF] Initializing upgrade step Move to next project -2021-03-06 10:12:47.488 +01:00 [INF] Applying upgrade step Move to next project -2021-03-06 10:12:47.489 +01:00 [INF] Upgrade step Move to next project applied successfully -2021-03-06 10:12:48.833 +01:00 [INF] Initializing upgrade step Select project to upgrade -2021-03-06 10:12:50.361 +01:00 [INF] Applying upgrade step Select project to upgrade -2021-03-06 10:12:54.374 +01:00 [ERR] Unknown selection: '' -2021-03-06 10:13:02.205 +01:00 [ERR] Unknown selection: '' -2021-03-06 10:13:04.059 +01:00 [ERR] Unknown selection: 'exit' -2021-03-06 10:13:06.542 +01:00 [ERR] Unknown selection: '0' -2021-03-06 10:13:08.242 +01:00 [INF] Saving upgrade progress file at H:\dev\vs\Catalog\.upgrade-assistant -2021-03-06 10:13:13.625 +01:00 [INF] MSBuild registered from C:\Program Files\dotnet\sdk\5.0.200\ -2021-03-06 10:13:13.651 +01:00 [INF] Registered 1 extensions: - Default extension -2021-03-06 10:13:15.795 +01:00 [INF] Loading upgrade progress file at H:\dev\vs\Catalog\.upgrade-assistant -2021-03-06 10:13:17.819 +01:00 [INF] Initializing upgrade step Select project to upgrade -2021-03-06 10:13:29.438 +01:00 [INF] Skipping upgrade step Select project to upgrade -2021-03-06 10:13:29.440 +01:00 [INF] Upgrade step Select project to upgrade skipped -2021-03-06 10:13:31.325 +01:00 [INF] Initializing upgrade step Finalize Solution -2021-03-06 10:13:34.820 +01:00 [INF] Applying upgrade step Finalize Solution -2021-03-06 10:13:34.821 +01:00 [INF] Upgrade step Finalize Solution applied successfully -2021-03-06 10:13:36.563 +01:00 [INF] Upgrade has completed. Please review any changes. -2021-03-06 10:13:36.565 +01:00 [INF] Saving upgrade progress file at H:\dev\vs\Catalog\.upgrade-assistant From f8d4687a9741db7a0c62b8500a50d3d5abc7d7af Mon Sep 17 00:00:00 2001 From: MaddoScientisto Date: Sat, 21 Feb 2026 20:01:31 +0100 Subject: [PATCH 30/80] Refactor CI pipeline for GitLab: streamline publish_release job and improve artifact handling --- .gitlab-ci.yml | 91 ++++++++++++++++++++------------------------------ 1 file changed, 36 insertions(+), 55 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fee2f0b..452d9da 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -91,66 +91,47 @@ build_windows: - "imagecatalog/bin/$BUILD_CONFIG/net10.0-windows/**" expire_in: 1 hour -# Publish and create GitLab Release when building a tag. This job expects a Windows runner with PowerShell and curl available. +# Publish and create GitLab Release when building a tag. publish_release: stage: publish - tags: - - saas-windows-medium-amd64 + image: mcr.microsoft.com/dotnet/sdk:10.0 needs: - - build_windows - script: - - | - powershell -NoProfile -Command { - # Ensure .NET 10 SDK is available (install to user folder if missing) and use that dotnet for publish - $needsInstall = -not (dotnet --list-sdks 2>$null | Select-String '^10\.') - if ($needsInstall) { - Write-Host 'Installing .NET 10 SDK using dotnet-install.ps1' - Invoke-WebRequest 'https://dot.net/v1/dotnet-install.ps1' -OutFile dotnet-install.ps1 -UseBasicParsing - .\dotnet-install.ps1 -Channel 10.0 -InstallDir $env:USERPROFILE\.dotnet - $dotnetExe = Join-Path $env:USERPROFILE '.dotnet\dotnet.exe' - } else { - $dotnetExe = 'dotnet' - } - - & $dotnetExe publish "imagecatalog\ImageCatalog 2.csproj" -c $env:BUILD_CONFIG -f net10.0-windows -r win-x64 --self-contained false /p:PublishSingleFile=true /p:PublishReadyToRun=true -o publish - Write-Host "Published to $(pwd)\\publish" - - # Configure private NuGet source from GitLab Packages using CI_JOB_TOKEN - # Fallback to repository variables NUGET_USERNAME/NUGET_PASSWORD for shared runners - $nugetUrl = 'https://gitlab.com/api/v4/projects/79509532/packages/nuget/index.json' - if ($env:CI_JOB_TOKEN) { - Write-Host 'Configuring private NuGet source Nuget-GitLab-AIFotoONLUS using CI_JOB_TOKEN...' - try { & $dotnetExe nuget remove source Nuget-GitLab-AIFotoONLUS } catch {} - & $dotnetExe nuget add source $nugetUrl --name Nuget-GitLab-AIFotoONLUS --username gitlab-ci-token --password $env:CI_JOB_TOKEN --store-password-in-clear-text - } elseif ($env:NUGET_USERNAME -and $env:NUGET_PASSWORD) { - Write-Host 'Configuring private NuGet source Nuget-GitLab-AIFotoONLUS using NUGET_USERNAME/NUGET_PASSWORD...' - try { & $dotnetExe nuget remove source Nuget-GitLab-AIFotoONLUS } catch {} - & $dotnetExe nuget add source $nugetUrl --name Nuget-GitLab-AIFotoONLUS --username $env:NUGET_USERNAME --password $env:NUGET_PASSWORD --store-password-in-clear-text - } else { - Write-Host 'No credentials available; skipping private NuGet source configuration.' - } - - # Find the produced EXE in publish folder (fallback to first file if no exe found) - $file = Get-ChildItem -Path publish -Filter *.exe -File | Select-Object -First 1 - if (-not $file) { $file = Get-ChildItem -Path publish -File | Select-Object -First 1 } - Write-Host "Uploading $($file.FullName)" - # Upload to GitLab project uploads API to get a public URL for the artifact - $uploadUrl = "$env:CI_API_V4_URL/projects/$env:CI_PROJECT_ID/uploads" - $formData = "file=@$($file.FullName)" - $uploadResp = curl --silent --show-error --header "JOB-TOKEN:$env:CI_JOB_TOKEN" --form $formData $uploadUrl - $uploadJson = $uploadResp | ConvertFrom-Json - $assetUrl = "$env:CI_SERVER_URL$($uploadJson.url)" - Write-Host "Uploaded asset url: $assetUrl" - # Create the release using uploads URL - $body = @{ name = $env:CI_COMMIT_TAG; tag_name = $env:CI_COMMIT_TAG; description = "Automated release from CI"; assets = @{ links = @(@{ name = "$($file.Name)"; url = $assetUrl }) } } | ConvertTo-Json -Depth 10 - Invoke-RestMethod -Method Post -Uri "$env:CI_API_V4_URL/projects/$env:CI_PROJECT_ID/releases" -Headers @{ "JOB-TOKEN" = $env:CI_JOB_TOKEN } -Body $body -ContentType "application/json" - } + - job: build_windows + artifacts: true + script: | + set -euo pipefail + dotnet --info + echo "Reading MinVer version from build artifacts" + # locate a minversion file produced by the build artifacts + minfile=$(find imagecatalog -type f -iname 'minversion' -print | head -n1 || true) + if [ -z "$minfile" ]; then minfile=$(find . -type f -iname 'minversion' -print | head -n1 || true); fi + if [ -z "$minfile" ]; then echo "No minversion file found in artifacts"; exit 1; fi + echo "Found minversion file: $minfile" + version=$(cat "$minfile" | tr -d '\r\n') + if [ -z "$version" ]; then echo "minversion was empty"; exit 1; fi + echo "Using version: $version" + # find the primary artifact to upload (prefer the executable or first file under the build output) + file=$(find imagecatalog/bin -type f \! -iname 'minversion' -print | head -n1 || true) + if [ -z "$file" ]; then file=$(find . -type f -name 'ImageCatalog.*' -print | head -n1 || true); fi + if [ -z "$file" ]; then echo "No artifact file found to attach"; exit 1; fi + echo "Uploading artifact: $file" + uploadResp=$(curl --silent --show-error --header "JOB-TOKEN:$CI_JOB_TOKEN" --form "file=@$file" "$CI_API_V4_URL/projects/$CI_PROJECT_ID/uploads") + assetPath=$(echo "$uploadResp" | sed -n 's/.*"url":"\([^\"]*\)".*/\1/p') + if [ -z "$assetPath" ]; then echo "Upload failed: $uploadResp"; exit 1; fi + assetUrl="$CI_SERVER_URL$assetPath" + echo "Uploaded asset url: $assetUrl" + basename=$(basename "$file") + # create release JSON using the exact minversion value as tag_name + cat > release.json < Date: Sat, 21 Feb 2026 20:11:46 +0100 Subject: [PATCH 31/80] Removed tags only from publish job --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 452d9da..e0ccef7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -129,8 +129,8 @@ publish_release: curl --silent --show-error --header "JOB-TOKEN:$CI_JOB_TOKEN" -X POST -H "Content-Type: application/json" --data @release.json "$CI_API_V4_URL/projects/$CI_PROJECT_ID/releases" artifacts: expire_in: 1 day - only: - - tags +# only: +# - tags # Notes for runner setup: The job now runs on the public .NET SDK image and downloads artifacts from the # `build_windows` job via `needs`. It reads the `minversion` file produced by the build artifacts and From 335da52abfd73567a9daed2bb967963e270667ca Mon Sep 17 00:00:00 2001 From: MaddoScientisto Date: Sun, 22 Feb 2026 00:57:23 +0100 Subject: [PATCH 32/80] Add minversion file generation to build output for downstream jobs --- .gitlab-ci.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e0ccef7..f13eb57 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -85,6 +85,23 @@ build_windows: } & $dotnetExe restore & $dotnetExe build "imagecatalog\ImageCatalog 2.csproj" -c $env:BUILD_CONFIG -v minimal + # Write a minversion file into the build output so downstream jobs can read the computed version. + try { + $outRoot = Join-Path -Path "imagecatalog\bin\$env:BUILD_CONFIG" -ChildPath '*' + # search under the build output for a file starting with ImageCatalog. + $built = Get-ChildItem -Path (Join-Path "imagecatalog\bin\$env:BUILD_CONFIG" '.') -Recurse -File -ErrorAction SilentlyContinue | Where-Object { $_.Name -like 'ImageCatalog.*' } | Select-Object -First 1 + if ($built) { + $base = [System.IO.Path]::GetFileNameWithoutExtension($built.Name) + $version = $base -replace '^ImageCatalog\.', '' + $minPath = Join-Path $built.DirectoryName 'minversion' + Write-Host "Writing minversion '$version' to $minPath" + Set-Content -Path $minPath -Value $version -Encoding UTF8 + } else { + Write-Host 'No ImageCatalog build artifact found to derive minversion from.' + } + } catch { + Write-Host "Failed to write minversion: $_" + } } artifacts: paths: From 3a964bbbcf09cf6902dc2f3e242bcf88a3a9ceaf Mon Sep 17 00:00:00 2001 From: MaddoScientisto Date: Sun, 22 Feb 2026 11:38:15 +0100 Subject: [PATCH 33/80] Refactor CI pipeline: replace minversion file generation with single-file publish for downstream jobs --- .gitlab-ci.yml | 48 ++++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f13eb57..f257f27 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -85,52 +85,45 @@ build_windows: } & $dotnetExe restore & $dotnetExe build "imagecatalog\ImageCatalog 2.csproj" -c $env:BUILD_CONFIG -v minimal - # Write a minversion file into the build output so downstream jobs can read the computed version. + # Produce a single-file, ready-to-run publish so downstream jobs only need the EXE. try { - $outRoot = Join-Path -Path "imagecatalog\bin\$env:BUILD_CONFIG" -ChildPath '*' - # search under the build output for a file starting with ImageCatalog. - $built = Get-ChildItem -Path (Join-Path "imagecatalog\bin\$env:BUILD_CONFIG" '.') -Recurse -File -ErrorAction SilentlyContinue | Where-Object { $_.Name -like 'ImageCatalog.*' } | Select-Object -First 1 - if ($built) { - $base = [System.IO.Path]::GetFileNameWithoutExtension($built.Name) - $version = $base -replace '^ImageCatalog\.', '' - $minPath = Join-Path $built.DirectoryName 'minversion' - Write-Host "Writing minversion '$version' to $minPath" - Set-Content -Path $minPath -Value $version -Encoding UTF8 - } else { - Write-Host 'No ImageCatalog build artifact found to derive minversion from.' - } + & $dotnetExe publish "imagecatalog\ImageCatalog 2.csproj" -c $env:BUILD_CONFIG -r win-x64 --self-contained true -p:PublishSingleFile=true -p:PublishTrimmed=true -p:PublishReadyToRun=true -o "imagecatalog\bin\$env:BUILD_CONFIG\net10.0-windows\publish" -v minimal } catch { - Write-Host "Failed to write minversion: $_" + Write-Host "dotnet publish failed: $_" + throw } } artifacts: paths: - - "imagecatalog/bin/$BUILD_CONFIG/net10.0-windows/**" + - "imagecatalog/bin/$BUILD_CONFIG/net10.0-windows/publish/**" expire_in: 1 hour # Publish and create GitLab Release when building a tag. publish_release: stage: publish image: mcr.microsoft.com/dotnet/sdk:10.0 + variables: + GIT_DEPTH: 0 needs: - job: build_windows artifacts: true script: | set -euo pipefail dotnet --info - echo "Reading MinVer version from build artifacts" - # locate a minversion file produced by the build artifacts - minfile=$(find imagecatalog -type f -iname 'minversion' -print | head -n1 || true) - if [ -z "$minfile" ]; then minfile=$(find . -type f -iname 'minversion' -print | head -n1 || true); fi - if [ -z "$minfile" ]; then echo "No minversion file found in artifacts"; exit 1; fi - echo "Found minversion file: $minfile" - version=$(cat "$minfile" | tr -d '\r\n') - if [ -z "$version" ]; then echo "minversion was empty"; exit 1; fi + export PATH="$PATH:$HOME/.dotnet/tools" + echo "Installing minver-cli" + dotnet tool install --global minver-cli --version 7.0.0 + # Ensure we have full git history and tags for MinVer to compute an accurate version + git fetch --prune --unshallow || true + git fetch --tags || true + echo "Computing version with minver-cli" + version=$(minver 2>/dev/null | tail -n1 || true) + if [ -z "$version" ]; then echo "minver failed to produce a version"; exit 1; fi echo "Using version: $version" - # find the primary artifact to upload (prefer the executable or first file under the build output) - file=$(find imagecatalog/bin -type f \! -iname 'minversion' -print | head -n1 || true) - if [ -z "$file" ]; then file=$(find . -type f -name 'ImageCatalog.*' -print | head -n1 || true); fi - if [ -z "$file" ]; then echo "No artifact file found to attach"; exit 1; fi + # find the single-file exe from the publish output + file=$(find imagecatalog/bin -type f -iname '*.exe' -print | head -n1 || true) + if [ -z "$file" ]; then file=$(find imagecatalog -type f -iname '*.exe' -print | head -n1 || true); fi + if [ -z "$file" ]; then echo "No artifact EXE found to attach"; exit 1; fi echo "Uploading artifact: $file" uploadResp=$(curl --silent --show-error --header "JOB-TOKEN:$CI_JOB_TOKEN" --form "file=@$file" "$CI_API_V4_URL/projects/$CI_PROJECT_ID/uploads") assetPath=$(echo "$uploadResp" | sed -n 's/.*"url":"\([^\"]*\)".*/\1/p') @@ -138,7 +131,6 @@ publish_release: assetUrl="$CI_SERVER_URL$assetPath" echo "Uploaded asset url: $assetUrl" basename=$(basename "$file") - # create release JSON using the exact minversion value as tag_name cat > release.json < Date: Sun, 22 Feb 2026 11:48:32 +0100 Subject: [PATCH 34/80] Made trimmed false --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f257f27..fb87b2e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -87,7 +87,7 @@ build_windows: & $dotnetExe build "imagecatalog\ImageCatalog 2.csproj" -c $env:BUILD_CONFIG -v minimal # Produce a single-file, ready-to-run publish so downstream jobs only need the EXE. try { - & $dotnetExe publish "imagecatalog\ImageCatalog 2.csproj" -c $env:BUILD_CONFIG -r win-x64 --self-contained true -p:PublishSingleFile=true -p:PublishTrimmed=true -p:PublishReadyToRun=true -o "imagecatalog\bin\$env:BUILD_CONFIG\net10.0-windows\publish" -v minimal + & $dotnetExe publish "imagecatalog\ImageCatalog 2.csproj" -c $env:BUILD_CONFIG -r win-x64 --self-contained true -p:PublishSingleFile=true -p:PublishTrimmed=false -p:PublishReadyToRun=true -o "imagecatalog\bin\$env:BUILD_CONFIG\net10.0-windows\publish" -v minimal } catch { Write-Host "dotnet publish failed: $_" throw From 3ae4da3e494fff81e189381902472553b56609dc Mon Sep 17 00:00:00 2001 From: MaddoScientisto Date: Sun, 22 Feb 2026 14:51:44 +0100 Subject: [PATCH 35/80] Enhance publish_release job: export version and add release metadata for automated releases --- .gitlab-ci.yml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fb87b2e..050a0aa 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -120,6 +120,7 @@ publish_release: version=$(minver 2>/dev/null | tail -n1 || true) if [ -z "$version" ]; then echo "minver failed to produce a version"; exit 1; fi echo "Using version: $version" + export VERSION="$version" # find the single-file exe from the publish output file=$(find imagecatalog/bin -type f -iname '*.exe' -print | head -n1 || true) if [ -z "$file" ]; then file=$(find imagecatalog -type f -iname '*.exe' -print | head -n1 || true); fi @@ -131,13 +132,18 @@ publish_release: assetUrl="$CI_SERVER_URL$assetPath" echo "Uploaded asset url: $assetUrl" basename=$(basename "$file") - cat > release.json < Date: Thu, 26 Feb 2026 18:43:07 +0100 Subject: [PATCH 36/80] Add Avalonia UI frontend alongside WinForms and WPF Introduce Avalonia as a new cross-platform UI option, including new XAML and code-behind files for the application and main window. Update Program.cs to support a --avalonia launch argument and add corresponding launch profile. Integrate Avalonia NuGet packages and ensure DataModel supports UI-thread invocation for all frontends. All business logic and state are shared via DI, enabling consistent behavior across WinForms, WPF, and Avalonia. --- imagecatalog/AvaloniaApp.axaml | 8 + imagecatalog/AvaloniaApp.axaml.cs | 20 ++ imagecatalog/AvaloniaMainWindow.axaml | 317 ++++++++++++++++++++ imagecatalog/AvaloniaMainWindow.axaml.cs | 151 ++++++++++ imagecatalog/DataModel.cs | 12 +- imagecatalog/ImageCatalog 2.csproj | 4 + imagecatalog/Program.cs | 23 +- imagecatalog/Properties/launchSettings.json | 9 +- 8 files changed, 535 insertions(+), 9 deletions(-) create mode 100644 imagecatalog/AvaloniaApp.axaml create mode 100644 imagecatalog/AvaloniaApp.axaml.cs create mode 100644 imagecatalog/AvaloniaMainWindow.axaml create mode 100644 imagecatalog/AvaloniaMainWindow.axaml.cs diff --git a/imagecatalog/AvaloniaApp.axaml b/imagecatalog/AvaloniaApp.axaml new file mode 100644 index 0000000..8ce9be1 --- /dev/null +++ b/imagecatalog/AvaloniaApp.axaml @@ -0,0 +1,8 @@ + + + + + + diff --git a/imagecatalog/AvaloniaApp.axaml.cs b/imagecatalog/AvaloniaApp.axaml.cs new file mode 100644 index 0000000..9a14f4d --- /dev/null +++ b/imagecatalog/AvaloniaApp.axaml.cs @@ -0,0 +1,20 @@ +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Markup.Xaml; +using Microsoft.Extensions.DependencyInjection; + +namespace ImageCatalog_2; + +public partial class AvaloniaApp : Avalonia.Application +{ + public override void Initialize() => AvaloniaXamlLoader.Load(this); + + public override void OnFrameworkInitializationCompleted() + { + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + var model = Program.ServiceProvider.GetRequiredService(); + desktop.MainWindow = new AvaloniaMainWindow(model); + } + base.OnFrameworkInitializationCompleted(); + } +} diff --git a/imagecatalog/AvaloniaMainWindow.axaml b/imagecatalog/AvaloniaMainWindow.axaml new file mode 100644 index 0000000..a16b949 --- /dev/null +++ b/imagecatalog/AvaloniaMainWindow.axaml @@ -0,0 +1,317 @@ + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/WPFCatalog/Controls/GeneralSettingsControl.xaml.cs b/WPFCatalog/Controls/GeneralSettingsControl.xaml.cs deleted file mode 100644 index af3e0aa..0000000 --- a/WPFCatalog/Controls/GeneralSettingsControl.xaml.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; - -namespace WPFCatalog.Controls -{ - /// - /// Interaction logic for GeneralSettingsControl.xaml - /// - public partial class GeneralSettingsControl : UserControl - { - public GeneralSettingsControl() - { - InitializeComponent(); - } - } -} diff --git a/WPFCatalog/Controls/TextSettingsControl.xaml b/WPFCatalog/Controls/TextSettingsControl.xaml deleted file mode 100644 index 7d7ac19..0000000 --- a/WPFCatalog/Controls/TextSettingsControl.xaml +++ /dev/null @@ -1,168 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/WPFCatalog/Controls/TextSettingsControl.xaml.cs b/WPFCatalog/Controls/TextSettingsControl.xaml.cs deleted file mode 100644 index 2c29c51..0000000 --- a/WPFCatalog/Controls/TextSettingsControl.xaml.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; - -namespace WPFCatalog.Controls -{ - /// - /// Interaction logic for TextSettingsControl.xaml - /// - public partial class TextSettingsControl : UserControl - { - public TextSettingsControl() - { - InitializeComponent(); - } - } -} diff --git a/WPFCatalog/Converters/FontFamilyStringConverter.cs b/WPFCatalog/Converters/FontFamilyStringConverter.cs deleted file mode 100644 index 66a103e..0000000 --- a/WPFCatalog/Converters/FontFamilyStringConverter.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Data; -using System.Windows.Media; - -namespace WPFCatalog -{ - public class FontFamilyStringConverter : IValueConverter - { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - FontFamily fontfamily = new FontFamily("Verdana"); - if (value != null) - { - fontfamily = new FontFamily(value.ToString()); - } - return fontfamily; - - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - throw new NotImplementedException(); - } - } -} diff --git a/WPFCatalog/Converters/MaddoColorConverter.cs b/WPFCatalog/Converters/MaddoColorConverter.cs deleted file mode 100644 index 2248484..0000000 --- a/WPFCatalog/Converters/MaddoColorConverter.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Diagnostics; -using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Data; -using System.Windows.Media; - -namespace WPFCatalog -{ - public class MaddoColorConverter : IValueConverter - { - private static readonly DependencyObject _dummy = new DependencyObject(); - - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - Color color = Colors.Black; - - if (value != null && value != DependencyProperty.UnsetValue && value is string && !String.IsNullOrWhiteSpace((string)value)) - { - string c = (string)value; - object convertedColor = null; - try - { - convertedColor = ColorConverter.ConvertFromString(c); - } - catch (Exception ex) - { - if (!DesignerProperties.GetIsInDesignMode(_dummy)) - { - throw new FormatException($"String {c} does not represent a valid color", ex); - } - } - if (convertedColor != null) - { - color = (Color)convertedColor; - } - } - - return color; - - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - if (value != null) - { - Color color = (Color)value; - Debug.WriteLine(color.ToString()); - return color.ToString(); - } - return string.Empty; - } - } -} diff --git a/WPFCatalog/Icons/camera-photo-5.png b/WPFCatalog/Icons/camera-photo-5.png deleted file mode 100644 index 1e54dea89239f7aecab3e55382432a57c6c60e54..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1231 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkEj_j@0&dJZ`)n?tl_D>YcrteH1n%v&r z_6D}Ly{R)T`VJp%U+u(U_=)Yn=RMi8mff8cWF)~OFv~$-WW{y$A1{yZestu=+3oSG z&-%`<+PkhrV8*hQ4ewnRUknIe7pLYMye{r1*HV%4X?dHU{>ck| zs(0@WS#7Fw`q{JI+3dR#C0qjge}50puz&x+!tD24v(58kk8ISvq@u{d^zUx|=RKci zEV-XtS~}Hxx}E&G32B;t>-d*GSbscw&PTgr*5=;!Ih!|bJNz+$VW-kr)vZyzZ`bDD zdOKmUiX>CfOy#944wp^VJktDE_l13#;i38c*D_eE=SXQ^&Zs#wS>6BV2j%{}<;_*M zMMau++<$!Y9pArWY%f0w28tA3$P_MhR$G2Mg#cHe}xXv-#y^E~XyA zxp~`9A3DSo931>4sOiiJqfXd0L&cpl=vk}N&X|36 zR#siFuT9OI5uz=6u{*hMGRsntvuTqJcr5E5+63w^3R~NB>hgxW7av*Fso9+0z3la` zwK}Jb8WcDl6>k>z+SPEbj{Eec6(L$J4;h2fmSlDXd2uNQExq!+>AH!r@n_8fu^&N~ zx18ouV|nwmav#qfwrkg~UoZFjqtCGHz5VvaE%BhFZ(8CSQR1ARo12WKm#mw4Gnb-4MGept&A*)L>|!Yha{nWDsIx zY-MC-Wn>7^Q1iRK5Jf|7eoAIqB~$~@2Ez~o3oBDIE0BJW4IybSR|7Q|ft=)%nVgze zoXU_|`z^)3Ja diff --git a/WPFCatalog/Icons/document-open-6.png b/WPFCatalog/Icons/document-open-6.png deleted file mode 100644 index fe03b7f429925fe2a0d967ce4ac873644a773707..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1028 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmUzPnffIy#(^vlDyqr zfHV;NblzPLq&N#aB8!2v2N=7Z%(epwmK8Xr18J~%3^B*n9%f)*{Nw537-DgH>cq3& zA%POd>Yv|RtZZy%X4!2LzBcQ+Q_L2PNgf5lYk%F?dio#p;@o=2gCZ^g21;8z7K(`p zvNXClg^7qXb=KafSyi0Ar}(^kcX7L*{+Ex3BIkVm^yl2?J?l4I`?TDu^3jh=KYq-t zxsbK;?)#gyH}9qU&-dZ>J3s&EvCf0Y2MTI=7~45>E}r*JU;y5#YWRk z_2+L6r8w!UX%u{UwNQR)S@u@PU2#nMYAtMh{SHewRS!J6zNB=wLFbGIzpBn$%L5w{$|YkN(F5kei=+)V)ST;=l!vT@w@nB zzjaS+`1qQx+~o*lab`adrLB74*fin)dnU5n+4I)Wh#^k8r651bc^`X=>Qjc>>pmu_ z{yW%Ubm7{Bciw`gSu&F6R3BIwNs247g+%L3HxkHX*AVHxv$I_M!v=>9D_@-V@|rEU zI^Hfs#bKo&Gt>6un}Q%+xA%j6NPGtYeY$MQEFmIs%{F9U@$T;u+%j))HO5>F*LI>u&^>Q)HN`- zGB8kC_wWHs14yM6L>Ewlp@FV}k*<+Jh>@|Ck(rgDDMSOCbxb3QhTQy=%(P0V2A~aw zAqJLKh89-F77z_#T2`z;4W=L``D7-i<`t(hWR#Q?Sn2D7?aC}mP0r8F&Ce^=%P&gT z&w(f@*7tD_@X}xJ3eHBg8TSeyWzAeg&vO5@cg=ep*R+Vo@rCV@iHfs)A>3 zVtQ&&YGO)d;mK4Rpdwy~qSB(|R0hA&vizLHHU6d_ff6PNiTKbUADENN%ggmLlk@X* ovorJ3^?(l7FDS~-N=+^)*3ScL*Dtf(0?OwMp00i_>zopr0HQU2XaE2J diff --git a/WPFCatalog/Icons/document-open-folder.png b/WPFCatalog/Icons/document-open-folder.png deleted file mode 100644 index 98b8a9448a5756451eadce70af3772be1f543993..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 852 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE0z%d<2gY`4S99w&sfq~J`)5S5w;`Gv>-CoX)0=DVp@A8@$w+gyk zW?Ac-n7w$Ze1a7Bf29fX7vwoQ4Hb2pPwpZlyzw76$+xg?=UZ@v)2#b0dFKL^yir1f2 zt+>ggS-@fCtq(Ex_jLpt?sq=QxidndJz~ivPG#4%|6CrooJiGKz_z#ckGRXBLZ=S# z=AO+0v)?T_Dip_agq^3>;pDE8aM_iI*m+c6pSkz-@$0O_tezzH&kKY#UzwjTyf!m7 z^Zxy?Tjg_SuDX&L3oGvKvI+89`ut4Jd~asWlEpt6A96=DZ(*2U2MkHo64!{5 z9nO2Eg!<&1*zW_C)gPi1(nVgzeoXU_vn(|^KQ}i&uUId?C|y4XqNG?qsZzH%QQuh4KwlxhNP!p~KJEcN`bK(&`qBM1 z$uKuUoQD(&2FALEmLY})R;ET)ra(`b0X=n7{@W&?21$?`gY(l$$`gxH8OqDc^)mCa zi<1)zQbA6e{mw=Ts7M&1sI(|KmBGKFGCeg(}6TtKSRv1wTBrPn7KV&978Nlr%v|Gh)I=bo&Wo;wf)BANB+lH zZr#}B5o^+8+L$5Qy-U#1iIvysU@Yf~)wiYwvButzat`B-xU*uVM@H@%-G43tQj^)d z7W)J%-S|_s$awOSnP*app4WY^yZ>4#WJzUsdZC3(#rekt*L!OnXBXX-b1CiYoW&@! z^pk@4nj8M}>*lWf|9h_WqhkUeiv*-U2=%r{^UL%vm#cAGSz+wqA#x@_^IuMWobA%y zILpfu9`x4Uees{Et*s!sx!#%UvxHbreyWK`4UUy z4@my*x%;tgS{ekt}^R9TRuU@Dh;*ZcQBo}}6huiwqJZY#kX63?F2!>&{5{m#E5RSSj=Ipl6nrGf)3-(>lN8FHB}<1h0ujo;_dm*Gnu}Ye(ta zkZJnSg%bCw9`F60dV6=>s_CaP^TKbP^!*yBtDC6A+wi*bPVoH`>$Yw0Jk3!0lKDEv*`k$L8nUW>zoz5M?3q8`t~_h) z{E0#A@wXX!e>yMkxP0-`jgKxn44XdIAAMnYgv}yPYWq8edwt?NO82f0nfkhB9#JiEjVMVjN=+$?Z| z=o{%7=;vgyt$bP0l+XkK^*s1x diff --git a/WPFCatalog/Icons/format-justify-left-2.png b/WPFCatalog/Icons/format-justify-left-2.png deleted file mode 100644 index d6abc0585efd6d5e4a41f17f3545b877c432432c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3517 zcmZXWcT`hNyTu2PVh|}x*C0(%DFGrS0ff+{h!7PO1?i!M5~>10M1d$ZG(iNUqe6%v zN)ZquQeS%S3K9`%p-B7U>;2YUcipqr%wA_^|JHuy%=zPqGBefZfCxbV033z}I_7lc z`ZL&A=(EV$!Ckr>a?&!<0)P~Af9Faf01$PIwze6@&JKWpk>?gpXp03t_05TOlu;y} zXoNNAWjke#BH+=O9G(P_{ZN2Mb1|~8J~Bt_0k7b3uljE8IFeX&gcfO&A&^aKc1lVK zJ;6C46ilA0RmN_V)^4aeJ^z&vtO4|F%5he# zD6;`lt?`jQ3}xxSCLz0>2yA`<{PVMX_Doy?z$S-_-GYH_1JuXq>n;N}MFy!S#L|GC z>sF$j762@l+Y`Pe5YfyYqHmi{THSshkfoxm{mN|U;o*l1jPKdz9UNK@^)!P-MJ9mP z^V7j|c5cq9BC8O{QI!$I{ffc^pzERVA9t@!ElMjlzxmbWa zOL(F`CxC6IADna+1X;rg$4>w}KX(Ls(rU&R0S16)gPSocIfrWqgfkD}#jEhhfH0Bv zM`n=^R4f6?Ai_9KTUI*as@WmQGVV$g@8YAIg^%@A7-c*eI~$p+7zd~L)bMu%@bfST z*5-s3mqMeCWu%fVK2>ZWQoK>uQ8dH=#uL^g8f5?x(gQc93kQS3ZL*yxDV`b}jc(joNC32UzoYo>i<#`?Dp`#(6oQi6fDy%2 zwAOU1iD5>VC#p#_Ez!y#ELX)`2y?iI_%^Xm2cbqKrwj#a@Cb4rm5+M-za0`XjqY<}_;*CO}6 zl0F8iipg_F)3q$!?jGk7=cKoKBY`8@Bj*v%J#_r@9`{PFC#_%lefPI+kjS38cKF@q zDR~}&OB5DL2t|;hPC0)%5kpzGr6}^YbF>G|sm|HWA$gOdUqh^QbIVbAH}h_M`_RgM zwYa#b_#Kt8|9(HD|7G#@tNML~E{-m07s5uoD_kmOUHtnfeK)8_soB&tY95ufU#^G~ z6L+B#f7Cr7?w2vN*(8TG*$^5q;Z9Yjm!3LJB?Yi*xD>hy zI2XdlT!-9MJnTK-gN5~lU%to7cci*zxYaaQjR*8K)k`$l7a4|s3AQLcI|%Q`rDF;f zZYlbZ1;`bSGLG7FH|OrJ-Ctu_d(3Cdewm=lcY#k?#xU8c4cGQOdGM9l`7SP_% zx}|hJw$m@I*3D0!OI%8!@Z5L9va4lkRWgS-(oUAEew{witJT&`1QEnq~g!qkkc5zOT2qQ zW%ZB)>G}+AM#Ag$%Ga&$TOYPafgx*^ox%p5m!vLLsZZVynb@4!{FX#LhX;xxLe zFS?KW@MUw!z%;(pO5{)XAm`uv>rqcqpX3`~aD{>@NLr2&Cfn-eVq030#q%{;WyGd)W>6-))RojfLnE-R?X7*h zjj|N8>Z$AVTqw>9ZmUW8c{@h>^3935#sJ;v=&&S)^PI18USG1NS%d{^1vdQXmoFKG z&>+|OHcAg$_L}9IOUQj74+Q^Q@_p!=;5+`Kpmefs--lGV;)^)~efClxB~swqt5`1F|P=j|6ql zZr zT{ORkUa{Qt>gYn{Z;E@*}?Y3@`DwxtmU(7nC7eoo4vT%f1>Ul zOuKf?sS5|l-qX-9Unl&QL*B8h*_ysyYF({or_Xw))!KCT+V4v{{riK8cizQDJXH@# z+;-e`UqSx#XPxkw^bd*LhN)!k#P5<;6TcNyc4@s3F|{`}-aW>Yy0$B6rU`2WT2>=F+p^g?>r7bVP#N(J2SHwrEv099nS8Pk% zD@`%eI0L?n@bI!Ju*fwkl|njnCvJ+FN0{$K!^ZA9ZnLeCr2aDAE4QyW6m8vq@9OEO zd7Vm)-Hg3j!MVrcnv6sq-*GP6Lz+Bi4;zMW-}l;_{!RPb@mM0{U|YFA#u-J#=Cl@H zxe^rod)MJZ=P2$}{QYC8`&*{TuQOeLosCWq5Hn#r5_`up*w;{_#o{t!{S?ej4Z4YY zlp1%6qQe%yB~`)-QjJfiBI&P}X2!n-at>A2GO>xSQrC|#J#1MMH8FT7(A}yD+THY7 z9d|!`9Gz`w_Ru6rtEdY4rgo~v#KdaF^|T^g_pl5s+b}1k+5;@>Ja%$%sb2M+KV*Wn zubjjLBkx(1y@@=k*^`+6Pt2>UnzQ$ zCeeWJ?XJ3zYLnqG*Ljaz_pT!~n`GJ^1OG|>nLA4yJM0$iVRE{0fWiMmrMT__~S(UrRab>Oa`VPqo9CRfFWRt2zmHl zK*G-LXH1I6_e#p{VpX z@dt|*ln(IyNwmQFdfPbwZSO!I++DX*X5LsA2Rq!4*{=k;EylH zlM_Xb*5^wZBz+F-{p+zn;l+i8o~(gKLbo?{Pp)q`*R}4^qZcchHTb#|^qQR6bJ@i& zu61k|3%Q^av82~9bJDY&&#i3MZ)@(Fz+GOccYbGk@j2f+a}%|GKRVXAU&*8I$&5J( zhkRIs6+03>>T(Cno$Z+Rpl^3`dcgtSJF?RQ1dN=E1S}+{-Pdtvh+MGq+thbyulJih z?`BognrzK;XU@B{?&r(nAN$>Tw_9pQ*v=y_?qxdM**39*j+_eNSJ{kkqeEm)s!b$P;!ebe@@h!Oz2Y@AIgrYg=-Ov0iQ{U(5FS zs!_a^t(EfUoIf*?eV+f=Q`c3NFVrfS_36c_yoQ8DasQ6JY1Gu(dH70~Q{3a=I?<0E z%2(SvGB!_>;TCI7DH4$}Hr)7Jph&PrdS}6rkUXn2M#YxhpJRFNEc$da!RgtPZ@rgx z|K!=uA!d93WW&;%6Xq1HJhGnq#4Jvmg%)AU0&et+up2*Le<3oO!DU^|obCMY9;&G{ zI!|(8o_st!y|#SY|E)j$r}9+y&Rkf>Y|j`ky>P$k(avmO%&V5TMwBEMr6!i7>ZSk* z1|tIlOI<@lT|=`FBO@zA3oAo&T?2C~1A}OWe+OY2Kq{>ux_}xC4Rj5F8Vo}W%&bg} ztqe>c8W;sP<)LWE%}>cptHiCLz=!J+P(u>PNj{m$sd>ez3>hUQ1y=g{V7oHQQj_y@ zbMy0x_413-^>ZLfiuIE!^^Nrm^cC`p6o^!Aq-Uz%-DZ;ta~{NH@BlE=H89pSGzu{? zv@$ib0(lP<0H?Qn_yW`*336U=ep*R+Vo@rCV@iHfs)A>3VtQ&&YGO)d;mK4Rpdx9A zqSB(|R0cOkUkFkN&dkYH@Jt4Jps6b5H&B@|LRoxhkPpna<>lpiX^FWIqzCk~eokVN dekMqxelgGt{X<81d4bv)JYD@<);T3K0RVitj@tkL diff --git a/WPFCatalog/Icons/picture.png b/WPFCatalog/Icons/picture.png deleted file mode 100644 index b773744c72df584d44d74ae66da69639b820ba19..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1075 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmUzPnffIy#(^vlDyqr zfHV;NblzPLq&N#aB8!2v2N=7Z%(epwmK8Xr18J~%3^B*n9%f)*{OIZ87-DgH>15mN z5J!==`NrSx?fsr6UZyC0*lm#t<3Xj4l|BC$xw)lRFWE5R3!`*>%YH|n^o3JfBP9Mi zI&9!*=~(cryC%nM_M1C%Et3T|r<{RzJq$VV6zLro8-Y zCtH?zQcHO8?I)hX;#2k>p0hqXwCzxCQd{M}6sGk`dj+}JkGV)R9?CHaysxHPyF4@6 z;(f>EDJMU&-M@DFidSg}y9qKGt3ES;>8*6da~>Bb-5cZ`QB9g2E4{?W4!o3=8v zPVwI461N?Orv9qg4?=(ET)ckp)jOs*(eDj*nwS9 z;lSaUNAEeC)E+3To}TlV`|EG+Gp?TVjn9|#Fg_95|7%a%`Rp6NuBg_@2pD=V0XnSQ z?S113`4EfU;*;iTcPMk(I%rNa&!2uhom+m{|8&d8972b)8Fs$1`p?Fee`_*x?ty*4 zl%QJT8c~v5l$uzQs+$5N7>o=IEOiYHbq&ozjEt-dEvyX9bq&m|3=EwgR%j8iFPNj{m$sd>ez z3>hUQ1y=g{V7oHQQj_y@bMy0x_413-^>ZLfiuIE!^^Nrm^cC`p6o^!Aq-Uz%-DZ;t za~{NH@BlE=H89pSGzu{?v@$ibGBkns$Nu+~=RggTAm;_=r9C%$#fm&t#wnnyONM1C<#gl*NYz`M`Wz sUS6)3mY54cdO$zx=OiZSXM!~97X!`EKXinb7pR@V)78&qol`;+06No>>Hq)$ diff --git a/WPFCatalog/MainWindow.xaml b/WPFCatalog/MainWindow.xaml deleted file mode 100644 index c7cd8fe..0000000 --- a/WPFCatalog/MainWindow.xaml +++ /dev/null @@ -1,203 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/imagecatalog/ImageCatalog 2 - Backup.csproj b/imagecatalog/ImageCatalog 2 - Backup.csproj deleted file mode 100644 index c77aca9..0000000 --- a/imagecatalog/ImageCatalog 2 - Backup.csproj +++ /dev/null @@ -1,59 +0,0 @@ - - - WinExe - net8.0-windows - enable - enable - true - False - 3.0.0.0 - 3.0.0.0 - 3.0.0-alpha.63+Branch.develop.Sha.39a9baf5c618d8d79c75b89e2d5c4020939697f2 - 3.0.0-alpha0063 - - - true - - - embedded - - - embedded - - - - MyApplicationCodeGenerator - Application.Designer.cs - - - SettingsSingleFileGenerator - Settings.Designer.cs - - - - - - - - - - - - - - - all - - - All - - - - - True - True - Settings.settings - - - - \ No newline at end of file diff --git a/imagecatalog/ImageCatalog 2.csproj b/imagecatalog/ImageCatalog 2.csproj index 36ac938..be6394f 100644 --- a/imagecatalog/ImageCatalog 2.csproj +++ b/imagecatalog/ImageCatalog 2.csproj @@ -51,17 +51,18 @@ - + + - - - - + + + + all diff --git a/imagecatalog/ImageCatalog 2.vbproj b/imagecatalog/ImageCatalog 2.vbproj deleted file mode 100644 index b8cc359..0000000 --- a/imagecatalog/ImageCatalog 2.vbproj +++ /dev/null @@ -1,347 +0,0 @@ - - - - Local - 9.0.30729 - 2.0 - {8D3AA2B0-8F06-4A61-9CAD-B920EB1A8E9C} - Debug - AnyCPU - - - - - ImageCatalog - - - None - JScript - Grid - IE50 - false - WinExe - Binary - On - On - ImageCatalog - ImageCatalog.My.MyApplication - - - WindowsForms - 3.5 - - - v4.7.2 - true - My Project\app.manifest - - - SAK - SAK - SAK - SAK - - - http://localhost/ImageCatalog/ - true - Web - true - Foreground - 7 - Days - false - false - true - 0 - 1.8.0.%2a - false - true - - - bin\ - ImageCatalog.xml - 285212672 - - - - - true - true - true - false - false - false - false - 1 - 42016,42017,42018,42019,42032,42353,42354,42355 - full - AnyCPU - AllRules.ruleset - false - - - bin\ - ImageCatalog.xml - 285212672 - - - - - false - true - false - true - false - false - false - 1 - 42016,42017,42018,42019,42032,42353,42354,42355 - none - AnyCPU - AllRules.ruleset - false - - - true - true - true - bin\x64\Debug\ - 285212672 - ImageCatalog.xml - 1 - 42016,42017,42018,42019,42032,42353,42354,42355 - full - x64 - AllRules.ruleset - false - - - true - bin\x64\Release\ - 285212672 - ImageCatalog.xml - true - 1 - 42016,42017,42018,42019,42032,42353,42354,42355 - x64 - AllRules.ruleset - false - - - true - true - true - bin\x86\Debug\ - 285212672 - ImageCatalog.xml - 1 - 42016,42017,42018,42019,42032,42353,42354,42355 - full - x86 - bin\ImageCatalog.exe.CodeAnalysisLog.xml - true - GlobalSuppressions.vb - AllRules.ruleset - ;F:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets - true - ;F:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules - true - false - false - - - true - bin\x86\Release\ - 285212672 - ImageCatalog.xml - true - 1 - 42016,42017,42018,42019,42032,42353,42354,42355 - x86 - bin\ImageCatalog.exe.CodeAnalysisLog.xml - true - GlobalSuppressions.vb - AllRules.ruleset - ;F:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets - true - ;F:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules - true - false - - - - ..\packages\Ben.Demystifier.0.3.0\lib\net45\Ben.Demystifier.dll - - - - System - - - ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll - - - ..\packages\System.Collections.Immutable.5.0.0\lib\net461\System.Collections.Immutable.dll - - - 3.5 - True - - - System.Data - True - - - System.Drawing - True - - - ..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll - - - - ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll - - - ..\packages\System.Reflection.Metadata.5.0.0\lib\net461\System.Reflection.Metadata.dll - - - ..\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll - - - ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll - - - System.Windows.Forms - - - System.XML - - - - - - - - - - - - - - - Code - - - - - - Code - - - Form - - - - MainForm.vb - - - Form - - - - True - Application.myapp - - - True - True - Settings.settings - - - - - Code - - - Code - - - Form1.vb - Designer - - - MainForm.vb - - - MyApplicationCodeGenerator - Application.Designer.vb - - - - - - My - SettingsSingleFileGenerator - Settings.Designer.vb - - - - - - False - .NET Framework 3.5 SP1 Client Profile - false - - - False - .NET Framework 2.0 %28x86%29 - false - - - False - .NET Framework 3.0 %28x86%29 - false - - - False - .NET Framework 3.5 - true - - - False - .NET Framework 3.5 SP1 - false - - - False - Windows Installer 3.1 - true - - - - - - - - {44465926-240d-473f-90b8-786ba4384406} - CatalogVbLib - - - {aebfe9e3-277c-4a7b-8448-145d1b11998b} - MaddoShared - - - - - - - - - - - - - - - - \ No newline at end of file From b29cc95a1e58c93565620a88cfc28c985c891bb4 Mon Sep 17 00:00:00 2001 From: MaddoScientisto Date: Sun, 8 Mar 2026 13:44:09 +0100 Subject: [PATCH 45/80] feat: Enhance Avalonia UI with compact styles and improved layout for various views; adjust margins and paddings for a denser interface --- imagecatalog/AvaloniaApp.axaml | 46 +++++++++++++++++++ imagecatalog/AvaloniaMainWindow.axaml | 34 +++++++------- imagecatalog/AvaloniaViews/AiTabView.axaml | 24 +++++----- .../AvaloniaViews/FaceAiTabView.axaml | 22 ++++----- .../AvaloniaViews/GeneralTabView.axaml | 36 +++++++-------- imagecatalog/AvaloniaViews/LogoTabView.axaml | 26 +++++------ imagecatalog/AvaloniaViews/PhotoTabView.axaml | 18 ++++---- .../AvaloniaViews/RaceUploadTabView.axaml | 11 ++--- imagecatalog/AvaloniaViews/TextTabView.axaml | 34 +++++++------- .../AvaloniaViews/ThumbnailsTabView.axaml | 16 +++---- 10 files changed, 156 insertions(+), 111 deletions(-) diff --git a/imagecatalog/AvaloniaApp.axaml b/imagecatalog/AvaloniaApp.axaml index e4a021d..fe06efa 100644 --- a/imagecatalog/AvaloniaApp.axaml +++ b/imagecatalog/AvaloniaApp.axaml @@ -4,6 +4,52 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/imagecatalog/AvaloniaMainWindow.axaml b/imagecatalog/AvaloniaMainWindow.axaml index e9f6ef2..bd8498f 100644 --- a/imagecatalog/AvaloniaMainWindow.axaml +++ b/imagecatalog/AvaloniaMainWindow.axaml @@ -10,17 +10,17 @@ - + - + - + @@ -30,7 +30,7 @@ - + @@ -40,7 +40,7 @@ - + @@ -50,7 +50,7 @@ - + @@ -60,7 +60,7 @@ - + @@ -70,7 +70,7 @@ - + @@ -80,7 +80,7 @@ - + @@ -90,7 +90,7 @@ - + @@ -99,24 +99,24 @@ - + - + @@ -124,20 +124,20 @@ Command="{Binding ProcessImagesCommand}" IsEnabled="{Binding UiEnabled}"> - + - + diff --git a/imagecatalog/AvaloniaViews/AiTabView.axaml b/imagecatalog/AvaloniaViews/AiTabView.axaml index e9652d4..a5f6971 100644 --- a/imagecatalog/AvaloniaViews/AiTabView.axaml +++ b/imagecatalog/AvaloniaViews/AiTabView.axaml @@ -3,33 +3,33 @@ xmlns:avaloniaDataGrid="clr-namespace:Avalonia.Controls;assembly=Avalonia.Controls.DataGrid" x:Class="ImageCatalog_2.AvaloniaViews.AiTabView"> - + - + - - + + -