source: oup/current/DataAccess/Access_OniArchive.pas@ 208

Last change on this file since 208 was 192, checked in by alloc, 18 years ago
File size: 20.3 KB
RevLine 
[93]1unit Access_OniArchive;
2interface
3
[101]4uses DataAccess, Classes, TypeDefs;
[93]5
6type
7 TAccess_OniArchive = class(TDataAccess)
8 private
[101]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;
[93]18 protected
19 public
20 property UnloadWhenUnused: Boolean Read FUnloadWhenUnused Write FUnloadWhenUnused;
21
[101]22 constructor Create(DatFilename: String; ConnectionID: Integer; var Msg: TStatusMessages); override;
[93]23 procedure Close; override;
24
[101]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;
[93]30
[101]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;
[93]35
[113]36 function GetDatLinks(FileID: Integer): TDatLinkList; override;
[116]37 function GetDatLink(FileID, DatOffset: Integer): TDatLink; override;
[101]38 function GetRawList(FileID: Integer): TRawDataList; override;
39 function GetRawInfo(FileID, DatOffset: Integer): TRawDataInfo; override;
40
[148]41 procedure LoadRawOffset(LocSep: Boolean; RawAddr, Size: Integer; var target: TStream); overload;
42 procedure LoadRawOffset(LocSep: Boolean; RawAddr, Size: Integer; target: Pointer); overload;
[101]43 procedure LoadRawFile(FileID, DatOffset: Integer; var Target: TStream); overload; override;
44 procedure UpdateRawFile(FileID, DatOffset: Integer; Src: TStream); overload; override;
45 procedure LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TStream); overload; override;
46 procedure UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: TStream); overload; override;
47
[105]48 function AppendRawFile(LocSep: Boolean; Src: TStream): Integer; overload; override;
[93]49 published
[101]50 end;
[93]51
52implementation
53
[101]54uses
[192]55 SysUtils, StrUtils, Data, Functions, RawList, DatLinks, Math;
[93]56
[101]57
[93]58(*
59================================================================================
60 Implementation of TOniDataDat
61*)
62
[101]63
64constructor TAccess_OniArchive.Create(DatFilename: String; ConnectionID: Integer; var Msg: TStatusMessages);
[93]65var
[101]66 i: Integer;
67 header_pc, header_mac, header_macbeta: Boolean;
68 Fdat_header: THeader;
69 Fdat_filesmap: TFilesMap;
70 Fdat_namedfilesmap: TNamedFilesMap;
[93]71begin
72 FUnloadWhenUnused := True;
73 FDatOpened := False;
74 FRawOpened := False;
[101]75 Msg := SM_UnknownError;
[93]76 if not FileExists(DatFilename) then
77 begin
[101]78 Msg := SM_FileNotFound;
[93]79 Exit;
80 end;
81 FFileName := DatFilename;
82 Fdat_file := TFileStream.Create(FFileName, fmOpenRead);
83 Fdat_file.Read(Fdat_header, SizeOf(Fdat_header));
84 header_pc := True;
85 header_mac := True;
[101]86 header_macbeta := True;
[113]87 for i := 0 to High(Fdat_header.GlobalIdent) do
88 if Fdat_header.GlobalIdent[i] <> HeaderGlobalIdent[i] then
89 begin
90 Msg := SM_IncompatibleFile;
91 Exit;
92 end;
93
94 for i := 0 to High(Fdat_header.OSIdent) do
[93]95 begin
[113]96 if Fdat_header.OSIdent[i] <> HeaderOSIdentWin[i] then
[93]97 header_pc := False;
[113]98 if Fdat_header.OSIdent[i] <> HeaderOSIdentMac[i] then
[93]99 header_mac := False;
[113]100 if Fdat_header.OSIdent[i] <> HeaderOSIdentMacBeta[i] then
[101]101 header_macbeta := False;
[93]102 end;
[101]103 if not (header_pc xor header_mac xor header_macbeta) then
[93]104 begin
[101]105 Msg := SM_IncompatibleFile;
[93]106 Exit;
107 end
108 else
109 begin
[101]110 if (header_pc and not header_mac and not header_macbeta) then
111 FDataOS := DOS_WIN
112 else if (not header_pc and header_mac and not header_macbeta) then
113 FDataOS := DOS_MAC
114 else if (not header_pc and not header_mac and header_macbeta) then
115 FDataOS := DOS_MACBETA;
[93]116 end;
117 SetLength(Fdat_filesmap, Fdat_header.Files);
118 SetLength(Fdat_files, Fdat_header.Files);
119 for i := 0 to Fdat_header.Files - 1 do
120 Fdat_file.Read(Fdat_filesmap[i], SizeOf(Fdat_filesmap[i]));
121 for i := 0 to Fdat_header.Files - 1 do
122 begin
123 Fdat_files[i].ID := i;
124 Fdat_files[i].Extension := Fdat_filesmap[i].Extension;
125 Fdat_files[i].Extension := ReverseString(Fdat_files[i].Extension);
126 Fdat_files[i].Size := Fdat_filesmap[i].FileSize;
127 Fdat_files[i].FileType := Fdat_filesmap[i].FileType;
128 Fdat_files[i].DatAddr := Fdat_filesmap[i].DataAddr - 8 + Fdat_header.DataAddr;
129 if (Fdat_filesmap[i].FileType and $01) = 0 then
130 begin
131 Fdat_file.Seek(Fdat_filesmap[i].NameAddr + Fdat_header.NamesAddr, soFromBeginning);
132 SetLength(Fdat_files[i].Name, 100);
133 Fdat_file.Read(Fdat_files[i].Name[1], 100);
134 Fdat_files[i].Name := MidStr(Fdat_files[i].Name, 1 + 4, Pos(
135 #0, Fdat_files[i].Name) - 1 - 4);
136 end
137 else
138 begin
139 Fdat_files[i].Name := '';
140 end;
141 end;
142 Fdat_file.Seek($40 + Fdat_header.Files * $14, soFromBeginning);
143 SetLength(Fdat_namedfilesmap, Fdat_header.NamedFiles);
144 for i := 0 to Fdat_header.NamedFiles - 1 do
145 Fdat_file.Read(Fdat_namedfilesmap[i], SizeOf(Fdat_namedfilesmap[i]));
146
147 Fdat_file.Seek($40 + Fdat_header.Files * $14 + Fdat_header.NamedFiles * $8, soFromBeginning);
148 SetLength(Fdat_extensionsmap, Fdat_header.Extensions);
149 for i := 0 to Fdat_header.Extensions - 1 do
150 Fdat_file.Read(Fdat_extensionsmap[i], SizeOf(Fdat_extensionsmap[i]));
151
152 Fdat_file.Seek(Fdat_files[0].DatAddr + 7, soFromBeginning);
[101]153 Fdat_file.Read(FLevelNumber, 1);
154 FLevelNumber := FLevelNumber div 2;
[93]155
156 Fdat_file.Free;
157
[101]158 Msg := SM_OK;
159 FBackend := DB_ONI;
[105]160 FConnectionID := ConnectionID;
[101]161 FChangeRights := [CR_EditDat, CR_EditRaw, CR_AppendRaw];
[93]162end;
163
164
165
166
[101]167procedure TAccess_OniArchive.Close;
[93]168begin
[101]169 if FDatOpened then
[93]170 Fdat_file.Free;
[101]171 if FRawOpened then
[93]172 Fraw_file.Free;
[101]173 if FSepOpened then
[93]174 Fsep_file.Free;
175 Self.Free;
176end;
177
178
179
180
[101]181function TAccess_OniArchive.GetFileInfo(fileid: Integer): TFileInfo;
[93]182begin
183 if fileid = -1 then
184 begin
185 Result := inherited GetFileInfo(fileid);
186 Exit;
187 end;
[101]188 if fileid < Self.GetFileCount then
[93]189 Result := Fdat_files[fileid]
190 else
191 Result.ID := -1;
192end;
193
194
195
196
[101]197function TAccess_OniArchive.GetFilesList(ext: String; pattern: String;
198 NoEmptyFiles: Boolean; SortType: TSortType): TStrings;
[93]199var
[101]200 i: Integer;
201 list: TStringList;
[93]202 id, name, extension: String;
203 fields: TStrings;
204
205 procedure getfields;
206 begin
[101]207 fields.CommaText := StringReplace(AnsiQuotedStr(list.Strings[i], '"'), ';', '","', [rfReplaceAll]);
208 if SortType in [ST_IDAsc, ST_IDDesc] then
[93]209 begin
210 id := fields.Strings[0];
211 name := fields.Strings[1];
212 extension := fields.Strings[2];
213 end;
[101]214 if SortType in [ST_NameAsc, ST_NameDesc] then
[93]215 begin
216 id := fields.Strings[1];
217 name := fields.Strings[0];
218 extension := fields.Strings[2];
219 end;
[101]220 if SortType in [ST_ExtAsc, ST_ExtDesc] then
[93]221 begin
222 id := fields.Strings[1];
223 name := fields.Strings[2];
224 extension := fields.Strings[0];
225 end;
[112]226 if SortType in [ST_ExtNameAsc, ST_ExtNameDesc] then
227 begin
228 id := fields.Strings[2];
229 name := fields.Strings[1];
230 extension := fields.Strings[0];
231 end;
[93]232 end;
233
234begin
235 list := TStringList.Create;
236 list.Sorted := True;
[101]237 for i := 0 to GetFileCount - 1 do
[93]238 begin
239 if ((Length(ext) = 0) or (Pos(Fdat_files[i].Extension, ext) > 0)) and
240 ((Length(pattern) = 0) or
241 (Pos(UpperCase(pattern), UpperCase(Fdat_files[i].Name)) > 0)) then
242 begin
243 if (NoEmptyFiles = False) or ((Fdat_files[i].FileType and $02) = 0) then
244 begin
[112]245 id := FormatNumber(Fdat_files[i].ID, 5, '0');
[93]246 name := Fdat_files[i].Name;
247 extension := Fdat_files[i].Extension;
248
[101]249 case SortType of
250 ST_IDAsc, ST_IDDesc: list.Add(id + ';' + name + ';' + extension);
251 ST_NameAsc, ST_NameDesc: list.Add(name + ';' + id + ';' + extension);
252 ST_ExtAsc, ST_ExtDesc: list.Add(extension + ';' + id + ';' + name);
[112]253 ST_ExtNameAsc, ST_ExtNameDesc: list.Add(name + ';' + extension + ';' + id);
[93]254 end;
255 end;
256 end;
257 end;
[113]258 if not Assigned(Result) then
259 Result := TStringList.Create;
[101]260 if list.Count > 0 then
[93]261 begin
262 fields := TStringList.Create;
[112]263 if SortType in [ST_IDAsc, ST_NameAsc, ST_ExtAsc, ST_ExtNameAsc] then
[93]264 for i := 0 to list.Count - 1 do
265 begin
266 getfields;
[101]267 Result.Add(id + '-' + name + '.' + extension);
[93]268 end
269 else
270 for i := list.Count - 1 downto 0 do
271 begin
272 getfields;
[101]273 Result.Add(id + '-' + name + '.' + extension);
[93]274 end;
275 fields.Free;
276 end;
277 list.Free;
278end;
279
280
281
282
[101]283function TAccess_OniArchive.GetFileCount: Integer;
[93]284begin
[101]285 Result := Length(Fdat_files);
[93]286end;
287
288
289
290
[101]291function TAccess_OniArchive.GetExtensionsList(ExtListFormat: TExtensionFormat): TStrings;
[93]292var
[101]293 i: Integer;
[93]294begin
[113]295 if not Assigned(Result) then
296 Result := TStringList.Create;
297 if Result is TStringList then
298 TStringList(Result).Sorted := True;
[101]299 for i := 0 to Length(Fdat_extensionsmap) - 1 do
[93]300 begin
301 with Fdat_extensionsmap[i] do
302 begin
[101]303 case ExtListFormat of
304 EF_ExtOnly:
305 Result.Add(Extension[3] + Extension[2] + Extension[1] + Extension[0]);
306 EF_ExtCount:
307 Result.Add(Extension[3] + Extension[2] + Extension[1] + Extension[0] +
308 ' (' + IntToStr(ExtCount) + ')');
309 end;
[93]310 end;
311 end;
312end;
313
314
315
[101]316procedure TAccess_OniArchive.LoadDatFile(FileID: Integer; var Target: TStream);
[93]317var
[101]318 streampos: Integer;
[93]319begin
[101]320 if fileid < GetFileCount then
[93]321 begin
[101]322 if not Assigned(Target) then
323 Target := TMemoryStream.Create;
324 if not FDatOpened then
[93]325 Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);
326 Fdat_file.Seek(Fdat_files[fileid].DatAddr, soFromBeginning);
[101]327 streampos := Target.Position;
328 Target.CopyFrom(Fdat_file, Fdat_files[fileid].Size);
329 Target.Seek(streampos, soFromBeginning);
[93]330 if UnloadWhenUnused then
[101]331 begin
332 Fdat_file.Free;
333 FDatOpened := False;
334 end
[93]335 else
336 FDatOpened := True;
337 end;
338end;
339
[101]340procedure TAccess_OniArchive.UpdateDatFile(FileID: Integer; Src: TStream);
[93]341begin
[101]342 if fileid < GetFileCount then
[93]343 begin
[101]344 if not FDatOpened then
[93]345 Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);
346 Fdat_file.Seek(Fdat_files[fileid].DatAddr, soFromBeginning);
[101]347 Fdat_file.CopyFrom(Src, Fdat_files[fileid].Size);
[93]348 if UnloadWhenUnused then
[101]349 begin
350 Fdat_file.Free;
351 FDatOpened := False;
352 end
[93]353 else
354 FDatOpened := True;
355 end;
356end;
357
[101]358procedure TAccess_OniArchive.LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TStream);
359var
360 streampos: Integer;
[93]361begin
[101]362 if fileid < GetFileCount then
[93]363 begin
[101]364 if not Assigned(Target) then
365 Target := TMemoryStream.Create;
366 if not FDatOpened then
[93]367 Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);
368 Fdat_file.Seek(Fdat_files[fileid].DatAddr + offset, soFromBeginning);
[101]369 streampos := Target.Position;
370 Target.CopyFrom(Fdat_file, size);
371 Target.Seek(streampos, soFromBeginning);
[93]372 if UnloadWhenUnused then
[101]373 begin
374 FDatOpened := False;
375 Fdat_file.Free;
376 end
[93]377 else
378 FDatOpened := True;
379 end;
380end;
381
[101]382procedure TAccess_OniArchive.UpdateDatFilePart(FileID, Offset, Size: Integer; Src: TStream);
[93]383begin
[101]384 if fileid < GetFileCount then
[93]385 begin
[101]386 if not FDatOpened then
[93]387 Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);
388 Fdat_file.Seek(Fdat_files[fileid].DatAddr + offset, soFromBeginning);
[101]389 Fdat_file.CopyFrom(Src, Size);
[93]390 if UnloadWhenUnused then
[101]391 begin
392 Fdat_file.Free;
393 FDatOpened := False;
394 end
[93]395 else
396 FDatOpened := True;
397 end;
398end;
399
400
401
[116]402function TAccess_OniArchive.GetDatLink(FileID, DatOffset: Integer): TDatLink;
403var
404 link: Integer;
405begin
406 Result := DatLinksManager.GetDatLink(FConnectionID, FileID, DatOffset);
407 LoadDatFilePart(fileid, Result.SrcOffset, 4, @link);
408 if link > 0 then
409 Result.DestID := link div 256
410 else
411 Result.DestID := -1;
412end;
413
414
415function TAccess_OniArchive.GetDatLinks(FileID: Integer): TDatLinkList;
416var
417 i: Integer;
418 link: Integer;
419begin
420 Result := DatLinksManager.GetDatLinks(FConnectionID, FileID);
421 if Length(Result) > 0 then
422 begin
423 for i := 0 to High(Result) do
424 begin
425 LoadDatFilePart(fileid, Result[i].SrcOffset, 4, @link);
426 if link > 0 then
427 Result[i].DestID := link div 256
428 else
429 Result[i].DestID := -1;
430 end;
431 end;
432end;
433
434
[101]435function TAccess_OniArchive.GetRawList(FileID: Integer): TRawDataList;
436begin
437 Result := RawLists.GetRawList(FConnectionID, FileID);
438end;
[93]439
[101]440
441function TAccess_OniArchive.GetRawInfo(FileID, DatOffset: Integer): TRawDataInfo;
[93]442begin
[101]443 Result := RawLists.GetRawInfo(FConnectionID, FileID, DatOffset);
[93]444end;
445
446
447
[148]448procedure TAccess_OniArchive.LoadRawOffset(LocSep: Boolean; RawAddr, Size: Integer; var target: TStream);
[93]449begin
[148]450 if not Assigned(Target) then
451 Target := TMemoryStream.Create;
[101]452 if not LocSep then
[93]453 begin
[101]454 if not FRawOpened then
[93]455 Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
456 fmOpenReadWrite);
[101]457 if RawAddr <= Fraw_file.Size then
[93]458 begin
[101]459 Fraw_file.Seek(RawAddr, soFromBeginning);
[148]460 Target.CopyFrom(Fraw_file, size);
461 Target.Seek(0, soFromBeginning);
[93]462 end;
463 if UnloadWhenUnused then
[101]464 begin
465 FRawOpened := False;
466 Fraw_file.Free;
467 end
[93]468 else
469 FRawOpened := True;
470 end
471 else
472 begin
[101]473 if not FSepOpened then
[93]474 Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
475 fmOpenReadWrite);
[101]476 if RawAddr <= Fsep_file.Size then
[93]477 begin
[101]478 Fsep_file.Seek(RawAddr, soFromBeginning);
[148]479 Target.CopyFrom(Fsep_file, size);
480 Target.Seek(0, soFromBeginning);
[93]481 end;
482 if UnloadWhenUnused then
[101]483 begin
484 FSepOpened := False;
485 Fsep_file.Free;
486 end
[93]487 else
488 FSepOpened := True;
489 end;
490end;
491
[148]492procedure TAccess_OniArchive.LoadRawOffset(LocSep: Boolean; RawAddr, Size: Integer; target: Pointer);
493var
494 data: TStream;
495begin
496 data := nil;
497 LoadRawOffset(LocSep, RawAddr, Size, data);
498 data.Read(Target^, Size);
499 data.Free;
500end;
501
[101]502procedure TAccess_OniArchive.LoadRawFile(FileID, DatOffset: Integer; var Target: TStream);
[93]503var
[101]504 raw_info: TRawDataInfo;
505 streampos: Integer;
[93]506begin
[101]507 if not Assigned(Target) then
508 Target := TMemoryStream.Create;
509 if fileid < GetFileCount then
[93]510 begin
[101]511 raw_info := Self.GetRawInfo(FileID, DatOffset);
512 if not raw_info.LocSep then
[93]513 begin
[101]514 if not FRawOpened then
[93]515 Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
516 fmOpenReadWrite);
[101]517 Fraw_file.Seek(raw_info.RawAddr, soFromBeginning);
518 streampos := Target.Position;
519 Target.CopyFrom(Fraw_file, raw_info.RawSize);
520 Target.Seek(streampos, soFromBeginning);
[93]521 if UnloadWhenUnused then
[101]522 begin
523 FRawOpened := False;
524 Fraw_file.Free;
525 end
[93]526 else
527 FRawOpened := True;
528 end
529 else
530 begin
531 if FUnloadWhenUnused or not FSepOpened then
532 Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
533 fmOpenReadWrite);
[101]534 Fsep_file.Seek(raw_info.RawAddr, soFromBeginning);
535 streampos := Target.Position;
536 Target.CopyFrom(Fsep_file, raw_info.RawSize);
537 Target.Seek(streampos, soFromBeginning);
[93]538 if UnloadWhenUnused then
[101]539 begin
540 FSepOpened := False;
541 Fsep_file.Free;
542 end
[93]543 else
544 FSepOpened := True;
545 end;
546 end;
547end;
548
[101]549procedure TAccess_OniArchive.UpdateRawFile(FileID, DatOffset: Integer; Src: TStream);
[93]550var
[101]551 raw_info: TRawDataInfo;
[93]552begin
[101]553 if fileid < GetFileCount then
[93]554 begin
[101]555 raw_info := GetRawInfo(FileID, DatOffset);
556 if not raw_info.LocSep then
[93]557 begin
[101]558 if not FRawOpened then
[93]559 Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
560 fmOpenReadWrite);
[101]561 Fraw_file.Seek(raw_info.RawAddr, soFromBeginning);
[192]562 Fraw_file.CopyFrom(Src, Min(raw_info.RawSize, Src.Size));
[93]563 if UnloadWhenUnused then
[101]564 begin
565 FRawOpened := False;
566 Fraw_file.Free;
567 end
[93]568 else
569 FRawOpened := True;
570 end
571 else
572 begin
[101]573 if not FSepOpened then
[93]574 Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
575 fmOpenReadWrite);
[101]576 Fsep_file.Seek(raw_info.RawAddr, soFromBeginning);
577 Fsep_file.CopyFrom(Src, raw_info.RawSize);
[93]578 if UnloadWhenUnused then
[101]579 begin
580 FSepOpened := False;
581 Fsep_file.Free;
582 end
[93]583 else
584 FSepOpened := True;
585 end;
586 end;
587end;
588
[101]589procedure TAccess_OniArchive.LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TStream);
[93]590var
[101]591 Data: TStream;
592 streampos: Integer;
[93]593begin
[101]594 if not Assigned(Target) then
595 Target := TMemoryStream.Create;
596 if fileid < Self.GetFileCount then
[93]597 begin
[101]598 data := nil;
599 LoadRawFile(FileID, DatOffset, Data);
600 Data.Seek(Offset, soFromBeginning);
601 streampos := Target.Position;
602 Target.CopyFrom(Data, Size);
603 Target.Seek(streampos, soFromBeginning);
[93]604 end;
605end;
606
[148]607
[101]608procedure TAccess_OniArchive.UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: TStream);
[93]609var
[101]610 raw_info: TRawDataInfo;
[93]611begin
[101]612 if fileid < GetFileCount then
[93]613 begin
[101]614 raw_info := GetRawInfo(FileID, DatOffset);
615 if not raw_info.LocSep then
[93]616 begin
[101]617 if not FRawOpened then
[93]618 Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
619 fmOpenReadWrite);
[101]620 Fraw_file.Seek(raw_info.RawAddr + Offset, soFromBeginning);
621 Fraw_file.CopyFrom(Src, Size);
[93]622 if UnloadWhenUnused then
[101]623 begin
624 FRawOpened := False;
625 Fraw_file.Free;
626 end
[93]627 else
628 FRawOpened := True;
629 end
630 else
631 begin
[101]632 if not FSepOpened then
[93]633 Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
634 fmOpenReadWrite);
[101]635 Fsep_file.Seek(raw_info.RawAddr + Offset, soFromBeginning);
636 Fsep_file.CopyFrom(Src, Size);
[93]637 if UnloadWhenUnused then
[101]638 begin
639 FSepOpened := False;
640 Fsep_file.Free;
641 end
[93]642 else
643 FSepOpened := True;
644 end;
645 end;
646end;
647
[105]648function TAccess_OniArchive.AppendRawFile(LocSep: Boolean; Src: TStream): Integer;
[173]649const
650 EmptyBytes: Array[0..31] of Byte = (
651 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 );
[93]652begin
[101]653 if not LocSep then
[93]654 begin
[101]655 if not FRawOpened then
[93]656 Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
657 fmOpenReadWrite);
[173]658 if (Fraw_file.Size mod 32) > 0 then
659 Fraw_file.Write(EmptyBytes[0], 32 - (Fraw_file.Size mod 32));
[93]660 Result := Fraw_file.Size;
661 Fraw_file.Seek(0, soFromEnd);
[105]662 Fraw_file.CopyFrom(Src, Src.Size);
[173]663 if (Fraw_file.Size mod 32) > 0 then
664 Fraw_file.Write(EmptyBytes[0], 32 - (Fraw_file.Size mod 32));
[93]665 if UnloadWhenUnused then
[101]666 begin
667 FRawOpened := False;
668 Fraw_file.Free;
669 end
[93]670 else
671 FRawOpened := True;
672 end
673 else
674 begin
[101]675 if not FSepOpened then
[93]676 Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
677 fmOpenReadWrite);
[173]678 if (Fsep_file.Size mod 32) > 0 then
679 Fsep_file.Write(EmptyBytes[0], 32 - (Fsep_file.Size mod 32));
[93]680 Result := Fsep_file.Size;
681 Fsep_file.Seek(0, soFromEnd);
[105]682 Fsep_file.CopyFrom(Src, Src.Size);
[173]683 if (Fsep_file.Size mod 32) > 0 then
684 Fsep_file.Write(EmptyBytes[0], 32 - (Fsep_file.Size mod 32));
[93]685 if UnloadWhenUnused then
[101]686 begin
687 FSepOpened := False;
688 Fsep_file.Free;
689 end
[93]690 else
691 FSepOpened := True;
692 end;
693end;
694
695end.
Note: See TracBrowser for help on using the repository browser.