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