| 1 | unit Extractor; | 
 
 
 
 
 | 2 | interface | 
 
 
 
 
 | 3 | uses | 
 
 
 
 
 | 4 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, | 
 
 
 
 
 | 5 | Dialogs, Template, StdCtrls, ExtCtrls, ComCtrls, Menus, Buttons; | 
 
 
 
 
 | 6 |  | 
 
 
 
 
 | 7 | type | 
 
 
 
 
 | 8 | TForm_Extractor = class(TForm_ToolTemplate) | 
 
 
 
 
 | 9 | group_extract: TGroupBox; | 
 
 
 
 
 | 10 | group_singlefiles: TGroupBox; | 
 
 
 
 
 | 11 | btn_sel_dat: TButton; | 
 
 
 
 
 | 12 | btn_sel_datraw: TButton; | 
 
 
 
 
 | 13 | btn_sel_datraw_convert: TButton; | 
 
 
 
 
 | 14 | btn_all_dat: TButton; | 
 
 
 
 
 | 15 | btn_all_datraw: TButton; | 
 
 
 
 
 | 16 | btn_all_datraw_convert: TButton; | 
 
 
 
 
 | 17 | btn_sel_files_toone: TButton; | 
 
 
 
 
 | 18 | btn_all_files_toone: TButton; | 
 
 
 
 
 | 19 | group_onefile: TGroupBox; | 
 
 
 
 
 | 20 | group_progress: TGroupBox; | 
 
 
 
 
 | 21 | lbl_progress: TLabel; | 
 
 
 
 
 | 22 | lbl_estimated: TLabel; | 
 
 
 
 
 | 23 | progress: TProgressBar; | 
 
 
 
 
 | 24 | btn_abort: TButton; | 
 
 
 
 
 | 25 | saved: TSaveDialog; | 
 
 
 
 
 | 26 | procedure FormCreate(Sender: TObject); | 
 
 
 
 
 | 27 | procedure Extract(Sender: TObject); | 
 
 
 
 
 | 28 | procedure btn_abortClick(Sender: TObject); | 
 
 
 
 
 | 29 | private | 
 
 
 
 
 | 30 | public | 
 
 
 
 
 | 31 | end; | 
 
 
 
 
 | 32 |  | 
 
 
 
 
 | 33 | var | 
 
 
 
 
 | 34 | Form_Extractor: TForm_Extractor; | 
 
 
 
 
 | 35 |  | 
 
 
 
 
 | 36 | implementation | 
 
 
 
 
 | 37 | {$R *.dfm} | 
 
 
 
 
 | 38 | uses Main, Functions, Data, OniDataClass; | 
 
 
 
 
 | 39 |  | 
 
 
 
 
 | 40 | procedure TForm_Extractor.FormCreate(Sender: TObject); | 
 
 
 
 
 | 41 | begin | 
 
 
 
 
 | 42 | inherited; | 
 
 
 
 
 | 43 | Self.AllowMultiSelect := True; | 
 
 
 
 
 | 44 |  | 
 
 
 
 
 | 45 | btn_sel_dat.Caption    := 'Selected files' + CrLf + '(dat contents only)'; | 
 
 
 
 
 | 46 | btn_sel_datraw.Caption := 'Selected files' + CrLf + '(dat+raw contents)'; | 
 
 
 
 
 | 47 | btn_sel_datraw_convert.Caption := | 
 
 
 
 
 | 48 | 'Selected files' + CrLf + '(dat+raw contents)' + CrLf + '(with convert if possible)'; | 
 
 
 
 
 | 49 | btn_all_dat.Caption    := 'All files in list' + CrLf + '(dat contents only)'; | 
 
 
 
 
 | 50 | btn_all_datraw.Caption := 'All files in list' + CrLf + '(dat+raw contents)'; | 
 
 
 
 
 | 51 | btn_all_datraw_convert.Caption := | 
 
 
 
 
 | 52 | 'All files in list' + CrLf + '(dat+raw contents)' + CrLf + '(with convert if possible)'; | 
 
 
 
 
 | 53 | btn_sel_files_toone.Caption := 'Selected files' + CrLf + '(dat contents only)'; | 
 
 
 
 
 | 54 | btn_all_files_toone.Caption := 'All files in list' + CrLf + '(dat contents only)'; | 
 
 
 
 
 | 55 | end; | 
 
 
 
 
 | 56 |  | 
 
 
 
 
 | 57 | procedure TForm_Extractor.btn_abortClick(Sender: TObject); | 
 
 
 
 
 | 58 | begin | 
 
 
 
 
 | 59 | ShowMessage('X'); | 
 
 
 
 
 | 60 | end; | 
 
 
 
 
 | 61 |  | 
 
 
 
 
 | 62 | procedure TForm_Extractor.Extract(Sender: TObject); | 
 
 
 
 
 | 63 | var | 
 
 
 
 
 | 64 | sel_only:  Boolean; | 
 
 
 
 
 | 65 | dat_only:  Boolean; | 
 
 
 
 
 | 66 | convert:   Boolean; | 
 
 
 
 
 | 67 | one_file:  Boolean; | 
 
 
 
 
 | 68 | settings:  TExportSet; | 
 
 
 
 
 | 69 | files:     LongWord; | 
 
 
 
 
 | 70 | i, done:   LongWord; | 
 
 
 
 
 | 71 | begintime: Double; | 
 
 
 
 
 | 72 | begin | 
 
 
 
 
 | 73 | sel_only := Pos('sel', TButton(Sender).Name) > 0; | 
 
 
 
 
 | 74 | dat_only := not (Pos('datraw', TButton(Sender).Name) > 0); | 
 
 
 
 
 | 75 | convert  := Pos('convert', TButton(Sender).Name) > 0; | 
 
 
 
 
 | 76 | one_file := Pos('toone', TButton(Sender).Name) > 0; | 
 
 
 
 
 | 77 | if dat_only then | 
 
 
 
 
 | 78 | settings := [DO_dat] | 
 
 
 
 
 | 79 | else | 
 
 
 
 
 | 80 | settings := [DO_dat, DO_raw]; | 
 
 
 
 
 | 81 | if convert then | 
 
 
 
 
 | 82 | settings := settings + [DO_convert]; | 
 
 
 
 
 | 83 | if one_file then | 
 
 
 
 
 | 84 | settings := settings + [DO_toone]; | 
 
 
 
 
 | 85 | progress.Position := 0; | 
 
 
 
 
 | 86 |  | 
 
 
 
 
 | 87 | if saved.Execute then | 
 
 
 
 
 | 88 | begin | 
 
 
 
 
 | 89 | begintime := Time; | 
 
 
 
 
 | 90 | group_progress.Visible := True; | 
 
 
 
 
 | 91 | panel_files.Enabled := False; | 
 
 
 
 
 | 92 | group_singlefiles.Enabled := False; | 
 
 
 
 
 | 93 | group_onefile.Enabled := False; | 
 
 
 
 
 | 94 | lbl_estimated.Caption := 'Estimated finishing time: unknown'; | 
 
 
 
 
 | 95 | if one_file then | 
 
 
 
 
 | 96 | begin | 
 
 
 
 
 | 97 | if FileExists(saved.FileName) then | 
 
 
 
 
 | 98 | begin | 
 
 
 
 
 | 99 | if MessageBox(Self.Handle, PChar( | 
 
 
 
 
 | 100 | 'File already exists. Do you want to overwrite it?'), PChar('Warning!'), MB_YESNO) = | 
 
 
 
 
 | 101 | ID_YES then | 
 
 
 
 
 | 102 | begin | 
 
 
 
 
 | 103 | DeleteFile(saved.FileName); | 
 
 
 
 
 | 104 | end | 
 
 
 
 
 | 105 | else | 
 
 
 
 
 | 106 | begin | 
 
 
 
 
 | 107 | group_progress.Visible    := False; | 
 
 
 
 
 | 108 | panel_files.Enabled      := True; | 
 
 
 
 
 | 109 | group_singlefiles.Enabled := True; | 
 
 
 
 
 | 110 | group_onefile.Enabled     := True; | 
 
 
 
 
 | 111 | Exit; | 
 
 
 
 
 | 112 | end; | 
 
 
 
 
 | 113 | end; | 
 
 
 
 
 | 114 | i := FileCreate(saved.FileName); | 
 
 
 
 
 | 115 | FileClose(i); | 
 
 
 
 
 | 116 | i := 0; | 
 
 
 
 
 | 117 | end; | 
 
 
 
 
 | 118 | if sel_only then | 
 
 
 
 
 | 119 | begin | 
 
 
 
 
 | 120 | files := filelist.SelCount; | 
 
 
 
 
 | 121 | lbl_progress.Caption := 'Files done: 0/' + IntToStr(files); | 
 
 
 
 
 | 122 | progress.Max := files; | 
 
 
 
 
 | 123 | done  := 0; | 
 
 
 
 
 | 124 | for i := 0 to filelist.Count - 1 do | 
 
 
 
 
 | 125 | begin | 
 
 
 
 
 | 126 | if filelist.Selected[i] then | 
 
 
 
 
 | 127 | begin | 
 
 
 
 
 | 128 | if one_file then | 
 
 
 
 
 | 129 | begin | 
 
 
 
 
 | 130 | ExportFile(OniDataConnection.ExtractFileID( | 
 
 
 
 
 | 131 | filelist.Items.Strings[filelist.ItemIndex]), ExtractFileName(saved.FileName), | 
 
 
 
 
 | 132 | settings, ExtractFileDir(saved.FileName)); | 
 
 
 
 
 | 133 | end | 
 
 
 
 
 | 134 | else | 
 
 
 
 
 | 135 | begin | 
 
 
 
 
 | 136 | ExportFile(OniDataConnection.ExtractFileID( | 
 
 
 
 
 | 137 | filelist.Items.Strings[filelist.ItemIndex]), filelist.Items.Strings[i], settings, 'D:'); | 
 
 
 
 
 | 138 | end; | 
 
 
 
 
 | 139 | Inc(done); | 
 
 
 
 
 | 140 | end; | 
 
 
 
 
 | 141 | if ((done mod 10) = 0) and (done >= 50) then | 
 
 
 
 
 | 142 | lbl_estimated.Caption := 'Estimated finishing time: ' + TimeToStr( | 
 
 
 
 
 | 143 | (Time - begintime) / done * files + begintime); | 
 
 
 
 
 | 144 | if (i mod 10) = 0 then | 
 
 
 
 
 | 145 | begin | 
 
 
 
 
 | 146 | progress.Position    := done; | 
 
 
 
 
 | 147 | lbl_progress.Caption := 'Files done: ' + IntToStr(done) + '/' + IntToStr(files); | 
 
 
 
 
 | 148 | Application.ProcessMessages; | 
 
 
 
 
 | 149 | end; | 
 
 
 
 
 | 150 | end; | 
 
 
 
 
 | 151 | end | 
 
 
 
 
 | 152 | else | 
 
 
 
 
 | 153 | begin | 
 
 
 
 
 | 154 | files := filelist.Count; | 
 
 
 
 
 | 155 | lbl_progress.Caption := 'Files done: 0/' + IntToStr(files); | 
 
 
 
 
 | 156 | progress.Max := files; | 
 
 
 
 
 | 157 | for i := 0 to filelist.Count - 1 do | 
 
 
 
 
 | 158 | begin | 
 
 
 
 
 | 159 | if one_file then | 
 
 
 
 
 | 160 | begin | 
 
 
 
 
 | 161 | ExportFile(OniDataConnection.ExtractFileID( | 
 
 
 
 
 | 162 | filelist.Items.Strings[filelist.ItemIndex]), ExtractFileName(saved.FileName), | 
 
 
 
 
 | 163 | settings, ExtractFileDir(saved.FileName)); | 
 
 
 
 
 | 164 | end | 
 
 
 
 
 | 165 | else | 
 
 
 
 
 | 166 | begin | 
 
 
 
 
 | 167 | ExportFile(OniDataConnection.ExtractFileID( | 
 
 
 
 
 | 168 | filelist.Items.Strings[filelist.ItemIndex]), filelist.Items.Strings[i], settings, 'D:'); | 
 
 
 
 
 | 169 | end; | 
 
 
 
 
 | 170 | if ((i mod 10) = 0) and (i >= 50) then | 
 
 
 
 
 | 171 | lbl_estimated.Caption := 'Estimated finishing time: ' + TimeToStr( | 
 
 
 
 
 | 172 | (Time - begintime) / i * files + begintime); | 
 
 
 
 
 | 173 | if (i mod 5) = 0 then | 
 
 
 
 
 | 174 | begin | 
 
 
 
 
 | 175 | progress.Position    := i; | 
 
 
 
 
 | 176 | lbl_progress.Caption := 'Files done: ' + IntToStr(i) + '/' + IntToStr(files); | 
 
 
 
 
 | 177 | Application.ProcessMessages; | 
 
 
 
 
 | 178 | end; | 
 
 
 
 
 | 179 | end; | 
 
 
 
 
 | 180 | end; | 
 
 
 
 
 | 181 | group_progress.Visible    := False; | 
 
 
 
 
 | 182 | panel_files.Enabled      := True; | 
 
 
 
 
 | 183 | group_singlefiles.Enabled := True; | 
 
 
 
 
 | 184 | group_onefile.Enabled     := True; | 
 
 
 
 
 | 185 | end; | 
 
 
 
 
 | 186 | end; | 
 
 
 
 
 | 187 |  | 
 
 
 
 
 | 188 | begin | 
 
 
 
 
 | 189 | AddToolListEntry('extractor', 'Extractor', ''); | 
 
 
 
 
 | 190 | end. |