| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- using Quadarax.Foundation.Core.Value.Extensions;
- using System.Text;
- namespace qdr.app.tools.qfu.gui.Subforms
- {
- public partial class CtrlClone : UserControl, ICommanControl
- {
- public string Description => "Clone Command\r\nClone a source file to one or more destination files.\r\n\r\nSyntax:\r\nqfu clone <source_file> <target_files> [options]\r\n\r\nArguments:\r\n- `source_file`: Path to the source file to clone\r\n- `target_files`: Pipe-separated list of target file paths (`file1.txt|file2.txt|file3.txt`)\r\n\r\nOptions:\r\n- `-pe` or `-path_ensure`: Create destination directories if they don't exist\r\n- `-force`: Overwrite existing destination files\r\n- `-list`: Treat the first target file as a text file containing a list of destination paths (one per line)\r\n- `-n <count>`: Generate N numbered copies instead of using target files list";
- public string ViewName => "Clone";
- public CtrlClone()
- {
- InitializeComponent();
- chbFileList_CheckedChanged(this, new EventArgs());
- chbRepeat_CheckedChanged(this, new EventArgs());
- }
- private void chbRepeat_CheckedChanged(object sender, EventArgs e)
- {
- tbNRepeat.Enabled = chbRepeat.Checked;
- tbOutputs.Enabled = !chbRepeat.Checked;
- chbFileList.Enabled = !chbRepeat.Checked;
- }
- public void Execute()
- {
- var arguments = new StringBuilder();
- arguments.Append("clone");
- arguments.Append(" ");
- arguments.Append("\"").Append(ctrlSource.SelectedFile).Append("\"");
- if (chbRepeat.Enabled && chbRepeat.Checked)
- {
- if (int.TryParse(tbNRepeat.Text, out int n) && n > 0)
- {
- arguments.Append(" -n:").Append(n);
- }
- else
- throw new ArgumentException($"Invalid number of repeats specified '{tbNRepeat.Text}'. Please enter a valid positive integer.");
- }
- else if (chbFileList.Checked)
- {
- arguments.Append(" \"").Append(ctrlFileList.SelectedFile).Append("\"");
- arguments.Append(" -list");
- }
- else
- {
- arguments.Append(" ");
- var outputs = tbOutputs.Text.Split("\n", StringSplitOptions.RemoveEmptyEntries);
- foreach (var output in outputs)
- arguments.Append(output.Trim()).Append("|");
- }
- if (chbPe.Checked)
- {
- arguments.Append(" -pe");
- }
- if (chbForce.Checked)
- {
- arguments.Append(" -force");
- }
- ConsoleRunner.Run(arguments.ToString().SplitQuoted(" ", "\"", removeEmptyItems: true, trimValues: false, keepBracket: true));
- }
- private void chbFileList_CheckedChanged(object sender, EventArgs e)
- {
- ctrlFileList.Enabled = chbFileList.Checked;
- tbOutputs.Enabled = !chbFileList.Checked;
- chbRepeat.Enabled = !chbFileList.Checked;
- }
- private void ctrlFileList_SelectedFileChanged_1(object sender, EventArgs e)
- {
- tbOutputs.Text = File.ReadAllText(ctrlFileList.SelectedFile);
- }
- }
- }
|