-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJclFileUtils.pas
More file actions
7069 lines (6472 loc) · 211 KB
/
Copy pathJclFileUtils.pas
File metadata and controls
7069 lines (6472 loc) · 211 KB
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
{**************************************************************************************************}
{ }
{ Project JEDI Code Library (JCL) }
{ }
{ The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); }
{ you may not use this file except in compliance with the License. You may obtain a copy of the }
{ License at http://www.mozilla.org/MPL/ }
{ }
{ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF }
{ ANY KIND, either express or implied. See the License for the specific language governing rights }
{ and limitations under the License. }
{ }
{ The Original Code is JclFileUtils.pas. }
{ }
{ The Initial Developer of the Original Code is Marcel van Brakel. }
{ Portions created by Marcel van Brakel are Copyright (C) Marcel van Brakel. All rights reserved. }
{ }
{ Contributors: }
{ Andre Snepvangers (asnepvangers) }
{ Andreas Hausladen (ahuser) }
{ Anthony Steele }
{ Rik Barker (rikbarker) }
{ Azret Botash }
{ Charlie Calvert }
{ David Hervieux }
{ Florent Ouchet (outchy) }
{ Jean-Fabien Connault (cycocrew) }
{ Jens Fudickar (jfudickar) }
{ JohnML }
{ John Molyneux }
{ Marcel Bestebroer }
{ Marcel van Brakel }
{ Massimo Maria Ghisalberti }
{ Matthias Thoma (mthoma) }
{ Olivier Sannier (obones) }
{ Pelle F. S. Liljendal }
{ Robert Marquardt (marquardt) }
{ Robert Rossmair (rrossmair) }
{ Rudy Velthuis }
{ Scott Price }
{ Wim De Cleen }
{ }
{**************************************************************************************************}
{ }
{ This unit contains routines and classes for working with files, directories and path strings. }
{ Additionally it contains wrapper classes for file mapping objects and version resources. }
{ Generically speaking, everything that has to do with files and directories. Note that filesystem }
{ specific functionality has been extracted into external units, for example JclNTFS which }
{ contains NTFS specific utility routines, and that the JclShell unit contains some file related }
{ routines as well but they are specific to the Windows shell. }
{ }
{**************************************************************************************************}
{ }
{ Last modified: $Date:: $ }
{ Revision: $Rev:: $ }
{ Author: $Author:: $ }
{ }
{**************************************************************************************************}
unit JclFileUtils;
{$I jcl.inc}
{$I crossplatform.inc}
interface
uses
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
{$IFDEF HAS_UNIT_LIBC}
Libc,
{$ENDIF HAS_UNIT_LIBC}
{$IFDEF HAS_UNITSCOPE}
{$IFDEF MSWINDOWS}
Winapi.Windows, JclWin32,
{$ENDIF MSWINDOWS}
System.Classes, System.SysUtils,
{$ELSE ~HAS_UNITSCOPE}
{$IFDEF MSWINDOWS}
Windows, JclWin32,
{$ENDIF MSWINDOWS}
Classes, SysUtils,
{$ENDIF ~HAS_UNITSCOPE}
JclBase, JclSysUtils;
// Path Manipulation
//
// Various support routines for working with path strings. For example, building a path from
// elements or extracting the elements from a path, interpretation of paths and transformations of
// paths.
const
{$IFDEF UNIX}
// renamed to DirDelimiter
// PathSeparator = '/';
DirDelimiter = '/';
DirSeparator = ':';
{$ENDIF UNIX}
{$IFDEF MSWINDOWS}
PathDevicePrefix = '\\.\';
// renamed to DirDelimiter
// PathSeparator = '\';
DirDelimiter = '\';
DirSeparator = ';';
PathUncPrefix = '\\';
{$ENDIF MSWINDOWS}
faSymLink = $00000040 {$IFDEF SUPPORTS_PLATFORM} platform {$ENDIF}; // defined since D7
faNormalFile = $00000080;
faTemporary = $00000100 {$IFDEF SUPPORTS_PLATFORM} platform {$ENDIF};
faSparseFile = $00000200 {$IFDEF SUPPORTS_PLATFORM} platform {$ENDIF};
faReparsePoint = $00000400 {$IFDEF SUPPORTS_PLATFORM} platform {$ENDIF};
faCompressed = $00000800 {$IFDEF SUPPORTS_PLATFORM} platform {$ENDIF};
faOffline = $00001000 {$IFDEF SUPPORTS_PLATFORM} platform {$ENDIF};
faNotContentIndexed = $00002000 {$IFDEF SUPPORTS_PLATFORM} platform {$ENDIF};
faEncrypted = $00004000 {$IFDEF SUPPORTS_PLATFORM} platform {$ENDIF};
// Note: faVolumeID is potentially dangerous and its usage has been discontinued
// Please see QC report 6003 for details, available online at this URL:
// http://qc.embarcadero.com/wc/qcmain.aspx?d=6003
faRejectedByDefault = faHidden + faSysFile + faDirectory;
faWindowsSpecific = faArchive + faTemporary + faSparseFile + faReparsePoint +
faCompressed + faOffline + faNotContentIndexed + faEncrypted;
faUnixSpecific = faSymLink;
type
TCompactPath = ({cpBegin, }cpCenter, cpEnd);
function CharIsDriveLetter(const C: char): Boolean;
function CharIsInvalidFileNameCharacter(const C: Char): Boolean;
function CharIsInvalidPathCharacter(const C: Char): Boolean;
function PathAddSeparator(const Path: string): string;
function PathAddExtension(const Path, Extension: string): string;
function PathAppend(const Path, Append: string): string;
function PathBuildRoot(const Drive: Byte): string;
function PathCanonicalize(const Path: string): string;
function PathCommonPrefix(const Path1, Path2: string): Integer;
{$IFDEF MSWINDOWS}
function PathCompactPath(const DC: HDC; const Path: string; const Width: Integer;
CmpFmt: TCompactPath): string;
{$ENDIF MSWINDOWS}
procedure PathExtractElements(const Source: string; var Drive, Path, FileName, Ext: string);
function PathExtractFileDirFixed(const S: string): string;
function PathExtractFileNameNoExt(const Path: string): string;
function PathExtractPathDepth(const Path: string; Depth: Integer): string;
function PathGetDepth(const Path: string): Integer;
{$IFDEF MSWINDOWS}
function PathGetLongName(const Path: string): string;
function PathGetShortName(const Path: string): string;
{$ENDIF MSWINDOWS}
function PathGetRelativePath(Origin, Destination: string): string;
function PathGetTempPath: string;
function PathIsAbsolute(const Path: string): Boolean;
function PathIsChild(const Path, Base: string): Boolean;
function PathIsEqualOrChild(const Path, Base: string): Boolean;
function PathIsDiskDevice(const Path: string): Boolean;
function PathIsUNC(const Path: string): Boolean;
function PathRemoveSeparator(const Path: string): string;
function PathRemoveExtension(const Path: string): string;
// Windows Vista uses localized path names in the Windows Explorer but these
// folders do not really exist on disk. This causes all I/O operations to fail
// if the user specifies such a localized directory like "C:\Benutzer\MyName\Bilder"
// instead of the physical folder "C:\Users\MyName\Pictures".
// These two functions allow to convert the user's input from localized to
// physical paths and vice versa.
function PathGetPhysicalPath(const LocalizedPath: string): string;
function PathGetLocalizedPath(const PhysicalPath: string): string;
// Files and Directories
//
// Routines for working with files and directories. Includes routines to extract various file
// attributes or update them, volume locking and routines for creating temporary files.
type
TDelTreeProgress = function (const FileName: string; Attr: DWORD): Boolean;
TFileListOption = (flFullNames, flRecursive, flMaskedSubfolders);
TFileListOptions = set of TFileListOption;
TJclAttributeMatch = (amAny, amExact, amSubSetOf, amSuperSetOf, amCustom);
TFileMatchFunc = function(const Attr: Integer; const FileInfo: TSearchRec): Boolean;
TFileHandler = procedure (const FileName: string) of object;
TFileHandlerEx = procedure (const Directory: string; const FileInfo: TSearchRec) of object;
TFileInfoHandlerEx = procedure (const FileInfo: TSearchRec) of object;
function BuildFileList(const Path: string; const Attr: Integer; const List: TStrings; IncludeDirectoryName: Boolean =
False): Boolean;
function AdvBuildFileList(const Path: string; const Attr: Integer; const Files: TStrings;
const AttributeMatch: TJclAttributeMatch = amSuperSetOf; const Options: TFileListOptions = [];
const SubfoldersMask: string = ''; const FileMatchFunc: TFileMatchFunc = nil): Boolean;
function VerifyFileAttributeMask(var RejectedAttributes, RequiredAttributes: Integer): Boolean;
function IsFileAttributeMatch(FileAttributes, RejectedAttributes,
RequiredAttributes: Integer): Boolean;
function FileAttributesStr(const FileInfo: TSearchRec): string;
function IsFileNameMatch(FileName: string; const Mask: string;
const CaseSensitive: Boolean = {$IFDEF MSWINDOWS} False {$ELSE} True {$ENDIF}): Boolean;
procedure EnumFiles(const Path: string; HandleFile: TFileHandlerEx;
RejectedAttributes: Integer = faRejectedByDefault; RequiredAttributes: Integer = 0;
Abort: PBoolean = nil); overload;
procedure EnumFiles(const Path: string; HandleFile: TFileInfoHandlerEx;
RejectedAttributes: Integer = faRejectedByDefault; RequiredAttributes: Integer = 0;
Abort: PBoolean = nil); overload;
procedure EnumDirectories(const Root: string; const HandleDirectory: TFileHandler;
const IncludeHiddenDirectories: Boolean = False; const SubDirectoriesMask: string = '';
Abort: PBoolean = nil {$IFDEF UNIX}; ResolveSymLinks: Boolean = True {$ENDIF});
{$IFDEF MSWINDOWS}
procedure CreateEmptyFile(const FileName: string);
function CloseVolume(var Volume: THandle): Boolean;
{$IFNDEF FPC}
function DeleteDirectory(const DirectoryName: string; MoveToRecycleBin: Boolean): Boolean;
function CopyDirectory(ExistingDirectoryName, NewDirectoryName: string): Boolean;
function MoveDirectory(ExistingDirectoryName, NewDirectoryName: string): Boolean;
{$ENDIF ~FPC}
function DelTree(const Path: string): Boolean;
function DelTreeEx(const Path: string; AbortOnFailure: Boolean; Progress: TDelTreeProgress): Boolean;
function DiskInDrive(Drive: Char): Boolean;
{$ENDIF MSWINDOWS}
function DirectoryExists(const Name: string {$IFDEF UNIX}; ResolveSymLinks: Boolean = True {$ENDIF}): Boolean;
function FileCreateTemp(var Prefix: string): THandle;
function FileBackup(const FileName: string; Move: Boolean = False): Boolean;
function FileCopy(const ExistingFileName, NewFileName: string; ReplaceExisting: Boolean = False): Boolean;
function FileDateTime(const FileName: string): TDateTime;
function FileDelete(const FileName: string; MoveToRecycleBin: Boolean = False): Boolean;
function FileExists(const FileName: string): Boolean;
/// <summary>procedure FileHistory Creates a list of history files of a specified
/// source file. Each version of the file get's an extention .~<Nr>~ The file with
/// the lowest number is the youngest file.
/// </summary>
/// <param name="FileName"> (string) Name of the source file</param>
/// <param name="HistoryPath"> (string) Folder where the history files should be
/// created. If no folder is defined the folder of the source file is used.</param>
/// <param name="MaxHistoryCount"> (Integer) Max number of files</param>
/// <param name="MinFileDate"> (TDateTime) Timestamp how old the file has to be to
/// create a new history version. For example: NOW-1/24 => Only once per hour a new
/// history file is created. Default 0 means allways
/// <param name="ReplaceExtention"> (boolean) Flag to define that the history file
/// extention should replace the current extention or should be added at the
/// end</param>
/// </param>
procedure FileHistory(const FileName: string; HistoryPath: string = ''; MaxHistoryCount: Integer = 100; MinFileDate:
TDateTime = 0; ReplaceExtention: Boolean = true);
function FileMove(const ExistingFileName, NewFileName: string; ReplaceExisting: Boolean = False): Boolean;
function FileRestore(const FileName: string): Boolean;
function GetBackupFileName(const FileName: string): string;
function IsBackupFileName(const FileName: string): Boolean;
function FileGetDisplayName(const FileName: string): string;
function FileGetGroupName(const FileName: string {$IFDEF UNIX}; ResolveSymLinks: Boolean = True {$ENDIF}): string;
function FileGetOwnerName(const FileName: string {$IFDEF UNIX}; ResolveSymLinks: Boolean = True {$ENDIF}): string;
function FileGetSize(const FileName: string): Int64;
function FileGetTempName(const Prefix: string): string;
{$IFDEF MSWINDOWS}
function FileGetTypeName(const FileName: string): string;
{$ENDIF MSWINDOWS}
function FindUnusedFileName(FileName: string; const FileExt: string; NumberPrefix: string = ''): string;
function ForceDirectories(Name: string): Boolean;
function GetDirectorySize(const Path: string): Int64;
{$IFDEF MSWINDOWS}
function GetDriveTypeStr(const Drive: Char): string;
function GetFileAgeCoherence(const FileName: string): Boolean;
{$ENDIF MSWINDOWS}
procedure GetFileAttributeList(const Items: TStrings; const Attr: Integer);
{$IFDEF MSWINDOWS}
procedure GetFileAttributeListEx(const Items: TStrings; const Attr: Integer);
{$ENDIF MSWINDOWS}
function GetFileInformation(const FileName: string; out FileInfo: TSearchRec): Boolean; overload;
function GetFileInformation(const FileName: string): TSearchRec; overload;
{$IFDEF UNIX}
function GetFileStatus(const FileName: string; out StatBuf: TStatBuf64;
const ResolveSymLinks: Boolean): Integer;
{$ENDIF UNIX}
{$IFDEF MSWINDOWS}
function GetFileLastWrite(const FileName: string): TFileTime; overload;
function GetFileLastWrite(const FileName: string; out LocalTime: TDateTime): Boolean; overload;
function GetFileLastAccess(const FileName: string): TFileTime; overload;
function GetFileLastAccess(const FileName: string; out LocalTime: TDateTime): Boolean; overload;
function GetFileCreation(const FileName: string): TFileTime; overload;
function GetFileCreation(const FileName: string; out LocalTime: TDateTime): Boolean; overload;
{$ENDIF MSWINDOWS}
{$IFDEF UNIX}
function GetFileLastWrite(const FileName: string; out TimeStamp: Integer; ResolveSymLinks: Boolean = True): Boolean; overload;
function GetFileLastWrite(const FileName: string; out LocalTime: TDateTime; ResolveSymLinks: Boolean = True): Boolean; overload;
function GetFileLastWrite(const FileName: string; ResolveSymLinks: Boolean = True): Integer; overload;
function GetFileLastAccess(const FileName: string; out TimeStamp: Integer; ResolveSymLinks: Boolean = True): Boolean; overload;
function GetFileLastAccess(const FileName: string; out LocalTime: TDateTime; ResolveSymLinks: Boolean = True): Boolean; overload;
function GetFileLastAccess(const FileName: string; ResolveSymLinks: Boolean = True): Integer; overload;
function GetFileLastAttrChange(const FileName: string; out TimeStamp: Integer; ResolveSymLinks: Boolean = True): Boolean; overload;
function GetFileLastAttrChange(const FileName: string; out LocalTime: TDateTime; ResolveSymLinks: Boolean = True): Boolean; overload;
function GetFileLastAttrChange(const FileName: string; ResolveSymLinks: Boolean = True): Integer; overload;
{$ENDIF UNIX}
function GetModulePath(const Module: HMODULE): string;
function GetSizeOfFile(const FileName: string): Int64; overload;
function GetSizeOfFile(const FileInfo: TSearchRec): Int64; overload;
{$IFDEF MSWINDOWS}
function GetSizeOfFile(Handle: THandle): Int64; overload;
function GetStandardFileInfo(const FileName: string): TWin32FileAttributeData;
{$ENDIF MSWINDOWS}
function IsDirectory(const FileName: string {$IFDEF UNIX}; ResolveSymLinks: Boolean = True {$ENDIF}): Boolean;
function IsRootDirectory(const CanonicFileName: string): Boolean;
{$IFDEF MSWINDOWS}
function LockVolume(const Volume: string; var Handle: THandle): Boolean;
function OpenVolume(const Drive: Char): THandle;
function SetDirLastWrite(const DirName: string; const DateTime: TDateTime; RequireBackupRestorePrivileges: Boolean = True): Boolean;
function SetDirLastAccess(const DirName: string; const DateTime: TDateTime; RequireBackupRestorePrivileges: Boolean = True): Boolean;
function SetDirCreation(const DirName: string; const DateTime: TDateTime; RequireBackupRestorePrivileges: Boolean = True): Boolean;
{$ENDIF MSWINDOWS}
function SetFileLastWrite(const FileName: string; const DateTime: TDateTime): Boolean;
function SetFileLastAccess(const FileName: string; const DateTime: TDateTime): Boolean;
{$IFDEF MSWINDOWS}
function SetFileCreation(const FileName: string; const DateTime: TDateTime): Boolean;
procedure ShredFile(const FileName: string; Times: Integer = 1);
function UnlockVolume(var Handle: THandle): Boolean;
{$ENDIF MSWINDOWS}
{$IFDEF UNIX}
function CreateSymbolicLink(const Name, Target: string): Boolean;
{ This function gets the value of the symbolic link filename. }
function SymbolicLinkTarget(const Name: string): string;
{$ENDIF UNIX}
// TJclFileAttributeMask
//
// File search helper class, allows to specify required/rejected attributes
type
TAttributeInterest = (aiIgnored, aiRejected, aiRequired);
TJclCustomFileAttrMask = class(TPersistent)
private
FRequiredAttr: Integer;
FRejectedAttr: Integer;
function GetAttr(Index: Integer): TAttributeInterest;
procedure SetAttr(Index: Integer; const Value: TAttributeInterest);
procedure ReadRequiredAttributes(Reader: TReader);
procedure ReadRejectedAttributes(Reader: TReader);
procedure WriteRequiredAttributes(Writer: TWriter);
procedure WriteRejectedAttributes(Writer: TWriter);
protected
procedure DefineProperties(Filer: TFiler); override;
property ReadOnly: TAttributeInterest index faReadOnly
read GetAttr write SetAttr stored False;
property Hidden: TAttributeInterest index faHidden
read GetAttr write SetAttr stored False;
property System: TAttributeInterest index faSysFile
read GetAttr write SetAttr stored False;
property Directory: TAttributeInterest index faDirectory
read GetAttr write SetAttr stored False;
property SymLink: TAttributeInterest index faSymLink
read GetAttr write SetAttr stored False;
property Normal: TAttributeInterest index faNormalFile
read GetAttr write SetAttr stored False;
property Archive: TAttributeInterest index faArchive
read GetAttr write SetAttr stored False;
property Temporary: TAttributeInterest index faTemporary
read GetAttr write SetAttr stored False;
property SparseFile: TAttributeInterest index faSparseFile
read GetAttr write SetAttr stored False;
property ReparsePoint: TAttributeInterest index faReparsePoint
read GetAttr write SetAttr stored False;
property Compressed: TAttributeInterest index faCompressed
read GetAttr write SetAttr stored False;
property OffLine: TAttributeInterest index faOffline
read GetAttr write SetAttr stored False;
property NotContentIndexed: TAttributeInterest index faNotContentIndexed
read GetAttr write SetAttr stored False;
property Encrypted: TAttributeInterest index faEncrypted
read GetAttr write SetAttr stored False;
public
constructor Create;
procedure Assign(Source: TPersistent); override;
procedure Clear;
function Match(FileAttributes: Integer): Boolean; overload;
function Match(const FileInfo: TSearchRec): Boolean; overload;
property Required: Integer read FRequiredAttr write FRequiredAttr;
property Rejected: Integer read FRejectedAttr write FRejectedAttr;
property Attribute[Index: Integer]: TAttributeInterest read GetAttr write SetAttr; default;
end;
TJclFileAttributeMask = class(TJclCustomFileAttrMask)
private
procedure ReadVolumeID(Reader: TReader);
protected
procedure DefineProperties(Filer: TFiler); override;
published
property ReadOnly;
property Hidden;
property System;
property Directory;
property Normal;
{$IFDEF UNIX}
property SymLink;
{$ENDIF UNIX}
{$IFDEF MSWINDOWS}
property Archive;
property Temporary;
property SparseFile;
property ReparsePoint;
property Compressed;
property OffLine;
property NotContentIndexed;
property Encrypted;
{$ENDIF MSWINDOWS}
end;
type
TFileSearchOption = (fsIncludeSubDirectories, fsIncludeHiddenSubDirectories, fsLastChangeAfter,
fsLastChangeBefore, fsMaxSize, fsMinSize);
TFileSearchOptions = set of TFileSearchOption;
TFileSearchTaskID = Integer;
TFileSearchTerminationEvent = procedure (const ID: TFileSearchTaskID; const Aborted: Boolean) of object;
TFileEnumeratorSyncMode = (smPerFile, smPerDirectory);
// IJclFileSearchOptions
//
// Interface for file search options
type
IJclFileSearchOptions = interface
['{B73D9E3D-34C5-4DA9-88EF-4CA730328FC9}']
function GetAttributeMask: TJclFileAttributeMask;
function GetCaseSensitiveSearch: Boolean;
function GetRootDirectories: TStrings;
function GetRootDirectory: string;
function GetFileMask: string;
function GetFileMasks: TStrings;
function GetFileSizeMax: Int64;
function GetFileSizeMin: Int64;
function GetIncludeSubDirectories: Boolean;
function GetIncludeHiddenSubDirectories: Boolean;
function GetLastChangeAfter: TDateTime;
function GetLastChangeBefore: TDateTime;
function GetLastChangeAfterStr: string;
function GetLastChangeBeforeStr: string;
function GetSubDirectoryMask: string;
function GetOption(const Option: TFileSearchOption): Boolean;
function GetOptions: TFileSearchoptions;
procedure SetAttributeMask(const Value: TJclFileAttributeMask);
procedure SetCaseSensitiveSearch(const Value: Boolean);
procedure SetRootDirectories(const Value: TStrings);
procedure SetRootDirectory(const Value: string);
procedure SetFileMask(const Value: string);
procedure SetFileMasks(const Value: TStrings);
procedure SetFileSizeMax(const Value: Int64);
procedure SetFileSizeMin(const Value: Int64);
procedure SetIncludeSubDirectories(const Value: Boolean);
procedure SetIncludeHiddenSubDirectories(const Value: Boolean);
procedure SetLastChangeAfter(const Value: TDateTime);
procedure SetLastChangeBefore(const Value: TDateTime);
procedure SetLastChangeAfterStr(const Value: string);
procedure SetLastChangeBeforeStr(const Value: string);
procedure SetOption(const Option: TFileSearchOption; const Value: Boolean);
procedure SetOptions(const Value: TFileSearchOptions);
procedure SetSubDirectoryMask(const Value: string);
// properties
property CaseSensitiveSearch: Boolean read GetCaseSensitiveSearch write SetCaseSensitiveSearch;
property RootDirectories: TStrings read GetRootDirectories write SetRootDirectories;
property RootDirectory: string read GetRootDirectory write SetRootDirectory;
property FileMask: string read GetFileMask write SetFileMask;
property SubDirectoryMask: string read GetSubDirectoryMask write SetSubDirectoryMask;
property AttributeMask: TJclFileAttributeMask read GetAttributeMask write SetAttributeMask;
property FileSizeMin: Int64 read GetFileSizeMin write SetFileSizeMin;
property FileSizeMax: Int64 read GetFileSizeMax write SetFileSizeMax; // default InvalidFileSize;
property LastChangeAfter: TDateTime read GetLastChangeAfter write SetLastChangeAfter;
property LastChangeBefore: TDateTime read GetLastChangeBefore write SetLastChangeBefore;
property LastChangeAfterAsString: string read GetLastChangeAfterStr write SetLastChangeAfterStr;
property LastChangeBeforeAsString: string read GetLastChangeBeforeStr write SetLastChangeBeforeStr;
property IncludeSubDirectories: Boolean read GetIncludeSubDirectories
write SetIncludeSubDirectories;
property IncludeHiddenSubDirectories: Boolean read GetIncludeHiddenSubDirectories
write SetIncludeHiddenSubDirectories;
end;
// IJclFileSearchOptions
//
// Interface for file search options
type
TJclFileSearchOptions = class(TJclInterfacedPersistent, IJclFileSearchOptions)
protected
FFileMasks: TStringList;
FRootDirectories: TStringList;
FSubDirectoryMask: string;
FAttributeMask: TJclFileAttributeMask;
FFileSizeMin: Int64;
FFileSizeMax: Int64;
FLastChangeBefore: TDateTime;
FLastChangeAfter: TDateTime;
FOptions: TFileSearchOptions;
FCaseSensitiveSearch: Boolean;
function IsLastChangeAfterStored: Boolean;
function IsLastChangeBeforeStored: Boolean;
public
constructor Create;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
{ IJclFileSearchOptions }
function GetAttributeMask: TJclFileAttributeMask;
function GetCaseSensitiveSearch: Boolean;
function GetRootDirectories: TStrings;
function GetRootDirectory: string;
function GetFileMask: string;
function GetFileMasks: TStrings;
function GetFileSizeMax: Int64;
function GetFileSizeMin: Int64;
function GetIncludeSubDirectories: Boolean;
function GetIncludeHiddenSubDirectories: Boolean;
function GetLastChangeAfter: TDateTime;
function GetLastChangeBefore: TDateTime;
function GetLastChangeAfterStr: string;
function GetLastChangeBeforeStr: string;
function GetSubDirectoryMask: string;
function GetOption(const Option: TFileSearchOption): Boolean;
function GetOptions: TFileSearchoptions;
procedure SetAttributeMask(const Value: TJclFileAttributeMask);
procedure SetCaseSensitiveSearch(const Value: Boolean);
procedure SetRootDirectories(const Value: TStrings);
procedure SetRootDirectory(const Value: string);
procedure SetFileMask(const Value: string);
procedure SetFileMasks(const Value: TStrings);
procedure SetFileSizeMax(const Value: Int64);
procedure SetFileSizeMin(const Value: Int64);
procedure SetIncludeSubDirectories(const Value: Boolean);
procedure SetIncludeHiddenSubDirectories(const Value: Boolean);
procedure SetLastChangeAfter(const Value: TDateTime);
procedure SetLastChangeBefore(const Value: TDateTime);
procedure SetLastChangeAfterStr(const Value: string);
procedure SetLastChangeBeforeStr(const Value: string);
procedure SetOption(const Option: TFileSearchOption; const Value: Boolean);
procedure SetOptions(const Value: TFileSearchOptions);
procedure SetSubDirectoryMask(const Value: string);
published
property CaseSensitiveSearch: Boolean read GetCaseSensitiveSearch write SetCaseSensitiveSearch
default {$IFDEF MSWINDOWS} False {$ELSE} True {$ENDIF};
property FileMasks: TStrings read GetFileMasks write SetFileMasks;
property RootDirectories: TStrings read GetRootDirectories write SetRootDirectories;
property RootDirectory: string read GetRootDirectory write SetRootDirectory;
property SubDirectoryMask: string read FSubDirectoryMask write FSubDirectoryMask;
property AttributeMask: TJclFileAttributeMask read FAttributeMask write SetAttributeMask;
property FileSizeMin: Int64 read FFileSizeMin write FFileSizeMin;
property FileSizeMax: Int64 read FFileSizeMax write FFileSizeMax;
property LastChangeAfter: TDateTime read FLastChangeAfter write FLastChangeAfter
stored IsLastChangeAfterStored;
property LastChangeBefore: TDateTime read FLastChangeBefore write FLastChangeBefore
stored IsLastChangeBeforeStored;
property Options: TFileSearchOptions read FOptions write FOptions
default [fsIncludeSubDirectories];
end;
// IJclFileEnumerator
//
// Interface for thread-based file search
type
IJclFileEnumerator = interface(IJclFileSearchOptions)
['{F7E747ED-1C41-441F-B25B-BB314E00C4E9}']
// property access methods
function GetRunningTasks: Integer;
function GetSynchronizationMode: TFileEnumeratorSyncMode;
function GetOnEnterDirectory: TFileHandler;
function GetOnTerminateTask: TFileSearchTerminationEvent;
procedure SetSynchronizationMode(const Value: TFileEnumeratorSyncMode);
procedure SetOnEnterDirectory(const Value: TFileHandler);
procedure SetOnTerminateTask(const Value: TFileSearchTerminationEvent);
// other methods
function FillList(List: TStrings): TFileSearchTaskID;
function ForEach(Handler: TFileHandler): TFileSearchTaskID; overload;
function ForEach(Handler: TFileHandlerEx): TFileSearchTaskID; overload;
procedure StopTask(ID: TFileSearchTaskID);
procedure StopAllTasks(Silently: Boolean = False); // Silently: Don't call OnTerminateTask
// properties
property RunningTasks: Integer read GetRunningTasks;
property SynchronizationMode: TFileEnumeratorSyncMode read GetSynchronizationMode
write SetSynchronizationMode;
property OnEnterDirectory: TFileHandler read GetOnEnterDirectory write SetOnEnterDirectory;
property OnTerminateTask: TFileSearchTerminationEvent read GetOnTerminateTask
write SetOnTerminateTask;
end;
// TJclFileEnumerator
//
// Class for thread-based file search
type
TJclFileEnumerator = class(TJclFileSearchOptions, IInterface, IJclFileSearchOptions, IJclFileEnumerator)
private
FTasks: TList;
FOnEnterDirectory: TFileHandler;
FOnTerminateTask: TFileSearchTerminationEvent;
FNextTaskID: TFileSearchTaskID;
FSynchronizationMode: TFileEnumeratorSyncMode;
function GetNextTaskID: TFileSearchTaskID;
protected
function CreateTask: TThread;
procedure TaskTerminated(Sender: TObject);
property NextTaskID: TFileSearchTaskID read GetNextTaskID;
public
constructor Create;
destructor Destroy; override;
{ IJclFileEnumerator }
function GetRunningTasks: Integer;
function GetSynchronizationMode: TFileEnumeratorSyncMode;
function GetOnEnterDirectory: TFileHandler;
function GetOnTerminateTask: TFileSearchTerminationEvent;
procedure SetSynchronizationMode(const Value: TFileEnumeratorSyncMode);
procedure SetOnEnterDirectory(const Value: TFileHandler);
procedure SetOnTerminateTask(const Value: TFileSearchTerminationEvent);
procedure Assign(Source: TPersistent); override;
function FillList(List: TStrings): TFileSearchTaskID;
function ForEach(Handler: TFileHandler): TFileSearchTaskID; overload;
function ForEach(Handler: TFileHandlerEx): TFileSearchTaskID; overload;
procedure StopTask(ID: TFileSearchTaskID);
procedure StopAllTasks(Silently: Boolean = False); // Silently: Don't call OnTerminateTask
property FileMask: string read GetFileMask write SetFileMask;
property IncludeSubDirectories: Boolean
read GetIncludeSubDirectories write SetIncludeSubDirectories;
property IncludeHiddenSubDirectories: Boolean
read GetIncludeHiddenSubDirectories write SetIncludeHiddenSubDirectories;
property SearchOption[const Option: TFileSearchOption]: Boolean read GetOption write SetOption;
property LastChangeAfterAsString: string read GetLastChangeAfterStr write SetLastChangeAfterStr;
property LastChangeBeforeAsString: string read GetLastChangeBeforeStr write SetLastChangeBeforeStr;
published
property RunningTasks: Integer read GetRunningTasks;
property SynchronizationMode: TFileEnumeratorSyncMode read FSynchronizationMode write FSynchronizationMode
default smPerDirectory;
property OnEnterDirectory: TFileHandler read FOnEnterDirectory write FOnEnterDirectory;
property OnTerminateTask: TFileSearchTerminationEvent read FOnTerminateTask write FOnTerminateTask;
end;
function FileSearch: IJclFileEnumerator;
{$IFDEF MSWINDOWS}
// TFileVersionInfo
//
// Class that enables reading the version information stored in a PE file.
type
TFileFlag = (ffDebug, ffInfoInferred, ffPatched, ffPreRelease, ffPrivateBuild, ffSpecialBuild);
TFileFlags = set of TFileFlag;
PLangIdRec = ^TLangIdRec;
TLangIdRec = packed record
case Integer of
0: (
LangId: Word;
CodePage: Word);
1: (
Pair: DWORD);
end;
EJclFileVersionInfoError = class(EJclError);
TJclFileVersionInfo = class(TObject)
private
FBuffer: AnsiString;
FFixedInfo: PVSFixedFileInfo;
FFileFlags: TFileFlags;
FItemList: TStringList;
FItems: TStringList;
FLanguages: array of TLangIdRec;
FLanguageIndex: Integer;
FTranslations: array of TLangIdRec;
function GetFixedInfo: TVSFixedFileInfo;
function GetItems: TStrings;
function GetLanguageCount: Integer;
function GetLanguageIds(Index: Integer): string;
function GetLanguageNames(Index: Integer): string;
function GetLanguages(Index: Integer): TLangIdRec;
function GetTranslationCount: Integer;
function GetTranslations(Index: Integer): TLangIdRec;
procedure SetLanguageIndex(const Value: Integer);
protected
procedure CreateItemsForLanguage;
procedure CheckLanguageIndex(Value: Integer);
procedure ExtractData;
procedure ExtractFlags;
function GetBinFileVersion: string;
function GetBinProductVersion: string;
function GetFileOS: DWORD;
function GetFileSubType: DWORD;
function GetFileType: DWORD;
function GetFileVersionBuild: string;
function GetFileVersionMajor: string;
function GetFileVersionMinor: string;
function GetFileVersionRelease: string;
function GetProductVersionBuild: string;
function GetProductVersionMajor: string;
function GetProductVersionMinor: string;
function GetProductVersionRelease: string;
function GetVersionKeyValue(Index: Integer): string;
public
constructor Attach(VersionInfoData: Pointer; Size: Integer);
constructor Create(const FileName: string); overload;
{$IFDEF MSWINDOWS}
{$IFDEF FPC}
constructor Create(const Window: HWND; Dummy: Pointer = nil); overload;
{$ELSE}
constructor Create(const Window: HWND); overload;
{$ENDIF}
constructor Create(const Module: HMODULE); overload;
{$ENDIF MSWINDOWS}
destructor Destroy; override;
function GetCustomFieldValue(const FieldName: string): string;
class function VersionLanguageId(const LangIdRec: TLangIdRec): string;
class function VersionLanguageName(const LangId: Word): string;
class function FileHasVersionInfo(const FileName: string): boolean;
function TranslationMatchesLanguages(Exact: Boolean = True): Boolean;
property BinFileVersion: string read GetBinFileVersion;
property BinProductVersion: string read GetBinProductVersion;
property Comments: string index 1 read GetVersionKeyValue;
property CompanyName: string index 2 read GetVersionKeyValue;
property FileDescription: string index 3 read GetVersionKeyValue;
property FixedInfo: TVSFixedFileInfo read GetFixedInfo;
property FileFlags: TFileFlags read FFileFlags;
property FileOS: DWORD read GetFileOS;
property FileSubType: DWORD read GetFileSubType;
property FileType: DWORD read GetFileType;
property FileVersion: string index 4 read GetVersionKeyValue;
property FileVersionBuild: string read GetFileVersionBuild;
property FileVersionMajor: string read GetFileVersionMajor;
property FileVersionMinor: string read GetFileVersionMinor;
property FileVersionRelease: string read GetFileVersionRelease;
property Items: TStrings read GetItems;
property InternalName: string index 5 read GetVersionKeyValue;
property LanguageCount: Integer read GetLanguageCount;
property LanguageIds[Index: Integer]: string read GetLanguageIds;
property LanguageIndex: Integer read FLanguageIndex write SetLanguageIndex;
property Languages[Index: Integer]: TLangIdRec read GetLanguages;
property LanguageNames[Index: Integer]: string read GetLanguageNames;
property LegalCopyright: string index 6 read GetVersionKeyValue;
property LegalTradeMarks: string index 7 read GetVersionKeyValue;
property OriginalFilename: string index 8 read GetVersionKeyValue;
property PrivateBuild: string index 12 read GetVersionKeyValue;
property ProductName: string index 9 read GetVersionKeyValue;
property ProductVersion: string index 10 read GetVersionKeyValue;
property ProductVersionBuild: string read GetProductVersionBuild;
property ProductVersionMajor: string read GetProductVersionMajor;
property ProductVersionMinor: string read GetProductVersionMinor;
property ProductVersionRelease: string read GetProductVersionRelease;
property SpecialBuild: string index 11 read GetVersionKeyValue;
property TranslationCount: Integer read GetTranslationCount;
property Translations[Index: Integer]: TLangIdRec read GetTranslations;
end;
function OSIdentToString(const OSIdent: DWORD): string;
function OSFileTypeToString(const OSFileType: DWORD; const OSFileSubType: DWORD = 0): string;
function VersionResourceAvailable(const FileName: string): Boolean; overload;
function VersionResourceAvailable(const Window: HWND): Boolean; overload;
function VersionResourceAvailable(const Module: HMODULE): Boolean; overload;
function WindowToModuleFileName(const Window: HWND): string;
{$ENDIF MSWINDOWS}
// Version Info formatting
type
TFileVersionFormat = (vfMajorMinor, vfFull);
function FormatVersionString(const HiV, LoV: Word): string; overload;
function FormatVersionString(const Major, Minor, Build, Revision: Word): string; overload;
{$IFDEF MSWINDOWS}
function FormatVersionString(const FixedInfo: TVSFixedFileInfo; VersionFormat: TFileVersionFormat = vfFull): string; overload;
// Version Info extracting
procedure VersionExtractFileInfo(const FixedInfo: TVSFixedFileInfo; var Major, Minor, Build, Revision: Word);
procedure VersionExtractProductInfo(const FixedInfo: TVSFixedFileInfo; var Major, Minor, Build, Revision: Word);
// Fixed Version Info routines
function VersionFixedFileInfo(const FileName: string; var FixedInfo: TVSFixedFileInfo): Boolean;
function VersionFixedFileInfoString(const FileName: string; VersionFormat: TFileVersionFormat = vfFull;
const NotAvailableText: string = ''): string;
{$ENDIF MSWINDOWS}
// Streams
//
// TStream descendent classes for dealing with temporary files and for using file mapping objects.
type
TJclTempFileStream = class(THandleStream)
private
FFileName: string;
public
constructor Create(const Prefix: string);
destructor Destroy; override;
property FileName: string read FFileName;
end;
{$IFDEF MSWINDOWS}
TJclCustomFileMapping = class;
TJclFileMappingView = class(TCustomMemoryStream)
private
FFileMapping: TJclCustomFileMapping;
FOffsetHigh: Cardinal;
FOffsetLow: Cardinal;
function GetIndex: Integer;
function GetOffset: Int64;
public
constructor Create(const FileMap: TJclCustomFileMapping;
Access, Size: Cardinal; ViewOffset: Int64);
constructor CreateAt(FileMap: TJclCustomFileMapping; Access,
Size: Cardinal; ViewOffset: Int64; Address: Pointer);
destructor Destroy; override;
function Flush(const Count: Cardinal): Boolean;
procedure LoadFromStream(const Stream: TStream);
procedure LoadFromFile(const FileName: string);
function Write(const Buffer; Count: Longint): Longint; override;
property Index: Integer read GetIndex;
property FileMapping: TJclCustomFileMapping read FFileMapping;
property Offset: Int64 read GetOffset;
end;
TJclFileMappingRoundOffset = (rvDown, rvUp);
TJclCustomFileMapping = class(TObject)
private
FExisted: Boolean;
FHandle: THandle;
FName: string;
FRoundViewOffset: TJclFileMappingRoundOffset;
FViews: TList;
function GetCount: Integer;
function GetView(Index: Integer): TJclFileMappingView;
protected
procedure ClearViews;
procedure InternalCreate(const FileHandle: THandle; const Name: string;
const Protect: Cardinal; MaximumSize: Int64; SecAttr: PSecurityAttributes);
procedure InternalOpen(const Name: string; const InheritHandle: Boolean;
const DesiredAccess: Cardinal);
public
constructor Create;
constructor Open(const Name: string; const InheritHandle: Boolean; const DesiredAccess: Cardinal);
destructor Destroy; override;
function Add(const Access, Count: Cardinal; const Offset: Int64): Integer;
function AddAt(const Access, Count: Cardinal; const Offset: Int64; const Address: Pointer): Integer;
procedure Delete(const Index: Integer);
function IndexOf(const View: TJclFileMappingView): Integer;
property Count: Integer read GetCount;
property Existed: Boolean read FExisted;
property Handle: THandle read FHandle;
property Name: string read FName;
property RoundViewOffset: TJclFileMappingRoundOffset read FRoundViewOffset write FRoundViewOffset;
property Views[index: Integer]: TJclFileMappingView read GetView;
end;
TJclFileMapping = class(TJclCustomFileMapping)
private
FFileHandle: THandle;
public
constructor Create(const FileName: string; FileMode: Cardinal;
const Name: string; Protect: Cardinal; const MaximumSize: Int64;
SecAttr: PSecurityAttributes); overload;
constructor Create(const FileHandle: THandle; const Name: string;
Protect: Cardinal; const MaximumSize: Int64;
SecAttr: PSecurityAttributes); overload;
destructor Destroy; override;
property FileHandle: THandle read FFileHandle;
end;
TJclSwapFileMapping = class(TJclCustomFileMapping)
public
constructor Create(const Name: string; Protect: Cardinal;
const MaximumSize: Int64; SecAttr: PSecurityAttributes);
end;
TJclFileMappingStream = class(TCustomMemoryStream)
private
FFileHandle: THandle;
FMapping: THandle;
protected
procedure Close;
public
constructor Create(const FileName: string; FileMode: Word = fmOpenRead or fmShareDenyWrite);
destructor Destroy; override;
function Write(const Buffer; Count: Longint): Longint; override;
end;
{$ENDIF MSWINDOWS}
TJclMappedTextReaderIndex = (tiNoIndex, tiFull);
PPAnsiCharArray = ^TPAnsiCharArray;
TPAnsiCharArray = array [0..MaxInt div SizeOf(PAnsiChar) - 1] of PAnsiChar;
TJclAnsiMappedTextReader = class(TPersistent)
private
FContent: PAnsiChar;
FEnd: PAnsiChar;
FIndex: PPAnsiCharArray;
FIndexOption: TJclMappedTextReaderIndex;
FFreeStream: Boolean;
FLastLineNumber: Integer;
FLastPosition: PAnsiChar;
FLineCount: Integer;
FMemoryStream: TCustomMemoryStream;
FPosition: PAnsiChar;
FSize: Integer;
function GetAsString: AnsiString;
function GetEof: Boolean;
function GetChars(Index: Integer): AnsiChar;
function GetLineCount: Integer;
function GetLines(LineNumber: Integer): AnsiString;
function GetPosition: Integer;
function GetPositionFromLine(LineNumber: Integer): Integer;
procedure SetPosition(const Value: Integer);
protected
procedure AssignTo(Dest: TPersistent); override;
procedure CreateIndex;
procedure Init;
function PtrFromLine(LineNumber: Integer): PAnsiChar;
function StringFromPosition(var StartPos: PAnsiChar): AnsiString;
public
constructor Create(MemoryStream: TCustomMemoryStream; FreeStream: Boolean = True;
const AIndexOption: TJclMappedTextReaderIndex = tiNoIndex); overload;
constructor Create(const FileName: TFileName;
const AIndexOption: TJclMappedTextReaderIndex = tiNoIndex); overload;
destructor Destroy; override;
procedure GoBegin;
function Read: AnsiChar;
function ReadLn: AnsiString;
property AsString: AnsiString read GetAsString;
property Chars[Index: Integer]: AnsiChar read GetChars;
property Content: PAnsiChar read FContent;
property Eof: Boolean read GetEof;
property IndexOption: TJclMappedTextReaderIndex read FIndexOption;
property Lines[LineNumber: Integer]: AnsiString read GetLines;
property LineCount: Integer read GetLineCount;
property PositionFromLine[LineNumber: Integer]: Integer read GetPositionFromLine;
property Position: Integer read GetPosition write SetPosition;
property Size: Integer read FSize;
end;
PPWideCharArray = ^TPWideCharArray;
TPWideCharArray = array [0..MaxInt div SizeOf(PWideChar) - 1] of PWideChar;
TJclWideMappedTextReader = class(TPersistent)
private
FContent: PWideChar;
FEnd: PWideChar;
FIndex: PPWideCharArray;
FIndexOption: TJclMappedTextReaderIndex;
FFreeStream: Boolean;
FLastLineNumber: Integer;
FLastPosition: PWideChar;
FLineCount: Integer;
FMemoryStream: TCustomMemoryStream;
FPosition: PWideChar;
FSize: Integer;
function GetAsString: WideString;
function GetEof: Boolean;
function GetChars(Index: Integer): WideChar;
function GetLineCount: Integer;
function GetLines(LineNumber: Integer): WideString;
function GetPosition: Integer;
function GetPositionFromLine(LineNumber: Integer): Integer;
procedure SetPosition(const Value: Integer);
protected
procedure AssignTo(Dest: TPersistent); override;
procedure CreateIndex;
procedure Init;
function PtrFromLine(LineNumber: Integer): PWideChar;
function StringFromPosition(var StartPos: PWideChar): WideString;
public
constructor Create(MemoryStream: TCustomMemoryStream; FreeStream: Boolean = True;
const AIndexOption: TJclMappedTextReaderIndex = tiNoIndex); overload;
constructor Create(const FileName: TFileName;
const AIndexOption: TJclMappedTextReaderIndex = tiNoIndex); overload;
destructor Destroy; override;
procedure GoBegin;
function Read: WideChar;
function ReadLn: WideString;
property AsString: WideString read GetAsString;
property Chars[Index: Integer]: WideChar read GetChars;
property Content: PWideChar read FContent;
property Eof: Boolean read GetEof;
property IndexOption: TJclMappedTextReaderIndex read FIndexOption;
property Lines[LineNumber: Integer]: WideString read GetLines;
property LineCount: Integer read GetLineCount;
property PositionFromLine[LineNumber: Integer]: Integer read GetPositionFromLine;
property Position: Integer read GetPosition write SetPosition;
property Size: Integer read FSize;
end;
{ TODO : UNTESTED/UNDOCUMENTED }
type
TJclFileMaskComparator = class(TObject)
private
FFileMask: string;
FExts: array of string;
FNames: array of string;
FWildChars: array of Byte;
FSeparator: Char;
procedure CreateMultiMasks;
function GetCount: Integer;
function GetExts(Index: Integer): string;
function GetMasks(Index: Integer): string;
function GetNames(Index: Integer): string;
procedure SetFileMask(const Value: string);
procedure SetSeparator(const Value: Char);
public