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
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);
[143]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 );
[93]50var
[112]51 DatHeader: THeader;
52 FilesHeader: TFilesMap;
[93]53 NamedFilesHeader: TNamedFilesMap;
54 ExtensionsHeader: TExtensionsMap;
[112]55
56 Stream_Body, Stream_Names: TMemoryStream;
[93]57 Stream_Dat, Stream_Raw, Stream_Sep: TFileStream;
58
[112]59 BeginTime, FileTime: Double;
60 Step: Integer;
61 LevelID: Integer;
62 TimeFormat: TFormatSettings;
[93]63
[112]64 ConID: Integer;
65 Connection: TDataAccess;
66 ConRepMsg: TStatusMessages;
[93]67
[120]68 FileID: Integer;
69
[112]70 Strings: TStrings;
71 i, j: Integer;
[113]72 temps: String;
[120]73 tempi: Integer;
74 tempb: Byte;
[113]75 FileInfo: TFileInfo;
[120]76 DatLinks: TDatLinkList;
77 RawLinks: TRawDataList;
[113]78
79 DatFileStream, RawFileStream: TMemoryStream;
[93]80const
[112]81 Steps: Byte = 3;
[93]82
83
[112]84 procedure DoStep(StepName: String);
[93]85 begin
[112]86 Inc(Step);
87 if StepName <> 'FIN' then
[93]88 group_progress.Caption :=
[112]89 'Creating Dat (Step ' + IntToStr(Step) + '/' + IntToStr(Steps) + ': ' + StepName + ')'
[93]90 else
91 group_progress.Caption := 'Creating Dat (FINISHED)';
92 end;
93
[138]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
[93]122begin
123
124 //
125 // FILE EXISTS CHECK FÜR DAT/RAW/SEP!!!
126 //
127
[112]128 TimeFormat.ShortTimeFormat := 'hh:nn:ss';
129 TimeFormat.LongTimeFormat := 'hh:nn:ss';
130 TimeFormat.TimeSeparator := ':';
[93]131
[112]132 ConID := ConManager.OpenConnection(Source, ConRepMsg);
133 if not (ConRepMsg in [SM_OK, SM_AlreadyOpened]) then
[93]134 begin
[112]135 ShowMessage('Source-file couldn''t be opened! Aborting' + CrLf + GetOpenMsg(ConRepMsg));
[93]136 Exit;
[112]137 end else
138 Connection := ConManager.Connection[ConID];
[93]139
[112]140 ConID := ConManager.FileOpened(Target);
141 if ConID >= 0 then
[93]142 begin
[112]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;
[93]157 end;
158
[112]159 if FileExists(Target) then
[93]160 begin
[112]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;
[131]169 end;
170 if FileExists(AnsiReplaceStr(Target, '.dat', '.raw')) then
171 if not DeleteFile(AnsiReplaceStr(Target, '.dat', '.raw')) then
[130]172 begin
173 ShowMessage('Couldn''t delete file. Aborting');
174 Exit;
175 end;
[131]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;
[112]183 end else begin
184 ShowMessage('Aborting');
185 Exit;
186 end;
[93]187 end;
[112]188
189 LevelID := Connection.LevelNumber;
190 LevelID := (LevelID * 2) * 256 * 256 * 256 + $01;
[93]191
192 Self.Visible := True;
193 Form_Main.Visible := False;
[112]194 Step := 0;
195 Converting := True;
196 Abort := False;
[93]197 btn_abortok.Caption := '&Abort...';
198 btn_abortok.Default := False;
[112]199 BeginTime := Time;
[93]200
201 Stream_Body := TMemoryStream.Create;
202 Stream_Names := TMemoryStream.Create;
[112]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);
[93]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
[112]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
[113]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;
[93]241 DatHeader.NamedFiles := Length(NamedFilesHeader);
[113]242
243 Strings := Connection.GetExtensionsList(EF_ExtCount);
244
245 DatHeader.Extensions := Strings.Count;
[93]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
[112]255
[93]256 DoStep('Writing extensions-header');
[113]257 progress.Max := Strings.Count;
[93]258 Application.ProcessMessages;
[113]259 for i := 0 to Strings.Count - 1 do
[93]260 begin
[113]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);
[93]267 for j := 0 to 3 do
[113]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;
[93]284 progress.Position := i + 1;
285 lbl_progress.Caption := 'Extensions done: ' + IntToStr(i + 1) + '/' +
[113]286 IntToStr(Strings.Count);
[93]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
[113]297 FileTime := Time;
[120]298 for FileID := 0 to DatHeader.Files - 1 do
[93]299 begin
[120]300 FileInfo := Connection.GetFileInfo(FileID);
[93]301 for j := 0 to 3 do
[120]302 FilesHeader[FileID].Extension[j] := FileInfo.Extension[4 - j];
[113]303 if FileInfo.Size > 0 then
[93]304 begin
[120]305 FilesHeader[FileID].DataAddr := Stream_Body.Size + 8;
[113]306 DatFileStream := TMemoryStream.Create;
[120]307 Connection.LoadDatFile(FileID, TStream(DatFileStream));
[133]308 DatFileStream.Seek(0, soFromBeginning);
[137]309 tempi := FileID * 256 + 1;
310 DatFileStream.Write(tempi, 4);
[113]311 DatFileStream.Write(LevelID, 4);
[93]312
[120]313 DatLinks := Connection.GetDatLinks(FileID);
314 if Length(DatLinks) > 0 then
[93]315 begin
[120]316 for i := 0 to High(DatLinks) do
[93]317 begin
[120]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
[93]333 begin
[120]334 RawFileStream := TMemoryStream.Create;
[127]335 Connection.LoadRawFile(FileID, RawLinks[i].SrcOffset, TStream(RawFileStream));
336 RawFileStream.Seek(0, soFromBeginning);
337 if RawLinks[i].LocSep then
[120]338 begin
[127]339 RawLinks[i].RawAddr := Stream_Sep.Size;
340 Stream_sep.CopyFrom(RawFileStream, RawFileStream.Size);
[143]341 if (Stream_Sep.Size mod 32) > 0 then
342 Stream_Sep.Write(EmptyBytes[0], 32 - (Stream_Sep.Size mod 32));
[120]343 end else begin
[127]344 RawLinks[i].RawAddr := Stream_Raw.Size;
345 Stream_Raw.CopyFrom(RawFileStream, RawFileStream.Size);
[143]346 if (Stream_Raw.Size mod 32) > 0 then
347 Stream_Raw.Write(EmptyBytes[0], 32 - (Stream_Raw.Size mod 32));
[120]348 end;
349 end else
350 RawLinks[i].RawAddr := 0;
[129]351 DatFileStream.Seek(RawLinks[i].SrcOffset, soFromBeginning);
352 DatFileStream.Write(RawLinks[i].RawAddr, 4);
[120]353 end;
354 end;
[129]355 DatFileStream.Seek(0, soFromBeginning);
356 Stream_Body.CopyFrom(DatFileStream, DatFileStream.Size);
[143]357 if (Stream_Body.Size mod 32) > 0 then
[150]358 begin
359 ShowMessage(
360 IntToStr(FileID) + '-' + FileInfo.Name + '.' + FileInfo.Extension + #13#10 +
[152]361 IntToStr(FileInfo.Size) + ' - 0x' + IntToHex(FileInfo.Size, 6) + ' - real: ' + IntToStr(DatFileStream.Size) + ' - 0x' + IntToHex(DatFileStream.Size, 6) + #13#10 +
[151]362 IntToStr(Stream_Body.Size) + ' - 0x' + IntToHex(Stream_Body.Size, 6) );
[143]363 Stream_Body.Write(EmptyBytes[0], 32 - (Stream_Body.Size mod 32));
[150]364 end;
[93]365 end
366 else
[134]367 FilesHeader[FileID].DataAddr := 0;
[93]368 if Length(fileinfo.Name) > 0 then
369 begin
[134]370 FilesHeader[FileID].NameAddr := Stream_Names.Size;
[93]371 temps := fileinfo.Extension + fileinfo.Name + Chr(0);
372 Stream_Names.Write(temps[1], Length(temps));
373 end
374 else
[134]375 FilesHeader[FileID].NameAddr := 0;
376 FilesHeader[FileID].FileSize := fileinfo.Size;
377 FilesHeader[FileID].FileType := fileinfo.FileType;
[93]378
[130]379 if ((FileID mod 10) = 0) and (FileID >= 100) then
[93]380 lbl_estimation.Caption := 'Estimated time left: ' + TimeToStr(
[130]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);
[93]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
[143]395 if (Stream_Dat.Size mod 32) > 0 then
396 Stream_Dat.Write(EmptyBytes[0], 32 - (Stream_Dat.Size mod 32));
397
[93]398 DatHeader.DataSize := Stream_Body.Size;
399 DatHeader.NamesSize := Stream_Names.Size;
400 DatHeader.DataAddr := Stream_Dat.Size;
[133]401
[93]402 Stream_Body.Seek(0, soFromBeginning);
403 Stream_Dat.CopyFrom(Stream_Body, Stream_Body.Size);
[143]404
405 if (Stream_Dat.Size mod 32) > 0 then
406 Stream_Dat.Write(EmptyBytes[0], 32 - (Stream_Dat.Size mod 32));
407
[93]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;
[129]419
420 if Connection.DataOS in [DOS_WINDEMO, DOS_MAC, DOS_MACBETA] then
[93]421 Stream_Sep.Free;
422
423 progress.Position := progress.Max;
424 lbl_progress.Caption := 'Files done: ' + IntToStr(progress.Max) + '/' +
425 IntToStr(progress.Max);
[113]426 lbl_estimation.Caption := 'FINISHED (duration: ' + TimeToStr(Time - Begintime, TimeFormat) + ')';
[93]427
428 DoStep('FIN');
429 btn_abortok.Caption := '&OK';
430 btn_abortok.Default := True;
431
432 converting := False;
433
[129]434// CloseDataConnection(DataConnections[conIndex]);
[93]435end;
436
437
438
439
440procedure TForm_LevelDB.CreateDatabase(Source, target: String);
[134]441var
442 DataBase: TABSDatabase;
[138]443 Query: TABSQuery;
444 MimeCoder: TStringFormat_MIME64;
[112]445
[138]446 BeginTime, FileTime: Double;
447 Step: Integer;
448 TimeFormat: TFormatSettings;
[93]449
[138]450 ConID: Integer;
451 Connection: TDataAccess;
452 ConRepMsg: TStatusMessages;
[93]453
[138]454 FileID: Integer;
[93]455
[138]456 i: Integer;
457 temps: String;
458 tempdata: TByteData;
459 FileInfo: TFileInfo;
460 DatLinks: TDatLinkList;
461 RawLinks: TRawDataList;
462const
463 steps: Byte = 2;
[93]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
[138]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
[93]492begin
[138]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
[93]504 begin
[138]505 ShowMessage('Source-file couldn''t be opened! Aborting' + CrLf + GetOpenMsg(ConRepMsg));
[93]506 Exit;
[138]507 end else
508 Connection := ConManager.Connection[ConID];
509
510 ConID := ConManager.FileOpened(Target);
511 if ConID >= 0 then
[93]512 begin
[138]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;
[93]527 end;
528
[138]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;
[93]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
[138]554 BeginTime := Time;
[93]555
556 DataBase := TABSDatabase.Create(Self);
[134]557 DataBase.MaxConnections := 1;
[136]558 DataBase.PageSize := 8112;
559 DataBase.PageCountInExtent := 8;
[138]560
[93]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 :=
[136]574 'CREATE TABLE globals ( id AUTOINC PRIMARY KEY, name STRING(128), ' +
575 'value STRING(128) );';
[93]576 Query.ExecSQL;
577 Query.SQL.Text :=
[136]578 'CREATE TABLE linkmap ( id AUTOINC PRIMARY KEY, src_id INTEGER, ' +
[141]579 'src_link_offset INTEGER, target_id INTEGER);';
[93]580 Query.ExecSQL;
[141]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;
[93]585 Query.SQL.Text :=
[136]586 'CREATE TABLE rawmap ( id AUTOINC PRIMARY KEY, src_id INTEGER, ' +
587 'src_link_offset INTEGER, sep BOOLEAN, size INTEGER, ' +
[141]588 'data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib);';
[93]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;
[141]591 Query.SQL.Text := 'CREATE INDEX idsrcid ON rawmap (src_id);';
592 Query.ExecSQL;
[93]593 Query.SQL.Text :=
[136]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 );';
[93]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;
[136]599// Query.SQL.Text :=
600// 'CREATE TABLE extlist ( id AUTOINC PRIMARY KEY, ext CHAR(4), ident CHAR(16) );';
601// Query.ExecSQL;
[93]602
603 Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("dbversion","' +
604 dbversion + '");';
605 Query.ExecSQL;
[138]606
[93]607 Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("lvl","' +
[138]608 IntToStr(Connection.LevelNumber) + '");';
[93]609 Query.ExecSQL;
[138]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 + '");';
[93]617 Query.ExecSQL;
618
619 progress.Position := 0;
620 lbl_progress.Caption := 'Files done: ' + IntToStr(0) + '/' + IntToStr(
[138]621 Connection.GetFileCount);
[93]622 lbl_estimation.Caption := 'Estimated finishing time: unknown';
623
[138]624 progress.Max := Connection.GetFileCount;
[93]625 begintime := Time;
626 DoStep('Writing .dat-fileslist');
627 Application.ProcessMessages;
628
[142]629 FileTime := Time;
[93]630 Database.StartTransaction;
[138]631 for FileID := 0 to Connection.GetFileCount - 1 do
[93]632 begin
[138]633 fileinfo := Connection.GetFileInfo(FileID);
[93]634 if (fileinfo.FileType and $02) = 0 then
635 begin
636 mimecoder := TStringFormat_MIME64.Create;
[138]637 Connection.LoadDatFile(FileID, tempdata);
[93]638 Query.SQL.Text :=
639 'INSERT INTO datfiles (id,extension,name,contenttype,size,data) VALUES (' +
[138]640 IntToStr(FileID) + ',"' + fileinfo.Extension + '","' + fileinfo.Name + '","' + IntToHex(
[93]641 fileinfo.FileType, 8) + '",' + IntToStr(fileinfo.Size) + ',MimeToBin("' +
[138]642 MimeCoder.StrTo(@tempdata[0], Length(tempdata)) + '") );';
[93]643 Query.ExecSQL;
644 mimecoder.Free;
645
[138]646 RawLinks := Connection.GetRawList(FileID);
647 if Length(RawLinks) > 0 then
[93]648 begin
[138]649 for i := 0 to High(RawLinks) do
[93]650 begin
[138]651 if RawLinks[i].RawSize > 0 then
[93]652 begin
[138]653 SetLength(tempdata, RawLinks[i].RawSize);
654 Connection.LoadRawFile(FileID, RawLinks[i].SrcOffset, tempdata);
[93]655 mimecoder := TStringFormat_MIME64.Create;
656 Query.SQL.Text :=
657 'INSERT INTO rawmap (src_id,src_link_offset,sep,size,data) VALUES (' +
[138]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) + '") );';
[93]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 (' +
[138]669 IntToStr(FileID) + ', ' + IntToStr(RawLinks[i].SrcOffset) + ', ' +
670 BoolToStr(RawLinks[i].LocSep) + ', 0);';
[93]671 Query.ExecSQL;
672 end;
673 end;
674 end;
675
[138]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;
[93]688 end
689 else
690 begin
691 Query.SQL.Text :=
692 'INSERT INTO datfiles (id,extension,name,contenttype,size) VALUES (' +
[138]693 IntToStr(FileID) + ', "' + fileinfo.Extension + '", ' +
694 '"' + fileinfo.Name + '", "' + IntToHex(fileinfo.FileType, 8) + '", 0);';
[93]695 Query.ExecSQL;
696 end;
[138]697 if ((FileID mod 100) = 0) and (FileID > 0) then
[93]698 begin
699 Database.Commit(False);
700 Database.StartTransaction;
701 end;
[138]702 if ((FileID mod 10) = 0) and (FileID >= 100) then
[93]703 lbl_estimation.Caption := 'Estimated time left: ' + TimeToStr(
[142]704 (Time - FileTime) / FileID * (progress.Max - FileID + 1) * 1.1, timeformat );
[138]705 progress.Position := FileID;
706 lbl_progress.Caption := 'Files done: ' + IntToStr(FileID) + '/' + IntToStr(progress.Max);
[93]707 Application.ProcessMessages;
708 if abort then
709 begin
[138]710 StopConvert;
[93]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
[138]719 lbl_estimation.Caption := 'FINISHED (duration: ' + TimeToStr(Time - BeginTime, timeformat) + ')';
[93]720
721 DoStep('FIN');
722 btn_abortok.Caption := '&OK';
723 btn_abortok.Default := True;
724
725 converting := False;
726
[138]727 Query.Close;
728 Query.Free;
729 DataBase.Close;
730 DataBase.Free;
[93]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
[138]753end.
Note: See TracBrowser for help on using the repository browser.