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