-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFSReaderBase.pas
More file actions
115 lines (88 loc) · 2.45 KB
/
Copy pathFSReaderBase.pas
File metadata and controls
115 lines (88 loc) · 2.45 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
unit FSReaderBase;
(*
Filesytem data reader base classes and defines
for embedded filesystems, archives and packed data storages
Author: Sergey Bodrov, 2024 Minsk
License: MIT
*)
interface
uses
SysUtils, Classes;
type
TFSNode = class(TObject)
public
FileName: string;
ParentNode: TFSNode;
end;
{ FS reader base class }
{ TFSReader }
TFSReader = class(TComponent)
protected
FFile: TStream;
FOnLog: TGetStrProc;
FOnPageReaded: TNotifyEvent;
public
IsDebugPages: Boolean; // debug messages for pages
FileName: string;
procedure AfterConstruction(); override;
procedure BeforeDestruction(); override;
procedure LogInfo(AStr: string); virtual;
function OpenFile(AFileName: string; AStream: TStream = nil): Boolean; virtual;
// get detailed multi-line description of node
function FillNodeInfoText(ANode: TFSNode; ALines: TStrings): Boolean; virtual;
// get progress value 0..1000
function GetProgress(): Integer; virtual;
// get files count
function GetFilesCount(): Integer; virtual;
// get file node by index 0..GetFilesCount()-1
function GetFileByIndex(AIndex: Integer): TFSNode; virtual;
// messages from reader
property OnLog: TGetStrProc read FOnLog write FOnLog;
// after portion of data readed, for progress update
property OnPageReaded: TNotifyEvent read FOnPageReaded write FOnPageReaded;
end;
TFSReaderClass = class of TFSReader;
implementation
{ TFSReader }
procedure TFSReader.AfterConstruction;
begin
inherited;
end;
procedure TFSReader.BeforeDestruction;
begin
FreeAndNil(FFile);
inherited;
end;
function TFSReader.GetProgress: Integer;
begin
Result := Trunc(FFile.Position / (FFile.Size + 1) * 1000);
end;
function TFSReader.GetFilesCount(): Integer;
begin
Result := 0;
end;
function TFSReader.GetFileByIndex(AIndex: Integer): TFSNode;
begin
Result := nil;
end;
procedure TFSReader.LogInfo(AStr: string);
begin
if Assigned(OnLog) then OnLog(AStr);
end;
function TFSReader.OpenFile(AFileName: string; AStream: TStream): Boolean;
begin
Result := False;
FreeAndNil(FFile);
if not FileExists(AFileName) and (not Assigned(AStream)) then Exit;
if Assigned(AStream) then
FFile := AStream
else
FFile := TFileStream.Create(AFileName, fmOpenRead + fmShareDenyNone);
FileName := AFileName;
Result := True;
end;
function TFSReader.FillNodeInfoText(ANode: TFSNode; ALines: TStrings): Boolean;
begin
Result := False;
end;
end.