[112] | 1 | unit LevelDB;
|
---|
[93] | 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
|
---|
[97] | 16 | procedure CreateDatabase(Source, Target: String);
|
---|
| 17 | procedure CreateLevel(Source, Target: String);
|
---|
[93] | 18 | end;
|
---|
| 19 |
|
---|
| 20 |
|
---|
| 21 | var
|
---|
| 22 | Form_LevelDB: TForm_LevelDB;
|
---|
| 23 |
|
---|
| 24 | implementation
|
---|
| 25 | {$R *.dfm}
|
---|
[112] | 26 | uses ABSMain, ABSDecUtil, Main,
|
---|
[138] | 27 | ConnectionManager, TypeDefs, DataAccess, OniImgClass, Data, RawList;
|
---|
[93] | 28 |
|
---|
| 29 | var
|
---|
[112] | 30 | Converting: Boolean = False;
|
---|
| 31 | Abort: Boolean = False;
|
---|
[93] | 32 |
|
---|
[112] | 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);
|
---|
[93] | 47 | var
|
---|
[112] | 48 | DatHeader: THeader;
|
---|
| 49 | FilesHeader: TFilesMap;
|
---|
[93] | 50 | NamedFilesHeader: TNamedFilesMap;
|
---|
| 51 | ExtensionsHeader: TExtensionsMap;
|
---|
[112] | 52 |
|
---|
| 53 | Stream_Body, Stream_Names: TMemoryStream;
|
---|
[93] | 54 | Stream_Dat, Stream_Raw, Stream_Sep: TFileStream;
|
---|
| 55 |
|
---|
[112] | 56 | BeginTime, FileTime: Double;
|
---|
| 57 | Step: Integer;
|
---|
| 58 | LevelID: Integer;
|
---|
| 59 | TimeFormat: TFormatSettings;
|
---|
[93] | 60 |
|
---|
[112] | 61 | ConID: Integer;
|
---|
| 62 | Connection: TDataAccess;
|
---|
| 63 | ConRepMsg: TStatusMessages;
|
---|
[93] | 64 |
|
---|
[120] | 65 | FileID: Integer;
|
---|
| 66 |
|
---|
[112] | 67 | Strings: TStrings;
|
---|
| 68 | i, j: Integer;
|
---|
[113] | 69 | temps: String;
|
---|
[120] | 70 | tempi: Integer;
|
---|
| 71 | tempb: Byte;
|
---|
[113] | 72 | FileInfo: TFileInfo;
|
---|
[120] | 73 | DatLinks: TDatLinkList;
|
---|
| 74 | RawLinks: TRawDataList;
|
---|
[113] | 75 |
|
---|
| 76 | DatFileStream, RawFileStream: TMemoryStream;
|
---|
[93] | 77 | const
|
---|
[112] | 78 | Steps: Byte = 3;
|
---|
[93] | 79 |
|
---|
| 80 |
|
---|
[112] | 81 | procedure DoStep(StepName: String);
|
---|
[93] | 82 | begin
|
---|
[112] | 83 | Inc(Step);
|
---|
| 84 | if StepName <> 'FIN' then
|
---|
[93] | 85 | group_progress.Caption :=
|
---|
[112] | 86 | 'Creating Dat (Step ' + IntToStr(Step) + '/' + IntToStr(Steps) + ': ' + StepName + ')'
|
---|
[93] | 87 | else
|
---|
| 88 | group_progress.Caption := 'Creating Dat (FINISHED)';
|
---|
| 89 | end;
|
---|
| 90 |
|
---|
[138] | 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 |
|
---|
[93] | 119 | begin
|
---|
| 120 |
|
---|
| 121 | //
|
---|
| 122 | // FILE EXISTS CHECK FÜR DAT/RAW/SEP!!!
|
---|
| 123 | //
|
---|
| 124 |
|
---|
[112] | 125 | TimeFormat.ShortTimeFormat := 'hh:nn:ss';
|
---|
| 126 | TimeFormat.LongTimeFormat := 'hh:nn:ss';
|
---|
| 127 | TimeFormat.TimeSeparator := ':';
|
---|
[93] | 128 |
|
---|
[112] | 129 | ConID := ConManager.OpenConnection(Source, ConRepMsg);
|
---|
| 130 | if not (ConRepMsg in [SM_OK, SM_AlreadyOpened]) then
|
---|
[93] | 131 | begin
|
---|
[112] | 132 | ShowMessage('Source-file couldn''t be opened! Aborting' + CrLf + GetOpenMsg(ConRepMsg));
|
---|
[93] | 133 | Exit;
|
---|
[112] | 134 | end else
|
---|
| 135 | Connection := ConManager.Connection[ConID];
|
---|
[93] | 136 |
|
---|
[112] | 137 | ConID := ConManager.FileOpened(Target);
|
---|
| 138 | if ConID >= 0 then
|
---|
[93] | 139 | begin
|
---|
[112] | 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;
|
---|
[93] | 154 | end;
|
---|
| 155 |
|
---|
[112] | 156 | if FileExists(Target) then
|
---|
[93] | 157 | begin
|
---|
[112] | 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;
|
---|
[131] | 166 | end;
|
---|
| 167 | if FileExists(AnsiReplaceStr(Target, '.dat', '.raw')) then
|
---|
| 168 | if not DeleteFile(AnsiReplaceStr(Target, '.dat', '.raw')) then
|
---|
[130] | 169 | begin
|
---|
| 170 | ShowMessage('Couldn''t delete file. Aborting');
|
---|
| 171 | Exit;
|
---|
| 172 | end;
|
---|
[131] | 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;
|
---|
[112] | 180 | end else begin
|
---|
| 181 | ShowMessage('Aborting');
|
---|
| 182 | Exit;
|
---|
| 183 | end;
|
---|
[93] | 184 | end;
|
---|
[112] | 185 |
|
---|
| 186 | LevelID := Connection.LevelNumber;
|
---|
| 187 | LevelID := (LevelID * 2) * 256 * 256 * 256 + $01;
|
---|
[93] | 188 |
|
---|
| 189 | Self.Visible := True;
|
---|
| 190 | Form_Main.Visible := False;
|
---|
[112] | 191 | Step := 0;
|
---|
| 192 | Converting := True;
|
---|
| 193 | Abort := False;
|
---|
[93] | 194 | btn_abortok.Caption := '&Abort...';
|
---|
| 195 | btn_abortok.Default := False;
|
---|
[112] | 196 | BeginTime := Time;
|
---|
[93] | 197 |
|
---|
| 198 | Stream_Body := TMemoryStream.Create;
|
---|
| 199 | Stream_Names := TMemoryStream.Create;
|
---|
[112] | 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);
|
---|
[93] | 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 |
|
---|
[112] | 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 |
|
---|
[113] | 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;
|
---|
[93] | 238 | DatHeader.NamedFiles := Length(NamedFilesHeader);
|
---|
[113] | 239 |
|
---|
| 240 | Strings := Connection.GetExtensionsList(EF_ExtCount);
|
---|
| 241 |
|
---|
| 242 | DatHeader.Extensions := Strings.Count;
|
---|
[93] | 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 |
|
---|
[112] | 252 |
|
---|
[93] | 253 | DoStep('Writing extensions-header');
|
---|
[113] | 254 | progress.Max := Strings.Count;
|
---|
[93] | 255 | Application.ProcessMessages;
|
---|
[113] | 256 | for i := 0 to Strings.Count - 1 do
|
---|
[93] | 257 | begin
|
---|
[113] | 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);
|
---|
[93] | 264 | for j := 0 to 3 do
|
---|
[113] | 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;
|
---|
[93] | 281 | progress.Position := i + 1;
|
---|
| 282 | lbl_progress.Caption := 'Extensions done: ' + IntToStr(i + 1) + '/' +
|
---|
[113] | 283 | IntToStr(Strings.Count);
|
---|
[93] | 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 |
|
---|
[113] | 294 | FileTime := Time;
|
---|
[120] | 295 | for FileID := 0 to DatHeader.Files - 1 do
|
---|
[93] | 296 | begin
|
---|
[120] | 297 | FileInfo := Connection.GetFileInfo(FileID);
|
---|
[93] | 298 | for j := 0 to 3 do
|
---|
[120] | 299 | FilesHeader[FileID].Extension[j] := FileInfo.Extension[4 - j];
|
---|
[113] | 300 | if FileInfo.Size > 0 then
|
---|
[93] | 301 | begin
|
---|
[120] | 302 | FilesHeader[FileID].DataAddr := Stream_Body.Size + 8;
|
---|
[113] | 303 | DatFileStream := TMemoryStream.Create;
|
---|
[120] | 304 | Connection.LoadDatFile(FileID, TStream(DatFileStream));
|
---|
[133] | 305 | DatFileStream.Seek(0, soFromBeginning);
|
---|
[137] | 306 | tempi := FileID * 256 + 1;
|
---|
| 307 | DatFileStream.Write(tempi, 4);
|
---|
[113] | 308 | DatFileStream.Write(LevelID, 4);
|
---|
[93] | 309 |
|
---|
[120] | 310 | DatLinks := Connection.GetDatLinks(FileID);
|
---|
| 311 | if Length(DatLinks) > 0 then
|
---|
[93] | 312 | begin
|
---|
[120] | 313 | for i := 0 to High(DatLinks) do
|
---|
[93] | 314 | begin
|
---|
[120] | 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
|
---|
[93] | 330 | begin
|
---|
[120] | 331 | RawFileStream := TMemoryStream.Create;
|
---|
[127] | 332 | Connection.LoadRawFile(FileID, RawLinks[i].SrcOffset, TStream(RawFileStream));
|
---|
| 333 | RawFileStream.Seek(0, soFromBeginning);
|
---|
| 334 | if RawLinks[i].LocSep then
|
---|
[120] | 335 | begin
|
---|
[127] | 336 | RawLinks[i].RawAddr := Stream_Sep.Size;
|
---|
| 337 | Stream_sep.CopyFrom(RawFileStream, RawFileStream.Size);
|
---|
[120] | 338 | end else begin
|
---|
[127] | 339 | RawLinks[i].RawAddr := Stream_Raw.Size;
|
---|
| 340 | Stream_Raw.CopyFrom(RawFileStream, RawFileStream.Size);
|
---|
[120] | 341 | end;
|
---|
| 342 | end else
|
---|
| 343 | RawLinks[i].RawAddr := 0;
|
---|
[129] | 344 | DatFileStream.Seek(RawLinks[i].SrcOffset, soFromBeginning);
|
---|
| 345 | DatFileStream.Write(RawLinks[i].RawAddr, 4);
|
---|
[120] | 346 | end;
|
---|
| 347 | end;
|
---|
[129] | 348 | DatFileStream.Seek(0, soFromBeginning);
|
---|
| 349 | Stream_Body.CopyFrom(DatFileStream, DatFileStream.Size);
|
---|
[93] | 350 | end
|
---|
| 351 | else
|
---|
[134] | 352 | FilesHeader[FileID].DataAddr := 0;
|
---|
[93] | 353 | if Length(fileinfo.Name) > 0 then
|
---|
| 354 | begin
|
---|
[134] | 355 | FilesHeader[FileID].NameAddr := Stream_Names.Size;
|
---|
[93] | 356 | temps := fileinfo.Extension + fileinfo.Name + Chr(0);
|
---|
| 357 | Stream_Names.Write(temps[1], Length(temps));
|
---|
| 358 | end
|
---|
| 359 | else
|
---|
[134] | 360 | FilesHeader[FileID].NameAddr := 0;
|
---|
| 361 | FilesHeader[FileID].FileSize := fileinfo.Size;
|
---|
| 362 | FilesHeader[FileID].FileType := fileinfo.FileType;
|
---|
[93] | 363 |
|
---|
[130] | 364 | if ((FileID mod 10) = 0) and (FileID >= 100) then
|
---|
[93] | 365 | lbl_estimation.Caption := 'Estimated time left: ' + TimeToStr(
|
---|
[130] | 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);
|
---|
[93] | 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;
|
---|
[133] | 383 |
|
---|
[93] | 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;
|
---|
[129] | 397 |
|
---|
| 398 | if Connection.DataOS in [DOS_WINDEMO, DOS_MAC, DOS_MACBETA] then
|
---|
[93] | 399 | Stream_Sep.Free;
|
---|
| 400 |
|
---|
| 401 | progress.Position := progress.Max;
|
---|
| 402 | lbl_progress.Caption := 'Files done: ' + IntToStr(progress.Max) + '/' +
|
---|
| 403 | IntToStr(progress.Max);
|
---|
[113] | 404 | lbl_estimation.Caption := 'FINISHED (duration: ' + TimeToStr(Time - Begintime, TimeFormat) + ')';
|
---|
[93] | 405 |
|
---|
| 406 | DoStep('FIN');
|
---|
| 407 | btn_abortok.Caption := '&OK';
|
---|
| 408 | btn_abortok.Default := True;
|
---|
| 409 |
|
---|
| 410 | converting := False;
|
---|
| 411 |
|
---|
[129] | 412 | // CloseDataConnection(DataConnections[conIndex]);
|
---|
[93] | 413 | end;
|
---|
| 414 |
|
---|
| 415 |
|
---|
| 416 |
|
---|
| 417 |
|
---|
| 418 | procedure TForm_LevelDB.CreateDatabase(Source, target: String);
|
---|
[134] | 419 | var
|
---|
| 420 | DataBase: TABSDatabase;
|
---|
[138] | 421 | Query: TABSQuery;
|
---|
| 422 | MimeCoder: TStringFormat_MIME64;
|
---|
[112] | 423 |
|
---|
[138] | 424 | BeginTime, FileTime: Double;
|
---|
| 425 | Step: Integer;
|
---|
| 426 | TimeFormat: TFormatSettings;
|
---|
[93] | 427 |
|
---|
[138] | 428 | ConID: Integer;
|
---|
| 429 | Connection: TDataAccess;
|
---|
| 430 | ConRepMsg: TStatusMessages;
|
---|
[93] | 431 |
|
---|
[138] | 432 | FileID: Integer;
|
---|
[93] | 433 |
|
---|
[138] | 434 | i: Integer;
|
---|
| 435 | temps: String;
|
---|
| 436 | tempdata: TByteData;
|
---|
| 437 | FileInfo: TFileInfo;
|
---|
| 438 | DatLinks: TDatLinkList;
|
---|
| 439 | RawLinks: TRawDataList;
|
---|
| 440 | const
|
---|
| 441 | steps: Byte = 2;
|
---|
[93] | 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 |
|
---|
[138] | 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 |
|
---|
[93] | 470 | begin
|
---|
[138] | 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
|
---|
[93] | 482 | begin
|
---|
[138] | 483 | ShowMessage('Source-file couldn''t be opened! Aborting' + CrLf + GetOpenMsg(ConRepMsg));
|
---|
[93] | 484 | Exit;
|
---|
[138] | 485 | end else
|
---|
| 486 | Connection := ConManager.Connection[ConID];
|
---|
| 487 |
|
---|
| 488 | ConID := ConManager.FileOpened(Target);
|
---|
| 489 | if ConID >= 0 then
|
---|
[93] | 490 | begin
|
---|
[138] | 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;
|
---|
[93] | 505 | end;
|
---|
| 506 |
|
---|
[138] | 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;
|
---|
[93] | 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 |
|
---|
[138] | 532 | BeginTime := Time;
|
---|
[93] | 533 |
|
---|
| 534 | DataBase := TABSDatabase.Create(Self);
|
---|
[134] | 535 | DataBase.MaxConnections := 1;
|
---|
[136] | 536 | DataBase.PageSize := 8112;
|
---|
| 537 | DataBase.PageCountInExtent := 8;
|
---|
[138] | 538 |
|
---|
[93] | 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 :=
|
---|
[136] | 552 | 'CREATE TABLE globals ( id AUTOINC PRIMARY KEY, name STRING(128), ' +
|
---|
| 553 | 'value STRING(128) );';
|
---|
[93] | 554 | Query.ExecSQL;
|
---|
| 555 | Query.SQL.Text :=
|
---|
[136] | 556 | 'CREATE TABLE linkmap ( id AUTOINC PRIMARY KEY, src_id INTEGER, ' +
|
---|
[141] | 557 | 'src_link_offset INTEGER, target_id INTEGER);';
|
---|
[93] | 558 | Query.ExecSQL;
|
---|
[141] | 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;
|
---|
[93] | 563 | Query.SQL.Text :=
|
---|
[136] | 564 | 'CREATE TABLE rawmap ( id AUTOINC PRIMARY KEY, src_id INTEGER, ' +
|
---|
| 565 | 'src_link_offset INTEGER, sep BOOLEAN, size INTEGER, ' +
|
---|
[141] | 566 | 'data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib);';
|
---|
[93] | 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;
|
---|
[141] | 569 | Query.SQL.Text := 'CREATE INDEX idsrcid ON rawmap (src_id);';
|
---|
| 570 | Query.ExecSQL;
|
---|
[93] | 571 | Query.SQL.Text :=
|
---|
[136] | 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 );';
|
---|
[93] | 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;
|
---|
[136] | 577 | // Query.SQL.Text :=
|
---|
| 578 | // 'CREATE TABLE extlist ( id AUTOINC PRIMARY KEY, ext CHAR(4), ident CHAR(16) );';
|
---|
| 579 | // Query.ExecSQL;
|
---|
[93] | 580 |
|
---|
| 581 | Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("dbversion","' +
|
---|
| 582 | dbversion + '");';
|
---|
| 583 | Query.ExecSQL;
|
---|
[138] | 584 |
|
---|
[93] | 585 | Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("lvl","' +
|
---|
[138] | 586 | IntToStr(Connection.LevelNumber) + '");';
|
---|
[93] | 587 | Query.ExecSQL;
|
---|
[138] | 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 + '");';
|
---|
[93] | 595 | Query.ExecSQL;
|
---|
| 596 |
|
---|
| 597 | progress.Position := 0;
|
---|
| 598 | lbl_progress.Caption := 'Files done: ' + IntToStr(0) + '/' + IntToStr(
|
---|
[138] | 599 | Connection.GetFileCount);
|
---|
[93] | 600 | lbl_estimation.Caption := 'Estimated finishing time: unknown';
|
---|
| 601 |
|
---|
[138] | 602 | progress.Max := Connection.GetFileCount;
|
---|
[93] | 603 | begintime := Time;
|
---|
| 604 | DoStep('Writing .dat-fileslist');
|
---|
| 605 | Application.ProcessMessages;
|
---|
| 606 |
|
---|
[142] | 607 | FileTime := Time;
|
---|
[93] | 608 | Database.StartTransaction;
|
---|
[138] | 609 | for FileID := 0 to Connection.GetFileCount - 1 do
|
---|
[93] | 610 | begin
|
---|
[138] | 611 | fileinfo := Connection.GetFileInfo(FileID);
|
---|
[93] | 612 | if (fileinfo.FileType and $02) = 0 then
|
---|
| 613 | begin
|
---|
| 614 | mimecoder := TStringFormat_MIME64.Create;
|
---|
[138] | 615 | Connection.LoadDatFile(FileID, tempdata);
|
---|
[93] | 616 | Query.SQL.Text :=
|
---|
| 617 | 'INSERT INTO datfiles (id,extension,name,contenttype,size,data) VALUES (' +
|
---|
[138] | 618 | IntToStr(FileID) + ',"' + fileinfo.Extension + '","' + fileinfo.Name + '","' + IntToHex(
|
---|
[93] | 619 | fileinfo.FileType, 8) + '",' + IntToStr(fileinfo.Size) + ',MimeToBin("' +
|
---|
[138] | 620 | MimeCoder.StrTo(@tempdata[0], Length(tempdata)) + '") );';
|
---|
[93] | 621 | Query.ExecSQL;
|
---|
| 622 | mimecoder.Free;
|
---|
| 623 |
|
---|
[138] | 624 | RawLinks := Connection.GetRawList(FileID);
|
---|
| 625 | if Length(RawLinks) > 0 then
|
---|
[93] | 626 | begin
|
---|
[138] | 627 | for i := 0 to High(RawLinks) do
|
---|
[93] | 628 | begin
|
---|
[138] | 629 | if RawLinks[i].RawSize > 0 then
|
---|
[93] | 630 | begin
|
---|
[138] | 631 | SetLength(tempdata, RawLinks[i].RawSize);
|
---|
| 632 | Connection.LoadRawFile(FileID, RawLinks[i].SrcOffset, tempdata);
|
---|
[93] | 633 | mimecoder := TStringFormat_MIME64.Create;
|
---|
| 634 | Query.SQL.Text :=
|
---|
| 635 | 'INSERT INTO rawmap (src_id,src_link_offset,sep,size,data) VALUES (' +
|
---|
[138] | 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) + '") );';
|
---|
[93] | 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 (' +
|
---|
[138] | 647 | IntToStr(FileID) + ', ' + IntToStr(RawLinks[i].SrcOffset) + ', ' +
|
---|
| 648 | BoolToStr(RawLinks[i].LocSep) + ', 0);';
|
---|
[93] | 649 | Query.ExecSQL;
|
---|
| 650 | end;
|
---|
| 651 | end;
|
---|
| 652 | end;
|
---|
| 653 |
|
---|
[138] | 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;
|
---|
[93] | 666 | end
|
---|
| 667 | else
|
---|
| 668 | begin
|
---|
| 669 | Query.SQL.Text :=
|
---|
| 670 | 'INSERT INTO datfiles (id,extension,name,contenttype,size) VALUES (' +
|
---|
[138] | 671 | IntToStr(FileID) + ', "' + fileinfo.Extension + '", ' +
|
---|
| 672 | '"' + fileinfo.Name + '", "' + IntToHex(fileinfo.FileType, 8) + '", 0);';
|
---|
[93] | 673 | Query.ExecSQL;
|
---|
| 674 | end;
|
---|
[138] | 675 | if ((FileID mod 100) = 0) and (FileID > 0) then
|
---|
[93] | 676 | begin
|
---|
| 677 | Database.Commit(False);
|
---|
| 678 | Database.StartTransaction;
|
---|
| 679 | end;
|
---|
[138] | 680 | if ((FileID mod 10) = 0) and (FileID >= 100) then
|
---|
[93] | 681 | lbl_estimation.Caption := 'Estimated time left: ' + TimeToStr(
|
---|
[142] | 682 | (Time - FileTime) / FileID * (progress.Max - FileID + 1) * 1.1, timeformat );
|
---|
[138] | 683 | progress.Position := FileID;
|
---|
| 684 | lbl_progress.Caption := 'Files done: ' + IntToStr(FileID) + '/' + IntToStr(progress.Max);
|
---|
[93] | 685 | Application.ProcessMessages;
|
---|
| 686 | if abort then
|
---|
| 687 | begin
|
---|
[138] | 688 | StopConvert;
|
---|
[93] | 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 |
|
---|
[138] | 697 | lbl_estimation.Caption := 'FINISHED (duration: ' + TimeToStr(Time - BeginTime, timeformat) + ')';
|
---|
[93] | 698 |
|
---|
| 699 | DoStep('FIN');
|
---|
| 700 | btn_abortok.Caption := '&OK';
|
---|
| 701 | btn_abortok.Default := True;
|
---|
| 702 |
|
---|
| 703 | converting := False;
|
---|
| 704 |
|
---|
[138] | 705 | Query.Close;
|
---|
| 706 | Query.Free;
|
---|
| 707 | DataBase.Close;
|
---|
| 708 | DataBase.Free;
|
---|
[93] | 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 |
|
---|
[138] | 731 | end.
|
---|