[205] | 1 | unit DataAccess;
|
---|
| 2 | interface
|
---|
| 3 |
|
---|
| 4 | uses TypeDefs, Classes, StrUtils, SysUtils;
|
---|
| 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 | 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 |
|
---|
| 69 | implementation
|
---|
| 70 |
|
---|
| 71 |
|
---|
| 72 | (*
|
---|
| 73 | Implementation of TDataAccess
|
---|
| 74 | *)
|
---|
| 75 |
|
---|
| 76 | function TDataAccess.ExtractFileIDOfName(Name: String): Integer;
|
---|
| 77 | begin
|
---|
| 78 | if Name[5] = '-' then
|
---|
| 79 | Result := StrToInt(MidStr(Name, 1, 4))
|
---|
| 80 | else
|
---|
| 81 | Result := StrToInt(MidStr(Name, 1, 5));
|
---|
| 82 | end;
|
---|
| 83 |
|
---|
| 84 |
|
---|
| 85 | function TDataAccess.GetFileInfo(FileID: Integer): TFileInfo;
|
---|
| 86 | begin
|
---|
| 87 | Result.ID := -1;
|
---|
| 88 | Result.Name := '';
|
---|
| 89 | Result.Extension := '';
|
---|
| 90 | Result.Size := -1;
|
---|
| 91 | Result.FileType := 0;
|
---|
| 92 | Result.DatAddr := -1;
|
---|
| 93 | end;
|
---|
| 94 |
|
---|
| 95 |
|
---|
| 96 | function TDataAccess.GetFileInfoByName(Name: String): TFileInfo;
|
---|
| 97 | var
|
---|
| 98 | i: Integer;
|
---|
| 99 | files: TStrings;
|
---|
| 100 | begin
|
---|
| 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;
|
---|
| 117 | end;
|
---|
| 118 |
|
---|
| 119 |
|
---|
| 120 | procedure TDataAccess.LoadDatFile(FileID: Integer; var Target: TByteData);
|
---|
| 121 | var
|
---|
| 122 | data: TStream;
|
---|
| 123 | begin
|
---|
| 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;
|
---|
| 132 | end;
|
---|
| 133 |
|
---|
| 134 | procedure TDataAccess.UpdateDatFile(FileID: Integer; Src: TByteData);
|
---|
| 135 | var
|
---|
| 136 | data: TStream;
|
---|
| 137 | begin
|
---|
| 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;
|
---|
| 146 | end;
|
---|
| 147 |
|
---|
| 148 | procedure TDataAccess.LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TByteData);
|
---|
| 149 | var
|
---|
| 150 | data: TStream;
|
---|
| 151 | begin
|
---|
| 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;
|
---|
| 160 | end;
|
---|
| 161 |
|
---|
| 162 | procedure TDataAccess.LoadDatFilePart(FileID, Offset, Size: Integer; Target: Pointer);
|
---|
| 163 | var
|
---|
| 164 | data: TStream;
|
---|
| 165 | begin
|
---|
| 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;
|
---|
| 173 | end;
|
---|
| 174 |
|
---|
| 175 | procedure TDataAccess.UpdateDatFilePart(FileID, Offset, Size: Integer; Src: Pointer);
|
---|
| 176 | var
|
---|
| 177 | data: TStream;
|
---|
| 178 | begin
|
---|
| 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;
|
---|
| 187 | end;
|
---|
| 188 |
|
---|
| 189 |
|
---|
| 190 |
|
---|
| 191 | procedure TDataAccess.LoadRawFile(FileID, DatOffset: Integer; var Target: TByteData);
|
---|
| 192 | var
|
---|
| 193 | data: TStream;
|
---|
| 194 | begin
|
---|
| 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;
|
---|
| 203 | end;
|
---|
| 204 |
|
---|
| 205 | procedure TDataAccess.UpdateRawFile(FileID, DatOffset: Integer; Src: TByteData);
|
---|
| 206 | var
|
---|
| 207 | data: TStream;
|
---|
| 208 | begin
|
---|
| 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;
|
---|
| 217 | end;
|
---|
| 218 |
|
---|
| 219 | procedure TDataAccess.LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TByteData);
|
---|
| 220 | var
|
---|
| 221 | data: TStream;
|
---|
| 222 | begin
|
---|
| 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;
|
---|
| 232 | end;
|
---|
| 233 |
|
---|
| 234 | procedure TDataAccess.LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; Target: Pointer);
|
---|
| 235 | var
|
---|
| 236 | data: TStream;
|
---|
| 237 | begin
|
---|
| 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;
|
---|
| 246 | end;
|
---|
| 247 |
|
---|
| 248 | procedure TDataAccess.UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: Pointer);
|
---|
| 249 | var
|
---|
| 250 | data: TStream;
|
---|
| 251 | begin
|
---|
| 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;
|
---|
| 260 | end;
|
---|
| 261 |
|
---|
| 262 |
|
---|
| 263 | function TDataAccess.AppendRawFile(LocSep: Boolean; Src: TStream): Integer;
|
---|
| 264 | begin
|
---|
| 265 | raise ENotImplemented.Create('ERROR: AppendRawFile not implemented here!!!');
|
---|
| 266 | end;
|
---|
| 267 |
|
---|
| 268 |
|
---|
| 269 | function TDataAccess.AppendRawFile(LocSep: Boolean; Src: TByteData): Integer;
|
---|
| 270 | var
|
---|
| 271 | data: TStream;
|
---|
| 272 | begin
|
---|
| 273 | data := TMemoryStream.Create;
|
---|
| 274 | data.Write(Src[0], Length(Src));
|
---|
| 275 | data.Seek(0, soFromBeginning);
|
---|
| 276 | Result := AppendRawFile(LocSep, data);
|
---|
| 277 | data.Free;
|
---|
| 278 | end;
|
---|
| 279 | {
|
---|
| 280 | function TDataAccess.AppendRawFile(LocSep: Boolean; Size: Integer; Src: Pointer): Integer;
|
---|
| 281 | var
|
---|
| 282 | data: TStream;
|
---|
| 283 | begin
|
---|
| 284 | data := TMemoryStream.Create;
|
---|
| 285 | data.Write(Src^, Size);
|
---|
| 286 | data.Seek(0, soFromBeginning);
|
---|
| 287 | Result := AppendRawFile(LocSep, data);
|
---|
| 288 | data.Free;
|
---|
| 289 | end;
|
---|
| 290 | }
|
---|
| 291 |
|
---|
| 292 |
|
---|
| 293 | procedure TDataAccess.SetDataOS(DataOS: TDataOS);
|
---|
| 294 | begin
|
---|
| 295 | raise ENotImplemented.Create('TDataAccess.SetDataOS: TBD!');
|
---|
| 296 | end;
|
---|
| 297 |
|
---|
| 298 | end.
|
---|