Changeset 256 for oup/current
- Timestamp:
- Oct 19, 2008, 1:27:59 AM (16 years ago)
- Location:
- oup/current
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
oup/current/DataAccess/Access_OniArchive.pas
r252 r256 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); 14 19 protected 15 20 public 21 property UnloadWhenUnused: Boolean Read FUnloadWhenUnused Write SetUnloadWhenUnused; 22 16 23 constructor Create(DatFilename: String; ConnectionID: Integer; var Msg: TStatusMessages); override; 17 24 procedure Close; override; … … 65 72 Fdat_namedfilesmap: TNamedFilesMap; 66 73 begin 74 FUnloadWhenUnused := True; 75 FDatOpened := False; 76 FRawOpened := False; 67 77 Msg := SM_UnknownError; 68 78 if not FileExists(DatFilename) then … … 72 82 end; 73 83 FFileName := DatFilename; 74 Fdat_file := TFileStream.Create(FFileName, fmOpenRead Write);84 Fdat_file := TFileStream.Create(FFileName, fmOpenRead); 75 85 Fdat_file.Read(Fdat_header, SizeOf(Fdat_header)); 76 86 header_pc := True; … … 146 156 FLevelNumber := FLevelNumber div 2; 147 157 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); 158 Fdat_file.Free; 153 159 154 160 Msg := SM_OK; … … 163 169 164 170 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 165 218 procedure TAccess_OniArchive.Close; 166 219 begin 167 if Assigned(Fdat_file)then220 if FDatOpened then 168 221 Fdat_file.Free; 169 if Assigned(Fraw_file)then222 if FRawOpened then 170 223 Fraw_file.Free; 171 if Assigned(Fsep_file)then224 if FSepOpened then 172 225 Fsep_file.Free; 173 226 Self.Free; … … 324 377 if GetFileInfo(FileID).Size > 0 then 325 378 begin 379 if not FDatOpened then 380 Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite); 326 381 Fdat_file.Seek(Fdat_files[fileid].DatAddr, soFromBeginning); 327 382 streampos := Target.Position; 328 383 Target.CopyFrom(Fdat_file, Fdat_files[fileid].Size); 329 384 Target.Seek(streampos, soFromBeginning); 385 if UnloadWhenUnused then 386 begin 387 Fdat_file.Free; 388 FDatOpened := False; 389 end 390 else 391 FDatOpened := True; 330 392 end; 331 393 end; … … 336 398 if fileid < GetFileCount then 337 399 begin 400 if not FDatOpened then 401 Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite); 338 402 Fdat_file.Seek(Fdat_files[fileid].DatAddr, soFromBeginning); 339 403 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; 340 411 end; 341 412 end; … … 349 420 if not Assigned(Target) then 350 421 Target := TMemoryStream.Create; 422 if not FDatOpened then 423 Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite); 351 424 Fdat_file.Seek(Fdat_files[fileid].DatAddr + offset, soFromBeginning); 352 425 streampos := Target.Position; 353 426 Target.CopyFrom(Fdat_file, size); 354 427 Target.Seek(streampos, soFromBeginning); 428 if UnloadWhenUnused then 429 begin 430 FDatOpened := False; 431 Fdat_file.Free; 432 end 433 else 434 FDatOpened := True; 355 435 end; 356 436 end; … … 360 440 if fileid < GetFileCount then 361 441 begin 442 if not FDatOpened then 443 Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite); 362 444 Fdat_file.Seek(Fdat_files[fileid].DatAddr + offset, soFromBeginning); 363 445 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; 364 453 end; 365 454 end; … … 442 531 if not LocSep then 443 532 begin 533 if not FRawOpened then 534 Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'), 535 fmOpenReadWrite); 444 536 if RawAddr <= Fraw_file.Size then 445 537 begin … … 448 540 Target.Seek(0, soFromBeginning); 449 541 end; 542 if UnloadWhenUnused then 543 begin 544 FRawOpened := False; 545 Fraw_file.Free; 546 end 547 else 548 FRawOpened := True; 450 549 end 451 550 else 452 551 begin 552 if not FSepOpened then 553 Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'), 554 fmOpenReadWrite); 453 555 if RawAddr <= Fsep_file.Size then 454 556 begin … … 457 559 Target.Seek(0, soFromBeginning); 458 560 end; 561 if UnloadWhenUnused then 562 begin 563 FSepOpened := False; 564 Fsep_file.Free; 565 end 566 else 567 FSepOpened := True; 459 568 end; 460 569 end; … … 482 591 if not raw_info.LocSep then 483 592 begin 593 if not FRawOpened then 594 Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'), 595 fmOpenReadWrite); 484 596 Fraw_file.Seek(raw_info.RawAddr, soFromBeginning); 485 597 streampos := Target.Position; 486 598 Target.CopyFrom(Fraw_file, raw_info.RawSize); 487 599 Target.Seek(streampos, soFromBeginning); 488 end 489 else 490 begin 600 if UnloadWhenUnused then 601 begin 602 FRawOpened := False; 603 Fraw_file.Free; 604 end 605 else 606 FRawOpened := True; 607 end 608 else 609 begin 610 if FUnloadWhenUnused or not FSepOpened then 611 Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'), 612 fmOpenReadWrite); 491 613 Fsep_file.Seek(raw_info.RawAddr, soFromBeginning); 492 614 streampos := Target.Position; 493 615 Target.CopyFrom(Fsep_file, raw_info.RawSize); 494 616 Target.Seek(streampos, soFromBeginning); 617 if UnloadWhenUnused then 618 begin 619 FSepOpened := False; 620 Fsep_file.Free; 621 end 622 else 623 FSepOpened := True; 495 624 end; 496 625 end; … … 506 635 if not raw_info.LocSep then 507 636 begin 637 if not FRawOpened then 638 Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'), 639 fmOpenReadWrite); 508 640 Fraw_file.Seek(raw_info.RawAddr, soFromBeginning); 509 641 Fraw_file.CopyFrom(Src, Min(raw_info.RawSize, Src.Size)); 510 end 511 else 512 begin 642 if UnloadWhenUnused then 643 begin 644 FRawOpened := False; 645 Fraw_file.Free; 646 end 647 else 648 FRawOpened := True; 649 end 650 else 651 begin 652 if not FSepOpened then 653 Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'), 654 fmOpenReadWrite); 513 655 Fsep_file.Seek(raw_info.RawAddr, soFromBeginning); 514 656 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; 515 664 end; 516 665 end; … … 545 694 if not raw_info.LocSep then 546 695 begin 696 if not FRawOpened then 697 Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'), 698 fmOpenReadWrite); 547 699 Fraw_file.Seek(raw_info.RawAddr + Offset, soFromBeginning); 548 700 Fraw_file.CopyFrom(Src, Size); 549 end 550 else 551 begin 701 if UnloadWhenUnused then 702 begin 703 FRawOpened := False; 704 Fraw_file.Free; 705 end 706 else 707 FRawOpened := True; 708 end 709 else 710 begin 711 if not FSepOpened then 712 Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'), 713 fmOpenReadWrite); 552 714 Fsep_file.Seek(raw_info.RawAddr + Offset, soFromBeginning); 553 715 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; 554 723 end; 555 724 end; … … 563 732 if not LocSep then 564 733 begin 734 if not FRawOpened then 735 Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'), 736 fmOpenReadWrite); 565 737 if (Fraw_file.Size mod 32) > 0 then 566 738 Fraw_file.Write(EmptyBytes[0], 32 - (Fraw_file.Size mod 32)); … … 570 742 if (Fraw_file.Size mod 32) > 0 then 571 743 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; 572 751 end 573 752 else 574 753 begin 754 if not FSepOpened then 755 Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'), 756 fmOpenReadWrite); 575 757 if (Fsep_file.Size mod 32) > 0 then 576 758 Fsep_file.Write(EmptyBytes[0], 32 - (Fsep_file.Size mod 32)); … … 580 762 if (Fsep_file.Size mod 32) > 0 then 581 763 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; 582 771 end; 583 772 end;
Note:
See TracChangeset
for help on using the changeset viewer.