2021-03-04 10:44:09 +01:00
using System ;
using System.Collections.Concurrent ;
using System.Collections.Generic ;
2025-07-08 14:35:27 +02:00
using System.ComponentModel ;
2021-03-04 10:44:09 +01:00
using System.Drawing ;
using System.Drawing.Text ;
using System.IO ;
using System.Linq ;
2024-10-14 19:57:24 +02:00
using System.Reflection ;
2021-03-04 10:44:09 +01:00
using System.Runtime.InteropServices ;
2025-07-23 15:08:25 +02:00
using System.Text ;
2021-03-04 10:44:09 +01:00
using System.Threading ;
using System.Threading.Tasks ;
using System.Windows.Forms ;
using CatalogVbLib ;
2024-10-14 22:55:52 +02:00
using ImageCatalog_2 ;
2024-10-14 22:18:03 +02:00
using ImageCatalog_2.Services ;
2021-03-04 10:44:09 +01:00
using MaddoShared ;
2025-07-23 15:08:25 +02:00
using Microsoft.Extensions.Logging ;
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
namespace ImageCatalog ;
public delegate void XyThreadAdd ( string Info ) ;
public partial class MainForm
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:49:55 +02:00
private readonly DataModel Model ;
2025-07-28 09:00:07 +02:00
private readonly ILogger < MainForm > _logger ;
private readonly ImageCreationStuff _imageCreationService ;
2021-03-04 10:44:09 +01:00
2025-07-28 09:15:45 +02:00
private readonly ParametriSetup _parametriSetup ;
2025-07-28 09:49:55 +02:00
public MainForm ( DataModel model , ImageCreationStuff imageCreationStuff , ParametriSetup parametriSetup , ILogger < MainForm > logger )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:49:55 +02:00
Model = model ;
2025-07-28 09:00:07 +02:00
_imageCreationService = imageCreationStuff ;
2025-07-28 09:15:45 +02:00
_parametriSetup = parametriSetup ;
2025-07-28 09:00:07 +02:00
_logger = logger ;
_logger . LogDebug ( "Start" ) ;
InitializeComponent ( ) ;
BindControls ( ) ;
_Button3 . Name = "Button3" ;
_Button2 . Name = "Button2" ;
_Button8 . Name = "Button8" ;
_CheckBox18 . Name = "CheckBox18" ;
_CheckBox4 . Name = "CheckBox4" ;
_CheckBox12 . Name = "CheckBox12" ;
_PictureBox1 . Name = "PictureBox1" ;
_Button4 . Name = "Button4" ;
_Label27 . Name = "Label27" ;
_Button7 . Name = "Button7" ;
_Button5 . Name = "Button5" ;
//_btnCreaCatalogo.Name = "btnCreaCatalogo";
_Button6 . Name = "Button6" ;
_btnCreaCatalogoAsync . Name = "btnCreaCatalogoAsync" ;
var version = Assembly . GetExecutingAssembly ( ) . GetName ( ) . Version ;
_Label27 . Text = $"Version: {version.Major}.{version.Minor}.{version.Build}.{version.Revision}" ;
_results = new ConcurrentBag < string > ( ) ;
UiUpdateEvent + = OnUiUpdateEvent ;
}
2024-10-14 22:55:52 +02:00
2025-07-28 09:00:07 +02:00
protected void BindControls ( )
{
//txtSorgente.DataBindings.Add(new Binding("Text", SourcePath, ""));
}
2024-10-14 22:18:03 +02:00
2025-07-28 09:00:07 +02:00
private event EventHandler < Tuple < string , int > > UiUpdateEvent ;
2025-07-23 17:16:06 +02:00
2025-07-28 09:00:07 +02:00
delegate void SetTextCallback ( Label target , string text ) ;
2024-10-14 22:55:52 +02:00
2025-07-28 09:00:07 +02:00
private void SetText ( Label target , string text )
{
if ( InvokeRequired )
2024-10-14 22:55:52 +02:00
{
2025-07-28 09:00:07 +02:00
SetTextCallback d = new SetTextCallback ( SetText ) ;
this . Invoke ( d , new object [ ] { target , text } ) ;
2024-10-14 22:55:52 +02:00
}
2025-07-28 09:00:07 +02:00
else
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
target . Text = text ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
}
2025-07-23 15:08:25 +02:00
2025-07-28 09:00:07 +02:00
delegate void SetProgressCallback ( ProgressBar target , int amount , int maximum ) ;
2025-07-23 15:08:25 +02:00
2025-07-28 09:00:07 +02:00
private void SetProgress ( ProgressBar target , int amount , int maximum )
{
if ( InvokeRequired )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
SetProgressCallback d = new SetProgressCallback ( SetProgress ) ;
this . Invoke ( d , new object [ ] { target , amount , maximum } ) ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
else
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
target . Maximum = maximum ;
target . Value = amount ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
private void OnUiUpdateEvent ( object sender , Tuple < string , int > args )
{
SetProgress ( ProgressBar1 , _results . Count , args . Item2 ) ;
SetText ( Label18 , _results . Count . ToString ( ) ) ;
SetText ( Label10 , args . Item1 ) ;
SetText ( lblFotoTotaliNum , args . Item2 . ToString ( ) ) ;
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
/* TODO ERROR: Skipped DefineDirectiveTrivia */
private bool StopAttivo ;
private bool WaterSelectColor = false ;
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// Private ContaFotoCuori As Integer
// Private TaskCuori() As PicInfo
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
private XYThreadPool MyPool = new XYThreadPool ( ) ;
private int ContaImmaginiThread ;
private int maxThreads = 15 ;
private int minThreads = 5 ;
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
private ConcurrentBag < string > _results ;
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
private void setDefaults ( )
{
//txtSorgente.Text = "";
Model . SourcePath = string . Empty ;
Model . DestinationPath = string . Empty ;
TextBox3 . Text = "tn_" ;
2025-07-28 09:49:55 +02:00
Model . HorizontalText = "" ;
2025-07-28 09:00:07 +02:00
TextBox5 . Text = "350" ;
TextBox6 . Text = "350" ;
TextBox27 . Text = "2240" ;
TextBox28 . Text = "2240" ;
TextBox9 . Text = "0" ;
TextBox11 . Text = "20" ;
TextBox12 . Text = "8" ;
// TextBox13.Text = ""
TextBox10 . Text = "" ;
TextBox14 . Text = "430" ;
TextBox15 . Text = "430" ;
TextBox16 . Text = "290" ;
txtFilePerCartella . Text = "99" ;
TextBox19 . Text = "100" ;
txtSuffissoCartelle . Text = "" ;
txtCifreContatore . Text = "2" ;
TextBox25 . Text = "50" ;
TextBox26 . Text = "" ;
TextBox7 . Text = 4. ToString ( ) ;
TextBox8 . Text = 4. ToString ( ) ;
TextBox34 . Text = "Yellow" ;
TextBox30 . Text = "20" ;
TextBox31 . Text = "6" ;
TextBox32 . Text = "85" ;
TextBox33 . Text = "30" ;
ComboBox1 . Items . Add ( "Alto" ) ;
ComboBox1 . Items . Add ( "Basso" ) ;
ComboBox1 . SelectedIndex = 1 ;
ComboBox2 . Items . Add ( "Sinistra" ) ;
ComboBox2 . Items . Add ( "Centro" ) ;
ComboBox2 . Items . Add ( "Destra" ) ;
ComboBox2 . SelectedIndex = 1 ;
// Create a obejct of InstalledFontCollection
var InstalledFonts = new InstalledFontCollection ( ) ;
// Gets the array of FontFamily objects associated with this FontCollection.
var fontfamilies = InstalledFonts . Families ;
// Populates font combobox with the font name
foreach ( FontFamily fontFamily in fontfamilies )
ComboBox3 . Items . Add ( fontFamily . Name ) ;
ComboBox3 . Text = ComboBox3 . Items [ 0 ] . ToString ( ) ;
// ComboBox3.Items.Add("Arial")
// ComboBox3.Items.Add("Arial Black")
// ComboBox3.Items.Add("Arial Narrow")
// ComboBox3.Items.Add("Comic Sans MS")
// ComboBox3.Items.Add("Courier New")
// ComboBox3.Items.Add("System")
// ComboBox3.Items.Add("Times New Roman")
// ComboBox3.Items.Add("Verdana")
// ComboBox3.Items.Add("Wingdings")
// ComboBox3.SelectedIndex = 7
ComboBox4 . Items . Add ( "Sinistra" ) ;
ComboBox4 . Items . Add ( "Centro" ) ;
ComboBox4 . Items . Add ( "Destra" ) ;
ComboBox4 . SelectedIndex = 2 ;
ComboBox5 . Items . Add ( "Alto" ) ;
ComboBox5 . Items . Add ( "Centro" ) ;
ComboBox5 . Items . Add ( "Basso" ) ;
ComboBox5 . SelectedIndex = 2 ;
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
private void Form1_Load ( object sender , EventArgs e )
{
bindingSource1 . DataSource = Model ;
Application . EnableVisualStyles ( ) ;
setDefaults ( ) ;
// /* TODO ERROR: Skipped IfDirectiveTrivia */
// AllocConsole();
// /* TODO ERROR: Skipped EndIfDirectiveTrivia */
_logger . LogInformation ( "Programma Avviato" ) ;
//Console.WriteLine("Programma avviato");
}
private void FixPaths ( )
{
Model . SourcePath = FixPath ( Model . SourcePath ) ;
Model . DestinationPath = FixPath ( Model . DestinationPath ) ;
}
private string FixPath ( string path )
{
if ( string . IsNullOrWhiteSpace ( path ) )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
return string . Empty ;
2025-07-23 15:08:25 +02:00
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// Trim leading/trailing quotes
path = path . Trim ( ) . Trim ( '"' ) ;
2025-07-23 15:08:25 +02:00
2025-07-28 09:00:07 +02:00
// Normalize directory separators
path = path . Replace ( '/' , Path . DirectorySeparatorChar )
. Replace ( '\\' , Path . DirectorySeparatorChar ) ;
2025-07-23 15:08:25 +02:00
2025-07-28 09:00:07 +02:00
// Remove trailing separators then add one back
path = path . TrimEnd ( Path . DirectorySeparatorChar ) + Path . DirectorySeparatorChar ;
2025-07-23 15:08:25 +02:00
2025-07-28 09:00:07 +02:00
return path ;
}
2025-07-23 15:08:25 +02:00
2025-07-28 09:00:07 +02:00
private void lockUI ( )
{
Model . UiEnabled = false ;
//TabControl1.Enabled = false;
//Button5.Enabled = false;
//Button6.Enabled = false;
//btnCreaCatalogoAsync.Enabled = false;
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
private void unlockUI ( )
{
Model . UiEnabled = true ;
//TabControl1.Enabled = true;
//Button5.Enabled = true;
//Button6.Enabled = true;
//btnCreaCatalogoAsync.Enabled = true;
}
private void creaCatalogoThread ( )
{
var timeStart = DateTime . Now ;
MyPool . StopThreadPool ( ) ;
MyPool . StartThreadPool ( minThreads , maxThreads ) ;
ContaImmaginiThread = 0 ;
// creaImmaginiWithThreadMod(txtSorgente.Text, txtDestinazione.Text)
CreaimmaginiWithThreadDict ( Model . SourcePath , Model . DestinationPath ) ;
ThreadPoolWorkItem ThAttivo = null ;
int i = 0 ;
/* TODO ERROR: Skipped DefineDirectiveTrivia */
/* TODO ERROR: Skipped IfDirectiveTrivia */
while ( i ! = ContaImmaginiThread )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
Thread . Sleep ( 100 ) ;
ThAttivo = MyPool . ExtractWorkItem ( ) ;
if ( ThAttivo is object )
{
i + = 1 ;
// stepProgressBar()
int threads = MyPool . GetThreadCount ( ) ;
setLabel10Text ( "File: " + ThAttivo . m_sName + " Threads: " + threads . ToString ( ) ) ;
// setLabel18Text(ContaImmaginiThread.ToString)
// setLabel18Text(i.ToString)
// Label10.Text = "File: " & ThAttivo.m_sName
// Label18.Text = ContaImmaginiThread.ToString
}
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
MyPool . StopThreadPool ( ) ;
var timeStop = DateTime . Now ;
setLabel10Text ( "Finito" ) ;
setLabel43Text ( CalcTime ( timeStart , timeStop , ContaImmaginiThread ) ) ;
/* TODO ERROR: Skipped EndIfDirectiveTrivia */
}
private string CalcTime ( DateTime timeStart , DateTime timeStop , int numFoto )
{
long timediffH , timediffS ;
long timediffM ;
TimeSpan timeDiff = timeStop - timeStart ;
timediffM = ( int ) timeDiff . TotalMinutes ;
timediffS = ( int ) timeDiff . TotalSeconds ;
timediffH = ( int ) timeDiff . TotalHours ;
// timediffM = DateAndTime.DateDiff(DateInterval.Minute, timeStart, timeStop);
// timediffS = DateAndTime.DateDiff(DateInterval.Second, timeStart, timeStop);
// timediffH = DateAndTime.DateDiff(DateInterval.Hour, timeStart, timeStop);
double fotoSec = numFoto / ( double ) timediffS ;
double fotoMin = numFoto / ( double ) timediffM ;
double fotoOra = numFoto / ( double ) timediffH ;
string s = "S: " + timediffS . ToString ( ) + "; F/s: " +
fotoSec . ToString (
"0.000" ) ; // + " F/m: " + fotoMin.ToString("0.00") + " F/h: " + fotoOra.ToString("0.00")
return s ;
}
private string SelectFolder ( string startingFolder )
{
var dialog = new FolderBrowserDialog ( ) ;
dialog . InitialDirectory = startingFolder ;
if ( dialog . ShowDialog ( ) ! = DialogResult . OK ) return string . Empty ;
// CommonOpenFileDialog dialog = new CommonOpenFileDialog
// {
// InitialDirectory = startingFolder,
// IsFolderPicker = true
// };
// if (dialog.ShowDialog() != CommonFileDialogResult.Ok) return null;
var directoryScelta = FixPath ( dialog . SelectedPath ) ; // dialog.FileName;
// if (directoryScelta.EndsWith(@"\") == false)
// {
// directoryScelta += @"\";
// }
return directoryScelta ;
}
private void Button2_Click ( object sender , EventArgs e )
{
var dialogResult = SelectFolder ( Model . SourcePath ) ;
if ( ! string . IsNullOrWhiteSpace ( dialogResult ) )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
Model . SourcePath = dialogResult ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
//CommonOpenFileDialog dialog = new CommonOpenFileDialog();
//dialog.InitialDirectory = txtSorgente.Text;
//dialog.IsFolderPicker = true;
//if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
//{
// string directoryScelta = dialog.FileName;
// if (directoryScelta.EndsWith(@"\") == false)
// {
// directoryScelta += @"\";
// }
// txtSorgente.Text = directoryScelta;
//}
//var DirSearch = new FolderBrowserDialog();
//DirSearch.SelectedPath = txtSorgente.Text;
//if (DialogResult.OK == DirSearch.ShowDialog())
//{
// string DirectoryScelta = DirSearch.SelectedPath;
// if (DirectoryScelta.EndsWith(@"\") == false)
// {
// DirectoryScelta += @"\";
// }
// txtSorgente.Text = DirectoryScelta;
//}
}
private void Button3_Click ( object sender , EventArgs e )
{
var dialogResult = SelectFolder ( Model . DestinationPath ) ;
if ( ! string . IsNullOrWhiteSpace ( dialogResult ) )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
Model . DestinationPath = dialogResult ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
}
private void Button5_Click ( object sender , EventArgs e )
{
var SaveFileDlg = new SaveFileDialog ( ) ;
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// SaveFileDlg.InitialDirectory = "c:\"
SaveFileDlg . Filter = "Setup (*.xml)|*.xml|All valid files (*.*)|*.*" ;
SaveFileDlg . FilterIndex = 0 ;
SaveFileDlg . RestoreDirectory = true ;
if ( DialogResult . OK = = SaveFileDlg . ShowDialog ( ) )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
string IlNome = SaveFileDlg . FileName ;
2025-07-28 09:15:45 +02:00
_parametriSetup . NomeFileSetup = IlNome ;
_parametriSetup . AggiornaParametro ( "DirSorgente" , Model . SourcePath ) ;
_parametriSetup . AggiornaParametro ( "DirDestinazione" , Model . DestinationPath ) ;
_parametriSetup . AggiornaParametro ( "DirSottoDirectory" , chkAggiornaSottodirectory . Checked ) ;
_parametriSetup . AggiornaParametro ( "DirDividiDestinazione" , chkCreaSottocartelle . Checked ) ;
_parametriSetup . AggiornaParametro ( "DirDividiNumFile" , txtFilePerCartella . Text ) ;
_parametriSetup . AggiornaParametro ( "DirDividiSuffisso" , txtSuffissoCartelle . Text ) ;
_parametriSetup . AggiornaParametro ( "DirDividiNumCifre" , txtCifreContatore . Text ) ;
2025-07-28 09:00:07 +02:00
if ( rdbNumProgressiva . Checked = = true )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:15:45 +02:00
_parametriSetup . AggiornaParametro ( "DirDividiTipoNumerazione" , "Progressiva" ) ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
else
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:15:45 +02:00
_parametriSetup . AggiornaParametro ( "DirDividiTipoNumerazione" , "Files" ) ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:15:45 +02:00
_parametriSetup . AggiornaParametro ( "MiniatureCrea" , CheckBox1 . Checked ) ;
_parametriSetup . AggiornaParametro ( "MiniatureSuffisso" , TextBox3 . Text ) ;
_parametriSetup . AggiornaParametro ( "MiniatureAltezza" , TextBox5 . Text ) ;
_parametriSetup . AggiornaParametro ( "MiniatureLarghezza" , TextBox6 . Text ) ;
_parametriSetup . AggiornaParametro ( "MiniatureAddScritta" , RadioButton3 . Checked ) ;
_parametriSetup . AggiornaParametro ( "MiniatureAddOrario" , RadioButton4 . Checked ) ;
_parametriSetup . AggiornaParametro ( "FotoAltezza" , TextBox27 . Text ) ;
_parametriSetup . AggiornaParametro ( "FotoLarghezza" , TextBox28 . Text ) ;
2025-07-28 09:00:07 +02:00
// SetupIni.AggiornaParametro("FotoCodice", TextBox13.Text)
// SetupIni.AggiornaParametro("FotoDimOriginali", CheckBox2.Checked)
2025-07-28 09:15:45 +02:00
_parametriSetup . AggiornaParametro ( "FontDimensione" , TextBox11 . Text ) ;
_parametriSetup . AggiornaParametro ( "FontDimensioneMiniatura" , TextBox25 . Text ) ;
_parametriSetup . AggiornaParametro ( "FontBold" , CheckBox3 . Checked ) ;
_parametriSetup . AggiornaParametro ( "FontNome" , ComboBox3 . Text ) ;
2025-07-28 09:49:55 +02:00
_parametriSetup . AggiornaParametro ( "TestoTesto" , Model . HorizontalText ) ;
2025-07-28 09:15:45 +02:00
_parametriSetup . AggiornaParametro ( "TestoTrasparente" , TextBox9 . Text ) ;
_parametriSetup . AggiornaParametro ( "TestoMargine" , TextBox12 . Text ) ;
_parametriSetup . AggiornaParametro ( "TestoPosizione" , ComboBox1 . Text ) ;
_parametriSetup . AggiornaParametro ( "TestoAllineamento" , ComboBox2 . Text ) ;
_parametriSetup . AggiornaParametro ( "MarchioFile" , TextBox10 . Text ) ;
_parametriSetup . AggiornaParametro ( "MarchioAltezza" , TextBox14 . Text ) ;
_parametriSetup . AggiornaParametro ( "MarchioLarghezza" , TextBox15 . Text ) ;
_parametriSetup . AggiornaParametro ( "MarchioMargine" , TextBox16 . Text ) ;
_parametriSetup . AggiornaParametro ( "MarchioAllOrizzontale" , ComboBox4 . Text ) ;
_parametriSetup . AggiornaParametro ( "MarchioAllVerticale" , ComboBox5 . Text ) ;
_parametriSetup . AggiornaParametro ( "MarchioTrasparenza" , TextBox19 . Text ) ;
_parametriSetup . AggiornaParametro ( "MarchioAggiungi" , CheckBox5 . Checked ) ;
_parametriSetup . AggiornaParametro ( "TempoGara" , CheckBox7 . Checked ) ;
_parametriSetup . AggiornaParametro ( "Orario" , CheckBox8 . Checked ) ;
_parametriSetup . AggiornaParametro ( "EtichettaOrario" , TextBox18 . Text ) ;
_parametriSetup . AggiornaParametro ( "GeneraleForzaJpg" , chkForzaJpg . Checked ) ;
_parametriSetup . AggiornaParametro ( "GeneraleRotazioneAutomatica" , chkRotazioneAutomatica . Checked ) ;
_parametriSetup . AggiornaParametro ( "GrandezzaVerticale" , TextBox30 . Text ) ;
_parametriSetup . AggiornaParametro ( "MargineVerticale" , TextBox31 . Text ) ;
_parametriSetup . AggiornaParametro ( "DimensioniOriginali" , CheckBox15 . Checked ) ;
_parametriSetup . AggiornaParametro ( "TestoVerticale" , TextBox29 . Text ) ;
_parametriSetup . AggiornaParametro ( "NomeMiniatura" , RadioButton6 . Checked ) ;
_parametriSetup . AggiornaParametro ( "DataFoto" , CheckBox16 . Checked ) ;
_parametriSetup . AggiornaParametro ( "NumeroFoto" , CheckBox17 . Checked ) ;
_parametriSetup . AggiornaParametro ( "ColoreTestoRGB" , TextBox34 . Text ) ;
_parametriSetup . AggiornaParametro ( "TempoSmall" , RadioButton5 . Checked ) ;
_parametriSetup . AggiornaParametro ( "NumTempoSmall" , RadioButton7 . Checked ) ;
_parametriSetup . AggiornaParametro ( "CompressioneJpeg" , TextBox32 . Text ) ;
_parametriSetup . AggiornaParametro ( "CompressioneJpegMiniatura" , TextBox33 . Text ) ;
2025-07-28 09:00:07 +02:00
// 2021
2025-07-28 09:15:45 +02:00
_parametriSetup . AggiornaParametro ( "ChunkSize" , TextBox8 . Text ) ;
_parametriSetup . AggiornaParametro ( "ThreadsCount" , TextBox7 . Text ) ;
_parametriSetup . SalvaParametriSetup ( ) ;
2025-07-28 09:00:07 +02:00
Text = "Image Catalog - " + LeggiSoloNomeFile ( IlNome ) ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
private void Button6_Click ( object sender , EventArgs e )
{
var openFileDialog = new OpenFileDialog ( ) ;
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// openFileDialog.InitialDirectory = TextBox1.Text
openFileDialog . Filter = "Setup (*.xml)|*.xml|All valid files (*.*)|*.*" ;
openFileDialog . FilterIndex = 0 ;
openFileDialog . RestoreDirectory = true ;
if ( DialogResult . OK = = openFileDialog . ShowDialog ( ) )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
string IlNome = openFileDialog . FileName ;
2025-07-28 09:15:45 +02:00
_parametriSetup . NomeFileSetup = IlNome ;
_parametriSetup . CaricaParametriSetup ( ) ;
Model . SourcePath = _parametriSetup . LeggiParametroString ( "DirSorgente" ) ;
Model . DestinationPath = _parametriSetup . LeggiParametroString ( "DirDestinazione" ) ;
chkAggiornaSottodirectory . Checked = _parametriSetup . LeggiParametroBoolean ( "DirSottoDirectory" ) ;
chkCreaSottocartelle . Checked = _parametriSetup . LeggiParametroBoolean ( "DirDividiDestinazione" ) ;
txtFilePerCartella . Text = _parametriSetup . LeggiParametroString ( "DirDividiNumFile" ) ;
txtSuffissoCartelle . Text = _parametriSetup . LeggiParametroString ( "DirDividiSuffisso" ) ;
txtCifreContatore . Text = _parametriSetup . LeggiParametroString ( "DirDividiNumCifre" ) ;
string TestoTemp = _parametriSetup . LeggiParametroString ( "DirDividiTipoNumerazione" ) ;
2025-07-28 09:00:07 +02:00
if ( TestoTemp . ToUpper ( ) = = "PROGRESSIVA" )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
rdbNumProgressiva . Checked = true ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
else
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
rdbNumFiles . Checked = true ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:15:45 +02:00
CheckBox1 . Checked = _parametriSetup . LeggiParametroBoolean ( "MiniatureCrea" ) ;
TextBox3 . Text = _parametriSetup . LeggiParametroString ( "MiniatureSuffisso" ) ;
TextBox5 . Text = _parametriSetup . LeggiParametroString ( "MiniatureAltezza" ) ;
TextBox6 . Text = _parametriSetup . LeggiParametroString ( "MiniatureLarghezza" ) ;
RadioButton3 . Checked = _parametriSetup . LeggiParametroBoolean ( "MiniatureAddScritta" ) ;
RadioButton4 . Checked = _parametriSetup . LeggiParametroBoolean ( "MiniatureAddOrario" ) ;
TextBox27 . Text = _parametriSetup . LeggiParametroString ( "FotoAltezza" ) ;
TextBox28 . Text = _parametriSetup . LeggiParametroString ( "FotoLarghezza" ) ;
2025-07-28 09:00:07 +02:00
// TextBox13.Text = SetupIni.LeggiParametroString("FotoCodice")
// CheckBox2.Checked = SetupIni.LeggiParametroBoolean("FotoDimOriginali")
2025-07-28 09:15:45 +02:00
TextBox11 . Text = _parametriSetup . LeggiParametroString ( "FontDimensione" ) ;
TextBox25 . Text = _parametriSetup . LeggiParametroString ( "FontDimensioneMiniatura" ) ;
CheckBox3 . Checked = _parametriSetup . LeggiParametroBoolean ( "FontBold" ) ;
ComboBox3 . Text = _parametriSetup . LeggiParametroString ( "FontNome" ) ;
2025-07-28 09:00:07 +02:00
if ( string . IsNullOrEmpty ( TextBox25 . Text ) )
{
TextBox25 . Text = "0" ;
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:49:55 +02:00
Model . HorizontalText = _parametriSetup . LeggiParametroString ( "TestoTesto" ) ;
2025-07-28 09:15:45 +02:00
TextBox9 . Text = _parametriSetup . LeggiParametroString ( "TestoTrasparente" ) ;
TextBox12 . Text = _parametriSetup . LeggiParametroString ( "TestoMargine" ) ;
ComboBox1 . Text = _parametriSetup . LeggiParametroString ( "TestoPosizione" ) ;
ComboBox2 . Text = _parametriSetup . LeggiParametroString ( "TestoAllineamento" ) ;
TextBox10 . Text = _parametriSetup . LeggiParametroString ( "MarchioFile" ) ;
TextBox14 . Text = _parametriSetup . LeggiParametroString ( "MarchioAltezza" ) ;
TextBox15 . Text = _parametriSetup . LeggiParametroString ( "MarchioLarghezza" ) ;
TextBox16 . Text = _parametriSetup . LeggiParametroString ( "MarchioMargine" ) ;
ComboBox4 . Text = _parametriSetup . LeggiParametroString ( "MarchioAllOrizzontale" ) ;
ComboBox5 . Text = _parametriSetup . LeggiParametroString ( "MarchioAllVerticale" ) ;
TextBox19 . Text = _parametriSetup . LeggiParametroString ( "MarchioTrasparenza" ) ;
CheckBox5 . Checked = _parametriSetup . LeggiParametroBoolean ( "MarchioAggiungi" ) ;
CheckBox7 . Checked = _parametriSetup . LeggiParametroBoolean ( "TempoGara" ) ;
CheckBox8 . Checked = _parametriSetup . LeggiParametroBoolean ( "Orario" ) ;
TextBox18 . Text = _parametriSetup . LeggiParametroString ( "EtichettaOrario" ) ;
chkForzaJpg . Checked = _parametriSetup . LeggiParametroBoolean ( "GeneraleForzaJpg" ) ;
chkRotazioneAutomatica . Checked = _parametriSetup . LeggiParametroBoolean ( "GeneraleRotazioneAutomatica" ) ;
TextBox30 . Text = _parametriSetup . LeggiParametroString ( "GrandezzaVerticale" ) ;
TextBox31 . Text = _parametriSetup . LeggiParametroString ( "MargineVerticale" ) ;
CheckBox15 . Checked = _parametriSetup . LeggiParametroBoolean ( "DimensioniOriginali" ) ;
TextBox29 . Text = _parametriSetup . LeggiParametroString ( "TestoVerticale" ) ;
RadioButton6 . Checked = _parametriSetup . LeggiParametroBoolean ( "NomeMiniatura" ) ;
CheckBox16 . Checked = _parametriSetup . LeggiParametroBoolean ( "DataFoto" ) ;
CheckBox17 . Checked = _parametriSetup . LeggiParametroBoolean ( "NumeroFoto" ) ;
RadioButton5 . Checked = _parametriSetup . LeggiParametroBoolean ( "TempoSmall" ) ;
RadioButton7 . Checked = _parametriSetup . LeggiParametroBoolean ( "NumTempoSmall" ) ;
TextBox32 . Text = _parametriSetup . LeggiParametroString ( "CompressioneJpeg" ) ;
TextBox33 . Text = _parametriSetup . LeggiParametroString ( "CompressioneJpegMiniatura" ) ;
TextBox34 . Text = _parametriSetup . LeggiParametroString ( "ColoreTestoRGB" ) ;
2025-07-28 09:00:07 +02:00
if ( File . Exists ( TextBox10 . Text ) )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
PictureBox1 . Image = Image . FromFile ( TextBox10 . Text ) ;
if ( PictureBox1 . Image . Height > = PictureBox1 . Image . Width )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
PictureBox1 . Height = 160 ;
PictureBox1 . Width =
( int ) ( 160 * PictureBox1 . Image . Width / ( double ) PictureBox1 . Image . Height ) ;
2021-03-04 10:44:09 +01:00
}
else
{
2025-07-28 09:00:07 +02:00
PictureBox1 . Width = 224 ;
PictureBox1 . Height =
( int ) ( 224 * PictureBox1 . Image . Height / ( double ) PictureBox1 . Image . Width ) ;
2021-03-04 10:44:09 +01:00
}
}
2025-07-28 09:00:07 +02:00
Text = "Image Catalog - " + LeggiSoloNomeFile ( IlNome ) ;
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// 2021
2025-07-28 09:15:45 +02:00
TextBox8 . Text = _parametriSetup . LeggiParametroString ( "ChunkSize" ) ;
TextBox7 . Text = _parametriSetup . LeggiParametroString ( "ThreadsCount" ) ;
2025-07-28 09:00:07 +02:00
}
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
private void setPicSettings ( string SourcePath , string DestPath )
{
var SourceDir = new DirectoryInfo ( SourcePath ) ;
var DestDirStart = new DirectoryInfo ( DestPath ) ;
DirectoryInfo DestDir = null ;
PicSettings . DirectorySorgente = SourcePath ;
PicSettings . DirectoryDestinazione = Model . DestinationPath ;
// PicSettings.DestDir = DestDir
// PicSettings.SourceDir = SourceDir
// PicSettings.DestDirStart = DestDirStart
PicSettings . DimStandard = int . Parse ( TextBox11 . Text ) ;
PicSettings . DimStandardMiniatura = int . Parse ( TextBox25 . Text ) ;
PicSettings . UsaOrarioMiniatura = CheckBox12 . Checked ;
PicSettings . UsaOrarioTestoApplicare = CheckBox8 . Checked ;
PicSettings . UsaTempoGaraTestoApplicare = CheckBox7 . Checked ;
PicSettings . UsaRotazioneAutomatica = chkRotazioneAutomatica . Checked ;
PicSettings . UsaForzaJpg = chkForzaJpg . Checked ;
if ( CheckBox17 . Checked )
{
PicSettings . TestoNome = true ;
}
else
{
PicSettings . TestoNome = false ;
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
if ( CheckBox16 . Checked )
{
PicSettings . NomeData = true ;
}
else
{
PicSettings . NomeData = false ;
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:49:55 +02:00
PicSettings . TestoFirmaStart = Model . HorizontalText ;
2025-07-28 09:00:07 +02:00
PicSettings . TestoFirmaStartV = TextBox29 . Text ;
PicSettings . DataPartenza = DateTimePicker1 . Value ;
PicSettings . TestoOrario = TextBox18 . Text ;
PicSettings . AltezzaSmall = int . Parse ( TextBox6 . Text ) ;
PicSettings . LarghezzaSmall = int . Parse ( TextBox5 . Text ) ;
PicSettings . CreaMiniature = CheckBox1 . Checked ;
PicSettings . AggiungiScritteMiniature = RadioButton3 . Checked ;
PicSettings . AggTempoGaraMin = RadioButton5 . Checked ;
PicSettings . AggNumTempMin = RadioButton7 . Checked ;
PicSettings . DimVert = int . Parse ( TextBox30 . Text ) ;
PicSettings . MargVert = int . Parse ( TextBox31 . Text ) ;
// PicSettings.NomeFileChild = childFile.Name
PicSettings . Suffisso = TextBox3 . Text ;
// PicSettings.Codice = TextBox13.Text
PicSettings . Trasparenza = int . Parse ( TextBox9 . Text ) ;
PicSettings . IlFont = ComboBox3 . SelectedItem . ToString ( ) ;
PicSettings . Grassetto = CheckBox3 . Checked ;
PicSettings . Posizione = ComboBox1 . SelectedItem . ToString ( ) ;
PicSettings . Allineamento = ComboBox2 . SelectedItem . ToString ( ) ;
PicSettings . Margine = int . Parse ( TextBox12 . Text ) ;
PicSettings . LogoAltezza = int . Parse ( TextBox14 . Text ) ;
PicSettings . LogoLarghezza = int . Parse ( TextBox15 . Text ) ;
PicSettings . fontColoreRGB = ColorTranslator . FromHtml ( TextBox34 . Text ) ;
PicSettings . LogoAggiungi = CheckBox5 . Checked ;
PicSettings . LogoNomeFile = TextBox10 . Text ;
PicSettings . LogoTrasparenza = TextBox19 . Text ;
PicSettings . LogoMargine = TextBox16 . Text ;
PicSettings . LogoPosizioneH = ComboBox4 . Text ;
PicSettings . LogoPosizioneV = ComboBox5 . Text ;
PicSettings . FotoGrandeDimOrigina = CheckBox15 . Checked ;
PicSettings . AltezzaBig = int . Parse ( TextBox27 . Text ) ;
PicSettings . LarghezzaBig = int . Parse ( TextBox28 . Text ) ;
PicSettings . DimMin = int . Parse ( TextBox25 . Text ) ;
PicSettings . TestoMin = RadioButton6 . Checked ;
PicSettings . jpegQuality = int . Parse ( TextBox32 . Text ) ;
PicSettings . jpegQualityMin = int . Parse ( TextBox33 . Text ) ;
PicSettings . mainForm = this ;
}
2021-03-04 17:23:44 +01:00
2025-07-28 09:00:07 +02:00
private List < List < FileInfo > > makeFilesList ( string SourcePath )
{
var SourceDir = new DirectoryInfo ( SourcePath ) ;
DirectoryInfo DestDir = null ;
int NumFileXDir = int . Parse ( txtFilePerCartella . Text ) ;
string SuffixDir = txtSuffissoCartelle . Text ;
int NumCifreDir = int . Parse ( txtCifreContatore . Text ) ;
bool DividiFile = false ;
StopAttivo = false ;
int FileConta = 0 ;
int ContaFileXDir = 0 ;
int ContaDirXDir = 0 ;
string TestoTemp = "" ;
int ContaTemp = 0 ;
var picList = new List < FileInfo > ( ) ;
var dirList = new List < List < FileInfo > > ( ) ;
// controlla directory principale
// Dim childFile As FileInfo
// For Each childFile In SourceDir.GetFiles("*.jpg")
// picList.Add(childFile)
// Next
// picList = getFiles(SourceDir, SearchOption.AllDirectories)
// dirList.Add(picList)
// controlla sottodirectory
if ( chkAggiornaSottodirectory . Checked = = true )
{
foreach ( var subDir in SourceDir . GetDirectories ( ) )
{
var filesList = new List < FileInfo > ( ) ;
filesList = getFiles ( subDir ) ;
dirList . Add ( filesList ) ;
2021-03-04 10:44:09 +01:00
}
}
2025-07-28 09:00:07 +02:00
return dirList ;
}
private List < FileInfo > getFiles ( DirectoryInfo sourceDir )
{
var picList = new List < FileInfo > ( ) ;
foreach ( var childFile in sourceDir . GetFiles ( "*.jpg" ) )
picList . Add ( childFile ) ;
return picList ;
}
private Dictionary < FileInfo , DirectoryInfo > getDirsDict ( string SourcePath , string DestPath )
{
var SourceDir = new DirectoryInfo ( SourcePath ) ;
var DestDirStart = new DirectoryInfo ( DestPath ) ;
DirectoryInfo DestDir = null ;
int NumFileXDir = int . Parse ( txtFilePerCartella . Text ) ;
string SuffixDir = txtSuffissoCartelle . Text ;
int NumCifreDir = int . Parse ( txtCifreContatore . Text ) ;
bool DividiFile = false ;
StopAttivo = false ;
int FileConta = 0 ;
int ContaFileXDir = 0 ;
int ContaDirXDir = 0 ;
// Dim TestoTemp As String = ""
// Dim ContaTemp As Integer = 0
var dirSourceDest = new Dictionary < FileInfo , DirectoryInfo > ( ) ;
if ( SourceDir . Exists )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
if ( chkAggiornaSottodirectory . Checked )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
FileConta = SourceDir . GetFiles ( "*.jpg" , SearchOption . AllDirectories ) . GetLength ( 0 ) ;
2021-03-04 10:44:09 +01:00
}
else
{
2025-07-28 09:00:07 +02:00
FileConta = SourceDir . GetFiles ( "*.jpg" , SearchOption . TopDirectoryOnly ) . GetLength ( 0 ) ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
var a = ( int . Parse ( lblFotoTotaliNum . Text ) + FileConta ) ;
setLabel17Text ( a . ToString ( ) ) ;
setProgressBarMaximum ( a ) ;
if ( chkAggiornaSottodirectory . Checked )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
foreach ( DirectoryInfo directory in SourceDir . GetDirectories ( ) )
{
foreach ( FileInfo file in directory . GetFiles ( ".jpg" ) )
{
}
}
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
foreach ( FileInfo file in SourceDir . GetFiles ( "*.jpg" , SearchOption . AllDirectories ) )
2021-03-04 10:44:09 +01:00
{
}
2025-07-28 09:00:07 +02:00
if ( NumFileXDir > 0 & chkCreaSottocartelle . Checked = = true & FileConta > NumFileXDir )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
DividiFile = true ;
}
else
{
DestDir = DestDirStart ;
if ( ! DestDir . Exists )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
DestDir . Create ( ) ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
DividiFile = false ;
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
var filesList = new List < FileInfo > ( ) ;
if ( chkAggiornaSottodirectory . Checked )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
filesList . AddRange ( SourceDir . GetFiles ( "*.jpg" , SearchOption . AllDirectories ) ) ;
filesList . AddRange ( SourceDir . GetFiles ( "*.png" , SearchOption . AllDirectories ) ) ;
}
else
{
filesList . AddRange ( SourceDir . GetFiles ( "*.jpg" , SearchOption . TopDirectoryOnly ) ) ;
filesList . AddRange ( SourceDir . GetFiles ( "*.png" , SearchOption . TopDirectoryOnly ) ) ;
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
foreach ( FileInfo file in filesList )
{
ContaFileXDir + = 1 ;
if ( DividiFile = = true )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
if ( ContaFileXDir = = ContaDirXDir * NumFileXDir + 1 )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
ContaDirXDir + = 1 ;
string TestoTemp ;
if ( rdbNumProgressiva . Checked = = true )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
TestoTemp = ContaDirXDir . ToString ( ) ;
}
else
{
TestoTemp = ( ContaDirXDir * NumFileXDir ) . ToString ( ) ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
for ( int ContaTemp = 1 , loopTo = NumCifreDir - TestoTemp . Length ;
ContaTemp < = loopTo ;
ContaTemp + + )
TestoTemp = "0" + TestoTemp ;
DestDir = new DirectoryInfo ( Path . Combine ( DestDirStart . FullName , SuffixDir , TestoTemp ) ) ;
// DestDir = New DirectoryInfo(DestDirStart.FullName & IIf(Not DestDirStart.FullName.EndsWith("\"), "\", String.Empty).ToString & SuffixDir & TestoTemp)
dirSourceDest . Add ( file , DestDir ) ;
if ( ! DestDir . Exists )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
DestDir . Create ( ) ;
2021-03-04 10:44:09 +01:00
}
}
}
}
}
2025-07-28 09:00:07 +02:00
return dirSourceDest ;
}
private void setLabel17Text ( string text )
{
if ( lblFotoTotaliNum . InvokeRequired )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
lblFotoTotaliNum . Invoke ( new Action < string > ( setLabel17Text ) , text ) ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
else
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
lblFotoTotaliNum . Text = text ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
private void setLabel10Text ( string text )
{
if ( Label10 . InvokeRequired )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
Label10 . Invoke ( new Action < string > ( setLabel10Text ) , text ) ;
}
else
{
Label10 . Text = text ;
}
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
public void stepProgressBar ( )
{
if ( ProgressBar1 . InvokeRequired )
{
ProgressBar1 . Invoke ( new System . Windows . Forms . MethodInvoker ( ProgressBar1 . PerformStep ) ) ;
}
else
{
ProgressBar1 . PerformStep ( ) ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
setLabel18Text ( ProgressBar1 . Value . ToString ( ) ) ;
}
private void setProgressBarMaximum ( int value )
{
if ( ProgressBar1 . InvokeRequired )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
ProgressBar1 . Invoke ( new Action < int > ( setProgressBarMaximum ) , ( object ) value ) ;
}
else
{
ProgressBar1 . Maximum = value ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
private void setProgressBarValue ( int value )
{
if ( ProgressBar1 . InvokeRequired )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
ProgressBar1 . Invoke ( new Action < int > ( setProgressBarValue ) , ( object ) value ) ;
}
else
{
ProgressBar1 . Value = value ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
private void setLabel18Text ( string text )
{
if ( Label18 . InvokeRequired )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
Label18 . Invoke ( new Action < string > ( setLabel18Text ) , text ) ;
}
else
{
Label18 . Text = text ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
private void setLabel43Text ( string text )
{
if ( Label43 . InvokeRequired )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
Label43 . Invoke ( new Action < string > ( setLabel43Text ) , text ) ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
else
{
Label43 . Text = text ;
}
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
private void creaImmaginiWithThreadMod ( string SourcePath , string DestPath )
{
var SourceDir = new DirectoryInfo ( SourcePath ) ;
var DestDirStart = new DirectoryInfo ( DestPath ) ;
DirectoryInfo DestDir = null ;
int NumFileXDir = int . Parse ( txtFilePerCartella . Text ) ;
string SuffixDir = txtSuffissoCartelle . Text ;
int NumCifreDir = int . Parse ( txtCifreContatore . Text ) ;
bool DividiFile = false ;
StopAttivo = false ;
int FileConta = 0 ;
int ContaFileXDir = 0 ;
int ContaDirXDir = 0 ;
string TestoTemp = "" ;
int ContaTemp = 0 ;
if ( SourceDir . Exists )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
FileConta = SourceDir . GetFiles ( "*.jpg" ) . GetLength ( 0 ) ;
// Label17.Text = (CType(Label17.Text, Integer) + FileConta).ToString
var a = ( int . Parse ( lblFotoTotaliNum . Text ) + FileConta ) ;
setLabel17Text ( a . ToString ( ) ) ;
setProgressBarMaximum ( a ) ;
if ( NumFileXDir > 0 & chkCreaSottocartelle . Checked = = true )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
if ( FileConta > NumFileXDir )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
DividiFile = true ;
2021-03-04 10:44:09 +01:00
}
else
{
DestDir = DestDirStart ;
if ( ! DestDir . Exists )
{
DestDir . Create ( ) ;
}
2025-07-28 09:00:07 +02:00
DividiFile = false ;
}
}
else
{
DestDir = DestDirStart ;
if ( ! DestDir . Exists )
{
DestDir . Create ( ) ;
}
DividiFile = false ;
}
foreach ( var childFile in SourceDir . GetFiles ( "*.jpg" ) )
{
if ( StopAttivo = = true )
{
break ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
setLabel10Text ( "File: " + childFile . Name ) ;
string b = ( int . Parse ( Label18 . Text ) + 1 ) . ToString ( ) ;
// setLabel18Text(b)
// setProgressBarValue(CInt(b))
// Label10.Text = "File: " & childFile.Name
// Label18.Text = (CType(Label18.Text, Integer) + 1).ToString
// Application.DoEvents()
ContaFileXDir + = 1 ;
if ( DividiFile = = true )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
if ( ContaFileXDir = = ContaDirXDir * NumFileXDir + 1 )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
ContaDirXDir + = 1 ;
if ( rdbNumProgressiva . Checked = = true )
{
TestoTemp = ContaDirXDir . ToString ( ) ;
}
else
{
TestoTemp = ( ContaDirXDir * NumFileXDir ) . ToString ( ) ;
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
var loopTo = NumCifreDir - TestoTemp . Length ;
for ( ContaTemp = 1 ; ContaTemp < = loopTo ; ContaTemp + + )
TestoTemp = "0" + TestoTemp ;
if ( DestDirStart . FullName . EndsWith ( @"\" ) )
{
DestDir = new DirectoryInfo ( DestDirStart . FullName + SuffixDir + TestoTemp ) ;
}
else
{
DestDir = new DirectoryInfo ( DestDirStart . FullName + @"\" + SuffixDir + TestoTemp ) ;
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
if ( ! DestDir . Exists )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
DestDir . Create ( ) ;
2021-03-04 10:44:09 +01:00
}
}
2025-07-28 09:00:07 +02:00
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// Application.DoEvents()
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
var ClsCreaImmagine = new ImageCreatorSharp ( childFile . Name , SourceDir , DestDir , DestDirStart ) ;
// ClsCreaImmagine.NomeFileChild = childFile.Name
// ClsCreaImmagine.DestDir = DestDir
// ClsCreaImmagine.SourceDir = SourceDir
// ClsCreaImmagine.DestDirStart = DestDirStart
2025-07-23 15:08:25 +02:00
2025-07-28 09:00:07 +02:00
ContaImmaginiThread + = 1 ;
//MyPool.InsertWorkItem(childFile.Name, new XyThreadAdd((_) => ClsCreaImmagine.CreaImmagineThread()), new object[1] { childFile.Name }, true);
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
// copy all the sub-directories by recursively calling this same routine
if ( chkAggiornaSottodirectory . Checked = = true )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
foreach ( var subDir in SourceDir . GetDirectories ( ) )
creaImmaginiWithThreadMod ( subDir . FullName , Path . Combine ( DestDir . FullName , subDir . Name ) ) ;
2021-03-04 10:44:09 +01:00
}
}
2025-07-28 09:00:07 +02:00
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
private int getNumerazione ( )
{
int numerazione ;
if ( rdbNumProgressiva . Checked )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
numerazione = ( int ) FileHelper . numerazione . Progressiva ;
}
else
{
numerazione = ( int ) FileHelper . numerazione . Files ;
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
return numerazione ;
}
private NumerazioneType GetNumerazioneEnum ( )
{
NumerazioneType numerazioneType ;
if ( rdbNumProgressiva . Checked )
{
numerazioneType = NumerazioneType . Progressiva ; // FileHelper.numerazione.Progressiva
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
else
{
numerazioneType = NumerazioneType . Files ;
} // FileHelper.numerazione.Files
return numerazioneType ;
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
private void CreaimmaginiWithThreadDict ( string SourcePath , string DestPath )
{
var dirSourceDest = new Dictionary < FileInfo , DirectoryInfo > ( ) ;
if ( chkAggiornaSottodirectory . Checked & chkCreaSottocartelle . Checked )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
var helper = new FileHelper ( int . Parse ( txtFilePerCartella . Text ) , txtSuffissoCartelle . Text ,
int . Parse ( txtCifreContatore . Text ) , getNumerazione ( ) ) ;
// getfilesrecursive
dirSourceDest =
helper . GetFilesRecursive ( new DirectoryInfo ( SourcePath ) , new DirectoryInfo ( DestPath ) , "*.jpg" ) ;
}
else if ( chkAggiornaSottodirectory . Checked & ! chkCreaSottocartelle . Checked )
{
// = getDirsDict(SourcePath, DestPath)
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
foreach ( var pair in dirSourceDest )
{
setLabel10Text ( "File: " + pair . Key . Name ) ;
string b = ( int . Parse ( Label18 . Text ) + 1 ) . ToString ( ) ;
var ClsCreaImmagine = new ImageCreatorSharp ( pair . Key , pair . Value ) ;
ContaImmaginiThread + = 1 ;
//MyPool.InsertWorkItem(pair.Key.Name, new XyThreadAdd((_) => ClsCreaImmagine.CreaImmagineThread()), new object[1] { pair.Key.Name }, true);
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// il posto giusto dove fare modifiche
private void CreaImmaginiWithThread ( string SourcePath , string DestPath )
{
var SourceDir = new DirectoryInfo ( SourcePath ) ;
var DestDirStart = new DirectoryInfo ( DestPath ) ;
DirectoryInfo DestDir = null ;
int NumFileXDir = int . Parse ( txtFilePerCartella . Text ) ;
string SuffixDir = txtSuffissoCartelle . Text ;
int NumCifreDir = int . Parse ( txtCifreContatore . Text ) ;
bool DividiFile = false ;
StopAttivo = false ;
int FileConta = 0 ;
int ContaFileXDir = 0 ;
int ContaDirXDir = 0 ;
string TestoTemp = "" ;
int ContaTemp = 0 ;
if ( SourceDir . Exists )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
FileConta = SourceDir . GetFiles ( "*.jpg" ) . GetLength ( 0 ) ;
lblFotoTotaliNum . Text = ( int . Parse ( lblFotoTotaliNum . Text ) + FileConta ) . ToString ( ) ;
if ( NumFileXDir > 0 & chkCreaSottocartelle . Checked = = true )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
if ( FileConta > NumFileXDir )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
DividiFile = true ;
2021-03-04 10:44:09 +01:00
}
else
{
DestDir = DestDirStart ;
if ( ! DestDir . Exists )
{
DestDir . Create ( ) ;
}
DividiFile = false ;
}
2025-07-28 09:00:07 +02:00
}
else
{
DestDir = DestDirStart ;
if ( ! DestDir . Exists )
{
DestDir . Create ( ) ;
}
DividiFile = false ;
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
foreach ( var childFile in SourceDir . GetFiles ( "*.jpg" ) )
{
if ( StopAttivo = = true )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
break ;
}
// Label10.Text = "File: " & childFile.Name
// Label18.Text = (CType(Label18.Text, Integer) + 1).ToString
// Application.DoEvents()
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
ContaFileXDir + = 1 ;
if ( DividiFile = = true )
{
if ( ContaFileXDir = = ContaDirXDir * NumFileXDir + 1 )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
ContaDirXDir + = 1 ;
if ( rdbNumProgressiva . Checked = = true )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
TestoTemp = ContaDirXDir . ToString ( ) ;
}
else
{
TestoTemp = ( ContaDirXDir * NumFileXDir ) . ToString ( ) ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
var loopTo = NumCifreDir - TestoTemp . Length ;
for ( ContaTemp = 1 ; ContaTemp < = loopTo ; ContaTemp + + )
TestoTemp = "0" + TestoTemp ;
if ( DestDirStart . FullName . EndsWith ( @"\" ) )
{
DestDir = new DirectoryInfo ( DestDirStart . FullName + SuffixDir + TestoTemp ) ;
}
else
{
DestDir = new DirectoryInfo ( DestDirStart . FullName + @"\" + SuffixDir + TestoTemp ) ;
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
if ( ! DestDir . Exists )
{
DestDir . Create ( ) ;
}
2021-03-04 10:44:09 +01:00
}
}
2025-07-23 15:08:25 +02:00
2025-07-28 09:00:07 +02:00
Application . DoEvents ( ) ;
var ClsCreaImmagine = new CreaImmagineSeparateThread ( ) ;
ClsCreaImmagine . DirectorySorgente = SourcePath ;
ClsCreaImmagine . DirectoryDestinazione = Model . DestinationPath ;
ClsCreaImmagine . DestDir = DestDir ;
ClsCreaImmagine . SourceDir = SourceDir ;
ClsCreaImmagine . DestDirStart = DestDirStart ;
ClsCreaImmagine . DimStandard = int . Parse ( TextBox11 . Text ) ;
ClsCreaImmagine . DimStandardMiniatura = int . Parse ( TextBox25 . Text ) ;
ClsCreaImmagine . UsaOrarioMiniatura = CheckBox12 . Checked ;
ClsCreaImmagine . UsaOrarioTestoApplicare = CheckBox8 . Checked ;
ClsCreaImmagine . UsaTempoGaraTestoApplicare = CheckBox7 . Checked ;
ClsCreaImmagine . UsaRotazioneAutomatica = chkRotazioneAutomatica . Checked ;
ClsCreaImmagine . UsaForzaJpg = chkForzaJpg . Checked ;
if ( CheckBox17 . Checked )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
ClsCreaImmagine . TestoNome = true ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
else
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
ClsCreaImmagine . TestoNome = false ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
if ( CheckBox16 . Checked )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
ClsCreaImmagine . NomeData = true ;
}
else
{
ClsCreaImmagine . NomeData = false ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:49:55 +02:00
ClsCreaImmagine . TestoFirmaStart = Model . HorizontalText ;
2025-07-28 09:00:07 +02:00
ClsCreaImmagine . TestoFirmaStartV = TextBox29 . Text ;
ClsCreaImmagine . DataPartenza = DateTimePicker1 . Value ;
ClsCreaImmagine . TestoOrario = TextBox18 . Text ;
ClsCreaImmagine . AltezzaSmall = int . Parse ( TextBox5 . Text ) ;
ClsCreaImmagine . LarghezzaSmall = int . Parse ( TextBox5 . Text ) ;
ClsCreaImmagine . CreaMiniature = CheckBox1 . Checked ;
ClsCreaImmagine . AggiungiScritteMiniature = RadioButton3 . Checked ;
ClsCreaImmagine . AggTempoGaraMin = RadioButton5 . Checked ;
ClsCreaImmagine . AggNumTempMin = RadioButton7 . Checked ;
ClsCreaImmagine . DimVert = int . Parse ( TextBox30 . Text ) ;
ClsCreaImmagine . MargVert = int . Parse ( TextBox31 . Text ) ;
ClsCreaImmagine . NomeFileChild = childFile . Name ;
ClsCreaImmagine . Suffisso = TextBox3 . Text ;
// ClsCreaImmagine.Codice = TextBox13.Text
ClsCreaImmagine . Trasparenza = int . Parse ( TextBox9 . Text ) ;
ClsCreaImmagine . IlFont = ComboBox3 . SelectedItem . ToString ( ) ;
ClsCreaImmagine . Grassetto = CheckBox3 . Checked ;
ClsCreaImmagine . Posizione = ComboBox1 . SelectedItem . ToString ( ) ;
ClsCreaImmagine . Allineamento = ComboBox2 . SelectedItem . ToString ( ) ;
ClsCreaImmagine . Margine = int . Parse ( TextBox12 . Text ) ;
ClsCreaImmagine . LogoAltezza = int . Parse ( TextBox14 . Text ) ;
ClsCreaImmagine . LogoLarghezza = int . Parse ( TextBox15 . Text ) ;
// ClsCreaImmagine.FontColoreR = CType(TextBox22.Text, Integer)
// ClsCreaImmagine.FontColoreG = CType(TextBox23.Text, Integer)
// ClsCreaImmagine.FontColoreB = CType(TextBox24.Text, Integer)
ClsCreaImmagine . fontColoreRGB = ColorTranslator . FromHtml ( TextBox34 . Text ) ;
ClsCreaImmagine . LogoAggiungi = CheckBox5 . Checked ;
ClsCreaImmagine . LogoNomeFile = TextBox10 . Text ;
ClsCreaImmagine . LogoTrasparenza = TextBox19 . Text ;
ClsCreaImmagine . LogoMargine = TextBox16 . Text ;
ClsCreaImmagine . LogoPosizioneH = ComboBox4 . Text ;
ClsCreaImmagine . LogoPosizioneV = ComboBox5 . Text ;
ClsCreaImmagine . FotoGrandeDimOrigina = CheckBox15 . Checked ;
ClsCreaImmagine . AltezzaBig = int . Parse ( TextBox27 . Text ) ;
ClsCreaImmagine . LarghezzaBig = int . Parse ( TextBox28 . Text ) ;
ClsCreaImmagine . DimMin = int . Parse ( TextBox25 . Text ) ;
ClsCreaImmagine . TestoMin = RadioButton6 . Checked ;
ClsCreaImmagine . jpegQuality = int . Parse ( TextBox32 . Text ) ;
ClsCreaImmagine . jpegQualityMin = int . Parse ( TextBox33 . Text ) ;
ContaImmaginiThread + = 1 ;
MyPool . InsertWorkItem ( childFile . Name , new XyThreadAdd ( ClsCreaImmagine . CreaImmagineThread ) ,
new object [ 1 ] { childFile . Name } , true ) ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
// copy all the sub-directories by recursively calling this same routine
if ( chkAggiornaSottodirectory . Checked = = true )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
foreach ( var subDir in SourceDir . GetDirectories ( ) )
CreaImmaginiWithThread ( subDir . FullName , Path . Combine ( DestDir . FullName , subDir . Name ) ) ;
2021-03-04 10:44:09 +01:00
}
}
2025-07-28 09:00:07 +02:00
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
private void CopyDirectoryFile ( string SourcePath , string DestPath , bool OverWrite = false )
{
var SourceDir = new DirectoryInfo ( SourcePath ) ;
var DestDir = new DirectoryInfo ( DestPath ) ;
if ( SourceDir . Exists )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
if ( ! DestDir . Exists )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
DestDir . Create ( ) ;
// copy all the files of the current directory
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
foreach ( var childFile in SourceDir . GetFiles ( ) )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
if ( OverWrite )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
childFile . CopyTo ( Path . Combine ( DestDir . FullName , childFile . Name ) , true ) ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
// if overwrite = false, copy the file only if it does not exist
// this is done to avoid an IOException if a file already exists
// this way the other files can be copied anyway...
else if ( ! File . Exists ( Path . Combine ( DestDir . FullName , childFile . Name ) ) )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
childFile . CopyTo ( Path . Combine ( DestDir . FullName , childFile . Name ) , false ) ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
// copy all the sub-directories by recursively calling this same routine
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
foreach ( var subDir in SourceDir . GetDirectories ( ) )
CopyDirectoryFile ( subDir . FullName , Path . Combine ( DestDir . FullName , subDir . Name ) , OverWrite ) ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
public Size NewthumbSize ( int currentwidth , int currentheight , int MaxPixel , string TipoSize )
{
// Calculate the Size of the New image
// *** Larghezza, Altezza, Auto
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
double tempMultiplier ;
if ( ( TipoSize . ToUpper ( ) ? ? "" ) = = ( "Larghezza" . ToUpper ( ) ? ? "" ) )
{
tempMultiplier = MaxPixel / ( double ) currentwidth ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
else if ( ( TipoSize . ToUpper ( ) ? ? "" ) = = ( "Altezza" . ToUpper ( ) ? ? "" ) )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
tempMultiplier = MaxPixel / ( double ) currentheight ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
else if ( currentheight > currentwidth ) // portrait
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
tempMultiplier = MaxPixel / ( double ) currentheight ;
}
else
{
tempMultiplier = MaxPixel / ( double ) currentwidth ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
var NewSize = new Size ( ( int ) Math . Round ( currentwidth * tempMultiplier ) ,
( int ) Math . Round ( currentheight * tempMultiplier ) ) ;
return NewSize ;
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
private void Button7_Click ( object sender , EventArgs e )
{
StopAttivo = true ;
//MyPool.StopThreadPool();
try
{
_mainToken ? . Cancel ( ) ;
}
catch ( Exception exception )
{
_logger . LogError ( exception . Message ) ;
_logger . LogInformation ( "Ignora questo errore" ) ;
// Console.WriteLine(exception);
// Console.WriteLine("Ignora questo errore");
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
unlockUI ( ) ;
}
private void Button4_Click ( object sender , EventArgs e )
{
var openFileDialog = new OpenFileDialog ( ) ;
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// openFileDialog.InitialDirectory = TextBox1.Text
openFileDialog . Filter = "Immagini jpg (*.jpg)|*.jpg|Immagini gif (*.gif)|*.gif|Tutti i file (*.*)|*.*" ;
if ( TextBox10 . Text . Length > 0 )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
openFileDialog . FileName = TextBox10 . Text ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
openFileDialog . FilterIndex = 0 ;
openFileDialog . RestoreDirectory = true ;
if ( DialogResult . OK = = openFileDialog . ShowDialog ( ) )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
TextBox10 . Text = openFileDialog . FileName ;
PictureBox1 . Image = Image . FromFile ( TextBox10 . Text ) ;
if ( PictureBox1 . Image . Height > = PictureBox1 . Image . Width )
{
PictureBox1 . Height = 160 ;
PictureBox1 . Width =
( int ) ( 160 * PictureBox1 . Image . Width / ( double ) PictureBox1 . Image . Height ) ;
}
else
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
PictureBox1 . Width = 224 ;
PictureBox1 . Height =
( int ) ( 224 * PictureBox1 . Image . Height / ( double ) PictureBox1 . Image . Width ) ;
2021-03-04 10:44:09 +01:00
}
}
2025-07-28 09:00:07 +02:00
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
private string LeggiSoloNomeFile ( string FileName )
{
string Testo = FileName ;
string Risposta = "" ;
var Nomi = Testo . Split ( new char [ ] { '\\' } ) ;
if ( Nomi . Length > 1 )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
Risposta = Nomi [ Nomi . Length - 1 ] ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
return Risposta ;
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
private void PictureBox1_MouseMove ( object sender , MouseEventArgs e )
{
// GetColor()
// GetPixelColor(PictureBox1.PointToScreen(e.Location)).ToArgb.ToString("X8")
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
private void PictureBox1_MouseUp ( object sender , MouseEventArgs e )
{
if ( e . Button = = MouseButtons . Left )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
WaterSelectColor = true ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
else
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
WaterSelectColor = false ;
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// Private Declare Function CreateDC Lib "gdi32.dll" (ByVal strDriver As String, ByVal strDevice As String, ByVal strOutput As String, ByVal pData As IntPtr) As IntPtr
// Private Declare Function DeleteDC Lib "gdi32.dll" (ByVal hdc As IntPtr) As Boolean
// Private Declare Function GetPixel Lib "gdi32.dll" (ByVal hdc As IntPtr, ByVal x As Integer, ByVal y As Integer) As Integer
// Private Declare Function GetCursorPos Lib "user32.dll" (ByRef lpPoint As Point) As Boolean
2021-03-04 11:25:40 +01:00
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// ''' <summary>
// ''' Get the color relative to mouse position
// ''' </summary>
// Private Sub GetColor()
// Dim hdcScreen As IntPtr = CreateDC("Display", Nothing, Nothing, IntPtr.Zero)
// Dim pt As Point = New Point
// GetCursorPos(pt)
// Dim cr As Integer = GetPixel(hdcScreen, pt.X, pt.Y)
// DeleteDC(hdcScreen)
// Dim clr As Color = Color.FromArgb((cr And &HFF), (cr And &HFF00) >> 8, (cr And &HFF0000) >> 16)
// PictureBox3.BackColor = clr
// If WaterSelectColor = True Then
// PictureBox2.BackColor = clr
// End If
// WaterSelectColor = False
// End Sub
2025-07-23 15:08:25 +02:00
2025-07-28 09:00:07 +02:00
private Color [ ] GetPixelColor ( Point screenLocation )
{
// Dim bm As New Bitmap(1, 1, Imaging.PixelFormat.Format24bppRgb)
// Dim g As Graphics = Graphics.FromImage(bm)
// g.CopyFromScreen(screenLocation, New Point(0, 0), New Size(1, 1))
// Dim result As Color = bm.GetPixel(0, 0)
// g.Dispose()
// bm.Dispose()
// Return result
return null ;
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
private void Button8_Click ( object sender , EventArgs e )
{
var MyDialog = new ColorDialog ( ) ;
MyDialog . AllowFullOpen = true ;
// If TextBox22.Text.Length > 0 And TextBox23.Text.Length > 0 And TextBox24.Text.Length > 0 Then
// If CType(TextBox22.Text, Integer) >= 0 And CType(TextBox23.Text, Integer) >= 0 And CType(TextBox24.Text, Integer) >= 0 Then
// MyDialog.Color = Color.FromArgb(0, CType(TextBox22.Text, Integer), CType(TextBox23.Text, Integer), CType(TextBox24.Text, Integer))
// End If
// End If
2025-07-23 15:08:25 +02:00
2025-07-28 09:00:07 +02:00
if ( MyDialog . ShowDialog ( ) = = DialogResult . OK )
2021-03-04 11:25:40 +01:00
{
2025-07-28 09:00:07 +02:00
// TextBox22.Text = MyDialog.Color.R.ToString
// TextBox23.Text = MyDialog.Color.G.ToString
// TextBox24.Text = MyDialog.Color.B.ToString
TextBox34 . Text = ColorTranslator . ToHtml ( MyDialog . Color ) ;
TextBox34 . BackColor = MyDialog . Color ;
2021-03-04 11:25:40 +01:00
}
2025-07-28 09:00:07 +02:00
}
private void TextBox27_TextChanged ( object sender , EventArgs e )
{
}
private void CheckBox18_CheckedChanged ( object sender , EventArgs e )
{
CheckBox4 . Checked = false ;
CheckBox12 . Checked = false ;
}
private void CheckBox4_CheckedChanged ( object sender , EventArgs e )
{
CheckBox18 . Checked = false ;
}
private void CheckBox12_CheckedChanged ( object sender , EventArgs e )
{
CheckBox18 . Checked = false ;
}
private void Label27_Click ( object sender , EventArgs e )
{
}
2021-03-04 11:25:40 +01:00
2025-07-28 09:00:07 +02:00
private CancellationTokenSource ? _mainToken ;
private async void Button1_Click ( object sender , EventArgs e )
{
_logger . LogInformation ( "Avvio elaborazione..." ) ;
lockUI ( ) ;
// Dim timeStart As Date
// Dim timeStop As Date
_mainToken ? . Dispose ( ) ;
_mainToken = new CancellationTokenSource ( ) ;
var token = _mainToken . Token ;
// timeStart = TimeOfDay
FixPaths ( ) ;
Label10 . Text = "Elaborazione in corso..." ;
lblFotoTotaliNum . Text = "0" ;
Label18 . Text = "0" ;
Label43 . Text = "-s" ;
setPicSettings ( Model . SourcePath , Model . DestinationPath ) ;
ProgressBar1 . Minimum = 0 ;
ProgressBar1 . Step = 1 ;
ProgressBar1 . Value = 0 ;
// Await CreaCatalogoParallel()
var imgStf = _imageCreationService ; //new ImageCreationStuff();
var imageCreationOptions = new ImageCreationStuff . Options
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
AggiornaSottodirectory = chkAggiornaSottodirectory . Checked ,
CreaSottocartelle = chkCreaSottocartelle . Checked ,
FilePerCartella = int . Parse ( txtFilePerCartella . Text ) ,
SuffissoCartelle = txtSuffissoCartelle . Text ,
CifreContatore = int . Parse ( txtCifreContatore . Text ) ,
NumerazioneType = GetNumerazioneEnum ( ) ,
SourcePath = Model . SourcePath ,
DestinationPath = Model . DestinationPath ,
MaxThreads = int . Parse ( TextBox7 . Text ) ,
ChunksSize = int . Parse ( TextBox8 . Text ) ,
LinearExecution = rdbVecchioMetodo . Checked
} ;
try
{
_results = [ ] ;
_currentAmount = 0 ;
_previousAmount = 0 ;
timer1 . Tick + = Timer1OnTick ;
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
timer1 . Interval = 1000 * 60 ;
timer1 . Enabled = true ;
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
string time = await imgStf . CreaCatalogoParallel ( imageCreationOptions , _results , UiUpdateEvent , token ) ;
Label43 . Text = time ;
timer1 . Enabled = false ;
}
catch ( OperationCanceledException operationCanceledException )
2021-03-04 10:44:09 +01:00
{
2025-07-28 09:00:07 +02:00
_logger . LogInformation ( "Operazione Cancellata" ) ;
//Console.WriteLine("Operazione cancellata");
2021-03-04 10:44:09 +01:00
}
2025-07-28 09:00:07 +02:00
finally
{
_mainToken ? . Dispose ( ) ;
_mainToken = null ;
timer1 . Tick - = Timer1OnTick ;
}
Label10 . Text = "Finito" ;
unlockUI ( ) ;
}
private int _currentAmount = 0 ;
private int _previousAmount = 0 ;
private void Timer1OnTick ( object sender , EventArgs e )
{
_previousAmount = _currentAmount ;
_currentAmount = _results . Count ;
int diff = _currentAmount - _previousAmount ;
SetText ( Label43 , $"{diff} f/m" ) ;
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
private void UpdateCounter ( string text )
{
Label10 . Invoke ( new Action ( ( ) = > Label10 . Text = text ) ) ;
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
private async Task CreaCatalogoParallel ( )
{
var timeStart = DateTime . Now ;
ContaImmaginiThread = 0 ;
setLabel10Text ( "Elaborazione in corso..." ) ;
var imgStf = _imageCreationService ;
var imageCreationOptions = new ImageCreationStuff . Options ( ) ;
imageCreationOptions . AggiornaSottodirectory = chkAggiornaSottodirectory . Checked ;
imageCreationOptions . CreaSottocartelle = chkCreaSottocartelle . Checked ;
imageCreationOptions . FilePerCartella = int . Parse ( txtFilePerCartella . Text ) ;
imageCreationOptions . SuffissoCartelle = txtSuffissoCartelle . Text ;
imageCreationOptions . CifreContatore = int . Parse ( txtCifreContatore . Text ) ;
imageCreationOptions . NumerazioneType = GetNumerazioneEnum ( ) ;
imageCreationOptions . SourcePath = Model . SourcePath ;
imageCreationOptions . DestinationPath = Model . DestinationPath ;
await imgStf . ProcessImagesParallel ( imageCreationOptions , _results , UiUpdateEvent ) ;
// Await CreaImmaginiParallel(txtSorgente.Text, txtDestinazione.Text)
setLabel10Text ( "Finito" ) ;
var timeStop = DateTime . Now ;
setLabel43Text ( CalcTime ( timeStart , timeStop , ContaImmaginiThread ) ) ;
}
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// Private Async Function CreaImmaginiParallel(ByVal SourcePath As String, ByVal DestPath As String) As Task
// Dim dataToProcess As List(Of FileData) = New List(Of FileData)
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// 'Dim dirSourceDest As Dictionary(Of FileInfo, DirectoryInfo) = New Dictionary(Of FileInfo, DirectoryInfo)
// If chkAggiornaSottodirectory.Checked And chkCreaSottocartelle.Checked Then
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// Dim helperSharp As New FileHelperSharp()
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// 'Dim helper As New FileHelper(CInt(txtFilePerCartella.Text), txtSuffissoCartelle.Text, CInt(txtCifreContatore.Text), getNumerazione())
// 'getfilesrecursive
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// Dim fileHelperOptions As FileHelperOptions = New FileHelperOptions()
// fileHelperOptions.FilesPerFolder = CInt(txtFilePerCartella.Text)
// fileHelperOptions.Suffix = txtSuffissoCartelle.Text
// fileHelperOptions.CounterSize = CInt(txtCifreContatore.Text)
// fileHelperOptions.NumerationType = GetNumerazioneEnum()
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// dataToProcess = helperSharp.GetFilesRecursive(New DirectoryInfo(SourcePath), New DirectoryInfo(DestPath), "*.jpg", fileHelperOptions)
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// 'dataToProcess = helper.GetFilesRecursiveParallel(New DirectoryInfo(SourcePath), New DirectoryInfo(DestPath), "*.jpg")
// ElseIf chkAggiornaSottodirectory.Checked And Not chkCreaSottocartelle.Checked Then
// ' TODO manca tutto?!?!?!?
// End If
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// Dim scheduler As TaskScheduler = New ConcurrentExclusiveSchedulerPair(TaskScheduler.Default, Environment.ProcessorCount * 2).ConcurrentScheduler
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// Dim test As IEnumerable(Of Task) = From d In dataToProcess Select Task.Factory.StartNew(Sub()
// 'setLabel10Text("File: " & p.File.Name)
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// Dim b As String = (CType(Label18.Text, Integer) + 1).ToString
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// Dim clsCreaImmagine As New ImageCreator(d.File, d.Directory)
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// clsCreaImmagine.CreaImmagineThread(d.File.Name)
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// ContaImmaginiThread += 1
// UpdateCounter(ContaImmaginiThread & " " & d.File.Name)
// End Sub, CancellationToken.None, TaskCreationOptions.LongRunning, scheduler) 'TODO Cancellation Token
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// 'ThreadingHelper.StartAndWaitAllThrottled(test, CType(TextBox7.Text, Integer))
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// Await Task.WhenAll(test)
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// '= getDirsDict(SourcePath, DestPath)
// 'Parallel.ForEach(dataToProcess,
// ' Sub(p, state)
// ' 'setLabel10Text("File: " & p.File.Name)
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// ' Dim b As String = (CType(Label18.Text, Integer) + 1).ToString
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// ' Dim clsCreaImmagine As New ImageCreator(p.File, p.Directory)
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// ' clsCreaImmagine.CreaImmagineThread(p.File.Name)
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// ' ContaImmaginiThread += 1
// ' UpdateCounter(ContaImmaginiThread & " " & p.File.Name)
// ' 'MyPool.InsertWorkItem(p.File.Name, New XyThreadAdd(AddressOf ClsCreaImmagine.CreaImmagineThread), New Object(0) {p.File.Name}, True)
// ' ' TODO: BREAK ON STOP state.stop()
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// ' End Sub)
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// 'Dim pair As KeyValuePair(Of FileInfo, DirectoryInfo)
// 'For Each pair In dirSourceDest
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// ' setLabel10Text("File: " & pair.Key.Name)
// ' Dim b As String = (CType(Label18.Text, Integer) + 1).ToString
2021-03-04 10:44:09 +01:00
2025-07-28 09:00:07 +02:00
// ' Dim ClsCreaImmagine As New ImageCreator(pair.Key, pair.Value)
// ' ContaImmaginiThread += 1
// ' MyPool.InsertWorkItem(pair.Key.Name, New XyThreadAdd(AddressOf ClsCreaImmagine.CreaImmagineThread), New Object(0) {pair.Key.Name}, True)
// 'Next
// End Function
}
public class PicInfo
{
public DirectoryInfo DirSource , DirDest , DirDestStart ;
public string NomeImmagine ;
public PicInfo ( DirectoryInfo Dir_Source , DirectoryInfo Dir_Dest , DirectoryInfo Dir_DestStart ,
string Nome_Immagine )
{
DirSource = Dir_Source ;
DirDest = Dir_Dest ;
DirDestStart = Dir_DestStart ;
NomeImmagine = Nome_Immagine ;
2021-03-04 10:44:09 +01:00
}
}