Changeset 248 for oup/current/DataAccess


Ignore:
Timestamp:
Nov 26, 2007, 12:02:28 PM (17 years ago)
Author:
alloc
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • oup/current/DataAccess/Access_OniArchive.pas

    r243 r248  
    1212    Fdat_files:          TFiles;
    1313    Fdat_extensionsmap:  TExtensionsMap;
    14     FUnloadWhenUnused:   Boolean;
    15     FDatOpened:          Boolean;
    16     FRawOpened:          Boolean;
    17     FSepOpened:          Boolean;
    18     procedure SetUnloadWhenUnused(doit: Boolean);
    1914  protected
    2015  public
    21     property UnloadWhenUnused: Boolean Read FUnloadWhenUnused Write SetUnloadWhenUnused;
    22 
    2316    constructor Create(DatFilename: String; ConnectionID: Integer; var Msg: TStatusMessages); override;
    2417    procedure Close; override;
     
    7265  Fdat_namedfilesmap: TNamedFilesMap;
    7366begin
    74   FUnloadWhenUnused := True;
    75   FDatOpened := False;
    76   FRawOpened := False;
    7767  Msg := SM_UnknownError;
    7868  if not FileExists(DatFilename) then
     
    156146  FLevelNumber := FLevelNumber div 2;
    157147
    158   Fdat_file.Free;
     148  Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
     149    fmOpenReadWrite);
     150  if not (FDataOS = DOS_WIN) then
     151    Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
     152      fmOpenReadWrite);
    159153
    160154  Msg := SM_OK;
     
    169163
    170164
    171 procedure TAccess_OniArchive.SetUnloadWhenUnused(doit: Boolean);
    172 begin
    173   FUnloadWhenUnused := doit;
    174   if FUnloadWhenUnused then
    175   begin
    176     if FDatOpened then
    177     begin
    178       FDatOpened := False;
    179       Fdat_file.Free;
    180     end;
    181     if FRawOpened then
    182     begin
    183       FRawOpened := False;
    184       Fraw_file.Free;
    185     end;
    186     if FSepOpened then
    187     begin
    188       FSepOpened := False;
    189       Fsep_file.Free;
    190     end;
    191   end
    192   else
    193   begin
    194     if not FDatOpened then
    195     begin
    196       Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);
    197       FDatOpened := True;
    198     end;
    199     if not FRawOpened then
    200     begin
    201       Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
    202         fmOpenReadWrite);
    203       FRawOpened := True;
    204     end;
    205     if (not FSepOpened) and (FDataOS <> DOS_WIN) then
    206     begin
    207       Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
    208         fmOpenReadWrite);
    209       FSepOpened := True;
    210     end;
    211   end;
    212 end;
    213 
    214 
    215 
    216 
    217 
    218165procedure TAccess_OniArchive.Close;
    219166begin
    220   if FDatOpened then
     167  if Assigned(Fdat_file) then
    221168    Fdat_file.Free;
    222   if FRawOpened then
     169  if Assigned(Fraw_file) then
    223170    Fraw_file.Free;
    224   if FSepOpened then
     171  if Assigned(Fsep_file) then
    225172    Fsep_file.Free;
    226173  Self.Free;
     
    373320  if fileid < GetFileCount then
    374321  begin
     322    if not Assigned(Target) then
     323      Target := TMemoryStream.Create;
    375324    if GetFileInfo(FileID).Size > 0 then
    376325    begin
    377       if not Assigned(Target) then
    378         Target := TMemoryStream.Create;
    379       if not FDatOpened then
    380         Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);
    381326      Fdat_file.Seek(Fdat_files[fileid].DatAddr, soFromBeginning);
    382327      streampos := Target.Position;
    383328      Target.CopyFrom(Fdat_file, Fdat_files[fileid].Size);
    384329      Target.Seek(streampos, soFromBeginning);
    385       if UnloadWhenUnused then
    386       begin
    387         Fdat_file.Free;
    388         FDatOpened := False;
    389       end
    390       else
    391         FDatOpened := True;
    392330    end;
    393331  end;
     
    398336  if fileid < GetFileCount then
    399337  begin
    400     if not FDatOpened then
    401       Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);
    402338    Fdat_file.Seek(Fdat_files[fileid].DatAddr, soFromBeginning);
    403339    Fdat_file.CopyFrom(Src, Fdat_files[fileid].Size);
    404     if UnloadWhenUnused then
    405     begin
    406       Fdat_file.Free;
    407       FDatOpened := False;
    408     end
    409     else
    410       FDatOpened := True;
    411340  end;
    412341end;
     
    420349    if not Assigned(Target) then
    421350      Target := TMemoryStream.Create;
    422     if not FDatOpened then
    423       Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);
    424351    Fdat_file.Seek(Fdat_files[fileid].DatAddr + offset, soFromBeginning);
    425352    streampos := Target.Position;
    426353    Target.CopyFrom(Fdat_file, size);
    427354    Target.Seek(streampos, soFromBeginning);
    428     if UnloadWhenUnused then
    429     begin
    430       FDatOpened := False;
    431       Fdat_file.Free;
    432     end
    433     else
    434       FDatOpened := True;
    435355  end;
    436356end;
     
    440360  if fileid < GetFileCount then
    441361  begin
    442     if not FDatOpened then
    443       Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);
    444362    Fdat_file.Seek(Fdat_files[fileid].DatAddr + offset, soFromBeginning);
    445363    Fdat_file.CopyFrom(Src, Size);
    446     if UnloadWhenUnused then
    447     begin
    448       Fdat_file.Free;
    449       FDatOpened := False;
    450     end
    451     else
    452       FDatOpened := True;
    453364  end;
    454365end;
     
    531442  if not LocSep then
    532443  begin
    533     if not FRawOpened then
    534       Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
    535         fmOpenReadWrite);
    536444    if RawAddr <= Fraw_file.Size then
    537445    begin
     
    540448      Target.Seek(0, soFromBeginning);
    541449    end;
    542     if UnloadWhenUnused then
    543     begin
    544       FRawOpened := False;
    545       Fraw_file.Free;
    546     end
    547     else
    548       FRawOpened := True;
    549450  end
    550451  else
    551452  begin
    552     if not FSepOpened then
    553       Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
    554         fmOpenReadWrite);
    555453    if RawAddr <= Fsep_file.Size then
    556454    begin
     
    559457      Target.Seek(0, soFromBeginning);
    560458    end;
    561     if UnloadWhenUnused then
    562     begin
    563       FSepOpened := False;
    564       Fsep_file.Free;
    565     end
    566     else
    567       FSepOpened := True;
    568459  end;
    569460end;
     
    591482    if not raw_info.LocSep then
    592483    begin
    593       if not FRawOpened then
    594         Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
    595           fmOpenReadWrite);
    596484      Fraw_file.Seek(raw_info.RawAddr, soFromBeginning);
    597485      streampos := Target.Position;
    598486      Target.CopyFrom(Fraw_file, raw_info.RawSize);
    599487      Target.Seek(streampos, soFromBeginning);
    600       if UnloadWhenUnused then
    601       begin
    602         FRawOpened := False;
    603         Fraw_file.Free;
    604       end
    605       else
    606         FRawOpened := True;
    607488    end
    608489    else
    609490    begin
    610       if FUnloadWhenUnused or not FSepOpened then
    611         Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
    612           fmOpenReadWrite);
    613491      Fsep_file.Seek(raw_info.RawAddr, soFromBeginning);
    614492      streampos := Target.Position;
    615493      Target.CopyFrom(Fsep_file, raw_info.RawSize);
    616494      Target.Seek(streampos, soFromBeginning);
    617       if UnloadWhenUnused then
    618       begin
    619         FSepOpened := False;
    620         Fsep_file.Free;
    621       end
    622       else
    623         FSepOpened := True;
    624495    end;
    625496  end;
     
    635506    if not raw_info.LocSep then
    636507    begin
    637       if not FRawOpened then
    638         Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
    639           fmOpenReadWrite);
    640508      Fraw_file.Seek(raw_info.RawAddr, soFromBeginning);
    641509      Fraw_file.CopyFrom(Src, Min(raw_info.RawSize, Src.Size));
    642       if UnloadWhenUnused then
    643       begin
    644         FRawOpened := False;
    645         Fraw_file.Free;
    646       end
    647       else
    648         FRawOpened := True;
    649510    end
    650511    else
    651512    begin
    652       if not FSepOpened then
    653         Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
    654           fmOpenReadWrite);
    655513      Fsep_file.Seek(raw_info.RawAddr, soFromBeginning);
    656514      Fsep_file.CopyFrom(Src, raw_info.RawSize);
    657       if UnloadWhenUnused then
    658       begin
    659         FSepOpened := False;
    660         Fsep_file.Free;
    661       end
    662       else
    663         FSepOpened := True;
    664515    end;
    665516  end;
     
    694545    if not raw_info.LocSep then
    695546    begin
    696       if not FRawOpened then
    697         Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
    698           fmOpenReadWrite);
    699547      Fraw_file.Seek(raw_info.RawAddr + Offset, soFromBeginning);
    700548      Fraw_file.CopyFrom(Src, Size);
    701       if UnloadWhenUnused then
    702       begin
    703         FRawOpened := False;
    704         Fraw_file.Free;
    705       end
    706       else
    707         FRawOpened := True;
    708549    end
    709550    else
    710551    begin
    711       if not FSepOpened then
    712         Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
    713           fmOpenReadWrite);
    714552      Fsep_file.Seek(raw_info.RawAddr + Offset, soFromBeginning);
    715553      Fsep_file.CopyFrom(Src, Size);
    716       if UnloadWhenUnused then
    717       begin
    718         FSepOpened := False;
    719         Fsep_file.Free;
    720       end
    721       else
    722         FSepOpened := True;
    723554    end;
    724555  end;
     
    732563  if not LocSep then
    733564  begin
    734     if not FRawOpened then
    735       Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
    736         fmOpenReadWrite);
    737565    if (Fraw_file.Size mod 32) > 0 then
    738566      Fraw_file.Write(EmptyBytes[0], 32 - (Fraw_file.Size mod 32));
     
    742570    if (Fraw_file.Size mod 32) > 0 then
    743571      Fraw_file.Write(EmptyBytes[0], 32 - (Fraw_file.Size mod 32));
    744     if UnloadWhenUnused then
    745     begin
    746       FRawOpened := False;
    747       Fraw_file.Free;
    748     end
    749     else
    750       FRawOpened := True;
    751572  end
    752573  else
    753574  begin
    754     if not FSepOpened then
    755       Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
    756         fmOpenReadWrite);
    757575    if (Fsep_file.Size mod 32) > 0 then
    758576      Fsep_file.Write(EmptyBytes[0], 32 - (Fsep_file.Size mod 32));
     
    762580    if (Fsep_file.Size mod 32) > 0 then
    763581      Fsep_file.Write(EmptyBytes[0], 32 - (Fsep_file.Size mod 32));
    764     if UnloadWhenUnused then
    765     begin
    766       FSepOpened := False;
    767       Fsep_file.Free;
    768     end
    769     else
    770       FSepOpened := True;
    771582  end;
    772583end;
Note: See TracChangeset for help on using the changeset viewer.