-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEushullyFS.pas
159 lines (136 loc) · 3.72 KB
/
EushullyFS.pas
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
unit EushullyFS;
interface
uses
Classes, SysUtils, EushullyALF, EushullyFile, ComCtrls;
type
TEushullyFS = class
private
f_root: string;
f_archives_count: UInt32;
f_archives: array of TEushullyALF;
function getLoaded(): boolean;
function getRoot(): string;
function getArchive(FileName: string): TEushullyALF;
function getMainArchive(): TEushullyALF;
procedure onFile(FileIterator: TSearchRec);
public
destructor Destroy(); override;
function load(path: string): boolean;
procedure unload();
property Loaded: boolean read getLoaded;
property Root: string read getRoot;
property Archive[FileName: string]: TEushullyALF read getArchive;
property MainArchive: TEushullyALF read getMainArchive;
procedure MakeTree(Tree: TTreeView; parent: TTreeNode);
function getArchiveByFile(FileName: string): TEushullyALF;
function open(FileName: string): TEushullyFile;
end;
implementation
destructor TEushullyFS.Destroy();
begin
unload();
end;
procedure TEushullyFS.onFile(FileIterator: TSearchRec);
begin
if (TEushullyALF.isFormat(FileIterator.Name)) then
begin
SetLength(self.f_archives, f_archives_count + 1);
self.f_archives[f_archives_count] := TEushullyALF.Create();
if (not self.f_archives[f_archives_count].LoadFromFile(FileIterator.Name))
then
self.f_archives[f_archives_count] := nil;
inc(f_archives_count);
end;
end;
function TEushullyFS.load(path: string): boolean;
var
rec: TSearchRec;
begin
self.f_root := path;
if FindFirst(IncludeTrailingPathDelimiter(path) + '*.*',
faAnyFile - faDirectory, rec) = 0 then
begin
repeat
onFile(rec);
until FindNext(rec) <> 0;
FindClose(rec);
end;
result := (f_archives_count > 0);
end;
procedure TEushullyFS.unload();
var
i: integer;
begin
for i := 0 to self.f_archives_count - 1 do
self.f_archives[i].Free;
SetLength(self.f_archives, 0);
self.f_archives_count := 0;
end;
function TEushullyFS.getLoaded(): boolean;
begin
result := (f_archives_count > 0);
end;
function TEushullyFS.getRoot(): string;
begin
result := self.f_root;
end;
function TEushullyFS.getArchive(FileName: string): TEushullyALF;
var
i: integer;
begin
for i := 0 to self.f_archives_count - 1 do
if (self.f_archives[i].isExist(FileName)) then
begin
result := self.f_archives[i];
Exit;
end;
result := nil;
end;
function TEushullyFS.getMainArchive(): TEushullyALF;
var
i: integer;
begin
for i := 0 to self.f_archives_count - 1 do
if (self.f_archives[i].ArchiveType = ALF_DATA) then
begin
result := self.f_archives[i];
Exit;
end;
result := nil;
end;
procedure TEushullyFS.MakeTree(Tree: TTreeView; parent: TTreeNode);
var
i, j: integer;
alf: TEushullyALF;
alf_node: TTreeNode;
begin
for i := 0 to self.f_archives_count - 1 do
begin
alf := f_archives[i];
alf_node := Tree.Items.AddChild(parent, ExtractFileName(alf.Name));
alf_node.Data := alf;
for j := 0 to alf.FilesCount - 1 do
begin
if (alf.FileName[j] <> '@') then
Tree.Items.AddChild(alf_node, alf.FileName[j]).Data := Pointer(j);
end;
end;
Tree.Selected := parent;
end;
function TEushullyFS.getArchiveByFile(FileName: string): TEushullyALF;
var
i: integer;
begin
for i := 0 to self.f_archives_count - 1 do
if (self.f_archives[i].isExist(FileName)) then
begin
result := f_archives[i];
Exit;
end;
result := nil;
end;
function TEushullyFS.open(FileName: string): TEushullyFile;
begin
result := TEushullyFile.Create(self.Archive[FileName], self.Root, FileName);
end;
end.