Ignore:
Timestamp:
Feb 20, 2007, 9:43:29 PM (18 years ago)
Author:
alloc
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • oup/rewrite/DataAccess/Access_OUP_ADB.pas

    r93 r101  
    22interface
    33
    4 uses DataAccess;
     4uses DataAccess, ABSMain, TypeDefs, Classes;
    55
    66type
    77  TAccess_OUP_ADB = class(TDataAccess)
    88  private
    9 {    FDatabase: TABSDatabase;
    10     FQuery:    TABSQuery;
    11     Fdat_files:    TFiles;
     9    FDatabase:          TABSDatabase;
     10    FQuery:             TABSQuery;
     11    Fdat_files:         TFiles;
    1212    Fdat_extensionsmap: TExtensionsMap;
    1313  protected
    1414  public
    15     constructor Create(OLDBFilename: String; var Result: Boolean); override;
     15    constructor Create(DBFilename: String; ConnectionID: Integer; var Msg: TStatusMessages); override;
    1616    procedure Close; override;
    1717
    1818    procedure UpdateListCache;
    19     //      function GetDatLinks(srcid:LongWord):TDatLinks;
    20     function GetFileInfo(fileid: Integer): TFileInfo; override;
    21     function GetFilesList(ext: String; pattern: String;
    22       NoEmptyFiles: Boolean; sort: TSortType): TStringArray; override;
    23     function GetFilesCount: LongWord; override;
    24     function GetExtensionsList: TStringArray; override;
    25     function GetExtendedExtensionsList: TExtensionsMap; override;
    26     function GetNamedFilesMap: TNamedFilesMap;
    27 
    28     function LoadDatFile(fileid: LongWord): Tdata; override;
    29     procedure UpdateDatFile(fileid: LongWord; Data: Tdata); override;
    30     procedure LoadDatFilePart(fileid, offset, size: LongWord; target: Pointer); override;
    31     procedure UpdateDatFilePart(fileid, offset, size: LongWord; target: Pointer); override;
    32 
    33     function GetRawList(fileid: LongWord): TRawList; override;
    34     procedure LoadRawFile(fileid, dat_offset: LongWord; target: Pointer); override;
    35     procedure UpdateRawFile(fileid, dat_offset: LongWord; size: LongWord;
    36       target: Pointer); override;
    37     procedure LoadRawFilePart(fileid, dat_offset: LongWord;
    38       offset, size: LongWord; target: Pointer); override;
    39     procedure UpdateRawFilePart(fileid, dat_offset: LongWord;
    40       offset, size: LongWord; target: Pointer); override;
     19
     20    function GetFileInfo(FileID: Integer): TFileInfo; override;
     21    function GetFilesList(Ext: String; Pattern: String;
     22      NoEmptyFiles: Boolean; SortType: TSortType): TStrings; override;
     23    function GetFileCount: Integer; override;
     24    function GetExtensionsList(ExtListFormat: TExtensionFormat): TStrings; override;
     25
     26    procedure LoadDatFile(FileID: Integer; var Target: TStream); overload; override;
     27    procedure UpdateDatFile(FileID: Integer; Src: TStream); overload; override;
     28    procedure LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TStream); overload; override;
     29    procedure UpdateDatFilePart(FileID, Offset, Size: Integer; Src: TStream); overload; override;
     30
     31    function GetRawList(FileID: Integer): TRawDataList; override;
     32    function GetRawInfo(FileID, DatOffset: Integer): TRawDataInfo; override;
     33
     34    procedure LoadRawFile(FileID, DatOffset: Integer; var Target: TStream); overload; override;
     35    procedure UpdateRawFile(FileID, DatOffset: Integer; Src: TStream); overload; override;
     36    procedure LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TStream); overload; override;
     37    procedure UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: TStream); overload; override;
    4138  published
    42 }  end;
     39  end;
    4340
    4441
    4542implementation
     43
     44uses
     45  SysUtils, Data, Functions, ABSDecUtil, DB;
    4646
    4747
     
    5151*)
    5252
    53 {
    54 constructor TOniDataADB.Create(OLDBFilename: String; var Result: Boolean);
    55 var
    56   i, j:  Byte;
    57   temps: String;
    58 begin
    59   if not FileExists(OLDBFilename) then
    60   begin
    61     ShowMessage('File doesn''t exist!!!');
    62     Result := False;
     53
     54constructor TAccess_OUP_ADB.Create(DBFilename: String; ConnectionID: Integer; var Msg: TStatusMessages);
     55var
     56  i: Integer;
     57begin
     58  Msg := SM_UnknownError;
     59  if not FileExists(DBFilename) then
     60  begin
     61    Msg := SM_FileNotFound;
    6362    Exit;
    6463  end;
    65   FFileName := OLDBFilename;
     64  FFileName := DBFilename;
     65
    6666  FDatabase := TABSDatabase.Create(nil);
    67   FDatabase.DatabaseName := 'OLDBcon';
    68   FDatabase.DatabaseFileName := OLDBFilename;
     67  FDatabase.DatabaseName := 'OLDBcon' + IntToStr(ConnectionID);
     68  FDatabase.DatabaseFileName := DBFilename;
    6969  FDatabase.Open;
    7070  FQuery := TABSQuery.Create(FDatabase);
    71   FQuery.DatabaseName := 'OLDBcon';
     71  FQuery.DatabaseName := 'OLDBcon' + IntToStr(ConnectionID);
    7272  FQuery.SQL.Text := 'SELECT [name],[value] FROM globals ORDER BY [name] ASC';
    7373  FQuery.Open;
     
    7878      if FQuery.FieldByName('value').AsString <> DBversion then
    7979      begin
    80         ShowMessage('Database-file ' + #13 + #10 +
    81           '"' + OLDBFilename + '"' + #13 + #10 +
    82           'has wrong version. (Required: ' + DBversion + '; found: ' +
    83           FQuery.FieldByName('value').AsString + ')');
     80        Msg := SM_IncompatibleDBVersion;
    8481        FQuery.Close;
    85         Result := False;
    8682        Exit;
    8783      end;
    8884    end;
    8985    if FQuery.FieldByName('name').AsString = 'lvl' then
    90     begin
    91       FLevelInfo.LevelNumber := StrToInt(FQuery.FieldByName('value').AsString);
    92     end;
    93     if FQuery.FieldByName('name').AsString = 'ident' then
    94     begin
    95       temps := FQuery.FieldByName('value').AsString;
    96       for i := 0 to High(FLevelInfo.Ident) do
    97       begin
    98         j := i * 2 + 1;
    99         case temps[j] of
    100           '0'..'9':
    101             FLevelInfo.Ident[i] := Ord(temps[j]) - 48;
    102           'A'..'F':
    103             FLevelInfo.Ident[i] := Ord(temps[j]) - 55;
    104         end;
    105         FLevelInfo.Ident[i] := FLevelInfo.Ident[i] * 16;
    106         case temps[j + 1] of
    107           '0'..'9':
    108             FLevelInfo.Ident[i] := FLevelInfo.Ident[i] + Ord(temps[j + 1]) - 48;
    109           'A'..'F':
    110             FLevelInfo.Ident[i] := FLevelInfo.Ident[i] + Ord(temps[j + 1]) - 55;
    111         end;
    112       end;
    113     end;
    114     if FQuery.FieldByName('name').AsString = 'ident' then
    115     begin
    116       temps   := FQuery.FieldByName('value').AsString;
    117       Fos_mac := temps = 'MAC';
     86      FLevelNumber := StrToInt(FQuery.FieldByName('value').AsString);
     87    if FQuery.FieldByName('name').AsString = 'DataOS' then
     88    begin
     89      if FQuery.FieldByName('value').AsString = 'WIN' then
     90        FDataOS := DOS_WIN
     91      else if FQuery.FieldByName('value').AsString = 'WINDEMO' then
     92        FDataOS := DOS_WINDEMO
     93      else if FQuery.FieldByName('value').AsString = 'MAC' then
     94        FDataOS := DOS_MAC
     95      else if FQuery.FieldByName('value').AsString = 'MACBETA' then
     96        FDataOS := DOS_MACBETA;
    11897    end;
    11998    FQuery.Next;
     
    121100  FQuery.Close;
    122101
     102  Msg := SM_OK;
     103  FBackend := DB_ADB;
     104
     105  FChangeRights := [CR_EditDat, CR_EditRaw, CR_ResizeDat, CR_ResizeRaw];
     106
    123107  UpdateListCache;
    124 
    125   Result   := True;
    126   FBackend := ODB_ADB;
    127 end;
    128 
    129 
    130 
    131 
    132 procedure TOniDataADB.Close;
    133 begin
     108end;
     109
     110
     111
     112
     113procedure TAccess_OUP_ADB.Close;
     114begin
     115  FQuery.Free;
    134116  FDatabase.Close;
    135117  FDatabase.Free;
     
    139121
    140122
    141 procedure TOniDataADB.UpdateListCache;
    142 var
    143   i:     LongWord;
     123procedure TAccess_OUP_ADB.UpdateListCache;
     124var
     125  i:     Integer;
    144126  temps: String;
    145127begin
    146128  FQuery.SQL.Text := 'SELECT id,name,extension,[size],contenttype FROM datfiles ORDER BY id ASC;';
    147129  FQuery.Open;
     130  SetLength(Fdat_files, FQuery.RecordCount);
    148131  if FQuery.RecordCount > 0 then
    149132  begin
    150133    FQuery.First;
    151     SetLength(Fdat_files, FQuery.RecordCount);
    152134    i := 0;
    153135    repeat
     
    155137      Fdat_files[i].Name := FQuery.FieldByName('name').AsString;
    156138      Fdat_files[i].Extension := FQuery.FieldByName('extension').AsString;
    157       Fdat_files[i].FileName := FormatNumber(Fdat_files[i].ID, 5, '0') + '-' +
    158           Fdat_files[i].Name + '.' + Fdat_files[0].Extension;
    159       Fdat_files[i].FileNameHex := IntToHex(Fdat_files[i].ID, 4) + '-' +
    160           Fdat_files[i].Name + '.' + Fdat_files[0].Extension;
    161139      Fdat_files[i].Size := FQuery.FieldByName('size').AsInteger;
    162140      Fdat_files[i].FileType := HexToLong(FQuery.FieldByName('contenttype').AsString);
    163141      Fdat_files[i].DatAddr := 0;
    164       Fdat_files[i].opened := False;
    165142      Inc(i);
    166143      FQuery.Next;
     
    169146  FQuery.Close;
    170147
    171   SetLength(Fdat_extensionsmap, 0);
    172148  FQuery.SQL.Text :=
    173149    'SELECT extension,count(extension) AS x FROM datfiles GROUP BY extension ORDER BY extension ASC;';
    174150  FQuery.Open;
     151  SetLength(Fdat_extensionsmap, FQuery.RecordCount);
    175152  if FQuery.RecordCount > 0 then
    176153  begin
    177     SetLength(Fdat_extensionsmap, FQuery.RecordCount);
    178154    i := 0;
    179155    repeat
    180       temps := FQuery.FieldByName('extension').AsString[1];
     156      temps := FQuery.FieldByName('extension').AsString;
    181157      Fdat_extensionsmap[i].Extension[3] := temps[1];
    182158      Fdat_extensionsmap[i].Extension[2] := temps[2];
     
    192168
    193169
    194 function TOniDataADB.GetFileInfo(fileid: Integer): TFileInfo;
    195 var
    196   i: Integer;
     170function TAccess_OUP_ADB.GetFileInfo(fileid: Integer): TFileInfo;
    197171begin
    198172  if fileid = -1 then
     
    201175    Exit;
    202176  end;
    203   if fileid < Self.GetFilesCount then
    204   begin
    205     for i := 0 to High(Fdat_files) do
    206       if Fdat_files[i].ID = fileid then
    207         Break;
    208     if i < Length(Fdat_files) then
    209       Result := Fdat_files[i]
    210     else
    211       Result.ID := -1;
    212   end
     177  if fileid < Self.GetFileCount then
     178    Result    := Fdat_files[fileid]
    213179  else
    214   begin
    215180    Result.ID := -1;
    216   end;
    217 end;
    218 
    219 
    220 
    221 
    222 function TOniDataADB.GetFilesList(ext: String; pattern: String;
    223   NoEmptyFiles: Boolean; sort: TSortType): TStringArray;
    224 var
    225   i: LongWord;
    226   list: TStringList;
     181end;
     182
     183
     184
     185
     186function TAccess_OUP_ADB.GetFilesList(ext: String; pattern: String;
     187  NoEmptyFiles: Boolean; SortType: TSortType): TStrings;
     188var
     189  i:      Integer;
     190  list:   TStringList;
    227191  id, name, extension: String;
    228192  fields: TStrings;
     
    230194  procedure getfields;
    231195  begin
    232      fields.CommaText := StringReplace(AnsiQuotedStr(list.Strings[i], '"'), ';', '","', [rfReplaceAll]);
    233     if sort in [stIDAsc, stIDDesc] then
     196    fields.CommaText := StringReplace(AnsiQuotedStr(list.Strings[i], '"'), ';', '","', [rfReplaceAll]);
     197    if SortType in [ST_IDAsc, ST_IDDesc] then
    234198    begin
    235199      id := fields.Strings[0];
     
    237201      extension := fields.Strings[2];
    238202    end;
    239     if sort in [stNameAsc, stNameDesc] then
     203    if SortType in [ST_NameAsc, ST_NameDesc] then
    240204    begin
    241205      id := fields.Strings[1];
     
    243207      extension := fields.Strings[2];
    244208    end;
    245     if sort in [stExtAsc, stExtDesc] then
     209    if SortType in [ST_ExtAsc, ST_ExtDesc] then
    246210    begin
    247211      id := fields.Strings[1];
     
    254218  list := TStringList.Create;
    255219  list.Sorted := True;
    256   for i := 0 to High(Fdat_files) do
     220  for i := 0 to GetFileCount - 1 do
    257221  begin
    258222    if ((Length(ext) = 0) or (Pos(Fdat_files[i].Extension, ext) > 0)) and
     
    269233        extension := Fdat_files[i].Extension;
    270234
    271         case sort of
    272           stIDAsc, stIDDesc:     list.Add(id + ';' + name + ';' + extension);
    273           stNameAsc, stNameDesc: list.Add(name + ';' + id + ';' + extension);
    274           stExtAsc, stExtDesc:   list.Add(extension + ';' + id + ';' + name);
     235        case SortType of
     236          ST_IDAsc, ST_IDDesc:     list.Add(id + ';' + name + ';' + extension);
     237          ST_NameAsc, ST_NameDesc: list.Add(name + ';' + id + ';' + extension);
     238          ST_ExtAsc, ST_ExtDesc:   list.Add(extension + ';' + id + ';' + name);
    275239        end;
    276240      end;
    277241    end;
    278242  end;
    279   SetLength(Result, list.Count);
    280   fields := TStringList.Create;
    281   if sort in [stIDAsc, stNameAsc, stExtAsc] then
    282     for i := 0 to list.Count - 1 do
    283     begin
    284       getfields;
    285       Result[i] := id + '-' + name + '.' + extension;
    286     end
    287   else
    288     for i := list.Count - 1 downto 0 do
    289     begin
    290       getfields;
    291       Result[list.Count - i - 1] := id + '-' + name + '.' + extension;
    292     end;
     243  Result := TStringList.Create;
     244  if list.Count > 0 then
     245  begin
     246    fields := TStringList.Create;
     247    if SortType in [ST_IDAsc, ST_NameAsc, ST_ExtAsc] then
     248      for i := 0 to list.Count - 1 do
     249      begin
     250        getfields;
     251        Result.Add(id + '-' + name + '.' + extension);
     252      end
     253    else
     254      for i := list.Count - 1 downto 0 do
     255      begin
     256        getfields;
     257        Result.Add(id + '-' + name + '.' + extension);
     258      end;
     259    fields.Free;
     260  end;
    293261  list.Free;
    294   fields.Free;
    295 end;
    296 
    297 
    298 
    299 
    300 function TOniDataADB.GetFilesCount: LongWord;
     262end;
     263
     264
     265
     266
     267function TAccess_OUP_ADB.GetFileCount: Integer;
    301268begin
    302269  Result := Length(Fdat_files);
     
    304271
    305272
    306 
    307 
    308 function TOniDataADB.GetExtensionsList: TStringArray;
    309 var
    310   i: LongWord;
    311 begin
    312   SetLength(Result, Length(Fdat_extensionsmap));
    313   for i := 0 to High(Result) do
     273function TAccess_OUP_ADB.GetExtensionsList(ExtListFormat: TExtensionFormat): TStrings;
     274var
     275  i: Integer;
     276begin
     277  Result := TStringList.Create;
     278  for i := 0 to Length(Fdat_extensionsmap) - 1 do
    314279  begin
    315280    with Fdat_extensionsmap[i] do
    316281    begin
    317       Result[i] := Extension[3] + Extension[2] + Extension[1] + Extension[0] +
    318         ' (' + IntToStr(ExtCount) + ')';
    319     end;
    320   end;
    321 end;
    322 
    323 
    324 
    325 
    326 function TOniDataADB.GetExtendedExtensionsList: TExtensionsMap;
    327 var
    328   i, j:  LongWord;
    329   temps: String;
    330   Data:  Tdata;
    331 begin
    332   SetLength(Result, 0);
    333   FQuery.SQL.Text := 'SELECT ext,ident FROM extlist ORDER BY ext ASC;';
    334   FQuery.Open;
    335   if FQuery.RecordCount > 0 then
    336   begin
    337     SetLength(Result, FQuery.RecordCount);
    338     i := 0;
    339     repeat
    340       temps := FQuery.FieldByName('ext').AsString;
    341       for j := 0 to 3 do
    342         Result[i].Extension[j] := temps[4 - j];
    343       Data := DecodeHexString(FQuery.FieldByName('ident').AsString);
    344       for j := 0 to 7 do
    345         Result[i].Ident[j] := Data[j];
    346       Inc(i);
    347       FQuery.Next;
    348     until FQuery.EOF;
    349   end;
    350   FQuery.Close;
    351 end;
    352 
    353 
    354 
    355 
    356 function TOniDataADB.GetNamedFilesMap: TNamedFilesMap;
    357 var
    358   i:     LongWord;
    359   temp:  Integer;
    360   temps: String;
    361   temparray: array of record
    362     id: Integer;
    363     fullname: String[50];
    364   end;
    365 begin
    366   SetLength(temparray, 0);
    367   FQuery.SQL.Text :=
    368     'SELECT id,(extension+name) AS xname FROM datfiles WHERE Length(name)>0 ORDER BY extension,name ASC;';
    369   FQuery.Open;
    370   if FQuery.RecordCount > 0 then
    371   begin
    372     repeat
    373       temp  := FQuery.FieldByName('id').AsInteger;
    374       temps := FQuery.FieldByName('xname').AsString;
    375 
    376       SetLength(temparray, Length(temparray) + 1);
    377       if Length(temparray) > 1 then
    378       begin
    379         for i := High(temparray) - 1 downto 0 do
    380         begin
    381           if StringSmaller(temps, temparray[i].fullname) then
    382           begin
    383             temparray[i + 1] := temparray[i];
    384             if i = 0 then
    385             begin
    386               temparray[i].id := temp;
    387               temparray[i].fullname := temps;
    388             end;
    389           end
    390           else
    391           begin
    392             temparray[i + 1].id := temp;
    393             temparray[i + 1].fullname := temps;
    394             Break;
    395           end;
    396         end;
    397       end
    398       else
    399       begin
    400         temparray[0].id := temp;
    401         temparray[0].fullname := temps;
     282      case ExtListFormat of
     283        EF_ExtOnly:
     284          Result.Add(Extension[3] + Extension[2] + Extension[1] + Extension[0]);
     285        EF_ExtCount:
     286          Result.Add(Extension[3] + Extension[2] + Extension[1] + Extension[0] +
     287                ' (' + IntToStr(ExtCount) + ')');
    402288      end;
    403       FQuery.Next;
    404     until FQuery.EOF;
    405   end;
    406   FQuery.Close;
    407   SetLength(Result, Length(temparray));
    408   for i := 0 to High(temparray) do
    409   begin
    410     Result[i].FileNumber := temparray[i].id;
    411     Result[i].blubb      := 0;
    412   end;
    413 end;
    414 
    415 
    416 
    417 
    418 function TOniDataADB.LoadDatFile(fileid: LongWord): Tdata;
     289    end;
     290  end;
     291end;
     292
     293
     294procedure TAccess_OUP_ADB.LoadDatFile(FileID: Integer; var Target: TStream);
    419295var
    420296  mem: TStream;
    421 begin
    422   if fileid < Self.GetFilesCount then
    423   begin
     297  streampos: Integer;
     298begin
     299  if fileid < GetFileCount then
     300  begin
     301    if not Assigned(Target) then
     302      Target := TMemoryStream.Create;
     303
     304    streampos := Target.Position;
     305
    424306    FQuery.SQL.Text := 'SELECT data FROM datfiles WHERE id=' + IntToStr(fileid) + ';';
    425307    FQuery.Open;
     
    427309    begin
    428310      mem := FQuery.CreateBlobStream(FQuery.FieldByName('data'), bmRead);
    429       SetLength(Result, mem.Size);
    430311      mem.Seek(0, soFromBeginning);
    431       mem.Read(Result[0], mem.Size);
     312      Target.CopyFrom(mem, mem.Size);
    432313      mem.Free;
    433314    end;
    434315    FQuery.Close;
    435   end;
    436 end;
    437 
    438 
    439 
    440 
    441 procedure TOniDataADB.UpdateDatFile(fileid: LongWord; Data: Tdata);
     316
     317    Target.Seek(streampos, soFromBeginning);
     318  end;
     319end;
     320
     321procedure TAccess_OUP_ADB.UpdateDatFile(FileID: Integer; Src: TStream);
    442322var
    443323  MimeCoder: TStringFormat_MIME64;
    444324  mem: TMemoryStream;
    445325begin
    446   if fileid < Self.GetFilesCount then
     326  if fileid < GetFileCount then
    447327  begin
    448328    mimecoder := TStringFormat_MIME64.Create;
    449329    mem := TMemoryStream.Create;
    450     mem.Write(Data[0], Length(Data));
    451     mem.Seek(0, soFromBeginning);
     330    mem.CopyFrom(Src, Src.Size);
    452331    FQuery.SQL.Text := 'UPDATE datfiles SET data=MimeToBin("' +
    453332      MimeCoder.StrTo(mem.Memory, mem.Size) + '"), size=' + IntToStr(mem.Size) +
     
    457336    mimecoder.Free;
    458337  end;
    459   UpdateListCache;
    460 end;
    461 
    462 
    463 
    464 
    465 procedure TOniDataADB.LoadDatFilePart(fileid, offset, size: LongWord; target: Pointer);
    466 var
     338end;
     339
     340
     341
     342procedure TAccess_OUP_ADB.LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TStream);
     343var
     344  streampos: Integer;
    467345  mem: TStream;
    468346begin
    469   if fileid < Self.GetFilesCount then
    470   begin
     347  if fileid < GetFileCount then
     348  begin
     349    if not Assigned(Target) then
     350      Target := TMemoryStream.Create;
     351    streampos := Target.Position;
     352
    471353    FQuery.SQL.Text := 'SELECT data FROM datfiles WHERE id=' + IntToStr(fileid) + ';';
    472354    FQuery.Open;
     
    475357      mem := FQuery.CreateBlobStream(FQuery.FieldByName('data'), bmRead);
    476358      mem.Seek(offset, soFromBeginning);
    477       mem.Read(target^, size);
     359      Target.CopyFrom(mem, size);
    478360      mem.Free;
    479361    end;
    480362    FQuery.Close;
    481   end;
    482 end;
    483 
    484 
    485 
    486 
    487 procedure TOniDataADB.UpdateDatFilePart(fileid, offset, size: LongWord; target: Pointer);
     363    Target.Seek(streampos, soFromBeginning);
     364  end;
     365end;
     366
     367
     368
     369procedure TAccess_OUP_ADB.UpdateDatFilePart(FileID, Offset, Size: Integer; Src: TStream);
    488370var
    489371  MimeCoder: TStringFormat_MIME64;
    490372  mem:  TMemoryStream;
    491   Data: Tdata;
    492 begin
    493   if fileid < Self.GetFilesCount then
    494   begin
    495     Data := Self.LoadDatFile(fileid);
     373begin
     374  if fileid < GetFileCount then
     375  begin
     376    mem := nil;
     377    LoadDatFile(fileid, TStream(mem));
     378    mem.Seek(Offset, soFromBeginning);
     379    mem.CopyFrom(Src, Size);
     380    mem.Seek(0, soFromBeginning);
    496381    mimecoder := TStringFormat_MIME64.Create;
    497     mem := TMemoryStream.Create;
    498     mem.Write(Data[0], Length(Data));
    499     mem.Seek(offset, soFromBeginning);
    500     mem.Write(target^, size);
    501     mem.Seek(0, soFromBeginning);
    502382    FQuery.SQL.Text := 'UPDATE datfiles SET data=MimeToBin("' +
    503383      MimeCoder.StrTo(mem.Memory, mem.Size) + '") WHERE id=' + IntToStr(fileid) + ';';
     
    509389
    510390
    511 
    512 
    513 function TOniDataADB.GetRawList(fileid: LongWord): TRawList;
    514 var
    515   i: LongWord;
     391function TAccess_OUP_ADB.GetRawList(FileID: Integer): TRawDataList;
     392var
     393  i: Integer;
    516394begin
    517395  SetLength(Result, 0);
     
    525403    i := 0;
    526404    repeat
    527       Result[i].src_id     := fileid;
    528       Result[i].src_offset := FQuery.FieldByName('src_link_offset').AsInteger;
    529       Result[i].raw_addr   := 0;
    530       Result[i].raw_size   := FQuery.FieldByName('size').AsInteger;
    531       Result[i].loc_sep    := FQuery.FieldByName('sep').AsBoolean;
     405      Result[i].SrcID     := fileid;
     406      Result[i].SrcOffset := FQuery.FieldByName('src_link_offset').AsInteger;
     407      Result[i].RawAddr   := 0;
     408      Result[i].RawSize   := FQuery.FieldByName('size').AsInteger;
     409      Result[i].LocSep    := FQuery.FieldByName('sep').AsBoolean;
    532410      Inc(i);
    533411      FQuery.Next;
     
    538416
    539417
    540 
    541 
    542 procedure TOniDataADB.LoadRawFile(fileid, dat_offset: LongWord; target: Pointer);
     418function TAccess_OUP_ADB.GetRawInfo(FileID, DatOffset: Integer): TRawDataInfo;
     419var
     420  i: Integer;
     421  rawlist: TRawDataList;
     422begin
     423  rawlist := GetRawList(FileID);
     424  if Length(rawlist) > 0 then
     425  begin
     426    for i := 0 to High(rawlist) do
     427      if rawlist[i].SrcOffset = DatOffset then
     428        Break;
     429    if i < Length(rawlist) then
     430      Result := rawlist[i]
     431    else begin
     432      Result.SrcID     := -1;
     433      Result.SrcOffset := -1;
     434      Result.RawAddr   := -1;
     435      Result.RawSize   := -1;
     436    end;
     437  end;
     438end;
     439
     440
     441
     442procedure TAccess_OUP_ADB.LoadRawFile(FileID, DatOffset: Integer; var Target: TStream);
    543443var
    544444  mem: TStream;
    545 begin
    546   if fileid < Self.GetFilesCount then
    547   begin
     445  streampos: Integer;
     446begin
     447  if fileid < GetFileCount then
     448  begin
     449    if not Assigned(Target) then
     450      Target := TMemoryStream.Create;
     451    streampos := Target.Position;
    548452    FQuery.SQL.Text := 'SELECT data FROM rawmap WHERE (src_id=' +
    549       IntToStr(fileid) + ') AND (src_link_offset=' + IntToStr(dat_offset) + ');';
     453      IntToStr(FileID) + ') AND (src_link_offset=' + IntToStr(DatOffset) + ');';
    550454    FQuery.Open;
    551455    if FQuery.RecordCount > 0 then
     
    553457      mem := FQuery.CreateBlobStream(FQuery.FieldByName('data'), bmRead);
    554458      mem.Seek(0, soFromBeginning);
    555       mem.Read(target^, mem.size);
     459      Target.CopyFrom(mem, mem.Size);
    556460      mem.Free;
    557461    end;
    558462    FQuery.Close;
    559   end;
    560 end;
    561 
    562 
    563 
    564 
    565 procedure TOniDataADB.UpdateRawFile(fileid, dat_offset: LongWord;
    566   size: LongWord; target: Pointer);
     463    Target.Seek(streampos, soFromBeginning);
     464  end;
     465end;
     466
     467
     468procedure TAccess_OUP_ADB.UpdateRawFile(FileID, DatOffset: Integer; Src: TStream);
    567469var
    568470  MimeCoder: TStringFormat_MIME64;
    569471  mem: TMemoryStream;
    570472begin
    571   if fileid < Self.GetFilesCount then
     473  if fileid < GetFileCount then
    572474  begin
    573475    mimecoder := TStringFormat_MIME64.Create;
    574476    mem := TMemoryStream.Create;
    575     mem.Write(target^, size);
     477    mem.CopyFrom(Src, Src.Size);
    576478    mem.Seek(0, soFromBeginning);
    577479    FQuery.SQL.Text := 'UPDATE rawmap SET data=MimeToBin("' + MimeCoder.StrTo(
    578       mem.Memory, mem.Size) + '") WHERE (src_id=' + IntToStr(fileid) +
    579       ') AND (src_link_offset=' + IntToStr(dat_offset) + ');';
     480      mem.Memory, mem.Size) + '") WHERE (src_id=' + IntToStr(FileID) +
     481      ') AND (src_link_offset=' + IntToStr(DatOffset) + ');';
    580482    FQuery.ExecSQL;
    581483    mem.Free;
     
    587489
    588490
    589 procedure TOniDataADB.LoadRawFilePart(fileid, dat_offset: LongWord;
    590   offset, size: LongWord; target: Pointer);
    591 var
    592   Data: Tdata;
     491procedure TAccess_OUP_ADB.LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TStream);
     492var
    593493  mem:  TMemoryStream;
    594 begin
    595   if fileid < Self.GetFilesCount then
    596   begin
    597     SetLength(Data, Self.GetRawInfo(fileid, dat_offset).raw_size);
    598     Self.LoadRawFile(fileid, dat_offset, @Data[0]);
    599     mem := TMemoryStream.Create;
    600     mem.Write(Data[offset], size);
    601     mem.Read(target^, size);
     494  streampos: Integer;
     495begin
     496  if fileid < GetFileCount then
     497  begin
     498    if not Assigned(Target) then
     499      Target := TMemoryStream.Create;
     500    streampos := Target.Position;
     501    mem := nil;
     502    LoadRawFile(FileID, DatOffset, TStream(mem));
     503    mem.Seek(Offset, soFromBeginning);
     504    Target.CopyFrom(mem, Size);
    602505    mem.Free;
    603   end;
    604 end;
    605 
    606 
    607 
    608 
    609 procedure TOniDataADB.UpdateRawFilePart(fileid, dat_offset: LongWord;
    610   offset, size: LongWord; target: Pointer);
     506    Target.Seek(streampos, soFromBeginning);
     507  end;
     508end;
     509
     510
     511
     512
     513procedure TAccess_OUP_ADB.UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: TStream);
    611514var
    612515  MimeCoder: TStringFormat_MIME64;
    613516  mem:  TMemoryStream;
    614   Data: Tdata;
    615 begin
    616   if fileid < Self.GetFilesCount then
    617   begin
    618     SetLength(Data, Self.GetRawInfo(fileid, offset).raw_size);
    619     Self.LoadRawFile(fileid, offset, @Data[0]);
     517begin
     518  if fileid < GetFileCount then
     519  begin
     520    mem := nil;
     521    LoadRawFile(fileid, offset, TStream(mem));
     522    mem.Seek(offset, soFromBeginning);
     523    mem.CopyFrom(Src, Size);
     524    mem.Seek(0, soFromBeginning);
    620525    mimecoder := TStringFormat_MIME64.Create;
    621     mem := TMemoryStream.Create;
    622     mem.Write(Data[0], Length(Data));
    623     mem.Seek(offset, soFromBeginning);
    624     mem.Write(target^, size);
    625     mem.Seek(0, soFromBeginning);
    626526    FQuery.SQL.Text := 'UPDATE rawmap SET data=MimeToBin("' + MimeCoder.StrTo(
    627527      mem.Memory, mem.Size) + '") WHERE (src_id=' + IntToStr(fileid) +
    628       ') AND (src_link_offset=' + IntToStr(dat_offset) + ');';
     528      ') AND (src_link_offset=' + IntToStr(DatOffset) + ');';
    629529    FQuery.ExecSQL;
    630530    mem.Free;
     
    633533end;
    634534
    635 }
     535
    636536
    637537
Note: See TracChangeset for help on using the changeset viewer.