CtrlClearDir.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. using Quadarax.Foundation.Core.Value.Extensions;
  2. using System.Text;
  3. namespace qdr.app.tools.qfu.gui.Subforms
  4. {
  5. public partial class CtrlClearDir : UserControl, ICommanControl
  6. {
  7. #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.
  8. public CtrlClearDir()
  9. #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.
  10. {
  11. InitializeComponent();
  12. }
  13. 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";
  14. public string ViewName => "Clear Dir";
  15. public void Execute()
  16. {
  17. var arguments = new StringBuilder();
  18. arguments.Append("cleardir");
  19. arguments.Append(" ");
  20. if (rbScopeFile.Checked)
  21. {
  22. arguments.Append("files");
  23. }
  24. else if (rbScopeDir.Checked)
  25. {
  26. arguments.Append("directories");
  27. }
  28. else
  29. {
  30. throw new InvalidOperationException("Please select a scope (files or directories).");
  31. }
  32. arguments.Append(" ");
  33. arguments.Append("\"").Append(ctrlDirSelection.SelectedPath).Append("\"");
  34. if (chbIncludeSubdirs.Checked)
  35. {
  36. arguments.Append(" ");
  37. arguments.Append(" -s");
  38. }
  39. if (ctrlFilter.FilterEnabled)
  40. {
  41. arguments.Append(" ");
  42. arguments.Append(" -f:\"").Append(ctrlFilter.FilterText).Append("\"");
  43. }
  44. if (chbDryRun.Checked)
  45. {
  46. arguments.Append(" ");
  47. arguments.Append(" -dry");
  48. }
  49. if (chbDeleteEmpty.Checked)
  50. {
  51. arguments.Append(" ");
  52. arguments.Append(" -empty");
  53. }
  54. ConsoleRunner.Run(arguments.ToString().SplitQuoted(" ", "\"", removeEmptyItems: true, trimValues: false, keepBracket: true));
  55. }
  56. private void InitializeComponent()
  57. {
  58. tlpLevel0 = new TableLayoutPanel();
  59. tlpLevel1L = new TableLayoutPanel();
  60. groupBox1 = new GroupBox();
  61. rbScopeFile = new RadioButton();
  62. rbScopeDir = new RadioButton();
  63. ctrlDirSelection = new qdr.app.tools.qfu.gui.Subforms.Common.DirectorySelectionCtrl();
  64. tlpLevel1R = new TableLayoutPanel();
  65. chbDeleteEmpty = new CheckBox();
  66. chbDryRun = new CheckBox();
  67. chbIncludeSubdirs = new CheckBox();
  68. ctrlFilter = new qdr.app.tools.qfu.gui.Subforms.Common.FilterPathCtrl();
  69. tlpLevel0.SuspendLayout();
  70. tlpLevel1L.SuspendLayout();
  71. groupBox1.SuspendLayout();
  72. tlpLevel1R.SuspendLayout();
  73. SuspendLayout();
  74. //
  75. // tlpLevel0
  76. //
  77. tlpLevel0.ColumnCount = 2;
  78. tlpLevel0.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
  79. tlpLevel0.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
  80. tlpLevel0.Controls.Add(tlpLevel1L, 0, 0);
  81. tlpLevel0.Controls.Add(tlpLevel1R, 1, 0);
  82. tlpLevel0.Dock = DockStyle.Fill;
  83. tlpLevel0.Location = new Point(0, 0);
  84. tlpLevel0.Name = "tlpLevel0";
  85. tlpLevel0.RowCount = 1;
  86. tlpLevel0.RowStyles.Add(new RowStyle(SizeType.Percent, 50F));
  87. tlpLevel0.Size = new Size(800, 220);
  88. tlpLevel0.TabIndex = 0;
  89. //
  90. // tlpLevel1L
  91. //
  92. tlpLevel1L.ColumnCount = 1;
  93. tlpLevel1L.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
  94. tlpLevel1L.Controls.Add(groupBox1, 0, 0);
  95. tlpLevel1L.Controls.Add(ctrlDirSelection, 0, 1);
  96. tlpLevel1L.Dock = DockStyle.Fill;
  97. tlpLevel1L.Location = new Point(3, 3);
  98. tlpLevel1L.Name = "tlpLevel1L";
  99. tlpLevel1L.RowCount = 3;
  100. tlpLevel1L.RowStyles.Add(new RowStyle());
  101. tlpLevel1L.RowStyles.Add(new RowStyle(SizeType.Absolute, 60F));
  102. tlpLevel1L.RowStyles.Add(new RowStyle());
  103. tlpLevel1L.Size = new Size(394, 214);
  104. tlpLevel1L.TabIndex = 0;
  105. //
  106. // groupBox1
  107. //
  108. groupBox1.Controls.Add(rbScopeFile);
  109. groupBox1.Controls.Add(rbScopeDir);
  110. groupBox1.Location = new Point(3, 3);
  111. groupBox1.Name = "groupBox1";
  112. groupBox1.Size = new Size(388, 41);
  113. groupBox1.TabIndex = 0;
  114. groupBox1.TabStop = false;
  115. groupBox1.Text = "Scope";
  116. //
  117. // rbScopeFile
  118. //
  119. rbScopeFile.AutoSize = true;
  120. rbScopeFile.Location = new Point(106, 20);
  121. rbScopeFile.Name = "rbScopeFile";
  122. rbScopeFile.Size = new Size(48, 19);
  123. rbScopeFile.TabIndex = 1;
  124. rbScopeFile.Text = "Files";
  125. rbScopeFile.UseVisualStyleBackColor = true;
  126. //
  127. // rbScopeDir
  128. //
  129. rbScopeDir.AutoSize = true;
  130. rbScopeDir.Checked = true;
  131. rbScopeDir.Location = new Point(10, 20);
  132. rbScopeDir.Name = "rbScopeDir";
  133. rbScopeDir.Size = new Size(81, 19);
  134. rbScopeDir.TabIndex = 0;
  135. rbScopeDir.TabStop = true;
  136. rbScopeDir.Text = "Directories";
  137. rbScopeDir.UseVisualStyleBackColor = true;
  138. //
  139. // ctrlDirSelection
  140. //
  141. ctrlDirSelection.Caption = "Directory to operate";
  142. ctrlDirSelection.Dock = DockStyle.Fill;
  143. ctrlDirSelection.Location = new Point(3, 49);
  144. ctrlDirSelection.Margin = new Padding(3, 2, 3, 2);
  145. ctrlDirSelection.Name = "ctrlDirSelection";
  146. ctrlDirSelection.SelectedPath = "";
  147. ctrlDirSelection.Size = new Size(388, 56);
  148. ctrlDirSelection.TabIndex = 1;
  149. //
  150. // tlpLevel1R
  151. //
  152. tlpLevel1R.ColumnCount = 1;
  153. tlpLevel1R.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
  154. tlpLevel1R.Controls.Add(chbDeleteEmpty, 0, 2);
  155. tlpLevel1R.Controls.Add(chbDryRun, 0, 1);
  156. tlpLevel1R.Controls.Add(chbIncludeSubdirs, 0, 0);
  157. tlpLevel1R.Controls.Add(ctrlFilter, 0, 3);
  158. tlpLevel1R.Dock = DockStyle.Fill;
  159. tlpLevel1R.Location = new Point(403, 3);
  160. tlpLevel1R.Name = "tlpLevel1R";
  161. tlpLevel1R.RowCount = 4;
  162. tlpLevel1R.RowStyles.Add(new RowStyle());
  163. tlpLevel1R.RowStyles.Add(new RowStyle());
  164. tlpLevel1R.RowStyles.Add(new RowStyle());
  165. tlpLevel1R.RowStyles.Add(new RowStyle());
  166. tlpLevel1R.Size = new Size(394, 214);
  167. tlpLevel1R.TabIndex = 1;
  168. //
  169. // chbDeleteEmpty
  170. //
  171. chbDeleteEmpty.AutoSize = true;
  172. chbDeleteEmpty.Location = new Point(3, 48);
  173. chbDeleteEmpty.Margin = new Padding(3, 2, 3, 2);
  174. chbDeleteEmpty.Name = "chbDeleteEmpty";
  175. chbDeleteEmpty.Size = new Size(219, 19);
  176. chbDeleteEmpty.TabIndex = 3;
  177. chbDeleteEmpty.Text = "Only delete empty files or directories";
  178. chbDeleteEmpty.UseVisualStyleBackColor = true;
  179. //
  180. // chbDryRun
  181. //
  182. chbDryRun.AutoSize = true;
  183. chbDryRun.Location = new Point(3, 25);
  184. chbDryRun.Margin = new Padding(3, 2, 3, 2);
  185. chbDryRun.Name = "chbDryRun";
  186. chbDryRun.Size = new Size(152, 19);
  187. chbDryRun.TabIndex = 2;
  188. chbDryRun.Text = "Dry run - without delete";
  189. chbDryRun.UseVisualStyleBackColor = true;
  190. //
  191. // chbIncludeSubdirs
  192. //
  193. chbIncludeSubdirs.AutoSize = true;
  194. chbIncludeSubdirs.Location = new Point(3, 2);
  195. chbIncludeSubdirs.Margin = new Padding(3, 2, 3, 2);
  196. chbIncludeSubdirs.Name = "chbIncludeSubdirs";
  197. chbIncludeSubdirs.Size = new Size(143, 19);
  198. chbIncludeSubdirs.TabIndex = 1;
  199. chbIncludeSubdirs.Text = "Include Subdirectories";
  200. chbIncludeSubdirs.UseVisualStyleBackColor = true;
  201. //
  202. // ctrlFilter
  203. //
  204. ctrlFilter.Caption = "Filter to include";
  205. ctrlFilter.FilterEnabled = false;
  206. ctrlFilter.FilterText = "";
  207. ctrlFilter.Location = new Point(3, 71);
  208. ctrlFilter.Margin = new Padding(3, 2, 3, 2);
  209. ctrlFilter.Name = "ctrlFilter";
  210. ctrlFilter.Size = new Size(388, 118);
  211. ctrlFilter.TabIndex = 4;
  212. //
  213. // CtrlClearDir
  214. //
  215. AutoScroll = true;
  216. AutoScrollMinSize = new Size(530, 220);
  217. Controls.Add(tlpLevel0);
  218. Name = "CtrlClearDir";
  219. Size = new Size(800, 188);
  220. tlpLevel0.ResumeLayout(false);
  221. tlpLevel1L.ResumeLayout(false);
  222. groupBox1.ResumeLayout(false);
  223. groupBox1.PerformLayout();
  224. tlpLevel1R.ResumeLayout(false);
  225. tlpLevel1R.PerformLayout();
  226. ResumeLayout(false);
  227. }
  228. private TableLayoutPanel tlpLevel0;
  229. private TableLayoutPanel tlpLevel1L;
  230. private GroupBox groupBox1;
  231. private RadioButton rbScopeFile;
  232. private RadioButton rbScopeDir;
  233. private TableLayoutPanel tlpLevel1R;
  234. private CheckBox chbDeleteEmpty;
  235. private CheckBox chbDryRun;
  236. private CheckBox chbIncludeSubdirs;
  237. private Common.FilterPathCtrl ctrlFilter;
  238. private Common.DirectorySelectionCtrl ctrlDirSelection;
  239. }
  240. }