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
Line 
1unit LevelDB;
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
16 procedure CreateDatabase(Source, Target: String);
17 procedure CreateLevel(Source, Target: String);
18 end;
19
20
21var
22 Form_LevelDB: TForm_LevelDB;
23
24implementation
25{$R *.dfm}
26uses ABSMain, ABSDecUtil, Main,
27 ConnectionManager, TypeDefs, DataAccess, OniImgClass, Data, RawList;
28
29var
30 Converting: Boolean = False;
31 Abort: Boolean = False;
32
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);
47var
48 DatHeader: THeader;
49 FilesHeader: TFilesMap;
50 NamedFilesHeader: TNamedFilesMap;
51 ExtensionsHeader: TExtensionsMap;
52
53 Stream_Body, Stream_Names: TMemoryStream;
54 Stream_Dat, Stream_Raw, Stream_Sep: TFileStream;
55
56 BeginTime, FileTime: Double;
57 Step: Integer;
58 LevelID: Integer;
59 TimeFormat: TFormatSettings;
60
61 ConID: Integer;
62 Connection: TDataAccess;
63 ConRepMsg: TStatusMessages;
64
65 FileID: Integer;
66
67 Strings: TStrings;
68 i, j: Integer;
69 temps: String;
70 tempi: Integer;
71 tempb: Byte;
72 FileInfo: TFileInfo;
73 DatLinks: TDatLinkList;
74 RawLinks: TRawDataList;
75
76 DatFileStream, RawFileStream: TMemoryStream;
77
78// ###########################
79 datsum, linksum, rawsum: Int64;
80 freq: Int64;
81 tempticks1, tempticks2: Int64;
82// ###########################
83const
84 Steps: Byte = 3;
85
86
87 procedure DoStep(StepName: String);
88 begin
89 Inc(Step);
90 if StepName <> 'FIN' then
91 group_progress.Caption :=
92 'Creating Dat (Step ' + IntToStr(Step) + '/' + IntToStr(Steps) + ': ' + StepName + ')'
93 else
94 group_progress.Caption := 'Creating Dat (FINISHED)';
95 end;
96
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
125begin
126
127 //
128 // FILE EXISTS CHECK FÜR DAT/RAW/SEP!!!
129 //
130
131 TimeFormat.ShortTimeFormat := 'hh:nn:ss';
132 TimeFormat.LongTimeFormat := 'hh:nn:ss';
133 TimeFormat.TimeSeparator := ':';
134
135 ConID := ConManager.OpenConnection(Source, ConRepMsg);
136 if not (ConRepMsg in [SM_OK, SM_AlreadyOpened]) then
137 begin
138 ShowMessage('Source-file couldn''t be opened! Aborting' + CrLf + GetOpenMsg(ConRepMsg));
139 Exit;
140 end else
141 Connection := ConManager.Connection[ConID];
142
143 ConID := ConManager.FileOpened(Target);
144 if ConID >= 0 then
145 begin
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;
160 end;
161
162 if FileExists(Target) then
163 begin
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;
172 end;
173 if FileExists(AnsiReplaceStr(Target, '.dat', '.raw')) then
174 if not DeleteFile(AnsiReplaceStr(Target, '.dat', '.raw')) then
175 begin
176 ShowMessage('Couldn''t delete file. Aborting');
177 Exit;
178 end;
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;
186 end else begin
187 ShowMessage('Aborting');
188 Exit;
189 end;
190 end;
191
192 LevelID := Connection.LevelNumber;
193 LevelID := (LevelID * 2) * 256 * 256 * 256 + $01;
194
195 Self.Visible := True;
196 Form_Main.Visible := False;
197 Step := 0;
198 Converting := True;
199 Abort := False;
200 btn_abortok.Caption := '&Abort...';
201 btn_abortok.Default := False;
202 BeginTime := Time;
203
204 Stream_Body := TMemoryStream.Create;
205 Stream_Names := TMemoryStream.Create;
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);
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
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
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;
244 DatHeader.NamedFiles := Length(NamedFilesHeader);
245
246 Strings := Connection.GetExtensionsList(EF_ExtCount);
247
248 DatHeader.Extensions := Strings.Count;
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
258
259 DoStep('Writing extensions-header');
260 progress.Max := Strings.Count;
261 Application.ProcessMessages;
262 for i := 0 to Strings.Count - 1 do
263 begin
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);
270 for j := 0 to 3 do
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;
287 progress.Position := i + 1;
288 lbl_progress.Caption := 'Extensions done: ' + IntToStr(i + 1) + '/' +
289 IntToStr(Strings.Count);
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
300 QueryPerformanceFrequency(freq);
301 datsum := 0;
302 linksum := 0;
303 rawsum := 0;
304
305 FileTime := Time;
306 for FileID := 0 to DatHeader.Files - 1 do
307 begin
308 FileInfo := Connection.GetFileInfo(FileID);
309 for j := 0 to 3 do
310 FilesHeader[FileID].Extension[j] := FileInfo.Extension[4 - j];
311 if FileInfo.Size > 0 then
312 begin
313 QueryPerformanceCounter(tempticks1);
314
315 FilesHeader[FileID].DataAddr := Stream_Body.Size + 8;
316 DatFileStream := TMemoryStream.Create;
317 Connection.LoadDatFile(FileID, TStream(DatFileStream));
318 DatFileStream.Seek(0, soFromBeginning);
319 tempi := FileID * 256 + 1;
320 DatFileStream.Write(tempi, 4);
321 DatFileStream.Write(LevelID, 4);
322
323 QueryPerformanceCounter(tempticks2);
324 datsum := datsum + (tempticks2 - tempticks1);
325
326 DatLinks := Connection.GetDatLinks(FileID);
327 if Length(DatLinks) > 0 then
328 begin
329 for i := 0 to High(DatLinks) do
330 begin
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
340 QueryPerformanceCounter(tempticks1);
341 linksum := linksum + (tempticks1 - tempticks2);
342
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
349 begin
350 RawFileStream := TMemoryStream.Create;
351 Connection.LoadRawFile(FileID, RawLinks[i].SrcOffset, TStream(RawFileStream));
352 RawFileStream.Seek(0, soFromBeginning);
353 if RawLinks[i].LocSep then
354 begin
355 RawLinks[i].RawAddr := Stream_Sep.Size;
356 Stream_sep.CopyFrom(RawFileStream, RawFileStream.Size);
357 end else begin
358 RawLinks[i].RawAddr := Stream_Raw.Size;
359 Stream_Raw.CopyFrom(RawFileStream, RawFileStream.Size);
360 end;
361 end else
362 RawLinks[i].RawAddr := 0;
363 DatFileStream.Seek(RawLinks[i].SrcOffset, soFromBeginning);
364 DatFileStream.Write(RawLinks[i].RawAddr, 4);
365 end;
366 end;
367 DatFileStream.Seek(0, soFromBeginning);
368 Stream_Body.CopyFrom(DatFileStream, DatFileStream.Size);
369
370 QueryPerformanceCounter(tempticks2);
371 rawsum := rawsum + (tempticks2 - tempticks1);
372 end
373 else
374 FilesHeader[FileID].DataAddr := 0;
375 if Length(fileinfo.Name) > 0 then
376 begin
377 FilesHeader[FileID].NameAddr := Stream_Names.Size;
378 temps := fileinfo.Extension + fileinfo.Name + Chr(0);
379 Stream_Names.Write(temps[1], Length(temps));
380 end
381 else
382 FilesHeader[FileID].NameAddr := 0;
383 FilesHeader[FileID].FileSize := fileinfo.Size;
384 FilesHeader[FileID].FileType := fileinfo.FileType;
385
386 if ((FileID mod 10) = 0) and (FileID >= 100) then
387 lbl_estimation.Caption := 'Estimated time left: ' + TimeToStr(
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);
391 Application.ProcessMessages;
392 end;
393
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
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;
410
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;
424
425 if Connection.DataOS in [DOS_WINDEMO, DOS_MAC, DOS_MACBETA] then
426 Stream_Sep.Free;
427
428 progress.Position := progress.Max;
429 lbl_progress.Caption := 'Files done: ' + IntToStr(progress.Max) + '/' +
430 IntToStr(progress.Max);
431 lbl_estimation.Caption := 'FINISHED (duration: ' + TimeToStr(Time - Begintime, TimeFormat) + ')';
432
433 DoStep('FIN');
434 btn_abortok.Caption := '&OK';
435 btn_abortok.Default := True;
436
437 converting := False;
438
439// CloseDataConnection(DataConnections[conIndex]);
440end;
441
442
443
444
445procedure TForm_LevelDB.CreateDatabase(Source, target: String);
446var
447 DataBase: TABSDatabase;
448 Query: TABSQuery;
449 MimeCoder: TStringFormat_MIME64;
450
451 BeginTime, FileTime: Double;
452 Step: Integer;
453 LevelID: Integer;
454 TimeFormat: TFormatSettings;
455
456 ConID: Integer;
457 Connection: TDataAccess;
458 ConRepMsg: TStatusMessages;
459
460 FileID: Integer;
461
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;
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
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
501begin
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
513 begin
514 ShowMessage('Source-file couldn''t be opened! Aborting' + CrLf + GetOpenMsg(ConRepMsg));
515 Exit;
516 end else
517 Connection := ConManager.Connection[ConID];
518
519 ConID := ConManager.FileOpened(Target);
520 if ConID >= 0 then
521 begin
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;
536 end;
537
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;
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
563 BeginTime := Time;
564
565 DataBase := TABSDatabase.Create(Self);
566 DataBase.MaxConnections := 1;
567 DataBase.PageSize := 8112;
568 DataBase.PageCountInExtent := 8;
569
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 :=
583 'CREATE TABLE globals ( id AUTOINC PRIMARY KEY, name STRING(128), ' +
584 'value STRING(128) );';
585 Query.ExecSQL;
586 Query.SQL.Text :=
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);';
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 src_id);';
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 :=
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 );';
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;
604// Query.SQL.Text :=
605// 'CREATE TABLE extlist ( id AUTOINC PRIMARY KEY, ext CHAR(4), ident CHAR(16) );';
606// Query.ExecSQL;
607
608 Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("dbversion","' +
609 dbversion + '");';
610 Query.ExecSQL;
611
612 Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("lvl","' +
613 IntToStr(Connection.LevelNumber) + '");';
614 Query.ExecSQL;
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 + '");';
622 Query.ExecSQL;
623
624 progress.Position := 0;
625 lbl_progress.Caption := 'Files done: ' + IntToStr(0) + '/' + IntToStr(
626 Connection.GetFileCount);
627 lbl_estimation.Caption := 'Estimated finishing time: unknown';
628
629 progress.Max := Connection.GetFileCount;
630 begintime := Time;
631 DoStep('Writing .dat-fileslist');
632 Application.ProcessMessages;
633
634 Database.StartTransaction;
635 for FileID := 0 to Connection.GetFileCount - 1 do
636 begin
637 fileinfo := Connection.GetFileInfo(FileID);
638 if (fileinfo.FileType and $02) = 0 then
639 begin
640 mimecoder := TStringFormat_MIME64.Create;
641 Connection.LoadDatFile(FileID, tempdata);
642 Query.SQL.Text :=
643 'INSERT INTO datfiles (id,extension,name,contenttype,size,data) VALUES (' +
644 IntToStr(FileID) + ',"' + fileinfo.Extension + '","' + fileinfo.Name + '","' + IntToHex(
645 fileinfo.FileType, 8) + '",' + IntToStr(fileinfo.Size) + ',MimeToBin("' +
646 MimeCoder.StrTo(@tempdata[0], Length(tempdata)) + '") );';
647 Query.ExecSQL;
648 mimecoder.Free;
649
650 RawLinks := Connection.GetRawList(FileID);
651 if Length(RawLinks) > 0 then
652 begin
653 for i := 0 to High(RawLinks) do
654 begin
655 if RawLinks[i].RawSize > 0 then
656 begin
657 SetLength(tempdata, RawLinks[i].RawSize);
658 Connection.LoadRawFile(FileID, RawLinks[i].SrcOffset, tempdata);
659 mimecoder := TStringFormat_MIME64.Create;
660 Query.SQL.Text :=
661 'INSERT INTO rawmap (src_id,src_link_offset,sep,size,data) VALUES (' +
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) + '") );';
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 (' +
673 IntToStr(FileID) + ', ' + IntToStr(RawLinks[i].SrcOffset) + ', ' +
674 BoolToStr(RawLinks[i].LocSep) + ', 0);';
675 Query.ExecSQL;
676 end;
677 end;
678 end;
679
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;
692 end
693 else
694 begin
695 Query.SQL.Text :=
696 'INSERT INTO datfiles (id,extension,name,contenttype,size) VALUES (' +
697 IntToStr(FileID) + ', "' + fileinfo.Extension + '", ' +
698 '"' + fileinfo.Name + '", "' + IntToHex(fileinfo.FileType, 8) + '", 0);';
699 Query.ExecSQL;
700 end;
701 if ((FileID mod 100) = 0) and (FileID > 0) then
702 begin
703 Database.Commit(False);
704 Database.StartTransaction;
705 end;
706 if ((FileID mod 10) = 0) and (FileID >= 100) then
707 lbl_estimation.Caption := 'Estimated time left: ' + TimeToStr(
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);
711 Application.ProcessMessages;
712 if abort then
713 begin
714 StopConvert;
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
723 lbl_estimation.Caption := 'FINISHED (duration: ' + TimeToStr(Time - BeginTime, timeformat) + ')';
724
725 DoStep('FIN');
726 btn_abortok.Caption := '&OK';
727 btn_abortok.Default := True;
728
729 converting := False;
730
731 Query.Close;
732 Query.Free;
733 DataBase.Close;
734 DataBase.Free;
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
757end.
Note: See TracBrowser for help on using the repository browser.