source: oup/current/Tool_Extractor.pas@ 44

Last change on this file since 44 was 43, checked in by alloc, 18 years ago

DevTree 0.33a.

File size: 8.5 KB
Line 
1unit Tool_Extractor;
2
3interface
4
5uses
6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, StdCtrls, ExtCtrls, StrUtils, ComCtrls;
8
9type
10 TForm_Extractor = class(TForm)
11 group_select: TGroupBox;
12 group_extract: TGroupBox;
13 group_singlefiles: TGroupBox;
14 btn_sel_dat: TButton;
15 btn_sel_datraw: TButton;
16 btn_sel_datraw_convert: TButton;
17 btn_all_dat: TButton;
18 btn_all_datraw: TButton;
19 btn_all_datraw_convert: TButton;
20 group_onefile: TGroupBox;
21 btn_sel_files_toone: TButton;
22 btn_all_files_toone: TButton;
23 group_progress: TGroupBox;
24 progress: TProgressBar;
25 lbl_progress: TLabel;
26 lbl_estimated: TLabel;
27 btn_abort: TButton;
28 saved: TSaveDialog;
29 panel_extension: TPanel;
30 lbl_filter: TLabel;
31 combo_extension: TComboBox;
32 check_zerobyte: TCheckBox;
33 edit_filtername: TEdit;
34 check_filtername: TCheckBox;
35 list: TListBox;
36 procedure LoadFileNames;
37 procedure check_filternameClick(Sender: TObject);
38 procedure check_zerobyteClick(Sender: TObject);
39 procedure combo_extensionClick(Sender: TObject);
40 procedure panel_extensionResize(Sender: TObject);
41 procedure Recreatelist;
42
43 procedure FormCreate(Sender: TObject);
44 procedure FormClose(Sender: TObject; var Action: TCloseAction);
45 procedure FormResize(Sender: TObject);
46 procedure Extract(Sender: TObject);
47 private
48 public
49 end;
50
51var
52 Form_Extractor: TForm_Extractor;
53
54implementation
55
56{$R *.dfm}
57
58uses Main, Code_Functions, Data, Code_OniDataClass;
59
60
61
62
63procedure TForm_Extractor.Recreatelist;
64var
65 i: LongWord;
66 exts: TStringArray;
67begin
68 combo_extension.Items.Clear;
69 combo_extension.Items.Add('_All files_ (' + IntToStr(
70 OniDataConnection.GetFilesCount) + ')');
71 exts := OniDataConnection.GetExtensionsList;
72 for i := 0 to High(exts) do
73 combo_extension.Items.Add(exts[i]);
74 combo_extension.ItemIndex := 0;
75 combo_extensionClick(Self);
76end;
77
78
79
80
81procedure TForm_Extractor.LoadFileNames;
82var
83 Extension: String[4];
84 no_zero_bytes: Boolean;
85 pattern: String;
86 files: TStringArray;
87 i: LongWord;
88begin
89 Extension := MidStr(combo_extension.Items.Strings[combo_extension.ItemIndex], 1, 4);
90 no_zero_bytes := not check_zerobyte.Checked;
91 pattern := '';
92 if check_filtername.Checked then
93 pattern := edit_filtername.Text;
94 if Extension = '_All' then
95 Extension := '';
96
97 files := OniDataConnection.GetFilesList(extension, pattern, no_zero_bytes);
98 list.Items.Clear;
99 if Length(files) > 0 then
100 for i := 0 to High(files) do
101 list.Items.Add(files[i]);
102end;
103
104
105
106
107procedure TForm_Extractor.panel_extensionResize(Sender: TObject);
108begin
109 combo_extension.Width := panel_extension.Width - 5;
110 edit_filtername.Width := panel_extension.Width - 5;
111end;
112
113
114
115
116procedure TForm_Extractor.combo_extensionClick(Sender: TObject);
117begin
118 LoadFileNames;
119end;
120
121
122
123
124procedure TForm_Extractor.check_zerobyteClick(Sender: TObject);
125var
126 i: Byte;
127begin
128 LoadFileNames;
129end;
130
131
132
133
134procedure TForm_Extractor.check_filternameClick(Sender: TObject);
135begin
136 edit_filtername.Enabled := not check_filtername.Checked;
137 LoadFileNames;
138end;
139
140
141
142
143procedure TForm_Extractor.FormResize(Sender: TObject);
144begin
145 if Self.Width >= 450 then
146 begin
147 end
148 else
149 Self.Width := 450;
150 if Self.Height >= 400 then
151 begin
152 group_progress.Height := group_extract.Height - 293;
153 end
154 else
155 Self.Height := 400;
156end;
157
158
159
160
161procedure TForm_Extractor.FormClose(Sender: TObject; var Action: TCloseAction);
162begin
163 Action := caFree;
164end;
165
166
167
168
169procedure TForm_Extractor.FormCreate(Sender: TObject);
170begin
171 btn_sel_dat.Caption := 'Selected files' + CrLf + '(dat contents only)';
172 btn_sel_datraw.Caption := 'Selected files' + CrLf + '(dat+raw contents)';
173 btn_sel_datraw_convert.Caption :=
174 'Selected files' + CrLf + '(dat+raw contents)' + CrLf + '(with convert if possible)';
175 btn_all_dat.Caption := 'All files in list' + CrLf + '(dat contents only)';
176 btn_all_datraw.Caption := 'All files in list' + CrLf + '(dat+raw contents)';
177 btn_all_datraw_convert.Caption :=
178 'All files in list' + CrLf + '(dat+raw contents)' + CrLf + '(with convert if possible)';
179 btn_sel_files_toone.Caption := 'Selected files' + CrLf + '(dat contents only)';
180 btn_all_files_toone.Caption := 'All files in list' + CrLf + '(dat contents only)';
181end;
182
183
184
185
186procedure TForm_Extractor.Extract(Sender: TObject);
187var
188 sel_only: Boolean;
189 dat_only: Boolean;
190 convert: Boolean;
191 one_file: Boolean;
192 settings: TExportSet;
193 files: LongWord;
194 i, done: LongWord;
195 begintime: Double;
196begin
197 sel_only := Pos('sel', TButton(Sender).Name) > 0;
198 dat_only := not (Pos('datraw', TButton(Sender).Name) > 0);
199 convert := Pos('convert', TButton(Sender).Name) > 0;
200 one_file := Pos('toone', TButton(Sender).Name) > 0;
201 if dat_only then
202 settings := [DO_dat]
203 else
204 settings := [DO_dat, DO_raw];
205 if convert then
206 settings := settings + [DO_convert];
207 if one_file then
208 settings := settings + [DO_toone];
209 progress.Position := 0;
210
211 if saved.Execute then
212 begin
213 begintime := Time;
214 group_progress.Visible := True;
215 group_select.Enabled := False;
216 group_singlefiles.Enabled := False;
217 group_onefile.Enabled := False;
218 lbl_estimated.Caption := 'Estimated finishing time: unknown';
219 if one_file then
220 begin
221 if FileExists(saved.FileName) then
222 begin
223 if MessageBox(Self.Handle, PChar(
224 'File already exists. Do you want to overwrite it?'), PChar('Warning!'), MB_YESNO) =
225 ID_YES then
226 begin
227 DeleteFile(saved.FileName);
228 end
229 else
230 begin
231 group_progress.Visible := False;
232 group_select.Enabled := True;
233 group_singlefiles.Enabled := True;
234 group_onefile.Enabled := True;
235 Exit;
236 end;
237 end;
238 i := FileCreate(saved.FileName);
239 FileClose(i);
240 i := 0;
241 end;
242 if sel_only then
243 begin
244 files := list.SelCount;
245 lbl_progress.Caption := 'Files done: 0/' + IntToStr(files);
246 progress.Max := files;
247 done := 0;
248 for i := 0 to list.Count - 1 do
249 begin
250 if list.Selected[i] then
251 begin
252 if one_file then
253 begin
254 ExportFile(OniDataConnection.ExtractFileID(
255 list.Items.Strings[list.ItemIndex]), ExtractFileName(saved.FileName),
256 settings, ExtractFileDir(saved.FileName));
257 end
258 else
259 begin
260 ExportFile(OniDataConnection.ExtractFileID(
261 list.Items.Strings[list.ItemIndex]), list.Items.Strings[i], settings, 'D:');
262 end;
263 Inc(done);
264 end;
265 if ((done mod 10) = 0) and (done >= 50) then
266 lbl_estimated.Caption := 'Estimated finishing time: ' + TimeToStr(
267 (Time - begintime) / done * files + begintime);
268 if (i mod 10) = 0 then
269 begin
270 progress.Position := done;
271 lbl_progress.Caption := 'Files done: ' + IntToStr(done) + '/' + IntToStr(files);
272 Application.ProcessMessages;
273 end;
274 end;
275 end
276 else
277 begin
278 files := list.Count;
279 lbl_progress.Caption := 'Files done: 0/' + IntToStr(files);
280 progress.Max := files;
281 for i := 0 to list.Count - 1 do
282 begin
283 if one_file then
284 begin
285 ExportFile(OniDataConnection.ExtractFileID(
286 list.Items.Strings[list.ItemIndex]), ExtractFileName(saved.FileName),
287 settings, ExtractFileDir(saved.FileName));
288 end
289 else
290 begin
291 ExportFile(OniDataConnection.ExtractFileID(
292 list.Items.Strings[list.ItemIndex]), list.Items.Strings[i], settings, 'D:');
293 end;
294 if ((i mod 10) = 0) and (i >= 50) then
295 lbl_estimated.Caption := 'Estimated finishing time: ' + TimeToStr(
296 (Time - begintime) / i * files + begintime);
297 if (i mod 5) = 0 then
298 begin
299 progress.Position := i;
300 lbl_progress.Caption := 'Files done: ' + IntToStr(i) + '/' + IntToStr(files);
301 Application.ProcessMessages;
302 end;
303 end;
304 end;
305 group_progress.Visible := False;
306 group_select.Enabled := True;
307 group_singlefiles.Enabled := True;
308 group_onefile.Enabled := True;
309 end;
310end;
311
312end.
Note: See TracBrowser for help on using the repository browser.