source: oup/releases/0.34b/DataAccess/DataAccess.pas@ 432

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