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;
|
---|
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 | function GetRawsForType(RawType: String): TRawDataList; virtual; abstract;
|
---|
53 |
|
---|
54 | procedure LoadRawFile(FileID, DatOffset: Integer; var Target: TStream); overload; virtual; abstract;
|
---|
55 | procedure LoadRawFile(FileID, DatOffset: Integer; var Target: TByteData); overload;
|
---|
56 | procedure UpdateRawFile(FileID, DatOffset: Integer; Src: TStream); overload; virtual; abstract;
|
---|
57 | procedure UpdateRawFile(FileID, DatOffset: Integer; Src: TByteData); overload;
|
---|
58 | procedure LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TStream); overload; virtual; abstract;
|
---|
59 | procedure LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TByteData); overload;
|
---|
60 | procedure LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; Target: Pointer); overload;
|
---|
61 | procedure UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: TStream); overload; virtual; abstract;
|
---|
62 | procedure UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: Pointer); overload;
|
---|
63 |
|
---|
64 | function AppendRawFile(LocSep: Boolean; Src: TStream): Integer; overload; virtual;
|
---|
65 | function AppendRawFile(LocSep: Boolean; Src: TByteData): Integer; overload;
|
---|
66 | // function AppendRawFile(LocSep: Boolean; Size: Integer; Src: Pointer): Integer; overload;
|
---|
67 | published
|
---|
68 | end;
|
---|
69 |
|
---|
70 |
|
---|
71 |
|
---|
72 | implementation
|
---|
73 |
|
---|
74 |
|
---|
75 | (*
|
---|
76 | Implementation of TDataAccess
|
---|
77 | *)
|
---|
78 |
|
---|
79 | constructor TDataAccess.Create(FileName: String; ConnectionID: Integer;
|
---|
80 | var Msg: TStatusMessages);
|
---|
81 | begin
|
---|
82 | FMeta := TMetaManager.Create(FConnectionID, Self);
|
---|
83 | end;
|
---|
84 |
|
---|
85 |
|
---|
86 |
|
---|
87 | function TDataAccess.ExtractFileIDOfName(Name: String): Integer;
|
---|
88 | begin
|
---|
89 | if Name[5] = '-' then
|
---|
90 | Result := StrToInt(MidStr(Name, 1, 4))
|
---|
91 | else
|
---|
92 | Result := StrToInt(MidStr(Name, 1, 5));
|
---|
93 | end;
|
---|
94 |
|
---|
95 |
|
---|
96 | function TDataAccess.GetFileInfo(FileID: Integer): TFileInfo;
|
---|
97 | begin
|
---|
98 | Result.ID := -1;
|
---|
99 | Result.Name := '';
|
---|
100 | Result.Extension := '';
|
---|
101 | Result.Size := -1;
|
---|
102 | Result.FileType := 0;
|
---|
103 | Result.DatAddr := -1;
|
---|
104 | end;
|
---|
105 |
|
---|
106 |
|
---|
107 | function TDataAccess.GetFileInfoByName(Name: String): TFileInfo;
|
---|
108 | var
|
---|
109 | i: Integer;
|
---|
110 | files: TStrings;
|
---|
111 | begin
|
---|
112 | Result := GetFileInfo(-1);
|
---|
113 | files := GetFilesList('', Name, False, ST_IDAsc);
|
---|
114 | if files.Count = 0 then
|
---|
115 | else
|
---|
116 | begin
|
---|
117 | for i := 0 to files.Count - 1 do
|
---|
118 | begin
|
---|
119 | if MidStr(files.Strings[i], Pos('-', files.Strings[i]) + 1,
|
---|
120 | Length(files.Strings[i]) - Pos('-', files.Strings[i]) - 5) = name then
|
---|
121 | begin
|
---|
122 | Result := GetFileInfo(ExtractFileIDOfName(files.Strings[i]));
|
---|
123 | Break;
|
---|
124 | end;
|
---|
125 | end;
|
---|
126 | end;
|
---|
127 | files.Free;
|
---|
128 | end;
|
---|
129 |
|
---|
130 |
|
---|
131 | procedure TDataAccess.LoadDatFile(FileID: Integer; var Target: TByteData);
|
---|
132 | var
|
---|
133 | data: TStream;
|
---|
134 | begin
|
---|
135 | if fileid < GetFileCount then
|
---|
136 | begin
|
---|
137 | data := nil;
|
---|
138 | LoadDatFile(FileID, data);
|
---|
139 | SetLength(Target, data.Size);
|
---|
140 | data.Read(Target[0], data.Size);
|
---|
141 | data.Free;
|
---|
142 | end;
|
---|
143 | end;
|
---|
144 |
|
---|
145 | procedure TDataAccess.UpdateDatFile(FileID: Integer; Src: TByteData);
|
---|
146 | var
|
---|
147 | data: TStream;
|
---|
148 | begin
|
---|
149 | if fileid < GetFileCount then
|
---|
150 | begin
|
---|
151 | data := TMemoryStream.Create;
|
---|
152 | data.Write(Src[0], Length(Src));
|
---|
153 | data.Seek(0, soFromBeginning);
|
---|
154 | UpdateDatFile(FileID, data);
|
---|
155 | data.Free;
|
---|
156 | end;
|
---|
157 | end;
|
---|
158 |
|
---|
159 | procedure TDataAccess.LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TByteData);
|
---|
160 | var
|
---|
161 | data: TStream;
|
---|
162 | begin
|
---|
163 | if fileid < GetFileCount then
|
---|
164 | begin
|
---|
165 | data := nil;
|
---|
166 | LoadDatFilePart(FileID, offset, size, data);
|
---|
167 | SetLength(Target, data.Size);
|
---|
168 | data.Read(Target[0], data.Size);
|
---|
169 | data.Free;
|
---|
170 | end;
|
---|
171 | end;
|
---|
172 |
|
---|
173 | procedure TDataAccess.LoadDatFilePart(FileID, Offset, Size: Integer; Target: Pointer);
|
---|
174 | var
|
---|
175 | data: TStream;
|
---|
176 | begin
|
---|
177 | if fileid < GetFileCount then
|
---|
178 | begin
|
---|
179 | data := nil;
|
---|
180 | LoadDatFilePart(FileID, offset, size, data);
|
---|
181 | data.Read(Target^, data.Size);
|
---|
182 | data.Free;
|
---|
183 | end;
|
---|
184 | end;
|
---|
185 |
|
---|
186 | procedure TDataAccess.UpdateDatFilePart(FileID, Offset, Size: Integer; Src: Pointer);
|
---|
187 | var
|
---|
188 | data: TStream;
|
---|
189 | begin
|
---|
190 | if fileid < GetFileCount then
|
---|
191 | begin
|
---|
192 | data := TMemoryStream.Create;
|
---|
193 | data.Write(Src^, Size);
|
---|
194 | data.Seek(0, soFromBeginning);
|
---|
195 | UpdateDatFilePart(FileID, offset, size, data);
|
---|
196 | data.Free;
|
---|
197 | end;
|
---|
198 | end;
|
---|
199 |
|
---|
200 |
|
---|
201 |
|
---|
202 | procedure TDataAccess.LoadRawFile(FileID, DatOffset: Integer; var Target: TByteData);
|
---|
203 | var
|
---|
204 | data: TStream;
|
---|
205 | begin
|
---|
206 | if fileid < GetFileCount then
|
---|
207 | begin
|
---|
208 | data := nil;
|
---|
209 | LoadRawFile(FileID, DatOffset, data);
|
---|
210 | SetLength(Target, data.Size);
|
---|
211 | data.Read(Target[0], data.Size);
|
---|
212 | data.Free;
|
---|
213 | end;
|
---|
214 | end;
|
---|
215 |
|
---|
216 | procedure TDataAccess.UpdateRawFile(FileID, DatOffset: Integer; Src: TByteData);
|
---|
217 | var
|
---|
218 | data: TStream;
|
---|
219 | begin
|
---|
220 | if fileid < GetFileCount then
|
---|
221 | begin
|
---|
222 | data := TMemoryStream.Create;
|
---|
223 | data.Write(Src[0], Length(Src));
|
---|
224 | data.Seek(0, soFromBeginning);
|
---|
225 | UpdateRawFile(FileID, DatOffset, data);
|
---|
226 | data.Free;
|
---|
227 | end;
|
---|
228 | end;
|
---|
229 |
|
---|
230 | procedure TDataAccess.LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TByteData);
|
---|
231 | var
|
---|
232 | data: TStream;
|
---|
233 | begin
|
---|
234 | if fileid < GetFileCount then
|
---|
235 | begin
|
---|
236 | data := nil;
|
---|
237 | SetLength(Target, Size);
|
---|
238 | LoadRawFile(FileID, DatOffset, Data);
|
---|
239 | Data.Seek(Offset, soFromBeginning);
|
---|
240 | Data.Read(Target[0], Size);
|
---|
241 | Data.Free;
|
---|
242 | end;
|
---|
243 | end;
|
---|
244 |
|
---|
245 | procedure TDataAccess.LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; Target: Pointer);
|
---|
246 | var
|
---|
247 | data: TStream;
|
---|
248 | begin
|
---|
249 | if fileid < GetFileCount then
|
---|
250 | begin
|
---|
251 | data := nil;
|
---|
252 | LoadRawFile(FileID, DatOffset, Data);
|
---|
253 | Data.Seek(Offset, soFromBeginning);
|
---|
254 | Data.Read(Target^, Size);
|
---|
255 | Data.Free;
|
---|
256 | end;
|
---|
257 | end;
|
---|
258 |
|
---|
259 | procedure TDataAccess.UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: Pointer);
|
---|
260 | var
|
---|
261 | data: TStream;
|
---|
262 | begin
|
---|
263 | if fileid < GetFileCount then
|
---|
264 | begin
|
---|
265 | data := TMemoryStream.Create;
|
---|
266 | data.Write(Src^, Size);
|
---|
267 | data.Seek(0, soFromBeginning);
|
---|
268 | UpdateRawFilePart(FileID, DatOffset, Offset, Size, data);
|
---|
269 | data.Free;
|
---|
270 | end;
|
---|
271 | end;
|
---|
272 |
|
---|
273 |
|
---|
274 | function TDataAccess.AppendRawFile(LocSep: Boolean; Src: TStream): Integer;
|
---|
275 | begin
|
---|
276 | raise ENotImplemented.Create('ERROR: AppendRawFile not implemented here!!!');
|
---|
277 | end;
|
---|
278 |
|
---|
279 |
|
---|
280 | function TDataAccess.AppendRawFile(LocSep: Boolean; Src: TByteData): Integer;
|
---|
281 | var
|
---|
282 | data: TStream;
|
---|
283 | begin
|
---|
284 | data := TMemoryStream.Create;
|
---|
285 | data.Write(Src[0], Length(Src));
|
---|
286 | data.Seek(0, soFromBeginning);
|
---|
287 | Result := AppendRawFile(LocSep, data);
|
---|
288 | data.Free;
|
---|
289 | end;
|
---|
290 | {
|
---|
291 | function TDataAccess.AppendRawFile(LocSep: Boolean; Size: Integer; Src: Pointer): Integer;
|
---|
292 | var
|
---|
293 | data: TStream;
|
---|
294 | begin
|
---|
295 | data := TMemoryStream.Create;
|
---|
296 | data.Write(Src^, Size);
|
---|
297 | data.Seek(0, soFromBeginning);
|
---|
298 | Result := AppendRawFile(LocSep, data);
|
---|
299 | data.Free;
|
---|
300 | end;
|
---|
301 | }
|
---|
302 |
|
---|
303 |
|
---|
304 | procedure TDataAccess.SetDataOS(DataOS: TDataOS);
|
---|
305 | begin
|
---|
306 | raise ENotImplemented.Create('TDataAccess.SetDataOS: TBD!');
|
---|
307 | end;
|
---|
308 |
|
---|
309 | end.
|
---|