Changeset 101 for oup/rewrite


Ignore:
Timestamp:
Feb 20, 2007, 9:43:29 PM (18 years ago)
Author:
alloc
Message:
 
Location:
oup/rewrite
Files:
14 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
  • oup/rewrite/DataAccess/Access_OniArchive.pas

    r93 r101  
    22interface
    33
    4 uses DataAccess, Classes;
     4uses DataAccess, Classes, TypeDefs;
    55
    66type
    7 {
    8   THeader = packed record
    9     Ident:      array[0..$13] of Byte;
    10     Files:      LongWord;
    11     NamedFiles: LongWord;
    12     Extensions: LongWord;
    13     DataAddr:   LongWord;
    14     DataSize:   LongWord;
    15     NamesAddr:  LongWord;
    16     NamesSize:  LongWord;
    17     Ident2:     array[0..$F] of Byte;
    18   end;
    19   TFilesMap = array of packed record
    20     Extension: array[0..$3] of Char;
    21     DataAddr:  LongWord;
    22     NameAddr:  LongWord;
    23     FileSize:  LongWord;
    24     FileType:  LongWord;
    25   end;
    26 
    27   TFileInfo = packed record
    28     ID:      Integer;
    29     FileName: String;
    30     FileNameHex: String;
    31     Extension: String[4];
    32     Name:    String;
    33     Size:    LongWord;
    34     FileType: LongWord;
    35     DatAddr: LongWord;
    36     opened:  Boolean;
    37   end;
    38   TFiles = array of TFileInfo;
    39 
    40   TNamedFilesMap = array of packed record
    41     FileNumber: LongWord;
    42     blubb:      LongWord;
    43   end;
    44   TExtensionsMap = array of packed record
    45     Ident:     array[0..$7] of Byte;
    46     Extension: array[0..$3] of Char;
    47     ExtCount:  LongWord;
    48   end;
    49 }
    50 
    517  TAccess_OniArchive = class(TDataAccess)
    528  private
    53 {    Fdat_file:     TFileStream;
    54     Fraw_file:     TFileStream;
    55     Fsep_file:     TFileStream;
    56     Fdat_header:   THeader;
    57     Fdat_filesmap: TFilesMap;
    58     Fdat_files:    TFiles;
    59     Fdat_namedfilesmap: TNamedFilesMap;
    60     Fdat_extensionsmap: TExtensionsMap;
    61     FUnloadWhenUnused: Boolean;
    62     FDatOpened:    Boolean;
    63     FRawOpened:    Boolean;
    64     FSepOpened:    Boolean;
     9    Fdat_file:           TFileStream;
     10    Fraw_file:           TFileStream;
     11    Fsep_file:           TFileStream;
     12    Fdat_files:          TFiles;
     13    Fdat_extensionsmap:  TExtensionsMap;
     14    FUnloadWhenUnused:   Boolean;
     15    FDatOpened:          Boolean;
     16    FRawOpened:          Boolean;
     17    FSepOpened:          Boolean;
    6518  protected
    6619  public
    6720    property UnloadWhenUnused: Boolean Read FUnloadWhenUnused Write FUnloadWhenUnused;
    6821
    69     constructor Create(DatFilename: String; var Result: Boolean); override;
     22    constructor Create(DatFilename: String; ConnectionID: Integer; var Msg: TStatusMessages); override;
    7023    procedure Close; override;
    7124
    72     function GetFileInfo(fileid: Integer): TFileInfo; override;
    73     function GetFilesList(ext: String; pattern: String;
    74       NoEmptyFiles: Boolean; sort: TSortType): TStringArray; override;
    75     function GetFilesCount: LongWord; override;
    76     function GetExtensionsList: TStringArray; override;
    77     function GetExtendedExtensionsList: TExtensionsMap; override;
    78 
    79     function LoadDatFile(fileid: LongWord): Tdata; override;
    80     procedure UpdateDatFile(fileid: LongWord; Data: Tdata); override;
    81     procedure LoadDatFilePart(fileid, offset, size: LongWord; target: Pointer); override;
    82     procedure UpdateDatFilePart(fileid, offset, size: LongWord; target: Pointer); override;
    83 
    84     procedure LoadRawOffset(loc_sep: Boolean; raw_addr, size: LongWord; target: Pointer);
    85     function GetRawList(fileid: LongWord): TRawList; override;
    86     procedure LoadRawFile(fileid, dat_offset: LongWord; target: Pointer); override;
    87     procedure UpdateRawFile(fileid, dat_offset: LongWord; size: LongWord;
    88       target: Pointer); override;
    89     procedure LoadRawFilePart(fileid, dat_offset: LongWord;
    90       offset, size: LongWord; target: Pointer); override;
    91     procedure UpdateRawFilePart(fileid, dat_offset: LongWord;
    92       offset, size: LongWord; target: Pointer); override;
    93     function AppendRawFile(loc_sep: Boolean; size: LongWord; target: Pointer): LongWord;
    94       override;//Returns new Address
     25    function GetFileInfo(FileID: Integer): TFileInfo; override;
     26    function GetFilesList(Ext: String; Pattern: String;
     27      NoEmptyFiles: Boolean; SortType: TSortType): TStrings; override;
     28    function GetFileCount: Integer; override;
     29    function GetExtensionsList(ExtListFormat: TExtensionFormat): TStrings; override;
     30
     31    procedure LoadDatFile(FileID: Integer; var Target: TStream); overload; override;
     32    procedure UpdateDatFile(FileID: Integer; Src: TStream); overload; override;
     33    procedure LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TStream); overload; override;
     34    procedure UpdateDatFilePart(FileID, Offset, Size: Integer; Src: TStream); overload; override;
     35
     36    function GetRawList(FileID: Integer): TRawDataList; override;
     37    function GetRawInfo(FileID, DatOffset: Integer): TRawDataInfo; override;
     38
     39    procedure LoadRawOffset(LocSep: Boolean; RawAddr, Size: Integer; target: Pointer);
     40    procedure LoadRawFile(FileID, DatOffset: Integer; var Target: TStream); overload; override;
     41    procedure UpdateRawFile(FileID, DatOffset: Integer; Src: TStream); overload; override;
     42    procedure LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TStream); overload; override;
     43    procedure UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: TStream); overload; override;
     44
     45    function AppendRawFile(LocSep: Boolean; Size: Integer; Src: TStream): Integer; overload; override;
    9546  published
    96 }  end;
     47  end;
    9748
    9849implementation
     50
     51uses
     52  SysUtils, StrUtils, Data, Functions, RawList;
    9953
    10054
     
    10458*)
    10559
    106 {
    107 constructor TOniDataDat.Create(DatFilename: String; var Result: Boolean);
     60
     61constructor TAccess_OniArchive.Create(DatFilename: String; ConnectionID: Integer; var Msg: TStatusMessages);
     62type
     63  THeader = packed record
     64    Ident:      array[0..$13] of Byte;
     65    Files:      Integer;
     66    NamedFiles: Integer;
     67    Extensions: Integer;
     68    DataAddr:   Integer;
     69    DataSize:   Integer;
     70    NamesAddr:  Integer;
     71    NamesSize:  Integer;
     72    Ident2:     array[0..$F] of Byte;
     73  end;
     74  TFilesMap = array of packed record
     75    Extension: array[0..$3] of Char;
     76    DataAddr:  Integer;
     77    NameAddr:  Integer;
     78    FileSize:  Integer;
     79    FileType:  LongWord;
     80  end;
     81  TNamedFilesMap = array of packed record
     82    FileNumber: Integer;
     83    blubb:      Integer;
     84  end;
    10885const
    10986  header_ident1_pc: array[0..$13] of Byte =
     
    11996    ($99, $CF, $40, $00, $90, $4F, $63, $00, $F4, $55, $5F, $00, $90, $4F, $63, $00);
    12097var
    121   i: LongWord;
    122   header_pc, header_mac: Boolean;
     98  i: Integer;
     99  header_pc, header_mac, header_macbeta: Boolean;
     100  Fdat_header:   THeader;
     101  Fdat_filesmap: TFilesMap;
     102  Fdat_namedfilesmap: TNamedFilesMap;
    123103begin
    124104  FUnloadWhenUnused := True;
    125105  FDatOpened := False;
    126106  FRawOpened := False;
     107  Msg := SM_UnknownError;
    127108  if not FileExists(DatFilename) then
    128109  begin
    129     ShowMessage('File doesn''t exist!!!');
    130     Result := False;
     110    Msg := SM_FileNotFound;
    131111    Exit;
    132112  end;
     
    136116  header_pc  := True;
    137117  header_mac := True;
     118  header_macbeta := True;
    138119  for i := 0 to High(Fdat_header.Ident) do
    139120  begin
    140     FLevelInfo.Ident[i] := Fdat_header.Ident[i];
     121//    FLevelInfo.Ident[i] := Fdat_header.Ident[i];
    141122    if Fdat_header.Ident[i] <> header_ident1_pc[i] then
    142123      header_pc := False;
    143124    if Fdat_header.Ident[i] <> header_ident1_mac[i] then
    144125      header_mac := False;
    145   end;
    146   if not (header_pc xor header_mac) then
    147   begin
    148     Result := False;
     126    if Fdat_header.Ident[i] <> header_ident1_macbeta[i] then
     127      header_macbeta := False;
     128  end;
     129  if not (header_pc xor header_mac xor header_macbeta) then
     130  begin
     131    Msg := SM_IncompatibleFile;
    149132    Exit;
    150133  end
    151134  else
    152135  begin
    153     if (header_pc and not header_mac) then
    154       Fos_mac := False
    155     else
    156       Fos_mac := True;
     136    if (header_pc and not header_mac and not header_macbeta) then
     137      FDataOS := DOS_WIN
     138    else if (not header_pc and header_mac and not header_macbeta) then
     139      FDataOS := DOS_MAC
     140    else if (not header_pc and not header_mac and header_macbeta) then
     141      FDataOS := DOS_MACBETA;
    157142  end;
    158143  SetLength(Fdat_filesmap, Fdat_header.Files);
     
    180165      Fdat_files[i].Name := '';
    181166    end;
    182     Fdat_files[i].FileName    :=
    183       FormatNumber(i, 5, '0') + '-' + Fdat_files[i].Name + '.' + Fdat_files[i].Extension;
    184     Fdat_files[i].FileNameHex :=
    185       IntToHex(i, 4) + '-' + Fdat_files[i].Name + '.' + Fdat_files[i].Extension;
    186167  end;
    187168  Fdat_file.Seek($40 + Fdat_header.Files * $14, soFromBeginning);
     
    196177
    197178  Fdat_file.Seek(Fdat_files[0].DatAddr + 7, soFromBeginning);
    198   Fdat_file.Read(FLevelInfo.LevelNumber, 1);
    199   FLevelInfo.LevelNumber := FLevelInfo.LevelNumber div 2;
     179  Fdat_file.Read(FLevelNumber, 1);
     180  FLevelNumber := FLevelNumber div 2;
    200181
    201182  Fdat_file.Free;
    202183
    203   Result   := True;
    204   FBackend := ODB_Dat;
    205 end;
    206 
    207 
    208 
    209 
    210 procedure TOniDataDat.Close;
    211 begin
    212   if not FUnloadWhenUnused and FDatOpened then
     184  Msg := SM_OK;
     185  FBackend := DB_ONI;
     186  FChangeRights := [CR_EditDat, CR_EditRaw, CR_AppendRaw];
     187end;
     188
     189
     190
     191
     192procedure TAccess_OniArchive.Close;
     193begin
     194  if FDatOpened then
    213195    Fdat_file.Free;
    214   if not FUnloadWhenUnused and FRawOpened then
     196  if FRawOpened then
    215197    Fraw_file.Free;
    216   if not FUnloadWhenUnused and FSepOpened then
     198  if FSepOpened then
    217199    Fsep_file.Free;
    218200  Self.Free;
     
    222204
    223205
    224 function TOniDataDat.GetFileInfo(fileid: Integer): TFileInfo;
     206function TAccess_OniArchive.GetFileInfo(fileid: Integer): TFileInfo;
    225207begin
    226208  if fileid = -1 then
     
    229211    Exit;
    230212  end;
    231   if fileid < Self.GetFilesCount then
     213  if fileid < Self.GetFileCount then
    232214    Result    := Fdat_files[fileid]
    233215  else
     
    238220
    239221
    240 function TOniDataDat.GetFilesList(ext: String; pattern: String;
    241   NoEmptyFiles: Boolean; sort: TSortType): TStringArray;
    242 var
    243   i: LongWord;
    244   list: TStringList;
     222function TAccess_OniArchive.GetFilesList(ext: String; pattern: String;
     223  NoEmptyFiles: Boolean; SortType: TSortType): TStrings;
     224var
     225  i:      Integer;
     226  list:   TStringList;
    245227  id, name, extension: String;
    246228  fields: TStrings;
     
    248230  procedure getfields;
    249231  begin
    250      fields.CommaText := StringReplace(AnsiQuotedStr(list.Strings[i], '"'), ';', '","', [rfReplaceAll]);
    251     if sort in [stIDAsc, stIDDesc] then
     232    fields.CommaText := StringReplace(AnsiQuotedStr(list.Strings[i], '"'), ';', '","', [rfReplaceAll]);
     233    if SortType in [ST_IDAsc, ST_IDDesc] then
    252234    begin
    253235      id := fields.Strings[0];
     
    255237      extension := fields.Strings[2];
    256238    end;
    257     if sort in [stNameAsc, stNameDesc] then
     239    if SortType in [ST_NameAsc, ST_NameDesc] then
    258240    begin
    259241      id := fields.Strings[1];
     
    261243      extension := fields.Strings[2];
    262244    end;
    263     if sort in [stExtAsc, stExtDesc] then
     245    if SortType in [ST_ExtAsc, ST_ExtDesc] then
    264246    begin
    265247      id := fields.Strings[1];
     
    272254  list := TStringList.Create;
    273255  list.Sorted := True;
    274   for i := 0 to Fdat_header.Files - 1 do
     256  for i := 0 to GetFileCount - 1 do
    275257  begin
    276258    if ((Length(ext) = 0) or (Pos(Fdat_files[i].Extension, ext) > 0)) and
     
    287269        extension := Fdat_files[i].Extension;
    288270
    289         case sort of
    290           stIDAsc, stIDDesc:     list.Add(id + ';' + name + ';' + extension);
    291           stNameAsc, stNameDesc: list.Add(name + ';' + id + ';' + extension);
    292           stExtAsc, stExtDesc:   list.Add(extension + ';' + id + ';' + name);
     271        case SortType of
     272          ST_IDAsc, ST_IDDesc:     list.Add(id + ';' + name + ';' + extension);
     273          ST_NameAsc, ST_NameDesc: list.Add(name + ';' + id + ';' + extension);
     274          ST_ExtAsc, ST_ExtDesc:   list.Add(extension + ';' + id + ';' + name);
    293275        end;
    294276      end;
    295277    end;
    296278  end;
    297   SetLength(Result, list.Count);
    298   if Length(Result) > 0 then
     279  Result := TStringList.Create;
     280  if list.Count > 0 then
    299281  begin
    300282    fields := TStringList.Create;
    301     if sort in [stIDAsc, stNameAsc, stExtAsc] then
     283    if SortType in [ST_IDAsc, ST_NameAsc, ST_ExtAsc] then
    302284      for i := 0 to list.Count - 1 do
    303285      begin
    304286        getfields;
    305         Result[i] := id + '-' + name + '.' + extension;
     287        Result.Add(id + '-' + name + '.' + extension);
    306288      end
    307289    else
     
    309291      begin
    310292        getfields;
    311         Result[list.Count - i - 1] := id + '-' + name + '.' + extension;
     293        Result.Add(id + '-' + name + '.' + extension);
    312294      end;
    313295    fields.Free;
     
    319301
    320302
    321 function TOniDataDat.GetFilesCount: LongWord;
    322 begin
    323   Result := Fdat_header.Files;
    324 end;
    325 
    326 
    327 
    328 
    329 function TOniDataDat.GetExtensionsList: TStringArray;
    330 var
    331   i: LongWord;
    332 begin
    333   SetLength(Result, Fdat_header.Extensions);
    334   for i := 0 to Fdat_header.Extensions - 1 do
     303function TAccess_OniArchive.GetFileCount: Integer;
     304begin
     305  Result := Length(Fdat_files);
     306end;
     307
     308
     309
     310
     311function TAccess_OniArchive.GetExtensionsList(ExtListFormat: TExtensionFormat): TStrings;
     312var
     313  i: Integer;
     314begin
     315  Result := TStringList.Create;
     316  for i := 0 to Length(Fdat_extensionsmap) - 1 do
    335317  begin
    336318    with Fdat_extensionsmap[i] do
    337319    begin
    338       Result[i] := Extension[3] + Extension[2] + Extension[1] + Extension[0] +
    339         ' (' + IntToStr(ExtCount) + ')';
    340     end;
    341   end;
    342 end;
    343 
    344 
    345 
    346 
    347 function TOniDataDat.GetExtendedExtensionsList: TExtensionsMap;
    348 var
    349   i: LongWord;
    350 begin
    351   SetLength(Result, Fdat_header.Extensions);
    352   for i := 0 to Fdat_header.Extensions - 1 do
    353   begin
    354     Result[i] := Fdat_extensionsmap[i];
    355   end;
    356 end;
    357 
    358 
    359 
    360 
    361 function TOniDataDat.LoadDatFile(fileid: LongWord): Tdata;
    362 begin
    363   if fileid < Self.GetFilesCount then
    364   begin
    365     if FUnloadWhenUnused or not FDatOpened then
     320      case ExtListFormat of
     321        EF_ExtOnly:
     322          Result.Add(Extension[3] + Extension[2] + Extension[1] + Extension[0]);
     323        EF_ExtCount:
     324          Result.Add(Extension[3] + Extension[2] + Extension[1] + Extension[0] +
     325                ' (' + IntToStr(ExtCount) + ')');
     326      end;
     327    end;
     328  end;
     329end;
     330
     331
     332
     333procedure TAccess_OniArchive.LoadDatFile(FileID: Integer; var Target: TStream);
     334var
     335  streampos: Integer;
     336begin
     337  if fileid < GetFileCount then
     338  begin
     339    if not Assigned(Target) then
     340      Target := TMemoryStream.Create;
     341    if not FDatOpened then
    366342      Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);
    367343    Fdat_file.Seek(Fdat_files[fileid].DatAddr, soFromBeginning);
    368     SetLength(Result, Fdat_files[fileid].Size);
    369     Fdat_file.Read(Result[0], Fdat_files[fileid].Size);
    370     if UnloadWhenUnused then
    371       Fdat_file.Free
     344    streampos := Target.Position;
     345    Target.CopyFrom(Fdat_file, Fdat_files[fileid].Size);
     346    Target.Seek(streampos, soFromBeginning);
     347    if UnloadWhenUnused then
     348    begin
     349      Fdat_file.Free;
     350      FDatOpened := False;
     351    end
    372352    else
    373353      FDatOpened := True;
     
    375355end;
    376356
    377 
    378 
    379 
    380 procedure TOniDataDat.UpdateDatFile(fileid: LongWord; Data: Tdata);
    381 begin
    382   if fileid < Self.GetFilesCount then
    383   begin
    384     if FUnloadWhenUnused or not FDatOpened then
     357procedure TAccess_OniArchive.UpdateDatFile(FileID: Integer; Src: TStream);
     358begin
     359  if fileid < GetFileCount then
     360  begin
     361    if not FDatOpened then
    385362      Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);
    386363    Fdat_file.Seek(Fdat_files[fileid].DatAddr, soFromBeginning);
    387     Fdat_file.Write(Data[0], Length(Data));
    388     if UnloadWhenUnused then
    389       Fdat_file.Free
     364    Fdat_file.CopyFrom(Src, Fdat_files[fileid].Size);
     365    if UnloadWhenUnused then
     366    begin
     367      Fdat_file.Free;
     368      FDatOpened := False;
     369    end
    390370    else
    391371      FDatOpened := True;
     
    393373end;
    394374
    395 
    396 
    397 
    398 procedure TOniDataDat.LoadDatFilePart(fileid, offset, size: LongWord; target: Pointer);
    399 begin
    400   if fileid < Self.GetFilesCount then
    401   begin
    402     if FUnloadWhenUnused or not FDatOpened then
     375procedure TAccess_OniArchive.LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TStream);
     376var
     377  streampos: Integer;
     378begin
     379  if fileid < GetFileCount then
     380  begin
     381    if not Assigned(Target) then
     382      Target := TMemoryStream.Create;
     383    if not FDatOpened then
    403384      Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);
    404385    Fdat_file.Seek(Fdat_files[fileid].DatAddr + offset, soFromBeginning);
    405     Fdat_file.Read(target^, size);
    406     if UnloadWhenUnused then
    407       Fdat_file.Free
     386    streampos := Target.Position;
     387    Target.CopyFrom(Fdat_file, size);
     388    Target.Seek(streampos, soFromBeginning);
     389    if UnloadWhenUnused then
     390    begin
     391      FDatOpened := False;
     392      Fdat_file.Free;
     393    end
    408394    else
    409395      FDatOpened := True;
     
    411397end;
    412398
    413 
    414 
    415 
    416 procedure TOniDataDat.UpdateDatFilePart(fileid, offset, size: LongWord; target: Pointer);
    417 begin
    418   if fileid < Self.GetFilesCount then
    419   begin
    420     if FUnloadWhenUnused or not FDatOpened then
     399procedure TAccess_OniArchive.UpdateDatFilePart(FileID, Offset, Size: Integer; Src: TStream);
     400begin
     401  if fileid < GetFileCount then
     402  begin
     403    if not FDatOpened then
    421404      Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);
    422405    Fdat_file.Seek(Fdat_files[fileid].DatAddr + offset, soFromBeginning);
    423     Fdat_file.Write(target^, size);
    424     if UnloadWhenUnused then
    425       Fdat_file.Free
     406    Fdat_file.CopyFrom(Src, Size);
     407    if UnloadWhenUnused then
     408    begin
     409      Fdat_file.Free;
     410      FDatOpened := False;
     411    end
    426412    else
    427413      FDatOpened := True;
     
    431417
    432418
    433 
    434 function TOniDataDat.GetRawList(fileid: LongWord): TRawList;
    435 var
    436   i: LongWord;
    437 begin
    438   SetLength(Result, 0);
    439   for i := 0 to High(RawListHandlers) do
    440     if UpperCase(RawListHandlers[i].Ext) = UpperCase(Fdat_files[fileid].extension) then
    441       if RawListHandlers[i].needed then
    442       begin
    443         Result := RawListHandlers[i].Handler(Self, fileid);
    444         Break;
    445       end
    446       else
    447         Break;
    448 end;
    449 
    450 
    451 
    452 
    453 procedure TOniDataDat.LoadRawOffset(loc_sep: Boolean; raw_addr, size: LongWord;
    454   target: Pointer);
    455 begin
    456   if not loc_sep then
    457   begin
    458     if FUnloadWhenUnused or not FRawOpened then
     419function TAccess_OniArchive.GetRawList(FileID: Integer): TRawDataList;
     420begin
     421  Result := RawLists.GetRawList(FConnectionID, FileID);
     422end;
     423
     424
     425function TAccess_OniArchive.GetRawInfo(FileID, DatOffset: Integer): TRawDataInfo;
     426begin
     427  Result := RawLists.GetRawInfo(FConnectionID, FileID, DatOffset);
     428end;
     429
     430
     431
     432
     433procedure TAccess_OniArchive.LoadRawOffset(LocSep: Boolean; RawAddr, Size: Integer; target: Pointer);
     434begin
     435  if not LocSep then
     436  begin
     437    if not FRawOpened then
    459438      Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
    460439        fmOpenReadWrite);
    461     if raw_addr <= Fraw_file.Size then
    462     begin
    463       Fraw_file.Seek(raw_addr, soFromBeginning);
     440    if RawAddr <= Fraw_file.Size then
     441    begin
     442      Fraw_file.Seek(RawAddr, soFromBeginning);
    464443      Fraw_file.Read(target^, size);
    465444    end;
    466445    if UnloadWhenUnused then
    467       Fraw_file.Free
     446    begin
     447      FRawOpened := False;
     448      Fraw_file.Free;
     449    end
    468450    else
    469451      FRawOpened := True;
     
    471453  else
    472454  begin
    473     if FUnloadWhenUnused or not FSepOpened then
     455    if not FSepOpened then
    474456      Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
    475457        fmOpenReadWrite);
    476     if raw_addr <= Fsep_file.Size then
    477     begin
    478       Fsep_file.Seek(raw_addr, soFromBeginning);
     458    if RawAddr <= Fsep_file.Size then
     459    begin
     460      Fsep_file.Seek(RawAddr, soFromBeginning);
    479461      Fsep_file.Read(target^, size);
    480462    end;
    481463    if UnloadWhenUnused then
    482       Fsep_file.Free
     464    begin
     465      FSepOpened := False;
     466      Fsep_file.Free;
     467    end
    483468    else
    484469      FSepOpened := True;
     
    486471end;
    487472
    488 
    489 
    490 
    491 procedure TOniDataDat.LoadRawFile(fileid, dat_offset: LongWord; target: Pointer);
    492 var
    493   raw_info: TRawInfo;
    494 begin
    495   if fileid < Self.GetFilesCount then
    496   begin
    497     raw_info := Self.GetRawInfo(fileid, dat_offset);
    498     if not raw_info.loc_sep then
    499     begin
    500       if FUnloadWhenUnused or not FRawOpened then
     473procedure TAccess_OniArchive.LoadRawFile(FileID, DatOffset: Integer; var Target: TStream);
     474var
     475  raw_info: TRawDataInfo;
     476  streampos: Integer;
     477begin
     478  if not Assigned(Target) then
     479    Target := TMemoryStream.Create;
     480  if fileid < GetFileCount then
     481  begin
     482    raw_info := Self.GetRawInfo(FileID, DatOffset);
     483    if not raw_info.LocSep then
     484    begin
     485      if not FRawOpened then
    501486        Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
    502487          fmOpenReadWrite);
    503       Fraw_file.Seek(raw_info.raw_addr, soFromBeginning);
    504       Fraw_file.Read(target^, raw_info.raw_size);
     488      Fraw_file.Seek(raw_info.RawAddr, soFromBeginning);
     489      streampos := Target.Position;
     490      Target.CopyFrom(Fraw_file, raw_info.RawSize);
     491      Target.Seek(streampos, soFromBeginning);
    505492      if UnloadWhenUnused then
    506         Fraw_file.Free
     493      begin
     494        FRawOpened := False;
     495        Fraw_file.Free;
     496      end
    507497      else
    508498        FRawOpened := True;
     
    513503        Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
    514504          fmOpenReadWrite);
    515       Fsep_file.Seek(raw_info.raw_addr, soFromBeginning);
    516       Fsep_file.Read(target^, raw_info.raw_size);
     505      Fsep_file.Seek(raw_info.RawAddr, soFromBeginning);
     506      streampos := Target.Position;
     507      Target.CopyFrom(Fsep_file, raw_info.RawSize);
     508      Target.Seek(streampos, soFromBeginning);
    517509      if UnloadWhenUnused then
    518         Fsep_file.Free
     510      begin
     511        FSepOpened := False;
     512        Fsep_file.Free;
     513      end
    519514      else
    520515        FSepOpened := True;
     
    523518end;
    524519
    525 
    526 
    527 
    528 procedure TOniDataDat.UpdateRawFile(fileid, dat_offset: LongWord;
    529   size: LongWord; target: Pointer);
    530 var
    531   raw_info: TRawInfo;
    532 begin
    533   if fileid < Self.GetFilesCount then
    534   begin
    535     raw_info := Self.GetRawInfo(fileid, dat_offset);
    536     if not raw_info.loc_sep then
    537     begin
    538       if FUnloadWhenUnused or not FRawOpened then
     520procedure TAccess_OniArchive.UpdateRawFile(FileID, DatOffset: Integer; Src: TStream);
     521var
     522  raw_info: TRawDataInfo;
     523begin
     524  if fileid < GetFileCount then
     525  begin
     526    raw_info := GetRawInfo(FileID, DatOffset);
     527    if not raw_info.LocSep then
     528    begin
     529      if not FRawOpened then
    539530        Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
    540531          fmOpenReadWrite);
    541       Fraw_file.Seek(raw_info.raw_addr, soFromBeginning);
    542       Fraw_file.Write(target^, raw_info.raw_size);
     532      Fraw_file.Seek(raw_info.RawAddr, soFromBeginning);
     533      Fraw_file.CopyFrom(Src, raw_info.RawSize);
    543534      if UnloadWhenUnused then
    544         Fraw_file.Free
     535      begin
     536        FRawOpened := False;
     537        Fraw_file.Free;
     538      end
    545539      else
    546540        FRawOpened := True;
     
    548542    else
    549543    begin
    550       if FUnloadWhenUnused or not FSepOpened then
     544      if not FSepOpened then
    551545        Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
    552546          fmOpenReadWrite);
    553       Fsep_file.Seek(raw_info.raw_addr, soFromBeginning);
    554       Fsep_file.Write(target^, raw_info.raw_size);
     547      Fsep_file.Seek(raw_info.RawAddr, soFromBeginning);
     548      Fsep_file.CopyFrom(Src, raw_info.RawSize);
    555549      if UnloadWhenUnused then
    556         Fsep_file.Free
     550      begin
     551        FSepOpened := False;
     552        Fsep_file.Free;
     553      end
    557554      else
    558555        FSepOpened := True;
     
    561558end;
    562559
    563 
    564 
    565 
    566 procedure TOniDataDat.LoadRawFilePart(fileid, dat_offset: LongWord;
    567   offset, size: LongWord; target: Pointer);
    568 var
    569   raw_info: TRawInfo;
    570   Data:     Tdata;
    571   mem:      TMemoryStream;
    572 begin
    573   if fileid < Self.GetFilesCount then
    574   begin
    575     raw_info := Self.GetRawInfo(fileid, dat_offset);
    576     SetLength(Data, raw_info.raw_size);
    577     Self.LoadRawFile(fileid, dat_offset, @Data[0]);
    578     mem := TMemoryStream.Create;
    579     mem.Write(Data[offset], size);
    580     mem.Read(target^, size);
    581     mem.Free;
    582   end;
    583 end;
    584 
    585 
    586 
    587 
    588 procedure TOniDataDat.UpdateRawFilePart(fileid, dat_offset: LongWord;
    589   offset, size: LongWord; target: Pointer);
    590 var
    591   raw_info: TRawInfo;
    592 begin
    593   if fileid < Self.GetFilesCount then
    594   begin
    595     raw_info := Self.GetRawInfo(fileid, dat_offset);
    596     if not raw_info.loc_sep then
    597     begin
    598       if FUnloadWhenUnused or not FRawOpened then
     560procedure TAccess_OniArchive.LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TStream);
     561var
     562  Data: TStream;
     563  streampos: Integer;
     564begin
     565  if not Assigned(Target) then
     566    Target := TMemoryStream.Create;
     567  if fileid < Self.GetFileCount then
     568  begin
     569    data := nil;
     570    LoadRawFile(FileID, DatOffset, Data);
     571    Data.Seek(Offset, soFromBeginning);
     572    streampos := Target.Position;
     573    Target.CopyFrom(Data, Size);
     574    Target.Seek(streampos, soFromBeginning);
     575  end;
     576end;
     577
     578procedure TAccess_OniArchive.UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: TStream);
     579var
     580  raw_info: TRawDataInfo;
     581begin
     582  if fileid < GetFileCount then
     583  begin
     584    raw_info := GetRawInfo(FileID, DatOffset);
     585    if not raw_info.LocSep then
     586    begin
     587      if not FRawOpened then
    599588        Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
    600589          fmOpenReadWrite);
    601       Fraw_file.Seek(raw_info.raw_addr + offset, soFromBeginning);
    602       Fraw_file.Write(target^, raw_info.raw_size);
     590      Fraw_file.Seek(raw_info.RawAddr + Offset, soFromBeginning);
     591      Fraw_file.CopyFrom(Src, Size);
    603592      if UnloadWhenUnused then
    604         Fraw_file.Free
     593      begin
     594        FRawOpened := False;
     595        Fraw_file.Free;
     596      end
    605597      else
    606598        FRawOpened := True;
     
    608600    else
    609601    begin
    610       if FUnloadWhenUnused or not FSepOpened then
     602      if not FSepOpened then
    611603        Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
    612604          fmOpenReadWrite);
    613       Fsep_file.Seek(raw_info.raw_addr + offset, soFromBeginning);
    614       Fsep_file.Write(target^, raw_info.raw_size);
     605      Fsep_file.Seek(raw_info.RawAddr + Offset, soFromBeginning);
     606      Fsep_file.CopyFrom(Src, Size);
    615607      if UnloadWhenUnused then
    616         Fsep_file.Free
     608      begin
     609        FSepOpened := False;
     610        Fsep_file.Free;
     611      end
    617612      else
    618613        FSepOpened := True;
     
    621616end;
    622617
    623 
    624 
    625 
    626 function TOniDataDat.AppendRawFile(loc_sep: Boolean; size: LongWord;
    627   target: Pointer): LongWord; //Returns new Address
    628 begin
    629   if not loc_sep then
    630   begin
    631     if FUnloadWhenUnused or not FRawOpened then
     618function TAccess_OniArchive.AppendRawFile(LocSep: Boolean; Size: Integer; Src: TStream): Integer;
     619begin
     620  if not LocSep then
     621  begin
     622    if not FRawOpened then
    632623      Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
    633624        fmOpenReadWrite);
    634625    Result := Fraw_file.Size;
    635626    Fraw_file.Seek(0, soFromEnd);
    636     Fraw_file.Write(target^, size);
    637     if UnloadWhenUnused then
    638       Fraw_file.Free
     627    Fraw_file.CopyFrom(Src, Size);
     628    if UnloadWhenUnused then
     629    begin
     630      FRawOpened := False;
     631      Fraw_file.Free;
     632    end
    639633    else
    640634      FRawOpened := True;
     
    642636  else
    643637  begin
    644     if FUnloadWhenUnused or not FSepOpened then
     638    if not FSepOpened then
    645639      Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
    646640        fmOpenReadWrite);
    647641    Result := Fsep_file.Size;
    648642    Fsep_file.Seek(0, soFromEnd);
    649     Fsep_file.Write(target^, size);
    650     if UnloadWhenUnused then
    651       Fsep_file.Free
     643    Fsep_file.CopyFrom(Src, Size);
     644    if UnloadWhenUnused then
     645    begin
     646      FSepOpened := False;
     647      Fsep_file.Free;
     648    end
    652649    else
    653650      FSepOpened := True;
     
    655652end;
    656653
    657 
    658 }
    659 
    660 
    661 
    662 
    663654end.
  • oup/rewrite/DataAccess/ConnectionManager.pas

    r97 r101  
    150150  ext := UpperCase(ExtractFileExt(FileName));
    151151
    152   if ext = 'ODB' then
     152  if ext = '.OLDB' then
    153153    backend := DB_ADB
    154   else if ext = 'DAT' then
     154  else if ext = '.DAT' then
    155155    backend := DB_ONI
    156156  else
     
    173173    FLastID := FConnections[i].ConnectionID;
    174174    Result := FLastID;
     175    Msg := SM_OK;
    175176  end
    176177  else
     
    180181    FConnections[i] := nil;
    181182    SetLength(FConnections, Length(FConnections) - 1);
    182     Msg := SM_UnknownError;
     183    Msg := CreateMsg;
    183184  end;
    184185end;
  • oup/rewrite/DataAccess/DataAccess.pas

    r97 r101  
    33
    44uses TypeDefs, Classes, StrUtils, SysUtils;
    5 //uses Data, Classes, SysUtils, StrUtils,
    6 //  Dialogs, ABSDecUtil, ABSMain, DB, Windows;
    7 
    85
    96type
    107  TDataAccess = class
    118  private
     9  protected
    1210    FConnectionID:  Integer;
    1311    FFileName:      String;
     
    1715    FChangeRights:  TChangeRights;
    1816    procedure SetDataOS(DataOS: TDataOS);
    19   protected
    2017  public
    2118    property ConnectionID: Integer      read FConnectionID;
     
    2421    property DataOS:       TDataOS      read FDataOS write SetDataOS;
    2522    property LevelNumber:  Integer      read FLevelNumber;
     23    property ChangeRights: TChangeRights read FChangeRights;
    2624
    2725    constructor Create(FileName: String; ConnectionID: Integer; var Msg: TStatusMessages); virtual; abstract;
     
    3735
    3836    procedure LoadDatFile(FileID: Integer; var Target: TStream); overload; virtual; abstract;
    39     procedure LoadDatFile(FileID: Integer; var Target: TByteData); overload; virtual; abstract;
     37    procedure LoadDatFile(FileID: Integer; var Target: TByteData); overload;
    4038    procedure UpdateDatFile(FileID: Integer; Src: TStream); overload; virtual; abstract;
    41     procedure UpdateDatFile(FileID: Integer; Src: TByteData); overload; virtual; abstract;
     39    procedure UpdateDatFile(FileID: Integer; Src: TByteData); overload;
    4240    procedure LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TStream); overload; virtual; abstract;
    43     procedure LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TByteData); overload; virtual; abstract;
    44     procedure LoadDatFilePart(FileID, Offset, Size: Integer; Target: Pointer); overload; virtual; abstract;
     41    procedure LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TByteData); overload;
     42    procedure LoadDatFilePart(FileID, Offset, Size: Integer; Target: Pointer); overload;
    4543    procedure UpdateDatFilePart(FileID, Offset, Size: Integer; Src: TStream); overload; virtual; abstract;
    46     procedure UpdateDatFilePart(FileID, Offset, Size: Integer; Src: TByteData); overload; virtual; abstract;
    47     procedure UpdateDatFilePart(FileID, Offset, Size: Integer; Src: Pointer); overload; virtual; abstract;
     44    procedure UpdateDatFilePart(FileID, Offset, Size: Integer; Src: TByteData); overload;
     45    procedure UpdateDatFilePart(FileID, Offset, Size: Integer; Src: Pointer); overload;
    4846
    4947    function GetRawList(FileID: Integer): TRawDataList; virtual; abstract;
    50     function GetRawInfo(FileID, DatOffset: Integer): TRawDataInfo;
     48    function GetRawInfo(FileID, DatOffset: Integer): TRawDataInfo; virtual; abstract;
    5149
    5250    procedure LoadRawFile(FileID, DatOffset: Integer; var Target: TStream); overload; virtual; abstract;
    53     procedure LoadRawFile(FileID, DatOffset: Integer; var Target: TByteData); overload; virtual; abstract;
    54     procedure UpdateRawFile(FileID, DatOffset, Size: Integer; Src: TStream); overload; virtual; abstract;
    55     procedure UpdateRawFile(FileID, DatOffset, Size: Integer; Src: TByteData); overload; virtual; abstract;
     51    procedure LoadRawFile(FileID, DatOffset: Integer; var Target: TByteData); overload;
     52    procedure UpdateRawFile(FileID, DatOffset: Integer; Src: TStream); overload; virtual; abstract;
     53    procedure UpdateRawFile(FileID, DatOffset: Integer; Src: TByteData); overload;
    5654    procedure LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TStream); overload; virtual; abstract;
    57     procedure LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TByteData); overload; virtual; abstract;
    58     procedure LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; Target: Pointer); overload; virtual; abstract;
     55    procedure LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TByteData); overload;
     56    procedure LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; Target: Pointer); overload;
    5957    procedure UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: TStream); overload; virtual; abstract;
    60     procedure UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: TByteData); overload; virtual; abstract;
    61     procedure UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: Pointer); overload; virtual; abstract;
    62 
    63     function AppendRawFile(LocSep: Boolean; Size: Integer; Src: TStream): Integer; overload; virtual; abstract;
    64     function AppendRawFile(LocSep: Boolean; Size: Integer; Src: TByteData): Integer; overload; virtual; abstract;
    65     function AppendRawFile(LocSep: Boolean; Size: Integer; Src: Pointer): Integer; overload; virtual; abstract;
     58    procedure UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: TByteData); overload;
     59    procedure UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: Pointer); overload;
     60
     61    function AppendRawFile(LocSep: Boolean; Size: Integer; Src: TStream): Integer; overload; virtual;
     62    function AppendRawFile(LocSep: Boolean; Size: Integer; Src: TByteData): Integer; overload;
     63    function AppendRawFile(LocSep: Boolean; Size: Integer; Src: Pointer): Integer; overload;
    6664  published
    6765  end;
     
    120118
    121119
    122 function TDataAccess.GetRawInfo(FileID, DatOffset: Integer): TRawDataInfo;
    123 var
    124   i: LongWord;
    125   RawList: TRawDataList;
    126 begin
    127   RawList          := GetRawList(FileID);
    128   Result.SrcID     := -1;
    129   Result.SrcOffset := -1;
    130   Result.RawAddr   := -1;
    131   Result.RawSize   := -1;
    132   if Length(RawList) > 0 then
    133   begin
    134     for i := 0 to High(RawList) do
    135     begin
    136       if RawList[i].SrcOffset = DatOffset then
    137       begin
    138         Result.SrcID     := FileID;
    139         Result.SrcOffset := RawList[i].SrcOffset;
    140         Result.RawAddr   := RawList[i].RawAddr;
    141         Result.RawSize   := RawList[i].RawSize;
    142         Result.LocSep    := RawList[i].LocSep;
    143         Break;
    144       end;
    145     end;
    146   end;
    147 end;
     120procedure TDataAccess.LoadDatFile(FileID: Integer; var Target: TByteData);
     121var
     122  data: TStream;
     123begin
     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;
     132end;
     133
     134procedure TDataAccess.UpdateDatFile(FileID: Integer; Src: TByteData);
     135var
     136  data: TStream;
     137begin
     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;
     146end;
     147
     148procedure TDataAccess.LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TByteData);
     149var
     150  data: TStream;
     151begin
     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;
     160end;
     161
     162procedure TDataAccess.LoadDatFilePart(FileID, Offset, Size: Integer; Target: Pointer);
     163var
     164  data: TStream;
     165begin
     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;
     173end;
     174
     175procedure TDataAccess.UpdateDatFilePart(FileID, Offset, Size: Integer; Src: TByteData);
     176var
     177  data: TStream;
     178begin
     179  if fileid < GetFileCount then
     180  begin
     181    data := TMemoryStream.Create;
     182    data.Write(Src[0], Size);
     183    data.Seek(0, soFromBeginning);
     184    UpdateDatFilePart(FileID, offset, size, data);
     185    data.Free;
     186  end;
     187end;
     188
     189procedure TDataAccess.UpdateDatFilePart(FileID, Offset, Size: Integer; Src: Pointer);
     190var
     191  data: TStream;
     192begin
     193  if fileid < GetFileCount then
     194  begin
     195    data := TMemoryStream.Create;
     196    data.Write(Src^, Size);
     197    data.Seek(0, soFromBeginning);
     198    UpdateDatFilePart(FileID, offset, size, data);
     199    data.Free;
     200  end;
     201end;
     202
     203
     204
     205procedure TDataAccess.LoadRawFile(FileID, DatOffset: Integer; var Target: TByteData);
     206var
     207  data: TStream;
     208begin
     209  if fileid < GetFileCount then
     210  begin
     211    data := nil;
     212    LoadRawFile(FileID, DatOffset, data);
     213    SetLength(Target, data.Size);
     214    data.Read(Target[0], data.Size);
     215    data.Free;
     216  end;
     217end;
     218
     219procedure TDataAccess.UpdateRawFile(FileID, DatOffset: Integer; Src: TByteData);
     220var
     221  data: TStream;
     222begin
     223  if fileid < GetFileCount then
     224  begin
     225    data := TMemoryStream.Create;
     226    data.Write(Src[0], Length(Src));
     227    data.Seek(0, soFromBeginning);
     228    UpdateRawFile(FileID, DatOffset, data);
     229    data.Free;
     230  end;
     231end;
     232
     233procedure TDataAccess.LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TByteData);
     234var
     235  data: TStream;
     236begin
     237  if fileid < GetFileCount then
     238  begin
     239    data := nil;
     240    SetLength(Target, Size);
     241    LoadRawFile(FileID, DatOffset, Data);
     242    Data.Seek(Offset, soFromBeginning);
     243    Data.Read(Target[0], Size);
     244    Data.Free;
     245  end;
     246end;
     247
     248procedure TDataAccess.LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; Target: Pointer);
     249var
     250  data: TStream;
     251begin
     252  if fileid < GetFileCount then
     253  begin
     254    data := nil;
     255    LoadRawFile(FileID, DatOffset, Data);
     256    Data.Seek(Offset, soFromBeginning);
     257    Data.Read(Target^, Size);
     258    Data.Free;
     259  end;
     260end;
     261
     262procedure TDataAccess.UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: TByteData);
     263var
     264  data: TStream;
     265begin
     266  if fileid < GetFileCount then
     267  begin
     268    data := TMemoryStream.Create;
     269    data.Write(Src[0], Size);
     270    data.Seek(0, soFromBeginning);
     271    UpdateRawFilePart(FileID, DatOffset, Offset, Size, data);
     272    data.Free;
     273  end;
     274end;
     275
     276procedure TDataAccess.UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: Pointer);
     277var
     278  data: TStream;
     279begin
     280  if fileid < GetFileCount then
     281  begin
     282    data := TMemoryStream.Create;
     283    data.Write(Src^, Size);
     284    data.Seek(0, soFromBeginning);
     285    UpdateRawFilePart(FileID, DatOffset, Offset, Size, data);
     286    data.Free;
     287  end;
     288end;
     289
     290
     291function TDataAccess.AppendRawFile(LocSep: Boolean; Size: Integer; Src: TStream): Integer;
     292begin
     293  raise ENotImplemented.Create('ERROR: AppendRawFile not implemented here!!!');
     294end;
     295
     296
     297function TDataAccess.AppendRawFile(LocSep: Boolean; Size: Integer; Src: TByteData): Integer;
     298var
     299  data: TStream;
     300begin
     301  data := TMemoryStream.Create;
     302  data.Write(Src[0], Size);
     303  AppendRawFile(LocSep, Size, data);
     304  data.Free;
     305end;
     306
     307function TDataAccess.AppendRawFile(LocSep: Boolean; Size: Integer; Src: Pointer): Integer;
     308var
     309  data: TStream;
     310begin
     311  data := TMemoryStream.Create;
     312  data.Write(Src^, Size);
     313  AppendRawFile(LocSep, Size, data);
     314  data.Free;
     315end;
     316
    148317
    149318
  • oup/rewrite/Global/OniImgClass.pas

    r97 r101  
    700700var
    701701  data: TByteData;
     702  streampos: Integer;
    702703begin
    703704  GetAsBMP(data);
     705  streampos := Target.Position;
    704706  Target.Write(data[0], Length(data));
     707  Target.Seek(streampos, soFromBeginning);
    705708end;
    706709
  • oup/rewrite/Global/RawList.pas

    r97 r101  
    33interface
    44
    5 uses TypeDefs, ConnectionManager;
     5uses TypeDefs;
    66
    77type
    88  THandler = function(ConnectionID, FileID: Integer): TRawDataList;
    9   TRawListHandlers = record
     9  TRawListHandler = record
    1010    Ext:     String[4];
    1111    needed:  Boolean;
    1212    Handler: THandler;
    1313  end;
     14  TRawListHandlers = array of TRawListHandler;
    1415
    1516  TRawLists = class
     
    2526var
    2627  RawLists: TRawLists;
    27  
     28
    2829
    2930implementation
    3031
    3132uses
    32   Template;
     33  Template, ConnectionManager, Access_OniArchive, Classes, SysUtils;
    3334
    3435
     
    3940  i:     Integer;
    4041begin
    41   if not connection.OSisMac then
    42   begin
    43     ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $1C, 4, @links);
    44     links := links * 2;
    45     SetLength(Result, links);
    46     for i := 0 to links - 1 do
    47     begin
    48       Result[i].src_offset := $20 + i * 4;
    49       ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $20 + i * 4, 4, @link);
    50       Result[i].raw_addr := link;
    51       Result[i].raw_size := 32;
    52       Result[i].loc_sep  := False;
    53     end;
     42  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $1C, 4, @links);
     43  links := links * 2;
     44  SetLength(Result, links);
     45  for i := 0 to links - 1 do
     46  begin
     47    Result[i].SrcOffset := $20 + i * 4;
     48    ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $20 + i * 4, 4, @link);
     49    Result[i].RawAddr := link;
     50    Result[i].RawSize := 32;
     51    Result[i].LocSep  := False;
    5452  end;
    5553end;
     
    6462  i:     Integer;
    6563begin
    66   if not connection.OSisMac then
    67   begin
    68     ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $1C, 4, @links);
    69     SetLength(Result, links);
    70     for i := 0 to links - 1 do
    71     begin
    72       Result[i].src_offset := $20 + i * $74 + $24;
    73       ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $20 + i * $74 + $24, 4, @link);
    74       Result[i].raw_addr := link;
    75       ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $20 + i * $74 + $28, 4, @link);
    76       Result[i].raw_size := link;
    77       Result[i].loc_sep  := False;
    78     end;
     64  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $1C, 4, @links);
     65  SetLength(Result, links);
     66  for i := 0 to links - 1 do
     67  begin
     68    Result[i].SrcOffset := $20 + i * $74 + $24;
     69    ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $20 + i * $74 + $24, 4, @link);
     70    Result[i].RawAddr := link;
     71    ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $20 + i * $74 + $28, 4, @link);
     72    Result[i].RawSize := link;
     73    Result[i].LocSep  := False;
    7974  end;
    8075end;
     
    9186  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $08, 4, @datasize);
    9287  SetLength(Result, 1);
    93   Result[0].src_offset := $0C;
    94   Result[0].raw_addr   := link;
    95   Result[0].raw_size   := datasize;
    96   Result[0].loc_sep    := connection.OSisMac;
     88  Result[0].SrcOffset := $0C;
     89  Result[0].RawAddr   := link;
     90  Result[0].RawSize   := datasize;
     91  Result[0].LocSep    := not (ConManager.Connection[ConnectionID].DataOS = DOS_WIN);
    9792end;
    9893
     
    108103  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $0C, 4, @link);
    109104  SetLength(Result, 1);
    110   Result[0].src_offset := $0C;
    111   Result[0].raw_addr   := link;
    112   Result[0].raw_size   := datasize;
    113   Result[0].loc_sep    := connection.OSisMac;
     105  Result[0].SrcOffset := $0C;
     106  Result[0].RawAddr   := link;
     107  Result[0].RawSize   := datasize;
     108  Result[0].LocSep     := not (ConManager.Connection[ConnectionID].DataOS = DOS_WIN);
    114109end;
    115110
     
    123118begin
    124119  SetLength(Result, 1);
    125   if not connection.OSisMac then
     120  if ConManager.Connection[ConnectionID].DataOS = DOS_MAC then
     121  begin
     122    ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $10, 4, @datasize);
     123    ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $14, 4, @link);
     124    Result[0].SrcOffset := $14;
     125  end
     126  else
    126127  begin
    127128    ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $40, 4, @datasize);
    128129    ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $44, 4, @link);
    129     Result[0].src_offset := $44;
    130   end
    131   else
    132   begin
    133     ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $10, 4, @datasize);
    134     ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $14, 4, @link);
    135     Result[0].src_offset := $14;
    136   end;
    137   Result[0].raw_addr := link;
    138   Result[0].raw_size := datasize;
    139   Result[0].loc_sep  := False;
     130    Result[0].SrcOffset := $44;
     131  end;
     132  Result[0].RawAddr := link;
     133  Result[0].RawSize := datasize;
     134  Result[0].LocSep  := False;
    140135end;
    141136
     
    148143  links: Integer;
    149144  j, k:  Integer;
    150   Data:  TByteData;
     145//  Data:  TByteData;
     146  Data:  TStream;
    151147begin
    152148  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $18, 4, @baselink);
     
    155151  begin
    156152    ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $20 + (links - 1) * 4, 4, @lastlink);
    157     SetLength(Data, lastlink + 1024);
    158     TOniDataDat(connection).LoadRawOffset(False,
    159       baselink, lastlink + 1024, Data);
     153//    SetLength(Data, lastlink + 1024);
     154    Data := nil;
     155    TAccess_OniArchive(ConManager.Connection[ConnectionID]).LoadRawOffset(
     156          False, baselink, lastlink + 1024, Data);
     157//    TOniDataDat(connection).LoadRawOffset(False, baselink, lastlink + 1024, Data);
    160158    //      connection.LoadRawFile(fileid,$1C,baselink,lastlink+1024,False,@data[0]);
     159    raise ENotImplemented.Create('RawList.SUBT');
     160  end;
     161{
    161162    k := 0;
    162163    for j := 0 to 1024 do
     
    182183    end;
    183184  end;
     185}
    184186end;
    185187
     
    203205  {y-pos}
    204206  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $0C, 4, @link);
    205   Result[0].src_offset := $0C;
    206   Result[0].raw_addr   := link;
    207   Result[0].raw_size   := frames * 4;
     207  Result[0].SrcOffset := $0C;
     208  Result[0].RawAddr   := link;
     209  Result[0].RawSize   := frames * 4;
    208210  {x-z-pos}
    209211  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $10, 4, @link);
    210   Result[1].src_offset := $10;
    211   Result[1].raw_addr   := link;
    212   Result[1].raw_size   := frames * 8;
     212  Result[1].SrcOffset := $10;
     213  Result[1].RawAddr   := link;
     214  Result[1].RawSize   := frames * 8;
    213215  {attacks}
    214216  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $182, 1, @tempb);
    215217  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $14, 4, @link);
    216   Result[2].src_offset := $14;
    217   Result[2].raw_addr   := link;
    218   Result[2].raw_size   := tempb * 32;
     218  Result[2].SrcOffset := $14;
     219  Result[2].RawAddr   := link;
     220  Result[2].RawSize   := tempb * 32;
    219221  {damage}
    220222  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $183, 1, @tempb);
    221223  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $18, 4, @link);
    222   Result[3].src_offset := $18;
    223   Result[3].raw_addr   := link;
    224   Result[3].raw_size   := tempb * 8;
     224  Result[3].SrcOffset := $18;
     225  Result[3].RawAddr   := link;
     226  Result[3].RawSize   := tempb * 8;
    225227  {motionblur}
    226228  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $184, 1, @tempb);
    227229  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $1C, 4, @link);
    228   Result[4].src_offset := $1C;
    229   Result[4].raw_addr   := link;
    230   Result[4].raw_size   := tempb * 8;
     230  Result[4].SrcOffset := $1C;
     231  Result[4].RawAddr   := link;
     232  Result[4].RawSize   := tempb * 8;
    231233  {shortcut}
    232234  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $185, 1, @tempb);
    233235  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $20, 4, @link);
    234   Result[5].src_offset := $20;
    235   Result[5].raw_addr   := link;
    236   Result[5].raw_size   := tempb * 8;
     236  Result[5].SrcOffset := $20;
     237  Result[5].RawAddr   := link;
     238  Result[5].RawSize   := tempb * 8;
    237239  {throw}
    238240  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $24, 4, @link);
    239   Result[6].src_offset := $24;
    240   Result[6].raw_addr   := link;
     241  Result[6].SrcOffset := $24;
     242  Result[6].RawAddr   := link;
    241243  if link > 0 then
    242     Result[6].raw_size := 24
     244    Result[6].RawSize := 24
    243245  else
    244     Result[6].raw_size := 0;
     246    Result[6].RawSize := 0;
    245247  {footstep}
    246248  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $186, 1, @tempb);
    247249  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $28, 4, @link);
    248   Result[7].src_offset := $28;
    249   Result[7].raw_addr   := link;
    250   Result[7].raw_size   := tempb * 4;
     250  Result[7].SrcOffset := $28;
     251  Result[7].RawAddr   := link;
     252  Result[7].RawSize   := tempb * 4;
    251253  {particle}
    252254  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $187, 1, @tempb);
    253255  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $2C, 4, @link);
    254   Result[8].src_offset := $2C;
    255   Result[8].raw_addr   := link;
    256   Result[8].raw_size   := tempb * 24;
     256  Result[8].SrcOffset := $2C;
     257  Result[8].RawAddr   := link;
     258  Result[8].RawSize   := tempb * 24;
    257259  {position}
    258260  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $30, 4, @link);
    259   Result[9].src_offset := $30;
    260   Result[9].raw_addr   := link;
    261   Result[9].raw_size   := frames * 8;
     261  Result[9].SrcOffset := $30;
     262  Result[9].RawAddr   := link;
     263  Result[9].RawSize   := frames * 8;
    262264  {particle}
    263265  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $154, 2, @tempw);
    264266  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $38, 4, @link);
    265   Result[11].src_offset := $38;
    266   Result[11].raw_addr   := link;
    267   Result[11].raw_size   := tempw * 34;
     267  Result[11].SrcOffset := $38;
     268  Result[11].RawAddr   := link;
     269  Result[11].RawSize   := tempw * 34;
    268270  {extent}
    269271  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $138, 4, @templ);
    270272  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $13C, 4, @link);
    271   Result[12].src_offset := $13C;
    272   Result[12].raw_addr   := link;
    273   Result[12].raw_size   := templ * 12;
     273  Result[12].SrcOffset := $13C;
     274  Result[12].RawAddr   := link;
     275  Result[12].RawSize   := templ * 12;
    274276
    275277  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $34, 4, @link);
     
    280282    i := 0;
    281283    SetLength(Data, $FFFF);
    282     TOniDataDat(connection).LoadRawOffset(False, link, $FFFF, Data);
     284    TAccess_OniArchive(ConManager.Connection[ConnectionID]).LoadRawOffset(
     285          False, link, $FFFF, Data);
    283286    offset := Data[$24] + Data[$25] * 256;
    284287    while (offset + i < Length(Data)) and (frame_count < frames - 1) do
     
    291294    begin
    292295      Inc(i, tempw);
    293       Result[10].raw_size := offset + i;
     296      Result[10].RawSize := offset + i;
    294297    end
    295298    else
    296299    begin
    297       Result[10].raw_size := 0;
     300      Result[10].RawSize := 0;
    298301    end;
    299302  end;
    300   Result[10].src_offset := $34;
    301   Result[10].raw_addr   := link;
     303  Result[10].SrcOffset := $34;
     304  Result[10].RawAddr   := link;
    302305end;
    303306
     
    327330  end;
    328331  SetLength(Result, 1);
    329   if not connection.OSisMac then
    330   begin
    331     Result[0].src_offset := $9C;
    332     Result[0].raw_addr   := link_pc;
     332  if ConManager.Connection[ConnectionID].DataOS = DOS_WIN then
     333  begin
     334    Result[0].SrcOffset := $9C;
     335    Result[0].RawAddr   := link_pc;
    333336  end
    334337  else
    335338  begin
    336     Result[0].src_offset := $A0;
    337     Result[0].raw_addr   := link_mac;
    338   end;
    339   Result[0].raw_size := datasize;
    340   Result[0].loc_sep  := connection.OSisMac;
     339    Result[0].SrcOffset := $A0;
     340    Result[0].RawAddr   := link_mac;
     341  end;
     342  Result[0].RawSize := datasize;
     343  Result[0].LocSep  := not (ConManager.Connection[ConnectionID].DataOS = DOS_WIN);
    341344end;
    342345
  • oup/rewrite/Global/TypeDefs.pas

    r97 r101  
    99
    1010  TDataBackend = (DB_ONI, DB_ADB);
    11   TDataOS = (DOS_WIN, DOS_MAC);
     11  TDataOS = (DOS_WIN, DOS_WINDEMO, DOS_MAC, DOS_MACBETA);
    1212
    13   TChangeRights = set of (CR_EditDat, CR_EditRaw, CR_ResizeDat, CR_ResizeRaw);
     13  TChangeRights = set of (CR_EditDat, CR_EditRaw, CR_ResizeDat, CR_ResizeRaw, CR_AppendRaw);
    1414
    1515  TStatusMessages = (
     
    1919      SM_UnknownExtension,
    2020      SM_IncompatibleFile,
     21      SM_IncompatibleDBVersion,
    2122      SM_UnknownError
    2223  );
     24
     25  TExtensionsMap = array of packed record
     26      Ident:       array[0..$7] of Byte;
     27      Extension:   array[0..$3] of Char;
     28      ExtCount:    LongWord;
     29  end;
    2330
    2431  TFileInfo = packed record
     
    3037      DatAddr:     Integer;
    3138  end;
     39  TFiles = array of TFileInfo;
    3240
    3341  TRawDataInfo = record
  • oup/rewrite/Helper/Helper_ValueEdit.pas

    r93 r101  
    3535implementation
    3636
    37 uses BinEdit, RawEdit, DataStructures, Main;
     37uses BinEdit, RawEdit, DatStructureLoader, Main;
    3838
    3939{$R *.dfm}
  • oup/rewrite/OniUnPacker.dpr

    r97 r101  
    1515  Settings in 'Settings.pas' {Form_Settings},
    1616  Template in 'Tools\Template.pas' {Form_ToolTemplate},
    17   TxmpReplace in 'Tools\TxmpReplace.pas' {Form_TxmpReplace},
    18   BinEdit in 'Tools\BinEdit.pas' {Form_BinEdit},
    19   Extractor in 'Tools\Extractor.pas' {Form_Extractor},
    2017  Preview in 'Tools\Preview.pas' {Form_Preview},
    21   RawEdit in 'Tools\RawEdit.pas' {Form_RawEdit},
    2218  OniImgClass in 'Global\OniImgClass.pas',
    2319  Functions in 'Global\Functions.pas',
    24   Helper_ValueEdit in 'Helper\Helper_ValueEdit.pas' {Form_ValueEdit},
    2520  RawList in 'Global\RawList.pas',
    2621  DatStructureLoader in 'Global\DatStructureLoader.pas',
     
    3530  Application.CreateForm(TForm_Main, Form_Main);
    3631  Application.CreateForm(TForm_Settings, Form_Settings);
    37   Application.CreateForm(TForm_ValueEdit, Form_ValueEdit);
    3832  Application.Run;
    3933end.
  • oup/rewrite/Tools/Preview.dfm

    r93 r101  
    11inherited Form_Preview: TForm_Preview
    22  Caption = 'Preview'
     3  OnCreate = FormCreate
     4  ExplicitWidth = 500
     5  ExplicitHeight = 450
    36  PixelsPerInch = 96
    47  TextHeight = 13
  • oup/rewrite/Tools/Preview.pas

    r97 r101  
    8484procedure TForm_Preview.LoadImage(fileid, index: Integer);
    8585var
    86   Data:      TByteData;
    8786  memstream: TMemoryStream;
    8887  OniImage:  TOniImage;
    89 
    9088begin
    9189  OniImage := TOniImage.Create;
    9290  OniImage.Load(ConnectionID, fileid);
    93   OniImage.GetAsBMP(Data);
     91  memstream := TMemoryStream.Create;
     92  OniImage.GetAsBMP(TStream(memstream));
    9493  OniImage.Free;
    95 
    96   memstream := TMemoryStream.Create;
    97   memstream.Write(Data[0], Length(Data));
    98   memstream.Seek(0, soFromBeginning);
    9994  bitmaps[index].LoadFromStream(memstream);
    10095  memstream.Free;
  • oup/rewrite/Tools/Template.dfm

    r97 r101  
    1919  OnActivate = FormActivate
    2020  OnClose = FormClose
    21   OnResize = FormResize
    2221  PixelsPerInch = 96
    2322  TextHeight = 13
     
    247246        Font.Color = clWindowText
    248247        Font.Height = -11
    249         Font.Name = 'Tahoma'
     248        Font.Name = 'Courier'
    250249        Font.Style = []
    251250        ItemHeight = 13
  • oup/rewrite/Tools/Template.pas

    r97 r101  
    5454      Shift: TShiftState; X, Y: Integer);
    5555
    56     procedure FormResize(Sender: TObject);
    5756    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    5857    procedure popup_importClick(Sender: TObject);
     
    220219  fs: TFileStream;
    221220begin
    222   id := ConManager.Connection[FConnectionID].ExtractFileIDOfName(filelist.Items.Strings[filelist.ItemIndex]);
    223   finfo := ConManager.Connection[FConnectionID].GetFileInfo(id);
    224 
    225   importd.Filter := 'Files of matching extension (*.' + finfo.Extension + ')|*.' +
    226         finfo.Extension + '|All files|*.*';
    227   if importd.Execute then
    228   begin
    229     fs := TFileStream.Create(importd.FileName, fmOpenRead);
    230     if fs.Size <> finfo.Size then
    231       ShowMessage('Can''t import ' + ExtractFilename(importd.FileName) +
    232         ', file has to have same size as file in .dat.' + CrLf +
    233         'Size of file in .dat: ' + FormatFileSize(finfo.Size) + CrLf +
    234         'Size of chosen file: ' + FormatFileSize(fs.Size))
    235     else begin
     221  if CR_EditDat in ConManager.Connection[FConnectionID].ChangeRights then
     222  begin
     223    id := ConManager.Connection[FConnectionID].ExtractFileIDOfName(filelist.Items.Strings[filelist.ItemIndex]);
     224    finfo := ConManager.Connection[FConnectionID].GetFileInfo(id);
     225
     226    importd.Filter := 'Files of matching extension (*.' + finfo.Extension + ')|*.' +
     227          finfo.Extension + '|All files|*.*';
     228    if importd.Execute then
     229    begin
     230      fs := TFileStream.Create(importd.FileName, fmOpenRead);
     231      if fs.Size <> finfo.Size then
     232      begin
     233        if not (CR_ResizeDat in ConManager.Connection[FConnectionID].ChangeRights) then
     234        begin
     235          ShowMessage('Can''t import ' + ExtractFilename(importd.FileName) +
     236            ', file has to have same size as file in .dat with this backend.' + CrLf +
     237            'Size of file in .dat: ' + FormatFileSize(finfo.Size) + CrLf +
     238            'Size of chosen file: ' + FormatFileSize(fs.Size));
     239          Exit;
     240        end else begin
     241          if MessageBox(Self.Handle,
     242              PChar('File has different size from the file in the .dat.' + CrLf +
     243                    'Size of file in .dat: ' + FormatFileSize(finfo.Size) + CrLf +
     244                    'Size of chosen file: ' + FormatFileSize(fs.Size) + CrLf +
     245                    'Replace anyway?'), PChar('Different size'), MB_YESNO + MB_ICONWARNING) = ID_NO then
     246          begin
     247            Exit;
     248          end;
     249        end;
     250      end;
    236251      ConManager.Connection[FConnectionID].UpdateDatFile(id, fs);
    237252      Self.listClick(Self);
     253      fs.Free;
    238254    end;
    239     fs.Free;
     255  end else begin
     256    ShowMessage('Editing .dat-contents not allowed with this backend.');
    240257  end;
    241258end;
     
    449466
    450467
    451 procedure TForm_ToolTemplate.FormResize(Sender: TObject);
    452 begin
    453   if Self.Width < 300 then
    454     Self.Width := 300;
    455   if Self.Height < 200 then
    456     Self.Height := 200;
    457 end;
    458 
    459 
    460 
    461468function TForm_ToolTemplate.GetToolCloseable: Boolean;
    462469begin
Note: See TracChangeset for help on using the changeset viewer.