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