-
Notifications
You must be signed in to change notification settings - Fork 4
/
Static.pas
734 lines (686 loc) · 22.1 KB
/
Static.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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
unit Static;
interface
uses Windows, SysUtils, Classes, Tlhelp32, Dialogs, Plugins, ShellApi, Forms, mmSystem;
function GetMyPath: string; // Âîçâðàùàåò ïàïêó, ãäå íàõîäèòñÿ ïðîãðàììà ñî ñëåøåì â êîíöå
function GetProgPath(Str: string): string; // Âûðåçàåò ïàïêó èç ïîëíîãî ïóòè (C:\Tmp\yo.exe -> C:\Tmp\)
function GetProgDrive(Str: string): string; // Âûðåçàåò äèñê èç ïîëíîãî ïóòè (C:\Tmp\yo.exe -> C:\)
function GetProgName(Str: string): string; // Âûðåçàåò èìÿ èç ïîëíîãî ïóòè (C:\Tmp\yo.exe qwe rty -> C:\Tmp\yo.exe)
function GetProgParam(Str: string): string; // Âûðåçàåò ïàðàìåòðû èç ïîëíîãî ïóòè (alias qwe rty -> qwe rty)
function GetLastDelimiter(Str: string): integer; // Âîçâðàùàåò ïîçèöèþ ïîñëåäíåãî ñëåøà èëè 0, åñëè èõ â ñòðîêå íåò
function IsWWW(Str: string): boolean; // Âîçâðàùàåò true, åñëè ïåðåäàííûé ïàðàìåòð - óðë èíòåðíåòà
function IsEmail(Str: string): boolean; // Âîçâðàùàåò true, åñëè ïåðåäàííûé ïàðàìåòð - àäðåñ ïî÷òû
function CorrectEMail(Str: string): string; // Âñòàâëÿåò âìåñòî ïðîáåëîâ - %20
function BindHotKey(keyAlt, keyCtrl, keyShift, keyWin: boolean; keyCode: cardinal; id: integer; frmHadle: HWND): boolean; // Çàáèâàåò â ñèñòåìå õîòêåé
procedure UnBindHotKey(id: integer; frmHadle: HWND); // Ñíîñèò åãî
function ParseConsole(strCon: string): boolean; // Ïàðñèò âñþ ñòðîêó, çàïóùåííóþ ñ êîíñîëè
function ParseAlias(Str: string): boolean; // Ïàðñèò àëèàñû
function ParseSysAlias(Str: string): boolean; // Ïàðñèò ñèñòåìíûå àëèàñû
function ParseInternal(Str: string): boolean; // Ïàðñèò âíóòðåííèå êîìàíäû
function ParseWWW(Str: string): boolean; // Ïàðñèò àäðåñà èíòåðíåòà
function ParseEMail(Str: string): boolean; // Ïàðñèò àäðåñà ïî÷òû
function ParseFolder(Str: string): boolean; // Ïàðñèò ïàïêè (ïóòè)
function ParseFile(Str: string): boolean; // Ïàðñèò ôàéëû (ïóòè)
function ParsePlugin(Str: string; FromAlias: boolean): boolean; // Ïàðñèò ïëàãèíû
function ParseDOS(Str: string): boolean; // Ïàðñèò DOS
function IsNumber(Str: string): boolean; // ßâëÿåòñÿ ëè ñòðîêà öåëûì ÷èñëîì
function KillZero(Str: string): string; // Óäàëÿåò ïåðâè÷íûå íóëè â ñòðîêå
function GetWinVersion: String; // Âîçâðàùàåò âåðñèþ windows
function KillTask(ExeFileName: string): integer; // Ñíèìàåò ïðîöåññ ïî èìåíè ôàéëà
function SetProcessPriority(Priority: integer): integer; // Èçìåíÿåò ïðèîðèòåò ñâîåãî ïðîöåññà
function GetProcessPriority: integer; // Âîçâðàùàåò ïðèîðèòåò ñâîåãî ïðîöåññà
function GetTypePath(Str: string; SelStart: integer): integer; // Âîçâðàùàåò íîìåð ñèìâîëà, ãäå íà÷èíàåòñÿ íàáèðàòüñÿ ïóòü
function GetDOSEnvVar(const VarName: string): string; // Âîçâðàùàåò çíà÷åíèå ñèñòåìíîé ïåðåìåííîé
function GetPathFolder(Str: string): string; // Âîçâðàùàåò ïîëíûé ïóòü ê ôàéëó, åñëè îí åñòü â îäíîì ìåñòå èç ïåðåìåííîé PATH
function GetNumWord(Str, Separator: string; Num: integer): string; // Âîçâðàùàåò íóæíîå ïî ñ÷åòó ñëîâî â äàííîé ñòðîêå è ñ äàííûì ðàçäåëèòåëåì
procedure SetKeyboardLayout(Str: string); // Óñòàíàâëèâàåò íóæíóþ ðàñêëàäêó
function DriveState(DrvLetter: string): integer; // Âîçâðàùàåò ñîñòîÿíèå äèñêà
function RunShell(action: string; param: string = ''; path: string = ''; state: integer = SW_ShowNormal; method: string = 'open'; handle: HWND = 0): HWND; // Çàïóñêàåò ÷åðåç ShellExecute è ñìîòðèò, ïîëó÷èëîñü ëè
procedure PlayFile(FileName: string); // Ïðîèãðûâàåò óêàçàííûé ôàéë
const
// Âñòðîåííûå êîìàíäû WinConsole
InSide: array[1..14] of string=('/about',
'/checkconfig',
'/config',
'/exit',
'/help',
'/hide',
'/homedir',
'/inidir',
'/inifiles',
'/load',
'/reread',
'/settings',
'/show',
'/unload'{,
'/test'});
Program_Name='TypeAndRun'; // Íàçâàíèå ïðîãðàììû
Program_Version='4.7b11'; // Âåðñèÿ ïðîãðàììû
HotKeyId=666; // Id ãëàâíîãî õîòêåÿ
var
Program_Config: string; // Íàçâàíèå èíèøêè êîíôèãà
Program_History: string; // Íàçâàíèå èíèøêè èñòîðèè
Program_Config_Old: string; // Êîíôèã ñ ìåðòâûìè àëèàñàìè
Program_Plugin: string; // Íàçâàíèå èíèøêè ïëàãèíîâ
implementation
uses Configs, ForAll, frmConsoleUnit, StrUtils, Settings;
// Âîçâðàùàåò ïàïêó, ãäå íàõîäèòñÿ ïðîãðàììà ñî ñëåøåì â êîíöå
// Èñïîëüçóåò ôóíêöèþ GetProgPath äëÿ âûðåçàíèÿ ïóòè
function GetMyPath: string;
begin
Result:=GetProgPath(ParamStr(0));
end;
// Âûðåçàåò ïàïêó èç ïîëíîãî ïóòè (C:\Tmp\yo.exe -> C:\Tmp\)
// Èñïîëüçóåò ôóíêöèþ GetLastDelimiter äëÿ ïîëó÷åíèÿ ïîçèöèè ïîñëåäíåãî ñëåøà
// Str - ïîëíûé ïóòü
function GetProgPath(Str: string): string;
begin
if Copy(Str, 0, 1)='"' then
Result:=Copy(Str, 2, GetLastDelimiter(Str)-1)
else
Result:=Copy(Str, 1, GetLastDelimiter(Str));
end;
// Âûðåçàåò äèñê èç ïîëíîãî ïóòè (C:\Tmp\yo.exe -> C:\)
// Str - ïîëíûé ïóòü
function GetProgDrive(Str: string): string;
begin
Result:=Copy(Str, 1, 3);
end;
// Âûðåçàåò èìÿ èç ïîëíîãî ïóòè (C:\Tmp\yo.exe qwe rty -> C:\Tmp\yo.exe)
// Str - ïîëíûé ïóòü
function GetProgName(Str: string): string;
var
tmpStr, tmpProg, tmpParam: string;
begin
tmpStr:=Trim(Str);
tmpParam:='';
if Copy(tmpStr, 0, 1)='"' then begin
Delete(tmpStr, 1, 1);
tmpProg:=Copy(tmpStr, 0, Pos('"', tmpStr)-1);
Delete(tmpStr, 1, Length(tmpProg)+2);
tmpParam:=tmpStr;
end
else if Pos(' ', tmpStr)<>0 then begin
tmpProg:=Copy(tmpStr, 0, Pos(' ', tmpStr)-1);
Delete(tmpStr, 1, Pos(' ', tmpStr));
tmpParam:=tmpStr;
end
else
tmpProg:=tmpStr;
Result:=tmpProg;
{if Pos(' ', Str)<> 0 then
Result:=Copy(Str, 0, Pos(' ', str)-1)
else
Result:=Str;}
end;
// Âûðåçàåò ïàðàìåòðû èç ïîëíîãî ïóòè (alias qwe rty -> qwe rty)
// Str - ïîëíûé ïóòü
function GetProgParam(Str: string): string;
var
tmpStr, tmpProg, tmpParam: string;
begin
tmpStr:=Trim(Str);
tmpParam:='';
if Copy(tmpStr, 0, 1)='"' then begin
Delete(tmpStr, 1, 1);
tmpProg:=Copy(tmpStr, 0, Pos('"', tmpStr)-1);
Delete(tmpStr, 1, Length(tmpProg)+2);
tmpParam:=tmpStr;
end
else if Pos(' ', tmpStr)<>0 then begin
tmpProg:=Copy(tmpStr, 0, Pos(' ', tmpStr)-1);
Delete(tmpStr, 1, Pos(' ', tmpStr));
tmpParam:=tmpStr;
end
else
tmpProg:=tmpStr;
Result:=tmpParam;
{if Pos(' ', Str)<> 0 then
Result:=Copy(Str, Pos(' ', str)+1, Length(Str)-Pos(' ', str)+1)
else
Result:='';}
end;
// Âîçâðàùàåò ïîçèöèþ ïîñëåäíåãî ñëåøà èëè 0, åñëè èõ â ñòðîêå íåò
// Ýòà ôóíêöèÿ èñïîëüçóåòñÿ, ãäå íàäî âûðåçàòü ÷àñòü ïóòè
// Str - ïóòü
function GetLastDelimiter(Str: string): integer;
var
i: integer;
begin
for i:=length(Str) downto 0 do begin
if Copy(Str, i, 1)='\' then Break;
end;
Result:=i;
end;
// Âîçâðàùàåò true, åñëè ïåðåäàííûé ïàðàìåòð - óðë èíòåðíåòà
// Îïðåäåëÿåò ïî íà÷àëüíûì 'www.' èëè 'http://' â ñòðîêå
// Str - óðë
function IsWWW(Str: string): boolean;
begin
Result:=(AnsiLowerCase(Copy(Str, 1, 4))=AnsiLowerCase('www.')) or (AnsiLowerCase(Copy(Str, 1, 7))=AnsiLowerCase('http://'));
end;
// Âîçâðàùàåò true, åñëè ïåðåäàííûé ïàðàìåòð - àäðåñ ïî÷òû
//  ñòðîêå äîëæíà áûòü ñíà÷àëà '@', à ïîòîì '.' - çíà÷èò ýòî ìûëî
// Str - àäðåñ ïî÷òû
function IsEMail(Str: string): boolean;
begin
if (Pos('@', Str)<>0) and (Copy(Str, 0, 1)<>'@') then begin
Delete(Str, 1, Pos('@', Str));
Result:=(Pos('.', Str)<>0) and (Copy(Str, 0, 1)<>'.');
end
else
Result:=False;
end;
// Âñòàâëÿåò âìåñòî ïðîáåëîâ - %20
// Òðåáóåòñÿ äëÿ çàïóñêà ïî÷òû ÷åðåç 'mailto:'
// Str - àäðåñ ïî÷òû äëÿ ïðîâåðêè
function CorrectEMail(Str: string): string;
begin
while Pos(' ', Str)<>0 do begin
Insert('%20', Str, Pos(' ', Str));
Delete(Str, Pos(' ', Str), 1);
end;
Result:=Str;
end;
// Çàáèâàåò â ñèñòåìå õîòêåé
// Ïåðåäàâàåìûå ïàðàìåòðû: Alt, Ctrl, Shift, Win, ñàìà êëàâèøà, Id õîòêåÿ è Handle ôîðìû
// Ôóíêöèÿ âîçâðàùàåò True, åñëè õîòêåé óäà÷íî çàáèò, èíà÷å - False
function BindHotKey(keyAlt, keyCtrl, keyShift, keyWin: boolean; keyCode: cardinal; id: integer; frmHadle: HWND): boolean;
var
ModKey: cardinal;
begin
ModKey:=0;
if keyAlt then ModKey:=ModKey+1;
if keyCtrl then ModKey:=ModKey+2;
if keyShift then ModKey:=ModKey+4;
if keyWin then ModKey:=ModKey+8;
Result:=RegisterHotkey(frmHadle, id, ModKey, keyCode);
end;
// Ñíîñèò çàáèòûé õîòêåé
// Ïåðåäàâàåìûå ïàðàìåòðû: Handle ôîðìû è Id õîòêåÿ
procedure UnBindHotKey(id: integer; frmHadle: HWND);
begin
UnRegisterHotkey(frmHadle, id);
end;
// Ïàðñèò âñþ ñòðîêó, çàïóùåííóþ ñ êîíñîëè, íà ïðåäìåò çàïóñêàåìîñòè ïî ðàçíûì êàòåãîðèÿì
// Âîçâðàùàåò TRUE, åñëè ÷òî-òî óäàëîñü çàïóñòèòü
// strCon - òåêñò â êîíñîëè íà ìîìåíò çàïóñêà
function ParseConsole(strCon: string): boolean;
var
IfExec: boolean;
// tmpCon: string;
begin
IfExec:=False;
{ while Pos(' & ', strCon)<>0 do begin
tmpCon:=Copy(strCon, 0, Pos(' & ', strCon)-1);
ShowMessage('|'+tmpCon+'|');
Exit;
end;}
if (not IfExec) and Options.Exec.Internal then
if ParseInternal(strCon) then IfExec:=True;
if (not IfExec) and Options.Exec.Alias then
if ParseAlias(strCon) then IfExec:=True;
if (not IfExec) and Options.Exec.SysAlias then
if ParseSysAlias(strCon) then IfExec:=True;
if (not IfExec) and Options.Exec.WWW then
if ParseWWW(strCon) then IfExec:=True;
if (not IfExec) and Options.Exec.EMail then
if ParseEMail(strCon) then IfExec:=True;
if (not IfExec) and Options.Exec.Folders then
if ParseFolder(strCon) then ifExec:=True;
if (not IfExec) and Options.Exec.Files then
if ParseFile(strCon) then IfExec:=True;
if (not IfExec) and Options.Exec.Plugins then
if ParsePlugin(strCon, False) then IfExec:=True;
if (not IfExec) and Options.Exec.Shell then
if ParseDOS(strCon) then IfExec:=True;
IsShift:=False;
IsParseCL:=False;
IsParseMessage:=False;
Result:=IfExec;
end;
// Ïàðñèò âíóòðåííèå êîìàíäû
// Âîçâðàùàåò TRUE, åñëè óäàëîñü çàïóñòèòü âíóòðåííóþ êîìàíäó
// Str - âíóòðåííÿÿ êîìàíäà
function ParseInternal(Str: string): boolean;
var
i: integer;
IfExec: boolean;
begin
IfExec:=False;
for i:=1 to High(InSide) do begin
if (GetProgName(Str)=Copy(InSide[i], 0, Length(Str))) or (not Options.EasyType.CaseSensitivity and (AnsiLowerCase(Str)=AnsiLowerCase(InSide[i]))) then begin
IfExec:=True;
HideCon;
ExecInternal(i, GetProgParam(Str));
SaveHistoryInternal(i, GetProgParam(Str));
Break;
end;
end;
Result:=IfExec;
end;
// Ïàðñèò àëèàñû
// Âîçâðàùàåò TRUE, åñëè óäàëîñü çàïóñòèòü õîòü îäèí èç íèõ
// Str - àëèàñ
function ParseAlias(Str: string): boolean;
var
i: integer;
IfExec: boolean;
tmpStr: string;
begin
IfExec:=False;
for i:=0 to ConfigStr.Count-1 do begin
if (GetProgName(Str)=GetName('alias', ConfigStr.Strings[i])) or (not Options.EasyType.CaseSensitivity and (AnsiLowerCase(GetProgName(Str))=AnsiLowerCase(GetName('alias', ConfigStr.Strings[i])))) then begin
HideCon;
if not IsShift then begin
tmpStr:=GetName('action', ConfigStr.Strings[i]);
if IsWWW(tmpStr) then begin
InsertS(tmpStr, GetProgParam(Str));
ExecWWW(tmpStr);
end
else begin
ExecAlias(i, GetProgParam(Str));
end;
end
else begin
tmpStr:=GetName('action', ConfigStr.Strings[i]);
if IsWWW(tmpStr) then begin
ExecAlias(i, GetProgParam(Str));
end
else
KillTask(ExtractFileName(tmpStr));
end;
SaveHistoryAlias(i, GetProgParam(Str));
MoveTopConfig(i);
IfExec:=True;
end;
end;
Result:=IfExec;
end;
// Ïàðñèò ñèñòåìíûå àëèàñû
// Âîçâðàùàåò TRUE, åñëè óäàëîñü çàïóñòèòü õîòü îäèí èç íèõ
// Str - àëèàñ
function ParseSysAlias(Str: string): boolean;
var
i: integer;
IfExec: boolean;
begin
IfExec:=False;
for i:=0 to Options.SystemAliases.Name.Count-1 do begin
if (GetProgName(Str)=Options.SystemAliases.Name.Strings[i]) or (not Options.EasyType.CaseSensitivity and (AnsiLowerCase(GetProgName(Str))=AnsiLowerCase(Options.SystemAliases.Name.Strings[i]))) then begin
HideCon;
if not IsShift then begin
ExecSysAlias(i, GetProgParam(Str));
SaveSysHistoryAlias(i, GetProgParam(Str));
end
else
KillTask(ExtractFileName(Options.SystemAliases.Action.Strings[i]));
IfExec:=True;
end;
end;
Result:=IfExec;
end;
// Ïàðñèò àäðåñà èíòåðíåòà
// Âîçâðàùàåò TRUE, åñëè óäàëîñü çàïóñòèòü àäðåñ èíòåðíåòà
// Str - óðë
function ParseWWW(Str: string): boolean;
begin
if IsWWW(Str) then begin
HideCon;
ExecWWW(Str);
SaveHistoryWWW(Str);
Result:=True;
end
else
Result:=False;
end;
// Ïàðñèò àäðåñà ïî÷òû
// Âîçâðàùàåò TRUE, åñëè óäàëîñü çàïóñòèòü àäðåñ ïî÷òû
// Str - àäðåñ ïî÷òû
function ParseEMail(Str: string): boolean;
begin
if IsEmail(Str) then begin
HideCon;
ExecEMail(Str);
SaveHistoryEMail(Str);
Result:=True;
end
else
Result:=False;
end;
// Ïàðñèò ïàïêè (ïóòè)
// Âîçâðàùàåò TRUE, åñëè óäàëîñü îòêðûòü ïàïêó
// Str - ïóòü ê ïàïêå
function ParseFolder(Str: string): boolean;
begin
if DirectoryExists(Str) then begin
HideCon;
ExecFolder(Str);
SaveHistoryFolder(Str);
Result:=True;
end
else
Result:=False;
end;
// Ïàðñèò ôàéëû (ïóòè)
// Str - ïóòü ê ôàéëó
function ParseFile(Str: string): boolean;
var
tmpStr: string;
begin
tmpStr:=Str;
while Pos('"', tmpStr)<>0 do begin
Delete(tmpStr, Pos('"', tmpStr), 1);
end;
if FileExists(tmpStr) then begin
HideCon;
ExecFile(tmpStr, '', GetProgPath(Str));
SaveHistoryDOS(Str);
Result:=True;
end
else if FileExists(GetProgName(tmpStr)) then begin
HideCon;
ExecFile(GetProgName(tmpStr), GetProgParam(Str), GetProgPath(tmpStr));
SaveHistoryDOS(Str);
Result:=True;
end
else if GetPathFolder(GetProgName(tmpStr))<>'' then begin
HideCon;
ExecFile(GetPathFolder(GetProgName(tmpStr)), GetProgParam(Str), GetProgPath(tmpStr));
SaveHistoryDOS(Str);
Result:=True;
end
else
Result:=False;
end;
// Ïàðñèò ïëàãèíû
// Str - ïóòü ê ôàéëó
// FromAlias - åñëè çàïóñê ïëàãèíà äåëàåòñÿ èç àëèàñà
function ParsePlugin(Str: string; FromAlias: boolean): boolean;
var
i: integer;
tmpParse: TExec;
begin
Result:=False;
for i:=0 to High(PluginDll) do begin
tmpParse.con_text:='';
tmpParse:=ExecPlugin(i, Str);
if tmpParse.run<>0 then begin
if tmpParse.run=2 then begin
frmTARConsole.txtConsole.Text:=tmpParse.con_text;
frmTARConsole.txtConsole.SelStart:=tmpParse.con_sel_start;
frmTARConsole.txtConsole.SelLength:=tmpParse.con_sel_length;
end
else
HideCon;
if (not FromAlias) and PluginDll[i].SaveHistory then SaveHistoryPlugin(Str);
Result:=True;
Break;
end;
end;
end;
// Ïàðñèò DOS
// Âîâðàùàåò TRUE, åñëè óäàëîñü çàïóñòèòü
// Str - ñòðîêà íà çàïóñê ÷åðåç shell
function ParseDOS(Str: string): boolean;
begin
if Options.Path.Shell<>'' then begin
HideCon;
ExecDOS(Str);
SaveHistoryDOS(Str);
Result:=True
end
else
Result:=False;
end;
// ßâëÿåòñÿ ëè ñòðîêà öåëûì ÷èñëîì
// Str - ñòðîêà äëÿ ïðîâåðêè
function IsNumber(Str: string): boolean;
var
i: integer;
flag: boolean;
// ßâëÿåòñÿ ëè ñèìâîë öåëûì ÷èñëîì
// Str - ñèìâîë äëÿ ïðîâåðêè
function IsNum(Str: string): boolean;
begin
IsNum:=((Str='0') or (Str='1') or (Str='2') or (Str='3') or (Str='4') or (Str='5') or (Str='6') or (Str='7') or (Str='8') or (Str='9'));
end;
begin
flag:=False;
for i:=0 to Length(Str) do begin
if (not IsNum(Copy(Str, i, 1))) then flag:=True;
end;
Result:=not flag;
end;
// Óäàëÿåò ïåðâè÷íûå íóëè â ñòðîêå
// Str - äàííàÿ ñòðîêà
function KillZero(Str: string): string;
begin
while (Copy(Str, 0, 1)='0') and (Length(Str)<>1) do
Delete(Str, 1, 1);
Result:=Str;
end;
// Âîçâðàùàåò âåðñèþ windows
function GetWinVersion: String;
var
VersionInfo: TOSVersionInfo;
OSName: string;
begin
VersionInfo.dwOSVersionInfoSize:= SizeOf(TOSVersionInfo);
if Windows.GetVersionEx(VersionInfo) then begin
with VersionInfo do begin
case dwPlatformId of
VER_PLATFORM_WIN32s: OSName:='Win32s';
VER_PLATFORM_WIN32_WINDOWS: OSName:='Windows 95';
VER_PLATFORM_WIN32_NT: OSName:='Windows NT';
end;
Result:=OSName+'|'+IntToStr(dwMajorVersion)+'|'+IntToStr(dwMinorVersion)+'|'+IntToStr(dwBuildNumber)+'|'+szCSDVersion;
end;
end
else
Result:='';
end;
// Ñíèìàåò ïðîöåññ ïî èìåíè ôàéëà
// ExeFileName - èìÿ ôàéëà
function KillTask(ExeFileName: string): integer;
const
PROCESS_TERMINATE=$0001;
var
ContinueLoop: boolean;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
result:= 0;
FSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize:=Sizeof(FProcessEntry32);
ContinueLoop:=Process32First(FSnapshotHandle, FProcessEntry32);
while integer(ContinueLoop)<>0 do begin
if((UpperCase(ExtractFileName(FProcessEntry32.szExeFile))=UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile)=UpperCase(ExeFileName))) then
Result:=Integer(TerminateProcess(OpenProcess(PROCESS_TERMINATE, BOOL(0), FProcessEntry32.th32ProcessID), 0));
ContinueLoop:=Process32Next(FSnapshotHandle, FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;
// Èçìåíÿåò ïðèîðèòåò ñâîåãî ïðîöåññà
// Priority - ïðèîðèòåò:
// -1 - idle
// 0 - normal
// 1 - high
// 2 - realtime
function SetProcessPriority(Priority: integer): integer;
var
H: THandle;
begin
Result:=0;
H:=GetCurrentProcess();
if(Priority=-1) then
SetPriorityClass(H, IDLE_PRIORITY_CLASS)
else if (Priority=0) then
SetPriorityClass(H, NORMAL_PRIORITY_CLASS)
else if (Priority=1) then
SetPriorityClass(H, HIGH_PRIORITY_CLASS)
else if (Priority=2) then
SetPriorityClass(H, REALTIME_PRIORITY_CLASS);
case GetPriorityClass(H) Of
IDLE_PRIORITY_CLASS: Result:=-1;
NORMAL_PRIORITY_CLASS: Result:=0;
HIGH_PRIORITY_CLASS: Result:=1;
REALTIME_PRIORITY_CLASS: Result:=2;
end;
end;
// Âîçâðàùàåò ïðèîðèòåò ñâîåãî ïðîöåññà
function GetProcessPriority: integer;
var
H: THandle;
begin
Result:=0;
H:=GetCurrentProcess();
case GetPriorityClass(H) Of
IDLE_PRIORITY_CLASS: Result:=-1;
NORMAL_PRIORITY_CLASS: Result:=0;
HIGH_PRIORITY_CLASS: Result:=1;
REALTIME_PRIORITY_CLASS: Result:=2;
end;
end;
// Âîçâðàùàåò íîìåð ñèìâîëà, ãäå íà÷èíàåòñÿ íàáèðàòüñÿ ïóòü
function GetTypePath(Str: string; SelStart: integer): integer;
var
Posit: integer;
begin
Str:=Copy(Str, 0, SelStart);
Posit:=0;
while pos(':\', Str)<>0 do begin
Posit:=Pos(':\', Str);
Str[Posit]:='¦';
Str[Posit+1]:='¦';
end;
Result:=Posit;
end;
// Âîçâðàùàåò çíà÷åíèå ñèñòåìíîé ïåðåìåííîé
// VarName - èìÿ ïåðåìåííîé, íàïðèìåð PATH
function GetDOSEnvVar(const VarName: string): string;
var
i: integer;
begin
Result:='';
try
i:=GetEnvironmentVariable(PChar(VarName), nil, 0);
if i>0 then begin
SetLength(Result, i-1);
GetEnvironmentVariable(Pchar(VarName), PChar(Result), i);
end
else begin
Result:='';
end;
except
Result:='';
end;
end;
// Âîçâðàùàåò ïîëíûé ïóòü ê ôàéëó, åñëè îí åñòü â îäíîì ìåñòå èç ïåðåìåííîé PATH
// Str - èìÿ ôàéëà
function GetPathFolder(Str: string): string;
var
strPATH, tmpPath: string;
tmpPos: integer;
i: integer;
const
extArr: array[1..10] of string=('.com', '.exe', '.bat', '.cmd', '.vbs', '.vbe', '.js', '.jse', '.wsf', '.wsh');
begin
strPATH:=GetDOSEnvVar('PATH');
while Pos(';', strPATH)<>0 do begin
tmpPos:=Pos(';', strPATH);
tmpPath:=Copy(strPATH, 0, tmpPos-1);
// Åñëè òàêîé ôàéë åñòü â ïóòÿõ çàïóñêà
if FileExists(tmpPath + '\' + Str) then begin
Result:=tmpPath + '\' + Str;
Exit;
end;
// Åñëè íåò - ïðîáóåì ïîäñòàâëÿòü ðàçíûå ñòàíäàðòíûå ðàñøèðåíèÿ
for i:=1 to High(ExtArr) do begin
if FileExists(tmpPath + '\' + Str + extArr[i]) then begin
Result:=tmpPath + '\' + Str;
Exit;
end;
end;
Delete(strPATH, 1, tmpPos);
end;
Result:='';
end;
// Âîçâðàùàåò íóæíîå ïî ñ÷åòó ñëîâî â äàííîé ñòðîêå è ñ äàííûì ðàçäåëèòåëåì
// Str - èçíà÷àëüíàÿ ñòðîêà
// Separator - ðàçäåëèòåëü ñëîâ
// Num - íóæíîå ïî ñ÷åòó ñëîâî ñëåâà
function GetNumWord(Str, Separator: string; Num: integer): string;
var
i: integer;
tmpStr: string;
begin
i:=0;
tmpStr:=Str;
while Pos(Separator, tmpStr)<>0 do begin
Inc(i);
Insert('¦', tmpStr, Pos(Separator, tmpStr));
Delete(tmpStr, Pos(Separator, tmpStr), 1);
end;
if Num>i+1 then begin
Result:='';
end
else begin
i:=0;
Str:=Str+Separator;
while i+1<=Num do begin
tmpStr:=Copy(Str, 1, Pos(Separator, Str)-1);
Delete(Str, 1, Pos(Separator, Str)+Length(Separator)-1);
Inc(i);
end;
Result:=tmpStr;
end;
end;
// Óñòàíàâëèâàåò íóæíóþ ðàñêëàäêó
// Str - Êîä íóæíîé ðàñêëàäêè
procedure SetKeyboardLayout(Str: string);
var
Layout: array [0..KL_NAMELENGTH] of char;
begin
LoadKeyboardLayout(StrCopy(Layout, PChar(Str)), KLF_ACTIVATE);
end;
// Âîçâðàùàåò ñîñòîÿíèå äèñêà
// DrvLetter - áóêâà äèñêà+':'
function DriveState(DrvLetter: string): integer;
var
SearchRec: TSearchRec;
oldMode: Cardinal;
ReturnCode: Integer;
begin
oldMode:=SetErrorMode(SEM_FAILCRITICALERRORS);
{$I-}
ReturnCode:=FindFirst(DrvLetter+'\*.*', faAnyfile, SearchRec);
FindClose(SearchRec);
{$I+}
Result:=ReturnCode;
SetErrorMode(oldMode);
end;
// Çàïóñêàåò ÷åðåç ShellExecute è ñìîòðèò, ïîëó÷èëîñü ëè
function RunShell(action: string; param: string = ''; path: string = ''; state: integer = SW_ShowNormal; method: string = 'open'; handle: HWND = 0): HWND;
begin
if handle=0 then
handle:=Application.Handle;
if (method='') and not Options.Exec.DefaultAction then
method:='open';
Result:=ShellExecute(handle, PAnsiChar(method), PAnsiChar(action), PAnsiChar(param), PAnsiChar(path), state);
end;
// Ïðîèãðûâàåò óêàçàííûé ôàéë
procedure PlayFile(FileName: string);
var
tmpFile: PChar;
begin
if Options.Sounds.EnableSounds then begin
tmpFile:='';
if FileExists(FileName) then
tmpFile:=PChar(FileName)
else if FileExists(GetMyPath + FileName) then
tmpFile:=PChar(GetMyPath + FileName);
if tmpFile<>'' then
PlaySound(tmpFile, 0, SND_ASYNC or SND_FILENAME);
end;
end;
end.