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

Last change on this file since 153 was 152, checked in by alloc, 18 years ago
File size: 24.4 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 begin
359 ShowMessage(
360 IntToStr(FileID) + '-' + FileInfo.Name + '.' + FileInfo.Extension + #13#10 +
361 IntToStr(FileInfo.Size) + ' - 0x' + IntToHex(FileInfo.Size, 6) + ' - real: ' + IntToStr(DatFileStream.Size) + ' - 0x' + IntToHex(DatFileStream.Size, 6) + #13#10 +
362 IntToStr(Stream_Body.Size) + ' - 0x' + IntToHex(Stream_Body.Size, 6) );
363 Stream_Body.Write(EmptyBytes[0], 32 - (Stream_Body.Size mod 32));
364 end;
365 end
366 else
367 FilesHeader[FileID].DataAddr := 0;
368 if Length(fileinfo.Name) > 0 then
369 begin
370 FilesHeader[FileID].NameAddr := Stream_Names.Size;
371 temps := fileinfo.Extension + fileinfo.Name + Chr(0);
372 Stream_Names.Write(temps[1], Length(temps));
373 end
374 else
375 FilesHeader[FileID].NameAddr := 0;
376 FilesHeader[FileID].FileSize := fileinfo.Size;
377 FilesHeader[FileID].FileType := fileinfo.FileType;
378
379 if ((FileID mod 10) = 0) and (FileID >= 100) then
380 lbl_estimation.Caption := 'Estimated time left: ' + TimeToStr(
381 (Time - FileTime) / FileID * (progress.Max - FileID + 1) * 1.1, TimeFormat );
382 progress.Position := FileID + 1;
383 lbl_progress.Caption := 'Files done: ' + IntToStr(FileID + 1) + '/' + IntToStr(progress.Max);
384 Application.ProcessMessages;
385 end;
386
387 Stream_Dat.Write(DatHeader, SizeOf(DatHeader));
388 for i := 0 to High(FilesHeader) do
389 Stream_Dat.Write(FilesHeader[i], SizeOf(FilesHeader[i]));
390 for i := 0 to High(NamedFilesHeader) do
391 Stream_Dat.Write(NamedFilesHeader[i], SizeOf(NamedFilesHeader[i]));
392 for i := 0 to High(ExtensionsHeader) do
393 Stream_Dat.Write(ExtensionsHeader[i], SizeOf(ExtensionsHeader[i]));
394
395 if (Stream_Dat.Size mod 32) > 0 then
396 Stream_Dat.Write(EmptyBytes[0], 32 - (Stream_Dat.Size mod 32));
397
398 DatHeader.DataSize := Stream_Body.Size;
399 DatHeader.NamesSize := Stream_Names.Size;
400 DatHeader.DataAddr := Stream_Dat.Size;
401
402 Stream_Body.Seek(0, soFromBeginning);
403 Stream_Dat.CopyFrom(Stream_Body, Stream_Body.Size);
404
405 if (Stream_Dat.Size mod 32) > 0 then
406 Stream_Dat.Write(EmptyBytes[0], 32 - (Stream_Dat.Size mod 32));
407
408 DatHeader.NamesAddr := Stream_Dat.Size;
409 Stream_Names.Seek(0, soFromBeginning);
410 Stream_Dat.CopyFrom(Stream_Names, Stream_Names.Size);
411
412 Stream_Dat.Seek(0, soFromBeginning);
413 Stream_Dat.Write(DatHeader, SizeOf(DatHeader));
414
415 Stream_Dat.Free;
416 Stream_Body.Free;
417 Stream_Names.Free;
418 Stream_Raw.Free;
419
420 if Connection.DataOS in [DOS_WINDEMO, DOS_MAC, DOS_MACBETA] then
421 Stream_Sep.Free;
422
423 progress.Position := progress.Max;
424 lbl_progress.Caption := 'Files done: ' + IntToStr(progress.Max) + '/' +
425 IntToStr(progress.Max);
426 lbl_estimation.Caption := 'FINISHED (duration: ' + TimeToStr(Time - Begintime, TimeFormat) + ')';
427
428 DoStep('FIN');
429 btn_abortok.Caption := '&OK';
430 btn_abortok.Default := True;
431
432 converting := False;
433
434// CloseDataConnection(DataConnections[conIndex]);
435end;
436
437
438
439
440procedure TForm_LevelDB.CreateDatabase(Source, target: String);
441var
442 DataBase: TABSDatabase;
443 Query: TABSQuery;
444 MimeCoder: TStringFormat_MIME64;
445
446 BeginTime, FileTime: Double;
447 Step: Integer;
448 TimeFormat: TFormatSettings;
449
450 ConID: Integer;
451 Connection: TDataAccess;
452 ConRepMsg: TStatusMessages;
453
454 FileID: Integer;
455
456 i: Integer;
457 temps: String;
458 tempdata: TByteData;
459 FileInfo: TFileInfo;
460 DatLinks: TDatLinkList;
461 RawLinks: TRawDataList;
462const
463 steps: Byte = 2;
464
465 procedure DoStep(stepname: String);
466 begin
467 Inc(step);
468 if stepname <> 'FIN' then
469 group_progress.Caption :=
470 'Creating DB (Step ' + IntToStr(step) + '/' + IntToStr(steps) + ': ' + stepname + ')'
471 else
472 group_progress.Caption := 'Creating DB (FINISHED)';
473 end;
474
475 procedure StopConvert;
476 begin
477 btn_abortok.Caption := '&Close';
478 btn_abortok.Default := True;
479 converting := False;
480 lbl_estimation.Caption := 'ABORTED';
481 group_progress.Caption := 'Creating DB (ABORTED)';
482 DataBase.Close;
483 if MessageBox(Self.Handle, PChar('Delete the unfinished DB-file?'),
484 PChar('Delete file?'), MB_YESNO) = idYes then
485 begin
486 DeleteFile(target);
487 end;
488end;
489
490
491
492begin
493
494 //
495 // FILE EXISTS CHECK FÜR DAT/RAW/SEP!!!
496 //
497
498 TimeFormat.ShortTimeFormat := 'hh:nn:ss';
499 TimeFormat.LongTimeFormat := 'hh:nn:ss';
500 TimeFormat.TimeSeparator := ':';
501
502 ConID := ConManager.OpenConnection(Source, ConRepMsg);
503 if not (ConRepMsg in [SM_OK, SM_AlreadyOpened]) then
504 begin
505 ShowMessage('Source-file couldn''t be opened! Aborting' + CrLf + GetOpenMsg(ConRepMsg));
506 Exit;
507 end else
508 Connection := ConManager.Connection[ConID];
509
510 ConID := ConManager.FileOpened(Target);
511 if ConID >= 0 then
512 begin
513 if MessageBox(Self.Handle, PChar('Destination-file is opened, close it in ' +
514 'order to proceed conversion?'), PChar('Destination-file opened'),
515 MB_YESNO + MB_ICONQUESTION) = ID_YES then
516 begin
517 if Form_Main.CheckConnectionCloseable(ConID) then
518 if not ConManager.CloseConnection(ConID, ConRepMsg) then
519 begin
520 ShowMessage('Couldn''t close destination-file. Aborting');
521 Exit;
522 end;
523 end else begin
524 ShowMessage('Aborting');
525 Exit;
526 end;
527 end;
528
529 if FileExists(Target) then
530 begin
531 if MessageBox(Self.Handle, PChar('Destination-file exists. ' +
532 'Overwrite it?'), PChar('Destination-file exists'),
533 MB_YESNO + MB_ICONWARNING) = ID_YES then
534 begin
535 if not DeleteFile(Target) then
536 begin
537 ShowMessage('Couldn''t delete file. Aborting');
538 Exit;
539 end;
540 end else begin
541 ShowMessage('Aborting');
542 Exit;
543 end;
544 end;
545
546 Self.Visible := True;
547 Form_Main.Visible := False;
548 step := 0;
549 converting := True;
550 abort := False;
551 btn_abortok.Caption := '&Abort...';
552 btn_abortok.Default := False;
553
554 BeginTime := Time;
555
556 DataBase := TABSDatabase.Create(Self);
557 DataBase.MaxConnections := 1;
558 DataBase.PageSize := 8112;
559 DataBase.PageCountInExtent := 8;
560
561 DataBase.DatabaseName := 'OLDB';
562 DataBase.DatabaseFileName := target;
563 DataBase.CreateDatabase;
564
565 DoStep('Creating tables');
566 progress.Position := 0;
567 lbl_progress.Caption := '';
568 lbl_estimation.Caption := 'Estimated finishing time: unknown';
569 Application.ProcessMessages;
570
571 Query := TABSQuery.Create(Self);
572 Query.DatabaseName := 'OLDB';
573 Query.SQL.Text :=
574 'CREATE TABLE globals ( id AUTOINC PRIMARY KEY, name STRING(128), ' +
575 'value STRING(128) );';
576 Query.ExecSQL;
577 Query.SQL.Text :=
578 'CREATE TABLE linkmap ( id AUTOINC PRIMARY KEY, src_id INTEGER, ' +
579 'src_link_offset INTEGER, target_id INTEGER);';
580 Query.ExecSQL;
581 Query.SQL.Text := 'CREATE INDEX idsrcid ON linkmap (src_id);';
582 Query.ExecSQL;
583 Query.SQL.Text := 'CREATE INDEX idtargetid ON linkmap (target_id);';
584 Query.ExecSQL;
585 Query.SQL.Text :=
586 'CREATE TABLE rawmap ( id AUTOINC PRIMARY KEY, src_id INTEGER, ' +
587 'src_link_offset INTEGER, sep BOOLEAN, size INTEGER, ' +
588 'data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib);';
589 // Query.SQL.Text:='CREATE TABLE rawmap ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, size INTEGER, data BLOB BlobCompressionAlgorithm None );';
590 Query.ExecSQL;
591 Query.SQL.Text := 'CREATE INDEX idsrcid ON rawmap (src_id);';
592 Query.ExecSQL;
593 Query.SQL.Text :=
594 'CREATE TABLE datfiles ( id INTEGER PRIMARY KEY, extension CHAR(4), ' +
595 'name STRING(128), contenttype INTEGER, size INTEGER, ' +
596 'data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib );';
597 // Query.SQL.Text:='CREATE TABLE datfiles ( id INTEGER PRIMARY KEY, extension CHAR(4), name STRING(128), contenttype INTEGER, size INTEGER, data BLOB BlobCompressionAlgorithm None );';
598 Query.ExecSQL;
599// Query.SQL.Text :=
600// 'CREATE TABLE extlist ( id AUTOINC PRIMARY KEY, ext CHAR(4), ident CHAR(16) );';
601// Query.ExecSQL;
602
603 Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("dbversion","' +
604 dbversion + '");';
605 Query.ExecSQL;
606
607 Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("lvl","' +
608 IntToStr(Connection.LevelNumber) + '");';
609 Query.ExecSQL;
610 case Connection.DataOS of
611 DOS_WIN: temps := 'WIN';
612 DOS_WINDEMO: temps := 'WINDEMO';
613 DOS_MAC: temps := 'MAC';
614 DOS_MACBETA: temps := 'MACBETA';
615 end;
616 Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("os","' + temps + '");';
617 Query.ExecSQL;
618
619 progress.Position := 0;
620 lbl_progress.Caption := 'Files done: ' + IntToStr(0) + '/' + IntToStr(
621 Connection.GetFileCount);
622 lbl_estimation.Caption := 'Estimated finishing time: unknown';
623
624 progress.Max := Connection.GetFileCount;
625 begintime := Time;
626 DoStep('Writing .dat-fileslist');
627 Application.ProcessMessages;
628
629 FileTime := Time;
630 Database.StartTransaction;
631 for FileID := 0 to Connection.GetFileCount - 1 do
632 begin
633 fileinfo := Connection.GetFileInfo(FileID);
634 if (fileinfo.FileType and $02) = 0 then
635 begin
636 mimecoder := TStringFormat_MIME64.Create;
637 Connection.LoadDatFile(FileID, tempdata);
638 Query.SQL.Text :=
639 'INSERT INTO datfiles (id,extension,name,contenttype,size,data) VALUES (' +
640 IntToStr(FileID) + ',"' + fileinfo.Extension + '","' + fileinfo.Name + '","' + IntToHex(
641 fileinfo.FileType, 8) + '",' + IntToStr(fileinfo.Size) + ',MimeToBin("' +
642 MimeCoder.StrTo(@tempdata[0], Length(tempdata)) + '") );';
643 Query.ExecSQL;
644 mimecoder.Free;
645
646 RawLinks := Connection.GetRawList(FileID);
647 if Length(RawLinks) > 0 then
648 begin
649 for i := 0 to High(RawLinks) do
650 begin
651 if RawLinks[i].RawSize > 0 then
652 begin
653 SetLength(tempdata, RawLinks[i].RawSize);
654 Connection.LoadRawFile(FileID, RawLinks[i].SrcOffset, tempdata);
655 mimecoder := TStringFormat_MIME64.Create;
656 Query.SQL.Text :=
657 'INSERT INTO rawmap (src_id,src_link_offset,sep,size,data) VALUES (' +
658 IntToStr(FileID) + ', ' + IntToStr(RawLinks[i].SrcOffset) + ',' +
659 BoolToStr(RawLinks[i].LocSep) + ', ' +
660 IntToStr(RawLinks[i].RawSize) + ', ' +
661 'MimeToBin("' + MimeCoder.StrTo(@tempdata[0], RawLinks[i].RawSize) + '") );';
662 Query.ExecSQL;
663 mimecoder.Free;
664 end
665 else
666 begin
667 Query.SQL.Text :=
668 'INSERT INTO rawmap (src_id,src_link_offset,sep,size) VALUES (' +
669 IntToStr(FileID) + ', ' + IntToStr(RawLinks[i].SrcOffset) + ', ' +
670 BoolToStr(RawLinks[i].LocSep) + ', 0);';
671 Query.ExecSQL;
672 end;
673 end;
674 end;
675
676 DatLinks := Connection.GetDatLinks(FileID);
677 if Length(DatLinks) > 0 then
678 begin
679 for i := 0 to High(DatLinks) do
680 begin
681 Query.SQL.Text :=
682 'INSERT INTO linkmap (src_id, src_link_offset, target_id) VALUES (' +
683 IntToStr(FileID) + ', ' + IntToStr(DatLinks[i].SrcOffset) + ', ' +
684 IntToStr(DatLinks[i].DestID) + ');';
685 Query.ExecSQL;
686 end;
687 end;
688 end
689 else
690 begin
691 Query.SQL.Text :=
692 'INSERT INTO datfiles (id,extension,name,contenttype,size) VALUES (' +
693 IntToStr(FileID) + ', "' + fileinfo.Extension + '", ' +
694 '"' + fileinfo.Name + '", "' + IntToHex(fileinfo.FileType, 8) + '", 0);';
695 Query.ExecSQL;
696 end;
697 if ((FileID mod 100) = 0) and (FileID > 0) then
698 begin
699 Database.Commit(False);
700 Database.StartTransaction;
701 end;
702 if ((FileID mod 10) = 0) and (FileID >= 100) then
703 lbl_estimation.Caption := 'Estimated time left: ' + TimeToStr(
704 (Time - FileTime) / FileID * (progress.Max - FileID + 1) * 1.1, timeformat );
705 progress.Position := FileID;
706 lbl_progress.Caption := 'Files done: ' + IntToStr(FileID) + '/' + IntToStr(progress.Max);
707 Application.ProcessMessages;
708 if abort then
709 begin
710 StopConvert;
711 Exit;
712 end;
713 end;
714 Database.Commit(False);
715 progress.Position := progress.Max;
716 lbl_progress.Caption := 'Files done: ' + IntToStr(progress.Max) + '/' +
717 IntToStr(progress.Max);
718
719 lbl_estimation.Caption := 'FINISHED (duration: ' + TimeToStr(Time - BeginTime, timeformat) + ')';
720
721 DoStep('FIN');
722 btn_abortok.Caption := '&OK';
723 btn_abortok.Default := True;
724
725 converting := False;
726
727 Query.Close;
728 Query.Free;
729 DataBase.Close;
730 DataBase.Free;
731end;
732
733
734
735
736procedure TForm_LevelDB.btn_abortokClick(Sender: TObject);
737begin
738 if converting then
739 begin
740 if MessageBox(Self.Handle,
741 PChar('Do you really want to cancel the convert-progress?'),
742 PChar('Warning: Converting'), MB_YESNO) = idYes then
743 abort := True;
744 end
745 else
746 begin
747 Self.Visible := False;
748 Form_Main.Visible := True;
749 end;
750end;
751
752
753end.
Note: See TracBrowser for help on using the repository browser.