-
Notifications
You must be signed in to change notification settings - Fork 3
/
Module10.bas
7935 lines (7519 loc) · 331 KB
/
Module10.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 = "Module10"
Option Explicit
' some utilities for String$( string as converter)
' some code from dilettante - vbforums
' http://www.vbforums.com/showthread.php?342995-VB6-URL-Path-String-Manipulation-Functions
' removed all InStrB. strings expexted to be as UTF16LE (as strings in VB6)
' if we have an ascii string then we have to convert it before use it
' also if we have a UTF8 string we have to convert it before use it here
Private Type PeekArrayType
Ptr As Long
Reserved As Currency
End Type
Private Declare Function PeekArray Lib "kernel32" Alias "RtlMoveMemory" (arr() As Any, Optional ByVal Length As Long = 4) As PeekArrayType
Private Declare Function SafeArrayGetDim Lib "OleAut32.dll" (ByVal Ptr As Long) As Long
Private Declare Function vbaVarLateMemSt Lib "msvbvm60" _
Alias "__vbaVarLateMemSt" ( _
ByRef vDst As Variant, _
ByRef sName As Any, _
ByVal vValue As Variant) As Long
Private Declare Function vbaVarLateMemCallLdRf CDecl Lib "msvbvm60" _
Alias "__vbaVarLateMemCallLdRf" ( _
ByRef vDst As Variant, _
ByRef vSrc As Variant, _
ByRef sName As Any, _
ByVal cArgs As Long) As Long
Private Declare Function vbaVarLateMemCallLdRf2 CDecl Lib "msvbvm60" _
Alias "__vbaVarLateMemCallLdRf" ( _
ByRef vDst As Variant, _
ByRef vSrc As Variant, _
ByRef sName As Any, _
ByVal cArgs As Long, _
ByVal vArg1) As Long
Private Declare Sub PutMem4 Lib "msvbvm60" (ByVal Addr As Long, ByVal NewVal As Long)
Private Declare Sub GetMem4 Lib "msvbvm60" (ByVal Addr As Long, RetVal As Long)
Private Const E_POINTER As Long = &H80004003
Private Const S_OK As Long = 0
Private Const INTERNET_MAX_URL_LENGTH As Long = 2083
Private Const URL_ESCAPE_PERCENT As Long = &H1000&
Private Const URL_PART_SCHEME As Long = 1
Private Const URL_PART_HOSTNAME As Long = 2
Private Const URL_PART_USERNAME As Long = 3
Private Const URL_PART_PASSWORD As Long = 4
Private Const URL_PART_PORT As Long = 5
Private Const URL_PART_QUERY As Long = 6
Private Declare Function UrlEscape Lib "shlwapi" Alias "UrlEscapeW" ( _
ByVal pszURL As Long, _
ByVal pszEscaped As Long, _
ByRef pcchEscaped As Long, _
ByVal dwFlags As Long) As Long
Private Declare Function UrlUnescape Lib "shlwapi" Alias "UrlUnescapeW" ( _
ByVal pszURL As Long, _
ByVal pszUnescaped As Long, _
ByRef pcchUnescaped As Long, _
ByVal dwFlags As Long) As Long
Private Const CONST_HOSTNAME = 2
Private Declare Function UrlGetPart Lib "shlwapi" Alias "UrlGetPartW" ( _
ByVal pszIn As Long, _
ByVal pszOut As Long, _
pcchOut As Long, _
ByVal dwPart As Long, _
ByVal dwFlags As Long) As Long
Private Declare Function UrlCanonicalizeApi Lib "shlwapi" Alias "UrlCanonicalizeW" ( _
ByVal pszURL As Long, _
ByVal pszCanonicalized As Long, _
pcchCanonicalized As Long, _
ByVal dwFlags As Long) As Long
Const NO_ERROR = 0&
Const MOVEFILE_REPLACE_EXISTING = &H1
Const FILE_ATTRIBUTE_TEMPORARY = &H100
Const FILE_BEGIN = 0
Const FILE_CURRENT = 1
Const FILE_END = 2
Const FILE_SHARE_READ = &H1
Const FILE_SHARE_WRITE = &H2
Const FILE_APPEND_DATA = &H4
Const FILE_READ_ATTRIBUTES As Long = &H80&
Const CREATE_NEW = 1
Const CREATE_ALWAYS = 2
Const OPEN_EXISTING = 3
Const OPEN_ALLWAYS = 4
Const GENERIC_READ = &H80000000
Const GENERIC_WRITE = &H40000000
Const ERROR_SHARING_VIOLATION = 32&
Const INVALID_HANDLE_VALUE = (-1&)
Const INVALID_SET_FILE_POINTER = (-1&)
Const FILE_ATTRIBUTE_NORMAL = &H80
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function FlushFileBuffers Lib "kernel32" (ByVal hFile As Long) As Long
Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Any) As Long
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByVal lpOverlapped As Any) As Long
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileW" (ByVal lpFileName As Long, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function SetFilePointer Lib "kernel32" (ByVal hFile As Long, ByVal lDistanceToMove As Long, lpDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long
Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
Private Declare Function SetEndOfFile Lib "kernel32" (ByVal hFile As Long) As Long
Private Declare Function GetLastError Lib "kernel32" () As Long
Private InUseHandlers As New FastCollection
Private FreeUseHandlers As New FastCollection
Enum MyOpenFileType
ForInput = 1 ' Read - Begin
ForOutput = 2 ' write - End
ForAppend = 3 ' Read+Write - End
ForField = 4 ' Read+Write - Begin
End Enum
Enum MyOpenFileExclusive
ExclusiveON = 0 ' Lock at open from 0 to
ExclusiveOff = 1 ' not Lock
End Enum
Public FileError As Long
Public Enum Ftypes
FnoUse = 0
Finput = 1
Foutput = 2
Fappend = 3
Frandom = 4
End Enum
Sub FileReadString(FileH As Long, R$, bytes As Long)
Dim Buf1() As Byte
If bytes <= 0 Then R$ = vbNullString: Exit Sub
If FileH = 0 Then Exit Sub
ReDim Buf1(0 To bytes - 1)
R$ = Buf1()
API_ReadFile FileH, bytes, Buf1()
CopyMemory ByVal StrPtr(R$), Buf1(0), bytes
End Sub
Sub FileReadBytes(FileH As Long, Buf1() As Byte, bytes As Long)
If bytes <= 0 Then Exit Sub
If FileH = 0 Then Exit Sub
API_ReadFile FileH, bytes, Buf1
End Sub
Sub FileWriteString(FileH As Long, R$)
Dim Buf1() As Byte, bytes As Long
If LenB(R$) = 0 Then Exit Sub
If FileH = 0 Then Exit Sub
bytes = LenB(R$)
ReDim Buf1(bytes - 1)
CopyMemory Buf1(0), ByVal StrPtr(R$), bytes
API_WriteFile FileH, bytes, Buf1()
End Sub
Sub FileWriteBytes(FileH As Long, ByRef Buf1() As Byte)
Dim bytes As Long
If PeekArray(Buf1()).Ptr = 0 Then Exit Sub
If FileH = 0 Then Exit Sub
bytes = UBound(Buf1()) - LBound(Buf1()) + 1
API_WriteFile FileH, bytes, Buf1()
End Sub
Private Function GetType(bstack As basetask, b$, p, v As Long, W$, Lang As Long, VarStat As Boolean, temphere$) As Integer
Dim ss$
If IsLabelSymbolNew(b$, "ÁÑÉÈÌÏÓ", "DECIMAL", Lang) Then
If FastSymbol(b$, "=") Then If Not IsNumberD2(b$, p) Then missNumber: Exit Function
p = CDec(p)
ElseIf IsLabelSymbolNew(b$, "ÄÉÐËÏÓ", "DOUBLE", Lang) Then
If FastSymbol(b$, "=") Then If Not IsNumberD2(b$, p) Then missNumber: Exit Function
p = CDbl(p)
ElseIf IsLabelSymbolNew(b$, "ÁÐËÏÓ", "SINGLE", Lang) Then
If FastSymbol(b$, "=") Then If Not IsNumberD2(b$, p) Then missNumber: Exit Function
p = CSng(p)
ElseIf IsLabelSymbolNew(b$, "ËÏÃÉÊÏÓ", "BOOLEAN", Lang) Then
If FastSymbol(b$, "=") Then If Not IsNumberD2(b$, p) Then missNumber: Exit Function
p = CBool(p)
ElseIf IsLabelSymbolNew(b$, "ÌÁÊÑÕÓ", "LONG", Lang) Then
If IsLabelSymbolNew(b$, "ÌÁÊÑÕÓ", "LONG", Lang) Then
If FastSymbol(b$, "=") Then If Not IsNumberD2(b$, p) Then missNumber: Exit Function
p = cInt64(p)
Else
If FastSymbol(b$, "=") Then If Not IsNumberD2(b$, p) Then missNumber: Exit Function
p = CLng(p)
End If
ElseIf IsLabelSymbolNew(b$, "ÁÊÅÑÁÉÏÓ", "INTEGER", Lang) Then
If FastSymbol(b$, "=") Then If Not IsNumberD2(b$, p) Then missNumber: Exit Function
p = CInt(p)
ElseIf IsLabelSymbolNew(b$, "ËÏÃÉÓÔÉÊÏÓ", "CURRENCY", Lang) Then
If FastSymbol(b$, "=") Then If Not IsNumberD2(b$, p) Then missNumber: Exit Function
p = CCur(p)
ElseIf IsLabelSymbolNew(b$, "ÃÑÁÌÌÁ", "STRING", Lang) Then
If FastSymbol(b$, "=") Then If Not ISSTRINGA(b$, ss$) Then MissString: Exit Function
p = vbNullString
SwapString2Variant ss$, p
ElseIf IsLabelSymbolNew(b$, "ÁÔÕÐÏÓ", "VARIANT", Lang) Then
If FastSymbol(b$, "=") Then
If Not IsNumberD2(b$, p) Then
If ISSTRINGA(b$, ss$) Then
p = vbNullString
SwapString2Variant ss$, p
Else
missNumber
Exit Function
End If
End If
End If
v = globalvar(W$, p, , VarStat, temphere$, UseType:=False)
If extreme Then GetType = 2 Else GetType = 1
Exit Function
ElseIf IsLabelSymbolNew(b$, "ØÇÖÉÏ", "BYTE", Lang) Then
If FastSymbol(b$, "=") Then If Not IsNumberD2(b$, p) Then missNumber: Exit Function
p = CByte(p)
ElseIf IsLabelSymbolNew(b$, "ÇÌÅÑÏÌÇÍÉÁ", "DATE", Lang) Then
If FastSymbol(b$, "=") Then
If Not IsNumberD2(b$, p) Then
If ISSTRINGA(b$, ss$) Then
p = vbNullString
SwapString2Variant ss$, p
Else
missNumber
Exit Function
End If
End If
End If
p = CDate(p)
ElseIf Not IsEnumAs(bstack, b$, p) Then
ExpectedEnumType
Exit Function
End If
v = globalvar(W$, p, , VarStat, temphere$)
If extreme Then GetType = 2 Else GetType = 1
End Function
' We have to provide a new file created before
' in any case
' 0 is error.
' non 0 is the filehandler from M2000 (not the real handler)
Function MyOpenFile(ByVal f$, ftype As MyOpenFileType, fexc As MyOpenFileExclusive, fstp As Long, unif As Long) As Long
If Left$(f$, 2) <> "\\" Then
f$ = "\\?\" + f$
End If
Dim FileH As Long
FileError = 511
On Error GoTo there:
Select Case ftype
Case ForInput
FileH = CreateFile(StrPtr(f$), GENERIC_READ, (FILE_SHARE_READ Or FILE_SHARE_WRITE) * fexc, ByVal 0&, OPEN_EXISTING, 0&, 0&)
Case ForOutput
FileH = CreateFile(StrPtr(f$), GENERIC_WRITE, (FILE_SHARE_READ Or FILE_SHARE_WRITE) * fexc, ByVal 0&, CREATE_ALWAYS, 0&, 0&)
Case Else
FileH = CreateFile(StrPtr(f$), GENERIC_READ Or GENERIC_WRITE, (FILE_SHARE_READ Or FILE_SHARE_WRITE) * fexc, ByVal 0&, OPEN_EXISTING, 0&, 0&)
End Select
If FileH = INVALID_HANDLE_VALUE Then
FileError = GetLastError()
If FileError = ERROR_SHARING_VIOLATION Then
MyEr "Can't open file, Not Sharing allowed" & FileError, "Äåí ìðïñþ íá áíïßîù ôï áñ÷åßï, äåí åðéôñÝðåôáé ìïßñáóìá"
Exit Function
End If
there:
MyEr "Can't open file, error :" & FileError, "Äåí ìðïñþ íá áíïßîù ôï áñ÷åßï :" & FileError
Exit Function
End If
' So now we get the filehandler as 1
MyOpenFile = BigFileHandler(CVar(FileH), ftype, fstp, unif)
Select Case ftype
Case ForOutput, ForAppend
SetFilePointer FileH, 0&, 0&, FILE_END
Case Else
SetFilePointer FileH, 0&, 0&, FILE_BEGIN
End Select
End Function
Private Function proc101(b$) As String
proc101 = vbNullString
If FastSymbol(b$, "+=", , 2) Then
proc101 = "+"
ElseIf FastSymbol(b$, "/=", , 2) Then
proc101 = "/"
ElseIf FastSymbol(b$, "-=", , 2) Then
proc101 = "-"
ElseIf FastSymbol(b$, "*=", , 2) Then
proc101 = "*"
ElseIf IsOperator0(b$, "++", 2) Then
proc101 = "++"
ElseIf IsOperator0(b$, "--", 2) Then
proc101 = "--"
ElseIf IsOperator0(b$, "-!", 2) Then
proc101 = "-!"
ElseIf IsOperator0(b$, "~") Then
proc101 = "!!"
ElseIf FastSymbol(b$, "<=", , 2) Then
proc101 = "g"
End If
End Function
Public Property Get uni(RHS) As Long
Dim H
If InUseHandlers.ExistKey(RHS) Then
H = InUseHandlers.Value
uni = H(3)
End If
End Property
Public Property Get Fstep(RHS) As Long
Dim H
If InUseHandlers.ExistKey(RHS) Then
H = InUseHandlers.Value
Fstep = H(2)
End If
End Property
Public Property Get Fkind(RHS) As Ftypes
Dim H
If InUseHandlers.ExistKey(RHS) Then
H = InUseHandlers.Value
Fkind = H(1)
End If
End Property
Public Property Let FileSeek(RHS, vvv)
Dim H, where, ret As Currency, LowLong As Long, HighLong As Long
Dim FileError As Long
ret = CCur(Int(vvv)) - 1
If InUseHandlers.ExistKey(RHS) Then
H = InUseHandlers.Value
where = H(0)
Size2Long ret, LowLong, HighLong
LowLong = SetFilePointer(where, LowLong, HighLong, FILE_BEGIN)
FileError = GetLastError()
If LowLong = INVALID_SET_FILE_POINTER And FileError <> 0 Then
MyEr "Can't write the seek value", "Äåí ìðïñþ íá ãñÜøù ôç ôéìÞ ìåôÜèåóçò"
End If
Else
MyEr "No such file handler", "Äåí õðÜñ÷åé ôÝôïéï ÷åéñéóôÞò áñ÷åßïõ"
End If
End Property
Public Property Get FileSeek(RHS) As Variant
Dim H, where, ret As Currency, LowLong As Long, HighLong As Long
FileSeek = ret
If InUseHandlers.ExistKey(RHS) Then
H = InUseHandlers.Value
where = H(0)
LowLong = 0
HighLong = 0
LowLong = SetFilePointer(where, LowLong, HighLong, FILE_CURRENT)
If LowLong = INVALID_SET_FILE_POINTER Then
MyEr "Can't read the seek value", "Äåí ìðïñþ íá äéáâÜóù ôç ôéìÞ ìåôÜèåóçò"
Else
Long2Size LowLong, HighLong, ret
FileSeek = ret + 1
End If
Else
MyEr "No such file handler", "Äåí õðÜñ÷åé ôÝôïéï ÷åéñéóôÞò áñ÷åßïõ"
End If
End Property
Public Property Let FileSeekFH(where As Long, ByVal ret As Currency)
Dim LowLong As Long, HighLong As Long
Dim FileError As Long
Size2Long ret - 1@, LowLong, HighLong
LowLong = SetFilePointer(where, LowLong, HighLong, FILE_BEGIN)
FileError = GetLastError()
If LowLong = INVALID_SET_FILE_POINTER And FileError <> 0 Then
MyEr "Can't write the seek value", "Äåí ìðïñþ íá ãñÜøù ôç ôéìÞ ìåôÜèåóçò"
End If
End Property
Public Property Get FileSeekFH(where As Long) As Currency
Dim LowLong As Long, HighLong As Long
LowLong = SetFilePointer(where, LowLong, HighLong, FILE_CURRENT)
If LowLong = INVALID_SET_FILE_POINTER Then
MyEr "Can't read the seek value", "Äåí ìðïñþ íá äéáâÜóù ôç ôéìÞ ìåôÜèåóçò"
Else
Long2Size LowLong, HighLong, FileSeekFH
FileSeekFH = FileSeekFH + 1
End If
End Property
Public Property Get FileEOFFH(where As Long) As Boolean
Dim ret As Currency, LowLong As Long, HighLong As Long
Dim fsize As Currency
LowLong = SetFilePointer(where, LowLong, HighLong, FILE_CURRENT)
If LowLong = INVALID_SET_FILE_POINTER Then
MyEr "Can't read the seek value on Eof() function", "Äåí ìðïñþ íá äéáâÜóù ôç ôéìÞ ìåôÜèåóçò óôç óõíÜñôçóç ÌåôÜèåóç()"
Else
Long2Size LowLong, HighLong, ret
LowLong = GetFileSize(where, HighLong)
Long2Size LowLong, HighLong, fsize
FileEOFFH = ret >= fsize
End If
End Property
Public Property Get FileEOF(RHS) As Boolean
Dim H, where, ret As Currency, LowLong As Long, HighLong As Long
Dim fsize As Currency
If InUseHandlers.ExistKey(RHS) Then
H = InUseHandlers.Value
where = H(0)
LowLong = SetFilePointer(where, LowLong, HighLong, FILE_BEGIN)
If LowLong = INVALID_SET_FILE_POINTER Then
MyEr "Can't read the seek value on Eof() function", "Äåí ìðïñþ íá äéáâÜóù ôç ôéìÞ ìåôÜèåóçò óôç óõíÜñôçóç ÌåôÜèåóç()"
Else
Long2Size LowLong, HighLong, ret
LowLong = GetFileSize(where, HighLong)
Long2Size LowLong, HighLong, fsize
FileEOF = ret >= fsize
End If
Else
MyEr "No such file handler", "Äåí õðÜñ÷åé ôÝôïéï ÷åéñéóôÞò áñ÷åßïõ"
End If
End Property
Public Function BigFileHandler(FH As Long, ftype As Long, fst As Long, unif As Long) As Long
Static MaxNum As Long
Dim where As Long
If FreeUseHandlers.count = 0 Then
MaxNum = MaxNum + 1
InUseHandlers.AddKey CVar(MaxNum), Array(FH, ftype, fst, unif)
InUseHandlers.sValue = FH
BigFileHandler = MaxNum
Else
FreeUseHandlers.ToEnd
where = CLng(FreeUseHandlers.KeyToNumber)
FreeUseHandlers.RemoveWithNoFind
FreeUseHandlers.Done = False
InUseHandlers.AddKey CVar(where), Array(FH, ftype, fst, unif)
InUseHandlers.sValue = FH
BigFileHandler = where
End If
End Function
'internal use
Public Function ReadFileHandler(H&) As Variant
If InUseHandlers.Find(CVar(H&)) Then
ReadFileHandler = InUseHandlers.sValue
Else
MyEr "No such file handler", "Äåí õðÜñ÷åé ôÝôïéï ÷åéñéóôÞò áñ÷åßïõ"
End If
End Function
' internal use You have to close file first
Public Sub CloseHandler(RHS)
Dim H&, ar() As Variant
On Error Resume Next
If InUseHandlers.ExistKey(RHS) Then
H& = CLng(InUseHandlers.sValue)
API_CloseFile H&
H& = InUseHandlers.KeyToNumber
InUseHandlers.RemoveWithNoFind
FreeUseHandlers.AddKey CVar(H&)
Else
' no error... (I am thinking about it)
End If
End Sub
Public Sub CloseAllHandlers()
Dim H&
On Error Resume Next
Do While InUseHandlers.count > 0
InUseHandlers.ToEnd
H& = CLng(InUseHandlers.sValue)
API_CloseFile H&
H& = InUseHandlers.KeyToNumber
InUseHandlers.RemoveWithNoFind
FreeUseHandlers.AddKey CVar(H&)
Loop
End Sub
Function myFileLen(ByVal FileName As String) As Currency
If Left$(FileName, 2) <> "\\" Then
FileName = "\\?\" + FileName
End If
Dim FileH As Long
Dim ret As Long, ok As Long
On Error Resume Next
FileH = CreateFile(StrPtr(FileName), _
FILE_READ_ATTRIBUTES, _
0, _
ByVal 0&, OPEN_EXISTING, 0&, 0&)
If Err.Number > 0 Or FileH = -1 Then
Err.Clear
there:
MyEr "Can't read the file length", "Äåí ìðïñþ íá äéáâÜóù ôï ìÞêïò ôïõ áñ÷åßïõ"
myFileLen = -1@
Else
ok = API_FileSize(FileH, myFileLen)
API_CloseFile FileH
If ok Then GoTo there ' no zero means error
End If
On Error GoTo 0
End Function
Public Sub API_OpenFile(ByVal FileName As String, ByRef FileNumber As Long, ByRef FileSize As Currency, SetPointerTo As Long)
Dim FileH As Long
Dim ret As Long, ok As Long
On Error Resume Next
FileH = CreateFile(StrPtr(FileName), GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, 0&, OPEN_ALLWAYS, 0, 0)
If Err.Number > 0 Then
Err.Clear
FileNumber = -1
Else
there:
FileNumber = FileH
ret = SetFilePointer(FileH, 0, 0, FILE_BEGIN)
API_FileSize FileH, FileSize
End If
On Error GoTo 0
End Sub
Function API_FileSize(ByVal FileNumber As Long, ByRef FileSize As Currency) As Long
Dim FileSizeL As Long
Dim FileSizeH As Long, ok As Long
FileSizeH = 0
FileSizeL = GetFileSize(FileNumber, FileSizeH)
If FileSizeL = -1& Then
ok = GetLastError
If ok Then API_FileSize = ok: Exit Function
End If
Long2Size FileSizeL, FileSizeH, FileSize
API_FileSize = 0
End Function
Public Sub API_ReadFile(ByVal FileNumber As Long, ByRef BlockSize As Long, ByRef Data() As Byte)
Dim PosL As Long
Dim PosH As Long
Dim SizeRead As Long
Dim ret As Long
ret = SetFilePointer(FileNumber, PosL, PosH, FILE_CURRENT)
ret = ReadFile(FileNumber, Data(0), BlockSize, SizeRead, 0&)
BlockSize = SizeRead
End Sub
Public Sub API_ReadBLOCK(ByVal FileNumber As Long, ByVal BlockSize As Long, ByVal Addr As Long)
Dim PosL As Long
Dim PosH As Long
Dim SizeRead As Long
Dim ret As Long
ret = SetFilePointer(FileNumber, PosL, PosH, FILE_CURRENT)
ret = ReadFile(FileNumber, ByVal Addr, BlockSize, SizeRead, 0&)
End Sub
Public Sub API_CloseFile(ByVal FileNumber As Long)
Dim ret As Long
FlushFileBuffers FileNumber
ret = CloseHandle(FileNumber)
End Sub
Public Function API_WriteFile(ByVal FileNumber As Long, ByRef BlockSize As Long, ByRef Data() As Byte) As Boolean
Dim PosL As Long
Dim PosH As Long
Dim SizeWrit As Long
Dim ret As Long
ret = SetFilePointer(FileNumber, PosL, PosH, FILE_CURRENT)
ret = WriteFile(FileNumber, Data(0), BlockSize, SizeWrit, 0&)
API_WriteFile = (BlockSize = SizeWrit)
End Function
Private Sub Size2Long(ByVal FileSize As Currency, ByRef LongLow As Long, ByRef LongHigh As Long)
Static ret As Currency
ret = FileSize / 10000@
GetMem4 VarPtr(ret), LongLow
GetMem4 VarPtr(ret) + 4, LongHigh
End Sub
Private Sub Long2Size(ByVal LongLow As Long, ByVal LongHigh As Long, ByRef FileSize As Currency)
FileSize = 0
PutMem4 VarPtr(FileSize), LongLow
PutMem4 VarPtr(FileSize) + 4, LongHigh
FileSize = FileSize * 10000@
End Sub
Public Function ApiCanonicalize(ByVal Url As String, Optional dwFlags As Long = 0) As String
Url = Left$(Url, INTERNET_MAX_URL_LENGTH)
Dim dwSize As Long, res As String
If Len(Url) > 0 Then
ApiCanonicalize = space$(INTERNET_MAX_URL_LENGTH)
dwSize = Len(ApiCanonicalize)
If UrlCanonicalizeApi(StrPtr(Url), _
StrPtr(ApiCanonicalize), _
dwSize, _
dwFlags) = 0 Then
ApiCanonicalize = Left$(ApiCanonicalize, dwSize)
Else
ApiCanonicalize = ""
End If
End If
End Function
Public Function GetUrlParts(ByVal sUrl As String, _
Optional ByVal dwPart As Long = 1, _
Optional ByVal dwFlags As Long = 0) As String
Dim sPart As String
Dim dwSize As Long
If Len(sUrl) > 0 Then
sPart = space$(INTERNET_MAX_URL_LENGTH)
dwSize = Len(sPart)
If UrlGetPart(StrPtr(sUrl), _
StrPtr(sPart), _
dwSize, _
dwPart, _
dwFlags) = 0 Then
GetUrlParts = Left$(sPart, dwSize)
End If
End If
End Function
Public Function GetUrlQuery(ByVal Address As String) As String
GetUrlQuery = GetUrlParts(UrlCanonicalize2(URLDecode(Address, True)), URL_PART_QUERY)
End Function
Public Function GetUrlPort(ByVal Address As String) As String
GetUrlPort = GetUrlParts(UrlCanonicalize2(URLDecode(Address, True)), URL_PART_PORT)
End Function
Public Function URLDecode( _
ByVal Url As String, _
Optional ByVal PlusSpace As Boolean = True, Optional flags As Long = 0) As String
Url = Left$(Url, INTERNET_MAX_URL_LENGTH)
Dim cchUnescaped As Long
Dim hResult As Long
If PlusSpace Then Url = Replace$(Url, "+", " ")
cchUnescaped = Len(Url)
URLDecode = String$(cchUnescaped, 0)
hResult = UrlUnescape(StrPtr(Url), StrPtr(URLDecode), cchUnescaped, flags)
If hResult = E_POINTER Then
URLDecode = String$(cchUnescaped, 0)
hResult = UrlUnescape(StrPtr(Url), StrPtr(URLDecode), cchUnescaped, flags)
End If
If hResult <> S_OK Then
MyEr "can't decode this url", "äåí ìðïñþ íá áðïêùäéêïðïéÞóù ôçí äéåýèõíóç"
Exit Function
End If
URLDecode = Left$(URLDecode, cchUnescaped)
End Function
Public Function URLEncode( _
ByVal Url As String, _
Optional ByVal SpacePlus As Boolean = True) As String
Url = Left$(Url, INTERNET_MAX_URL_LENGTH)
Dim cchEscaped As Long
Dim hResult As Long
If SpacePlus Then
Url = Replace$(Url, " ", "+")
End If
cchEscaped = Len(Url) * 1.5
URLEncode = String$(cchEscaped, 0)
hResult = UrlEscape(StrPtr(Url), StrPtr(URLEncode), cchEscaped, URL_ESCAPE_PERCENT + &H40000)
If hResult = E_POINTER Then
URLEncode = String$(cchEscaped, 0)
hResult = UrlEscape(StrPtr(Url), StrPtr(URLEncode), cchEscaped, URL_ESCAPE_PERCENT + &H40000)
End If
If hResult <> S_OK Then
Exit Function
End If
URLEncode = Left$(URLEncode, cchEscaped)
End Function
Public Function GetParentAddress(ByVal Address As String, Optional includeroot As Boolean = False) As String
Dim lngCharCount As Long
Dim lngBCount As Long
Dim strOutput As String
' new from me
Dim exclude As String
If includeroot Then
Address = URLDecode(Address)
Else
Address = RemoveRootName(URLDecode(Address, True), False)
End If
exclude = GetUrlParts(Address, URL_PART_QUERY)
If Len(exclude) > 0 Then
Address = Left$(Address, InStr(Address, exclude) - 2)
End If
GetParentAddress = ExtractPath(Address, False)
End Function
Private Function GetDomainName2(ByVal Address As String) As String
Dim strOutput As String
Dim strTemp As String
Dim lngLoopCount As Long
Dim lngBCount As Long
Dim lngCharCount As Long
Dim i As Long
' new from me
' Address = URLDecode(Address, True)
'
strOutput$ = Replace(Address, "\", "/")
lngCharCount = Len(strOutput)
i = InStr(1, strOutput, "/")
If i Then
If i - InStr(1, strOutput, ":") > 1 Then
Exit Function
Else
Do Until ((strTemp = "/") Or (lngLoopCount = lngCharCount))
lngLoopCount = lngLoopCount + 1
strTemp = Mid$(strOutput, lngBCount + 1, 1)
lngBCount = lngBCount + 1
Loop
End If
Else
Exit Function
End If
strOutput = Right$(strOutput, Len(strOutput) - lngBCount)
lngBCount = 0
strTemp = "/"
If (InStr(1, strOutput, "/")) Then
Do Until strTemp <> "/"
strTemp = Mid$(strOutput, lngBCount + 1, 1)
If strTemp = "/" Then lngBCount = lngBCount + 1
Loop
End If
strOutput = Right$(strOutput, Len(strOutput) - lngBCount)
If Left$(strOutput, 1) = "[" Then
lngBCount = InStr(strOutput, "]")
If lngBCount > 0 Then strOutput = Left$(strOutput, lngBCount) Else strOutput = vbNullString
GetDomainName2 = strOutput
Exit Function
ElseIf Not strOutput = vbNullString Then
If InStr(1, strOutput, "/", vbTextCompare) = 0 Then
i = InStr(1, strOutput, "@", vbTextCompare)
If i > 0 Then GoTo 500
End If
End If
On Error Resume Next
strOutput = Left$(strOutput, InStr(1, strOutput, "/", vbTextCompare) - 1)
If Err.Number > 0 Then strOutput = vbNullString
500 GetDomainName2 = strOutput
End Function
Public Function GetDomainName(ByVal Address As String, Optional userinfo As Boolean = False) As String
Dim strOutput As String
Dim strTemp As String
Dim lngLoopCount As Long
Dim lngBCount As Long
Dim lngCharCount As Long
Dim i As Long
' new from me
Address = URLDecode(Address, True)
'
strOutput$ = Replace(Address, "\", "/")
lngCharCount = Len(strOutput)
i = InStr(1, strOutput, "/")
If i Then
If i - InStr(1, strOutput, ":") > 1 Then
Exit Function
Else
Do Until ((strTemp = "/") Or (lngLoopCount = lngCharCount))
lngLoopCount = lngLoopCount + 1
strTemp = Mid$(strOutput, lngBCount + 1, 1)
lngBCount = lngBCount + 1
Loop
End If
Else
Exit Function
End If
strOutput = Right$(strOutput, Len(strOutput) - lngBCount)
lngBCount = 0
strTemp = "/"
If (InStr(1, strOutput, "/")) Then
Do Until strTemp <> "/"
strTemp = Mid$(strOutput, lngBCount + 1, 1)
If strTemp = "/" Then lngBCount = lngBCount + 1
Loop
End If
strOutput = Right$(strOutput, Len(strOutput) - lngBCount)
If Left$(strOutput, 1) = "[" Then
lngBCount = InStr(strOutput, "]")
If lngBCount > 0 Then strOutput = Left$(strOutput, lngBCount) Else strOutput = vbNullString
GetDomainName = strOutput
Exit Function
ElseIf Not strOutput = vbNullString Then
If InStr(1, strOutput, "/", vbTextCompare) = 0 Then
If Not userinfo Then
i = InStr(1, strOutput, "@", vbTextCompare)
If i > 0 Then strOutput = Mid$(strOutput, i + 1)
If Not strOutput = vbNullString Then If InStr(1, strOutput, ".", vbTextCompare) > 0 Then GoTo 500
Else
GoTo 500
End If
End If
End If
On Error Resume Next
strOutput = Left$(strOutput, InStr(1, strOutput, "/", vbTextCompare) - 1)
If Err.Number > 0 Then strOutput = vbNullString
500
GetDomainName = strOutput
End Function
Public Function GetUrlPath(ByVal Address As String) As String
Dim exclude As String, domain As String, scheme As String, W As Long
Address = URLDecode(Address, False)
scheme = GetUrlParts(Address)
domain = GetDomainName(Address, True)
exclude = GetUrlParts(Address, URL_PART_QUERY)
If Len(domain) > 0 Then
Address = UrlCanonicalize(Address)
Else 'remove scheme only
If Left$(Address, Len(scheme)) = scheme Then Address = Mid$(Address, Len(scheme) + 2)
End If
If domain <> vbNullString Then
Address = Mid$(Address, Len(domain) + 1)
ElseIf Not Address = vbNullString Then
If InStr(Address, "//") = 0 Then
If Left$(Address, Len(scheme)) = scheme Then Address = Mid$(Address, Len(scheme) + 2)
End If
End If
If Not Address = vbNullString Then
W = InStr(Address, "#")
If W > 0 Then Address = Left$(Address, W - 1)
End If
If Len(exclude) > 0 Then
Address = Left$(Address, Len(Address) - Len(exclude) - 1)
End If
GetUrlPath = Address
End Function
Private Function UrlCanonicalize2(ByVal pstrAddress As String) As String
Dim strOutput As String
Dim strTemp As String
Dim lngLoopCount As Long
Dim lngBCount As Long
Dim lngCharCount As Long
strOutput$ = Replace(pstrAddress, "\", "/")
lngCharCount = Len(strOutput)
If (InStr(1, strOutput, "/")) Then
Do Until ((strTemp = "/") Or (lngLoopCount = lngCharCount))
lngLoopCount = lngLoopCount + 1
strTemp = Mid$(strOutput, lngBCount + 1, 1)
lngBCount = lngBCount + 1
Loop
End If
strOutput = Right$(strOutput, Len(strOutput) - lngBCount)
lngBCount = 0
strTemp = "/"
If (InStr(1, strOutput, "/")) Then
Do Until (strTemp <> "/")
strTemp = Mid$(strOutput, lngBCount + 1, 1)
If strTemp = "/" Then lngBCount = lngBCount + 1
Loop
End If
strOutput = Right$(strOutput, Len(strOutput) - lngBCount)
lngBCount = 0
strTemp = "/"
lngCharCount = Len(strOutput)
If (InStr(1, strOutput, "/")) Then
Do Until (strTemp <> "/")
strTemp = Mid$(strOutput, lngCharCount - lngBCount, 1)
If strTemp = "/" Then lngBCount = lngBCount + 1
Loop
End If
UrlCanonicalize2 = Left$(strOutput, Len(strOutput) - lngBCount)
End Function
Public Function UrlCanonicalize(ByVal pstrAddress As String) As String
Dim strOutput As String
Dim strTemp As String
Dim lngLoopCount As Long
Dim lngBCount As Long
Dim lngCharCount As Long
' new from me
pstrAddress = URLDecode(pstrAddress, False)
'
strOutput$ = Replace(pstrAddress, "\", "/")
lngCharCount = Len(strOutput)
If (InStr(1, strOutput, "/")) Then
Do Until ((strTemp = "/") Or (lngLoopCount = lngCharCount))
lngLoopCount = lngLoopCount + 1
strTemp = Mid$(strOutput, lngBCount + 1, 1)
lngBCount = lngBCount + 1
Loop
End If
strOutput = Right$(strOutput, Len(strOutput) - lngBCount)
lngBCount = 0
strTemp = "/"
If (InStr(1, strOutput, "/")) Then
Do Until (strTemp <> "/")
strTemp = Mid$(strOutput, lngBCount + 1, 1)
If strTemp = "/" Then lngBCount = lngBCount + 1
Loop
End If
strOutput = Right$(strOutput, Len(strOutput) - lngBCount)
lngBCount = 0
strTemp = "/"
lngCharCount = Len(strOutput)
If (InStr(1, strOutput, "/")) Then
Do Until (strTemp <> "/")
strTemp = Mid$(strOutput, lngCharCount - lngBCount, 1)
If strTemp = "/" Then lngBCount = lngBCount + 1
Loop
End If
strOutput = Left$(strOutput, Len(strOutput) - lngBCount)
' strOutput = Replace(strOutput, "%20", " ") ' not used more
UrlCanonicalize = strOutput
End Function
' we can use PurifyName()
'Public Function RemoveIllegals(ByVal pstrCheckString As String) As String
'End Function
Public Function GetHost(Url$) As String
Dim W As Long
GetHost = GetDomainName(Url$, True)
If GetHost <> vbNullString Then
If Left$(GetHost, 1) <> "[" Then
W = InStr(GetHost, "@")
If W > 0 Then GetHost = Mid$(GetHost, W + 1)
If GetHost <> vbNullString Then
W = InStr(GetHost, ":")
If W > 0 Then GetHost = Left$(GetHost, W - 1)
End If
Else
W = InStr(GetHost, "]")
GetHost = Mid$(GetHost, 2, W - 2)
End If
End If
End Function
Public Function RemoveRootName(ByVal pstrPath As String, _
ByVal pblnGetLowestLevelName As Boolean) _
As String
Dim strOutput As String
Dim lngLoopCount As Long
Dim lngBCount As Long
Dim lngCharCount As Long
Dim strTemp As String
' new from me
pstrPath = URLDecode(pstrPath, True)
'
strOutput = Replace(pstrPath, "\", "/")
lngCharCount = Len(strOutput)
If (InStr(1, strOutput, "/")) Then
Do Until ((strTemp = "/") Or (lngLoopCount = lngCharCount))
lngLoopCount = lngLoopCount + 1
strTemp = Mid$(strOutput, lngBCount + 1, 1)
lngBCount = lngBCount + 1
Loop
End If
strOutput = Right$(strOutput, Len(strOutput) - lngBCount)
lngBCount = 0
strTemp = "/"
If (InStr(1, strOutput, "/")) Then
Do Until (strTemp <> "/")
strTemp = Mid$(strOutput, lngBCount + 1, 1)
If strTemp = "/" Then lngBCount = lngBCount + 1
Loop
End If
strOutput = Right$(strOutput, Len(strOutput) - lngBCount)
lngBCount = 0
strTemp = "/"
lngCharCount = Len(strOutput)
If (InStr(1, strOutput, "/")) Then
Do Until (strTemp <> "/")
strTemp = Mid$(strOutput, lngCharCount - lngBCount, 1)
If strTemp = "/" Then lngBCount = lngBCount + 1
Loop
End If
strOutput = Left$(strOutput, Len(strOutput) - lngBCount)
strOutput = Right$(strOutput, Len(strOutput) - InStr(1, strOutput, "/", vbTextCompare))
If (pblnGetLowestLevelName) Then _
strOutput = Right$(strOutput, Len(strOutput) - InStrRev(strOutput, "/"))
'strOutput = Replace(strOutput, "%20", " ")
RemoveRootName = strOutput
End Function
' ExpEnvirStr(string) as string exist
Public Function URLEncodeEsc(cc As String, Optional space_as_plus As Boolean = False, Optional typedata As Long = 0) As String
cc = StrConv(utf8encode(cc), vbUnicode)
Dim slen As Long, m$: slen = Len(cc)
Dim i As Long
If slen > 0 Then
ReDim res(slen) As String
Dim ccode As Byte
Dim cp1, cp2, cp3 As Integer
Dim space As String