Add drag&drop .asm preview and force CSV output to repo root

Fase 5 now shows the distinta's .asm files already copied to raw/ as
draggable icons, so they can be dropped straight onto Creo or Explorer
without re-hitting the DB/share. The CSV from fase 2 is now always
written to the repo root (found by walking up to CLAUDE.md) instead of
next to the input file, wherever that happens to be.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
davideandClaude Sonnet 5 committed 2026-09-21 09:54:06 +02:00
1 parent 8a8a7d0417
commit 0966e66232
3 files changed
+100 -12

No files matched your search

+81 -2
View File
@@ -12,6 +12,7 @@ public partial class Form1 : Form
private readonly Button _btnReport = new();
private readonly Button _btnVerifica = new();
private readonly Button _btnCompletezza = new();
private readonly ListView _lstAnteprimaAsm = new();
private readonly Button _btnPulisci = new();
private readonly Label _lblStatus = new();
private readonly Label _lblDb = new();
@@ -41,6 +42,19 @@ public partial class Form1 : Form
private static readonly string[] TipiPredefiniti = { "prt", "asm" };
private const string RadiceDiscoDefault = @"X:\";
/// <summary>Risale da AppContext.BaseDirectory (variabile tra Debug/Release/publish) fino
/// alla cartella che contiene CLAUDE.md, cioè la root del repo; se non la trova (es. exe
/// pubblicato e spostato altrove) ripiega su AppContext.BaseDirectory.</summary>
private static string TrovaRadiceRepo()
{
for (var dir = new DirectoryInfo(AppContext.BaseDirectory); dir is not null; dir = dir.Parent)
{
if (File.Exists(Path.Combine(dir.FullName, "CLAUDE.md")))
return dir.FullName;
}
return AppContext.BaseDirectory;
}
private string? _dbPath;
private string? _percorsoInputCorrente;
private List<(string Componente, string Descrizione)>? _righeCorrenti;
@@ -149,6 +163,47 @@ public partial class Form1 : Form
_btnIndietro.Visible = _faseAttuale > 0;
_btnAvanti.Visible = _faseAttuale < NomiFasi.Length - 1;
AggiornaStatoAvanti();
if (_faseAttuale == 4)
AggiornaAnteprimaAsm();
}
/// <summary>Popola le icone trascinabili (drag&amp;drop) dei file .asm della distinta importata
/// (non i sotto-assiemi di fase 4, che in "raw" servono solo a completarla) già copiati in
/// "raw" (non riletti dal DB/share: sono già in locale), mostrate in fase 5 prima ancora di
/// avviare la verifica.</summary>
private void AggiornaAnteprimaAsm()
{
_lstAnteprimaAsm.Items.Clear();
_lstAnteprimaAsm.LargeImageList!.Images.Clear();
if (_ultimaCartellaRaw is null || !Directory.Exists(_ultimaCartellaRaw) || _righeCorrenti is null)
return;
var codiciDistinta = _righeCorrenti.Select(r => r.Componente).ToHashSet(StringComparer.OrdinalIgnoreCase);
var percorsiAsm = Directory.GetFiles(_ultimaCartellaRaw)
.Where(p =>
{
var (codice, tipo, _) = Indexer.ParseFilename(Path.GetFileName(p));
return tipo.Equals("asm", StringComparison.OrdinalIgnoreCase) && codiciDistinta.Contains(codice);
});
foreach (var percorso in percorsiAsm)
{
Icon? icona = null;
try
{
icona = Icon.ExtractAssociatedIcon(percorso);
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or ArgumentException)
{
// ponytail: file irraggiungibile (share offline) -> icona generica, non blocca gli altri
}
int indice = _lstAnteprimaAsm.LargeImageList.Images.Count;
_lstAnteprimaAsm.LargeImageList.Images.Add(icona?.ToBitmap() ?? SystemIcons.WinLogo.ToBitmap());
icona?.Dispose();
_lstAnteprimaAsm.Items.Add(new ListViewItem(Path.GetFileName(percorso), indice) { Tag = percorso });
}
}
/// <summary>Condizione per cui la fase indicata è "conclusa" e si può passare alla successiva.</summary>
@@ -423,10 +478,34 @@ public partial class Form1 : Form
_btnCompletezza.Text = "Verifica completezza assiemi";
_btnCompletezza.Size = new Size(220, 32);
_btnCompletezza.Margin = new Padding(0, 0, 0, 20);
_btnCompletezza.Margin = new Padding(0, 0, 0, 8);
_btnCompletezza.Click += (_, _) => VerificaCompletezzaAssiemi();
contenuto.Controls.Add(_btnCompletezza);
var lblAnteprimaAsm = new Label
{
AutoSize = true,
ForeColor = SystemColors.GrayText,
Margin = new Padding(0, 0, 0, 4),
Text = "File .asm della distinta trovati nell'indice (trascinali su Creo/Esplora risorse):",
};
contenuto.Controls.Add(lblAnteprimaAsm);
_lstAnteprimaAsm.View = View.LargeIcon;
_lstAnteprimaAsm.MultiSelect = true;
_lstAnteprimaAsm.LargeImageList = new ImageList { ImageSize = new Size(32, 32) };
_lstAnteprimaAsm.Size = new Size(680, 160);
_lstAnteprimaAsm.Margin = new Padding(0, 0, 0, 20);
_lstAnteprimaAsm.ItemDrag += (_, e) =>
{
var percorsi = _lstAnteprimaAsm.SelectedItems.Cast<ListViewItem>()
.Select(item => (string)item.Tag!)
.ToArray();
if (percorsi.Length > 0)
_lstAnteprimaAsm.DoDragDrop(new DataObject(DataFormats.FileDrop, percorsi), DragDropEffects.Copy);
};
contenuto.Controls.Add(_lstAnteprimaAsm);
var lblIstruzioniStep = new Label
{
AutoSize = true,
@@ -463,7 +542,7 @@ public partial class Form1 : Form
{
try
{
var (csv, righe) = DistintaBaseImporter.ConvertiInCsv(percorso);
var (csv, righe) = DistintaBaseImporter.ConvertiInCsv(percorso, TrovaRadiceRepo());
_percorsoInputCorrente = percorso;
_righeCorrenti = righe;