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

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