[93] | 1 | unit Access_OUP_ADB;
|
---|
| 2 | interface
|
---|
| 3 |
|
---|
[101] | 4 | uses DataAccess, ABSMain, TypeDefs, Classes;
|
---|
[93] | 5 |
|
---|
| 6 | type
|
---|
| 7 | TAccess_OUP_ADB = class(TDataAccess)
|
---|
| 8 | private
|
---|
[101] | 9 | FDatabase: TABSDatabase;
|
---|
| 10 | FQuery: TABSQuery;
|
---|
| 11 | Fdat_files: TFiles;
|
---|
[93] | 12 | Fdat_extensionsmap: TExtensionsMap;
|
---|
| 13 | protected
|
---|
| 14 | public
|
---|
[101] | 15 | constructor Create(DBFilename: String; ConnectionID: Integer; var Msg: TStatusMessages); override;
|
---|
[93] | 16 | procedure Close; override;
|
---|
| 17 |
|
---|
| 18 | procedure UpdateListCache;
|
---|
| 19 |
|
---|
[106] | 20 | function GetLinksToFile(FileID: Integer): TLinks;
|
---|
| 21 | function GetLinksFromFile(FileID: Integer): TLinks;
|
---|
| 22 |
|
---|
[101] | 23 | function GetFileInfo(FileID: Integer): TFileInfo; override;
|
---|
| 24 | function GetFilesList(Ext: String; Pattern: String;
|
---|
| 25 | NoEmptyFiles: Boolean; SortType: TSortType): TStrings; override;
|
---|
| 26 | function GetFileCount: Integer; override;
|
---|
| 27 | function GetExtensionsList(ExtListFormat: TExtensionFormat): TStrings; override;
|
---|
[93] | 28 |
|
---|
[101] | 29 | procedure LoadDatFile(FileID: Integer; var Target: TStream); overload; override;
|
---|
| 30 | procedure UpdateDatFile(FileID: Integer; Src: TStream); overload; override;
|
---|
| 31 | procedure LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TStream); overload; override;
|
---|
| 32 | procedure UpdateDatFilePart(FileID, Offset, Size: Integer; Src: TStream); overload; override;
|
---|
| 33 |
|
---|
[113] | 34 | function GetDatLinks(FileID: Integer): TDatLinkList; override;
|
---|
[116] | 35 | function GetDatLink(FileID, DatOffset: Integer): TDatLink; override;
|
---|
[101] | 36 | function GetRawList(FileID: Integer): TRawDataList; override;
|
---|
| 37 | function GetRawInfo(FileID, DatOffset: Integer): TRawDataInfo; override;
|
---|
| 38 |
|
---|
| 39 | procedure LoadRawFile(FileID, DatOffset: Integer; var Target: TStream); overload; override;
|
---|
| 40 | procedure UpdateRawFile(FileID, DatOffset: Integer; Src: TStream); overload; override;
|
---|
| 41 | procedure LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TStream); overload; override;
|
---|
| 42 | procedure UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: TStream); overload; override;
|
---|
[93] | 43 | published
|
---|
[101] | 44 | end;
|
---|
[93] | 45 |
|
---|
| 46 |
|
---|
| 47 | implementation
|
---|
| 48 |
|
---|
[101] | 49 | uses
|
---|
[116] | 50 | SysUtils, Data, Functions, ABSDecUtil, DB, DatLinks;
|
---|
[93] | 51 |
|
---|
[101] | 52 |
|
---|
[93] | 53 | (*
|
---|
| 54 | ================================================================================
|
---|
| 55 | Implementation of TOniDataADB
|
---|
| 56 | *)
|
---|
| 57 |
|
---|
[101] | 58 |
|
---|
| 59 | constructor TAccess_OUP_ADB.Create(DBFilename: String; ConnectionID: Integer; var Msg: TStatusMessages);
|
---|
[93] | 60 | begin
|
---|
[101] | 61 | Msg := SM_UnknownError;
|
---|
| 62 | if not FileExists(DBFilename) then
|
---|
[93] | 63 | begin
|
---|
[101] | 64 | Msg := SM_FileNotFound;
|
---|
[93] | 65 | Exit;
|
---|
| 66 | end;
|
---|
[101] | 67 | FFileName := DBFilename;
|
---|
| 68 |
|
---|
[93] | 69 | FDatabase := TABSDatabase.Create(nil);
|
---|
[101] | 70 | FDatabase.DatabaseName := 'OLDBcon' + IntToStr(ConnectionID);
|
---|
| 71 | FDatabase.DatabaseFileName := DBFilename;
|
---|
[93] | 72 | FDatabase.Open;
|
---|
| 73 | FQuery := TABSQuery.Create(FDatabase);
|
---|
[101] | 74 | FQuery.DatabaseName := 'OLDBcon' + IntToStr(ConnectionID);
|
---|
[93] | 75 | FQuery.SQL.Text := 'SELECT [name],[value] FROM globals ORDER BY [name] ASC';
|
---|
| 76 | FQuery.Open;
|
---|
| 77 | FQuery.First;
|
---|
| 78 | repeat
|
---|
| 79 | if FQuery.FieldByName('name').AsString = 'dbversion' then
|
---|
| 80 | begin
|
---|
| 81 | if FQuery.FieldByName('value').AsString <> DBversion then
|
---|
| 82 | begin
|
---|
[101] | 83 | Msg := SM_IncompatibleDBVersion;
|
---|
[93] | 84 | FQuery.Close;
|
---|
| 85 | Exit;
|
---|
| 86 | end;
|
---|
| 87 | end;
|
---|
| 88 | if FQuery.FieldByName('name').AsString = 'lvl' then
|
---|
[101] | 89 | FLevelNumber := StrToInt(FQuery.FieldByName('value').AsString);
|
---|
| 90 | if FQuery.FieldByName('name').AsString = 'DataOS' then
|
---|
[93] | 91 | begin
|
---|
[101] | 92 | if FQuery.FieldByName('value').AsString = 'WIN' then
|
---|
| 93 | FDataOS := DOS_WIN
|
---|
| 94 | else if FQuery.FieldByName('value').AsString = 'WINDEMO' then
|
---|
| 95 | FDataOS := DOS_WINDEMO
|
---|
| 96 | else if FQuery.FieldByName('value').AsString = 'MAC' then
|
---|
| 97 | FDataOS := DOS_MAC
|
---|
| 98 | else if FQuery.FieldByName('value').AsString = 'MACBETA' then
|
---|
| 99 | FDataOS := DOS_MACBETA;
|
---|
[93] | 100 | end;
|
---|
| 101 | FQuery.Next;
|
---|
| 102 | until FQuery.EOF;
|
---|
| 103 | FQuery.Close;
|
---|
| 104 |
|
---|
[101] | 105 | Msg := SM_OK;
|
---|
| 106 | FBackend := DB_ADB;
|
---|
| 107 |
|
---|
[105] | 108 | FConnectionID := ConnectionID;
|
---|
[101] | 109 | FChangeRights := [CR_EditDat, CR_EditRaw, CR_ResizeDat, CR_ResizeRaw];
|
---|
| 110 |
|
---|
[93] | 111 | UpdateListCache;
|
---|
| 112 | end;
|
---|
| 113 |
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 |
|
---|
[101] | 117 | procedure TAccess_OUP_ADB.Close;
|
---|
[93] | 118 | begin
|
---|
[101] | 119 | FQuery.Free;
|
---|
[93] | 120 | FDatabase.Close;
|
---|
| 121 | FDatabase.Free;
|
---|
| 122 | Self.Free;
|
---|
| 123 | end;
|
---|
| 124 |
|
---|
| 125 |
|
---|
| 126 |
|
---|
[101] | 127 | procedure TAccess_OUP_ADB.UpdateListCache;
|
---|
[93] | 128 | var
|
---|
[101] | 129 | i: Integer;
|
---|
[93] | 130 | temps: String;
|
---|
| 131 | begin
|
---|
| 132 | FQuery.SQL.Text := 'SELECT id,name,extension,[size],contenttype FROM datfiles ORDER BY id ASC;';
|
---|
| 133 | FQuery.Open;
|
---|
[101] | 134 | SetLength(Fdat_files, FQuery.RecordCount);
|
---|
[93] | 135 | if FQuery.RecordCount > 0 then
|
---|
| 136 | begin
|
---|
| 137 | FQuery.First;
|
---|
| 138 | i := 0;
|
---|
| 139 | repeat
|
---|
| 140 | Fdat_files[i].ID := FQuery.FieldByName('id').AsInteger;
|
---|
| 141 | Fdat_files[i].Name := FQuery.FieldByName('name').AsString;
|
---|
| 142 | Fdat_files[i].Extension := FQuery.FieldByName('extension').AsString;
|
---|
| 143 | Fdat_files[i].Size := FQuery.FieldByName('size').AsInteger;
|
---|
[113] | 144 | Fdat_files[i].FileType := StrToInt('$'+FQuery.FieldByName('contenttype').AsString);
|
---|
[93] | 145 | Fdat_files[i].DatAddr := 0;
|
---|
| 146 | Inc(i);
|
---|
| 147 | FQuery.Next;
|
---|
| 148 | until FQuery.EOF;
|
---|
| 149 | end;
|
---|
| 150 | FQuery.Close;
|
---|
| 151 |
|
---|
| 152 | FQuery.SQL.Text :=
|
---|
| 153 | 'SELECT extension,count(extension) AS x FROM datfiles GROUP BY extension ORDER BY extension ASC;';
|
---|
| 154 | FQuery.Open;
|
---|
[101] | 155 | SetLength(Fdat_extensionsmap, FQuery.RecordCount);
|
---|
[93] | 156 | if FQuery.RecordCount > 0 then
|
---|
| 157 | begin
|
---|
| 158 | i := 0;
|
---|
| 159 | repeat
|
---|
[101] | 160 | temps := FQuery.FieldByName('extension').AsString;
|
---|
[93] | 161 | Fdat_extensionsmap[i].Extension[3] := temps[1];
|
---|
| 162 | Fdat_extensionsmap[i].Extension[2] := temps[2];
|
---|
| 163 | Fdat_extensionsmap[i].Extension[1] := temps[3];
|
---|
| 164 | Fdat_extensionsmap[i].Extension[0] := temps[4];
|
---|
| 165 | Fdat_extensionsmap[i].ExtCount := FQuery.FieldByName('x').AsInteger;
|
---|
| 166 | Inc(i);
|
---|
| 167 | FQuery.Next;
|
---|
| 168 | until FQuery.EOF;
|
---|
| 169 | end;
|
---|
| 170 | FQuery.Close;
|
---|
| 171 | end;
|
---|
| 172 |
|
---|
| 173 |
|
---|
[106] | 174 |
|
---|
| 175 | function TAccess_OUP_ADB.GetLinksToFile(FileID: Integer): TLinks;
|
---|
| 176 | var
|
---|
| 177 | i: Integer;
|
---|
| 178 | begin
|
---|
| 179 | SetLength(Result.ByName, 0);
|
---|
| 180 | FQuery.SQL.Text := 'SELECT src_link_offset, src_id FROM linkmap WHERE target_id = ' + IntToStr(FileID) + ' ORDER BY src_id ASC;';
|
---|
| 181 | FQuery.Open;
|
---|
| 182 | SetLength(Result.ByID, FQuery.RecordCount);
|
---|
| 183 | if FQuery.RecordCount > 0 then
|
---|
| 184 | begin
|
---|
| 185 | i := 0;
|
---|
| 186 | repeat
|
---|
| 187 | Result.ByID[i].SrcOffset := FQuery.FieldByName('src_link_offset').AsInteger;
|
---|
| 188 | Result.ByID[i].Destination := FQuery.FieldByName('src_id').AsInteger;
|
---|
| 189 | Inc(i);
|
---|
| 190 | FQuery.Next;
|
---|
| 191 | until FQuery.EOF;
|
---|
| 192 | end;
|
---|
| 193 | FQuery.Close;
|
---|
| 194 | end;
|
---|
| 195 |
|
---|
| 196 | function TAccess_OUP_ADB.GetLinksFromFile(FileID: Integer): TLinks;
|
---|
| 197 | var
|
---|
| 198 | i: Integer;
|
---|
| 199 | begin
|
---|
| 200 | SetLength(Result.ByName, 0);
|
---|
| 201 | FQuery.SQL.Text := 'SELECT src_link_offset, target_id FROM linkmap WHERE src_id = ' + IntToStr(FileID) + ' ORDER BY target_id ASC;';
|
---|
| 202 | FQuery.Open;
|
---|
| 203 | SetLength(Result.ByID, FQuery.RecordCount);
|
---|
| 204 | if FQuery.RecordCount > 0 then
|
---|
| 205 | begin
|
---|
| 206 | i := 0;
|
---|
| 207 | repeat
|
---|
| 208 | Result.ByID[i].SrcOffset := FQuery.FieldByName('src_link_offset').AsInteger;
|
---|
| 209 | Result.ByID[i].Destination := FQuery.FieldByName('target_id').AsInteger;
|
---|
| 210 | Inc(i);
|
---|
| 211 | FQuery.Next;
|
---|
| 212 | until FQuery.EOF;
|
---|
| 213 | end;
|
---|
| 214 | FQuery.Close;
|
---|
| 215 | end;
|
---|
| 216 |
|
---|
| 217 |
|
---|
| 218 |
|
---|
[101] | 219 | function TAccess_OUP_ADB.GetFileInfo(fileid: Integer): TFileInfo;
|
---|
[93] | 220 | begin
|
---|
| 221 | if fileid = -1 then
|
---|
| 222 | begin
|
---|
| 223 | Result := inherited GetFileInfo(fileid);
|
---|
| 224 | Exit;
|
---|
| 225 | end;
|
---|
[101] | 226 | if fileid < Self.GetFileCount then
|
---|
| 227 | Result := Fdat_files[fileid]
|
---|
[93] | 228 | else
|
---|
| 229 | Result.ID := -1;
|
---|
| 230 | end;
|
---|
| 231 |
|
---|
| 232 |
|
---|
| 233 |
|
---|
| 234 |
|
---|
[101] | 235 | function TAccess_OUP_ADB.GetFilesList(ext: String; pattern: String;
|
---|
| 236 | NoEmptyFiles: Boolean; SortType: TSortType): TStrings;
|
---|
[93] | 237 | var
|
---|
[101] | 238 | i: Integer;
|
---|
| 239 | list: TStringList;
|
---|
[93] | 240 | id, name, extension: String;
|
---|
| 241 | fields: TStrings;
|
---|
| 242 |
|
---|
| 243 | procedure getfields;
|
---|
| 244 | begin
|
---|
[101] | 245 | fields.CommaText := StringReplace(AnsiQuotedStr(list.Strings[i], '"'), ';', '","', [rfReplaceAll]);
|
---|
| 246 | if SortType in [ST_IDAsc, ST_IDDesc] then
|
---|
[93] | 247 | begin
|
---|
| 248 | id := fields.Strings[0];
|
---|
| 249 | name := fields.Strings[1];
|
---|
| 250 | extension := fields.Strings[2];
|
---|
| 251 | end;
|
---|
[101] | 252 | if SortType in [ST_NameAsc, ST_NameDesc] then
|
---|
[93] | 253 | begin
|
---|
| 254 | id := fields.Strings[1];
|
---|
| 255 | name := fields.Strings[0];
|
---|
| 256 | extension := fields.Strings[2];
|
---|
| 257 | end;
|
---|
[101] | 258 | if SortType in [ST_ExtAsc, ST_ExtDesc] then
|
---|
[93] | 259 | begin
|
---|
| 260 | id := fields.Strings[1];
|
---|
| 261 | name := fields.Strings[2];
|
---|
| 262 | extension := fields.Strings[0];
|
---|
| 263 | end;
|
---|
[112] | 264 | if SortType in [ST_ExtNameAsc, ST_ExtNameDesc] then
|
---|
| 265 | begin
|
---|
| 266 | id := fields.Strings[2];
|
---|
| 267 | name := fields.Strings[1];
|
---|
| 268 | extension := fields.Strings[0];
|
---|
| 269 | end;
|
---|
[93] | 270 | end;
|
---|
| 271 |
|
---|
| 272 | begin
|
---|
| 273 | list := TStringList.Create;
|
---|
| 274 | list.Sorted := True;
|
---|
[101] | 275 | for i := 0 to GetFileCount - 1 do
|
---|
[93] | 276 | begin
|
---|
| 277 | if ((Length(ext) = 0) or (Pos(Fdat_files[i].Extension, ext) > 0)) and
|
---|
| 278 | ((Length(pattern) = 0) or
|
---|
| 279 | (Pos(UpperCase(pattern), UpperCase(Fdat_files[i].Name)) > 0)) then
|
---|
| 280 | begin
|
---|
| 281 | if (NoEmptyFiles = False) or ((Fdat_files[i].FileType and $02) = 0) then
|
---|
| 282 | begin
|
---|
[112] | 283 | id := FormatNumber(Fdat_files[i].ID, 5, '0');
|
---|
[93] | 284 | name := Fdat_files[i].Name;
|
---|
| 285 | extension := Fdat_files[i].Extension;
|
---|
| 286 |
|
---|
[101] | 287 | case SortType of
|
---|
| 288 | ST_IDAsc, ST_IDDesc: list.Add(id + ';' + name + ';' + extension);
|
---|
| 289 | ST_NameAsc, ST_NameDesc: list.Add(name + ';' + id + ';' + extension);
|
---|
| 290 | ST_ExtAsc, ST_ExtDesc: list.Add(extension + ';' + id + ';' + name);
|
---|
[112] | 291 | ST_ExtNameAsc, ST_ExtNameDesc: list.Add(name + ';' + extension + ';' + id);
|
---|
[93] | 292 | end;
|
---|
| 293 | end;
|
---|
| 294 | end;
|
---|
| 295 | end;
|
---|
[113] | 296 | if not Assigned(Result) then
|
---|
| 297 | Result := TStringList.Create;
|
---|
[101] | 298 | if list.Count > 0 then
|
---|
| 299 | begin
|
---|
| 300 | fields := TStringList.Create;
|
---|
[112] | 301 | if SortType in [ST_IDAsc, ST_NameAsc, ST_ExtAsc, ST_ExtNameAsc] then
|
---|
[101] | 302 | for i := 0 to list.Count - 1 do
|
---|
| 303 | begin
|
---|
| 304 | getfields;
|
---|
| 305 | Result.Add(id + '-' + name + '.' + extension);
|
---|
| 306 | end
|
---|
| 307 | else
|
---|
| 308 | for i := list.Count - 1 downto 0 do
|
---|
| 309 | begin
|
---|
| 310 | getfields;
|
---|
| 311 | Result.Add(id + '-' + name + '.' + extension);
|
---|
| 312 | end;
|
---|
| 313 | fields.Free;
|
---|
| 314 | end;
|
---|
[93] | 315 | list.Free;
|
---|
| 316 | end;
|
---|
| 317 |
|
---|
| 318 |
|
---|
| 319 |
|
---|
| 320 |
|
---|
[101] | 321 | function TAccess_OUP_ADB.GetFileCount: Integer;
|
---|
[93] | 322 | begin
|
---|
| 323 | Result := Length(Fdat_files);
|
---|
| 324 | end;
|
---|
| 325 |
|
---|
| 326 |
|
---|
[101] | 327 | function TAccess_OUP_ADB.GetExtensionsList(ExtListFormat: TExtensionFormat): TStrings;
|
---|
[93] | 328 | var
|
---|
[101] | 329 | i: Integer;
|
---|
[93] | 330 | begin
|
---|
[113] | 331 | if not Assigned(Result) then
|
---|
| 332 | Result := TStringList.Create;
|
---|
| 333 | if Result is TStringList then
|
---|
| 334 | TStringList(Result).Sorted := True;
|
---|
[101] | 335 | for i := 0 to Length(Fdat_extensionsmap) - 1 do
|
---|
[93] | 336 | begin
|
---|
| 337 | with Fdat_extensionsmap[i] do
|
---|
| 338 | begin
|
---|
[101] | 339 | case ExtListFormat of
|
---|
| 340 | EF_ExtOnly:
|
---|
| 341 | Result.Add(Extension[3] + Extension[2] + Extension[1] + Extension[0]);
|
---|
| 342 | EF_ExtCount:
|
---|
| 343 | Result.Add(Extension[3] + Extension[2] + Extension[1] + Extension[0] +
|
---|
| 344 | ' (' + IntToStr(ExtCount) + ')');
|
---|
| 345 | end;
|
---|
[93] | 346 | end;
|
---|
| 347 | end;
|
---|
| 348 | end;
|
---|
| 349 |
|
---|
| 350 |
|
---|
[101] | 351 | procedure TAccess_OUP_ADB.LoadDatFile(FileID: Integer; var Target: TStream);
|
---|
[93] | 352 | var
|
---|
[101] | 353 | mem: TStream;
|
---|
| 354 | streampos: Integer;
|
---|
[93] | 355 | begin
|
---|
[101] | 356 | if fileid < GetFileCount then
|
---|
[93] | 357 | begin
|
---|
[101] | 358 | if not Assigned(Target) then
|
---|
| 359 | Target := TMemoryStream.Create;
|
---|
[93] | 360 |
|
---|
[101] | 361 | streampos := Target.Position;
|
---|
[93] | 362 |
|
---|
| 363 | FQuery.SQL.Text := 'SELECT data FROM datfiles WHERE id=' + IntToStr(fileid) + ';';
|
---|
| 364 | FQuery.Open;
|
---|
| 365 | if FQuery.RecordCount > 0 then
|
---|
| 366 | begin
|
---|
| 367 | mem := FQuery.CreateBlobStream(FQuery.FieldByName('data'), bmRead);
|
---|
| 368 | mem.Seek(0, soFromBeginning);
|
---|
[101] | 369 | Target.CopyFrom(mem, mem.Size);
|
---|
[93] | 370 | mem.Free;
|
---|
| 371 | end;
|
---|
| 372 | FQuery.Close;
|
---|
[101] | 373 |
|
---|
| 374 | Target.Seek(streampos, soFromBeginning);
|
---|
[93] | 375 | end;
|
---|
| 376 | end;
|
---|
| 377 |
|
---|
[101] | 378 | procedure TAccess_OUP_ADB.UpdateDatFile(FileID: Integer; Src: TStream);
|
---|
[93] | 379 | var
|
---|
| 380 | MimeCoder: TStringFormat_MIME64;
|
---|
| 381 | mem: TMemoryStream;
|
---|
| 382 | begin
|
---|
[101] | 383 | if fileid < GetFileCount then
|
---|
[93] | 384 | begin
|
---|
| 385 | mimecoder := TStringFormat_MIME64.Create;
|
---|
| 386 | mem := TMemoryStream.Create;
|
---|
[101] | 387 | mem.CopyFrom(Src, Src.Size);
|
---|
[93] | 388 | FQuery.SQL.Text := 'UPDATE datfiles SET data=MimeToBin("' +
|
---|
| 389 | MimeCoder.StrTo(mem.Memory, mem.Size) + '"), size=' + IntToStr(mem.Size) +
|
---|
| 390 | ' WHERE id=' + IntToStr(fileid) + ';';
|
---|
| 391 | FQuery.ExecSQL;
|
---|
| 392 | mem.Free;
|
---|
| 393 | mimecoder.Free;
|
---|
| 394 | end;
|
---|
| 395 | end;
|
---|
| 396 |
|
---|
| 397 |
|
---|
| 398 |
|
---|
[101] | 399 | procedure TAccess_OUP_ADB.LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TStream);
|
---|
[93] | 400 | var
|
---|
[101] | 401 | streampos: Integer;
|
---|
[93] | 402 | mem: TStream;
|
---|
| 403 | begin
|
---|
[101] | 404 | if fileid < GetFileCount then
|
---|
[93] | 405 | begin
|
---|
[101] | 406 | if not Assigned(Target) then
|
---|
| 407 | Target := TMemoryStream.Create;
|
---|
| 408 | streampos := Target.Position;
|
---|
| 409 |
|
---|
[93] | 410 | FQuery.SQL.Text := 'SELECT data FROM datfiles WHERE id=' + IntToStr(fileid) + ';';
|
---|
| 411 | FQuery.Open;
|
---|
| 412 | if FQuery.RecordCount > 0 then
|
---|
| 413 | begin
|
---|
| 414 | mem := FQuery.CreateBlobStream(FQuery.FieldByName('data'), bmRead);
|
---|
| 415 | mem.Seek(offset, soFromBeginning);
|
---|
[101] | 416 | Target.CopyFrom(mem, size);
|
---|
[93] | 417 | mem.Free;
|
---|
| 418 | end;
|
---|
| 419 | FQuery.Close;
|
---|
[101] | 420 | Target.Seek(streampos, soFromBeginning);
|
---|
[93] | 421 | end;
|
---|
| 422 | end;
|
---|
| 423 |
|
---|
| 424 |
|
---|
| 425 |
|
---|
[101] | 426 | procedure TAccess_OUP_ADB.UpdateDatFilePart(FileID, Offset, Size: Integer; Src: TStream);
|
---|
[93] | 427 | var
|
---|
| 428 | MimeCoder: TStringFormat_MIME64;
|
---|
| 429 | mem: TMemoryStream;
|
---|
| 430 | begin
|
---|
[101] | 431 | if fileid < GetFileCount then
|
---|
[93] | 432 | begin
|
---|
[101] | 433 | mem := nil;
|
---|
| 434 | LoadDatFile(fileid, TStream(mem));
|
---|
| 435 | mem.Seek(Offset, soFromBeginning);
|
---|
| 436 | mem.CopyFrom(Src, Size);
|
---|
| 437 | mem.Seek(0, soFromBeginning);
|
---|
[93] | 438 | mimecoder := TStringFormat_MIME64.Create;
|
---|
| 439 | FQuery.SQL.Text := 'UPDATE datfiles SET data=MimeToBin("' +
|
---|
| 440 | MimeCoder.StrTo(mem.Memory, mem.Size) + '") WHERE id=' + IntToStr(fileid) + ';';
|
---|
| 441 | FQuery.ExecSQL;
|
---|
| 442 | mem.Free;
|
---|
| 443 | mimecoder.Free;
|
---|
| 444 | end;
|
---|
| 445 | end;
|
---|
| 446 |
|
---|
| 447 |
|
---|
[116] | 448 |
|
---|
| 449 | function TAccess_OUP_ADB.GetDatLink(FileID, DatOffset: Integer): TDatLink;
|
---|
| 450 | begin
|
---|
| 451 | Result := DatLinksManager.GetDatLink(FConnectionID, FileID, DatOffset);
|
---|
| 452 | FQuery.SQL.Text := 'SELECT target_id FROM linkmap WHERE src_id = ' + IntToStr(FileID) + ' and src_link_offset = ' + IntToStr(DatOffset) + ';';
|
---|
| 453 | FQuery.Open;
|
---|
| 454 | if FQuery.RecordCount > 0 then
|
---|
| 455 | Result.DestID := FQuery.FieldByName('target_id').AsInteger;
|
---|
| 456 | FQuery.Close;
|
---|
| 457 | end;
|
---|
| 458 |
|
---|
| 459 |
|
---|
| 460 | function TAccess_OUP_ADB.GetDatLinks(FileID: Integer): TDatLinkList;
|
---|
| 461 | var
|
---|
| 462 | i: Integer;
|
---|
| 463 | SrcOffset, DestID: Integer;
|
---|
| 464 | begin
|
---|
| 465 | Result := DatLinksManager.GetDatLinks(FConnectionID, FileID);
|
---|
| 466 | if Length(Result) > 0 then
|
---|
| 467 | begin
|
---|
| 468 | FQuery.SQL.Text := 'SELECT src_link_offset, target_id FROM linkmap WHERE src_id = ' + IntToStr(FileID) + ' ORDER BY src_link_offset ASC;';
|
---|
| 469 | FQuery.Open;
|
---|
| 470 | if FQuery.RecordCount > 0 then
|
---|
| 471 | begin
|
---|
| 472 | repeat
|
---|
| 473 | SrcOffset := FQuery.FieldByName('src_link_offset').AsInteger;
|
---|
| 474 | DestID := FQuery.FieldByName('target_id').AsInteger;
|
---|
| 475 | for i := 0 to High(Result) do
|
---|
| 476 | if Result[i].SrcOffset = SrcOffset then
|
---|
| 477 | Break;
|
---|
| 478 | if i < Length(Result) then
|
---|
| 479 | Result[i].DestID := DestID
|
---|
| 480 | else
|
---|
| 481 | Result[i].DestID := -1;
|
---|
| 482 | FQuery.Next;
|
---|
| 483 | until FQuery.EOF;
|
---|
| 484 | end;
|
---|
| 485 | FQuery.Close;
|
---|
| 486 | end;
|
---|
| 487 | end;
|
---|
| 488 |
|
---|
| 489 |
|
---|
[101] | 490 | function TAccess_OUP_ADB.GetRawList(FileID: Integer): TRawDataList;
|
---|
[93] | 491 | var
|
---|
[101] | 492 | i: Integer;
|
---|
[93] | 493 | begin
|
---|
| 494 | SetLength(Result, 0);
|
---|
| 495 | FQuery.SQL.Text := 'SELECT [src_link_offset],[size],[sep] FROM rawmap WHERE [src_id]=' +
|
---|
| 496 | IntToStr(fileid) + ' ORDER BY src_link_offset ASC;';
|
---|
| 497 | FQuery.Open;
|
---|
| 498 | if FQuery.RecordCount > 0 then
|
---|
| 499 | begin
|
---|
| 500 | FQuery.First;
|
---|
| 501 | SetLength(Result, FQuery.RecordCount);
|
---|
| 502 | i := 0;
|
---|
| 503 | repeat
|
---|
[101] | 504 | Result[i].SrcID := fileid;
|
---|
| 505 | Result[i].SrcOffset := FQuery.FieldByName('src_link_offset').AsInteger;
|
---|
| 506 | Result[i].RawAddr := 0;
|
---|
| 507 | Result[i].RawSize := FQuery.FieldByName('size').AsInteger;
|
---|
| 508 | Result[i].LocSep := FQuery.FieldByName('sep').AsBoolean;
|
---|
[93] | 509 | Inc(i);
|
---|
| 510 | FQuery.Next;
|
---|
| 511 | until FQuery.EOF;
|
---|
| 512 | end;
|
---|
| 513 | FQuery.Close;
|
---|
| 514 | end;
|
---|
| 515 |
|
---|
| 516 |
|
---|
[101] | 517 | function TAccess_OUP_ADB.GetRawInfo(FileID, DatOffset: Integer): TRawDataInfo;
|
---|
| 518 | var
|
---|
| 519 | i: Integer;
|
---|
| 520 | rawlist: TRawDataList;
|
---|
| 521 | begin
|
---|
| 522 | rawlist := GetRawList(FileID);
|
---|
| 523 | if Length(rawlist) > 0 then
|
---|
| 524 | begin
|
---|
| 525 | for i := 0 to High(rawlist) do
|
---|
| 526 | if rawlist[i].SrcOffset = DatOffset then
|
---|
| 527 | Break;
|
---|
| 528 | if i < Length(rawlist) then
|
---|
| 529 | Result := rawlist[i]
|
---|
| 530 | else begin
|
---|
| 531 | Result.SrcID := -1;
|
---|
| 532 | Result.SrcOffset := -1;
|
---|
| 533 | Result.RawAddr := -1;
|
---|
| 534 | Result.RawSize := -1;
|
---|
| 535 | end;
|
---|
| 536 | end;
|
---|
| 537 | end;
|
---|
[93] | 538 |
|
---|
| 539 |
|
---|
[101] | 540 |
|
---|
| 541 | procedure TAccess_OUP_ADB.LoadRawFile(FileID, DatOffset: Integer; var Target: TStream);
|
---|
[93] | 542 | var
|
---|
| 543 | mem: TStream;
|
---|
[101] | 544 | streampos: Integer;
|
---|
[93] | 545 | begin
|
---|
[101] | 546 | if fileid < GetFileCount then
|
---|
[93] | 547 | begin
|
---|
[101] | 548 | if not Assigned(Target) then
|
---|
| 549 | Target := TMemoryStream.Create;
|
---|
| 550 | streampos := Target.Position;
|
---|
[93] | 551 | FQuery.SQL.Text := 'SELECT data FROM rawmap WHERE (src_id=' +
|
---|
[101] | 552 | IntToStr(FileID) + ') AND (src_link_offset=' + IntToStr(DatOffset) + ');';
|
---|
[93] | 553 | FQuery.Open;
|
---|
| 554 | if FQuery.RecordCount > 0 then
|
---|
| 555 | begin
|
---|
| 556 | mem := FQuery.CreateBlobStream(FQuery.FieldByName('data'), bmRead);
|
---|
| 557 | mem.Seek(0, soFromBeginning);
|
---|
[101] | 558 | Target.CopyFrom(mem, mem.Size);
|
---|
[93] | 559 | mem.Free;
|
---|
| 560 | end;
|
---|
| 561 | FQuery.Close;
|
---|
[101] | 562 | Target.Seek(streampos, soFromBeginning);
|
---|
[93] | 563 | end;
|
---|
| 564 | end;
|
---|
| 565 |
|
---|
| 566 |
|
---|
[101] | 567 | procedure TAccess_OUP_ADB.UpdateRawFile(FileID, DatOffset: Integer; Src: TStream);
|
---|
[93] | 568 | var
|
---|
| 569 | MimeCoder: TStringFormat_MIME64;
|
---|
| 570 | mem: TMemoryStream;
|
---|
| 571 | begin
|
---|
[101] | 572 | if fileid < GetFileCount then
|
---|
[93] | 573 | begin
|
---|
| 574 | mimecoder := TStringFormat_MIME64.Create;
|
---|
| 575 | mem := TMemoryStream.Create;
|
---|
[101] | 576 | mem.CopyFrom(Src, Src.Size);
|
---|
[93] | 577 | mem.Seek(0, soFromBeginning);
|
---|
| 578 | FQuery.SQL.Text := 'UPDATE rawmap SET data=MimeToBin("' + MimeCoder.StrTo(
|
---|
[101] | 579 | mem.Memory, mem.Size) + '") WHERE (src_id=' + IntToStr(FileID) +
|
---|
| 580 | ') AND (src_link_offset=' + IntToStr(DatOffset) + ');';
|
---|
[93] | 581 | FQuery.ExecSQL;
|
---|
| 582 | mem.Free;
|
---|
| 583 | mimecoder.Free;
|
---|
| 584 | end;
|
---|
| 585 | end;
|
---|
| 586 |
|
---|
| 587 |
|
---|
| 588 |
|
---|
| 589 |
|
---|
[101] | 590 | procedure TAccess_OUP_ADB.LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TStream);
|
---|
[93] | 591 | var
|
---|
| 592 | mem: TMemoryStream;
|
---|
[101] | 593 | streampos: Integer;
|
---|
[93] | 594 | begin
|
---|
[101] | 595 | if fileid < GetFileCount then
|
---|
[93] | 596 | begin
|
---|
[101] | 597 | if not Assigned(Target) then
|
---|
| 598 | Target := TMemoryStream.Create;
|
---|
| 599 | streampos := Target.Position;
|
---|
| 600 | mem := nil;
|
---|
| 601 | LoadRawFile(FileID, DatOffset, TStream(mem));
|
---|
| 602 | mem.Seek(Offset, soFromBeginning);
|
---|
| 603 | Target.CopyFrom(mem, Size);
|
---|
[93] | 604 | mem.Free;
|
---|
[101] | 605 | Target.Seek(streampos, soFromBeginning);
|
---|
[93] | 606 | end;
|
---|
| 607 | end;
|
---|
| 608 |
|
---|
| 609 |
|
---|
| 610 |
|
---|
| 611 |
|
---|
[101] | 612 | procedure TAccess_OUP_ADB.UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: TStream);
|
---|
[93] | 613 | var
|
---|
| 614 | MimeCoder: TStringFormat_MIME64;
|
---|
| 615 | mem: TMemoryStream;
|
---|
| 616 | begin
|
---|
[101] | 617 | if fileid < GetFileCount then
|
---|
[93] | 618 | begin
|
---|
[101] | 619 | mem := nil;
|
---|
| 620 | LoadRawFile(fileid, offset, TStream(mem));
|
---|
[93] | 621 | mem.Seek(offset, soFromBeginning);
|
---|
[101] | 622 | mem.CopyFrom(Src, Size);
|
---|
[93] | 623 | mem.Seek(0, soFromBeginning);
|
---|
[101] | 624 | mimecoder := TStringFormat_MIME64.Create;
|
---|
[93] | 625 | FQuery.SQL.Text := 'UPDATE rawmap SET data=MimeToBin("' + MimeCoder.StrTo(
|
---|
| 626 | mem.Memory, mem.Size) + '") WHERE (src_id=' + IntToStr(fileid) +
|
---|
[101] | 627 | ') AND (src_link_offset=' + IntToStr(DatOffset) + ');';
|
---|
[93] | 628 | FQuery.ExecSQL;
|
---|
| 629 | mem.Free;
|
---|
| 630 | mimecoder.Free;
|
---|
| 631 | end;
|
---|
| 632 | end;
|
---|
| 633 |
|
---|
| 634 |
|
---|
| 635 |
|
---|
[101] | 636 |
|
---|
[93] | 637 | end.
|
---|