Repository navigation
Expand file tree
/
Copy pathCommandPrompt.cs
More file actions
115 lines (99 loc) · 3.27 KB
/
Copy pathCommandPrompt.cs
File metadata and controls
115 lines (99 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace netCommander
{
public partial class CommandPrompt : UserControl
{
public CommandPrompt()
{
InitializeComponent();
set_lang();
//Font cmd_font = new Font(FontFamily.GenericMonospace, textBox1.Font.Size, FontStyle.Regular);
//Font cmd_font = new Font(Options.FontFilePanel, FontStyle.Regular);
//textBox1.Font = cmd_font;
}
private void set_lang()
{
if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
{
return;
}
buttonExecute.Text = Options.GetLiteral(Options.LANG_EXECUTE);
}
public string CommandText
{
get
{
return textBox1.Text;
}
set
{
textBox1.Text = value;
}
}
public void AddCommandChunk(string text)
{
textBox1.AppendText(" ");
if (text.Contains(" "))
{
text = '"' + text + '"';
}
textBox1.AppendText(text);
}
public void Execute()
{
intern_execute();
}
private void intern_execute()
{
string reg_pattern = Options.REGEX_PARSE_COMMAND;
Regex rex = new Regex(reg_pattern);
try
{
string[] splitted = rex.Split(textBox1.Text, 2);
if (splitted.Length < 2)
{
throw new ArgumentException(Options.GetLiteral(Options.LANG_CANNOT_PARSE_COMMAND_LINE));
// throw new ApplicationException(Options.GetLiteral(Options.LANG_CANNOT_PARSE_COMMAND_LINE));
}
string command_name = splitted[1];
string command_args = splitted.Length > 2 ? splitted[2] : string.Empty;
ProcessStartInfo psi = new ProcessStartInfo();
psi.Arguments = command_args;
psi.CreateNoWindow = false;
psi.ErrorDialog = false;
psi.FileName = command_name;
psi.UseShellExecute = true;
psi.WorkingDirectory = Directory.GetCurrentDirectory();
Process p = new Process();
p.StartInfo = psi;
p.Start();
}
catch (Exception ex)
{
Messages.ShowException(ex, string.Format(Options.GetLiteral(Options.LANG_CANNOT_EXECUTE_0), textBox1.Text));
}
}
private void buttonExecute_Click(object sender, EventArgs e)
{
intern_execute();
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Enter:
intern_execute();
break;
}
}
}
}