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

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