source: oup/current/Unit11_extractor.pas@ 17

Last change on this file since 17 was 10, checked in by alloc, 18 years ago
  • Property svn:executable set to *
File size: 8.0 KB
Line 
1UNIT Unit11_extractor;
2INTERFACE
3USES
4 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5 Dialogs, StdCtrls, ExtCtrls, StrUtils, ComCtrls;
6TYPE
7 TForm11 = Class(TForm)
8 group_select: TGroupBox;
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 group_onefile: TGroupBox;
18 btn_sel_files_toone: TButton;
19 btn_all_files_toone: TButton;
20 group_progress: TGroupBox;
21 progress: TProgressBar;
22 lbl_progress: TLabel;
23 lbl_estimated: TLabel;
24 btn_abort: TButton;
25 saved: TSaveDialog;
26 panel_extension: TPanel;
27 lbl_filter: TLabel;
28 combo_extension: TComboBox;
29 check_zerobyte: TCheckBox;
30 edit_filtername: TEdit;
31 check_filtername: TCheckBox;
32 list: TListBox;
33 PROCEDURE LoadFileNames;
34 PROCEDURE check_filternameClick(Sender: TObject);
35 PROCEDURE check_zerobyteClick(Sender: TObject);
36 PROCEDURE combo_extensionClick(Sender: TObject);
37 PROCEDURE panel_extensionResize(Sender: TObject);
38 PROCEDURE Recreatelist;
39
40 PROCEDURE FormCreate(Sender: TObject);
41 PROCEDURE FormClose(Sender: TObject; var Action: TCloseAction);
42 PROCEDURE FormResize(Sender: TObject);
43 PROCEDURE Extract(Sender: TObject);
44 PRIVATE
45 PUBLIC
46 END;
47
48VAR
49 Form11: TForm11;
50
51IMPLEMENTATION
52{$R *.dfm}
53USES Unit1_main, Unit2_functions, Unit3_data, Unit15_Classes;
54
55
56PROCEDURE TForm11.Recreatelist;
57 VAR
58 i:LongWord;
59 exts:TStringArray;
60 BEGIN
61 combo_extension.Items.Clear;
62 combo_extension.Items.Add('_All files_ ('+IntToStr(OniDataConnection.GetFilesCount)+')');
63 exts:=OniDataConnection.GetExtensionsList;
64 FOR i:=0 TO High(exts) DO
65 combo_extension.Items.Add(exts[i]);
66 combo_extension.ItemIndex:=0;
67 combo_extensionClick(Self);
68 END;
69
70PROCEDURE TForm11.LoadFileNames;
71 VAR
72 Extension:String[4];
73 no_zero_bytes:Boolean;
74 pattern:String;
75 files:TStringArray;
76 i:LongWord;
77 BEGIN
78 Extension:=MidStr(combo_extension.Items.Strings[combo_extension.ItemIndex],1,4);
79 no_zero_bytes:=NOT check_zerobyte.Checked;
80 pattern:='';
81 IF check_filtername.Checked THEN pattern:=edit_filtername.Text;
82 IF Extension='_All' THEN Extension:='';
83
84 files:=OniDataConnection.GetFilesList(extension,pattern,no_zero_bytes);
85 list.Items.Clear;
86 IF Length(files)>0 THEN
87 FOR i:=0 TO High(files) DO
88 list.Items.Add(files[i]);
89 END;
90
91PROCEDURE TForm11.panel_extensionResize(Sender: TObject);
92 BEGIN
93 combo_extension.Width:=panel_extension.Width-5;
94 edit_filtername.Width:=panel_extension.Width-5;
95 END;
96
97PROCEDURE TForm11.combo_extensionClick(Sender: TObject);
98 BEGIN
99 LoadFileNames;
100 END;
101
102PROCEDURE TForm11.check_zerobyteClick(Sender: TObject);
103 VAR
104 i:Byte;
105 BEGIN
106 LoadFileNames;
107 END;
108
109PROCEDURE TForm11.check_filternameClick(Sender: TObject);
110 BEGIN
111 edit_filtername.Enabled:=NOT check_filtername.Checked;
112 LoadFileNames;
113 END;
114
115
116
117PROCEDURE TForm11.FormResize(Sender: TObject);
118 BEGIN
119 IF Self.Width>=450 THEN BEGIN
120 END ELSE Self.Width:=450;
121 IF Self.Height>=400 THEN BEGIN
122 group_progress.Height:=group_extract.Height-293;
123 END ELSE Self.Height:=400;
124 END;
125
126PROCEDURE TForm11.FormClose(Sender: TObject; var Action: TCloseAction);
127 BEGIN
128 Action:=caFree;
129 END;
130
131PROCEDURE TForm11.FormCreate(Sender: TObject);
132 BEGIN
133 btn_sel_dat.Caption:= 'Selected files'+CrLf+'(dat contents only)';
134 btn_sel_datraw.Caption:= 'Selected files'+CrLf+'(dat+raw contents)';
135 btn_sel_datraw_convert.Caption:='Selected files'+CrLf+'(dat+raw contents)'+CrLf+'(with convert if possible)';
136 btn_all_dat.Caption:= 'All files in list'+CrLf+'(dat contents only)';
137 btn_all_datraw.Caption:= 'All files in list'+CrLf+'(dat+raw contents)';
138 btn_all_datraw_convert.Caption:='All files in list'+CrLf+'(dat+raw contents)'+CrLf+'(with convert if possible)';
139 btn_sel_files_toone.Caption:= 'Selected files'+CrLf+'(dat contents only)';
140 btn_all_files_toone.Caption:= 'All files in list'+CrLf+'(dat contents only)';
141 END;
142
143PROCEDURE TForm11.Extract(Sender: TObject);
144 VAR
145 sel_only:Boolean;
146 dat_only:Boolean;
147 convert:Boolean;
148 one_file:Boolean;
149 settings:TExportSet;
150 files:LongWord;
151 i,done:LongWord;
152 begintime:Double;
153 BEGIN
154 sel_only:=Pos('sel',TButton(Sender).Name)>0;
155 dat_only:=NOT (Pos('datraw',TButton(Sender).Name)>0);
156 convert:=Pos('convert',TButton(Sender).Name)>0;
157 one_file:=Pos('toone',TButton(Sender).Name)>0;
158 IF dat_only THEN settings:=[DO_dat]
159 ELSE settings:=[DO_dat,DO_raw];
160 IF convert THEN settings:=settings+[DO_convert];
161 IF one_file THEN settings:=settings+[DO_toone];
162 progress.Position:=0;
163
164 IF saved.Execute THEN BEGIN
165 begintime:=Time;
166 group_progress.Visible:=True;
167 group_select.Enabled:=False;
168 group_singlefiles.Enabled:=False;
169 group_onefile.Enabled:=False;
170 lbl_estimated.Caption:='Estimated finishing time: unknown';
171 IF one_file THEN BEGIN
172 IF FileExists(saved.FileName) THEN BEGIN
173 IF MessageBox(Self.Handle,PChar('File already exists. Do you want to overwrite it?'),PChar('Warning!'),MB_YESNO)=ID_YES THEN BEGIN
174 DeleteFile(saved.FileName);
175 END ELSE BEGIN
176 group_progress.Visible:=False;
177 group_select.Enabled:=True;
178 group_singlefiles.Enabled:=True;
179 group_onefile.Enabled:=True;
180 Exit;
181 END;
182 END;
183 i:=FileCreate(saved.FileName);
184 FileClose(i);
185 i:=0;
186 END;
187 IF sel_only THEN BEGIN
188 files:=list.SelCount;
189 lbl_progress.Caption:='Files done: 0/'+IntToStr(files);
190 progress.Max:=files;
191 done:=0;
192 FOR i:=0 TO list.Count-1 DO BEGIN
193 IF list.Selected[i] THEN BEGIN
194 IF one_file THEN BEGIN
195 ExportFile(OniDataConnection.ExtractFileID(list.Items.Strings[list.ItemIndex]),ExtractFileName(saved.FileName),settings,ExtractFileDir(saved.FileName));
196 END ELSE BEGIN
197 ExportFile(OniDataConnection.ExtractFileID(list.Items.Strings[list.ItemIndex]),list.Items.Strings[i],settings,'D:');
198 END;
199 Inc(done);
200 END;
201 IF ((done MOD 10)=0) AND (done>=50) THEN
202 lbl_estimated.Caption:='Estimated finishing time: '+TimeToStr((Time-begintime)/done*files+begintime);
203 IF (i MOD 10)=0 THEN BEGIN
204 progress.Position:=done;
205 lbl_progress.Caption:='Files done: '+IntToStr(done)+'/'+IntToStr(files);
206 Application.ProcessMessages;
207 END;
208 END;
209 END ELSE BEGIN
210 files:=list.Count;
211 lbl_progress.Caption:='Files done: 0/'+IntToStr(files);
212 progress.Max:=files;
213 FOR i:=0 TO list.Count-1 DO BEGIN
214 IF one_file THEN BEGIN
215 ExportFile(OniDataConnection.ExtractFileID(list.Items.Strings[list.ItemIndex]),ExtractFileName(saved.FileName),settings,ExtractFileDir(saved.FileName));
216 END ELSE BEGIN
217 ExportFile(OniDataConnection.ExtractFileID(list.Items.Strings[list.ItemIndex]),list.Items.Strings[i],settings,'D:');
218 END;
219 IF ((i MOD 10)=0) AND (i>=50) THEN
220 lbl_estimated.Caption:='Estimated finishing time: '+TimeToStr((Time-begintime)/i*files+begintime);
221 IF (i MOD 5)=0 THEN BEGIN
222 progress.Position:=i;
223 lbl_progress.Caption:='Files done: '+IntToStr(i)+'/'+IntToStr(files);
224 Application.ProcessMessages;
225 END;
226 END;
227 END;
228 group_progress.Visible:=False;
229 group_select.Enabled:=True;
230 group_singlefiles.Enabled:=True;
231 group_onefile.Enabled:=True;
232 END;
233 END;
234
235END.
Note: See TracBrowser for help on using the repository browser.