| 24 |
|
implementation |
| 25 |
|
{$R *.dfm} |
| 26 |
|
uses ABSMain, ABSDecUtil, Main, |
| 27 |
< |
ConnectionManager, TypeDefs, DataAccess, OniImgClass, Data, RawList; |
| 27 |
> |
ConnectionManager, TypeDefs, DataAccess, OniImgClass, Data, RawList, |
| 28 |
> |
Access_OniArchive; |
| 29 |
|
|
| 30 |
|
var |
| 31 |
|
Converting: Boolean = False; |
| 45 |
|
|
| 46 |
|
|
| 47 |
|
procedure TForm_LevelDB.CreateLevel(Source, Target: String); |
| 48 |
+ |
const |
| 49 |
+ |
EmptyBytes: Array[0..31] of Byte = ( |
| 50 |
+ |
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 ); |
| 51 |
|
var |
| 52 |
|
DatHeader: THeader; |
| 53 |
|
FilesHeader: TFilesMap; |
| 78 |
|
RawLinks: TRawDataList; |
| 79 |
|
|
| 80 |
|
DatFileStream, RawFileStream: TMemoryStream; |
| 77 |
– |
|
| 78 |
– |
// ########################### |
| 79 |
– |
datsum, linksum, rawsum: Int64; |
| 80 |
– |
freq: Int64; |
| 81 |
– |
tempticks1, tempticks2: Int64; |
| 82 |
– |
// ########################### |
| 81 |
|
const |
| 82 |
|
Steps: Byte = 3; |
| 83 |
|
|
| 203 |
|
Stream_Names := TMemoryStream.Create; |
| 204 |
|
Stream_Dat := TFileStream.Create(Target, fmCreate); |
| 205 |
|
Stream_Raw := TFileStream.Create(AnsiReplaceStr(Target, '.dat', '.raw'), fmCreate); |
| 206 |
+ |
Stream_Raw.Write(EmptyBytes[0], 32); |
| 207 |
|
if Connection.DataOS in [DOS_WINDEMO, DOS_MAC, DOS_MACBETA] then |
| 208 |
+ |
begin |
| 209 |
|
Stream_Sep := TFileStream.Create(AnsiReplaceStr(Target, '.dat', '.sep'), fmCreate); |
| 210 |
+ |
Stream_Sep.Write(EmptyBytes[0], 32); |
| 211 |
+ |
end; |
| 212 |
+ |
|
| 213 |
|
|
| 214 |
|
DoStep('Creating header'); |
| 215 |
|
progress.Position := 0; |
| 300 |
|
lbl_estimation.Caption := 'Estimated finishing time: unknown'; |
| 301 |
|
Application.ProcessMessages; |
| 302 |
|
|
| 300 |
– |
QueryPerformanceFrequency(freq); |
| 301 |
– |
datsum := 0; |
| 302 |
– |
linksum := 0; |
| 303 |
– |
rawsum := 0; |
| 304 |
– |
|
| 303 |
|
FileTime := Time; |
| 304 |
|
for FileID := 0 to DatHeader.Files - 1 do |
| 305 |
|
begin |
| 308 |
|
FilesHeader[FileID].Extension[j] := FileInfo.Extension[4 - j]; |
| 309 |
|
if FileInfo.Size > 0 then |
| 310 |
|
begin |
| 313 |
– |
QueryPerformanceCounter(tempticks1); |
| 314 |
– |
|
| 311 |
|
FilesHeader[FileID].DataAddr := Stream_Body.Size + 8; |
| 312 |
|
DatFileStream := TMemoryStream.Create; |
| 313 |
|
Connection.LoadDatFile(FileID, TStream(DatFileStream)); |
| 316 |
|
DatFileStream.Write(tempi, 4); |
| 317 |
|
DatFileStream.Write(LevelID, 4); |
| 318 |
|
|
| 323 |
– |
QueryPerformanceCounter(tempticks2); |
| 324 |
– |
datsum := datsum + (tempticks2 - tempticks1); |
| 325 |
– |
|
| 319 |
|
DatLinks := Connection.GetDatLinks(FileID); |
| 320 |
|
if Length(DatLinks) > 0 then |
| 321 |
|
begin |
| 330 |
|
end; |
| 331 |
|
end; |
| 332 |
|
|
| 340 |
– |
QueryPerformanceCounter(tempticks1); |
| 341 |
– |
linksum := linksum + (tempticks1 - tempticks2); |
| 342 |
– |
|
| 333 |
|
RawLinks := Connection.GetRawList(FileID); |
| 334 |
|
if Length(RawLinks) > 0 then |
| 335 |
|
begin |
| 344 |
|
begin |
| 345 |
|
RawLinks[i].RawAddr := Stream_Sep.Size; |
| 346 |
|
Stream_sep.CopyFrom(RawFileStream, RawFileStream.Size); |
| 347 |
+ |
if (Stream_Sep.Size mod 32) > 0 then |
| 348 |
+ |
Stream_Sep.Write(EmptyBytes[0], 32 - (Stream_Sep.Size mod 32)); |
| 349 |
|
end else begin |
| 350 |
|
RawLinks[i].RawAddr := Stream_Raw.Size; |
| 351 |
|
Stream_Raw.CopyFrom(RawFileStream, RawFileStream.Size); |
| 352 |
+ |
if (Stream_Raw.Size mod 32) > 0 then |
| 353 |
+ |
Stream_Raw.Write(EmptyBytes[0], 32 - (Stream_Raw.Size mod 32)); |
| 354 |
|
end; |
| 355 |
|
end else |
| 356 |
|
RawLinks[i].RawAddr := 0; |
| 360 |
|
end; |
| 361 |
|
DatFileStream.Seek(0, soFromBeginning); |
| 362 |
|
Stream_Body.CopyFrom(DatFileStream, DatFileStream.Size); |
| 363 |
< |
|
| 364 |
< |
QueryPerformanceCounter(tempticks2); |
| 365 |
< |
rawsum := rawsum + (tempticks2 - tempticks1); |
| 363 |
> |
if (Stream_Body.Size mod 32) > 0 then |
| 364 |
> |
begin |
| 365 |
> |
ShowMessage( |
| 366 |
> |
IntToStr(FileID) + '-' + FileInfo.Name + '.' + FileInfo.Extension + #13#10 + |
| 367 |
> |
IntToStr(FileInfo.Size) + ' - 0x' + IntToHex(FileInfo.Size, 6) + ' - real: ' + IntToStr(DatFileStream.Size) + ' - 0x' + IntToHex(DatFileStream.Size, 6) + #13#10 + |
| 368 |
> |
IntToStr(Stream_Body.Size) + ' - 0x' + IntToHex(Stream_Body.Size, 6) ); |
| 369 |
> |
Stream_Body.Write(EmptyBytes[0], 32 - (Stream_Body.Size mod 32)); |
| 370 |
> |
end; |
| 371 |
|
end |
| 372 |
|
else |
| 373 |
|
FilesHeader[FileID].DataAddr := 0; |
| 390 |
|
Application.ProcessMessages; |
| 391 |
|
end; |
| 392 |
|
|
| 394 |
– |
ShowMessage('AvgDats: ' + FloatToStr((datsum / progress.Max) / freq) + #13#10 + |
| 395 |
– |
'AvgLinks: ' + FloatToStr((linksum / progress.Max) / freq) + #13#10 + |
| 396 |
– |
'AvgRaws: ' + FloatToStr((rawsum / progress.Max) / freq) |
| 397 |
– |
); |
| 398 |
– |
|
| 393 |
|
Stream_Dat.Write(DatHeader, SizeOf(DatHeader)); |
| 394 |
|
for i := 0 to High(FilesHeader) do |
| 395 |
|
Stream_Dat.Write(FilesHeader[i], SizeOf(FilesHeader[i])); |
| 398 |
|
for i := 0 to High(ExtensionsHeader) do |
| 399 |
|
Stream_Dat.Write(ExtensionsHeader[i], SizeOf(ExtensionsHeader[i])); |
| 400 |
|
|
| 401 |
+ |
if (Stream_Dat.Size mod 32) > 0 then |
| 402 |
+ |
Stream_Dat.Write(EmptyBytes[0], 32 - (Stream_Dat.Size mod 32)); |
| 403 |
+ |
|
| 404 |
|
DatHeader.DataSize := Stream_Body.Size; |
| 405 |
|
DatHeader.NamesSize := Stream_Names.Size; |
| 406 |
|
DatHeader.DataAddr := Stream_Dat.Size; |
| 407 |
|
|
| 408 |
|
Stream_Body.Seek(0, soFromBeginning); |
| 409 |
|
Stream_Dat.CopyFrom(Stream_Body, Stream_Body.Size); |
| 410 |
+ |
|
| 411 |
+ |
if (Stream_Dat.Size mod 32) > 0 then |
| 412 |
+ |
Stream_Dat.Write(EmptyBytes[0], 32 - (Stream_Dat.Size mod 32)); |
| 413 |
+ |
|
| 414 |
|
DatHeader.NamesAddr := Stream_Dat.Size; |
| 415 |
|
Stream_Names.Seek(0, soFromBeginning); |
| 416 |
|
Stream_Dat.CopyFrom(Stream_Names, Stream_Names.Size); |
| 451 |
|
|
| 452 |
|
BeginTime, FileTime: Double; |
| 453 |
|
Step: Integer; |
| 453 |
– |
LevelID: Integer; |
| 454 |
|
TimeFormat: TFormatSettings; |
| 455 |
|
|
| 456 |
|
ConID: Integer; |
| 459 |
|
|
| 460 |
|
FileID: Integer; |
| 461 |
|
|
| 462 |
– |
Strings: TStrings; |
| 462 |
|
i: Integer; |
| 463 |
|
temps: String; |
| 465 |
– |
tempi: Integer; |
| 466 |
– |
tempb: Byte; |
| 464 |
|
tempdata: TByteData; |
| 465 |
|
FileInfo: TFileInfo; |
| 466 |
|
DatLinks: TDatLinkList; |
| 582 |
|
Query.ExecSQL; |
| 583 |
|
Query.SQL.Text := |
| 584 |
|
'CREATE TABLE linkmap ( id AUTOINC PRIMARY KEY, src_id INTEGER, ' + |
| 585 |
< |
'src_link_offset INTEGER, target_id INTEGER, INDEX idsrcid x src_id, ' + |
| 586 |
< |
'INDEX iddestid x target_id);'; |
| 585 |
> |
'src_link_offset INTEGER, target_id INTEGER);'; |
| 586 |
> |
Query.ExecSQL; |
| 587 |
> |
Query.SQL.Text := 'CREATE INDEX idsrcid ON linkmap (src_id);'; |
| 588 |
> |
Query.ExecSQL; |
| 589 |
> |
Query.SQL.Text := 'CREATE INDEX idtargetid ON linkmap (target_id);'; |
| 590 |
|
Query.ExecSQL; |
| 591 |
|
Query.SQL.Text := |
| 592 |
|
'CREATE TABLE rawmap ( id AUTOINC PRIMARY KEY, src_id INTEGER, ' + |
| 593 |
|
'src_link_offset INTEGER, sep BOOLEAN, size INTEGER, ' + |
| 594 |
< |
'data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib, ' + |
| 595 |
< |
'INDEX idsrcid x src_id);'; |
| 594 |
> |
'data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib);'; |
| 595 |
|
// Query.SQL.Text:='CREATE TABLE rawmap ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, size INTEGER, data BLOB BlobCompressionAlgorithm None );'; |
| 596 |
|
Query.ExecSQL; |
| 597 |
+ |
Query.SQL.Text := 'CREATE INDEX idsrcid ON rawmap (src_id);'; |
| 598 |
+ |
Query.ExecSQL; |
| 599 |
|
Query.SQL.Text := |
| 600 |
|
'CREATE TABLE datfiles ( id INTEGER PRIMARY KEY, extension CHAR(4), ' + |
| 601 |
|
'name STRING(128), contenttype INTEGER, size INTEGER, ' + |
| 632 |
|
DoStep('Writing .dat-fileslist'); |
| 633 |
|
Application.ProcessMessages; |
| 634 |
|
|
| 635 |
+ |
TAccess_OniArchive(Connection).UnloadWhenUnused := False; |
| 636 |
+ |
|
| 637 |
+ |
FileTime := Time; |
| 638 |
|
Database.StartTransaction; |
| 639 |
|
for FileID := 0 to Connection.GetFileCount - 1 do |
| 640 |
|
begin |
| 709 |
|
end; |
| 710 |
|
if ((FileID mod 10) = 0) and (FileID >= 100) then |
| 711 |
|
lbl_estimation.Caption := 'Estimated time left: ' + TimeToStr( |
| 712 |
< |
(Time - BeginTime) / FileID * (progress.Max - FileID + 1) * 1.1, timeformat ); |
| 712 |
> |
(Time - FileTime) / FileID * (progress.Max - FileID + 1) * 1.1, timeformat ); |
| 713 |
|
progress.Position := FileID; |
| 714 |
|
lbl_progress.Caption := 'Files done: ' + IntToStr(FileID) + '/' + IntToStr(progress.Max); |
| 715 |
|
Application.ProcessMessages; |
| 731 |
|
btn_abortok.Default := True; |
| 732 |
|
|
| 733 |
|
converting := False; |
| 734 |
+ |
TAccess_OniArchive(Connection).UnloadWhenUnused := True; |
| 735 |
|
|
| 736 |
|
Query.Close; |
| 737 |
|
Query.Free; |