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