| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- 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 <scope> <directory> [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 <patterns>`: 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;
- }
- }
|