Changeset 112 for oup/current/Helper
- Timestamp:
- Feb 22, 2007, 1:37:39 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
oup/current/Helper/LevelDB.pas
r105 r112 1 unit Helper_LevelDB;1 unit LevelDB; 2 2 3 3 interface … … 16 16 procedure btn_abortokClick(Sender: TObject); 17 17 private 18 procedure HandleFile( ext: String; fileid: Integer; dir_dat2db: Boolean);19 procedure stop_convert;18 procedure HandleFile(Ext: String; FileID: Integer); 19 procedure StopConvert; 20 20 public 21 21 procedure CreateDatabase(Source, Target: String); … … 31 31 {$R *.dfm} 32 32 33 uses ABSMain, ABSDecUtil, Main, Functions, Data, OniImgClass, DataStructures, ConnectionManager; 33 uses ABSMain, ABSDecUtil, Main, 34 ConnectionManager, TypeDefs, DataAccess, OniImgClass; 34 35 35 36 type 36 THandler = procedure(fileid: LongWord; dir_dat2db: Boolean); 37 38 TConvertHandlers = record 37 THandler = procedure(FileID: Integer); 38 TConvertHandler = record 39 39 Ext: String[4]; 40 needed: Boolean;41 40 Handler: THandler; 42 41 end; 43 42 44 43 var 45 ConvertHandlers: array of TConvertHandlers; 46 loaded_filename: String; 47 converting: Boolean = False; 48 abort: Boolean = False; 49 DataBase: TABSDatabase; 50 Query: TABSQuery; 51 MimeCoder: TStringFormat_MIME64; 52 53 var 54 DatHeader: THeader; 55 FilesHeader: TFilesMap; 44 ConvertHandlers: array of TConvertHandler; 45 // loaded_filename: String; 46 Converting: Boolean = False; 47 Abort: Boolean = False; 48 49 50 function GetOpenMsg(msg: TStatusMessages): String; 51 begin 52 case msg of 53 SM_AlreadyOpened: Result := 'File already opened.'; 54 SM_FileNotFound: Result := 'File not found.'; 55 SM_UnknownExtension: Result := 'Unknown extension.'; 56 SM_IncompatibleFile: Result := 'Incompatible file format.'; 57 SM_UnknownError: Result := 'Unknown error.'; 58 end; 59 end; 60 61 62 procedure TForm_LevelDB.CreateLevel(Source, Target: String); 63 var 64 DatHeader: THeader; 65 FilesHeader: TFilesMap; 56 66 NamedFilesHeader: TNamedFilesMap; 57 67 ExtensionsHeader: TExtensionsMap; 58 Stream_Body, Stream_Names: TMemoryStream; 68 69 Stream_Body, Stream_Names: TMemoryStream; 59 70 Stream_Dat, Stream_Raw, Stream_Sep: TFileStream; 60 OniDataConnection: TOniData; 61 62 63 64 65 procedure TForm_LevelDB.CreateLevel(Source, target: String); 66 var 67 files: LongWord; 68 69 i, j: LongWord; 70 temps, temps2: String; 71 Data, rawdata: Tdata; 72 absolutebegintime, begintime: Double; 73 step: Byte; 74 rawlist: TRawList; 75 extlist: TExtensionsMap; 76 fileinfo: TFileInfo; 77 datlinks: TDatLinks; 78 OniImage: TOniImage; 79 levelid: LongWord; 80 timeformat: TFormatSettings; 81 82 conIndex: Integer; 83 connection: TOniData; 71 72 // FileCount: Integer; 73 // temps, temps2: String; 74 // Data, rawdata: Tdata; 75 BeginTime, FileTime: Double; 76 Step: Integer; 77 // rawlist: TRawDataList; 78 // extlist: TExtensionsMap; 79 // fileinfo: TFileInfo; 80 // datlinks: TDatLinks; 81 OniImage: TOniImage; 82 LevelID: Integer; 83 TimeFormat: TFormatSettings; 84 85 ConID: Integer; 86 Connection: TDataAccess; 87 ConRepMsg: TStatusMessages; 88 89 Strings: TStrings; 90 i, j: Integer; 84 91 const 85 steps: Byte = 3; 86 87 88 89 90 procedure DoStep(stepname: String); 91 begin 92 Inc(step); 93 if stepname <> 'FIN' then 92 Steps: Byte = 3; 93 94 95 procedure DoStep(StepName: String); 96 begin 97 Inc(Step); 98 if StepName <> 'FIN' then 94 99 group_progress.Caption := 95 'Creating Dat (Step ' + IntToStr( step) + '/' + IntToStr(steps) + ': ' + stepname + ')'100 'Creating Dat (Step ' + IntToStr(Step) + '/' + IntToStr(Steps) + ': ' + StepName + ')' 96 101 else 97 102 group_progress.Caption := 'Creating Dat (FINISHED)'; … … 104 109 // 105 110 106 timeformat.ShortTimeFormat := 'hh:nn:ss';107 timeformat.LongTimeFormat:= 'hh:nn:ss';108 timeformat.TimeSeparator:= ':';109 110 connection := ConnectionExists(target);111 if connection <> nilthen112 begin 113 ShowMessage(' Destination-file is opened, close it in order to proceed conversion?');111 TimeFormat.ShortTimeFormat := 'hh:nn:ss'; 112 TimeFormat.LongTimeFormat := 'hh:nn:ss'; 113 TimeFormat.TimeSeparator := ':'; 114 115 ConID := ConManager.OpenConnection(Source, ConRepMsg); 116 if not (ConRepMsg in [SM_OK, SM_AlreadyOpened]) then 117 begin 118 ShowMessage('Source-file couldn''t be opened! Aborting' + CrLf + GetOpenMsg(ConRepMsg)); 114 119 Exit; 115 end; 116 117 connection := ConnectionExists(source); 118 if connection <> nil then 119 begin 120 ShowMessage('Source-file is opened, close it in order to proceed conversion?'); 121 Exit; 122 end; 123 124 125 if CreateDataConnection(Source, ODB_ADB) = nil then 126 begin 127 ShowMessage('Could not connect to .oldb-file'); 128 Exit; 129 end; 130 levelid := OniDataConnection.LevelInfo.LevelNumber; 131 levelid := (levelid * 2) * 256 * 256 * 256 + $01; 120 end else 121 Connection := ConManager.Connection[ConID]; 122 123 ConID := ConManager.FileOpened(Target); 124 if ConID >= 0 then 125 begin 126 if MessageBox(Self.Handle, PChar('Destination-file is opened, close it in ' + 127 'order to proceed conversion?'), PChar('Destination-file opened'), 128 MB_YESNO + MB_ICONQUESTION) = ID_YES then 129 begin 130 if Form_Main.CheckConnectionCloseable(ConID) then 131 if not ConManager.CloseConnection(ConID, ConRepMsg) then 132 begin 133 ShowMessage('Couldn''t close destination-file. Aborting'); 134 Exit; 135 end; 136 end else begin 137 ShowMessage('Aborting'); 138 Exit; 139 end; 140 end; 141 142 if FileExists(Target) then 143 begin 144 if MessageBox(Self.Handle, PChar('Destination-file exists. ' + 145 'Overwrite it?'), PChar('Destination-file exists'), 146 MB_YESNO + MB_ICONWARNING) = ID_YES then 147 begin 148 if not DeleteFile(Target) then 149 begin 150 ShowMessage('Couldn''t delete file. Aborting'); 151 Exit; 152 end else if not DeleteFile(AnsiReplaceStr(Target, '.dat', '.raw')) then 153 begin 154 ShowMessage('Couldn''t delete file. Aborting'); 155 Exit; 156 end else if not DeleteFile(AnsiReplaceStr(Target, '.dat', '.sep')) then 157 begin 158 ShowMessage('Couldn''t delete file. Aborting'); 159 Exit; 160 end; 161 end else begin 162 ShowMessage('Aborting'); 163 Exit; 164 end; 165 end; 166 167 LevelID := Connection.LevelNumber; 168 LevelID := (LevelID * 2) * 256 * 256 * 256 + $01; 132 169 OniImage := TOniImage.Create; 133 134 absolutebegintime := Time;135 170 136 171 Self.Visible := True; 137 172 Form_Main.Visible := False; 138 step:= 0;139 converting := True;140 abort := False;173 Step := 0; 174 Converting := True; 175 Abort := False; 141 176 btn_abortok.Caption := '&Abort...'; 142 177 btn_abortok.Default := False; 143 absolutebegintime := Time;178 BeginTime := Time; 144 179 145 180 Stream_Body := TMemoryStream.Create; 146 181 Stream_Names := TMemoryStream.Create; 147 Stream_Dat := TFileStream.Create( target, fmCreate);148 Stream_Raw := TFileStream.Create(AnsiReplaceStr( target, '.dat', '.raw'), fmCreate);149 if OniDataConnection.OSisMacthen150 Stream_Sep := TFileStream.Create(AnsiReplaceStr( target, '.dat', '.sep'), fmCreate);182 Stream_Dat := TFileStream.Create(Target, fmCreate); 183 Stream_Raw := TFileStream.Create(AnsiReplaceStr(Target, '.dat', '.raw'), fmCreate); 184 if Connection.DataOS in [DOS_WINDEMO, DOS_MAC, DOS_MACBETA] then 185 Stream_Sep := TFileStream.Create(AnsiReplaceStr(Target, '.dat', '.sep'), fmCreate); 151 186 152 187 DoStep('Creating header'); … … 156 191 Application.ProcessMessages; 157 192 158 NamedFilesHeader := TOniDataADB(OniDataConnection).GetNamedFilesMap; 193 SetLength(NamedFilesHeader, 0); 194 Strings := TStringList.Create; 195 Strings := Connection.GetFilesList('', '', False, ST_ExtNameAsc); 196 for i := 0 to Strings.Count - 1 do 197 begin 198 if MidStr(Strings.Strings[i], 199 Pos('-', Strings.Strings[i]) + 1, 200 Length(Strings.Strings[i]) - 201 Pos('.', ReverseString(Strings.Strings[i])) - 202 Pos('-', Strings.Strings[i]) 203 ) <> '' then 204 begin 205 SetLength(NamedFilesHeader, Length(NamedFilesHeader) + 1); 206 NamedFilesHeader[High(NamedFilesHeader)].FileNumber := StrToInt(MidStr(Strings.Strings[i], 1, 5)); 207 NamedFilesHeader[High(NamedFilesHeader)].blubb := 0; 208 end; 209 end; 210 211 159 212 extlist := OniDataConnection.GetExtendedExtensionsList; 160 213 for i := 0 to High(DatHeader.Ident) do … … 172 225 SetLength(ExtensionsHeader, DatHeader.Extensions); 173 226 227 174 228 DoStep('Writing extensions-header'); 175 229 progress.Max := Length(OniDataConnection.GetExtensionsList); … … 190 244 Application.ProcessMessages; 191 245 end; 246 192 247 193 248 DoStep('Storing files-data'); … … 354 409 procedure TForm_LevelDB.CreateDatabase(Source, target: String); 355 410 var 411 DataBase: TABSDatabase; 412 Query: TABSQuery; 413 MimeCoder: TStringFormat_MIME64; 414 356 415 i, j: LongWord; 357 416 temps, temps2: String;
Note:
See TracChangeset
for help on using the changeset viewer.