1 | unit DataAccess;
|
---|
2 | interface
|
---|
3 |
|
---|
4 | uses TypeDefs, Classes, StrUtils, SysUtils, _MetaManager;
|
---|
5 |
|
---|
6 | type
|
---|
7 | TDataAccess = class
|
---|
8 | private
|
---|
9 | protected
|
---|
10 | FConnectionID: Integer;
|
---|
11 | FFileName: String;
|
---|
12 | FBackend: TDataBackend;
|
---|
13 | FDataOS: TDataOS;
|
---|
14 | FLevelNumber: Integer;
|
---|
15 | FChangeRights: TChangeRights;
|
---|
16 | FMeta: TMetaManager;
|
---|
17 | procedure SetDataOS(DataOS: TDataOS);
|
---|
18 | public
|
---|
19 | property ConnectionID: Integer read FConnectionID;
|
---|
20 | property FileName: String read FFileName;
|
---|
21 | property Backend: TDataBackend read FBackend;
|
---|
22 | property DataOS: TDataOS read FDataOS write SetDataOS;
|
---|
23 | property LevelNumber: Integer read FLevelNumber;
|
---|
24 | property ChangeRights: TChangeRights read FChangeRights;
|
---|
25 | property MetaData: TMetaManager read FMeta;
|
---|
26 |
|
---|
27 | constructor Create(FileName: String; ConnectionID: Integer; var Msg: TStatusMessages); virtual; abstract;
|
---|
28 | procedure Close; virtual; abstract;
|
---|
29 |
|
---|
30 | function ExtractFileIDOfName(Name: String): Integer; virtual;
|
---|
31 | function GetFileInfo(FileID: Integer): TFileInfo; virtual;
|
---|
32 | function GetFileInfoByName(Name: String): TFileInfo; virtual;
|
---|
33 | function GetFilesList(Ext: String; Pattern: String;
|
---|
34 | NoEmptyFiles: Boolean; SortType: TSortType): TStrings; virtual; abstract;
|
---|
35 | function GetFileCount: Integer; virtual; abstract;
|
---|
36 | function GetExtensionsList(ExtListFormat: TExtensionFormat): TStrings; virtual; abstract;
|
---|
37 |
|
---|
38 | procedure LoadDatFile(FileID: Integer; var Target: TStream); overload; virtual; abstract;
|
---|
39 | procedure LoadDatFile(FileID: Integer; var Target: TByteData); overload;
|
---|
40 | procedure UpdateDatFile(FileID: Integer; Src: TStream); overload; virtual; abstract;
|
---|
41 | procedure UpdateDatFile(FileID: Integer; Src: TByteData); overload;
|
---|
42 | procedure LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TStream); overload; virtual; abstract;
|
---|
43 | procedure LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TByteData); overload;
|
---|
44 | procedure LoadDatFilePart(FileID, Offset, Size: Integer; Target: Pointer); overload;
|
---|
45 | procedure UpdateDatFilePart(FileID, Offset, Size: Integer; Src: TStream); overload; virtual; abstract;
|
---|
46 | procedure UpdateDatFilePart(FileID, Offset, Size: Integer; Src: Pointer); overload;
|
---|
47 |
|
---|
48 | function GetDatLinks(FileID: Integer): TDatLinkList; virtual; abstract;
|
---|
49 | function GetDatLink(FileID, DatOffset: Integer): TDatLink; virtual; abstract;
|
---|
50 | function GetRawList(FileID: Integer): TRawDataList; virtual; abstract;
|
---|
51 | function GetRawInfo(FileID, DatOffset: Integer): TRawDataInfo; virtual; abstract;
|
---|
52 |
|
---|
53 | procedure LoadRawFile(FileID, DatOffset: Integer; var Target: TStream); overload; virtual; abstract;
|
---|
54 | procedure LoadRawFile(FileID, DatOffset: Integer; var Target: TByteData); overload;
|
---|
55 | procedure UpdateRawFile(FileID, DatOffset: Integer; Src: TStream); overload; virtual; abstract;
|
---|
56 | procedure UpdateRawFile(FileID, DatOffset: Integer; Src: TByteData); overload;
|
---|
57 | procedure LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TStream); overload; virtual; abstract;
|
---|
58 | procedure LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TByteData); overload;
|
---|
59 | procedure LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; Target: Pointer); overload;
|
---|
60 | procedure UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: TStream); overload; virtual; abstract;
|
---|
61 | procedure UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: Pointer); overload;
|
---|
62 |
|
---|
63 | function AppendRawFile(LocSep: Boolean; Src: TStream): Integer; overload; virtual;
|
---|
64 | function AppendRawFile(LocSep: Boolean; Src: TByteData): Integer; overload;
|
---|
65 | // function AppendRawFile(LocSep: Boolean; Size: Integer; Src: Pointer): Integer; overload;
|
---|
66 | published
|
---|
67 | end;
|
---|
68 |
|
---|
69 |
|
---|
70 |
|
---|
71 | implementation
|
---|
72 |
|
---|
73 |
|
---|
74 | (*
|
---|
75 | Implementation of TDataAccess
|
---|
76 | *)
|
---|
77 |
|
---|
78 | function TDataAccess.ExtractFileIDOfName(Name: String): Integer;
|
---|
79 | begin
|
---|
80 | if Name[5] = '-' then
|
---|
81 | Result := StrToInt(MidStr(Name, 1, 4))
|
---|
82 | else
|
---|
83 | Result := StrToInt(MidStr(Name, 1, 5));
|
---|
84 | end;
|
---|
85 |
|
---|
86 |
|
---|
87 | function TDataAccess.GetFileInfo(FileID: Integer): TFileInfo;
|
---|
88 | begin
|
---|
89 | Result.ID := -1;
|
---|
90 | Result.Name := '';
|
---|
91 | Result.Extension := '';
|
---|
92 | Result.Size := -1;
|
---|
93 | Result.FileType := 0;
|
---|
94 | Result.DatAddr := -1;
|
---|
95 | end;
|
---|
96 |
|
---|
97 |
|
---|
98 | function TDataAccess.GetFileInfoByName(Name: String): TFileInfo;
|
---|
99 | var
|
---|
100 | i: Integer;
|
---|
101 | files: TStrings;
|
---|
102 | begin
|
---|
103 | Result := GetFileInfo(-1);
|
---|
104 | files := GetFilesList('', Name, False, ST_IDAsc);
|
---|
105 | if files.Count = 0 then
|
---|
106 | else
|
---|
107 | begin
|
---|
108 | for i := 0 to files.Count - 1 do
|
---|
109 | begin
|
---|
110 | if MidStr(files.Strings[i], Pos('-', files.Strings[i]) + 1,
|
---|
111 | Length(files.Strings[i]) - Pos('-', files.Strings[i]) - 5) = name then
|
---|
112 | begin
|
---|
113 | Result := GetFileInfo(ExtractFileIDOfName(files.Strings[i]));
|
---|
114 | Break;
|
---|
115 | end;
|
---|
116 | end;
|
---|
117 | end;
|
---|
118 | files.Free;
|
---|
119 | end;
|
---|
120 |
|
---|
121 |
|
---|
122 | procedure TDataAccess.LoadDatFile(FileID: Integer; var Target: TByteData);
|
---|
123 | var
|
---|
124 | data: TStream;
|
---|
125 | begin
|
---|
126 | if fileid < GetFileCount then
|
---|
127 | begin
|
---|
128 | data := nil;
|
---|
129 | LoadDatFile(FileID, data);
|
---|
130 | SetLength(Target, data.Size);
|
---|
131 | data.Read(Target[0], data.Size);
|
---|
132 | data.Free;
|
---|
133 | end;
|
---|
134 | end;
|
---|
135 |
|
---|
136 | procedure TDataAccess.UpdateDatFile(FileID: Integer; Src: TByteData);
|
---|
137 | var
|
---|
138 | data: TStream;
|
---|
139 | begin
|
---|
140 | if fileid < GetFileCount then
|
---|
141 | begin
|
---|
142 | data := TMemoryStream.Create;
|
---|
143 | data.Write(Src[0], Length(Src));
|
---|
144 | data.Seek(0, soFromBeginning);
|
---|
145 | UpdateDatFile(FileID, data);
|
---|
146 | data.Free;
|
---|
147 | end;
|
---|
148 | end;
|
---|
149 |
|
---|
150 | procedure TDataAccess.LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TByteData);
|
---|
151 | var
|
---|
152 | data: TStream;
|
---|
153 | begin
|
---|
154 | if fileid < GetFileCount then
|
---|
155 | begin
|
---|
156 | data := nil;
|
---|
157 | LoadDatFilePart(FileID, offset, size, data);
|
---|
158 | SetLength(Target, data.Size);
|
---|
159 | data.Read(Target[0], data.Size);
|
---|
160 | data.Free;
|
---|
161 | end;
|
---|
162 | end;
|
---|
163 |
|
---|
164 | procedure TDataAccess.LoadDatFilePart(FileID, Offset, Size: Integer; Target: Pointer);
|
---|
165 | var
|
---|
166 | data: TStream;
|
---|
167 | begin
|
---|
168 | if fileid < GetFileCount then
|
---|
169 | begin
|
---|
170 | data := nil;
|
---|
171 | LoadDatFilePart(FileID, offset, size, data);
|
---|
172 | data.Read(Target^, data.Size);
|
---|
173 | data.Free;
|
---|
174 | end;
|
---|
175 | end;
|
---|
176 |
|
---|
177 | procedure TDataAccess.UpdateDatFilePart(FileID, Offset, Size: Integer; Src: Pointer);
|
---|
178 | var
|
---|
179 | data: TStream;
|
---|
180 | begin
|
---|
181 | if fileid < GetFileCount then
|
---|
182 | begin
|
---|
183 | data := TMemoryStream.Create;
|
---|
184 | data.Write(Src^, Size);
|
---|
185 | data.Seek(0, soFromBeginning);
|
---|
186 | UpdateDatFilePart(FileID, offset, size, data);
|
---|
187 | data.Free;
|
---|
188 | end;
|
---|
189 | end;
|
---|
190 |
|
---|
191 |
|
---|
192 |
|
---|
193 | procedure TDataAccess.LoadRawFile(FileID, DatOffset: Integer; var Target: TByteData);
|
---|
194 | var
|
---|
195 | data: TStream;
|
---|
196 | begin
|
---|
197 | if fileid < GetFileCount then
|
---|
198 | begin
|
---|
199 | data := nil;
|
---|
200 | LoadRawFile(FileID, DatOffset, data);
|
---|
201 | SetLength(Target, data.Size);
|
---|
202 | data.Read(Target[0], data.Size);
|
---|
203 | data.Free;
|
---|
204 | end;
|
---|
205 | end;
|
---|
206 |
|
---|
207 | procedure TDataAccess.UpdateRawFile(FileID, DatOffset: Integer; Src: TByteData);
|
---|
208 | var
|
---|
209 | data: TStream;
|
---|
210 | begin
|
---|
211 | if fileid < GetFileCount then
|
---|
212 | begin
|
---|
213 | data := TMemoryStream.Create;
|
---|
214 | data.Write(Src[0], Length(Src));
|
---|
215 | data.Seek(0, soFromBeginning);
|
---|
216 | UpdateRawFile(FileID, DatOffset, data);
|
---|
217 | data.Free;
|
---|
218 | end;
|
---|
219 | end;
|
---|
220 |
|
---|
221 | procedure TDataAccess.LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TByteData);
|
---|
222 | var
|
---|
223 | data: TStream;
|
---|
224 | begin
|
---|
225 | if fileid < GetFileCount then
|
---|
226 | begin
|
---|
227 | data := nil;
|
---|
228 | SetLength(Target, Size);
|
---|
229 | LoadRawFile(FileID, DatOffset, Data);
|
---|
230 | Data.Seek(Offset, soFromBeginning);
|
---|
231 | Data.Read(Target[0], Size);
|
---|
232 | Data.Free;
|
---|
233 | end;
|
---|
234 | end;
|
---|
235 |
|
---|
236 | procedure TDataAccess.LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; Target: Pointer);
|
---|
237 | var
|
---|
238 | data: TStream;
|
---|
239 | begin
|
---|
240 | if fileid < GetFileCount then
|
---|
241 | begin
|
---|
242 | data := nil;
|
---|
243 | LoadRawFile(FileID, DatOffset, Data);
|
---|
244 | Data.Seek(Offset, soFromBeginning);
|
---|
245 | Data.Read(Target^, Size);
|
---|
246 | Data.Free;
|
---|
247 | end;
|
---|
248 | end;
|
---|
249 |
|
---|
250 | procedure TDataAccess.UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: Pointer);
|
---|
251 | var
|
---|
252 | data: TStream;
|
---|
253 | begin
|
---|
254 | if fileid < GetFileCount then
|
---|
255 | begin
|
---|
256 | data := TMemoryStream.Create;
|
---|
257 | data.Write(Src^, Size);
|
---|
258 | data.Seek(0, soFromBeginning);
|
---|
259 | UpdateRawFilePart(FileID, DatOffset, Offset, Size, data);
|
---|
260 | data.Free;
|
---|
261 | end;
|
---|
262 | end;
|
---|
263 |
|
---|
264 |
|
---|
265 | function TDataAccess.AppendRawFile(LocSep: Boolean; Src: TStream): Integer;
|
---|
266 | begin
|
---|
267 | raise ENotImplemented.Create('ERROR: AppendRawFile not implemented here!!!');
|
---|
268 | end;
|
---|
269 |
|
---|
270 |
|
---|
271 | function TDataAccess.AppendRawFile(LocSep: Boolean; Src: TByteData): Integer;
|
---|
272 | var
|
---|
273 | data: TStream;
|
---|
274 | begin
|
---|
275 | data := TMemoryStream.Create;
|
---|
276 | data.Write(Src[0], Length(Src));
|
---|
277 | data.Seek(0, soFromBeginning);
|
---|
278 | Result := AppendRawFile(LocSep, data);
|
---|
279 | data.Free;
|
---|
280 | end;
|
---|
281 | {
|
---|
282 | function TDataAccess.AppendRawFile(LocSep: Boolean; Size: Integer; Src: Pointer): Integer;
|
---|
283 | var
|
---|
284 | data: TStream;
|
---|
285 | begin
|
---|
286 | data := TMemoryStream.Create;
|
---|
287 | data.Write(Src^, Size);
|
---|
288 | data.Seek(0, soFromBeginning);
|
---|
289 | Result := AppendRawFile(LocSep, data);
|
---|
290 | data.Free;
|
---|
291 | end;
|
---|
292 | }
|
---|
293 |
|
---|
294 |
|
---|
295 | procedure TDataAccess.SetDataOS(DataOS: TDataOS);
|
---|
296 | begin
|
---|
297 | raise ENotImplemented.Create('TDataAccess.SetDataOS: TBD!');
|
---|
298 | end;
|
---|
299 |
|
---|
300 | end.
|
---|