[200] | 1 | unit Access_OniArchive;
|
---|
| 2 | interface
|
---|
| 3 |
|
---|
| 4 | uses DataAccess, Classes, TypeDefs;
|
---|
| 5 |
|
---|
| 6 | type
|
---|
| 7 | TAccess_OniArchive = class(TDataAccess)
|
---|
| 8 | private
|
---|
| 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;
|
---|
| 18 | protected
|
---|
| 19 | public
|
---|
| 20 | property UnloadWhenUnused: Boolean Read FUnloadWhenUnused Write FUnloadWhenUnused;
|
---|
| 21 |
|
---|
| 22 | constructor Create(DatFilename: String; ConnectionID: Integer; var Msg: TStatusMessages); override;
|
---|
| 23 | procedure Close; override;
|
---|
| 24 |
|
---|
| 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;
|
---|
| 30 |
|
---|
| 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;
|
---|
| 35 |
|
---|
| 36 | function GetDatLinks(FileID: Integer): TDatLinkList; override;
|
---|
| 37 | function GetDatLink(FileID, DatOffset: Integer): TDatLink; override;
|
---|
| 38 | function GetRawList(FileID: Integer): TRawDataList; override;
|
---|
| 39 | function GetRawInfo(FileID, DatOffset: Integer): TRawDataInfo; override;
|
---|
| 40 |
|
---|
| 41 | procedure LoadRawOffset(LocSep: Boolean; RawAddr, Size: Integer; var target: TStream); overload;
|
---|
| 42 | procedure LoadRawOffset(LocSep: Boolean; RawAddr, Size: Integer; target: Pointer); overload;
|
---|
| 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 |
|
---|
| 48 | function AppendRawFile(LocSep: Boolean; Src: TStream): Integer; overload; override;
|
---|
| 49 | published
|
---|
| 50 | end;
|
---|
| 51 |
|
---|
| 52 | implementation
|
---|
| 53 |
|
---|
| 54 | uses
|
---|
| 55 | SysUtils, StrUtils, Data, Functions, RawList, DatLinks, Math;
|
---|
| 56 |
|
---|
| 57 |
|
---|
| 58 | (*
|
---|
| 59 | ================================================================================
|
---|
| 60 | Implementation of TOniDataDat
|
---|
| 61 | *)
|
---|
| 62 |
|
---|
| 63 |
|
---|
| 64 | constructor TAccess_OniArchive.Create(DatFilename: String; ConnectionID: Integer; var Msg: TStatusMessages);
|
---|
| 65 | var
|
---|
| 66 | i: Integer;
|
---|
| 67 | header_pc, header_mac, header_macbeta: Boolean;
|
---|
| 68 | Fdat_header: THeader;
|
---|
| 69 | Fdat_filesmap: TFilesMap;
|
---|
| 70 | Fdat_namedfilesmap: TNamedFilesMap;
|
---|
| 71 | begin
|
---|
| 72 | FUnloadWhenUnused := True;
|
---|
| 73 | FDatOpened := False;
|
---|
| 74 | FRawOpened := False;
|
---|
| 75 | Msg := SM_UnknownError;
|
---|
| 76 | if not FileExists(DatFilename) then
|
---|
| 77 | begin
|
---|
| 78 | Msg := SM_FileNotFound;
|
---|
| 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;
|
---|
| 86 | header_macbeta := True;
|
---|
| 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
|
---|
| 95 | begin
|
---|
| 96 | if Fdat_header.OSIdent[i] <> HeaderOSIdentWin[i] then
|
---|
| 97 | header_pc := False;
|
---|
| 98 | if Fdat_header.OSIdent[i] <> HeaderOSIdentMac[i] then
|
---|
| 99 | header_mac := False;
|
---|
| 100 | if Fdat_header.OSIdent[i] <> HeaderOSIdentMacBeta[i] then
|
---|
| 101 | header_macbeta := False;
|
---|
| 102 | end;
|
---|
| 103 | if not (header_pc xor header_mac xor header_macbeta) then
|
---|
| 104 | begin
|
---|
| 105 | Msg := SM_IncompatibleFile;
|
---|
| 106 | Exit;
|
---|
| 107 | end
|
---|
| 108 | else
|
---|
| 109 | begin
|
---|
| 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;
|
---|
| 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);
|
---|
| 153 | Fdat_file.Read(FLevelNumber, 1);
|
---|
| 154 | FLevelNumber := FLevelNumber div 2;
|
---|
| 155 |
|
---|
| 156 | Fdat_file.Free;
|
---|
| 157 |
|
---|
| 158 | Msg := SM_OK;
|
---|
| 159 | FBackend := DB_ONI;
|
---|
| 160 | FConnectionID := ConnectionID;
|
---|
| 161 | FChangeRights := [CR_EditDat, CR_EditRaw, CR_AppendRaw];
|
---|
| 162 | end;
|
---|
| 163 |
|
---|
| 164 |
|
---|
| 165 |
|
---|
| 166 |
|
---|
| 167 | procedure TAccess_OniArchive.Close;
|
---|
| 168 | begin
|
---|
| 169 | if FDatOpened then
|
---|
| 170 | Fdat_file.Free;
|
---|
| 171 | if FRawOpened then
|
---|
| 172 | Fraw_file.Free;
|
---|
| 173 | if FSepOpened then
|
---|
| 174 | Fsep_file.Free;
|
---|
| 175 | Self.Free;
|
---|
| 176 | end;
|
---|
| 177 |
|
---|
| 178 |
|
---|
| 179 |
|
---|
| 180 |
|
---|
| 181 | function TAccess_OniArchive.GetFileInfo(fileid: Integer): TFileInfo;
|
---|
| 182 | begin
|
---|
| 183 | if fileid = -1 then
|
---|
| 184 | begin
|
---|
| 185 | Result := inherited GetFileInfo(fileid);
|
---|
| 186 | Exit;
|
---|
| 187 | end;
|
---|
| 188 | if fileid < Self.GetFileCount then
|
---|
| 189 | Result := Fdat_files[fileid]
|
---|
| 190 | else
|
---|
| 191 | Result.ID := -1;
|
---|
| 192 | end;
|
---|
| 193 |
|
---|
| 194 |
|
---|
| 195 |
|
---|
| 196 |
|
---|
| 197 | function TAccess_OniArchive.GetFilesList(ext: String; pattern: String;
|
---|
| 198 | NoEmptyFiles: Boolean; SortType: TSortType): TStrings;
|
---|
| 199 | var
|
---|
| 200 | i: Integer;
|
---|
| 201 | list: TStringList;
|
---|
| 202 | id, name, extension: String;
|
---|
| 203 | fields: TStrings;
|
---|
| 204 |
|
---|
| 205 | procedure getfields;
|
---|
| 206 | begin
|
---|
| 207 | fields.CommaText := StringReplace(AnsiQuotedStr(list.Strings[i], '"'), ';', '","', [rfReplaceAll]);
|
---|
| 208 | if SortType in [ST_IDAsc, ST_IDDesc] then
|
---|
| 209 | begin
|
---|
| 210 | id := fields.Strings[0];
|
---|
| 211 | name := fields.Strings[1];
|
---|
| 212 | extension := fields.Strings[2];
|
---|
| 213 | end;
|
---|
| 214 | if SortType in [ST_NameAsc, ST_NameDesc] then
|
---|
| 215 | begin
|
---|
| 216 | id := fields.Strings[1];
|
---|
| 217 | name := fields.Strings[0];
|
---|
| 218 | extension := fields.Strings[2];
|
---|
| 219 | end;
|
---|
| 220 | if SortType in [ST_ExtAsc, ST_ExtDesc] then
|
---|
| 221 | begin
|
---|
| 222 | id := fields.Strings[1];
|
---|
| 223 | name := fields.Strings[2];
|
---|
| 224 | extension := fields.Strings[0];
|
---|
| 225 | end;
|
---|
| 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;
|
---|
| 232 | end;
|
---|
| 233 |
|
---|
| 234 | begin
|
---|
| 235 | list := TStringList.Create;
|
---|
| 236 | list.Sorted := True;
|
---|
| 237 | for i := 0 to GetFileCount - 1 do
|
---|
| 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
|
---|
| 245 | id := FormatNumber(Fdat_files[i].ID, 5, '0');
|
---|
| 246 | name := Fdat_files[i].Name;
|
---|
| 247 | extension := Fdat_files[i].Extension;
|
---|
| 248 |
|
---|
| 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);
|
---|
| 253 | ST_ExtNameAsc, ST_ExtNameDesc: list.Add(name + ';' + extension + ';' + id);
|
---|
| 254 | end;
|
---|
| 255 | end;
|
---|
| 256 | end;
|
---|
| 257 | end;
|
---|
| 258 | if not Assigned(Result) then
|
---|
| 259 | Result := TStringList.Create;
|
---|
| 260 | if list.Count > 0 then
|
---|
| 261 | begin
|
---|
| 262 | fields := TStringList.Create;
|
---|
| 263 | if SortType in [ST_IDAsc, ST_NameAsc, ST_ExtAsc, ST_ExtNameAsc] then
|
---|
| 264 | for i := 0 to list.Count - 1 do
|
---|
| 265 | begin
|
---|
| 266 | getfields;
|
---|
| 267 | Result.Add(id + '-' + name + '.' + extension);
|
---|
| 268 | end
|
---|
| 269 | else
|
---|
| 270 | for i := list.Count - 1 downto 0 do
|
---|
| 271 | begin
|
---|
| 272 | getfields;
|
---|
| 273 | Result.Add(id + '-' + name + '.' + extension);
|
---|
| 274 | end;
|
---|
| 275 | fields.Free;
|
---|
| 276 | end;
|
---|
| 277 | list.Free;
|
---|
| 278 | end;
|
---|
| 279 |
|
---|
| 280 |
|
---|
| 281 |
|
---|
| 282 |
|
---|
| 283 | function TAccess_OniArchive.GetFileCount: Integer;
|
---|
| 284 | begin
|
---|
| 285 | Result := Length(Fdat_files);
|
---|
| 286 | end;
|
---|
| 287 |
|
---|
| 288 |
|
---|
| 289 |
|
---|
| 290 |
|
---|
| 291 | function TAccess_OniArchive.GetExtensionsList(ExtListFormat: TExtensionFormat): TStrings;
|
---|
| 292 | var
|
---|
| 293 | i: Integer;
|
---|
| 294 | begin
|
---|
| 295 | if not Assigned(Result) then
|
---|
| 296 | Result := TStringList.Create;
|
---|
| 297 | if Result is TStringList then
|
---|
| 298 | TStringList(Result).Sorted := True;
|
---|
| 299 | for i := 0 to Length(Fdat_extensionsmap) - 1 do
|
---|
| 300 | begin
|
---|
| 301 | with Fdat_extensionsmap[i] do
|
---|
| 302 | begin
|
---|
| 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;
|
---|
| 310 | end;
|
---|
| 311 | end;
|
---|
| 312 | end;
|
---|
| 313 |
|
---|
| 314 |
|
---|
| 315 |
|
---|
| 316 | procedure TAccess_OniArchive.LoadDatFile(FileID: Integer; var Target: TStream);
|
---|
| 317 | var
|
---|
| 318 | streampos: Integer;
|
---|
| 319 | begin
|
---|
| 320 | if fileid < GetFileCount then
|
---|
| 321 | begin
|
---|
| 322 | if not Assigned(Target) then
|
---|
| 323 | Target := TMemoryStream.Create;
|
---|
| 324 | if not FDatOpened then
|
---|
| 325 | Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);
|
---|
| 326 | Fdat_file.Seek(Fdat_files[fileid].DatAddr, soFromBeginning);
|
---|
| 327 | streampos := Target.Position;
|
---|
| 328 | Target.CopyFrom(Fdat_file, Fdat_files[fileid].Size);
|
---|
| 329 | Target.Seek(streampos, soFromBeginning);
|
---|
| 330 | if UnloadWhenUnused then
|
---|
| 331 | begin
|
---|
| 332 | Fdat_file.Free;
|
---|
| 333 | FDatOpened := False;
|
---|
| 334 | end
|
---|
| 335 | else
|
---|
| 336 | FDatOpened := True;
|
---|
| 337 | end;
|
---|
| 338 | end;
|
---|
| 339 |
|
---|
| 340 | procedure TAccess_OniArchive.UpdateDatFile(FileID: Integer; Src: TStream);
|
---|
| 341 | begin
|
---|
| 342 | if fileid < GetFileCount then
|
---|
| 343 | begin
|
---|
| 344 | if not FDatOpened then
|
---|
| 345 | Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);
|
---|
| 346 | Fdat_file.Seek(Fdat_files[fileid].DatAddr, soFromBeginning);
|
---|
| 347 | Fdat_file.CopyFrom(Src, Fdat_files[fileid].Size);
|
---|
| 348 | if UnloadWhenUnused then
|
---|
| 349 | begin
|
---|
| 350 | Fdat_file.Free;
|
---|
| 351 | FDatOpened := False;
|
---|
| 352 | end
|
---|
| 353 | else
|
---|
| 354 | FDatOpened := True;
|
---|
| 355 | end;
|
---|
| 356 | end;
|
---|
| 357 |
|
---|
| 358 | procedure TAccess_OniArchive.LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TStream);
|
---|
| 359 | var
|
---|
| 360 | streampos: Integer;
|
---|
| 361 | begin
|
---|
| 362 | if fileid < GetFileCount then
|
---|
| 363 | begin
|
---|
| 364 | if not Assigned(Target) then
|
---|
| 365 | Target := TMemoryStream.Create;
|
---|
| 366 | if not FDatOpened then
|
---|
| 367 | Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);
|
---|
| 368 | Fdat_file.Seek(Fdat_files[fileid].DatAddr + offset, soFromBeginning);
|
---|
| 369 | streampos := Target.Position;
|
---|
| 370 | Target.CopyFrom(Fdat_file, size);
|
---|
| 371 | Target.Seek(streampos, soFromBeginning);
|
---|
| 372 | if UnloadWhenUnused then
|
---|
| 373 | begin
|
---|
| 374 | FDatOpened := False;
|
---|
| 375 | Fdat_file.Free;
|
---|
| 376 | end
|
---|
| 377 | else
|
---|
| 378 | FDatOpened := True;
|
---|
| 379 | end;
|
---|
| 380 | end;
|
---|
| 381 |
|
---|
| 382 | procedure TAccess_OniArchive.UpdateDatFilePart(FileID, Offset, Size: Integer; Src: TStream);
|
---|
| 383 | begin
|
---|
| 384 | if fileid < GetFileCount then
|
---|
| 385 | begin
|
---|
| 386 | if not FDatOpened then
|
---|
| 387 | Fdat_file := TFileStream.Create(FFileName, fmOpenReadWrite);
|
---|
| 388 | Fdat_file.Seek(Fdat_files[fileid].DatAddr + offset, soFromBeginning);
|
---|
| 389 | Fdat_file.CopyFrom(Src, Size);
|
---|
| 390 | if UnloadWhenUnused then
|
---|
| 391 | begin
|
---|
| 392 | Fdat_file.Free;
|
---|
| 393 | FDatOpened := False;
|
---|
| 394 | end
|
---|
| 395 | else
|
---|
| 396 | FDatOpened := True;
|
---|
| 397 | end;
|
---|
| 398 | end;
|
---|
| 399 |
|
---|
| 400 |
|
---|
| 401 |
|
---|
| 402 | function TAccess_OniArchive.GetDatLink(FileID, DatOffset: Integer): TDatLink;
|
---|
| 403 | var
|
---|
| 404 | link: Integer;
|
---|
| 405 | begin
|
---|
| 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;
|
---|
| 412 | end;
|
---|
| 413 |
|
---|
| 414 |
|
---|
| 415 | function TAccess_OniArchive.GetDatLinks(FileID: Integer): TDatLinkList;
|
---|
| 416 | var
|
---|
| 417 | i: Integer;
|
---|
| 418 | link: Integer;
|
---|
| 419 | begin
|
---|
| 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;
|
---|
| 432 | end;
|
---|
| 433 |
|
---|
| 434 |
|
---|
| 435 | function TAccess_OniArchive.GetRawList(FileID: Integer): TRawDataList;
|
---|
| 436 | begin
|
---|
| 437 | Result := RawLists.GetRawList(FConnectionID, FileID);
|
---|
| 438 | end;
|
---|
| 439 |
|
---|
| 440 |
|
---|
| 441 | function TAccess_OniArchive.GetRawInfo(FileID, DatOffset: Integer): TRawDataInfo;
|
---|
| 442 | begin
|
---|
| 443 | Result := RawLists.GetRawInfo(FConnectionID, FileID, DatOffset);
|
---|
| 444 | end;
|
---|
| 445 |
|
---|
| 446 |
|
---|
| 447 |
|
---|
| 448 | procedure TAccess_OniArchive.LoadRawOffset(LocSep: Boolean; RawAddr, Size: Integer; var target: TStream);
|
---|
| 449 | begin
|
---|
| 450 | if not Assigned(Target) then
|
---|
| 451 | Target := TMemoryStream.Create;
|
---|
| 452 | if not LocSep then
|
---|
| 453 | begin
|
---|
| 454 | if not FRawOpened then
|
---|
| 455 | Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
|
---|
| 456 | fmOpenReadWrite);
|
---|
| 457 | if RawAddr <= Fraw_file.Size then
|
---|
| 458 | begin
|
---|
| 459 | Fraw_file.Seek(RawAddr, soFromBeginning);
|
---|
| 460 | Target.CopyFrom(Fraw_file, size);
|
---|
| 461 | Target.Seek(0, soFromBeginning);
|
---|
| 462 | end;
|
---|
| 463 | if UnloadWhenUnused then
|
---|
| 464 | begin
|
---|
| 465 | FRawOpened := False;
|
---|
| 466 | Fraw_file.Free;
|
---|
| 467 | end
|
---|
| 468 | else
|
---|
| 469 | FRawOpened := True;
|
---|
| 470 | end
|
---|
| 471 | else
|
---|
| 472 | begin
|
---|
| 473 | if not FSepOpened then
|
---|
| 474 | Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
|
---|
| 475 | fmOpenReadWrite);
|
---|
| 476 | if RawAddr <= Fsep_file.Size then
|
---|
| 477 | begin
|
---|
| 478 | Fsep_file.Seek(RawAddr, soFromBeginning);
|
---|
| 479 | Target.CopyFrom(Fsep_file, size);
|
---|
| 480 | Target.Seek(0, soFromBeginning);
|
---|
| 481 | end;
|
---|
| 482 | if UnloadWhenUnused then
|
---|
| 483 | begin
|
---|
| 484 | FSepOpened := False;
|
---|
| 485 | Fsep_file.Free;
|
---|
| 486 | end
|
---|
| 487 | else
|
---|
| 488 | FSepOpened := True;
|
---|
| 489 | end;
|
---|
| 490 | end;
|
---|
| 491 |
|
---|
| 492 | procedure TAccess_OniArchive.LoadRawOffset(LocSep: Boolean; RawAddr, Size: Integer; target: Pointer);
|
---|
| 493 | var
|
---|
| 494 | data: TStream;
|
---|
| 495 | begin
|
---|
| 496 | data := nil;
|
---|
| 497 | LoadRawOffset(LocSep, RawAddr, Size, data);
|
---|
| 498 | data.Read(Target^, Size);
|
---|
| 499 | data.Free;
|
---|
| 500 | end;
|
---|
| 501 |
|
---|
| 502 | procedure TAccess_OniArchive.LoadRawFile(FileID, DatOffset: Integer; var Target: TStream);
|
---|
| 503 | var
|
---|
| 504 | raw_info: TRawDataInfo;
|
---|
| 505 | streampos: Integer;
|
---|
| 506 | begin
|
---|
| 507 | if not Assigned(Target) then
|
---|
| 508 | Target := TMemoryStream.Create;
|
---|
| 509 | if fileid < GetFileCount then
|
---|
| 510 | begin
|
---|
| 511 | raw_info := Self.GetRawInfo(FileID, DatOffset);
|
---|
| 512 | if not raw_info.LocSep then
|
---|
| 513 | begin
|
---|
| 514 | if not FRawOpened then
|
---|
| 515 | Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
|
---|
| 516 | fmOpenReadWrite);
|
---|
| 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);
|
---|
| 521 | if UnloadWhenUnused then
|
---|
| 522 | begin
|
---|
| 523 | FRawOpened := False;
|
---|
| 524 | Fraw_file.Free;
|
---|
| 525 | end
|
---|
| 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);
|
---|
| 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);
|
---|
| 538 | if UnloadWhenUnused then
|
---|
| 539 | begin
|
---|
| 540 | FSepOpened := False;
|
---|
| 541 | Fsep_file.Free;
|
---|
| 542 | end
|
---|
| 543 | else
|
---|
| 544 | FSepOpened := True;
|
---|
| 545 | end;
|
---|
| 546 | end;
|
---|
| 547 | end;
|
---|
| 548 |
|
---|
| 549 | procedure TAccess_OniArchive.UpdateRawFile(FileID, DatOffset: Integer; Src: TStream);
|
---|
| 550 | var
|
---|
| 551 | raw_info: TRawDataInfo;
|
---|
| 552 | begin
|
---|
| 553 | if fileid < GetFileCount then
|
---|
| 554 | begin
|
---|
| 555 | raw_info := GetRawInfo(FileID, DatOffset);
|
---|
| 556 | if not raw_info.LocSep then
|
---|
| 557 | begin
|
---|
| 558 | if not FRawOpened then
|
---|
| 559 | Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
|
---|
| 560 | fmOpenReadWrite);
|
---|
| 561 | Fraw_file.Seek(raw_info.RawAddr, soFromBeginning);
|
---|
| 562 | Fraw_file.CopyFrom(Src, Min(raw_info.RawSize, Src.Size));
|
---|
| 563 | if UnloadWhenUnused then
|
---|
| 564 | begin
|
---|
| 565 | FRawOpened := False;
|
---|
| 566 | Fraw_file.Free;
|
---|
| 567 | end
|
---|
| 568 | else
|
---|
| 569 | FRawOpened := True;
|
---|
| 570 | end
|
---|
| 571 | else
|
---|
| 572 | begin
|
---|
| 573 | if not FSepOpened then
|
---|
| 574 | Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
|
---|
| 575 | fmOpenReadWrite);
|
---|
| 576 | Fsep_file.Seek(raw_info.RawAddr, soFromBeginning);
|
---|
| 577 | Fsep_file.CopyFrom(Src, raw_info.RawSize);
|
---|
| 578 | if UnloadWhenUnused then
|
---|
| 579 | begin
|
---|
| 580 | FSepOpened := False;
|
---|
| 581 | Fsep_file.Free;
|
---|
| 582 | end
|
---|
| 583 | else
|
---|
| 584 | FSepOpened := True;
|
---|
| 585 | end;
|
---|
| 586 | end;
|
---|
| 587 | end;
|
---|
| 588 |
|
---|
| 589 | procedure TAccess_OniArchive.LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; var Target: TStream);
|
---|
| 590 | var
|
---|
| 591 | Data: TStream;
|
---|
| 592 | streampos: Integer;
|
---|
| 593 | begin
|
---|
| 594 | if not Assigned(Target) then
|
---|
| 595 | Target := TMemoryStream.Create;
|
---|
| 596 | if fileid < Self.GetFileCount then
|
---|
| 597 | begin
|
---|
| 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);
|
---|
| 604 | end;
|
---|
| 605 | end;
|
---|
| 606 |
|
---|
| 607 |
|
---|
| 608 | procedure TAccess_OniArchive.UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: TStream);
|
---|
| 609 | var
|
---|
| 610 | raw_info: TRawDataInfo;
|
---|
| 611 | begin
|
---|
| 612 | if fileid < GetFileCount then
|
---|
| 613 | begin
|
---|
| 614 | raw_info := GetRawInfo(FileID, DatOffset);
|
---|
| 615 | if not raw_info.LocSep then
|
---|
| 616 | begin
|
---|
| 617 | if not FRawOpened then
|
---|
| 618 | Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
|
---|
| 619 | fmOpenReadWrite);
|
---|
| 620 | Fraw_file.Seek(raw_info.RawAddr + Offset, soFromBeginning);
|
---|
| 621 | Fraw_file.CopyFrom(Src, Size);
|
---|
| 622 | if UnloadWhenUnused then
|
---|
| 623 | begin
|
---|
| 624 | FRawOpened := False;
|
---|
| 625 | Fraw_file.Free;
|
---|
| 626 | end
|
---|
| 627 | else
|
---|
| 628 | FRawOpened := True;
|
---|
| 629 | end
|
---|
| 630 | else
|
---|
| 631 | begin
|
---|
| 632 | if not FSepOpened then
|
---|
| 633 | Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
|
---|
| 634 | fmOpenReadWrite);
|
---|
| 635 | Fsep_file.Seek(raw_info.RawAddr + Offset, soFromBeginning);
|
---|
| 636 | Fsep_file.CopyFrom(Src, Size);
|
---|
| 637 | if UnloadWhenUnused then
|
---|
| 638 | begin
|
---|
| 639 | FSepOpened := False;
|
---|
| 640 | Fsep_file.Free;
|
---|
| 641 | end
|
---|
| 642 | else
|
---|
| 643 | FSepOpened := True;
|
---|
| 644 | end;
|
---|
| 645 | end;
|
---|
| 646 | end;
|
---|
| 647 |
|
---|
| 648 | function TAccess_OniArchive.AppendRawFile(LocSep: Boolean; Src: TStream): Integer;
|
---|
| 649 | const
|
---|
| 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 );
|
---|
| 652 | begin
|
---|
| 653 | if not LocSep then
|
---|
| 654 | begin
|
---|
| 655 | if not FRawOpened then
|
---|
| 656 | Fraw_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.raw'),
|
---|
| 657 | fmOpenReadWrite);
|
---|
| 658 | if (Fraw_file.Size mod 32) > 0 then
|
---|
| 659 | Fraw_file.Write(EmptyBytes[0], 32 - (Fraw_file.Size mod 32));
|
---|
| 660 | Result := Fraw_file.Size;
|
---|
| 661 | Fraw_file.Seek(0, soFromEnd);
|
---|
| 662 | Fraw_file.CopyFrom(Src, Src.Size);
|
---|
| 663 | if (Fraw_file.Size mod 32) > 0 then
|
---|
| 664 | Fraw_file.Write(EmptyBytes[0], 32 - (Fraw_file.Size mod 32));
|
---|
| 665 | if UnloadWhenUnused then
|
---|
| 666 | begin
|
---|
| 667 | FRawOpened := False;
|
---|
| 668 | Fraw_file.Free;
|
---|
| 669 | end
|
---|
| 670 | else
|
---|
| 671 | FRawOpened := True;
|
---|
| 672 | end
|
---|
| 673 | else
|
---|
| 674 | begin
|
---|
| 675 | if not FSepOpened then
|
---|
| 676 | Fsep_file := TFileStream.Create(AnsiReplaceStr(FFileName, '.dat', '.sep'),
|
---|
| 677 | fmOpenReadWrite);
|
---|
| 678 | if (Fsep_file.Size mod 32) > 0 then
|
---|
| 679 | Fsep_file.Write(EmptyBytes[0], 32 - (Fsep_file.Size mod 32));
|
---|
| 680 | Result := Fsep_file.Size;
|
---|
| 681 | Fsep_file.Seek(0, soFromEnd);
|
---|
| 682 | Fsep_file.CopyFrom(Src, Src.Size);
|
---|
| 683 | if (Fsep_file.Size mod 32) > 0 then
|
---|
| 684 | Fsep_file.Write(EmptyBytes[0], 32 - (Fsep_file.Size mod 32));
|
---|
| 685 | if UnloadWhenUnused then
|
---|
| 686 | begin
|
---|
| 687 | FSepOpened := False;
|
---|
| 688 | Fsep_file.Free;
|
---|
| 689 | end
|
---|
| 690 | else
|
---|
| 691 | FSepOpened := True;
|
---|
| 692 | end;
|
---|
| 693 | end;
|
---|
| 694 |
|
---|
| 695 | end.
|
---|