--- oup/current/Tools/Extractor.pas 2006/12/23 16:26:43 46 +++ oup/current/Tools/Extractor.pas 2007/01/11 22:45:20 74 @@ -2,30 +2,30 @@ unit Extractor; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, - Dialogs, Template, StdCtrls, ExtCtrls, ComCtrls, Menus, Buttons; + Dialogs, Template, StdCtrls, ExtCtrls, ComCtrls, Menus, Buttons, StrUtils; type TForm_Extractor = class(TForm_ToolTemplate) group_extract: TGroupBox; - group_singlefiles: TGroupBox; - btn_sel_dat: TButton; - btn_sel_datraw: TButton; - btn_sel_datraw_convert: TButton; - btn_all_dat: TButton; - btn_all_datraw: TButton; - btn_all_datraw_convert: TButton; - btn_sel_files_toone: TButton; - btn_all_files_toone: TButton; - group_onefile: TGroupBox; + check_dat: TCheckBox; + check_raw: TCheckBox; + check_convert: TCheckBox; + radio_selected: TRadioButton; + label_export_sel: TLabel; + radio_all: TRadioButton; + label_path: TLabel; + edit_path: TEdit; + btn_path: TButton; + btn_export: TButton; group_progress: TGroupBox; lbl_progress: TLabel; lbl_estimated: TLabel; progress: TProgressBar; btn_abort: TButton; - saved: TSaveDialog; procedure FormCreate(Sender: TObject); - procedure Extract(Sender: TObject); procedure btn_abortClick(Sender: TObject); + procedure btn_pathClick(Sender: TObject); + procedure btn_exportClick(Sender: TObject); private public end; @@ -35,23 +35,14 @@ var implementation {$R *.dfm} -uses Main, Functions, Data, OniDataClass; +uses Main, Functions, Data, OniDataClass, FolderBrowser, Exporters; + procedure TForm_Extractor.FormCreate(Sender: TObject); begin inherited; Self.AllowMultiSelect := True; - - btn_sel_dat.Caption := 'Selected files' + CrLf + '(dat contents only)'; - btn_sel_datraw.Caption := 'Selected files' + CrLf + '(dat+raw contents)'; - btn_sel_datraw_convert.Caption := - 'Selected files' + CrLf + '(dat+raw contents)' + CrLf + '(with convert if possible)'; - btn_all_dat.Caption := 'All files in list' + CrLf + '(dat contents only)'; - btn_all_datraw.Caption := 'All files in list' + CrLf + '(dat+raw contents)'; - btn_all_datraw_convert.Caption := - 'All files in list' + CrLf + '(dat+raw contents)' + CrLf + '(with convert if possible)'; - btn_sel_files_toone.Caption := 'Selected files' + CrLf + '(dat contents only)'; - btn_all_files_toone.Caption := 'All files in list' + CrLf + '(dat contents only)'; + edit_path.Text := AppSettings.ExtractPath; end; procedure TForm_Extractor.btn_abortClick(Sender: TObject); @@ -59,132 +50,85 @@ begin ShowMessage('X'); end; -procedure TForm_Extractor.Extract(Sender: TObject); +procedure TForm_Extractor.btn_pathClick(Sender: TObject); var - sel_only: Boolean; - dat_only: Boolean; - convert: Boolean; - one_file: Boolean; - settings: TExportSet; + fb: TFolderBrowser; +begin + inherited; + + fb := TFolderBrowser.Create(Handle, 'Please select a folder where you want ' + + 'the files to be stored...', edit_path.Text, False, True); + if fb.Execute then + begin + edit_path.Text := fb.SelectedItem; + AppSettings.ExtractPath := edit_path.Text; + end; + fb.Free; +end; + +procedure TForm_Extractor.btn_exportClick(Sender: TObject); +var + begintime: Double; files: LongWord; i, done: LongWord; - begintime: Double; + selonly: Boolean; + fileid: LongWord; + filename: String; + path: String; begin - sel_only := Pos('sel', TButton(Sender).Name) > 0; - dat_only := not (Pos('datraw', TButton(Sender).Name) > 0); - convert := Pos('convert', TButton(Sender).Name) > 0; - one_file := Pos('toone', TButton(Sender).Name) > 0; - if dat_only then - settings := [DO_dat] - else - settings := [DO_dat, DO_raw]; - if convert then - settings := settings + [DO_convert]; - if one_file then - settings := settings + [DO_toone]; + inherited; + panel_files.Enabled := False; + group_extract.Enabled := False; + group_progress.Visible := True; + + path := edit_path.Text; + if not EndsText('\', path) then + path := path + '\'; + + begintime := Time; + lbl_estimated.Caption := 'Estimated finishing time: unknown'; progress.Position := 0; - if saved.Execute then + selonly := radio_selected.Checked; + + if selonly then + files := filelist.SelCount + else + files := filelist.Count; + + lbl_progress.Caption := 'Files done: 0/' + IntToStr(files); + progress.Max := files; + done := 0; + + for i := 0 to filelist.Count - 1 do begin - begintime := Time; - group_progress.Visible := True; - panel_files.Enabled := False; - group_singlefiles.Enabled := False; - group_onefile.Enabled := False; - lbl_estimated.Caption := 'Estimated finishing time: unknown'; - if one_file then + if (selonly and filelist.Selected[i]) or not selonly then begin - if FileExists(saved.FileName) then - begin - if MessageBox(Self.Handle, PChar( - 'File already exists. Do you want to overwrite it?'), PChar('Warning!'), MB_YESNO) = - ID_YES then - begin - DeleteFile(saved.FileName); - end - else - begin - group_progress.Visible := False; - panel_files.Enabled := True; - group_singlefiles.Enabled := True; - group_onefile.Enabled := True; - Exit; - end; - end; - i := FileCreate(saved.FileName); - FileClose(i); - i := 0; + fileid := OniDataConnection.ExtractFileID(filelist.Items.Strings[i]); + filename := GetWinFilename(filelist.Items.Strings[i]); + if check_dat.Checked then + ExportDatFile(fileid, path + filename); + if check_raw.Checked then + ExportRawFiles(fileid, path + filename); + if check_convert.Checked then + ExportConverted(fileid, path + filename); + Inc(done); end; - if sel_only then - begin - files := filelist.SelCount; - lbl_progress.Caption := 'Files done: 0/' + IntToStr(files); - progress.Max := files; - done := 0; - for i := 0 to filelist.Count - 1 do - begin - if filelist.Selected[i] then - begin - if one_file then - begin - ExportFile(OniDataConnection.ExtractFileID( - filelist.Items.Strings[filelist.ItemIndex]), ExtractFileName(saved.FileName), - settings, ExtractFileDir(saved.FileName)); - end - else - begin - ExportFile(OniDataConnection.ExtractFileID( - filelist.Items.Strings[filelist.ItemIndex]), filelist.Items.Strings[i], settings, 'D:'); - end; - Inc(done); - end; - if ((done mod 10) = 0) and (done >= 50) then - lbl_estimated.Caption := 'Estimated finishing time: ' + TimeToStr( + if ((done mod 10) = 0) and (done >= 50) then + lbl_estimated.Caption := 'Estimated finishing time: ' + TimeToStr( (Time - begintime) / done * files + begintime); - if (i mod 10) = 0 then - begin - progress.Position := done; - lbl_progress.Caption := 'Files done: ' + IntToStr(done) + '/' + IntToStr(files); - Application.ProcessMessages; - end; - end; - end - else - begin - files := filelist.Count; - lbl_progress.Caption := 'Files done: 0/' + IntToStr(files); - progress.Max := files; - for i := 0 to filelist.Count - 1 do - begin - if one_file then - begin - ExportFile(OniDataConnection.ExtractFileID( - filelist.Items.Strings[filelist.ItemIndex]), ExtractFileName(saved.FileName), - settings, ExtractFileDir(saved.FileName)); - end - else - begin - ExportFile(OniDataConnection.ExtractFileID( - filelist.Items.Strings[filelist.ItemIndex]), filelist.Items.Strings[i], settings, 'D:'); - end; - if ((i mod 10) = 0) and (i >= 50) then - lbl_estimated.Caption := 'Estimated finishing time: ' + TimeToStr( - (Time - begintime) / i * files + begintime); - if (i mod 5) = 0 then - begin - progress.Position := i; - lbl_progress.Caption := 'Files done: ' + IntToStr(i) + '/' + IntToStr(files); - Application.ProcessMessages; - end; - end; - end; - group_progress.Visible := False; - panel_files.Enabled := True; - group_singlefiles.Enabled := True; - group_onefile.Enabled := True; + + progress.Position := done; + lbl_progress.Caption := 'Files done: ' + IntToStr(done) + '/' + IntToStr(files); + Application.ProcessMessages; end; + + panel_files.Enabled := True; + group_extract.Enabled := True; + group_progress.Visible := False; end; + begin AddToolListEntry('extractor', 'Extractor', ''); end. \ No newline at end of file