using Quadarax.Foundation.Core.Value.Extensions; using System.Text; namespace qdr.app.tools.qfu.gui.Subforms { public partial class CtrlClearDir : UserControl, ICommanControl { #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. public CtrlClearDir() #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. { InitializeComponent(); } public string Description => "Clear Directory Command\r\nRemove files or directories from a specified directory with optional pattern matching.\r\n\r\nSyntax:\r\nqfu cleardir [options]\r\n\r\nArguments:\r\n- `scope`: Either `files` or `directories` - what to clean\r\n- `directory`: Path to the directory to clean\r\n\r\nOptions:\r\n- `-s`: Include subdirectories in the operation\r\n- `-f `: Filter patterns (pipe-separated, e.g., `*.txt|*.log`)\r\n- `-dry`: Dry run - show what would be deleted without actually deleting\r\n- `-empty`: Only delete empty files or directories"; public string ViewName => "Clear Dir"; public void Execute() { var arguments = new StringBuilder(); arguments.Append("cleardir"); arguments.Append(" "); if (rbScopeFile.Checked) { arguments.Append("files"); } else if (rbScopeDir.Checked) { arguments.Append("directories"); } else { throw new InvalidOperationException("Please select a scope (files or directories)."); } arguments.Append(" "); arguments.Append("\"").Append(ctrlDirSelection.SelectedPath).Append("\""); if (chbIncludeSubdirs.Checked) { arguments.Append(" "); arguments.Append(" -s"); } if (ctrlFilter.FilterEnabled) { arguments.Append(" "); arguments.Append(" -f:\"").Append(ctrlFilter.FilterText).Append("\""); } if (chbDryRun.Checked) { arguments.Append(" "); arguments.Append(" -dry"); } if (chbDeleteEmpty.Checked) { arguments.Append(" "); arguments.Append(" -empty"); } ConsoleRunner.Run(arguments.ToString().SplitQuoted(" ", "\"", removeEmptyItems: true, trimValues: false, keepBracket: true)); } private void InitializeComponent() { tlpLevel0 = new TableLayoutPanel(); tlpLevel1L = new TableLayoutPanel(); groupBox1 = new GroupBox(); rbScopeFile = new RadioButton(); rbScopeDir = new RadioButton(); ctrlDirSelection = new qdr.app.tools.qfu.gui.Subforms.Common.DirectorySelectionCtrl(); tlpLevel1R = new TableLayoutPanel(); chbDeleteEmpty = new CheckBox(); chbDryRun = new CheckBox(); chbIncludeSubdirs = new CheckBox(); ctrlFilter = new qdr.app.tools.qfu.gui.Subforms.Common.FilterPathCtrl(); tlpLevel0.SuspendLayout(); tlpLevel1L.SuspendLayout(); groupBox1.SuspendLayout(); tlpLevel1R.SuspendLayout(); SuspendLayout(); // // tlpLevel0 // tlpLevel0.ColumnCount = 2; tlpLevel0.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F)); tlpLevel0.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F)); tlpLevel0.Controls.Add(tlpLevel1L, 0, 0); tlpLevel0.Controls.Add(tlpLevel1R, 1, 0); tlpLevel0.Dock = DockStyle.Fill; tlpLevel0.Location = new Point(0, 0); tlpLevel0.Name = "tlpLevel0"; tlpLevel0.RowCount = 1; tlpLevel0.RowStyles.Add(new RowStyle(SizeType.Percent, 50F)); tlpLevel0.Size = new Size(800, 220); tlpLevel0.TabIndex = 0; // // tlpLevel1L // tlpLevel1L.ColumnCount = 1; tlpLevel1L.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); tlpLevel1L.Controls.Add(groupBox1, 0, 0); tlpLevel1L.Controls.Add(ctrlDirSelection, 0, 1); tlpLevel1L.Dock = DockStyle.Fill; tlpLevel1L.Location = new Point(3, 3); tlpLevel1L.Name = "tlpLevel1L"; tlpLevel1L.RowCount = 3; tlpLevel1L.RowStyles.Add(new RowStyle()); tlpLevel1L.RowStyles.Add(new RowStyle(SizeType.Absolute, 60F)); tlpLevel1L.RowStyles.Add(new RowStyle()); tlpLevel1L.Size = new Size(394, 214); tlpLevel1L.TabIndex = 0; // // groupBox1 // groupBox1.Controls.Add(rbScopeFile); groupBox1.Controls.Add(rbScopeDir); groupBox1.Location = new Point(3, 3); groupBox1.Name = "groupBox1"; groupBox1.Size = new Size(388, 41); groupBox1.TabIndex = 0; groupBox1.TabStop = false; groupBox1.Text = "Scope"; // // rbScopeFile // rbScopeFile.AutoSize = true; rbScopeFile.Location = new Point(106, 20); rbScopeFile.Name = "rbScopeFile"; rbScopeFile.Size = new Size(48, 19); rbScopeFile.TabIndex = 1; rbScopeFile.Text = "Files"; rbScopeFile.UseVisualStyleBackColor = true; // // rbScopeDir // rbScopeDir.AutoSize = true; rbScopeDir.Checked = true; rbScopeDir.Location = new Point(10, 20); rbScopeDir.Name = "rbScopeDir"; rbScopeDir.Size = new Size(81, 19); rbScopeDir.TabIndex = 0; rbScopeDir.TabStop = true; rbScopeDir.Text = "Directories"; rbScopeDir.UseVisualStyleBackColor = true; // // ctrlDirSelection // ctrlDirSelection.Caption = "Directory to operate"; ctrlDirSelection.Dock = DockStyle.Fill; ctrlDirSelection.Location = new Point(3, 49); ctrlDirSelection.Margin = new Padding(3, 2, 3, 2); ctrlDirSelection.Name = "ctrlDirSelection"; ctrlDirSelection.SelectedPath = ""; ctrlDirSelection.Size = new Size(388, 56); ctrlDirSelection.TabIndex = 1; // // tlpLevel1R // tlpLevel1R.ColumnCount = 1; tlpLevel1R.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); tlpLevel1R.Controls.Add(chbDeleteEmpty, 0, 2); tlpLevel1R.Controls.Add(chbDryRun, 0, 1); tlpLevel1R.Controls.Add(chbIncludeSubdirs, 0, 0); tlpLevel1R.Controls.Add(ctrlFilter, 0, 3); tlpLevel1R.Dock = DockStyle.Fill; tlpLevel1R.Location = new Point(403, 3); tlpLevel1R.Name = "tlpLevel1R"; tlpLevel1R.RowCount = 4; tlpLevel1R.RowStyles.Add(new RowStyle()); tlpLevel1R.RowStyles.Add(new RowStyle()); tlpLevel1R.RowStyles.Add(new RowStyle()); tlpLevel1R.RowStyles.Add(new RowStyle()); tlpLevel1R.Size = new Size(394, 214); tlpLevel1R.TabIndex = 1; // // chbDeleteEmpty // chbDeleteEmpty.AutoSize = true; chbDeleteEmpty.Location = new Point(3, 48); chbDeleteEmpty.Margin = new Padding(3, 2, 3, 2); chbDeleteEmpty.Name = "chbDeleteEmpty"; chbDeleteEmpty.Size = new Size(219, 19); chbDeleteEmpty.TabIndex = 3; chbDeleteEmpty.Text = "Only delete empty files or directories"; chbDeleteEmpty.UseVisualStyleBackColor = true; // // chbDryRun // chbDryRun.AutoSize = true; chbDryRun.Location = new Point(3, 25); chbDryRun.Margin = new Padding(3, 2, 3, 2); chbDryRun.Name = "chbDryRun"; chbDryRun.Size = new Size(152, 19); chbDryRun.TabIndex = 2; chbDryRun.Text = "Dry run - without delete"; chbDryRun.UseVisualStyleBackColor = true; // // chbIncludeSubdirs // chbIncludeSubdirs.AutoSize = true; chbIncludeSubdirs.Location = new Point(3, 2); chbIncludeSubdirs.Margin = new Padding(3, 2, 3, 2); chbIncludeSubdirs.Name = "chbIncludeSubdirs"; chbIncludeSubdirs.Size = new Size(143, 19); chbIncludeSubdirs.TabIndex = 1; chbIncludeSubdirs.Text = "Include Subdirectories"; chbIncludeSubdirs.UseVisualStyleBackColor = true; // // ctrlFilter // ctrlFilter.Caption = "Filter to include"; ctrlFilter.FilterEnabled = false; ctrlFilter.FilterText = ""; ctrlFilter.Location = new Point(3, 71); ctrlFilter.Margin = new Padding(3, 2, 3, 2); ctrlFilter.Name = "ctrlFilter"; ctrlFilter.Size = new Size(388, 118); ctrlFilter.TabIndex = 4; // // CtrlClearDir // AutoScroll = true; AutoScrollMinSize = new Size(530, 220); Controls.Add(tlpLevel0); Name = "CtrlClearDir"; Size = new Size(800, 188); tlpLevel0.ResumeLayout(false); tlpLevel1L.ResumeLayout(false); groupBox1.ResumeLayout(false); groupBox1.PerformLayout(); tlpLevel1R.ResumeLayout(false); tlpLevel1R.PerformLayout(); ResumeLayout(false); } private TableLayoutPanel tlpLevel0; private TableLayoutPanel tlpLevel1L; private GroupBox groupBox1; private RadioButton rbScopeFile; private RadioButton rbScopeDir; private TableLayoutPanel tlpLevel1R; private CheckBox chbDeleteEmpty; private CheckBox chbDryRun; private CheckBox chbIncludeSubdirs; private Common.FilterPathCtrl ctrlFilter; private Common.DirectorySelectionCtrl ctrlDirSelection; } }