source: oup/rewrite/DataAccess/DataAccess.pas@ 94

Last change on this file since 94 was 93, checked in by alloc, 18 years ago
File size: 6.0 KB
RevLine 
[93]1unit DataAccess;
2interface
3
4uses TypeDefs, Classes, StrUtils, SysUtils;
5//uses Data, Classes, SysUtils, StrUtils,
6// Dialogs, ABSDecUtil, ABSMain, DB, Windows;
7
8
9type
10 TDataAccess = class
11 private
12 FConnectionID: Integer;
13 FFileName: String;
14 FBackend: TDataBackend;
15 FLevelNumber: Integer;
16 FChangeRights: TChangeRights;
17 protected
18 public
19 property ConnectionID: Integer read FConnectionID;
20 property FileName: String read FFileName;
21 property Backend: TDataBackend read FBackend;
22 property LevelNumber: Integer read FLevelNumber;
23
24 constructor Create(FileName: String; ConnectionID: Integer; var Msg: TStatusMessages); virtual; abstract;
25 procedure Close; virtual; abstract;
26
27 function ExtractFileIDOfName(Name: String): Integer; virtual;
28 function GetFileInfo(FileID: Integer): TFileInfo; virtual;
29 function GetFileInfoByName(Name: String): TFileInfo; virtual;
30 function GetFilesList(Ext: String; Pattern: String;
31 NoEmptyFiles: Boolean; SortType: TSortType): TStrings; virtual; abstract;
32 function GetFileCount: Integer; virtual; abstract;
33 function GetExtensionsList(ExtListFormat: TExtensionFormat): TStrings; virtual; abstract;
34
35 procedure LoadDatFile(FileID: Integer; var Target: TStream); overload; virtual; abstract;
36 procedure LoadDatFile(FileID: Integer; var Target: TByteArray); overload; virtual; abstract;
37 procedure UpdateDatFile(FileID: Integer; Src: TStream); overload; virtual; abstract;
38 procedure UpdateDatFile(FileID: Integer; Src: TByteArray); overload; virtual; abstract;
39 procedure LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TStream); overload; virtual; abstract;
40 procedure LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TByteArray); overload; virtual; abstract;
41 procedure LoadDatFilePart(FileID, Offset, Size: Integer; Target: Pointer); overload; virtual; abstract;
42 procedure UpdateDatFilePart(FileID, Offset, Size: Integer; Src: TStream); overload; virtual; abstract;
43 procedure UpdateDatFilePart(FileID, Offset, Size: Integer; Src: TByteArray); overload; virtual; abstract;
44 procedure UpdateDatFilePart(FileID, Offset, Size: Integer; Src: Pointer); overload; virtual; abstract;
45
46 function GetRawList(FileID: Integer): TRawDataList; virtual; abstract;
47 function GetRawInfo(FileID, DatOffset: Integer): TRawDataInfo;
48
49 procedure LoadRawFile(FileID, DatOffset: Integer; var Target: TStream); overload; virtual; abstract;
50 procedure LoadRawFile(FileID, DatOffset: Integer; var Target: TByteArray); overload; virtual; abstract;
51 procedure UpdateRawFile(FileID, DatOffset, Size: Integer; Src: TStream); overload; virtual; abstract;
52 procedure UpdateRawFile(FileID, DatOffset, Size: Integer; Src: TByteArray); overload; virtual; abstract;
53 procedure LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TStream); overload; virtual; abstract;
54 procedure LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TByteArray); overload; virtual; abstract;
55 procedure LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; Target: Pointer); overload; virtual; abstract;
56 procedure UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: TStream); overload; virtual; abstract;
57 procedure UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: TByteArray); overload; virtual; abstract;
58 procedure UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: Pointer); overload; virtual; abstract;
59
60 function AppendRawFile(LocSep: Boolean; Size: Integer; Src: TStream): Integer; overload; virtual; abstract;
61 function AppendRawFile(LocSep: Boolean; Size: Integer; Src: TByteArray): Integer; overload; virtual; abstract;
62 function AppendRawFile(LocSep: Boolean; Size: Integer; Src: Pointer): Integer; overload; virtual; abstract;
63 published
64 end;
65
66
67
68
69
70{
71var
72 DataConnections: array of TOniData;
73
74function CreateDataConnection(filename: String; backend: Integer): TOniData;
75function ConnectionExists(filename: String): TOniData;
76procedure CloseDataConnection(connection: TOniData);
77function GetEmptyFileInfo: TFileInfo;
78}
79
80
81implementation
82
83
84(*
85 Implementation of TDataAccess
86*)
87
88function TDataAccess.ExtractFileIDOfName(Name: String): Integer;
89begin
90 if Name[5] = '-' then
91 Result := StrToInt(MidStr(Name, 1, 4))
92 else
93 Result := StrToInt(MidStr(Name, 1, 5));
94end;
95
96
97function TDataAccess.GetFileInfo(FileID: Integer): TFileInfo;
98begin
99 Result.ID := -1;
100 Result.Name := '';
101 Result.Extension := '';
102 Result.Size := -1;
103 Result.FileType := 0;
104 Result.DatAddr := -1;
105end;
106
107
108function TDataAccess.GetFileInfoByName(Name: String): TFileInfo;
109var
110 i: Integer;
111 files: TStrings;
112begin
113 Result := GetFileInfo(-1);
114 files := GetFilesList('', Name, False, ST_IDAsc);
115 if files.Count = 0 then
116 else
117 begin
118 for i := 0 to files.Count - 1 do
119 begin
120 if MidStr(files.Strings[i], Pos('-', files.Strings[i]) + 1,
121 Length(files.Strings[i]) - Pos('-', files.Strings[i]) - 5) = name then
122 begin
123 Result := GetFileInfo(ExtractFileIDOfName(files.Strings[i]));
124 Break;
125 end;
126 end;
127 end;
128 files.Free;
129end;
130
131
132function TDataAccess.GetRawInfo(FileID, DatOffset: Integer): TRawDataInfo;
133var
134 i: LongWord;
135 RawList: TRawDataList;
136begin
137 RawList := GetRawList(FileID);
138 Result.SrcID := -1;
139 Result.SrcOffset := -1;
140 Result.RawAddr := -1;
141 Result.RawSize := -1;
142 if Length(RawList) > 0 then
143 begin
144 for i := 0 to High(RawList) do
145 begin
146 if RawList[i].SrcOffset = DatOffset then
147 begin
148 Result.SrcID := FileID;
149 Result.SrcOffset := RawList[i].SrcOffset;
150 Result.RawAddr := RawList[i].RawAddr;
151 Result.RawSize := RawList[i].RawSize;
152 Result.LocSep := RawList[i].LocSep;
153 Break;
154 end;
155 end;
156 end;
157end;
158
159
160
161end.
Note: See TracBrowser for help on using the repository browser.