Override mode fix
This commit is contained in:
parent
abdd2a313a
commit
12d1bd57dc
7 changed files with 249 additions and 181 deletions
|
|
@ -680,6 +680,9 @@ public class ImageCreatorSharp(PicSettings picSettings, ILogger<ImageCreatorShar
|
||||||
|
|
||||||
private void SalvaFoto(Bitmap imgOutputBig, ImageState imgState, ImageFormat thisFormat)
|
private void SalvaFoto(Bitmap imgOutputBig, ImageState imgState, ImageFormat thisFormat)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
var fileName = Path.Combine(imgState.DestDir.FullName, imgState.NomeFileBig);
|
||||||
|
|
||||||
using var image1Stream = new MemoryStream();
|
using var image1Stream = new MemoryStream();
|
||||||
if (picSettings.FotoGrandeDimOrigina == false)
|
if (picSettings.FotoGrandeDimOrigina == false)
|
||||||
{
|
{
|
||||||
|
|
@ -699,52 +702,60 @@ public class ImageCreatorSharp(PicSettings picSettings, ILogger<ImageCreatorShar
|
||||||
using var g2 = Image.FromStream(image1Stream);
|
using var g2 = Image.FromStream(image1Stream);
|
||||||
imgState.ThumbSizeBig = g2.Width > g2.Height ? NewthumbSize(g2.Width, g2.Height, picSettings.LarghezzaBig, "Larghezza") : NewthumbSize(g2.Width, g2.Height, picSettings.AltezzaBig, "Altezza");
|
imgState.ThumbSizeBig = g2.Width > g2.Height ? NewthumbSize(g2.Width, g2.Height, picSettings.LarghezzaBig, "Larghezza") : NewthumbSize(g2.Width, g2.Height, picSettings.AltezzaBig, "Altezza");
|
||||||
using var imgOutputBig2 = new Bitmap(g2, imgState.ThumbSizeBig.Width, imgState.ThumbSizeBig.Height);
|
using var imgOutputBig2 = new Bitmap(g2, imgState.ThumbSizeBig.Width, imgState.ThumbSizeBig.Height);
|
||||||
if (thisFormat.Equals(ImageFormat.Jpeg))
|
|
||||||
SalvaImmagineCustomQuality(imgOutputBig2, Path.Combine(imgState.DestDir.FullName, imgState.NomeFileBig), picSettings.JpegQuality);
|
|
||||||
else
|
|
||||||
imgOutputBig2.Save(Path.Combine(imgState.DestDir.FullName, imgState.NomeFileBig), thisFormat);
|
|
||||||
|
|
||||||
//imgOutputBig2.Dispose();
|
if (!picSettings.OverwriteFiles && File.Exists(fileName))
|
||||||
|
{
|
||||||
//imgOutputBig.Dispose();
|
logger.LogInformation("Saltata foto {FileName}, esiste", fileName);
|
||||||
//g2.Dispose();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//
|
|
||||||
if (thisFormat.Equals(ImageFormat.Jpeg))
|
if (thisFormat.Equals(ImageFormat.Jpeg))
|
||||||
SalvaImmagineCustomQuality(imgOutputBig, Path.Combine(imgState.DestDir.FullName, imgState.NomeFileBig), picSettings.JpegQuality);
|
SalvaImmagineCustomQuality(imgOutputBig2, fileName, picSettings.JpegQuality);
|
||||||
else
|
else
|
||||||
imgOutputBig.Save(Path.Combine(imgState.DestDir.FullName, imgState.NomeFileBig), thisFormat);
|
imgOutputBig2.Save(fileName, thisFormat);
|
||||||
|
|
||||||
//imgOutputBig.Dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!picSettings.OverwriteFiles && File.Exists(fileName))
|
||||||
|
{
|
||||||
|
logger.LogInformation("Saltata foto {FileName}, esiste", fileName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (thisFormat.Equals(ImageFormat.Jpeg))
|
||||||
|
SalvaImmagineCustomQuality(imgOutputBig, fileName, picSettings.JpegQuality);
|
||||||
|
else
|
||||||
|
imgOutputBig.Save(fileName, thisFormat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
image1Stream.Seek(0, SeekOrigin.Begin);
|
image1Stream.Seek(0, SeekOrigin.Begin);
|
||||||
|
|
||||||
if (!picSettings.CreaMiniature) return;
|
if (!picSettings.CreaMiniature) return;
|
||||||
if (!picSettings.AggiungiScritteMiniature) return;
|
if (!picSettings.AggiungiScritteMiniature) return;
|
||||||
|
|
||||||
using var g1 = picSettings.FotoGrandeDimOrigina ? (Image)imgOutputBig.Clone() : Image.FromStream(image1Stream);
|
using var g1 = picSettings.FotoGrandeDimOrigina ? (Image)imgOutputBig.Clone() : Image.FromStream(image1Stream);
|
||||||
//if (_picSettings.FotoGrandeDimOrigina == false)
|
|
||||||
// g1 = Image.FromStream(image1Stream);
|
using var imgOutputSmall = new Bitmap(g1, imgState.ThumbSizeSmall.Width, imgState.ThumbSizeSmall.Height);
|
||||||
////g1 = System.Drawing.Image.FromFile(Path.Combine(DestDir.FullName, "Temp_" + NomeFileBig));
|
|
||||||
//else
|
|
||||||
// g1 = (Image)imgOutputBig.Clone();
|
|
||||||
//g1 = System.Drawing.Image.FromFile(Path.Combine(DestDir.FullName, NomeFileBig));
|
|
||||||
using Bitmap imgOutputSmall = new Bitmap(g1, imgState.ThumbSizeSmall.Width, imgState.ThumbSizeSmall.Height);
|
|
||||||
if (string.Equals(picSettings.DirectorySorgente, picSettings.DirectoryDestinazione, StringComparison.OrdinalIgnoreCase))
|
if (string.Equals(picSettings.DirectorySorgente, picSettings.DirectoryDestinazione, StringComparison.OrdinalIgnoreCase))
|
||||||
imgState.NomeFileSmall = imgState.NomeFileSmall.Substring(0, imgState.NomeFileSmall.Length - 4) + picSettings.Codice + imgState.NomeFileSmall.Substring(imgState.NomeFileSmall.Length - 4);
|
imgState.NomeFileSmall = imgState.NomeFileSmall.Substring(0, imgState.NomeFileSmall.Length - 4) + picSettings.Codice + imgState.NomeFileSmall.Substring(imgState.NomeFileSmall.Length - 4);
|
||||||
//
|
|
||||||
if (thisFormat.Equals(ImageFormat.Jpeg))
|
var tnFileName = Path.Combine(imgState.DestDir.FullName, imgState.NomeFileSmall);
|
||||||
SalvaImmagineCustomQuality(imgOutputSmall, Path.Combine(imgState.DestDir.FullName, imgState.NomeFileSmall), picSettings.JpegQualityMin);
|
|
||||||
|
if (!picSettings.OverwriteFiles && File.Exists(tnFileName))
|
||||||
|
{
|
||||||
|
logger.LogInformation("Saltata miniatura foto {TnFileName}, esiste", tnFileName);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
imgOutputSmall.Save(Path.Combine(imgState.DestDir.FullName, imgState.NomeFileSmall), thisFormat);
|
{
|
||||||
|
if (thisFormat.Equals(ImageFormat.Jpeg))
|
||||||
//imgOutputSmall.Dispose();
|
SalvaImmagineCustomQuality(imgOutputSmall, tnFileName, picSettings.JpegQualityMin);
|
||||||
|
else
|
||||||
//g1.Dispose();
|
imgOutputSmall.Save(tnFileName, thisFormat);
|
||||||
|
}
|
||||||
//if (File.Exists(Path.Combine(DestDir.FullName, "Temp_" + NomeFileBig)))
|
|
||||||
// File.Delete(Path.Combine(DestDir.FullName, "Temp_" + NomeFileBig));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SalvaImmagineCustomQuality(Bitmap imageToSave, string nomeFileFinale, long quality)
|
private void SalvaImmagineCustomQuality(Bitmap imageToSave, string nomeFileFinale, long quality)
|
||||||
|
|
|
||||||
|
|
@ -64,4 +64,5 @@ public class PicSettings
|
||||||
public bool FotoRuotaADestra { get; set; } = false;
|
public bool FotoRuotaADestra { get; set; } = false;
|
||||||
public bool FotoRuotaASinistra { get; set; } = false;
|
public bool FotoRuotaASinistra { get; set; } = false;
|
||||||
public string TempMinText { get; set; } = string.Empty;
|
public string TempMinText { get; set; } = string.Empty;
|
||||||
|
public bool OverwriteFiles { get; set; } = false;
|
||||||
}
|
}
|
||||||
|
|
@ -77,6 +77,18 @@ namespace ImageCatalog_2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool _overwriteImages;
|
||||||
|
|
||||||
|
public bool OverwriteImages
|
||||||
|
{
|
||||||
|
get => _overwriteImages;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_overwriteImages = value;
|
||||||
|
NotifyPropertyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private bool _uiEnabled = true;
|
private bool _uiEnabled = true;
|
||||||
|
|
||||||
public bool UiEnabled
|
public bool UiEnabled
|
||||||
|
|
|
||||||
1
imagecatalog/MainForm.Designer.cs
generated
1
imagecatalog/MainForm.Designer.cs
generated
|
|
@ -617,6 +617,7 @@ namespace ImageCatalog
|
||||||
//
|
//
|
||||||
// chkSovrascriviFile
|
// chkSovrascriviFile
|
||||||
//
|
//
|
||||||
|
chkSovrascriviFile.DataBindings.Add(new Binding("Checked", bindingSource1, "OverwriteImages", true, DataSourceUpdateMode.OnPropertyChanged));
|
||||||
chkSovrascriviFile.AutoSize = true;
|
chkSovrascriviFile.AutoSize = true;
|
||||||
chkSovrascriviFile.Location = new Point(21, 94);
|
chkSovrascriviFile.Location = new Point(21, 94);
|
||||||
chkSovrascriviFile.Margin = new Padding(4, 5, 4, 5);
|
chkSovrascriviFile.Margin = new Padding(4, 5, 4, 5);
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ public partial class MainForm
|
||||||
|
|
||||||
private ConcurrentBag<string> _results;
|
private ConcurrentBag<string> _results;
|
||||||
|
|
||||||
private void setDefaults()
|
private void SetDefaults()
|
||||||
{
|
{
|
||||||
//txtSorgente.Text = "";
|
//txtSorgente.Text = "";
|
||||||
Model.SourcePath = string.Empty;
|
Model.SourcePath = string.Empty;
|
||||||
|
|
@ -205,7 +205,7 @@ public partial class MainForm
|
||||||
{
|
{
|
||||||
bindingSource1.DataSource = Model;
|
bindingSource1.DataSource = Model;
|
||||||
Application.EnableVisualStyles();
|
Application.EnableVisualStyles();
|
||||||
setDefaults();
|
SetDefaults();
|
||||||
// /* TODO ERROR: Skipped IfDirectiveTrivia */
|
// /* TODO ERROR: Skipped IfDirectiveTrivia */
|
||||||
// AllocConsole();
|
// AllocConsole();
|
||||||
// /* TODO ERROR: Skipped EndIfDirectiveTrivia */
|
// /* TODO ERROR: Skipped EndIfDirectiveTrivia */
|
||||||
|
|
@ -318,10 +318,10 @@ public partial class MainForm
|
||||||
SaveFileDlg.Filter = "Setup (*.xml)|*.xml|All valid files (*.*)|*.*";
|
SaveFileDlg.Filter = "Setup (*.xml)|*.xml|All valid files (*.*)|*.*";
|
||||||
SaveFileDlg.FilterIndex = 0;
|
SaveFileDlg.FilterIndex = 0;
|
||||||
SaveFileDlg.RestoreDirectory = true;
|
SaveFileDlg.RestoreDirectory = true;
|
||||||
if (DialogResult.OK == SaveFileDlg.ShowDialog())
|
if (DialogResult.OK != SaveFileDlg.ShowDialog()) return;
|
||||||
{
|
|
||||||
string IlNome = SaveFileDlg.FileName;
|
var ilNome = SaveFileDlg.FileName;
|
||||||
_parametriSetup.NomeFileSetup = IlNome;
|
_parametriSetup.NomeFileSetup = ilNome;
|
||||||
_parametriSetup.AggiornaParametro("DirSorgente", Model.SourcePath);
|
_parametriSetup.AggiornaParametro("DirSorgente", Model.SourcePath);
|
||||||
_parametriSetup.AggiornaParametro("DirDestinazione", Model.DestinationPath);
|
_parametriSetup.AggiornaParametro("DirDestinazione", Model.DestinationPath);
|
||||||
_parametriSetup.AggiornaParametro("DirSottoDirectory", chkAggiornaSottodirectory.Checked);
|
_parametriSetup.AggiornaParametro("DirSottoDirectory", chkAggiornaSottodirectory.Checked);
|
||||||
|
|
@ -386,9 +386,9 @@ public partial class MainForm
|
||||||
// 2021
|
// 2021
|
||||||
_parametriSetup.AggiornaParametro("ChunkSize", TextBox8.Text);
|
_parametriSetup.AggiornaParametro("ChunkSize", TextBox8.Text);
|
||||||
_parametriSetup.AggiornaParametro("ThreadsCount", TextBox7.Text);
|
_parametriSetup.AggiornaParametro("ThreadsCount", TextBox7.Text);
|
||||||
|
_parametriSetup.AggiornaParametro("OverwriteImages", Model.OverwriteImages);
|
||||||
_parametriSetup.SalvaParametriSetup();
|
_parametriSetup.SalvaParametriSetup();
|
||||||
Text = "Image Catalog - " + LeggiSoloNomeFile(IlNome);
|
Text = "Image Catalog - " + LeggiSoloNomeFile(ilNome);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Button6_Click(object sender, EventArgs e)
|
private void Button6_Click(object sender, EventArgs e)
|
||||||
|
|
@ -471,6 +471,7 @@ public partial class MainForm
|
||||||
TextBox32.Text = _parametriSetup.LeggiParametroString("CompressioneJpeg");
|
TextBox32.Text = _parametriSetup.LeggiParametroString("CompressioneJpeg");
|
||||||
TextBox33.Text = _parametriSetup.LeggiParametroString("CompressioneJpegMiniatura");
|
TextBox33.Text = _parametriSetup.LeggiParametroString("CompressioneJpegMiniatura");
|
||||||
TextBox34.Text = _parametriSetup.LeggiParametroString("ColoreTestoRGB");
|
TextBox34.Text = _parametriSetup.LeggiParametroString("ColoreTestoRGB");
|
||||||
|
Model.OverwriteImages = _parametriSetup.LeggiParametroBoolean("OverwriteImages");
|
||||||
if (File.Exists(TextBox10.Text))
|
if (File.Exists(TextBox10.Text))
|
||||||
{
|
{
|
||||||
PictureBox1.Image = Image.FromFile(TextBox10.Text);
|
PictureBox1.Image = Image.FromFile(TextBox10.Text);
|
||||||
|
|
@ -572,6 +573,7 @@ public partial class MainForm
|
||||||
_picSettings.TestoMin = RadioButton6.Checked;
|
_picSettings.TestoMin = RadioButton6.Checked;
|
||||||
_picSettings.JpegQuality = int.Parse(TextBox32.Text);
|
_picSettings.JpegQuality = int.Parse(TextBox32.Text);
|
||||||
_picSettings.JpegQualityMin = int.Parse(TextBox33.Text);
|
_picSettings.JpegQualityMin = int.Parse(TextBox33.Text);
|
||||||
|
_picSettings.OverwriteFiles = Model.OverwriteImages;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<FileInfo> getFiles(DirectoryInfo sourceDir)
|
private List<FileInfo> getFiles(DirectoryInfo sourceDir)
|
||||||
|
|
|
||||||
|
|
@ -57,21 +57,21 @@ namespace ImageCatalog
|
||||||
return Risposta;
|
return Risposta;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool LeggiParametroBoolean(string NomeParametro)
|
public bool LeggiParametroBoolean(string nomeParametro)
|
||||||
{
|
{
|
||||||
string Risposta = "";
|
var risposta = "";
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var LElenco = _ElencoParametri.Tables["Setup"].Select("Nome='" + NomeParametro + "'");
|
var lElenco = _ElencoParametri.Tables["Setup"].Select("Nome='" + nomeParametro + "'");
|
||||||
foreach (var LaRiga in LElenco)
|
foreach (var laRiga in lElenco)
|
||||||
Risposta = LaRiga["Valore"].ToString();
|
risposta = laRiga["Valore"].ToString();
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
Risposta = "";
|
risposta = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (Risposta.ToUpper() ?? "")
|
switch (risposta.ToUpper() ?? "")
|
||||||
{
|
{
|
||||||
case "TRUE":
|
case "TRUE":
|
||||||
case "OK":
|
case "OK":
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,14 @@ using ImageCatalog_2.Services;
|
||||||
using MaddoShared;
|
using MaddoShared;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
|
using Microsoft.Extensions.Logging.Console;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace ImageCatalog_2
|
namespace ImageCatalog_2;
|
||||||
|
|
||||||
|
static class Program
|
||||||
{
|
{
|
||||||
static class Program
|
|
||||||
{
|
|
||||||
[DllImport("kernel32.dll", SetLastError = true)]
|
[DllImport("kernel32.dll", SetLastError = true)]
|
||||||
private static extern bool AllocConsole();
|
private static extern bool AllocConsole();
|
||||||
|
|
||||||
|
|
@ -92,9 +95,47 @@ namespace ImageCatalog_2
|
||||||
|
|
||||||
services.AddLogging(configure =>
|
services.AddLogging(configure =>
|
||||||
{
|
{
|
||||||
|
configure.AddCustomFormatter();
|
||||||
configure.AddConsole();
|
configure.AddConsole();
|
||||||
configure.SetMinimumLevel(LogLevel.Debug);
|
configure.SetMinimumLevel(LogLevel.Debug);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class ConsoleLoggerExtensions
|
||||||
|
{
|
||||||
|
public static ILoggingBuilder AddCustomFormatter(
|
||||||
|
this ILoggingBuilder builder) =>
|
||||||
|
builder.AddConsole(options => options.FormatterName = nameof(CustomLoggingFormatter))
|
||||||
|
.AddConsoleFormatter<CustomLoggingFormatter, ConsoleFormatterOptions>();
|
||||||
|
}
|
||||||
|
public sealed class CustomLoggingFormatter : ConsoleFormatter, IDisposable
|
||||||
|
{
|
||||||
|
private readonly IDisposable _optionsReloadToken;
|
||||||
|
private ConsoleFormatterOptions _formatterOptions;
|
||||||
|
public CustomLoggingFormatter(IOptionsMonitor<ConsoleFormatterOptions> options)
|
||||||
|
// Case insensitive
|
||||||
|
: base(nameof(CustomLoggingFormatter)) =>
|
||||||
|
(_optionsReloadToken, _formatterOptions) =
|
||||||
|
(options.OnChange(ReloadLoggerOptions), options.CurrentValue);
|
||||||
|
private void ReloadLoggerOptions(ConsoleFormatterOptions options) =>
|
||||||
|
_formatterOptions = options;
|
||||||
|
|
||||||
|
public override void Write<TState>(
|
||||||
|
in LogEntry<TState> logEntry,
|
||||||
|
IExternalScopeProvider scopeProvider,
|
||||||
|
TextWriter textWriter)
|
||||||
|
{
|
||||||
|
string? message =
|
||||||
|
logEntry.Formatter?.Invoke(
|
||||||
|
logEntry.State, logEntry.Exception);
|
||||||
|
|
||||||
|
if (message is null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
textWriter.WriteLine($"{message}");
|
||||||
|
}
|
||||||
|
public void Dispose() => _optionsReloadToken?.Dispose();
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue