forked from Zerolone/workermanHelper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.pas
236 lines (173 loc) · 4.5 KB
/
main.pas
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
unit main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ClientFunction, StdCtrls, Menus, FileSystemWatcher, ShellAPI,
DosCommand;
type
TMainForm = class(TForm)
btnInit: TButton;
mmoLog: TMemo;
pm1: TPopupMenu;
mniLogClear: TMenuItem;
FileSystemWatcher1: TFileSystemWatcher;
btnRe: TButton;
mmoDos: TMemo;
btnStop: TButton;
btnKill: TButton;
DosCommand1: TDosCommand;
procedure btnInitClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure mniLogClearClick(Sender: TObject);
procedure FileSystemWatcher1Change(FileOperation: TFileOperation;
const FileName1, FileName2: String);
procedure btnReClick(Sender: TObject);
procedure btnStopClick(Sender: TObject);
procedure btnKillClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
procedure sinfo(str:string);
end;
var
MainForm: TMainForm;
strFolder:string;
strFilext:string; //文件后缀
strCmd :string; //cmd
strTmp : string;
bolRun:Boolean;
i:Integer;
implementation
{$R *.dfm}
procedure TMainForm.sinfo(str:string);
begin
str:= FormatDateTime('hh:nn:ss',Now()) + ' ' + str;
mmoLog.Lines.Add(str);
SendMessage(mmoLog.Handle,WM_VSCROLL,SB_BOTTOM,0);
end;
procedure TMainForm.btnInitClick(Sender: TObject);
begin
bolRun := true;
try
strFolder:=GetIni('folder');
except
ShowMessage('folder配置不存在!');
sinfo('folder配置不存在!');
end;
if(strFolder = '')then
begin
ShowMessage('folder配置有问题!');
end;
try
strFilext:=GetIni('filext');
except
ShowMessage('filext配置不存在!');
sinfo('filext配置不存在!');
end;
if strFilext = 'filext' then
strFilext := '';
sinfo('监控文件夹为:' + strFolder);
sinfo('监控后缀为:' + strFilext);
FileSystemWatcher1.WatchedDir := strFolder;
FileSystemWatcher1.Actived := true;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
mmoLog.Clear;
mmoLog.PopupMenu:=pm1;
mmoLog.ScrollBars:=ssVertical;
mmoDos.Clear;
bolRun:=false;
end;
procedure TMainForm.mniLogClearClick(Sender: TObject);
begin
mmoLog.Clear
end;
procedure TMainForm.FileSystemWatcher1Change(FileOperation: TFileOperation;
const FileName1, FileName2: String);
var ResultList:TStringList;
begin
if strFilext = '' then
begin
sinfo(FileName1 + '发生变化,规则全部文件,重载中');
btnRe.Click;
end
else
begin
ResultList := TStringList.Create;
try
ResultList.Delimiter := '.';
ResultList.DelimitedText := FileName1;
//for i:= 0 to ResultList.Count-1 do
//begin
// sinfo(ResultList[i]);
//end;
strTmp := ResultList[ResultList.Count-1];
if strTmp = strFilext then
begin
sinfo(FileName1 + '发生变化,规则指定文件,重载中');
btnRe.Click;
end;
except
end;
end;
//sinfo(FileName1 + '发生变化,重载中');
//sinfo(FileName2);
//sinfo(FileOperation );
end;
procedure TMainForm.btnReClick(Sender: TObject);
begin
//handle := FIndwindow(nil,Exename)
//SendMessage(handle,WM_Close,0,0)
if bolRun=True then
begin
try
strCmd:=GetIni('cmd');
sinfo('开始执行'+strCmd);
DosCommand1.Stop;
DosCommand1.CommandLine := strCmd;
DosCommand1.OutputLines:=mmoDos.Lines;
DosCommand1.Execute; //launch format process
DosCommand1.SendLine('', True); //equivalent to press enter key
// DiskName := 'test';
// DosCommand1.SendLine(DiskName, True); //enter the name of the volume
//RunDosInMemo(strCmd, mmoDos);
//strTmp:=GetDosOutput(strCmd);
//mmoDos.Lines.Add(strTmp);
//WinExec(PChar(strCmd), SW_SHOWNORMAL);
//sw_normal
//shellexecute(handle,nil,'cmd.exe',pchar(strCmd),nil,sw_normal);
except
ShowMessage('cmd配置不存在!');
sinfo('cmd配置不存在!');
end
end;
end;
procedure TMainForm.btnStopClick(Sender: TObject);
begin
//bolRun:=False;
FileSystemWatcher1.Actived:=False;
end;
procedure TMainForm.btnKillClick(Sender: TObject);
Var
wh : THandle;
begin
strTmp := GetIni('kill');
sinfo('kill='+strTmp);
wh := findwindow(nil, PChar(strTmp));
if wh<> 0 then
begin
PostMessage(wh, WM_CLOSE, 0, 0);
end
else
begin
sinfo('没有找到需要关闭的窗口');
end;
end;
procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
DosCommand1.Stop;
end;
end.