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