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

Last change on this file since 227 was 227, checked in by alloc, 17 years ago
File size: 9.0 KB
RevLine 
[93]1unit DataAccess;
2interface
3
[227]4uses TypeDefs, Classes, StrUtils, SysUtils, _MetaManager;
[93]5
6type
7 TDataAccess = class
8 private
[101]9 protected
[93]10 FConnectionID: Integer;
11 FFileName: String;
12 FBackend: TDataBackend;
[97]13 FDataOS: TDataOS;
[93]14 FLevelNumber: Integer;
15 FChangeRights: TChangeRights;
[227]16 FMeta: TMetaManager;
[97]17 procedure SetDataOS(DataOS: TDataOS);
[93]18 public
19 property ConnectionID: Integer read FConnectionID;
[97]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;
[101]24 property ChangeRights: TChangeRights read FChangeRights;
[227]25 property MetaData: TMetaManager read FMeta;
[93]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;
[101]39 procedure LoadDatFile(FileID: Integer; var Target: TByteData); overload;
[93]40 procedure UpdateDatFile(FileID: Integer; Src: TStream); overload; virtual; abstract;
[101]41 procedure UpdateDatFile(FileID: Integer; Src: TByteData); overload;
[93]42 procedure LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TStream); overload; virtual; abstract;
[101]43 procedure LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TByteData); overload;
44 procedure LoadDatFilePart(FileID, Offset, Size: Integer; Target: Pointer); overload;
[93]45 procedure UpdateDatFilePart(FileID, Offset, Size: Integer; Src: TStream); overload; virtual; abstract;
[101]46 procedure UpdateDatFilePart(FileID, Offset, Size: Integer; Src: Pointer); overload;
[93]47
[113]48 function GetDatLinks(FileID: Integer): TDatLinkList; virtual; abstract;
[116]49 function GetDatLink(FileID, DatOffset: Integer): TDatLink; virtual; abstract;
[93]50 function GetRawList(FileID: Integer): TRawDataList; virtual; abstract;
[101]51 function GetRawInfo(FileID, DatOffset: Integer): TRawDataInfo; virtual; abstract;
[93]52
53 procedure LoadRawFile(FileID, DatOffset: Integer; var Target: TStream); overload; virtual; abstract;
[101]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;
[93]57 procedure LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TStream); overload; virtual; abstract;
[101]58 procedure LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TByteData); overload;
59 procedure LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; Target: Pointer); overload;
[93]60 procedure UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: TStream); overload; virtual; abstract;
[101]61 procedure UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: Pointer); overload;
[93]62
[105]63 function AppendRawFile(LocSep: Boolean; Src: TStream): Integer; overload; virtual;
64 function AppendRawFile(LocSep: Boolean; Src: TByteData): Integer; overload;
[193]65// function AppendRawFile(LocSep: Boolean; Size: Integer; Src: Pointer): Integer; overload;
[93]66 published
67 end;
68
69
70
71implementation
72
73
74(*
75 Implementation of TDataAccess
76*)
77
78function TDataAccess.ExtractFileIDOfName(Name: String): Integer;
79begin
80 if Name[5] = '-' then
81 Result := StrToInt(MidStr(Name, 1, 4))
82 else
83 Result := StrToInt(MidStr(Name, 1, 5));
84end;
85
86
87function TDataAccess.GetFileInfo(FileID: Integer): TFileInfo;
88begin
89 Result.ID := -1;
90 Result.Name := '';
91 Result.Extension := '';
92 Result.Size := -1;
93 Result.FileType := 0;
94 Result.DatAddr := -1;
95end;
96
97
98function TDataAccess.GetFileInfoByName(Name: String): TFileInfo;
99var
100 i: Integer;
101 files: TStrings;
102begin
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;
119end;
120
121
[101]122procedure TDataAccess.LoadDatFile(FileID: Integer; var Target: TByteData);
[93]123var
[101]124 data: TStream;
[93]125begin
[101]126 if fileid < GetFileCount then
[93]127 begin
[101]128 data := nil;
129 LoadDatFile(FileID, data);
130 SetLength(Target, data.Size);
131 data.Read(Target[0], data.Size);
132 data.Free;
[93]133 end;
134end;
135
[101]136procedure TDataAccess.UpdateDatFile(FileID: Integer; Src: TByteData);
137var
138 data: TStream;
139begin
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;
148end;
[93]149
[101]150procedure TDataAccess.LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TByteData);
151var
152 data: TStream;
153begin
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;
162end;
163
164procedure TDataAccess.LoadDatFilePart(FileID, Offset, Size: Integer; Target: Pointer);
165var
166 data: TStream;
167begin
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;
175end;
176
177procedure TDataAccess.UpdateDatFilePart(FileID, Offset, Size: Integer; Src: Pointer);
178var
179 data: TStream;
180begin
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;
189end;
190
191
192
193procedure TDataAccess.LoadRawFile(FileID, DatOffset: Integer; var Target: TByteData);
194var
195 data: TStream;
196begin
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;
205end;
206
207procedure TDataAccess.UpdateRawFile(FileID, DatOffset: Integer; Src: TByteData);
208var
209 data: TStream;
210begin
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;
219end;
220
221procedure TDataAccess.LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TByteData);
222var
223 data: TStream;
224begin
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;
234end;
235
236procedure TDataAccess.LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; Target: Pointer);
237var
238 data: TStream;
239begin
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;
248end;
249
250procedure TDataAccess.UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: Pointer);
251var
252 data: TStream;
253begin
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;
262end;
263
264
[105]265function TDataAccess.AppendRawFile(LocSep: Boolean; Src: TStream): Integer;
[101]266begin
267 raise ENotImplemented.Create('ERROR: AppendRawFile not implemented here!!!');
268end;
269
270
[105]271function TDataAccess.AppendRawFile(LocSep: Boolean; Src: TByteData): Integer;
[101]272var
273 data: TStream;
274begin
275 data := TMemoryStream.Create;
[105]276 data.Write(Src[0], Length(Src));
277 data.Seek(0, soFromBeginning);
[113]278 Result := AppendRawFile(LocSep, data);
[101]279 data.Free;
280end;
[193]281{
[101]282function TDataAccess.AppendRawFile(LocSep: Boolean; Size: Integer; Src: Pointer): Integer;
283var
284 data: TStream;
285begin
286 data := TMemoryStream.Create;
287 data.Write(Src^, Size);
[105]288 data.Seek(0, soFromBeginning);
[113]289 Result := AppendRawFile(LocSep, data);
[101]290 data.Free;
291end;
[193]292}
[101]293
294
[97]295procedure TDataAccess.SetDataOS(DataOS: TDataOS);
296begin
297 raise ENotImplemented.Create('TDataAccess.SetDataOS: TBD!');
298end;
[93]299
300end.
Note: See TracBrowser for help on using the repository browser.