source: oup/current/Helper/LevelDB.pas@ 138

Last change on this file since 138 was 138, checked in by alloc, 18 years ago
File size: 24.0 KB
RevLine 
[112]1unit LevelDB;
[93]2interface
3uses
4 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5 Dialogs, ComCtrls, StdCtrls, StrUtils;
6
7type
8 TForm_LevelDB = class(TForm)
9 group_progress: TGroupBox;
10 progress: TProgressBar;
11 lbl_progress: TLabel;
12 btn_abortok: TButton;
13 lbl_estimation: TLabel;
14 procedure btn_abortokClick(Sender: TObject);
15 public
[97]16 procedure CreateDatabase(Source, Target: String);
17 procedure CreateLevel(Source, Target: String);
[93]18 end;
19
20
21var
22 Form_LevelDB: TForm_LevelDB;
23
24implementation
25{$R *.dfm}
[112]26uses ABSMain, ABSDecUtil, Main,
[138]27 ConnectionManager, TypeDefs, DataAccess, OniImgClass, Data, RawList;
[93]28
29var
[112]30 Converting: Boolean = False;
31 Abort: Boolean = False;
[93]32
[112]33
34function GetOpenMsg(msg: TStatusMessages): String;
35begin
36 case msg of
37 SM_AlreadyOpened: Result := 'File already opened.';
38 SM_FileNotFound: Result := 'File not found.';
39 SM_UnknownExtension: Result := 'Unknown extension.';
40 SM_IncompatibleFile: Result := 'Incompatible file format.';
41 SM_UnknownError: Result := 'Unknown error.';
42 end;
43end;
44
45
46procedure TForm_LevelDB.CreateLevel(Source, Target: String);
[93]47var
[112]48 DatHeader: THeader;
49 FilesHeader: TFilesMap;
[93]50 NamedFilesHeader: TNamedFilesMap;
51 ExtensionsHeader: TExtensionsMap;
[112]52
53 Stream_Body, Stream_Names: TMemoryStream;
[93]54 Stream_Dat, Stream_Raw, Stream_Sep: TFileStream;
55
[112]56 BeginTime, FileTime: Double;
57 Step: Integer;
58 LevelID: Integer;
59 TimeFormat: TFormatSettings;
[93]60
[112]61 ConID: Integer;
62 Connection: TDataAccess;
63 ConRepMsg: TStatusMessages;
[93]64
[120]65 FileID: Integer;
66
[112]67 Strings: TStrings;
68 i, j: Integer;
[113]69 temps: String;
[120]70 tempi: Integer;
71 tempb: Byte;
[113]72 FileInfo: TFileInfo;
[120]73 DatLinks: TDatLinkList;
74 RawLinks: TRawDataList;
[113]75
76 DatFileStream, RawFileStream: TMemoryStream;
[132]77
78// ###########################
79 datsum, linksum, rawsum: Int64;
80 freq: Int64;
81 tempticks1, tempticks2: Int64;
82// ###########################
[93]83const
[112]84 Steps: Byte = 3;
[93]85
86
[112]87 procedure DoStep(StepName: String);
[93]88 begin
[112]89 Inc(Step);
90 if StepName <> 'FIN' then
[93]91 group_progress.Caption :=
[112]92 'Creating Dat (Step ' + IntToStr(Step) + '/' + IntToStr(Steps) + ': ' + StepName + ')'
[93]93 else
94 group_progress.Caption := 'Creating Dat (FINISHED)';
95 end;
96
[138]97 procedure StopConvert;
98 begin
99 btn_abortok.Caption := '&Close';
100 btn_abortok.Default := True;
101 converting := False;
102 lbl_estimation.Caption := 'ABORTED';
103 group_progress.Caption := 'Creating Level (ABORTED)';
104
105 Stream_Body.Free;
106 Stream_Names.Free;
107 DatFileStream.Free;
108 RawFileStream.Free;
109
110 Stream_Dat.Free;
111 Stream_Raw.Free;
112 if Connection.DataOS in [DOS_WINDEMO, DOS_MAC, DOS_MACBETA] then
113 Stream_Sep.Free;
114
115 if MessageBox(Self.Handle, PChar('Delete the unfinished level-files?'),
116 PChar('Delete files?'), MB_YESNO) = idYes then
117 begin
118 DeleteFile(target);
119 DeleteFile(AnsiReplaceStr(Target, '.dat', '.raw'));
120 if Connection.DataOS in [DOS_WINDEMO, DOS_MAC, DOS_MACBETA] then
121 DeleteFile(AnsiReplaceStr(Target, '.dat', '.sep'));
122 end;
123 end;
124
[93]125begin
126
127 //
128 // FILE EXISTS CHECK FÜR DAT/RAW/SEP!!!
129 //
130
[112]131 TimeFormat.ShortTimeFormat := 'hh:nn:ss';
132 TimeFormat.LongTimeFormat := 'hh:nn:ss';
133 TimeFormat.TimeSeparator := ':';
[93]134
[112]135 ConID := ConManager.OpenConnection(Source, ConRepMsg);
136 if not (ConRepMsg in [SM_OK, SM_AlreadyOpened]) then
[93]137 begin
[112]138 ShowMessage('Source-file couldn''t be opened! Aborting' + CrLf + GetOpenMsg(ConRepMsg));
[93]139 Exit;
[112]140 end else
141 Connection := ConManager.Connection[ConID];
[93]142
[112]143 ConID := ConManager.FileOpened(Target);
144 if ConID >= 0 then
[93]145 begin
[112]146 if MessageBox(Self.Handle, PChar('Destination-file is opened, close it in ' +
147 'order to proceed conversion?'), PChar('Destination-file opened'),
148 MB_YESNO + MB_ICONQUESTION) = ID_YES then
149 begin
150 if Form_Main.CheckConnectionCloseable(ConID) then
151 if not ConManager.CloseConnection(ConID, ConRepMsg) then
152 begin
153 ShowMessage('Couldn''t close destination-file. Aborting');
154 Exit;
155 end;
156 end else begin
157 ShowMessage('Aborting');
158 Exit;
159 end;
[93]160 end;
161
[112]162 if FileExists(Target) then
[93]163 begin
[112]164 if MessageBox(Self.Handle, PChar('Destination-file exists. ' +
165 'Overwrite it?'), PChar('Destination-file exists'),
166 MB_YESNO + MB_ICONWARNING) = ID_YES then
167 begin
168 if not DeleteFile(Target) then
169 begin
170 ShowMessage('Couldn''t delete file. Aborting');
171 Exit;
[131]172 end;
173 if FileExists(AnsiReplaceStr(Target, '.dat', '.raw')) then
174 if not DeleteFile(AnsiReplaceStr(Target, '.dat', '.raw')) then
[130]175 begin
176 ShowMessage('Couldn''t delete file. Aborting');
177 Exit;
178 end;
[131]179 if FileExists(AnsiReplaceStr(Target, '.dat', '.sep')) then
180 if Connection.DataOS in [DOS_WINDEMO, DOS_MAC, DOS_MACBETA] then
181 if not DeleteFile(AnsiReplaceStr(Target, '.dat', '.sep')) then
182 begin
183 ShowMessage('Couldn''t delete file. Aborting');
184 Exit;
185 end;
[112]186 end else begin
187 ShowMessage('Aborting');
188 Exit;
189 end;
[93]190 end;
[112]191
192 LevelID := Connection.LevelNumber;
193 LevelID := (LevelID * 2) * 256 * 256 * 256 + $01;
[93]194
195 Self.Visible := True;
196 Form_Main.Visible := False;
[112]197 Step := 0;
198 Converting := True;
199 Abort := False;
[93]200 btn_abortok.Caption := '&Abort...';
201 btn_abortok.Default := False;
[112]202 BeginTime := Time;
[93]203
204 Stream_Body := TMemoryStream.Create;
205 Stream_Names := TMemoryStream.Create;
[112]206 Stream_Dat := TFileStream.Create(Target, fmCreate);
207 Stream_Raw := TFileStream.Create(AnsiReplaceStr(Target, '.dat', '.raw'), fmCreate);
208 if Connection.DataOS in [DOS_WINDEMO, DOS_MAC, DOS_MACBETA] then
209 Stream_Sep := TFileStream.Create(AnsiReplaceStr(Target, '.dat', '.sep'), fmCreate);
[93]210
211 DoStep('Creating header');
212 progress.Position := 0;
213 lbl_progress.Caption := '';
214 lbl_estimation.Caption := 'Estimated finishing time: unknown';
215 Application.ProcessMessages;
216
[112]217 SetLength(NamedFilesHeader, 0);
218 Strings := TStringList.Create;
219 Strings := Connection.GetFilesList('', '', False, ST_ExtNameAsc);
220 for i := 0 to Strings.Count - 1 do
221 begin
222 if MidStr(Strings.Strings[i],
223 Pos('-', Strings.Strings[i]) + 1,
224 Length(Strings.Strings[i]) -
225 Pos('.', ReverseString(Strings.Strings[i])) -
226 Pos('-', Strings.Strings[i])
227 ) <> '' then
228 begin
229 SetLength(NamedFilesHeader, Length(NamedFilesHeader) + 1);
230 NamedFilesHeader[High(NamedFilesHeader)].FileNumber := StrToInt(MidStr(Strings.Strings[i], 1, 5));
231 NamedFilesHeader[High(NamedFilesHeader)].blubb := 0;
232 end;
233 end;
234
[113]235 for i := 0 to High(DatHeader.OSIdent) do
236 case Connection.DataOS of
237 DOS_WIN: DatHeader.OSIdent[i] := HeaderOSIdentWin[i];
238 DOS_MAC: DatHeader.OSIdent[i] := HeaderOSIdentMac[i];
239 DOS_MACBETA: DatHeader.OSIdent[i] := HeaderOSIdentMacBeta[i];
240 end;
241 for i := 0 to High(DatHeader.GlobalIdent) do
242 DatHeader.GlobalIdent[i] := HeaderGlobalIdent[i];
243 DatHeader.Files := Connection.GetFileCount;
[93]244 DatHeader.NamedFiles := Length(NamedFilesHeader);
[113]245
246 Strings := Connection.GetExtensionsList(EF_ExtCount);
247
248 DatHeader.Extensions := Strings.Count;
[93]249 DatHeader.DataAddr := 0;
250 DatHeader.DataSize := 0;
251 DatHeader.NamesAddr := 0;
252 DatHeader.NamesSize := 0;
253 for i := 0 to High(DatHeader.Ident2) do
254 DatHeader.Ident2[i] := 0;
255 SetLength(FilesHeader, DatHeader.Files);
256 SetLength(ExtensionsHeader, DatHeader.Extensions);
257
[112]258
[93]259 DoStep('Writing extensions-header');
[113]260 progress.Max := Strings.Count;
[93]261 Application.ProcessMessages;
[113]262 for i := 0 to Strings.Count - 1 do
[93]263 begin
[113]264 temps := Strings.Strings[i];
265 ExtensionsHeader[i].ExtCount := StrToInt( MidStr(
266 temps,
267 Pos('(', temps) + 1,
268 Pos(')', temps) - Pos('(', temps) - 1 ) );
269 temps := MidStr(temps, 1, 4);
[93]270 for j := 0 to 3 do
[113]271 ExtensionsHeader[i].Extension[j] := temps[4-j];
272 for j := 0 to High(FileTypes) do
273 if FileTypes[j].Extension = temps then
274 Break;
275 if j < Length(FileTypes) then
276 begin
277 case Connection.DataOS of
278 DOS_WIN: ExtensionsHeader[i].Ident := FileTypes[j].IdentWin;
279 DOS_WINDEMO: ExtensionsHeader[i].Ident := FileTypes[j].IdentMac;
280 DOS_MAC: ExtensionsHeader[i].Ident := FileTypes[j].IdentMac;
281 DOS_MACBETA: ExtensionsHeader[i].Ident := FileTypes[j].IdentMac;
282 end;
283 end else begin
284 ShowMessage('Unknown Extension: ' + Strings.Strings[i]);
285 Exit;
286 end;
[93]287 progress.Position := i + 1;
288 lbl_progress.Caption := 'Extensions done: ' + IntToStr(i + 1) + '/' +
[113]289 IntToStr(Strings.Count);
[93]290 Application.ProcessMessages;
291 end;
292
293 DoStep('Storing files-data');
294 progress.Position := 0;
295 progress.Max := DatHeader.Files;
296 lbl_progress.Caption := '';
297 lbl_estimation.Caption := 'Estimated finishing time: unknown';
298 Application.ProcessMessages;
299
[132]300 QueryPerformanceFrequency(freq);
301 datsum := 0;
302 linksum := 0;
303 rawsum := 0;
304
[113]305 FileTime := Time;
[120]306 for FileID := 0 to DatHeader.Files - 1 do
[93]307 begin
[120]308 FileInfo := Connection.GetFileInfo(FileID);
[93]309 for j := 0 to 3 do
[120]310 FilesHeader[FileID].Extension[j] := FileInfo.Extension[4 - j];
[113]311 if FileInfo.Size > 0 then
[93]312 begin
[132]313 QueryPerformanceCounter(tempticks1);
314
[120]315 FilesHeader[FileID].DataAddr := Stream_Body.Size + 8;
[113]316 DatFileStream := TMemoryStream.Create;
[120]317 Connection.LoadDatFile(FileID, TStream(DatFileStream));
[133]318 DatFileStream.Seek(0, soFromBeginning);
[137]319 tempi := FileID * 256 + 1;
320 DatFileStream.Write(tempi, 4);
[113]321 DatFileStream.Write(LevelID, 4);
[93]322
[132]323 QueryPerformanceCounter(tempticks2);
324 datsum := datsum + (tempticks2 - tempticks1);
325
[120]326 DatLinks := Connection.GetDatLinks(FileID);
327 if Length(DatLinks) > 0 then
[93]328 begin
[120]329 for i := 0 to High(DatLinks) do
[93]330 begin
[120]331 DatFileStream.Seek(DatLinks[i].SrcOffset, soFromBeginning);
332 if DatLinks[i].DestID < 0 then
333 tempi := 0
334 else
335 tempi := DatLinks[i].DestID * 256 + 1;
336 DatFileStream.Write(tempi, 4);
337 end;
338 end;
339
[132]340 QueryPerformanceCounter(tempticks1);
341 linksum := linksum + (tempticks1 - tempticks2);
342
[120]343 RawLinks := Connection.GetRawList(FileID);
344 if Length(RawLinks) > 0 then
345 begin
346 for i := 0 to High(RawLinks) do
347 begin
348 if RawLinks[i].RawSize > 0 then
[93]349 begin
[120]350 RawFileStream := TMemoryStream.Create;
[127]351 Connection.LoadRawFile(FileID, RawLinks[i].SrcOffset, TStream(RawFileStream));
352 RawFileStream.Seek(0, soFromBeginning);
353 if RawLinks[i].LocSep then
[120]354 begin
[127]355 RawLinks[i].RawAddr := Stream_Sep.Size;
356 Stream_sep.CopyFrom(RawFileStream, RawFileStream.Size);
[120]357 end else begin
[127]358 RawLinks[i].RawAddr := Stream_Raw.Size;
359 Stream_Raw.CopyFrom(RawFileStream, RawFileStream.Size);
[120]360 end;
361 end else
362 RawLinks[i].RawAddr := 0;
[129]363 DatFileStream.Seek(RawLinks[i].SrcOffset, soFromBeginning);
364 DatFileStream.Write(RawLinks[i].RawAddr, 4);
[120]365 end;
366 end;
[129]367 DatFileStream.Seek(0, soFromBeginning);
368 Stream_Body.CopyFrom(DatFileStream, DatFileStream.Size);
[132]369
370 QueryPerformanceCounter(tempticks2);
371 rawsum := rawsum + (tempticks2 - tempticks1);
[93]372 end
373 else
[134]374 FilesHeader[FileID].DataAddr := 0;
[93]375 if Length(fileinfo.Name) > 0 then
376 begin
[134]377 FilesHeader[FileID].NameAddr := Stream_Names.Size;
[93]378 temps := fileinfo.Extension + fileinfo.Name + Chr(0);
379 Stream_Names.Write(temps[1], Length(temps));
380 end
381 else
[134]382 FilesHeader[FileID].NameAddr := 0;
383 FilesHeader[FileID].FileSize := fileinfo.Size;
384 FilesHeader[FileID].FileType := fileinfo.FileType;
[93]385
[130]386 if ((FileID mod 10) = 0) and (FileID >= 100) then
[93]387 lbl_estimation.Caption := 'Estimated time left: ' + TimeToStr(
[130]388 (Time - FileTime) / FileID * (progress.Max - FileID + 1) * 1.1, TimeFormat );
389 progress.Position := FileID + 1;
390 lbl_progress.Caption := 'Files done: ' + IntToStr(FileID + 1) + '/' + IntToStr(progress.Max);
[93]391 Application.ProcessMessages;
392 end;
393
[132]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
[93]399 Stream_Dat.Write(DatHeader, SizeOf(DatHeader));
400 for i := 0 to High(FilesHeader) do
401 Stream_Dat.Write(FilesHeader[i], SizeOf(FilesHeader[i]));
402 for i := 0 to High(NamedFilesHeader) do
403 Stream_Dat.Write(NamedFilesHeader[i], SizeOf(NamedFilesHeader[i]));
404 for i := 0 to High(ExtensionsHeader) do
405 Stream_Dat.Write(ExtensionsHeader[i], SizeOf(ExtensionsHeader[i]));
406
407 DatHeader.DataSize := Stream_Body.Size;
408 DatHeader.NamesSize := Stream_Names.Size;
409 DatHeader.DataAddr := Stream_Dat.Size;
[133]410
[93]411 Stream_Body.Seek(0, soFromBeginning);
412 Stream_Dat.CopyFrom(Stream_Body, Stream_Body.Size);
413 DatHeader.NamesAddr := Stream_Dat.Size;
414 Stream_Names.Seek(0, soFromBeginning);
415 Stream_Dat.CopyFrom(Stream_Names, Stream_Names.Size);
416
417 Stream_Dat.Seek(0, soFromBeginning);
418 Stream_Dat.Write(DatHeader, SizeOf(DatHeader));
419
420 Stream_Dat.Free;
421 Stream_Body.Free;
422 Stream_Names.Free;
423 Stream_Raw.Free;
[129]424
425 if Connection.DataOS in [DOS_WINDEMO, DOS_MAC, DOS_MACBETA] then
[93]426 Stream_Sep.Free;
427
428 progress.Position := progress.Max;
429 lbl_progress.Caption := 'Files done: ' + IntToStr(progress.Max) + '/' +
430 IntToStr(progress.Max);
[113]431 lbl_estimation.Caption := 'FINISHED (duration: ' + TimeToStr(Time - Begintime, TimeFormat) + ')';
[93]432
433 DoStep('FIN');
434 btn_abortok.Caption := '&OK';
435 btn_abortok.Default := True;
436
437 converting := False;
438
[129]439// CloseDataConnection(DataConnections[conIndex]);
[93]440end;
441
442
443
444
445procedure TForm_LevelDB.CreateDatabase(Source, target: String);
[134]446var
447 DataBase: TABSDatabase;
[138]448 Query: TABSQuery;
449 MimeCoder: TStringFormat_MIME64;
[112]450
[138]451 BeginTime, FileTime: Double;
452 Step: Integer;
453 LevelID: Integer;
454 TimeFormat: TFormatSettings;
[93]455
[138]456 ConID: Integer;
457 Connection: TDataAccess;
458 ConRepMsg: TStatusMessages;
[93]459
[138]460 FileID: Integer;
[93]461
[138]462 Strings: TStrings;
463 i: Integer;
464 temps: String;
465 tempi: Integer;
466 tempb: Byte;
467 tempdata: TByteData;
468 FileInfo: TFileInfo;
469 DatLinks: TDatLinkList;
470 RawLinks: TRawDataList;
471const
472 steps: Byte = 2;
[93]473
474 procedure DoStep(stepname: String);
475 begin
476 Inc(step);
477 if stepname <> 'FIN' then
478 group_progress.Caption :=
479 'Creating DB (Step ' + IntToStr(step) + '/' + IntToStr(steps) + ': ' + stepname + ')'
480 else
481 group_progress.Caption := 'Creating DB (FINISHED)';
482 end;
483
[138]484 procedure StopConvert;
485 begin
486 btn_abortok.Caption := '&Close';
487 btn_abortok.Default := True;
488 converting := False;
489 lbl_estimation.Caption := 'ABORTED';
490 group_progress.Caption := 'Creating DB (ABORTED)';
491 DataBase.Close;
492 if MessageBox(Self.Handle, PChar('Delete the unfinished DB-file?'),
493 PChar('Delete file?'), MB_YESNO) = idYes then
494 begin
495 DeleteFile(target);
496 end;
497end;
498
499
500
[93]501begin
[138]502
503 //
504 // FILE EXISTS CHECK FÜR DAT/RAW/SEP!!!
505 //
506
507 TimeFormat.ShortTimeFormat := 'hh:nn:ss';
508 TimeFormat.LongTimeFormat := 'hh:nn:ss';
509 TimeFormat.TimeSeparator := ':';
510
511 ConID := ConManager.OpenConnection(Source, ConRepMsg);
512 if not (ConRepMsg in [SM_OK, SM_AlreadyOpened]) then
[93]513 begin
[138]514 ShowMessage('Source-file couldn''t be opened! Aborting' + CrLf + GetOpenMsg(ConRepMsg));
[93]515 Exit;
[138]516 end else
517 Connection := ConManager.Connection[ConID];
518
519 ConID := ConManager.FileOpened(Target);
520 if ConID >= 0 then
[93]521 begin
[138]522 if MessageBox(Self.Handle, PChar('Destination-file is opened, close it in ' +
523 'order to proceed conversion?'), PChar('Destination-file opened'),
524 MB_YESNO + MB_ICONQUESTION) = ID_YES then
525 begin
526 if Form_Main.CheckConnectionCloseable(ConID) then
527 if not ConManager.CloseConnection(ConID, ConRepMsg) then
528 begin
529 ShowMessage('Couldn''t close destination-file. Aborting');
530 Exit;
531 end;
532 end else begin
533 ShowMessage('Aborting');
534 Exit;
535 end;
[93]536 end;
537
[138]538 if FileExists(Target) then
539 begin
540 if MessageBox(Self.Handle, PChar('Destination-file exists. ' +
541 'Overwrite it?'), PChar('Destination-file exists'),
542 MB_YESNO + MB_ICONWARNING) = ID_YES then
543 begin
544 if not DeleteFile(Target) then
545 begin
546 ShowMessage('Couldn''t delete file. Aborting');
547 Exit;
548 end;
549 end else begin
550 ShowMessage('Aborting');
551 Exit;
552 end;
553 end;
[93]554
555 Self.Visible := True;
556 Form_Main.Visible := False;
557 step := 0;
558 converting := True;
559 abort := False;
560 btn_abortok.Caption := '&Abort...';
561 btn_abortok.Default := False;
562
[138]563 BeginTime := Time;
[93]564
565 DataBase := TABSDatabase.Create(Self);
[134]566 DataBase.MaxConnections := 1;
[136]567 DataBase.PageSize := 8112;
568 DataBase.PageCountInExtent := 8;
[138]569
[93]570 DataBase.DatabaseName := 'OLDB';
571 DataBase.DatabaseFileName := target;
572 DataBase.CreateDatabase;
573
574 DoStep('Creating tables');
575 progress.Position := 0;
576 lbl_progress.Caption := '';
577 lbl_estimation.Caption := 'Estimated finishing time: unknown';
578 Application.ProcessMessages;
579
580 Query := TABSQuery.Create(Self);
581 Query.DatabaseName := 'OLDB';
582 Query.SQL.Text :=
[136]583 'CREATE TABLE globals ( id AUTOINC PRIMARY KEY, name STRING(128), ' +
584 'value STRING(128) );';
[93]585 Query.ExecSQL;
586 Query.SQL.Text :=
[136]587 'CREATE TABLE linkmap ( id AUTOINC PRIMARY KEY, src_id INTEGER, ' +
588 'src_link_offset INTEGER, target_id INTEGER, INDEX idsrcid src_id, ' +
589 'INDEX iddestid target_id);';
[93]590 Query.ExecSQL;
591 Query.SQL.Text :=
[136]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 src_id);';
[93]596 // Query.SQL.Text:='CREATE TABLE rawmap ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, size INTEGER, data BLOB BlobCompressionAlgorithm None );';
597 Query.ExecSQL;
598 Query.SQL.Text :=
[136]599 'CREATE TABLE datfiles ( id INTEGER PRIMARY KEY, extension CHAR(4), ' +
600 'name STRING(128), contenttype INTEGER, size INTEGER, ' +
601 'data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib );';
[93]602 // Query.SQL.Text:='CREATE TABLE datfiles ( id INTEGER PRIMARY KEY, extension CHAR(4), name STRING(128), contenttype INTEGER, size INTEGER, data BLOB BlobCompressionAlgorithm None );';
603 Query.ExecSQL;
[136]604// Query.SQL.Text :=
605// 'CREATE TABLE extlist ( id AUTOINC PRIMARY KEY, ext CHAR(4), ident CHAR(16) );';
606// Query.ExecSQL;
[93]607
608 Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("dbversion","' +
609 dbversion + '");';
610 Query.ExecSQL;
[138]611
[93]612 Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("lvl","' +
[138]613 IntToStr(Connection.LevelNumber) + '");';
[93]614 Query.ExecSQL;
[138]615 case Connection.DataOS of
616 DOS_WIN: temps := 'WIN';
617 DOS_WINDEMO: temps := 'WINDEMO';
618 DOS_MAC: temps := 'MAC';
619 DOS_MACBETA: temps := 'MACBETA';
620 end;
621 Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("os","' + temps + '");';
[93]622 Query.ExecSQL;
623
624 progress.Position := 0;
625 lbl_progress.Caption := 'Files done: ' + IntToStr(0) + '/' + IntToStr(
[138]626 Connection.GetFileCount);
[93]627 lbl_estimation.Caption := 'Estimated finishing time: unknown';
628
[138]629 progress.Max := Connection.GetFileCount;
[93]630 begintime := Time;
631 DoStep('Writing .dat-fileslist');
632 Application.ProcessMessages;
633
634 Database.StartTransaction;
[138]635 for FileID := 0 to Connection.GetFileCount - 1 do
[93]636 begin
[138]637 fileinfo := Connection.GetFileInfo(FileID);
[93]638 if (fileinfo.FileType and $02) = 0 then
639 begin
640 mimecoder := TStringFormat_MIME64.Create;
[138]641 Connection.LoadDatFile(FileID, tempdata);
[93]642 Query.SQL.Text :=
643 'INSERT INTO datfiles (id,extension,name,contenttype,size,data) VALUES (' +
[138]644 IntToStr(FileID) + ',"' + fileinfo.Extension + '","' + fileinfo.Name + '","' + IntToHex(
[93]645 fileinfo.FileType, 8) + '",' + IntToStr(fileinfo.Size) + ',MimeToBin("' +
[138]646 MimeCoder.StrTo(@tempdata[0], Length(tempdata)) + '") );';
[93]647 Query.ExecSQL;
648 mimecoder.Free;
649
[138]650 RawLinks := Connection.GetRawList(FileID);
651 if Length(RawLinks) > 0 then
[93]652 begin
[138]653 for i := 0 to High(RawLinks) do
[93]654 begin
[138]655 if RawLinks[i].RawSize > 0 then
[93]656 begin
[138]657 SetLength(tempdata, RawLinks[i].RawSize);
658 Connection.LoadRawFile(FileID, RawLinks[i].SrcOffset, tempdata);
[93]659 mimecoder := TStringFormat_MIME64.Create;
660 Query.SQL.Text :=
661 'INSERT INTO rawmap (src_id,src_link_offset,sep,size,data) VALUES (' +
[138]662 IntToStr(FileID) + ', ' + IntToStr(RawLinks[i].SrcOffset) + ',' +
663 BoolToStr(RawLinks[i].LocSep) + ', ' +
664 IntToStr(RawLinks[i].RawSize) + ', ' +
665 'MimeToBin("' + MimeCoder.StrTo(@tempdata[0], RawLinks[i].RawSize) + '") );';
[93]666 Query.ExecSQL;
667 mimecoder.Free;
668 end
669 else
670 begin
671 Query.SQL.Text :=
672 'INSERT INTO rawmap (src_id,src_link_offset,sep,size) VALUES (' +
[138]673 IntToStr(FileID) + ', ' + IntToStr(RawLinks[i].SrcOffset) + ', ' +
674 BoolToStr(RawLinks[i].LocSep) + ', 0);';
[93]675 Query.ExecSQL;
676 end;
677 end;
678 end;
679
[138]680 DatLinks := Connection.GetDatLinks(FileID);
681 if Length(DatLinks) > 0 then
682 begin
683 for i := 0 to High(DatLinks) do
684 begin
685 Query.SQL.Text :=
686 'INSERT INTO linkmap (src_id, src_link_offset, target_id) VALUES (' +
687 IntToStr(FileID) + ', ' + IntToStr(DatLinks[i].SrcOffset) + ', ' +
688 IntToStr(DatLinks[i].DestID) + ');';
689 Query.ExecSQL;
690 end;
691 end;
[93]692 end
693 else
694 begin
695 Query.SQL.Text :=
696 'INSERT INTO datfiles (id,extension,name,contenttype,size) VALUES (' +
[138]697 IntToStr(FileID) + ', "' + fileinfo.Extension + '", ' +
698 '"' + fileinfo.Name + '", "' + IntToHex(fileinfo.FileType, 8) + '", 0);';
[93]699 Query.ExecSQL;
700 end;
[138]701 if ((FileID mod 100) = 0) and (FileID > 0) then
[93]702 begin
703 Database.Commit(False);
704 Database.StartTransaction;
705 end;
[138]706 if ((FileID mod 10) = 0) and (FileID >= 100) then
[93]707 lbl_estimation.Caption := 'Estimated time left: ' + TimeToStr(
[138]708 (Time - BeginTime) / FileID * (progress.Max - FileID + 1) * 1.1, timeformat );
709 progress.Position := FileID;
710 lbl_progress.Caption := 'Files done: ' + IntToStr(FileID) + '/' + IntToStr(progress.Max);
[93]711 Application.ProcessMessages;
712 if abort then
713 begin
[138]714 StopConvert;
[93]715 Exit;
716 end;
717 end;
718 Database.Commit(False);
719 progress.Position := progress.Max;
720 lbl_progress.Caption := 'Files done: ' + IntToStr(progress.Max) + '/' +
721 IntToStr(progress.Max);
722
[138]723 lbl_estimation.Caption := 'FINISHED (duration: ' + TimeToStr(Time - BeginTime, timeformat) + ')';
[93]724
725 DoStep('FIN');
726 btn_abortok.Caption := '&OK';
727 btn_abortok.Default := True;
728
729 converting := False;
730
[138]731 Query.Close;
732 Query.Free;
733 DataBase.Close;
734 DataBase.Free;
[93]735end;
736
737
738
739
740procedure TForm_LevelDB.btn_abortokClick(Sender: TObject);
741begin
742 if converting then
743 begin
744 if MessageBox(Self.Handle,
745 PChar('Do you really want to cancel the convert-progress?'),
746 PChar('Warning: Converting'), MB_YESNO) = idYes then
747 abort := True;
748 end
749 else
750 begin
751 Self.Visible := False;
752 Form_Main.Visible := True;
753 end;
754end;
755
756
[138]757end.
Note: See TracBrowser for help on using the repository browser.