This repository has been archived by the owner on Jan 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
mdlAMainIntepretator.bas
1256 lines (1201 loc) · 56 KB
/
mdlAMainIntepretator.bas
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
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Attribute VB_Name = "mdlAScriptIntepretator"
Option Explicit
Option Compare Text
Option Base 1
Public Const Delimiter = ","
Public Const ConstPrefix = "$"
Public Const WindowNotFound = 1&
Public LoopCounter As Long, sConsts As typeScriptConsts
Dim LinesCount As Long, c As Long, n As Long, LineToExecute As Long, _
NowLang As String, LoopRemain As Long ' LineToExecut - îáùèé ñ÷åò÷èê ëèíèé
Dim bIsScript As Boolean ' ïåðåêëþ÷àåòñÿ òîãäà, êîãäà âûïîëíÿåòñÿ VBScript\JScript
Public Type typeScriptConsts
Time As String
Date As String
Key As String
Window As String
End Type
Public Enum typeOperations
toEqv
toNotEqv
toLess ' ìåíüøå
toMore 'áîëüøå
toLessEqv
toMoreEqv
End Enum
'--------------------------------------------------- Functions Consts
Public Enum Functions
cClick = 1001
cWait = 1002
cPress = 1003
cExit = 1004
cStartScript = 1005
cSetCursorPos = 1006
cLoop = 1007
cMsgBox = 1008
cInputBox = 1009
cPrint = 1010 'Debug Print
cCreateFile = 1011
cWriteFile = 1012
cReadFile = 1013
cSetWindow = 1014
cShowWindow = 1015
cShell = 1016
cStop = 1017
cSkipErrors = 1018
cChangeResolution = 1019
cDeleteFile = 1020
cKillProcess = 1021
cDeleteDir = 1022
cCreateDir = 1023
cCloseWindow = 1024
cDownloadFile = 1025
cIf = 1026
cVBScript = 1027
cGoTo = 1028
End Enum
'--------------------------------------------------- Parameters
Public Const pFullPress = 1
Public Const pInfinitely = -1
Public Const pSeconds = "sec", pMinutes = "min", pHours = "hor"
Function ExecuteScript(ByVal Script As Variant, Optional ScriptWindow As Object, Optional Arrow As Object, Optional Status As Object) As Boolean
Dim RealLine() As String, RealLinesCount As Long, VisibleMode As Boolean, CleanScript As String, OrigStatusText As String
If Script = "" Then Exit Function
blnExecuting = True
LogEvent "Çàïóùåíî: " & LoadedFile.BaseTitle
If Settings.bSkipErrors Then On Error GoTo lSkip Else On Error GoTo ErrHandler
AddStage "Èíòåðåòàöèÿ ñêðèïòà - ãëàâíûé ìîäóëü"
Randomize
CleanAll
VisibleMode = (Not ScriptWindow Is Nothing) And (Not Arrow Is Nothing) And (Not Status Is Nothing)
If VisibleMode Then
frmMain.UpdateControlsState
OrigStatusText = Status.Text
End If
GetLines Script, RealLine, RealLinesCount
If Script = "" Then GoTo EndSub
For LineToExecute = 1 To RealLinesCount
AddStage "Èíòåðåòàöèÿ ñêðèïòà - ãëàâíûé ìîäóëü"
GlobalError.line = LineToExecute ' îáíîâëÿþ ëèíèþ â îøèáêå
CleanScript = RealLine(LineToExecute)
ConvertScript CleanScript
If Not IsValidScript(CleanScript) Then ' åñëè êîìàíäà íå îïðåäåëåíà
If CleanScript <> "" Then
If Not Settings.bSkipErrors Then Script = CleanScript
Err.Raise ErrNum, , "Êîìàíäà íå îïðåäåëåíà"
End If
GoTo lNext
End If
If VisibleMode Then
Status.Text = "Âûïîëíÿåòñÿ ñòðîêà ¹" & LineToExecute
If LoopRemain <> 0 Then
If LoopRemain = pInfinitely Then
Status.Text = Status.Text & vbCrLf & "Öèêëó îñòàëîñü âûïîëíÿòñÿ áåñêîíå÷íî ðàç"
Else
Status.Text = Status.Text & vbCrLf & "Öèêëó îñòàëîñü âûïîëíÿòñÿ " & LoopRemain & " ðàç(à)"
End If
End If
ScriptWindow.SelStart = GetSelStartFromLine(Script, LineToExecute)
If LineToExecute = 1 Then
Arrow.Top = 0
ElseIf (LineToExecute - 1) < GetMaxLines Then
Arrow.Top = GetTextHeight(ScriptWindow, String$(LineToExecute - 1, vbLf)) - 1.8
Else
Arrow.Top = GetTextHeight(ScriptWindow, String$(GetMaxLines - 1, vbLf))
End If
Arrow.Visible = True
End If
ExecuteCleanScript CleanScript
lNext:
DoEvents
If Not blnExecuting Then Exit For
Next LineToExecute
EndSub:
blnExecuting = False
If ErrorTitle = "" Then
LogEvent "Âûïîëíåíî: " & LoadedFile.BaseTitle
ExecuteScript = True
Else
LogEvent "Âûïîëíåíî ñ îøèáêàìè: " & LoadedFile.BaseTitle & "; Îøèáêà: " & ErrorTitle
ExecuteScript = False
ErrorTitle = ""
End If
If VisibleMode Then
Arrow.Visible = False
frmMain.UpdateAll
frmMain.SetNormalState
End If
LoopRemain = 0
LoopCounter = 0
Exit Function
lSkip:
ADL "íåâåðíàÿ êîíñòðóêöèÿ ñêðèïòà"
Resume Next
Exit Function
ErrHandler:
GlobalError.Description = "Îøèáêà íà ñòàäèè ïàðñèíãà ñêðèïòà"
GlobalError.Expression = Script
Call GlobalErrorHandler
End Function
Function IsValidScript(ByVal Script As Variant, Optional ByVal bConvert As Boolean) As Boolean
If bConvert Then ConvertScript Script
If GetActionType(Script, True) > 0 Then IsValidScript = True
End Function
Function GetActionType(ByVal line As String, Optional ByVal bBadScript As Boolean) As ActionType
If bBadScript Then ConvertScript line
If Len(line) < 1 Then Exit Function
For Each arr In Funcs
If InStr(1, line, arr) = 1 Then GetActionType = atFunc: Exit Function
Next
If Len(line) < 3 Then Exit Function
For Each arr In Operations
n = InStr(1, line, arr)
If n > 1 Then
If InStr(1, line, arr) > 0 Then GetActionType = atOperation: Exit Function
End If
Next
End Function
Sub ExecuteCleanScript(ByVal Script As Variant)
Dim ScriptLine() As String, i As Long, ActionType As ActionType
If Settings.bSkipErrors Then On Error GoTo lSkip Else On Error GoTo ErrHandler
AddStage "Èíòåðåòàöèÿ ñêðèïòà - èñïîëíèòåëüíûé ìîäóëü"
GetLines Script, ScriptLine(), LinesCount
For i = 1 To LinesCount
AddStage "Èíòåðåòàöèÿ ñêðèïòà - èñïîëíèòåëüíûé ìîäóëü"
ActionType = GetActionType(ScriptLine(i))
If ActionType = atFunc Then 'Function
ExecuteFunc ScriptLine(i)
ElseIf ActionType = atOperation Then 'Operation
SetVarBySides ScriptLine(i)
End If
Pause
If Not blnExecuting Then Exit For
Next i
Exit Sub
lSkip:
ADL "íåâåðíàÿ êîíñòðóêöèÿ ñêðèïòà"
Resume Next
Exit Sub
ErrHandler:
GlobalError.Description = "Îøèáêà ïðè ïîïûòêå ïðîèçâåñòè ïàðñèíã ñòðîêè"
GlobalError.Expression = Script
Call GlobalErrorHandler
End Sub
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Sub ExecuteFunc(ByVal line As String)
Dim Func As Functions, FuncLen As Long, ParamLine As String, Params() As Variant, FuncStatus As Boolean, buff As String, _
VarIndex As Long 'íîìåð ïåðåìåííîå íóæåí, ÷òîáû çàäàâàòü èì çíà÷åíèÿ â ô-öèÿõ òèïà ReadFile
If Settings.bSkipErrors Then On Error GoTo lSkip Else On Error GoTo ErrHandler
AddStage "Èíòåðåòàöèÿ êîìàíäû"
Func = GetFunc(line)
If SelectedWindow.hwnd > 0 Then
'ïðîâåêðà, â òîì ëè îêíå ïðîèñõîäÿò äåéñòâèÿ
If IsWindowVisible(SelectedWindow.hwnd) = 0 Then
If SelectedWindow.hwnd = WindowNotFound Then ' ÅÑËÈ çàäàíà êîíòñòàíòà WNF, òî îøèáêà ïðîïóñêàåòñÿ è ïðîãðàììà ïî ñóòè äîæèäàåòñÿ îêíà
If Func = cClick Or Func = cPress Then Exit Sub
Else
Err.Raise ErrNum, , "Íåâîçìîæíî íàéòè çàäàííîå îêíî"
Exit Sub
End If
End If
If GetForegroundWindow <> SelectedWindow.hwnd Then
If GetForegroundWindow <> frmMain.hwnd Then ShowWindow SelectedWindow.hwnd
End If
End If
FuncLen = Len(Func)
ParamLine = GetParamLine(line, FuncLen)
ParseParameters ParamLine, Params()
If Not blnExecuting Then Exit Sub
Select Case Func
Case cExit: End
Case cClick
' click êîîðäèíàòà x=*, êîîðäèíàòà y=*, ñîáûòèå=êëèê, êíîïêà ìûøè=ëåâàÿ, ñêîëüêî ðàç=1, âåðíóòü êóðñîð=äà, çàäåðæêà ïåðåä äåéñòâèåì=0, çàäåðæêà ïîñëå äåéñòâèÿ=0
' click555,777,click,left,5,yes,100,100
CheckParameters Params(), 0, 0, pClick, pLeft, 1, pYes, 0, 0, 0, 0
AddStage "Âûïîëíåíèå êîìàíäû Click"
FuncStatus = sfClick(Params(1), Params(2), Params(3), Params(4), Params(5), Params(6), Params(7), Params(8), Params(9), Params(10))
Case cWait
' wait âðåìÿ îæèäàíèÿ=1000, ðàíäîìèçèðîâàòü íà=0
' wait100,50
CheckParameters Params(), 1000, 0
AddStage "Âûïîëíåíèå êîìàíäû Wait"
FuncStatus = sfWait(Params(1), Params(2))
Case cPress
' press "êëàâèøà", ñêîëüêî ðàç=1, çàäåðæêà ïåðåä äåéñòâèåì=0, çàäåðæêà ïîñëå äåéñòâèÿ=0
' press"A",5,100,100
CheckParameters Params(), "", 1, 0, 0
AddStage "Âûïîëíåíèå êîìàíäû Press"
If Params(1) = "" Then Err.Raise ErrNum, , "Ïîòåðÿí îáÿçàòåëüíûé ïàðàìåòð êîìàíäû Press"
FuncStatus = sfPress(Params(1), Params(2), Params(3), Params(4))
Case cStartScript
'StartScript èìÿ ñêðèïòà, ñêîëüêî ðàç=1, æäàòü çàâåðøåíèÿ=äà
'StartScript"C:\Script.es",1,yes
CheckParameters Params(), "", 1, pYes
AddStage "Âûïîëíåíèå êîìàíäû StartMacros"
If Params(1) = "" Then Err.Raise ErrNum, , "Ïîòåðÿí îáÿçàòåëüíûé ïàðàìåòð êîìàíäû StartMacros"
FuncStatus = sfStartScript(Params(1), Params(2), Params(3))
Case cSetCursorPos
' SetCursoePos êîîðäèíàòà x=*, êîîðäèíàòà y=*, çàäåðæêà äî âûïîëíåíèÿ äåéñòâèÿ=0, çàäåðæêà ïîñëå âûïîëíåíèÿ äåéñòâèÿ=0
' setcursorpos 100,200,0,0
AddStage "Âûïîëíåíèå êîìàíäû SetCursorPos"
CheckParameters Params(), 0, 0, 0, 0
If Params(1) = 0 And Params(2) = 0 Then Err.Raise ErrNum, , "Ïîòåðÿí îáÿçàòåëüíûé ïàðàìåòð êîìàíäû SetCursorPos"
FuncStatus = sfSetCursorPos(Params(1), Params(2), Params(3), Params(4))
Case cLoop
' Loop ñêîëüêî ðàç=áåñêîíå÷íî, íà÷èíàÿ ñ êàêîé ëèíèè=1, çàäåðæêà ïåðåä ïðûæêîì=0
' loop5,1,0
CheckParameters Params(), pInfinitely, 1, 0
AddStage "Âûïîëíåíèå êîìàíäû Loop"
FuncStatus = sfLoop(Params(1), Params(2), Params(3), LineToExecute, LoopRemain)
Case cMsgBox
'MsgBox òåêñò, çàãîëîâîê=EasyScript, ñòèëü ñîîáùåíèå=èíôîðìàöèÿ, ïîâåðõ âñåõ îêîí=äà
'MsgBox"ñîîáùåíèå", "çàãîëîâîê", 48, äà
CheckParameters Params(), "", "EasyScript", vbInformation, pYes
AddStage "Âûïîëíåíèå êîìàíäû MsgBox"
FuncStatus = sfMsgBox(Params(1), Params(2), Params(3), Params(4))
Case cInputBox
'InpuBox òåêñò, çàãîëîâîê=EasyScript, ïîëó÷èòü èíôîðìàöèþ â
'InpuBox"ñîîáùåíèå", "çàãîëîâîê", õ
CheckParameters Params(), "", "EasyScript", "#VAR#"
AddStage "Âûïîëíåíèå êîìàíäû InpuBox"
FuncStatus = sfInputBox(Params(1), Params(2), buff)
SetVarValue Params(3), buff
Case cPrint
AddStage "Âûïîëíåíèå êîìàíäû Print"
CheckParameters Params(), ""
If Params(0) = "" Then Err.Raise ErrNum, , "Ïîòåðÿí îáÿçàòåëüíûé ïàðàìåòð êîìàíäû Print"
ADL ParamLine, False
If frmDebug.Visible = False Then frmDebug.Show , frmMain
FuncStatus = True
Case cCreateFile
'CreateFile Èìÿ ôàéëà, êîíòåíò=""
'CreateFile"C:\1.txt", "content"
CheckParameters Params(), "", ""
AddStage "Âûïîëíåíèå êîìàíäû CreateFile"
If Params(1) = "" Then Err.Raise ErrNum, , "Ïîòåðÿí îáÿçàòåëüíûé ïàðàìåòð êîìàíäû CreateFile"
FuncStatus = sfCreateFile(Params(1), Params(2))
Case cWriteFile
'WriteFile Èìÿ ôàéëà, êîíòåíò=""
'WriteFile"C:\1.txt", "content"
CheckParameters Params(), "", ""
AddStage "Âûïîëíåíèå êîìàíäû WriteFile"
If Params(1) = "" Then Err.Raise ErrNum, , "Ïîòåðÿí îáÿçàòåëüíûé ïàðàìåòð êîìàíäû WriteFile"
FuncStatus = sfWriteFile(Params(1), Params(2))
Case cReadFile
'ReadFile èìÿ ôàéëà, ïåðåìåííàÿ, íà÷èíàÿ ñ êàêîé ñòðîêè, ñêîëüêî ñòðîê
'ReadFile"C:\1.txt", x, 5, 5
CheckParameters Params(), "", "#VAR#", 0, 0
AddStage "Âûïîëíåíèå êîìàíäû ReadFile"
If Params(1) = "" Then Err.Raise ErrNum, , "Ïîòåðÿí îáÿçàòåëüíûé ïàðàìåòð êîìàíäû ReadFile"
FuncStatus = sfReadFile(Params(1), buff, Params(3), Params(4))
SetVarValue Params(2), buff
Case cSetWindow
' SetWindow çàãîëîâîê="", åñëè îêíî íå îáíàðóæåíî ïîêàçàòü îøèáêó=äà
' SetWindow"any",yes
CheckParameters Params(), "", pYes
AddStage "Âûïîëíåíèå êîìàíäû SetWindow"
FuncStatus = sfSetWindow(Params(1), Params(2))
Case cShowWindow
' SetWindow çàãîëîâîê="", åñëè îêíî íå îáíàðóæåíî ïîêàçàòü îøèáêó=äà
' SetWindow"any",yes
CheckParameters Params(), "", pYes
AddStage "Âûïîëíåíèå êîìàíäû ShowWindow"
FuncStatus = sfShowWindow(Params(1), Params(2))
Case cShell
' Shell ïîëíîå èìÿ ïðîãðàììû="", äîæèäàòüñÿ ïîÿâëåíèÿ îêíà=íåò, äîæèäàòüñÿ çàâåðøåíèÿ ïðîöåññà,ñòèëü îêíà ïðè çàïóñêå=íîðìàëüíî
' Shell"C:\1.exe",no,no,normal
CheckParameters Params(), "", pNo, pNo, vbNormalFocus
AddStage "Âûïîëíåíèå êîìàíäû Shell"
If Params(1) = "" Then Err.Raise ErrNum, , "Ïîòåðÿí îáÿçàòåëüíûé ïàðàìåòð êîìàíäû Shell"
FuncStatus = sfShell(Params(1), Params(2), Params(3), Params(4))
Case cStop
' Stop
blnExecuting = False
FuncStatus = True
Case cSkipErrors
' SkipErrors yes
CheckParameters Params(), pYes
Settings.bSkipErrors = CBool(Params(1))
FuncStatus = True
Case cChangeResolution
' ChangeResolution øèðèíà, âûñîòà
' ChangeResolution 800,600
CheckParameters Params(), 0, 0
AddStage "Âûïîëíåíèå êîìàíäû ChangeResolution"
If Params(1) = 0 Or Params(2) = 0 Then Err.Raise ErrNum, , "Ïîòåðÿí îáÿçàòåëüíûé ïàðàìåòð êîìàíäû ChangeResolution"
FuncStatus = sfChangeResolution(Params(1), Params(2))
Case cDeleteFile
'DeleteFile Èìÿ ôàéëà
'DeleteFile"C:\1.txt"
CheckParameters Params(), ""
AddStage "Âûïîëíåíèå êîìàíäû DeleteFile"
If Params(1) = "" Then Err.Raise ErrNum, , "Ïîòåðÿí îáÿçàòåëüíûé ïàðàìåòð êîìàíäû DeleteFile"
FuncStatus = sfDeleteFile(Params(1))
Case cKillProcess
'KillProcess Èìÿ ïðîöåññà
'KillProcess"explorer.exe"
CheckParameters Params(), "", pNo
AddStage "Âûïîëíåíèå êîìàíäû KillProcess"
If Params(1) = "" Then Err.Raise ErrNum, , "Ïîòåðÿí îáÿçàòåëüíûé ïàðàìåòð êîìàíäû KillProcess"
FuncStatus = sfKillProcess(Params(1), Params(2))
Case cDeleteDir
'DeleteDir Èìÿ äèðåêòîðèè
'DeleteFir"C:\dir\"
CheckParameters Params(), ""
AddStage "Âûïîëíåíèå êîìàíäû DeleteDir"
If Params(1) = "" Then Err.Raise ErrNum, , "Ïîòåðÿí îáÿçàòåëüíûé ïàðàìåòð êîìàíäû DeleteDir"
FuncStatus = sfDeleteDir(Params(1))
Case cCreateDir
'CreateDir Èìÿ ïàïêè
'CreateDir"C:\dir\"
CheckParameters Params(), ""
AddStage "Âûïîëíåíèå êîìàíäû CreateDir"
If Params(1) = "" Then Err.Raise ErrNum, , "Ïîòåðÿí îáÿçàòåëüíûé ïàðàìåòð êîìàíäû CreateDir"
MkDir (Params(1)): FuncStatus = True
Case cCloseWindow
'CloseWindow çàãîëîâîê, óñèëåííî
'CloseWindow"áëîêíîò",1
CheckParameters Params(), "", pYes, pYes
AddStage "Âûïîëíåíèå êîìàíäû CloseWindow"
If Params(1) = "" Then Err.Raise ErrNum, , "Ïîòåðÿí îáÿçàòåëüíûé ïàðàìåòð êîìàíäû CloseWindow"
FuncStatus = sfCloseWindow(Params(1), Params(2), Params(3))
Case cDownloadFile
'DownloadFile àäðåñ*, ïóòü ê ôàéëó èëè èìÿ ïåðåìåííîé, ìåòîä , çàãîëîâêè ÷åðåç |, POST-äàííûå, Cookies, ïååðåìåííàÿ äëÿ ïîëó÷àåíèÿ îòâåòíûõ Cookie
'DownloadFile"asd.ru"
CheckParameters Params(), "", "", "GET", "", "", "", "", pYes
AddStage "Âûïîëíåíèå êîìàíäû DownloadFile"
If Params(1) = "" Then Err.Raise ErrNum, , "Ïîòåðÿí îáÿçàòåëüíûé ïàðàìåòð êîìàíäû DownloadFile"
Downloader = sfDownloadFile(Params(1), Params(2), Params(3), Params(4), Params(5), Params(6), Params(7), Params(8))
If Downloader.Headers <> "" Then
If Params(7) <> "" Then ' ÅÑËÈ ïåðåìåííàÿ äëÿ ïîëó÷åíèÿ êóêè ââåäåíà
SetVarValue Params(7), Downloader.Cookie, True
End If
If InStr(1, Params(2), "\") > 0 Or InStr(1, Params(2), ".") > 0 Then
' Ââåäåíî èìÿ ôàéëà
buff = Params(2)
CheckFileName buff
FuncStatus = CreateFile(buff, Downloader.Body)
ElseIf Params(2) <> "" Then
' Ââåäåíà ïåðåìåííàÿ
FuncStatus = SetVarValue(Params(2), Downloader.Body)
Else
' Íè÷åãî íå ââåäåíî, çíà÷èò èìÿ ôàéëà ïîëó÷àþ èç URL
buff = GetFileBaseName(Params(1), "/")
If buff = "" Then buff = "page.html"
CheckFileName buff
FuncStatus = CreateFile(buff, Downloader.Body)
End If
Else
FuncStatus = False
End If
Case cIf ' Óñëîâèå
'If a=1, then Click, else End
CheckParameters Params(), "#COND#", "", ""
AddStage "Âûïîëíåíèå êîíñòðóêöèè If"
If Params(1) = "" Or Params(1) = "#COND#" Or Params(2) = "" Then Err.Raise ErrNum, , "Ïîòåðÿí îáÿçàòåëüíûé ïàðàìåòð êîíñòðóêöèè If"
FuncStatus = sfIf(Params(1), Params(2), Params(3))
Case cVBScript
bIsScript = True
CheckParameters Params(), "", "#VAR#", pNo
AddStage "Âûïîëíåíèå êîäà VBScript"
If Params(1) = "" Then Err.Raise ErrNum, , "Ïîòåðÿí îáÿçàòåëüíûé ïàðàìåòð êîìàíäû VBScript"
FuncStatus = sfVBScript(Params(1), buff, Params(3))
SetVarValue Params(2), buff
Case cGoTo
' GoTo íîìåð ñòðîêè
' goto5
CheckParameters Params(), 0
AddStage "Âûïîëíåíèå êîìàíäû GoTo"
If Params(1) = 0 Then Err.Raise ErrNum, , "Ïîòåðÿí îáÿçàòåëüíûé ïàðàìåòð êîìàíäû GoTo"
FuncStatus = sfGoTo(Params(1), LineToExecute)
End Select
If Err.Number <> 0 Or FuncStatus = False Then
If Settings.bSkipErrors Then GoTo lSkip Else GoTo ErrHandler
End If
Exit Sub
lSkip:
ADL "êîìàíäà íå ìîæåò áûòü âûïîëíåíà"
Exit Sub
ErrHandler:
GlobalError.Description = "Îøèáêà âî âðåìÿ âûïîëíåíèÿ êîìàíäû"
GlobalError.Expression = line
Call GlobalErrorHandler
End Sub
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Function SetVarValue(ByVal sVar As String, ByVal sValue As String, Optional bIsText As Boolean) As Long 'Âîçâðàùàåò èíäåêñ íàçíà÷åííîé ïåðåìåííîé
Dim VarIndex As Long
If sVar = "" Then Exit Function
Select Case Right$(sValue, 1)
Case "+": sValue = sVar & "+1"
Case "-": sValue = sVar & "-1"
End Select
ReplaceVars sValue ' ïåðåìåííûå çàìåíÿþòñÿ â ñêðèïòå, è ãîòîâûé âàðèàíò ïîñûëàåòñÿ â èíòåðïðåòàòîð âûðàæåíèé
VarIndex = GetVarIndex(sVar)
If VarIndex = 0 Then
VarsCount = VarsCount + 1
VarIndex = VarsCount
VarName(VarIndex) = sVar
End If
VarVal(VarIndex) = sValue
If (Not bIsText) And (Not IsTextOnQuotes(sValue)) And IsExpression(VarVal(VarIndex)) Then
VarVal(VarIndex) = Calculate(sValue)
ElseIf Not IsTextOnQuotes(sValue) Then 'ÅÑËÈ ýòî òåêñò, íî îí íå â êàâû÷êàõ, óáèðàþ åãî â êàâû÷êè
sValue = Chr$(34) & sValue & Chr$(34)
End If
SetVarValue = VarIndex
End Function
Function GetVarIndex(ByVal Name As String) As Long
If VarsCount > 0 Then
For i = 1 To VarsCount
If VarName(i) = "" Then Exit Function
If VarName(i) = Name Then GetVarIndex = i: Exit Function
Next i
End If
End Function
Function SetVarBySides(ByVal line As String) As Long 'Âîçâðàùàåò èíäåêñ íàçíà÷åííîé ïåðåìåííîé
Dim LeftSide As String, RightSide As String
If Settings.bSkipErrors Then On Error GoTo lSkip Else On Error GoTo ErrHandler
AddStage "Íàçíà÷åíèå ïåðåìåííîé"
If InStr(1, line, Chr$(34)) = 0 Then line = LCase(line)
If InStr(1, line, "=") Then
GetSides line, LeftSide, RightSide, "="
LeftSide = LCase(LeftSide)
Else
LeftSide = LCase(GetVar(line))
RightSide = line
End If
If LeftSide = "" Then Err.Raise ErrNum, , "Ïåðåìåííàÿ íå ââåäåíà"
SetVarBySides = SetVarValue(LeftSide, RightSide)
Exit Function
lSkip:
ADL "íå ïîëó÷àåòñÿ çàäàòü ïåðåìåííóþ"
'Resume Next
Exit Function
ErrHandler:
GlobalError.Description = "Îøèáêà ïðè ïîïûòêå çàäàòü çíà÷åíèå ïåðåìåííîé"
GlobalError.Expression = line
Call GlobalErrorHandler
End Function
Function GetVar(line As String) As String
Dim NextSymbol As String
If Len(line) <= 3 Then GetVar = Left$(line, 1): Exit Function
For c = 1 To Len(line)
c = c + 1
GetVar = Left$(line, c)
NextSymbol = Mid$(line, c + 1, 1)
If NextSymbol = "" Then Exit For
If Asc(NextSymbol) < 65 Or _
(Asc(NextSymbol) > 90 And Asc(NextSymbol) < 97) Or _
(Asc(NextSymbol) > 122 And Asc(NextSymbol) < 127) Then Exit For
Next c
End Function
Sub ReplaceVars(ByRef line As Variant, Optional ByVal bLeaveQuotes As Boolean)
For c = 1 To VarsCount
'If VarVal(c) = "" Then VarVal(c) = "0"
'ReplaceOutQuotes line, VarName(c), VarVal(c), rtVar
RealReplaceVar line, VarName(c), VarVal(c), bLeaveQuotes
Next c
End Sub
Sub Pause(Optional Ms As Long = 10)
If Settings.bFakeWait Then Wait Ms
CheckHotKeys hkExecuteScript
End Sub
Function GetParamLine(line As String, FuncLen As Long) As String
If Len(line) = FuncLen Then Exit Function
GetParamLine = Mid$(line, FuncLen + 1, Len(line) - FuncLen)
If Left$(GetParamLine, 1) = "(" And Right$(GetParamLine, 1) = ")" Then GetParamLine = Mid$(GetParamLine, 2, Len(GetParamLine) - 2)
End Function
Function RandomSign() As Long
If Rnd > 0.5 Then RandomSign = 1& Else RandomSign = -1&
End Function
Sub ConvertNumber(str As Variant, Optional Default As Variant, Optional JustPositive As Boolean)
Dim Unit As String, num As Long, cuted As String
If Settings.bSkipErrors Then On Error GoTo lSkip Else On Error GoTo ErrHandler
AddStage "Êîíâåðòàöèÿ ÷èñëà"
If IsNumeric(str) Then Exit Sub
'ñåê, ìèí, ÷àñ
If InStr(1, str, pHours) = 0 And InStr(1, str, pMinutes) = 0 And InStr(1, str, pSeconds) = 0 Then Exit Sub
str = Replace(str, pHours, "*3600000+")
str = Replace(str, pMinutes, "*60000+")
str = Replace(str, pSeconds, "*1000+")
If Right$(str, 1) = "+" Then str = Left(str, Len(str) - 1)
' Unit = Right(str, 3)
' If Unit = pSeconds Or Unit = pMinutes Or Unit = pHours Then
' cuted = Left(str, Len(str) - 3)
' If cuted = "" Then cuted = "1"
' Else
' cuted = str
' End If
' cuted = Calculate(cuted)
' If (Not IsNumeric(cuted) And Len(str) < 3) Then
' GoTo SetDefault
' ElseIf IsNumeric(cuted) Then
' If JustPositive And CLng(cuted) < 0 Then GoTo SetDefault
' End If
' If IsNumeric(cuted) Then num = CLng(cuted) Else num = 1
' Select Case Unit
' Case pSeconds
' num = num * 1000
' Case pMinutes
' num = num * 1000 * 60
' Case pHours
' num = num * 1000 * 60 * 60
' Case Else 'åñëè íåïîíÿòíî ÷òî, òî çàäàåòñÿ çíà÷åíèå ïî óìîë÷àíèþ
'SetDefault:
' Err.Raise ErrNum, , "íåâåðíîå çíà÷åíèå ñâîéñòâà"
' num = CLng(Default)
' End Select
' str = CStr(num)
Exit Sub
lSkip:
ADL "ïàðàìåòð íå ÿâëÿåòñÿ ÷èñëîì"
Resume Next
Exit Sub
ErrHandler:
GlobalError.Description = "Ïàðàìåòð, êîòîðûé äîëæåí ÿâëÿòñÿ ÷èñëîì, òàêîâûì íå ÿâëÿåòñÿ"
GlobalError.Expression = str
Call GlobalErrorHandler
End Sub
Function DeleteLineComment(ByVal sInput As String, Optional ByVal sCommentSign = "'") As String
Dim CommentStart As Long, CommentEnd As Long, QuotesStart As Long, QuotesEnd As Long, _
LineStart As Long, LineEnd As Long, line As String, CommentPosInLine As Long, PrevCommentPosInLine As Long, _
PrevLineStart As Long
If InStr(1, sCommentSign, sCommentSign) = 0 Then DeleteLineComment = sInput: Exit Function
'----------------- ñòðîêîâûé êîììåíò
Do While InStr(CommentEnd + 1, sInput, sCommentSign)
CommentStart = InStr(CommentEnd + 1, sInput, sCommentSign)
LineStart = InStrRev(sInput, vbCrLf, CommentStart)
If PrevLineStart <> LineStart Then PrevCommentPosInLine = 0
PrevLineStart = LineStart
CommentEnd = InStr(CommentStart, sInput, vbCrLf)
If CommentEnd <= 0 Then CommentEnd = Len(sInput) + 1
LineEnd = CommentEnd
line = Mid$(sInput, LineStart + 1, LineEnd - LineStart)
CommentPosInLine = InStr(PrevCommentPosInLine + 1, line, sCommentSign)
PrevCommentPosInLine = CommentPosInLine
QuotesStart = InStrRev(line, Chr$(34), CommentPosInLine)
QuotesEnd = InStr(CommentPosInLine, line, Chr$(34))
If QuotesStart > 0 And CommentPosInLine > QuotesStart And CommentPosInLine < QuotesEnd Then CommentEnd = CommentStart: GoTo lLoop
sInput = Replace(sInput, Mid$(sInput, CommentStart, CommentEnd - CommentStart), "")
CommentEnd = CommentStart
lLoop:
Loop
DeleteLineComment = sInput
End Function
Sub DeleteComments(Script As Variant)
If Settings.bSkipErrors Then On Error GoTo lSkip Else On Error GoTo ErrHandler
Dim CommentStart As Long, CommentEnd As Long, QuotesStart As Long, QuotesEnd As Long, _
LineStart As Long, LineEnd As Long, line As String, CommentPosInLine As Long, PrevCommentPosInLine As Long, _
PrevLineStart As Long
'----------------- ñòðîêîâûé êîììåíò
Script = DeleteLineComment(Script, "'")
Script = DeleteLineComment(Script, "//")
Script = DeleteLineComment(Script, ";")
'----------------- ïîòîêîâûé êîììåíò /* ... */
If InStr(1, Script, "/*") = 0 Then Exit Sub
Do While InStr(CommentEnd + 1, Script, "/*")
CommentStart = InStr(CommentEnd + 1, Script, "/*")
CommentEnd = InStr(CommentStart, Script, "*/") + 1
If CommentEnd <= 2 Then CommentEnd = Len(Script)
LineStart = InStrRev(Script, vbCrLf, CommentStart)
If PrevLineStart <> LineStart Then PrevCommentPosInLine = 0
PrevLineStart = LineStart
LineEnd = InStr(CommentStart, Script, vbCrLf)
If LineEnd <= 0 Then LineEnd = Len(Script) + 1
line = Mid$(Script, LineStart + 1, LineEnd - LineStart)
CommentPosInLine = InStr(PrevCommentPosInLine + 1, line, "/*")
PrevCommentPosInLine = CommentPosInLine
QuotesStart = InStrRev(line, Chr$(34), CommentPosInLine)
QuotesEnd = InStr(CommentPosInLine, line, Chr$(34))
If CommentPosInLine > QuotesStart And CommentPosInLine < QuotesEnd Then CommentEnd = CommentStart: GoTo lLoop2
Script = Replace(Script, Mid$(Script, CommentStart, CommentEnd - CommentStart + 1), "")
CommentEnd = CommentEnd - (CommentEnd - CommentStart + 1)
lLoop2:
Loop
'------------------------------------------
Script = ReplaceCrLf(Script)
Exit Sub
lSkip:
ADL "êîììåíòàðèé èìååò íåâåðíóþ êîíñòðóêöèþ"
Resume Next
Exit Sub
ErrHandler:
GlobalError.Description = "Îøèáêà íà ñòàäèè óäàëåíèÿ êîììåíòàðèé"
GlobalError.Expression = Script
Call GlobalErrorHandler
End Sub
Sub CheckParameters(Params() As Variant, ParamArray DefaultParams() As Variant)
If Settings.bSkipErrors Then On Error GoTo lSkip Else On Error GoTo ErrHandler
' ìàññèâ äåôîëòíûõ ïàðàìåòðîâ íà÷èíàåòñÿ ñ 0, à ìàññèâ ïàðàìåòðîâ ñ 1
AddStage "Ïðîâåðêà ïàðàìåòðîâ íà âàëèäíîñòü"
ReDim Preserve Params(1 To UBound(DefaultParams) + 1)
For n = 1 To UBound(DefaultParams) + 1
If bIsScript And n = 1 Then
ReplaceVars Params(n), True
bIsScript = False
Else
If DefaultParams(n - 1) <> "#VAR#" Then ReplaceVars Params(n)
End If
If InStr(1, Params(n), ConstPrefix) > 0 Then ReplaceConsts Params(n)
If Params(n) = "" Or Params(n) = Chr(34) & Chr(34) Then 'åñëè ïóñòûå êàâû÷êè
Params(n) = DefaultParams(n - 1)
ElseIf InStr(1, Params(n), "~") > 0 And Left$(Params(n), 1) <> Chr$(34) And Len(Params(n)) < 30 Then ' ÅÑËÈ èñïîëüçóåòñÿ ðàíäîìèçàòîð ~
Dim buff() As String
buff = Split(Params(n), "~")
If (Not IsNumeric(buff(0))) Or (Not IsNumeric(buff(1))) Then
If (Not IsNumeric(buff(0))) And (Not IsNumeric(buff(1))) Then ' ÅÑËÈ îáå ÷àñòè íå ÿâëÿþòñÿ ÷èñëîì (1 ìèí 30 ñåê ~ 2 ìèí 50 ñåê)
ConvertNumber buff(0)
ConvertNumber buff(1)
buff(0) = Calculate(buff(0))
buff(1) = Calculate(buff(1))
ElseIf IsNumeric(buff(0)) And (Not IsNumeric(buff(1))) Then ' ÅÑËÈ òîëüêî ïðàâàÿ ÷àñòü íå ÿâëÿåòñÿ ÷èñëîì (1~2 ìèíóòû)
buff(0) = buff(0) & Right$(buff(1), 3) ' Çàäàþ ëåâîé ÷àñòè òó æå ñèñòåìó èçìåðåíèÿ ÷òî è ïðàâîé
ConvertNumber buff(0)
ConvertNumber buff(1)
buff(0) = Calculate(buff(0))
buff(1) = Calculate(buff(1))
ElseIf (Not IsNumeric(buff(0))) And IsNumeric(buff(1)) Then ' ÅÑËÈ òîëüêî ëåâàÿ ÷àñòü íå ÿâëÿåòñÿ ÷èñëîì (1 ìèíóòà ~ 2)
buff(1) = buff(1) & Right$(buff(0), 3) ' Çàäàþ ïðàâîé ÷àñòè òó æå ñèñòåìó èçìåðåíèÿ ÷òî è ïðàâîé
ConvertNumber buff(0)
ConvertNumber buff(1)
buff(0) = Calculate(buff(0))
buff(1) = Calculate(buff(1))
End If
End If
If (Not IsNumeric(buff(0))) Or (Not IsNumeric(buff(1))) Then Err.Raise ErrNum, "Íåïðàâèëüíî èñïîëüçîâàí ðàíäîìèçàòîð ~"
Params(n) = GenerateRnd(buff(0), buff(1), False)
ElseIf IsNumeric(DefaultParams(n - 1)) And Not IsNumeric(Params(n)) Then
'åñëè ïî óìîë÷àíèþ äîëæíî áûòü ÷èñëîâîå çíà÷åíèå, à â ïàðàìåòðå íå ÷èñëîâîå, òî îíî êîíâåðòèðóåòñÿ
ConvertNumber Params(n), DefaultParams(n - 1), True ' Íà âñÿêèé ñëó÷àé ïîïðîáîâàòü êîíâåðòèðîâàòü èç ñèñòåì èçìåðåíèÿ
If IsExpression(Params(n)) Then ' ÅÑËÈ âûðàæåíèå, òî ïîïðîáîâàòü ïîñ÷èòàòü
Params(n) = Calculate(Params(n))
End If
ElseIf IsExpression(Params(n)) And Not IsNumeric(DefaultParams(n - 1)) Then
' åñëè íàïèñàíî âûðàæåíèå, òî ïîïðîáîâàòü åãî âûñ÷èòàòü, ïðîïóñêàÿ îøèáêè
Params(n) = Calculate(Params(n), True)
ElseIf InStr(1, Params(n), Chr$(34)) > 0 Then
' åñëè åñòü êàâû÷êè, òî óáðàòü èõ
If IsTextOnQuotes(Params(n)) And DefaultParams(n - 1) <> "#COND#" Then _
Params(n) = Mid(Params(n), 2, Len(Params(n)) - 2)
End If
Params(n) = UnEscapeChars(Params(n)) 'Äåêîäèðóþ äàííûå èç ýêðàíà
Next n
Exit Sub
lSkip:
ADL "íåâåðíûå ïàðàìåòðû"
Resume Next
Exit Sub
ErrHandler:
GlobalError.Description = "Îøèáêà ïðè ïîïûòêå çàäàòü ïàðàìåòðû ïî óìîë÷àíèþ"
Call GlobalErrorHandler
End Sub
Sub ParseParameters(ByVal ParamLine As String, ByRef Params() As Variant)
Dim RealCount As Long, NullParam() As String
If Settings.bSkipErrors Then On Error GoTo lSkip Else On Error GoTo ErrHandler
AddStage "Îïðåäåëåíèå ïàðàìåòðîâ"
If ParamLine = "" Then Exit Sub
ParamLine = ReplaceInQuotesSTR(ParamLine, Delimiter, vbLf & vbCr)
NullParam() = Split(ParamLine, Delimiter)
ReDim Params(1 To UBound(NullParam) + 1)
For n = 1 To UBound(NullParam) + 1
Params(n) = NullParam(n - 1)
Params(n) = Replace(Params(n), vbLf & vbCr, Delimiter) ' ðåïëåéñ ","
Next n
Exit Sub
lSkip:
ADL "íåâåðíûå ïàðàìåòðû"
Resume Next
Exit Sub
ErrHandler:
GlobalError.Description = "Îøèáêà ïðè ïîïûòêå ïîëó÷èòü ïàðàìåòðû"
GlobalError.Expression = ParamLine
Call GlobalErrorHandler
End Sub
Function GetSelStartFromLine(ByVal str As String, LineNum As Long) As Long
If LineNum = 1 Then GetSelStartFromLine = 0: Exit Function
For n = 1 To LineNum - 1
GetSelStartFromLine = InStr(GetSelStartFromLine + 1, str, vbCrLf)
Next n
GetSelStartFromLine = GetSelStartFromLine + 1
End Function
Function GetFunc(ByVal line As Variant, Optional SkipErrs As Boolean) As Functions
' ïîèñê ôóíêöèè
If SkipErrs Then
On Error Resume Next
ConvertScript line
End If
For c = 1 To Len(line)
GetFunc = LCase(Mid$(line, 1, c))
For Each arr In Funcs
If GetFunc = arr Then Exit Function 'And (Mid$(line, Len(GetFunc) + 1, 1) = "(" Or Len(line) = Len(GetFunc)) Then Exit Function
Next
Next c
End Function
Function GetScript(ByVal line As Variant) As String
ConvertScript line
GetScript = CStr(line)
End Function
Function EscapeChars(ByVal sIn, Optional EscChar As String = "\") As Variant
Dim c As Long, Chars(), EscedChar As String
EscapeChars = sIn
If InStr(1, EscapeChars, EscChar) = 0 Then Exit Function
Chars = Array(Chr$(34), "{", "}", "'", "*", "+", "-", ":", "/", ",", "(", ")", "^", "~", "=", "$")
For c = LBound(Chars) To UBound(Chars)
If InStr(1, EscapeChars, EscChar & Chars(c)) > 0 Then
EscedChar = "#" & GetEscedChar(c) & "#"
EscapeChars = Replace(EscapeChars, EscChar & Chars(c), EscedChar)
End If
Next c
End Function
Function UnEscapeChars(ByVal sIn, Optional EscChar As String = "\") As Variant
Dim c As Long, Chars(), EscedChar As String, EscSign As String
UnEscapeChars = sIn
If InStr(1, UnEscapeChars, "#") = 0 Then Exit Function
Chars = Array(Chr$(34), "{", "}", "'", "*", "+", "-", ":", "/", ",", "(", ")", "^", "~", "=", "$")
For c = LBound(Chars) To UBound(Chars)
EscedChar = "#" & GetEscedChar(c) & "#"
If InStr(1, UnEscapeChars, EscedChar) > 0 Then
UnEscapeChars = Replace(UnEscapeChars, EscedChar, Chars(c))
End If
Next c
End Function
Function GetEscedChar(ByVal num As String) As String
Dim sFirst As String, sSecond As String
If Len(num) = 1 Then num = "0" & num
sFirst = Left$(num, 1)
sSecond = Right$(num, 1)
GetEscedChar = Chr$(CLng(sFirst)) & Chr$(CLng(sSecond))
End Function
Sub ReplaceConsts(ByRef Data As Variant)
With sConsts
If ConstExists(Data, .Time) Then ReplaceConst Data, .Time, Format$(Time, "hh:mm:ss")
If ConstExists(Data, .Date) Then ReplaceConst Data, .Date, Format$(Date, "yyyy.mm.dd")
If ConstExists(Data, .Key) Then ReplaceConst Data, .Key, ScanKey
If ConstExists(Data, .Window) Then ReplaceConst Data, .Window, GetForegroundWindowCaption
End With
End Sub
Function ConstExists(ByRef Data As Variant, ByVal ConstName As String) As Boolean
ConstExists = (InStr(1, Data, ConstPrefix & ConstName) > 0)
End Function
Sub ReplaceConst(ByRef Data As Variant, ByVal ConstName As String, ByVal ConstValue As String)
If IsNumeric(ConstValue) Then
RealReplaceVar Data, ConstPrefix & ConstName, ConstValue
Else
RealReplaceVar Data, ConstPrefix & ConstName, Chr$(34) & ConstValue & Chr$(34)
End If
End Sub
Sub ConvertScript(ByRef Script As Variant)
If Settings.bSkipErrors Then On Error GoTo lSkip Else On Error GoTo ErrHandler
'AddStage "Êîíâåðòàöèÿ ñêðèïòà"
Script = EscapeChars(Script)
' ' ýêðàíèðóþ íîâûå ñòðîêè, åñëè îíè â êàâû÷êàõ
' ReplaceInQuotes Script, vbCrLf, ""
DeleteComments Script
If (Not Not ConstName) <> 0 Then 'åñëè ìàññèâ ñóùåñòâóåò - ðåïëåéñ êîíñòàíò
For n = 1 To UBound(ConstName)
ReplaceOutQuotes Script, ConstName(n), ConstVal(n)
Next n
End If
If (Not Not FuncName) <> 0 Then 'åñëè ìàññèâ ñóùåñòâóåò - ðåïëåéñ ôóíêöèé
For n = 1 To UBound(FuncName)
ReplaceOutQuotes Script, FuncName(n), FuncVal(n)
Next n
End If
ReplaceOutQuotes Script, ", òîãäà ", ","
ReplaceOutQuotes Script, ", òî ", ","
ReplaceOutQuotes Script, ", èíà÷å ", ","
ReplaceOutQuotes Script, " òîãäà ", ","
ReplaceOutQuotes Script, " òî ", ","
ReplaceOutQuotes Script, " èíà÷å ", ","
ReplaceOutQuotes Script, ", then ", ","
ReplaceOutQuotes Script, ", else ", ","
ReplaceOutQuotes Script, " then ", ","
ReplaceOutQuotes Script, " else ", ","
ReplaceOutQuotes Script, " ", ""
'-----------------------------------------------------------------------------------------------------------------
ReplaceFunc Script, ClickV(), cClick
ReplaceFunc Script, WaitV(), cWait
ReplaceFunc Script, PressV(), cPress
ReplaceFunc Script, ExitV(), cExit
ReplaceFunc Script, StartScriptV(), cStartScript
ReplaceFunc Script, SetCursorPosV(), cSetCursorPos
ReplaceFunc Script, LoopV(), cLoop
ReplaceFunc Script, MsgBoxV(), cMsgBox
ReplaceFunc Script, InputBoxV(), cInputBox
ReplaceFunc Script, PrintV(), cPrint
ReplaceFunc Script, CreateFileV(), cCreateFile
ReplaceFunc Script, WriteFileV(), cWriteFile
ReplaceFunc Script, ReadFileV(), cReadFile
ReplaceFunc Script, SetWindowV(), cSetWindow
ReplaceFunc Script, ShowWindowV(), cShowWindow
ReplaceFunc Script, ShellV(), cShell
ReplaceFunc Script, StopV(), cStop
ReplaceFunc Script, SkipErrorsV(), cSkipErrors
ReplaceFunc Script, ChangeResolutionV(), cChangeResolution
ReplaceFunc Script, DeleteFileV(), cDeleteFile
ReplaceFunc Script, KillProcessV(), cKillProcess
ReplaceFunc Script, DeleteDirV(), cDeleteDir
ReplaceFunc Script, CreateDirV(), cCreateDir
ReplaceFunc Script, CloseWindowV(), cCloseWindow
ReplaceFunc Script, DownloadFileV(), cDownloadFile
ReplaceFunc Script, IfV(), cIf
ReplaceFunc Script, VBScriptV(), cVBScript
ReplaceFunc Script, GoToV(), cGoTo
ReplaceParam Script, "ñåêóíäà ñåêóíäû ñåêóíäó ñåêóíä ñåê. ñåê", pSeconds, False, True
ReplaceParam Script, "ìèíóòà ìèíóòó ìèíóòû ìèíóò ìèí. ìèí", pMinutes, False, True
ReplaceParam Script, "÷àñîâ ÷àñà ÷àñ. ÷àñ", pHours, False, True
ReplaceParam Script, "ñîáûòèå:êëèê êëèê", pClick
ReplaceParam Script, "ëåâàÿ", pLeft
ReplaceParam Script, "ïðàâàÿ", pRight
ReplaceParam Script, "ñðåäíÿÿ", pMiddle
ReplaceParam Script, "âíèç", pDown
ReplaceParam Script, "ââåðõ", pUp
ReplaceParam Script, "äà yes true", pYes
ReplaceParam Script, "íåò no false", pNo
ReplaceParam Script, "ðàçà ðàç ìñ", "", False
ReplaceParam Script, "íîðìàëüíî", vbNormalFocus
ReplaceParam Script, "ñâåðíóòî", vbMinimizedFocus
ReplaceParam Script, "ðàçâåðíóòî", vbMaximizedFocus
ReplaceParam Script, "ñâ¸ðíóòî", vbMinimizedFocus
ReplaceParam Script, "ðàçâ¸ðíóòî", vbMaximizedFocus
ReplaceParam Script, "ñêðûòî", vbHide
ReplaceParam Script, "èíôîðìàöèÿ", vbInformation
ReplaceParam Script, "êðèòè÷åñêàÿîøèáêà", vbCritical
ReplaceParam Script, "îøèáêà", vbExclamation
ReplaceParam Script, "áåñêîíå÷íî", pInfinitely
'Script = UnEscapeChars(Script) ' Äàííûå âûâîæó èç ýêðàíà òîëüêî íà ìîìåíò ïàðñèíãà ïàðàìåòðîâ
Exit Sub
lSkip:
ADL "ñêðèïò ñêîíâåðòèðîâàí íå ïîëíîñòüþ"
Resume Next
Exit Sub
ErrHandler:
GlobalError.Description = "Îøèáêà ïðè ïîïûòêå ïðèâåñòè ñêðèïò â íåîáõîäèìûé âèä"
GlobalError.Expression = Script
Call GlobalErrorHandler
End Sub
Sub ReplaceFunc(Script As Variant, FuncVariantes() As Variant, nReplace As Functions)
For Each arr In FuncVariantes
ReplaceOutQuotes Script, Replace(arr, " ", ""), nReplace, rtFunc
Next
End Sub
Sub ReplaceParam(Script As Variant, ParamVariantes As String, Replace As String, Optional ParamAlone As Boolean = True, Optional bReplaceAll As Boolean)
For Each arr In Split(ParamVariantes, " ")
If bReplaceAll Then
ReplaceOutQuotes Script, arr, Replace
Else
ReplaceOutQuotes Script, arr, Replace, rtParam, ParamAlone
End If
Next
End Sub
Sub ReplaceOutQuotes(ByRef Script As Variant, ByVal Find As String, ByVal nReplace As String, Optional ByVal ReplaceType As ReplaceType, Optional ParamAlone As Boolean = True)
Dim EmptyQuotesStringStart As Long, EmptyQuotesStringEnd As Long, EmptyQuotesString As String
'EmptyQuotesString - çíà÷èò ïóñòàÿ îò "
If Settings.bSkipErrors Then On Error GoTo lSkip Else On Error GoTo ErrHandler
If InStr(1, Script, Find) = 0 Then Exit Sub
If InStr(1, Script, Chr$(34)) = 0 Then
'åñëè êàâû÷åê íåò, òî ðåïëåéñèòü âñå
Select Case ReplaceType
Case rtFunc
RealReplaceFunc Script, Find, nReplace
Case rtParam
RealReplaceParam Script, Find, nReplace, ParamAlone
Case rtVar
RealReplaceVar Script, Find, nReplace
Case Else
Script = Replace(Script, Find, nReplace)
End Select
Exit Sub
End If
Do While InStr(EmptyQuotesStringStart + 1, Script, Find) > 0
EmptyQuotesStringEnd = InStr(EmptyQuotesStringStart + 1, Script, Chr$(34))
If EmptyQuotesStringEnd = 0 Then EmptyQuotesStringEnd = Len(Script)
EmptyQuotesString = Mid$(Script, EmptyQuotesStringStart + 1, EmptyQuotesStringEnd - EmptyQuotesStringStart)
Select Case ReplaceType
Case rtFunc
RealReplaceFunc EmptyQuotesString, Find, nReplace
Case rtParam
RealReplaceParam EmptyQuotesString, Find, nReplace
Case rtVar
RealReplaceVar EmptyQuotesString, Find, nReplace
Case Else
EmptyQuotesString = Replace(EmptyQuotesString, Find, nReplace)
End Select
Script = AccurateReplace(Script, EmptyQuotesString, EmptyQuotesStringStart + 1, EmptyQuotesStringEnd)
EmptyQuotesStringEnd = InStr(EmptyQuotesStringStart + 1, Script, Chr$(34)) ' Åùå ðàç èùó êàâû÷êó, ÷òîáû îáíîâèòü åå ïîçèöèþ, èáî ïîñëå çàìåíû îíà ìîæåò èçìåíèòüñÿ
EmptyQuotesStringStart = InStr(EmptyQuotesStringEnd + 1, Script, Chr$(34))
If EmptyQuotesStringEnd = 0 Or EmptyQuotesStringStart = 0 Then Exit Sub
Loop
Exit Sub
lSkip:
ADL "çàìåíà ïîòåðïåëà êðàõ"
Resume Next
Exit Sub
ErrHandler:
GlobalError.Description = "Îøèáêà ïðè ïîïûòêå çàìåíèòü äàííûå â ñêðèïòå"
GlobalError.Expression = Script
Call GlobalErrorHandler
End Sub
'Sub ReplaceOutQuotes(ByRef Script As Variant, ByVal Find As String, ByVal nReplace As String, Optional ByVal ReplaceType As ReplaceType, Optional ParamAlone As Boolean = True)
' Dim EmptyQuotesStringStart As Long, EmptyQuotesStringEnd As Long, EmptyQuotesString As String, SectionEnd As Long, TextBeforeLineEnd As String, LineStart As Long, LineEnd As Long
' 'EmptyQuotesString - çíà÷èò ïóñòàÿ îò "
' 'Line - çíà÷èò ôàêòè÷åñêàÿ ëèíèÿ îò CrLf äî CrLf
' If Settings.bSkipErrors Then On Error GoTo lSkip Else On Error GoTo ErrHandler
' If InStr(1, Script, Find) = 0 Then Exit Sub
' If InStr(1, Script, Chr$(34)) = 0 Then
' 'åñëè êàâû÷åê íåò, òî ðåïëåéñèòü âñå
' Select Case ReplaceType
' Case rtFunc
' RealReplaceFunc Script, Find, nReplace
' Case rtParam
' RealReplaceParam Script, Find, nReplace, ParamAlone
' Case rtVar
' RealReplaceVar Script, Find, nReplace
' Case Else