source: oup/releases/0.22a/Unit11_extractor.pas@ 31

Last change on this file since 31 was 22, checked in by alloc, 18 years ago
File size: 7.2 KB
RevLine 
[22]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 panel_extension: TPanel;
10 combo_extension: TComboBox;
11 list: TListBox;
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 PROCEDURE FormCreate(Sender: TObject);
30 PROCEDURE FormActivate(Sender: TObject);
31 PROCEDURE FormClose(Sender: TObject; var Action: TCloseAction);
32 PROCEDURE FormResize(Sender: TObject);
33 PROCEDURE combo_extensionClick(Sender: TObject);
34 PROCEDURE panel_extensionResize(Sender: TObject);
35 PROCEDURE Extract(Sender: TObject);
36 PRIVATE
37 PUBLIC
38 PROCEDURE Recreatelist;
39 END;
40
41VAR
42 Form11: TForm11;
43
44IMPLEMENTATION
45{$R *.dfm}
46USES Unit1_main, Unit2_functions, Unit3_data;
47
48PROCEDURE TForm11.Recreatelist;
49 VAR
50 i:LongWord;
51 exts:TStringList;
52 BEGIN
53 combo_extension.Items.Clear;
54 combo_extension.Items.Add('_All files_ ('{+IntToStr(dat_header.Files)}+')');
55 exts:=GetExtensionsList;
56 FOR i:=0 TO High(exts) DO
57 combo_extension.Items.Add(exts[i]);
58 combo_extension.ItemIndex:=0;
59 combo_extensionClick(Self);
60 END;
61
62PROCEDURE TForm11.panel_extensionResize(Sender: TObject);
63 BEGIN
64 combo_extension.Width:=panel_extension.Width-5;
65 END;
66
67PROCEDURE TForm11.combo_extensionClick(Sender: TObject);
68 VAR
69 Extension:String[4];
70 files:TStringList;
71 i:LongWord;
72 BEGIN
73 Extension:=MidStr(combo_extension.Items.Strings[combo_extension.ItemIndex],1,4);
74 list.Items.Clear;
75 IF Extension='_All' THEN
76 files:=GetFilesList('','',True)
77 ELSE
78 files:=GetFilesList(extension,'',True);
79 IF Length(files)>0 THEN
80 FOR i:=0 TO High(files) DO
81 list.Items.Add(files[i]);
82 END;
83
84PROCEDURE TForm11.FormResize(Sender: TObject);
85 BEGIN
86 IF Self.Width>=450 THEN BEGIN
87 END ELSE Self.Width:=450;
88 IF Self.Height>=400 THEN BEGIN
89 group_progress.Height:=group_extract.Height-293;
90 END ELSE Self.Height:=400;
91 END;
92
93PROCEDURE TForm11.FormClose(Sender: TObject; var Action: TCloseAction);
94 BEGIN
95 Action:=caFree;
96 Form1.close_window(Self.Name);
97 END;
98
99PROCEDURE TForm11.FormActivate(Sender: TObject);
100 BEGIN
101 Form1.SetActiveWindow(Self.Name);
102 END;
103
104PROCEDURE TForm11.FormCreate(Sender: TObject);
105 BEGIN
106 btn_sel_dat.Caption:= 'Selected files'+CrLf+'(dat contents only)';
107 btn_sel_datraw.Caption:= 'Selected files'+CrLf+'(dat+raw contents)';
108 btn_sel_datraw_convert.Caption:='Selected files'+CrLf+'(dat+raw contents)'+CrLf+'(with convert if possible)';
109 btn_all_dat.Caption:= 'All files in list'+CrLf+'(dat contents only)';
110 btn_all_datraw.Caption:= 'All files in list'+CrLf+'(dat+raw contents)';
111 btn_all_datraw_convert.Caption:='All files in list'+CrLf+'(dat+raw contents)'+CrLf+'(with convert if possible)';
112 btn_sel_files_toone.Caption:= 'Selected files'+CrLf+'(dat contents only)';
113 btn_all_files_toone.Caption:= 'All files in list'+CrLf+'(dat contents only)';
114 END;
115
116PROCEDURE TForm11.Extract(Sender: TObject);
117 VAR
118 sel_only:Boolean;
119 dat_only:Boolean;
120 convert:Boolean;
121 one_file:Boolean;
122 settings:TExportSet;
123 files:LongWord;
124 i,done:LongWord;
125 begintime:Double;
126 BEGIN
127 sel_only:=Pos('sel',TButton(Sender).Name)>0;
128 dat_only:=NOT (Pos('datraw',TButton(Sender).Name)>0);
129 convert:=Pos('convert',TButton(Sender).Name)>0;
130 one_file:=Pos('toone',TButton(Sender).Name)>0;
131 IF dat_only THEN settings:=[DO_dat]
132 ELSE settings:=[DO_dat,DO_raw];
133 IF convert THEN settings:=settings+[DO_convert];
134 IF one_file THEN settings:=settings+[DO_toone];
135 progress.Position:=0;
136
137 IF saved.Execute THEN BEGIN
138 begintime:=Time;
139 group_progress.Visible:=True;
140 group_select.Enabled:=False;
141 group_singlefiles.Enabled:=False;
142 group_onefile.Enabled:=False;
143 lbl_estimated.Caption:='Estimated finishing time: unknown';
144 IF one_file THEN BEGIN
145 IF FileExists(saved.FileName) THEN BEGIN
146 IF MessageBox(Self.Handle,PChar('File already exists. Do you want to overwrite it?'),PChar('Warning!'),MB_YESNO)=ID_YES THEN BEGIN
147 DeleteFile(saved.FileName);
148 END ELSE BEGIN
149 group_progress.Visible:=False;
150 group_select.Enabled:=True;
151 group_singlefiles.Enabled:=True;
152 group_onefile.Enabled:=True;
153 Exit;
154 END;
155 END;
156 i:=FileCreate(saved.FileName);
157 FileClose(i);
158 i:=0;
159 END;
160 IF sel_only THEN BEGIN
161 files:=list.SelCount;
162 lbl_progress.Caption:='Files done: 0/'+IntToStr(files);
163 progress.Max:=files;
164 done:=0;
165 FOR i:=0 TO list.Count-1 DO BEGIN
166 IF list.Selected[i] THEN BEGIN
167 IF one_file THEN BEGIN
168 ExportFile(StrToInt(MidStr(list.Items.Strings[i],1,5)),ExtractFileName(saved.FileName),settings,ExtractFileDir(saved.FileName));
169 END ELSE BEGIN
170 ExportFile(StrToInt(MidStr(list.Items.Strings[i],1,5)),list.Items.Strings[i],settings,'D:');
171 END;
172 Inc(done);
173 END;
174 IF ((done MOD 10)=0) AND (done>=50) THEN
175 lbl_estimated.Caption:='Estimated finishing time: '+TimeToStr((Time-begintime)/done*files+begintime);
176 IF (i MOD 10)=0 THEN BEGIN
177 progress.Position:=done;
178 lbl_progress.Caption:='Files done: '+IntToStr(done)+'/'+IntToStr(files);
179 Application.ProcessMessages;
180 END;
181 END;
182 END ELSE BEGIN
183 files:=list.Count;
184 lbl_progress.Caption:='Files done: 0/'+IntToStr(files);
185 progress.Max:=files;
186 FOR i:=0 TO list.Count-1 DO BEGIN
187 IF one_file THEN BEGIN
188 ExportFile(StrToInt(MidStr(list.Items.Strings[i],1,5)),ExtractFileName(saved.FileName),settings,ExtractFileDir(saved.FileName));
189 END ELSE BEGIN
190 ExportFile(StrToInt(MidStr(list.Items.Strings[i],1,5)),list.Items.Strings[i],settings,'D:');
191 END;
192 IF ((i MOD 10)=0) AND (i>=50) THEN
193 lbl_estimated.Caption:='Estimated finishing time: '+TimeToStr((Time-begintime)/i*files+begintime);
194 IF (i MOD 5)=0 THEN BEGIN
195 progress.Position:=i;
196 lbl_progress.Caption:='Files done: '+IntToStr(i)+'/'+IntToStr(files);
197 Application.ProcessMessages;
198 END;
199 END;
200 END;
201 group_progress.Visible:=False;
202 group_select.Enabled:=True;
203 group_singlefiles.Enabled:=True;
204 group_onefile.Enabled:=True;
205 END;
206 END;
207
208END.
Note: See TracBrowser for help on using the repository browser.