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