-
Notifications
You must be signed in to change notification settings - Fork 5
/
menufile.asm
1040 lines (989 loc) · 23.9 KB
/
menufile.asm
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
.code
assume fs:nothing
if 0
;
_OpenScript proc
LOCAL @nReturnInfo
LOCAL @nPos
LOCAL @pbInfo:_ProgBarInfo
LOCAL @szstr[SHORT_STRINGLEN]:byte
xor eax,eax
mov FileInfo2.bReadOnly,eax
inc eax
mov FileInfo1.bReadOnly,eax
.if dbConf+_Configs.nEditMode==EM_SINGLE
invoke _GenName2,FileInfo1.lpszName,offset FileInfo2.lpszName
or eax,eax
je _ExOS
.endif
mov eax,nCurMel
.if eax!=-1
mov edi,lpMels
mov bx,sizeof _MelInfo
mul bx
add edi,eax
mov ebx,_MelInfo.lpMelInfo2[edi]
.else
mov ebx,offset dbMelInfo2
.endif
invoke _LoadFile,offset FileInfo1,LM_NONE,ebx
.if !eax
invoke _ClearAll,offset FileInfo1
jmp _ErrLoadOS
.endif
.if dbConf+_Configs.nEditMode==EM_SINGLE
invoke _LoadFile,offset FileInfo2,LM_HALF,ebx
.if !eax
invoke GetLastError
.if eax==ERROR_FILE_NOT_FOUND
invoke CopyFileW,FileInfo1.lpszName,FileInfo2.lpszName,FALSE
invoke _LoadFile,offset FileInfo2,LM_HALF,ebx
or eax,eax
jne @F
.endif
invoke _ClearAll,offset FileInfo1
invoke _ClearAll,offset FileInfo2
jmp _ErrLoadOS
.endif
.endif
@@:
; invoke _ReadRec,REC_CHARSET
push offset _HandlerOS
push fs:[0]
mov fs:[0],esp
lea eax,@nReturnInfo
push eax
push offset FileInfo1
call dword ptr [dbSimpFunc+_SimpFunc.GetText]
.if !eax
.if @nReturnInfo==RI_SUC_LINEONLY
.if FileInfo1.nMemoryType==MT_POINTERONLY
invoke _MakeStringListFromStream,offset FileInfo1
.if eax
mov ecx,eax
mov eax,IDS_ERRORCODE
invoke _GetConstString
invoke wsprintfW,addr @szstr,eax,ecx
invoke _ClearAll,offset FileInfo1
invoke MessageBoxW,hWinMain,addr @szstr,0,MB_ICONERROR or MB_OK
.endif
.endif
invoke HeapAlloc,hGlobalHeap,HEAP_ZERO_MEMORY,FileInfo1.nLine
mov lpMarkTable,eax
; invoke _ReadRec,REC_MARKTABLE
.if dbConf+_Configs.bAlwaysFilter
invoke _UpdateHideTable,offset FileInfo1
.endif
mov bProgBarStopping1,0
invoke _AddLinesToList,offset FileInfo1,hList1,offset bProgBarStopping1
.endif
.else
jmp _ErrDllOS
.endif
.if dbConf+_Configs.nEditMode==EM_SINGLE
lea eax,@nReturnInfo
push eax
push offset FileInfo2
call dword ptr [dbSimpFunc+_SimpFunc.GetText]
.if !eax
mov eax,FileInfo1.nLine
.if eax!=FileInfo2.nLine
invoke _ClearAll,offset FileInfo1
invoke _ClearAll,offset FileInfo2
.if lpMarkTable
invoke HeapFree,hGlobalHeap,0,lpMarkTable
.endif
mov eax,IDS_LINENOTMATCH
invoke _GetConstString
invoke MessageBoxW,hWinMain,eax,0,MB_OK OR MB_ICONERROR
jmp _Ex2OS
.endif
.if @nReturnInfo==RI_SUC_LINEONLY
.if FileInfo2.nMemoryType==MT_POINTERONLY
invoke _MakeStringListFromStream,offset FileInfo2
.if eax
mov ecx,eax
mov eax,IDS_ERRORCODE
invoke _GetConstString
invoke wsprintfW,addr @szstr,eax,ecx
invoke _ClearAll,offset FileInfo1
invoke _ClearAll,offset FileInfo2
invoke MessageBoxW,hWinMain,addr @szstr,0,MB_ICONERROR or MB_OK
.if lpMarkTable
invoke HeapFree,hGlobalHeap,0,lpMarkTable
.endif
jmp _Ex2OS
.endif
.endif
mov nCurIdx,-1
mov bProgBarStopping2,0
invoke _DirFileNameW,FileInfo2.lpszName
mov @pbInfo.lpszTitle,eax
mov @pbInfo.bNoStop,0
invoke _AddLinesToList,offset FileInfo2,hList2,offset bProgBarStopping2
invoke DialogBoxParamW,hInstance,IDD_PROGBAR,hWinMain,offset _WndProgBarProc,addr @pbInfo
mov ecx,dbConf+_Configs.nAutoCode
.if ecx && FileInfo2.nCharSet!=CS_UNICODE && FileInfo2.nCharSet!=CS_UTF8
mov FileInfo2.nCharSet,ecx
xor ebx,ebx
xor edi,edi
.while ebx<FileInfo2.nLine
push ebx
push offset FileInfo2
call dbSimpFunc+_SimpFunc.ModifyLine
or edi,eax
inc ebx
.endw
.if edi
mov eax,IDS_CODECVTFAILED
invoke _GetConstString
invoke MessageBoxW,hWinMain,eax,0,MB_OK or MB_ICONERROR
.endif
.endif
invoke _SetOpenState,1
.endif
.else
.if lpMarkTable
invoke HeapFree,hGlobalHeap,0,lpMarkTable
.endif
jmp _ErrDllOS
.endif
invoke EnableMenuItem,hMenu,IDM_LOAD,MF_GRAYED
invoke HeapAlloc,hGlobalHeap,HEAP_ZERO_MEMORY,FileInfo1.nLine
mov lpModifyTable,eax
invoke HeapAlloc,hGlobalHeap,HEAP_ZERO_MEMORY,MAX_STRINGLEN+SHORT_STRINGLEN
or eax,eax
je _Ex2OS
mov ebx,eax
invoke _GenWindowTitle,ebx,GWT_FILENAME1
invoke SetWindowTextW,hWinMain,ebx
invoke HeapFree,hGlobalHeap,0,ebx
.else
invoke EnableMenuItem,hMenu,IDM_LOAD,MF_ENABLED
.endif
_Ex2OS:
pop fs:[0]
pop ecx
_ExOS:
xor eax,eax
ret
_ErrLoadOS:
mov eax,IDS_ERRLOADFILE
invoke _GetConstString
invoke MessageBoxW,hWinMain,eax,0,MB_OK or MB_ICONERROR
xor eax,eax
ret
_ErrDllOS:
pop fs:[0]
pop eax
mov eax,IDS_DLLERR
invoke _GetConstString
invoke MessageBoxW,hWinMain,eax,0,MB_OK or MB_ICONERROR
invoke _ClearAll,offset FileInfo1
invoke _ClearAll,offset FileInfo2
xor eax,eax
ret
_HandlerOS:
mov eax,[esp+0ch]
mov [eax+0b8h],offset _ErrDllOS
xor eax,eax
retn 0ch
_OpenScript endp
endif
_OpenScript2 proc uses edi esi ebx _lpOpenPara
LOCAL @err
LOCAL @pbInfo:_ProgBarInfo
mov edi,_lpOpenPara
assume edi:ptr _OpenParameters
invoke _OpenSingleScript,edi,offset FileInfo1,1
mov @err,eax
test eax,eax
jnz _ErrOS
invoke _OpenSingleScript,edi,offset FileInfo2,0
mov @err,eax
test eax,eax
jnz _Err2OS
mov eax,FileInfo1.nLine
.if eax!=FileInfo2.nLine
mov @err,E_LINENOTMATCH
jmp _Err3OS
.endif
invoke HeapAlloc,hGlobalHeap,HEAP_ZERO_MEMORY,FileInfo1.nLine
mov lpMarkTable,eax
invoke _ReadRec,[edi].ScriptName,REC_MARKTABLE,FileInfo1.nLine
.if dbConf+_Configs.bAlwaysFilter
invoke _UpdateHideTable,offset FileInfo1
.endif
mov ecx,dbConf+_Configs.nAutoCode
.if ecx && FileInfo2.nCharSet!=CS_UNICODE && FileInfo2.nCharSet!=CS_UTF8
mov FileInfo2.nCharSet,ecx
xor ebx,ebx
xor esi,esi
.while ebx<FileInfo2.nLine
push ebx
push offset FileInfo2
call dbSimpFunc+_SimpFunc.ModifyLine
or esi,eax
inc ebx
.endw
.if esi
mov eax,IDS_CODECVTFAILED
invoke _GetConstString
invoke MessageBoxW,hWinMain,eax,0,MB_OK or MB_ICONERROR
.endif
.endif
mov eax,[edi].Line
mov nCurIdx,eax
mov bProgBarStopping1,0
mov bProgBarStopping2,0
invoke _DirFileNameW,[edi].ScriptName
mov @pbInfo.lpszTitle,eax
mov @pbInfo.bNoStop,0
invoke _AddLinesToList,offset FileInfo1,hList1,offset bProgBarStopping1
invoke _AddLinesToList,offset FileInfo2,hList2,offset bProgBarStopping2
invoke DialogBoxParamW,hInstance,IDD_PROGBAR,hWinMain,offset _WndProgBarProc,addr @pbInfo
invoke _SetOpenState,1
invoke HeapAlloc,hGlobalHeap,HEAP_ZERO_MEMORY,FileInfo1.nLine
mov lpModifyTable,eax
invoke HeapAlloc,hGlobalHeap,HEAP_ZERO_MEMORY,MAX_STRINGLEN+SHORT_STRINGLEN
or eax,eax
je _ExOSS
mov ebx,eax
invoke _GenWindowTitle,ebx,GWT_FILENAME1
invoke SetWindowTextW,hWinMain,ebx
invoke HeapFree,hGlobalHeap,0,ebx
assume edi:nothing
_ExOSS:
ret
_Err3OS:
invoke _ClearAll,offset FileInfo2
_Err2OS:
invoke _ClearAll,offset FileInfo1
_ErrOS:
invoke _OutputMessage,@err,offset szInnerName,0,0
ret
_OpenScript2 endp
_OpenSingleScript proc uses esi edi ebx _lpOpenPara,_lpFI,_bIsLeft
LOCAL @nReturnInfo
mov edi,_lpOpenPara
assume edi:ptr _OpenParameters
mov eax,[edi].ScriptName
.if !eax
mov eax,E_INVALIDPARAMETER
jmp _ExOSS
.endif
.if _bIsLeft
invoke HeapAlloc,hGlobalHeap,0,MAX_STRINGLEN
.if !eax
mov eax,E_NOMEM
jmp _ExOSS
.endif
mov ecx,_lpFI
mov _FileInfo.lpszName[ecx],eax
.if nUIStatus&UIS_CONSOLE
mov _FileInfo.bReadOnly[ecx],0
.else
mov _FileInfo.bReadOnly[ecx],1
.endif
mov eax,[edi].Code1
mov _FileInfo.nCharSet[ecx],eax
invoke lstrcpyW,_FileInfo.lpszName[ecx],[edi].ScriptName
.else
mov ecx,_lpFI
mov _FileInfo.bReadOnly[ecx],0
mov eax,[edi].Code2
mov _FileInfo.nCharSet[ecx],eax
invoke _GenName2,[edi].ScriptName,addr _FileInfo.lpszName[ecx]
.if !eax
mov eax,E_NOMEM
jmp _ExOSS
.endif
.endif
mov eax,[edi].Plugin
.if eax!=-1
mov esi,lpMels
mov bx,sizeof _MelInfo
mul bx
add esi,eax
mov ebx,_MelInfo.lpMelInfo2[esi]
.else
mov eax,[edi].Filter
mov nCurMef,eax
mov ebx,offset dbMelInfo2
.endif
.if _bIsLeft
.if nUIStatus&UIS_CONSOLE
invoke _LoadFile,_lpFI,LM_ONE,ebx
.else
invoke _LoadFile,_lpFI,LM_NONE,ebx
.endif
@@:
.if !eax
mov eax,E_FILEACCESSERROR
jmp _ErrDll2OSS
.endif
.else
invoke _LoadFile,_lpFI,LM_HALF,ebx
.if !eax
invoke GetLastError
.if eax==ERROR_FILE_NOT_FOUND
mov ecx,_lpFI
invoke CopyFileW,[edi].ScriptName,_FileInfo.lpszName[ecx],FALSE
invoke _LoadFile,offset FileInfo2,LM_HALF,ebx
jmp @B
.endif
mov eax,E_FILEACCESSERROR
jmp _ErrDll2OSS
.endif
.endif
push ebp
push offset _HandlerOSS
push fs:[0]
mov fs:[0],esp
lea eax,@nReturnInfo
push eax
push _lpFI
call dword ptr [dbSimpFunc+_SimpFunc.GetText]
test eax,eax
jnz _ErrDllOSS
mov ecx,_lpFI
.if _FileInfo.nMemoryType[ecx]==MT_POINTERONLY
invoke _MakeStringListFromStream,_lpFI
test eax,eax
jnz _ErrDllOSS
.endif
assume edi:nothing
_Ex2OSS:
pop fs:[0]
add esp,8
_ExOSS:
ret
_ErrDllOSS:
pop fs:[0]
add esp,8
_ErrDll2OSS:
mov ebx,eax
invoke _ClearAll,_lpFI
mov eax,ebx
ret
_HandlerOSS:
mov edx,[esp+0ch]
mov [edx+0b8h],offset _ErrDllOSS
mov ecx,[esp+8]
mov [edx+0c4h],ecx
mov eax,[ecx+8]
mov [edx+0b4h],eax
mov ecx,[esp+4]
mov eax,[ecx]
.if eax==STATUS_BREAKPOINT ;8..3
mov dword ptr [edx+0b0h],E_ANALYSISFAILED
.elseif eax==STATUS_ACCESS_VIOLATION ;c..5
mov dword ptr [edx+0b0h],E_OVERMEM
.else
mov dword ptr [edx+0b0h],E_PLUGINERROR
.endif
xor eax,eax
retn 0ch
_OpenSingleScript endp
;
_LoadScript proc
LOCAL @nReturnInfo
LOCAL @szstr[20]:word
mov eax,nCurMel
.if eax!=-1
mov edi,lpMels
mov bx,sizeof _MelInfo
mul bx
add edi,eax
mov ebx,_MelInfo.lpMelInfo2[edi]
.else
mov ebx,offset dbMelInfo2
.endif
invoke _LoadFile,offset FileInfo2,LM_HALF,ebx
.if !eax
invoke _ClearAll,offset FileInfo2
jmp _ErrLoadLS
.endif
push offset _HandlerLS
push fs:[0]
mov fs:[0],esp
lea eax,@nReturnInfo
push eax
push offset FileInfo2
call dword ptr [dbSimpFunc+_SimpFunc.GetText]
.if !eax
mov eax,FileInfo1.nLine
.if eax!=FileInfo2.nLine
invoke _ClearAll,offset FileInfo2
mov eax,IDS_LINENOTMATCH
invoke _GetConstString
invoke MessageBoxW,hWinMain,eax,0,MB_OK OR MB_ICONERROR
jmp _ExLS
.endif
.if @nReturnInfo==RI_SUC_LINEONLY
.if FileInfo2.nMemoryType==MT_POINTERONLY
invoke _MakeStringListFromStream,offset FileInfo2
.if eax
mov ecx,eax
mov eax,IDS_ERRORCODE
invoke _GetConstString
invoke wsprintfW,addr @szstr,eax,ecx
invoke _ClearAll,offset FileInfo2
invoke MessageBoxW,hWinMain,addr @szstr,0,MB_ICONERROR or MB_OK
.endif
.endif
mov nCurIdx,-1
mov bProgBarStopping2,0
invoke _AddLinesToList,offset FileInfo2,hList2,offset bProgBarStopping2
mov ecx,dbConf+_Configs.nAutoCode
; .if ecx && FileInfo2.nCharSet!=CS_UNICODE && File2.nCharSet!=CS_UTF8
; mov FileInfo2.nCharSet,ecx
; xor ebx,ebx
; xor edi,edi
; .while ebx<FileInfo2.nLine
; push ebx
; push offset FileInfo2
; call dbSimpFunc+_SimpFunc.ModifyLine
; or edi,eax
; inc ebx
; .endw
; .if edi
; mov eax,IDS_CODECVTFAILED
; invoke _GetConstString
; invoke MessageBoxW,hWinMain,eax,0,MB_OK or MB_ICONERROR
; .endif
; .endif
invoke _SetOpenState,1
.endif
.else
invoke _ClearAll,offset FileInfo2
jmp _Ex2LS
.endif
_Ex2LS:
pop fs:[0]
pop ecx
invoke HeapAlloc,hGlobalHeap,HEAP_ZERO_MEMORY,MAX_STRINGLEN+SHORT_STRINGLEN
or eax,eax
je _ExLS
mov ebx,eax
invoke _GenWindowTitle,ebx,GWT_FILENAME2
invoke SetWindowTextW,hWinMain,ebx
invoke HeapFree,hGlobalHeap,0,ebx
_ExLS:
xor eax,eax
ret
_ErrLoadLS:
mov eax,IDS_ERRLOADFILE
invoke _GetConstString
invoke MessageBoxW,hWinMain,eax,0,MB_OK or MB_ICONERROR
xor eax,eax
ret
_ErrDllLS:
pop fs:[0]
pop eax
mov eax,IDS_DLLERR
invoke _GetConstString
invoke MessageBoxW,hWinMain,eax,0,MB_OK or MB_ICONERROR
invoke _ClearAll,offset FileInfo2
xor eax,eax
ret
_HandlerLS:
mov eax,[esp+0ch]
mov [eax+0b8h],offset _ErrDllLS
xor eax,eax
ret
_LoadScript endp
;
_SaveScript proc
.if bModified
invoke _SaveFile,offset FileInfo2
or eax,eax
jne _ErrSS
mov eax,IDS_SUCSAVE
INVOKE _GetConstString
invoke _DisplayStatus,eax,2000
invoke _SetModified,0
.endif
xor eax,eax
ret
_ErrSS:
mov eax,IDS_ERRSAVE
invoke _GetConstString
invoke MessageBoxW,hWinMain,eax,0,MB_OK or MB_ICONERROR
xor eax,eax
ret
_SaveScript endp
;
_SaveAs proc
LOCAL @fi:_FileInfo
LOCAL @szStr[MAX_STRINGLEN]:byte
lea eax,@szStr
mov word ptr [eax],0
mov eax,IDS_OPENTITLE3
invoke _GetConstString
invoke _SaveFileDlg,offset szOpenFilter,addr @szStr,dbConf+_Configs.lpInitDir2,eax
.if eax
lea edi,@fi
lea esi,FileInfo2
mov ecx,sizeof _FileInfo
rep movsb
lea eax,@szStr
mov @fi.lpszName,eax
invoke CreateFileW,@fi.lpszName,GENERIC_WRITE or GENERIC_READ,FILE_SHARE_READ,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0
.if eax==-1
mov eax,IDS_CANTOPENFILE
invoke _GetConstString
invoke MessageBoxW,hWinMain,eax,0,MB_OK or MB_ICONERROR
jmp _ExSA
.endif
mov @fi.hFile,eax
invoke _SaveFile,addr @fi
or eax,eax
jne _ErrSA
mov eax,IDS_SUCSAVE
INVOKE _GetConstString
invoke _DisplayStatus,eax,2000
.endif
_ExSA:
xor eax,eax
ret
_ErrSA:
mov eax,IDS_ERRSAVE
invoke _GetConstString
invoke MessageBoxW,hWinMain,eax,0,MB_OK or MB_ICONERROR
jmp _ExSA
_SaveAs endp
;
_CloseScript proc
cmp bOpen,0
je _ExCSC
.if bModified
invoke _SaveOrNot
.if eax==IDYES
invoke _SaveFile,offset FileInfo2
or eax,eax
je @F
mov eax,IDS_ERRSAVE
invoke _GetConstString
invoke MessageBoxW,hWinMain,eax,0,MB_OK or MB_ICONERROR
jmp _Ex2CSC
.endif
cmp eax,IDCANCEL
je _Ex2CSC
.endif
invoke _WriteRec
@@:
.if lpMarkTable
invoke HeapFree,hGlobalHeap,0,lpMarkTable
mov lpMarkTable,0
.endif
.if lpDisp2Real
invoke HeapFree,hGlobalHeap,0,lpDisp2Real
mov lpDisp2Real,0
.endif
.if lpModifyTable
invoke HeapFree,hGlobalHeap,0,lpModifyTable
mov lpModifyTable,0
.endif
invoke SendMessageW,hList1,LB_RESETCONTENT,0,0
invoke SendMessageW,hList2,LB_RESETCONTENT,0,0
invoke InvalidateRect,hWinMain,0,TRUE
invoke _ClearAll,offset FileInfo1
invoke _ClearAll,offset FileInfo2
invoke SendMessageW,hEdit1,WM_SETTEXT,0,offset szNULL
invoke SendMessageW,hEdit2,WM_SETTEXT,0,offset szNULL
invoke SetFocus,hList1
invoke _SetModified,0
invoke _SetOpenState,0
mov nCurIdx,-1
invoke HeapAlloc,hGlobalHeap,HEAP_ZERO_MEMORY,64
or eax,eax
je _ExCSC
push eax
invoke _GenWindowTitle,eax,GWT_VERSION
invoke SetWindowTextW,hWinMain,[esp]
push 0
push hGlobalHeap
call HeapFree
_ExCSC:
xor eax,eax
ret
_Ex2CSC:
or eax,-1
ret
_CloseScript endp
;
_SetCode proc
invoke DialogBoxParamW,hInstance,IDD_CODE,hWinMain,offset _WndCodeProc,0
ret
_SetCode endp
_WndCodeProc proc uses edi esi ebx hwnd,uMsg,wParam,lParam
LOCAL @lpMelInfo2
mov eax,uMsg
.if eax==WM_COMMAND
mov eax,wParam
.if ax==IDC_CODE_OK
invoke _GetMelInfo2,nCurMel
mov @lpMelInfo2,eax
invoke SendDlgItemMessageW,hwnd,IDC_CODE_OPEN1,CB_GETCURSEL,0,0
mov ecx,dword ptr [eax*4+dbCodeTable]
mov ebx,FileInfo1.nCharSet
.if ecx!=ebx
mov FileInfo1.nCharSet,ecx
mov eax,@lpMelInfo2
.if _MelInfo2.nCharacteristic[eax] & MIC_NOPREREAD
mov ecx,TRUE
.else
mov ecx,FALSE
.endif
invoke _RecodeFile,offset FileInfo1,FALSE,ecx
.if eax
.if eax==E_FATALERROR
mov bModified,0
invoke _CloseScript
mov eax,IDS_CODEFAILED
invoke _GetConstString
invoke MessageBoxW,hwnd,eax,0,MB_OK or MB_ICONERROR
jmp _ExitWCP
.endif
mov FileInfo1.nCharSet,ebx
.endif
.endif
invoke SendDlgItemMessageW,hwnd,IDC_CODE_OPEN2,CB_GETCURSEL,0,0
mov ecx,dword ptr [eax*4+dbCodeTable]
mov ebx,FileInfo2.nCharSet
.if ecx!=ebx
mov FileInfo2.nCharSet,ecx
mov eax,@lpMelInfo2
.if _MelInfo2.nCharacteristic[eax] & MIC_NOPREREAD
mov ecx,TRUE
.else
mov ecx,FALSE
.endif
invoke _RecodeFile,offset FileInfo2,FALSE,ecx
.if eax
.if eax==E_FATALERROR
mov bModified,0
invoke _CloseScript
mov eax,IDS_CODEFAILED
invoke _GetConstString
invoke MessageBoxW,hwnd,eax,0,MB_OK or MB_ICONERROR
jmp _ExitWCP
.endif
mov FileInfo1.nCharSet,ebx
mov eax,IDS_FAILCONVERT
invoke _GetConstString
invoke MessageBoxW,hwnd,eax,0,MB_OK or MB_ICONEXCLAMATION
jmp _ExWCP
.endif
.endif
invoke SendDlgItemMessageW,hwnd,IDC_CODE_SAVE2,CB_GETCURSEL,0,0
mov ecx,dword ptr [eax*4+dbCodeTable]
mov esi,FileInfo2.nCharSet
.if ecx!=esi
mov FileInfo2.nCharSet,ecx
xor ebx,ebx
xor edi,edi
.while ebx<FileInfo2.nLine
push ebx
push offset FileInfo2
call dbSimpFunc+_SimpFunc.ModifyLine
or edi,eax
inc ebx
.endw
.if edi
mov FileInfo2.nCharSet,esi
mov eax,IDS_FAILCONVERT
invoke _GetConstString
invoke MessageBoxW,hwnd,eax,0,MB_OK or MB_ICONEXCLAMATION
jmp _ExWCP
.endif
.endif
invoke InvalidateRect,hList1,0,TRUE
invoke InvalidateRect,hList2,0,TRUE
invoke SendMessageW,hList1,LB_GETCURSEL,0,1
.if eax<FileInfo1.nLine
invoke _SetTextToEdit,eax
.endif
jmp _ExitWCP
.elseif ax==IDC_CODE_CANCEL
_ExitWCP:
invoke EndDialog,hwnd,0
.endif
.elseif eax==WM_INITDIALOG
invoke GetDlgItem,hwnd,IDC_CODE_OPEN1
invoke _AddCodeCombo,eax
invoke GetDlgItem,hwnd,IDC_CODE_OPEN2
invoke _AddCodeCombo,eax
invoke GetDlgItem,hwnd,IDC_CODE_SAVE2
invoke _AddCodeCombo,eax
.if bOpen
invoke _GetCodeIndex,FileInfo1.nCharSet
invoke SendDlgItemMessageW,hwnd,IDC_CODE_OPEN1,CB_SETCURSEL,eax,0
invoke _GetCodeIndex,FileInfo2.nCharSet
mov ebx,eax
invoke SendDlgItemMessageW,hwnd,IDC_CODE_OPEN2,CB_SETCURSEL,eax,0
invoke SendDlgItemMessageW,hwnd,IDC_CODE_SAVE2,CB_SETCURSEL,ebx,0
.endif
.elseif eax==WM_CLOSE
invoke EndDialog,hwnd,0
.endif
_ExWCP:
xor eax,eax
ret
_WndCodeProc endp
;
_ExportTxt proc
LOCAL @szStr[MAX_STRINGLEN]:byte
LOCAL @hTxtFile
invoke lstrcpyW,addr @szStr,FileInfo2.lpszName
invoke _DirModifyExtendName,addr @szStr,offset szTxt
mov eax,IDS_EXPORTTXT
invoke _GetConstString
invoke _SaveFileDlg,offset szTxtFilter,addr @szStr,dbConf+_Configs.lpInitDir2,eax
.if eax
invoke CreateFileW,addr @szStr,GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0
.if eax==-1
mov eax,IDS_CANTOPENFILE
_ErrET:
invoke _GetConstString
invoke MessageBoxW,hWinMain,eax,0,MB_OK or MB_ICONERROR
jmp _ExET
.endif
mov @hTxtFile,eax
invoke _ExportSingleTxt,offset FileInfo2,@hTxtFile
mov ebx,eax
invoke CloseHandle,@hTxtFile
.if ebx
mov eax,IDS_FAILEXPORT
invoke _GetConstString
invoke MessageBoxW,hWinMain,eax,0,MB_OK or MB_ICONERROR
jmp _ExET
.endif
mov eax,IDS_SUCEXPORT
invoke _GetConstString
invoke _DisplayStatus,eax,2000
.endif
_ExET:
xor eax,eax
ret
_ExportTxt endp
;
_ExportSingleTxt proc uses esi edi ebx _lpFI,_hTxt
LOCAL @lpBuff,@nLine
mov ecx,_lpFI
assume ecx:ptr _FileInfo
mov eax,[ecx].nStreamSize
shl eax,1
invoke VirtualAlloc,0,eax,MEM_COMMIT,PAGE_READWRITE
.if !eax
mov eax,E_NOMEM
jmp _ExEST
.endif
mov @lpBuff,eax
mov edi,@lpBuff
mov ax,0feffh
stosw
xor ebx,ebx
mov ecx,_lpFI
mov eax,[ecx].nLine
mov @nLine,eax
.if [ecx].nMemoryType==MT_EVERYSTRING || [ecx].nMemoryType==MT_POINTERONLY
mov esi,[ecx].lpTextIndex
.while ebx<@nLine
invoke _IsDisplay,ebx
or eax,eax
je @F
invoke lstrcpyW,edi,[esi]
invoke lstrlenW,[esi]
shl eax,1
add edi,eax
mov eax,0a000dh
stosd
@@:
add esi,4
inc ebx
.endw
.else
mov eax,E_INVALIDPARAMETER
jmp _ExEST
.endif
sub edi,@lpBuff
invoke SetFilePointer,_hTxt,0,0,FILE_BEGIN
invoke WriteFile,_hTxt,@lpBuff,edi,offset dwTemp,0
mov ebx,eax
invoke VirtualFree,@lpBuff,0,MEM_RELEASE
invoke SetEndOfFile,_hTxt
or ebx,ebx
je _ErrEST
assume ecx:nothing
xor eax,eax
_ExEST:
ret
_ErrEST:
or eax,E_ERROR
ret
_ExportSingleTxt endp
_ImportSingleTxt proc uses esi edi ebx _lpFI,_lpTxt,_bFilterOn
local @nLineTxt
mov esi,_lpTxt
.if word ptr [esi]!=0feffh
mov eax,E_WRONGFORMAT
jmp _Ex
.endif
add esi,2
xor ecx,ecx
.while word ptr [esi]
.if dword ptr [esi]==0a000dh
mov dword ptr [esi],0
add esi,4
inc ecx
.continue
.endif
add esi,2
.endw
lea ebx,[ecx+1]
mov esi,lpMarkTable
.if !_bFilterOn
mov ecx,_lpFI
mov edx,_FileInfo.nLine[ecx]
.else
mov edx,_lpFI
mov ecx,_FileInfo.nLine[edx]
xor edx,edx
@@:
.if !(byte ptr [esi]&2)
inc edx
.endif
inc esi
loop @B
.endif
.if edx>ebx
mov eax,E_LINENOTMATCH
jmp _Ex
.endif
mov @nLineTxt,ebx
mov esi,_lpFI
assume esi:ptr _FileInfo
mov eax,[esi].nMemoryType
.if eax==MT_EVERYSTRING || eax==MT_POINTERONLY
xor ebx,ebx
mov edi,_lpTxt
add edi,2
.while ebx<[esi].nLine
.if _bFilterOn
invoke _IsDisplay,ebx
or eax,eax
je _NextLine2
.endif
mov eax,[esi].lpTextIndex
mov ecx,[eax+ebx*4]
mov dword ptr [eax+ebx*4],0
invoke HeapFree,hGlobalHeap,0,ecx
xor ax,ax
push edi
or ecx,-1
repne scasw
add edi,2
not ecx
shl ecx,1
invoke HeapAlloc,hGlobalHeap,0,ecx
.if !eax
add esp,4
mov eax,E_NOMEM
jmp _Ex
.endif
mov ecx,[esi].lpTextIndex
mov [ecx+ebx*4],eax
push eax
call lstrcpyW
_NextLine2:
inc ebx
.endw
.else
mov eax,E_PLUGINERROR
jmp _Ex
.endif
assume esi:nothing
xor eax,eax
_Ex:
ret
_ImportSingleTxt endp
;
_ImportTxt proc
LOCAL @lpStr
LOCAL @hTxtFile,@lpBuff,@pEnd,@nFlag
local @nFZ:LARGE_INTEGER
mov eax,IDS_IMPORTTXT
invoke _GetConstString
invoke _OpenFileDlg,offset szTxtFilter,addr @lpStr,dbConf+_Configs.lpInitDir2,eax,0
.if eax
invoke CreateFileW,@lpStr,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
.if eax==-1
mov eax,IDS_CANTOPENFILE
_ErrIT:
invoke _GetConstString
invoke MessageBoxW,hWinMain,eax,0,MB_OK or MB_ICONERROR
invoke HeapFree,hGlobalHeap,0,@lpStr
jmp _ExIT
.endif
mov @hTxtFile,eax
invoke HeapFree,hGlobalHeap,0,@lpStr
invoke GetFileSizeEx,@hTxtFile,addr @nFZ
invoke VirtualAlloc,0,dword ptr @nFZ,MEM_COMMIT,PAGE_READWRITE
.if !eax
_NomemIT:
invoke CloseHandle,@hTxtFile
mov eax,IDS_NOMEM
jmp _ErrIT
.endif
mov @lpBuff,eax
invoke ReadFile,@hTxtFile,@lpBuff,dword ptr @nFZ,offset dwTemp,0
invoke _ImportSingleTxt,offset FileInfo2,@lpBuff,TRUE
.if !eax
xor ebx,ebx
.while ebx<FileInfo2.nLine
invoke _IsDisplay,ebx
or eax,eax
je _NextIT
push ebx
push offset FileInfo2
call dbSimpFunc+_SimpFunc.ModifyLine
.if eax