Changeset 248 for oup/current/DataAccess
- Timestamp:
- Nov 26, 2007, 12:02:28 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
oup/current/DataAccess/Access_OniArchive.pas
r243 r248 12 12 Fdat_files: TFiles; 13 13 Fdat_extensionsmap: TExtensionsMap; 14 FUnloadWhenUnused: Boolean;15 FDatOpened: Boolean;16 FRawOpened: Boolean;17 FSepOpened: Boolean;18 procedure SetUnloadWhenUnused(doit: Boolean);19 14 protected 20 15 public 21 property UnloadWhenUnused: Boolean Read FUnloadWhenUnused Write SetUnloadWhenUnused;22 23 16 constructor Create(DatFilename: String; ConnectionID: Integer; var Msg: TStatusMessages); override; 24 17 procedure Close; override; … … 72 65 Fdat_namedfilesmap: TNamedFilesMap; 73 66 begin 74 FUnloadWhenUnused := True;75 FDatOpened := False;76 FRawOpened := False;77 67 Msg := SM_UnknownError; 78 68 if not FileExists(DatFilename) then … … 156 146 FLevelNumber := FLevelNumber div 2; 157 147 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); 159 153 160 154 Msg := SM_OK; … … 169 163 170 164 171 procedure TAccess_OniArchive.SetUnloadWhenUnused(doit: Boolean);172 begin173 FUnloadWhenUnused := doit;174 if FUnloadWhenUnused then175 begin176 if FDatOpened then177 begin178 FDatOpened := False;179 Fdat_file.Free;180 end;181 if FRawOpened then182 begin183 FRawOpened := False;184 Fraw_file.Free;185 end;186 if FSepOpened then187 begin188 FSepOpened := False;189 Fsep_file.Free;190 end;191 end192 else193 begin194 if not FDatOpened then195 begin196 Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);197 FDatOpened := True;198 end;199 if not FRawOpened then200 begin201 Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),202 fmOpenReadWrite);203 FRawOpened := True;204 end;205 if (not FSepOpened) and (FDataOS <> DOS_WIN) then206 begin207 Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),208 fmOpenReadWrite);209 FSepOpened := True;210 end;211 end;212 end;213 214 215 216 217 218 165 procedure TAccess_OniArchive.Close; 219 166 begin 220 if FDatOpenedthen167 if Assigned(Fdat_file) then 221 168 Fdat_file.Free; 222 if FRawOpenedthen169 if Assigned(Fraw_file) then 223 170 Fraw_file.Free; 224 if FSepOpenedthen171 if Assigned(Fsep_file) then 225 172 Fsep_file.Free; 226 173 Self.Free; … … 373 320 if fileid < GetFileCount then 374 321 begin 322 if not Assigned(Target) then 323 Target := TMemoryStream.Create; 375 324 if GetFileInfo(FileID).Size > 0 then 376 325 begin 377 if not Assigned(Target) then378 Target := TMemoryStream.Create;379 if not FDatOpened then380 Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);381 326 Fdat_file.Seek(Fdat_files[fileid].DatAddr, soFromBeginning); 382 327 streampos := Target.Position; 383 328 Target.CopyFrom(Fdat_file, Fdat_files[fileid].Size); 384 329 Target.Seek(streampos, soFromBeginning); 385 if UnloadWhenUnused then386 begin387 Fdat_file.Free;388 FDatOpened := False;389 end390 else391 FDatOpened := True;392 330 end; 393 331 end; … … 398 336 if fileid < GetFileCount then 399 337 begin 400 if not FDatOpened then401 Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);402 338 Fdat_file.Seek(Fdat_files[fileid].DatAddr, soFromBeginning); 403 339 Fdat_file.CopyFrom(Src, Fdat_files[fileid].Size); 404 if UnloadWhenUnused then405 begin406 Fdat_file.Free;407 FDatOpened := False;408 end409 else410 FDatOpened := True;411 340 end; 412 341 end; … … 420 349 if not Assigned(Target) then 421 350 Target := TMemoryStream.Create; 422 if not FDatOpened then423 Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);424 351 Fdat_file.Seek(Fdat_files[fileid].DatAddr + offset, soFromBeginning); 425 352 streampos := Target.Position; 426 353 Target.CopyFrom(Fdat_file, size); 427 354 Target.Seek(streampos, soFromBeginning); 428 if UnloadWhenUnused then429 begin430 FDatOpened := False;431 Fdat_file.Free;432 end433 else434 FDatOpened := True;435 355 end; 436 356 end; … … 440 360 if fileid < GetFileCount then 441 361 begin 442 if not FDatOpened then443 Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);444 362 Fdat_file.Seek(Fdat_files[fileid].DatAddr + offset, soFromBeginning); 445 363 Fdat_file.CopyFrom(Src, Size); 446 if UnloadWhenUnused then447 begin448 Fdat_file.Free;449 FDatOpened := False;450 end451 else452 FDatOpened := True;453 364 end; 454 365 end; … … 531 442 if not LocSep then 532 443 begin 533 if not FRawOpened then534 Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),535 fmOpenReadWrite);536 444 if RawAddr <= Fraw_file.Size then 537 445 begin … … 540 448 Target.Seek(0, soFromBeginning); 541 449 end; 542 if UnloadWhenUnused then543 begin544 FRawOpened := False;545 Fraw_file.Free;546 end547 else548 FRawOpened := True;549 450 end 550 451 else 551 452 begin 552 if not FSepOpened then553 Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),554 fmOpenReadWrite);555 453 if RawAddr <= Fsep_file.Size then 556 454 begin … … 559 457 Target.Seek(0, soFromBeginning); 560 458 end; 561 if UnloadWhenUnused then562 begin563 FSepOpened := False;564 Fsep_file.Free;565 end566 else567 FSepOpened := True;568 459 end; 569 460 end; … … 591 482 if not raw_info.LocSep then 592 483 begin 593 if not FRawOpened then594 Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),595 fmOpenReadWrite);596 484 Fraw_file.Seek(raw_info.RawAddr, soFromBeginning); 597 485 streampos := Target.Position; 598 486 Target.CopyFrom(Fraw_file, raw_info.RawSize); 599 487 Target.Seek(streampos, soFromBeginning); 600 if UnloadWhenUnused then601 begin602 FRawOpened := False;603 Fraw_file.Free;604 end605 else606 FRawOpened := True;607 488 end 608 489 else 609 490 begin 610 if FUnloadWhenUnused or not FSepOpened then611 Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),612 fmOpenReadWrite);613 491 Fsep_file.Seek(raw_info.RawAddr, soFromBeginning); 614 492 streampos := Target.Position; 615 493 Target.CopyFrom(Fsep_file, raw_info.RawSize); 616 494 Target.Seek(streampos, soFromBeginning); 617 if UnloadWhenUnused then618 begin619 FSepOpened := False;620 Fsep_file.Free;621 end622 else623 FSepOpened := True;624 495 end; 625 496 end; … … 635 506 if not raw_info.LocSep then 636 507 begin 637 if not FRawOpened then638 Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),639 fmOpenReadWrite);640 508 Fraw_file.Seek(raw_info.RawAddr, soFromBeginning); 641 509 Fraw_file.CopyFrom(Src, Min(raw_info.RawSize, Src.Size)); 642 if UnloadWhenUnused then643 begin644 FRawOpened := False;645 Fraw_file.Free;646 end647 else648 FRawOpened := True;649 510 end 650 511 else 651 512 begin 652 if not FSepOpened then653 Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),654 fmOpenReadWrite);655 513 Fsep_file.Seek(raw_info.RawAddr, soFromBeginning); 656 514 Fsep_file.CopyFrom(Src, raw_info.RawSize); 657 if UnloadWhenUnused then658 begin659 FSepOpened := False;660 Fsep_file.Free;661 end662 else663 FSepOpened := True;664 515 end; 665 516 end; … … 694 545 if not raw_info.LocSep then 695 546 begin 696 if not FRawOpened then697 Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),698 fmOpenReadWrite);699 547 Fraw_file.Seek(raw_info.RawAddr + Offset, soFromBeginning); 700 548 Fraw_file.CopyFrom(Src, Size); 701 if UnloadWhenUnused then702 begin703 FRawOpened := False;704 Fraw_file.Free;705 end706 else707 FRawOpened := True;708 549 end 709 550 else 710 551 begin 711 if not FSepOpened then712 Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),713 fmOpenReadWrite);714 552 Fsep_file.Seek(raw_info.RawAddr + Offset, soFromBeginning); 715 553 Fsep_file.CopyFrom(Src, Size); 716 if UnloadWhenUnused then717 begin718 FSepOpened := False;719 Fsep_file.Free;720 end721 else722 FSepOpened := True;723 554 end; 724 555 end; … … 732 563 if not LocSep then 733 564 begin 734 if not FRawOpened then735 Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),736 fmOpenReadWrite);737 565 if (Fraw_file.Size mod 32) > 0 then 738 566 Fraw_file.Write(EmptyBytes[0], 32 - (Fraw_file.Size mod 32)); … … 742 570 if (Fraw_file.Size mod 32) > 0 then 743 571 Fraw_file.Write(EmptyBytes[0], 32 - (Fraw_file.Size mod 32)); 744 if UnloadWhenUnused then745 begin746 FRawOpened := False;747 Fraw_file.Free;748 end749 else750 FRawOpened := True;751 572 end 752 573 else 753 574 begin 754 if not FSepOpened then755 Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),756 fmOpenReadWrite);757 575 if (Fsep_file.Size mod 32) > 0 then 758 576 Fsep_file.Write(EmptyBytes[0], 32 - (Fsep_file.Size mod 32)); … … 762 580 if (Fsep_file.Size mod 32) > 0 then 763 581 Fsep_file.Write(EmptyBytes[0], 32 - (Fsep_file.Size mod 32)); 764 if UnloadWhenUnused then765 begin766 FSepOpened := False;767 Fsep_file.Free;768 end769 else770 FSepOpened := True;771 582 end; 772 583 end;
Note:
See TracChangeset
for help on using the changeset viewer.