forked from LogExperts/LogExpert
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessLauncher.cs
More file actions
79 lines (62 loc) · 2.41 KB
/
ProcessLauncher.cs
File metadata and controls
79 lines (62 loc) · 2.41 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
using System;
using System.Diagnostics;
namespace LogExpert;
internal class ProcessLauncher : IKeywordAction
{
#region Properties
public string Text => GetName();
#endregion
#region IKeywordAction Member
private readonly object _callbackLock = new();
public void Execute (string keyword, string param, ILogExpertCallback callback, ILogLineColumnizer columnizer)
{
var start = 0;
int end;
if (param.StartsWith('"'))
{
start = 1;
end = param.IndexOf('"', start);
}
else
{
end = param.IndexOf(' ', StringComparison.Ordinal);
}
if (end == -1)
{
end = param.Length;
}
var procName = param[start..end];
lock (_callbackLock)
{
var parameters = param[end..].Trim();
parameters = parameters.Replace("%F", callback.GetFileName(), StringComparison.Ordinal);
parameters = parameters.Replace("%K", keyword, StringComparison.Ordinal);
var lineNumber = callback.LineNum; //Line Numbers start at 0, but are displayed (+1)
var logline = callback.GetLogLine(lineNumber).FullLine;
parameters = parameters.Replace("%L", string.Empty + lineNumber, System.StringComparison.Ordinal);
parameters = parameters.Replace("%T", callback.GetTabTitle(), StringComparison.Ordinal);
parameters = parameters.Replace("%C", logline, StringComparison.Ordinal);
Process explorer = new();
explorer.StartInfo.FileName = procName;
explorer.StartInfo.Arguments = parameters;
explorer.StartInfo.UseShellExecute = false;
explorer.Start();
}
}
public string GetName ()
{
return "ProcessLauncher keyword plugin";
}
public string GetDescription ()
{
return "Launches an external process. The plugin's parameter is the process name " +
"and its (optional) command line.\r\n" +
"Use the following variables for command line replacements:\r\n" +
"%F = Log file name (full path)\r\n" +
"%T = Tab title\r\n" +
"%L = Line number of keyword hit\r\n" +
"%K = Keyword\r\n" +
"%C = Complete line content";
}
#endregion
}