source: oup/current/DataAccess/DataAccess.pas@ 473

Last change on this file since 473 was 241, checked in by alloc, 17 years ago
File size: 9.2 KB
Line 
1unit DataAccess;
2interface
3
4uses TypeDefs, Classes, StrUtils, SysUtils, _MetaManager;
5
6type
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
72implementation
73
74
75(*
76 Implementation of TDataAccess
77*)
78
79constructor TDataAccess.Create(FileName: String; ConnectionID: Integer;
80 var Msg: TStatusMessages);
81begin
82 FMeta := TMetaManager.Create(FConnectionID, Self);
83end;
84
85
86
87function TDataAccess.ExtractFileIDOfName(Name: String): Integer;
88begin
89 if Name[5] = '-' then
90 Result := StrToInt(MidStr(Name, 1, 4))
91 else
92 Result := StrToInt(MidStr(Name, 1, 5));
93end;
94
95
96function TDataAccess.GetFileInfo(FileID: Integer): TFileInfo;
97begin
98 Result.ID := -1;
99 Result.Name := '';
100 Result.Extension := '';
101 Result.Size := -1;
102 Result.FileType := 0;
103 Result.DatAddr := -1;
104end;
105
106
107function TDataAccess.GetFileInfoByName(Name: String): TFileInfo;
108var
109 i: Integer;
110 files: TStrings;
111begin
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;
128end;
129
130
131procedure TDataAccess.LoadDatFile(FileID: Integer; var Target: TByteData);
132var
133 data: TStream;
134begin
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;
143end;
144
145procedure TDataAccess.UpdateDatFile(FileID: Integer; Src: TByteData);
146var
147 data: TStream;
148begin
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;
157end;
158
159procedure TDataAccess.LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TByteData);
160var
161 data: TStream;
162begin
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;
171end;
172
173procedure TDataAccess.LoadDatFilePart(FileID, Offset, Size: Integer; Target: Pointer);
174var
175 data: TStream;
176begin
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;
184end;
185
186procedure TDataAccess.UpdateDatFilePart(FileID, Offset, Size: Integer; Src: Pointer);
187var
188 data: TStream;
189begin
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;
198end;
199
200
201
202procedure TDataAccess.LoadRawFile(FileID, DatOffset: Integer; var Target: TByteData);
203var
204 data: TStream;
205begin
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;
214end;
215
216procedure TDataAccess.UpdateRawFile(FileID, DatOffset: Integer; Src: TByteData);
217var
218 data: TStream;
219begin
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;
228end;
229
230procedure TDataAccess.LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TByteData);
231var
232 data: TStream;
233begin
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;
243end;
244
245procedure TDataAccess.LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; Target: Pointer);
246var
247 data: TStream;
248begin
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;
257end;
258
259procedure TDataAccess.UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: Pointer);
260var
261 data: TStream;
262begin
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;
271end;
272
273
274function TDataAccess.AppendRawFile(LocSep: Boolean; Src: TStream): Integer;
275begin
276 raise ENotImplemented.Create('ERROR: AppendRawFile not implemented here!!!');
277end;
278
279
280function TDataAccess.AppendRawFile(LocSep: Boolean; Src: TByteData): Integer;
281var
282 data: TStream;
283begin
284 data := TMemoryStream.Create;
285 data.Write(Src[0], Length(Src));
286 data.Seek(0, soFromBeginning);
287 Result := AppendRawFile(LocSep, data);
288 data.Free;
289end;
290{
291function TDataAccess.AppendRawFile(LocSep: Boolean; Size: Integer; Src: Pointer): Integer;
292var
293 data: TStream;
294begin
295 data := TMemoryStream.Create;
296 data.Write(Src^, Size);
297 data.Seek(0, soFromBeginning);
298 Result := AppendRawFile(LocSep, data);
299 data.Free;
300end;
301}
302
303
304procedure TDataAccess.SetDataOS(DataOS: TDataOS);
305begin
306 raise ENotImplemented.Create('TDataAccess.SetDataOS: TBD!');
307end;
308
309end.
Note: See TracBrowser for help on using the repository browser.