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