Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | daniel-mar | 1 | Unit mainunit; |
2 | (************************************************************************ |
||
3 | Copyright (C) 2009, 2010 by Russell J. Peters, Roger Aelbrecht, |
||
4 | Eric W. Engler and Chris Vleghert. |
||
5 | |||
6 | This file is part of TZipMaster Version 1.9. |
||
7 | |||
8 | TZipMaster is free software: you can redistribute it and/or modify |
||
9 | it under the terms of the GNU Lesser General Public License as published by |
||
10 | the Free Software Foundation, either version 3 of the License, or |
||
11 | (at your option) any later version. |
||
12 | |||
13 | TZipMaster is distributed in the hope that it will be useful, |
||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
16 | GNU Lesser General Public License for more details. |
||
17 | |||
18 | You should have received a copy of the GNU Lesser General Public License |
||
19 | along with TZipMaster. If not, see <http://www.gnu.org/licenses/>. |
||
20 | |||
21 | contact: problems@delphizip.org (include ZipMaster in the subject). |
||
22 | updates: http://www.delphizip.org |
||
23 | DelphiZip maillist subscribe at http://www.freelists.org/list/delphizip |
||
24 | ************************************************************************) |
||
25 | |||
26 | {$INCLUDE '..\..\ZipVers19.inc'} |
||
27 | {$IFDEF VERD6up} |
||
28 | {$WARN UNIT_PLATFORM OFF} |
||
29 | {$WARN SYMBOL_PLATFORM OFF} |
||
30 | {$ENDIF} |
||
31 | |||
32 | Interface |
||
33 | |||
34 | Uses |
||
35 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, |
||
36 | StdCtrls, Grids, ExtCtrls, SortGrid, ZipMstr19, Menus, ShlObj, FileCtrl, |
||
37 | ImgList, printers; |
||
38 | |||
39 | Type |
||
40 | TMainform = Class(TForm) |
||
41 | Panel1: TPanel; |
||
42 | Panel2: TPanel; |
||
43 | Panel3: TPanel; |
||
44 | Panel4: TPanel; |
||
45 | // ZipMaster1: TZipMaster19; |
||
46 | // StringGrid1: TSortGrid; |
||
47 | OpenDialog1: TOpenDialog; |
||
48 | Label1: TLabel; |
||
49 | Label2: TLabel; |
||
50 | Label4: TLabel; |
||
51 | Bevel1: TBevel; |
||
52 | Bevel2: TBevel; |
||
53 | ZipFName: TLabel; |
||
54 | TimeLabel: TLabel; |
||
55 | FilesLabel: TLabel; |
||
56 | MsgBut: TButton; |
||
57 | AddBut: TButton; |
||
58 | TestBut: TButton; |
||
59 | CloseBut: TButton; |
||
60 | DeleteBut: TButton; |
||
61 | NewZipBut: TButton; |
||
62 | ZipOpenBut: TButton; |
||
63 | ConvertBut: TButton; |
||
64 | ExtractBut: TButton; |
||
65 | DeleteZipBut: TButton; |
||
66 | RenameBut: TButton; |
||
67 | MainMenu1: TMainMenu; |
||
68 | File1: TMenuItem; |
||
69 | Exit1: TMenuItem; |
||
70 | Project1: TMenuItem; |
||
71 | Zipcomment1: TMenuItem; |
||
72 | Showlasterror1: TMenuItem; |
||
73 | DLLversioninfo1: TMenuItem; |
||
74 | TraceCB: TCheckBox; |
||
75 | VerboseCB: TCheckBox; |
||
76 | UnattendedCB: TCheckBox; |
||
77 | ImageList1: TImageList; |
||
78 | |||
79 | Procedure ZipOpenButClick(Sender: TObject); |
||
80 | Procedure CloseButClick(Sender: TObject); |
||
81 | Procedure NewZipButClick(Sender: TObject); |
||
82 | Procedure DeleteZipButClick(Sender: TObject); |
||
83 | Procedure ExtractButClick(Sender: TObject); |
||
84 | Procedure ZipMaster1DirUpdate(Sender: TObject); |
||
85 | Procedure FormCreate(Sender: TObject); |
||
86 | Procedure FillGrid; |
||
87 | Procedure AddButClick(Sender: TObject); |
||
88 | Procedure DeleteButClick(Sender: TObject); |
||
89 | Procedure FormDestroy(Sender: TObject); |
||
90 | Procedure TestButClick(Sender: TObject); |
||
91 | Procedure MsgButClick(Sender: TObject); |
||
92 | Procedure ConvertButClick(Sender: TObject); |
||
93 | Procedure FormResize(Sender: TObject); |
||
94 | Procedure VerboseCBClick(Sender: TObject); |
||
95 | Procedure TraceCBClick(Sender: TObject); |
||
96 | Procedure DLLversioninfo1Click(Sender: TObject); |
||
97 | Procedure Zipcomment1Click(Sender: TObject); |
||
98 | Procedure Showlasterror1Click(Sender: TObject); |
||
99 | Procedure Exit1Click(Sender: TObject); |
||
100 | Procedure UnattendedCBClick(Sender: TObject); |
||
101 | Procedure StringGrid1GetCellFormat(Sender: TObject; Col, Row: LongInt; |
||
102 | State: TGridDrawState; Var FormatOptions: TFormatOptions); |
||
103 | Procedure StringGrid1EndSort(Sender: TObject; Col: LongInt); |
||
104 | Procedure RenameButClick(Sender: TObject); |
||
105 | PUBLIC |
||
106 | { Public declarations } |
||
107 | DoIt: Boolean; |
||
108 | TotUncomp, TotComp: Cardinal; |
||
109 | StringGrid1: TSortGrid; |
||
110 | ZipMaster1: TZipMaster19; |
||
111 | |||
112 | Function ShowLTime(s, f: LongInt): String; |
||
113 | Procedure SetZipFName(aCaption: String; AssignName: Boolean); |
||
114 | Function GetSpecialFolder(aFolder: Integer; Var Location: String): LongWord; |
||
115 | Procedure SetZipTotals; |
||
116 | Function AskDirDialog(Const FormHandle: HWND; Var DirPath: String): Boolean; |
||
117 | procedure ZipMaster1Message(Sender: TObject; ErrCode: Integer; |
||
118 | const Message: TZMString); |
||
119 | procedure ZipMaster1Progress(Sender: TObject; details: TZMProgressDetails); |
||
120 | procedure ZipMaster1Tick(Sender: TObject); |
||
121 | PROTECTED |
||
122 | FNewCount: Integer; |
||
123 | End; |
||
124 | |||
125 | Var |
||
126 | Mainform: TMainform; |
||
127 | ExtractDir: String; |
||
128 | ExpandDirs: Boolean; |
||
129 | OverWr: Boolean; |
||
130 | AllFiles: Boolean; |
||
131 | Canceled: Boolean; |
||
132 | |||
133 | Implementation |
||
134 | |||
135 | Uses extrunit, msgunit, addunit, sfxunit, renunit; |
||
136 | {$R *.DFM} |
||
137 | |||
138 | Procedure TMainform.FormCreate(Sender: TObject); |
||
139 | Begin |
||
140 | StringGrid1 := TSortGrid.Create(Self); |
||
141 | StringGrid1.Parent := Self; |
||
142 | With StringGrid1 Do |
||
143 | Begin |
||
144 | Left := 0; |
||
145 | Top := 125; |
||
146 | Width := 612; |
||
147 | Height := 247; |
||
148 | Align := alClient; |
||
149 | ColCount := 6; |
||
150 | DefaultRowHeight := 22; |
||
151 | FixedCols := 0; |
||
152 | RowCount := 8; |
||
153 | Font.Charset := DEFAULT_CHARSET; |
||
154 | Font.Color := clBlack; |
||
155 | Font.Height := -12; |
||
156 | Font.Name := 'Arial'; |
||
157 | Font.Style := []; |
||
158 | Options := [goFixedVertLine, goFixedHorzLine, goHorzLine, goRangeSelect, |
||
159 | goColSizing, goRowSelect, goThumbTracking]; |
||
160 | ColWidths[0] := 178; |
||
161 | ColWidths[1] := 91; |
||
162 | ColWidths[2] := 105; |
||
163 | ColWidths[3] := 108; |
||
164 | ColWidths[4] := 53; |
||
165 | ColWidths[5] := 251; |
||
166 | ParentFont := False; |
||
167 | TabOrder := 1; |
||
168 | CaseSensitive := False; |
||
169 | AlignmentHorz := taLeftJustify; |
||
170 | AlignmentVert := taTopJustify; |
||
171 | ProportionalScrollBars := True; |
||
172 | ExtendedKeys := False; |
||
173 | SortSymbol := sgGlyph; |
||
174 | SortColumn := 0; |
||
175 | SortOnClick := True; |
||
176 | FooterRows := 1; |
||
177 | FooterFont.Charset := DEFAULT_CHARSET; |
||
178 | FooterFont.Color := clWindowText; |
||
179 | FooterFont.Height := -11; |
||
180 | FooterFont.Name := 'MS Sans Serif'; |
||
181 | FooterFont.Style := [fsBold]; |
||
182 | PrintOptions.Orientation := poPortrait; |
||
183 | PrintOptions.PageTitleMargin := 0; |
||
184 | PrintOptions.PageFooter := 'date|time|page'; |
||
185 | PrintOptions.HeaderSize := 10; |
||
186 | PrintOptions.FooterSize := 7; |
||
187 | PrintOptions.DateFormat := 'd-mmm-yyyy'; |
||
188 | PrintOptions.TimeFormat := 'h:nn'; |
||
189 | PrintOptions.FromRow := 0; |
||
190 | PrintOptions.ToRow := 0; |
||
191 | PrintOptions.BorderStyle := bsNone; |
||
192 | PrintOptions.MarginBottom := 0; |
||
193 | PrintOptions.MarginLeft := 0; |
||
194 | PrintOptions.MarginTop := 0; |
||
195 | PrintOptions.MarginRight := 0; |
||
196 | WordWrap := False; |
||
197 | OnGetCellFormat := StringGrid1GetCellFormat; |
||
198 | OnEndSort := StringGrid1EndSort; |
||
199 | |||
200 | { Make sure "goColMoving" is false in object inspector. This lets the |
||
201 | TSortGrid use Mouse Clicks on the col headers. } |
||
202 | RowCount := 2; { first row is fixed, and used for column headers } |
||
203 | Cells[0, 0] := 'File Name'; |
||
204 | Cells[1, 0] := 'Compr. Size'; |
||
205 | Cells[2, 0] := 'Uncmpr. Size'; |
||
206 | Cells[3, 0] := 'Date/Time'; |
||
207 | Cells[4, 0] := 'Ratio'; |
||
208 | Cells[5, 0] := 'Path'; |
||
209 | End; |
||
210 | // Set up component |
||
211 | ZipMaster1 := TZipMaster19.Create(Self); |
||
212 | ZipMaster1.Active := True; |
||
213 | ZipMaster1.DLLDirectory := '..\..\dll'; |
||
214 | ZipMaster1.OnMessage := ZipMaster1Message; |
||
215 | ZipMaster1.OnProgress := ZipMaster1Progress; |
||
216 | ZipMaster1.OnTick := ZipMaster1Tick; |
||
217 | ZipMaster1.OnDirUpdate := ZipMaster1DirUpdate; |
||
218 | // load the dll |
||
219 | ZipMaster1.Dll_Load := True; |
||
220 | { If we had args on the cmd line, then try to open the first one |
||
221 | as a zip/exe file. This is most useful in case user has an association |
||
222 | to ".zip" that causes this program to run when user dble clicks on a zip |
||
223 | file in Explorer. } |
||
224 | If ParamCount > 0 Then |
||
225 | ZipMaster1.ZipFilename := ParamStr(1); |
||
226 | End; |
||
227 | |||
228 | Procedure TMainform.FormResize(Sender: TObject); |
||
229 | Begin |
||
230 | If Width - 291 > 0 Then |
||
231 | ZipFName.Width := Width - 291 |
||
232 | Else |
||
233 | ZipFName.Width := 0; |
||
234 | SetZipFName(ZipMaster1.ZipFilename, False); |
||
235 | End; |
||
236 | |||
237 | Procedure TMainform.CloseButClick(Sender: TObject); |
||
238 | Begin |
||
239 | Close; |
||
240 | End; |
||
241 | |||
242 | Procedure TMainform.FormDestroy(Sender: TObject); |
||
243 | Begin |
||
244 | ZipMaster1.Dll_Load := False; |
||
245 | End; |
||
246 | |||
247 | Procedure TMainform.ZipOpenButClick(Sender: TObject); |
||
248 | Var |
||
249 | FirstDir: String; |
||
250 | Begin |
||
251 | If FirstDir = '' Then |
||
252 | GetSpecialFolder(CSIDL_DESKTOPDIRECTORY, FirstDir); |
||
253 | With OpenDialog1 Do |
||
254 | Begin |
||
255 | InitialDir := FirstDir; |
||
256 | Title := 'Open Existing ZIP File'; |
||
257 | Filter := 'ZIP Files (*.ZIP, *.EXE)|*.zip;*.exe'; |
||
258 | FileName := ''; |
||
259 | Options := Options + [ofHideReadOnly, ofShareAware, ofPathMustExist, |
||
260 | ofFileMustExist]; |
||
261 | If Execute Then |
||
262 | Begin |
||
263 | FirstDir := ExtractFilePath(FileName); |
||
264 | { Set the caption after assigning the filename. This |
||
265 | way, the filename will be null if the open failed. } |
||
266 | SetZipFName(FileName, True); |
||
267 | End; |
||
268 | End; |
||
269 | End; |
||
270 | |||
271 | Procedure TMainform.NewZipButClick(Sender: TObject); |
||
272 | Var |
||
273 | ans: Boolean; |
||
274 | FirstDir: String; |
||
275 | Begin |
||
276 | If FirstDir = '' Then |
||
277 | GetSpecialFolder(CSIDL_DESKTOPDIRECTORY, FirstDir); |
||
278 | With OpenDialog1 Do |
||
279 | Begin |
||
280 | InitialDir := FirstDir; |
||
281 | FileName := ''; |
||
282 | Filter := 'ZIP Files (*.ZIP)|*.zip'; |
||
283 | DefaultExt := 'Zip'; |
||
284 | Title := 'Create New ZIP File'; |
||
285 | Options := Options + [ofHideReadOnly, ofShareAware]; |
||
286 | Options := Options - [ofPathMustExist, ofFileMustExist]; |
||
287 | If Execute Then |
||
288 | Begin |
||
289 | FirstDir := ExtractFilePath(FileName); |
||
290 | If FileExists(FileName) Then |
||
291 | Begin |
||
292 | ans := MessageDlg('Overwrite Existing File: ' + FileName + '?', |
||
293 | mtConfirmation, [mbYes, mbNo], 0) = mrYes; |
||
294 | If ans Then |
||
295 | DeleteFile(FileName) |
||
296 | Else |
||
297 | Exit; { Don't use the new name } |
||
298 | End; |
||
299 | SetZipFName(FileName, True); |
||
300 | End; |
||
301 | End; |
||
302 | End; |
||
303 | |||
304 | Procedure TMainform.DeleteZipButClick(Sender: TObject); |
||
305 | Var |
||
306 | ans: Boolean; |
||
307 | Begin |
||
308 | If FileExists(ZipMaster1.ZipFilename) Then |
||
309 | Begin |
||
310 | ans := MessageDlg('Are you sure you want to delete: ' + |
||
311 | ZipMaster1.ZipFilename + '?', mtConfirmation, [mbYes, mbNo], 0) = mrYes; |
||
312 | If ans Then |
||
313 | Begin |
||
314 | DeleteFile(ZipMaster1.ZipFilename); |
||
315 | SetZipFName('', True); |
||
316 | End |
||
317 | Else |
||
318 | Exit; { Don't use the new name } |
||
319 | End |
||
320 | Else |
||
321 | ShowMessage('Zip file not found: ' + ZipMaster1.ZipFilename); |
||
322 | End; |
||
323 | |||
324 | Procedure TMainform.ExtractButClick(Sender: TObject); |
||
325 | Var |
||
326 | i: Integer; |
||
327 | s, f, SelRow: LongInt; |
||
328 | IsOne: String; |
||
329 | Begin |
||
330 | If Not FileExists(ZipMaster1.ZipFilename) Then |
||
331 | Begin |
||
332 | ShowMessage('Error: file not found: ' + ZipMaster1.ZipFilename); |
||
333 | Exit; |
||
334 | End; |
||
335 | Extract.ShowModal; |
||
336 | If (ExtractDir = '') Or Canceled Then |
||
337 | Exit; |
||
338 | |||
339 | With StringGrid1 Do |
||
340 | Begin |
||
341 | If ZipMaster1.Count < 1 Then |
||
342 | Begin |
||
343 | ShowMessage('Error - no files to extract'); |
||
344 | Exit; |
||
345 | End; |
||
346 | ZipMaster1.FSpecArgs.Clear; |
||
347 | { Get fspecs of selected files, unless user wants all files extracted } |
||
348 | If Not AllFiles Then |
||
349 | Begin |
||
350 | For i := 1 To SelectedCount Do |
||
351 | Begin |
||
352 | SelRow := SelectedItems[i]; |
||
353 | If (SelRow > 0) And (SelRow <> RowCount - 1) Then |
||
354 | ZipMaster1.FSpecArgs.Add(Cells[5, SelRow] + Cells[0, SelRow]); |
||
355 | End; |
||
356 | If ZipMaster1.FSpecArgs.Count < 1 Then |
||
357 | Begin |
||
358 | ShowMessage('Error - no files selected'); |
||
359 | Exit; |
||
360 | End; |
||
361 | End; |
||
362 | End; { end with } |
||
363 | |||
364 | MsgForm.Memo1.Clear; |
||
365 | MsgForm.Show; |
||
366 | { Put this message into the message form's memo } |
||
367 | ZipMaster1Message(Self, 0, |
||
368 | 'Beginning Extract from ' + ZipMaster1.ZipFilename); |
||
369 | |||
370 | With ZipMaster1 Do |
||
371 | Begin |
||
372 | ExtrBaseDir := ExtractDir; |
||
373 | ExtrOptions := []; |
||
374 | If ExpandDirs Then |
||
375 | ExtrOptions := ExtrOptions + [ExtrDirNames]; |
||
376 | If OverWr Then |
||
377 | ExtrOptions := ExtrOptions + [ExtrOverwrite]; |
||
378 | s := GetTickCount; |
||
379 | Try |
||
380 | Extract; |
||
381 | Except |
||
382 | ShowMessage('Error in Extract; Fatal DLL Exception in mainunit'); |
||
383 | End; |
||
384 | f := GetTickCount; |
||
385 | TimeLabel.Caption := ShowLTime(s, f); |
||
386 | If SuccessCnt = 1 Then |
||
387 | IsOne := ' was' |
||
388 | Else |
||
389 | IsOne := 's were'; |
||
390 | ShowMessage(IntToStr(SuccessCnt) + ' file' + IsOne + ' extracted'); |
||
391 | End; { end with } |
||
392 | End; |
||
393 | |||
394 | Procedure TMainform.AddButClick(Sender: TObject); |
||
395 | Var |
||
396 | s, f: LongInt; |
||
397 | IsOne: String; |
||
398 | Begin |
||
399 | If ZipMaster1.ZipFilename = '' Then |
||
400 | Begin |
||
401 | ShowMessage('Error - open a zip file first'); |
||
402 | Exit; |
||
403 | End; |
||
404 | AddForm.Left := Left; |
||
405 | AddForm.Top := Top; |
||
406 | AddForm.Width := Width; |
||
407 | AddForm.Height := Height; |
||
408 | Canceled := False; |
||
409 | AddForm.ShowModal; { let user pick filenames to add } |
||
410 | If Canceled Then |
||
411 | Exit; |
||
412 | If AddForm.SelectedList.Items.Count = 0 Then |
||
413 | Begin |
||
414 | ShowMessage('No files selected'); |
||
415 | Exit; |
||
416 | End; |
||
417 | MsgForm.Memo1.Clear; |
||
418 | FNewCount := 0; |
||
419 | MsgForm.Show; |
||
420 | { Put this message into the message form's memo } |
||
421 | ZipMaster1Message(Self, 0, 'Beginning Add to ' + ZipMaster1.ZipFilename); |
||
422 | |||
423 | With ZipMaster1 Do |
||
424 | Begin |
||
425 | { We want any DLL error messages to show over the top |
||
426 | of the message form. } |
||
427 | AddOptions := []; |
||
428 | WriteOptions := []; |
||
429 | Case AddForm.ZipAction Of // Default is plain ADD. |
||
430 | 2: |
||
431 | AddOptions := AddOptions + [AddUpdate]; // Update |
||
432 | 3: |
||
433 | AddOptions := AddOptions + [AddFreshen]; // Freshen |
||
434 | 4: |
||
435 | AddOptions := AddOptions + [AddMove]; // Move |
||
436 | End; |
||
437 | If AddForm.RecurseCB.Checked Then |
||
438 | AddOptions := AddOptions + [AddRecurseDirs]; { we want recursion } |
||
439 | If AddForm.AtribOnlyCB.Checked Then |
||
440 | AddOptions := AddOptions + [AddArchiveOnly]; { we want changed only } |
||
441 | If AddForm.AtribResetCB.Checked Then |
||
442 | AddOptions := AddOptions + [AddResetArchive]; { we want reset } |
||
443 | If AddForm.DirnameCB.Checked Then |
||
444 | AddOptions := AddOptions + [AddDirNames]; { we want dirnames } |
||
445 | If AddForm.DiskSpanCB.Checked Then |
||
446 | WriteOptions := WriteOptions + [zwoDiskSpan]; { we want diskspanning } |
||
447 | // AddOptions := AddOptions + [AddDiskSpan]; { we want diskspanning } |
||
448 | If AddForm.EncryptCB.Checked Then |
||
449 | Begin |
||
450 | AddOptions := AddOptions + [AddEncrypt]; { we want a password } |
||
451 | // GetAddPassword; |
||
452 | // if Password = '' then |
||
453 | { The 2 password's entered by user didn't match. } |
||
454 | { We'll give him one more try; if he still messes it |
||
455 | up, the DLL itself will prompt him one final time. } |
||
456 | // GetAddPassword; |
||
457 | End; |
||
458 | FSpecArgs.Clear; |
||
459 | FSpecArgs.Assign(AddForm.SelectedList.Items); { specify filenames } |
||
460 | AddForm.SelectedList.Clear; |
||
461 | s := GetTickCount; |
||
462 | Try |
||
463 | Add; |
||
464 | Except |
||
465 | ShowMessage('Error in Add; Fatal DLL Exception in mainunit'); |
||
466 | End; |
||
467 | f := GetTickCount; |
||
468 | TimeLabel.Caption := ShowLTime(s, f); |
||
469 | If SuccessCnt = 1 Then |
||
470 | IsOne := ' was' |
||
471 | Else |
||
472 | IsOne := 's were'; |
||
473 | ShowMessage(IntToStr(SuccessCnt) + ' file' + IsOne + ' added'); |
||
474 | End; { end with } |
||
475 | End; |
||
476 | |||
477 | Procedure TMainform.DeleteButClick(Sender: TObject); |
||
478 | Var |
||
479 | i: Integer; |
||
480 | ans: Boolean; |
||
481 | s, f, SelRow: LongInt; |
||
482 | IsOne: String; |
||
483 | Begin |
||
484 | With StringGrid1 Do |
||
485 | Begin |
||
486 | If ZipMaster1.Count < 1 Then |
||
487 | Begin |
||
488 | ShowMessage('Error - no files to delete'); |
||
489 | Exit; |
||
490 | End; |
||
491 | ans := MessageDlg('Delete selected files from: ' + ZipMaster1.ZipFilename + |
||
492 | '?', mtConfirmation, [mbYes, mbNo], 0) = mrYes; |
||
493 | If Not ans Then |
||
494 | Exit; |
||
495 | |||
496 | ZipMaster1.FSpecArgs.Clear; |
||
497 | For i := 1 To SelectedCount Do |
||
498 | Begin |
||
499 | SelRow := SelectedItems[i]; |
||
500 | If (SelRow > 0) And (SelRow <> RowCount - 1) Then |
||
501 | ZipMaster1.FSpecArgs.Add(Cells[5, SelRow] + Cells[0, SelRow]); |
||
502 | End; |
||
503 | |||
504 | If ZipMaster1.FSpecArgs.Count < 1 Then |
||
505 | Begin |
||
506 | ShowMessage('Error - no files selected'); |
||
507 | Exit; |
||
508 | End; |
||
509 | End; { end with } |
||
510 | |||
511 | MsgForm.Memo1.Clear; |
||
512 | MsgForm.Show; |
||
513 | { Put this message into the message form's memo } |
||
514 | ZipMaster1Message(Self, 0, 'Beginning delete from ' + ZipMaster1.ZipFilename); |
||
515 | |||
516 | s := GetTickCount; |
||
517 | Try |
||
518 | ZipMaster1.Delete; |
||
519 | Except |
||
520 | ShowMessage('Fatal error trying to delete'); |
||
521 | End; |
||
522 | f := GetTickCount; |
||
523 | TimeLabel.Caption := ShowLTime(s, f); |
||
524 | If ZipMaster1.SuccessCnt = 1 Then |
||
525 | IsOne := ' was' |
||
526 | Else |
||
527 | IsOne := 's were'; |
||
528 | ShowMessage(IntToStr(ZipMaster1.SuccessCnt) + ' file' + IsOne + ' deleted'); |
||
529 | End; |
||
530 | |||
531 | Procedure TMainform.TestButClick(Sender: TObject); |
||
532 | Var |
||
533 | s, f: LongInt; |
||
534 | Begin |
||
535 | If ZipMaster1.Count < 1 Then |
||
536 | Begin |
||
537 | ShowMessage('Error - nothing to Test'); |
||
538 | Exit; |
||
539 | End; |
||
540 | If ZipMaster1.ZipFilename = '' Then |
||
541 | Exit; |
||
542 | MsgForm.Memo1.Clear; |
||
543 | MsgForm.Show; |
||
544 | ZipMaster1Message(Self, 0, 'Beginning test of ' + ZipMaster1.ZipFilename); |
||
545 | With ZipMaster1 Do |
||
546 | Begin |
||
547 | FSpecArgs.Clear; |
||
548 | ExtrOptions := ExtrOptions + [ExtrTest]; |
||
549 | FSpecArgs.Add('*.*'); // Test all the files in the .zip |
||
550 | // IMPORTANT: In this release, you must test all files. |
||
551 | s := GetTickCount; |
||
552 | Extract; // This will really do a test |
||
553 | End; |
||
554 | f := GetTickCount; |
||
555 | TimeLabel.Caption := ShowLTime(s, f); |
||
556 | |||
557 | With ZipMaster1 Do |
||
558 | Begin |
||
559 | If SuccessCnt = DirOnlyCnt + Count Then |
||
560 | ShowMessage('All ' + IntToStr(DirOnlyCnt + Count) + ' files tested OK') |
||
561 | Else |
||
562 | ShowMessage('ERROR: ' + IntToStr(DirOnlyCnt + Count - SuccessCnt) |
||
563 | + ' files tested as bad, or skipped!'); |
||
564 | End; |
||
565 | End; |
||
566 | |||
567 | Procedure TMainform.MsgButClick(Sender: TObject); |
||
568 | Begin |
||
569 | MsgForm.Show; |
||
570 | End; |
||
571 | |||
572 | Procedure TMainform.ConvertButClick(Sender: TObject); |
||
573 | Var |
||
574 | ConvertErr: Integer; |
||
575 | Begin |
||
576 | If ZipMaster1.Count = 0 Then |
||
577 | Begin |
||
578 | ShowMessage('Error: no files in archive'); |
||
579 | Exit; |
||
580 | End; |
||
581 | { determine which conversion is to be done } |
||
582 | If UpperCase(ExtractFileExt(ZipMaster1.ZipFilename)) = '.EXE' Then |
||
583 | Begin |
||
584 | { Convert .EXE to .ZIP } |
||
585 | ConvertErr := ZipMaster1.ConvertToZIP; |
||
586 | If ConvertErr = 0 Then |
||
587 | ShowMessage('Filename is now: ' + ZipMaster1.ZipFilename) |
||
588 | Else |
||
589 | ShowMessage('Error ' + IntToStr(ConvertErr) + |
||
590 | ' occured in making .ZIP file'); |
||
591 | End |
||
592 | Else |
||
593 | Begin |
||
594 | { Convert .ZIP to .EXE } |
||
595 | { NOTE: If you put the ZIPSFX.BIN file into the WINDOWS |
||
596 | or WINDOWS SYSTEM dir, then you don't need to set the |
||
597 | SFXPath property below: } |
||
598 | { ZipMaster1.SFXPath := 'c:\windows\system\zipsfx.bin'; } |
||
599 | MakeSFX.ShowModal; |
||
600 | If DoIt = False Then |
||
601 | Exit; |
||
602 | ConvertErr := ZipMaster1.ConvertToSFX; |
||
603 | If ConvertErr = 0 Then |
||
604 | ShowMessage('Filename is now: ' + ZipMaster1.ZipFilename) |
||
605 | Else |
||
606 | ShowMessage('Error ' + IntToStr(ConvertErr) + |
||
607 | ' occured in making .EXE file'); |
||
608 | End; |
||
609 | ZipFName.Caption := ZipMaster1.ZipFilename; |
||
610 | End; |
||
611 | |||
612 | Procedure TMainform.VerboseCBClick(Sender: TObject); |
||
613 | Begin |
||
614 | ZipMaster1.Verbose := VerboseCB.Checked; |
||
615 | End; |
||
616 | |||
617 | Procedure TMainform.TraceCBClick(Sender: TObject); |
||
618 | Begin |
||
619 | ZipMaster1.Trace := TraceCB.Checked; |
||
620 | End; |
||
621 | |||
622 | Procedure TMainform.UnattendedCBClick(Sender: TObject); |
||
623 | Begin |
||
624 | ZipMaster1.Unattended := UnattendedCB.Checked; |
||
625 | End; |
||
626 | |||
627 | Procedure TMainform.Showlasterror1Click(Sender: TObject); |
||
628 | Begin |
||
629 | If ZipMaster1.ErrCode <> 0 Then |
||
630 | ShowMessage(IntToStr(ZipMaster1.ErrCode) + ' ' + ZipMaster1.ErrMessage) |
||
631 | Else |
||
632 | ShowMessage('No last error present'); |
||
633 | End; |
||
634 | |||
635 | Procedure TMainform.Exit1Click(Sender: TObject); |
||
636 | Begin |
||
637 | Close; |
||
638 | End; |
||
639 | |||
640 | Procedure TMainform.Zipcomment1Click(Sender: TObject); |
||
641 | Begin |
||
642 | If ZipMaster1.ZipComment <> '' Then |
||
643 | Begin |
||
644 | MsgForm.Memo1.Clear; |
||
645 | MsgForm.Memo1.Lines.Add(ZipMaster1.ZipComment); |
||
646 | MsgForm.Show; |
||
647 | End |
||
648 | Else |
||
649 | ShowMessage('No Zip comment in this zip file'); |
||
650 | End; |
||
651 | |||
652 | Procedure TMainform.DLLversioninfo1Click(Sender: TObject); |
||
653 | Begin |
||
654 | // ShowMessage('UnZip Dll version: ' + IntToStr(ZipMaster1.UnzVers) + #10 + |
||
655 | // ' Zip Dll version: ' + IntToStr(ZipMaster1.ZipVers)); |
||
656 | ShowMessage(ZipMaster1.FullVersionString + #10 + ZipMaster1.Dll_Path); |
||
657 | End; |
||
658 | |||
659 | // ***********************ZipMaster Event handling*************************** |
||
660 | // --------------------------------------------------------------------------- |
||
661 | |||
662 | // This is the "OnMessage" event handler |
||
663 | |||
664 | procedure TMainform.ZipMaster1Message(Sender: TObject; ErrCode: Integer; |
||
665 | const Message: TZMString); |
||
666 | Begin |
||
667 | MsgForm.Memo1.Lines.Append(Message); |
||
668 | PostMessage(MsgForm.Memo1.Handle, EM_SCROLLCARET, 0, 0); |
||
669 | If (ErrCode > 0) And Not ZipMaster1.Unattended Then |
||
670 | ShowMessage('Error Msg: ' + Message); |
||
671 | End; |
||
672 | |||
673 | Procedure TMainform.ZipMaster1DirUpdate(Sender: TObject); |
||
674 | Begin |
||
675 | FillGrid; |
||
676 | FilesLabel.Caption := IntToStr(ZipMaster1.Count); |
||
677 | If UpperCase(ExtractFileExt(ZipMaster1.ZipFilename)) = '.EXE' Then |
||
678 | ConvertBut.Caption := 'Convert to ZIP' |
||
679 | Else |
||
680 | ConvertBut.Caption := 'Convert to EXE'; |
||
681 | End; |
||
682 | |||
683 | procedure TMainform.ZipMaster1Progress(Sender: TObject; details: |
||
684 | TZMProgressDetails); |
||
685 | begin |
||
686 | Case details.Order Of |
||
687 | TotalSize2Process: |
||
688 | Begin |
||
689 | MsgForm.StatusBar1.Panels.Items[0].Text := 'Total size: ' + IntToStr |
||
690 | (details.TotalSize Div 1024) + ' Kb'; |
||
691 | MsgForm.ProgressBar2.Position := 1; |
||
692 | MsgForm.ProgressBar1.Max := 100; |
||
693 | MsgForm.ProgressBar2.Max := 100; |
||
694 | // TotalSize2 := details.TotalSize; |
||
695 | End; |
||
696 | TotalFiles2Process: |
||
697 | Begin |
||
698 | MsgForm.StatusBar1.Panels.Items[1].Text := IntToStr(details.TotalCount) |
||
699 | + ' files'; |
||
700 | End; |
||
701 | NewFile: |
||
702 | Begin |
||
703 | MsgForm.FileBeingZipped.Caption := details.ItemName; |
||
704 | End; |
||
705 | ProgressUpdate: |
||
706 | Begin |
||
707 | MsgForm.ProgressBar1.Position := details.ItemPerCent; |
||
708 | MsgForm.ProgressBar2.Position := details.TotalPerCent; |
||
709 | End; |
||
710 | EndOfBatch: // Reset the progress bar and filename. |
||
711 | Begin |
||
712 | MsgForm.FileBeingZipped.Caption := ''; |
||
713 | MsgForm.ProgressBar1.Position := 1; |
||
714 | MsgForm.StatusBar1.Panels[0].Text := ''; |
||
715 | MsgForm.StatusBar1.Panels[1].Text := ''; |
||
716 | MsgForm.ProgressBar2.Position := 1; |
||
717 | End; |
||
718 | End; |
||
719 | |||
720 | end; |
||
721 | |||
722 | // TODO: ZipMaster1Progress |
||
723 | // procedure TMainform.ZipMaster1Progress(Sender: TObject; ProgrType: |
||
724 | // TZMProgressType; FileName: String; FileSize: Int64); |
||
725 | // Var |
||
726 | // Step: Integer; |
||
727 | // Begin |
||
728 | // Case ProgrType Of |
||
729 | // TotalSize2Process: |
||
730 | // Begin |
||
731 | // If Filename = '' Then |
||
732 | // Begin |
||
733 | // MsgForm.StatusBar1.Panels.Items[0].Text := 'Total size: ' + IntToStr(FileSize Div 1024) + ' Kb'; |
||
734 | // MsgForm.ProgressBar2.Position := 1; |
||
735 | // MsgForm.ProgressBar1.Max := 10001; |
||
736 | // TotalSize2 := FileSize; |
||
737 | // TotalProgress2 := 0; |
||
738 | // End |
||
739 | // Else |
||
740 | // Begin |
||
741 | // MsgForm.FileBeingZipped.Caption := Filename; |
||
742 | // MsgForm.ProgressBar1.Position := 1; |
||
743 | // MsgForm.ProgressBar1.Max := FileSize; |
||
744 | // End; |
||
745 | // End; |
||
746 | // TotalFiles2Process: |
||
747 | // Begin |
||
748 | // // ZipMaster1Message( self, 0, 'in OnProgress type TotalFiles, files= ' + IntToStr( FileSize ) ); |
||
749 | // If Filename = '' Then |
||
750 | // MsgForm.StatusBar1.Panels.Items[1].Text := IntToStr(FileSize) + ' files'; |
||
751 | // End; |
||
752 | // NewFile: |
||
753 | // Begin |
||
754 | // MsgForm.FileBeingZipped.Caption := Filename; |
||
755 | // MsgForm.ProgressBar1.Position := 1; // Current position of bar. |
||
756 | // TotalSize1 := FileSize; |
||
757 | // TotalProgress1 := 0; |
||
758 | // End; |
||
759 | // ProgressUpdate: |
||
760 | // Begin |
||
761 | // If Filename = '' Then |
||
762 | // Begin |
||
763 | // // ZipMaster1Message( self, 0, 'in OnProgress type Update, size= ' + IntToStr( FileSize ) ); |
||
764 | // // FileSize gives now the bytes processed since the last call. |
||
765 | // TotalProgress1 := TotalProgress1 + FileSize; |
||
766 | // TotalProgress2 := TotalProgress2 + FileSize; |
||
767 | // If TotalSize1 <> 0 Then |
||
768 | // Begin |
||
769 | // {$IFDEF VERD4+} // D4+ (D5 gives a compiler error when using Int64 conversion!?) |
||
770 | // Step := MulDiv(TotalProgress1, 10000, TotalSize1); |
||
771 | // {$ELSE} // D2 and D3 |
||
772 | // Try |
||
773 | // Step := Round(TotalProgress1 * 10000 / TotalSize1); |
||
774 | // Except |
||
775 | // Step := 2147483647; |
||
776 | // End; |
||
777 | // {$ENDIF} |
||
778 | // // ZipMaster1Message( self, 0, 'Step = ' + IntToStr( Step ) ); |
||
779 | // MsgForm.ProgressBar1.Position := 1 + Step; |
||
780 | // End |
||
781 | // Else |
||
782 | // MsgForm.ProgressBar1.Position := 10001; |
||
783 | // If TotalSize2 <> 0 Then |
||
784 | // Begin |
||
785 | // {$IFDEF VERD4+} |
||
786 | // Step := MulDiv(TotalProgress2, 10000, TotalSize2); |
||
787 | // {$ELSE} |
||
788 | // Try |
||
789 | // Step := Round(TotalProgress2 * 10000 / TotalSize2); |
||
790 | // Except |
||
791 | // Step := 2147483647; |
||
792 | // End; |
||
793 | // {$ENDIF} |
||
794 | // MsgForm.ProgressBar2.Position := 1 + Step; |
||
795 | // End; |
||
796 | // End |
||
797 | // Else |
||
798 | // Begin // non file progress |
||
799 | // MsgForm.ProgressBar1.Position := 1 + FileSize; |
||
800 | // End; |
||
801 | // End; |
||
802 | // EndOfBatch: // Reset the progress bar and filename. |
||
803 | // Begin |
||
804 | // // ZipMaster1Message( self, 0, 'in OnProgress type EndOfBatch' ); |
||
805 | // MsgForm.FileBeingZipped.Caption := ''; |
||
806 | // MsgForm.ProgressBar1.Position := 1; |
||
807 | // MsgForm.StatusBar1.Panels[0].Text := ''; |
||
808 | // MsgForm.StatusBar1.Panels[1].Text := ''; |
||
809 | // MsgForm.ProgressBar2.Position := 1; |
||
810 | // End; |
||
811 | // End; // EOF Case |
||
812 | // End; |
||
813 | |||
814 | // ***********************User defined functions ***************************** |
||
815 | // --------------------------------------------------------------------------- |
||
816 | |||
817 | Function TMainform.ShowLTime(s, f: LongInt): String; |
||
818 | Var |
||
819 | min, sec, st: Integer; |
||
820 | smin, ssec : String; |
||
821 | Begin |
||
822 | st := f - s; |
||
823 | sec := st Div 1000; |
||
824 | min := sec Div 60; |
||
825 | sec := sec Mod 60; |
||
826 | If sec > 9 Then |
||
827 | ssec := IntToStr(sec) |
||
828 | Else |
||
829 | ssec := '0' + IntToStr(sec); |
||
830 | If min > 9 Then |
||
831 | smin := IntToStr(min) |
||
832 | Else |
||
833 | smin := '0' + IntToStr(min); |
||
834 | Result := smin + ':' + ssec; |
||
835 | End; |
||
836 | |||
837 | Procedure TMainform.SetZipFName(aCaption: String; AssignName: Boolean); |
||
838 | Begin |
||
839 | // Assigning the filename will cause the table of contents to be read. |
||
840 | // and possibly reset it to an empty string (If error found). |
||
841 | If AssignName Then |
||
842 | ZipMaster1.ZipFilename := aCaption; |
||
843 | |||
844 | If ZipMaster1.ZipFilename = '' Then |
||
845 | ZipFName.Caption := AnsiString('<none>') |
||
846 | Else |
||
847 | ZipFName.Caption := MinimizeName(ZipMaster1.ZipFilename, ZipFName.Canvas, |
||
848 | ZipFName.Width); |
||
849 | |||
850 | If ZipFName.Canvas.TextWidth(ZipMaster1.ZipFilename) > ZipFName.Width Then |
||
851 | Begin |
||
852 | ZipFName.Hint := ZipMaster1.ZipFilename; |
||
853 | ZipFName.ShowHint := True; |
||
854 | End |
||
855 | Else |
||
856 | ZipFName.ShowHint := False; |
||
857 | End; |
||
858 | |||
859 | // --------------------------------------------------------------------------- |
||
860 | |||
861 | Procedure TMainform.SetZipTotals; |
||
862 | Begin |
||
863 | With StringGrid1 Do |
||
864 | Begin |
||
865 | Cells[0, RowCount - 1] := 'Total'; |
||
866 | Cells[1, RowCount - 1] := IntToStr(TotComp); |
||
867 | Cells[2, RowCount - 1] := IntToStr(TotUncomp); |
||
868 | If TotUncomp <> 0 Then |
||
869 | Cells[4, RowCount - 1] := IntToStr |
||
870 | (Round((1 - (TotComp / TotUncomp)) * 100)) + '% ' |
||
871 | Else |
||
872 | Cells[4, RowCount - 1] := '0 % '; |
||
873 | Cells[5, RowCount - 1] := ''; |
||
874 | End; |
||
875 | End; |
||
876 | |||
877 | // --------------------------------------------------------------------------- |
||
878 | |||
879 | Function TMainform.AskDirDialog(Const FormHandle: HWND; Var DirPath: String) |
||
880 | : Boolean; |
||
881 | Var |
||
882 | pidl: PItemIDList; |
||
883 | FBrowseInfo: TBrowseInfo; |
||
884 | Success: Boolean; |
||
885 | TitleName: String; |
||
886 | Buffer: Array [0 .. MAX_PATH] Of Char; |
||
887 | Begin |
||
888 | Result := False; |
||
889 | ZeroMemory(@FBrowseInfo, SizeOf(FBrowseInfo)); |
||
890 | Try |
||
891 | GetMem(FBrowseInfo.pszDisplayName, MAX_PATH); |
||
892 | FBrowseInfo.hwndOwner := FormHandle; |
||
893 | TitleName := 'Please specify a directory'; |
||
894 | FBrowseInfo.lpszTitle := PChar(TitleName); |
||
895 | pidl := ShBrowseForFolder(FBrowseInfo); |
||
896 | If pidl <> Nil Then |
||
897 | Begin |
||
898 | Success := SHGetPathFromIDList(pidl, Buffer); |
||
899 | // if False then pidl not part of namespace |
||
900 | If Success Then |
||
901 | Begin |
||
902 | DirPath := Buffer; |
||
903 | If DirPath[Length(DirPath)] <> '\' Then |
||
904 | DirPath := DirPath + '\'; |
||
905 | Result := True; |
||
906 | End; |
||
907 | GlobalFreePtr(pidl); |
||
908 | End; |
||
909 | Finally |
||
910 | If Assigned(FBrowseInfo.pszDisplayName) Then |
||
911 | FreeMem(FBrowseInfo.pszDisplayName, MAX_PATH); |
||
912 | End; |
||
913 | End; |
||
914 | |||
915 | // --------------------------------------------------------------------------- |
||
916 | { * Folder types are a.o. |
||
917 | * CSIDL_DESKTOPDIRECTORY, CSIDL_STARTMENU, CSIDL_SENDTO, |
||
918 | * CSIDL_PROGRAMS, CSIDL_STARTUP etc. |
||
919 | * } |
||
920 | |||
921 | Function TMainform.GetSpecialFolder(aFolder: Integer; Var Location: String) |
||
922 | : LongWord; |
||
923 | Var |
||
924 | pidl: PItemIDList; |
||
925 | hRes: HRESULT; |
||
926 | RealPath: Array [0 .. MAX_PATH] Of Char; |
||
927 | Success: Boolean; |
||
928 | Begin |
||
929 | Result := 0; |
||
930 | hRes := SHGetSpecialFolderLocation(Handle, aFolder, pidl); |
||
931 | If hRes = NO_ERROR Then |
||
932 | Begin |
||
933 | Success := SHGetPathFromIDList(pidl, RealPath); |
||
934 | If Success Then |
||
935 | Location := String(RealPath) + '\' |
||
936 | Else |
||
937 | Result := LongWord(E_UNEXPECTED); |
||
938 | End |
||
939 | Else |
||
940 | Result := hRes; |
||
941 | End; |
||
942 | |||
943 | // **************************Grid functions ********************************** |
||
944 | // --------------------------------------------------------------------------- |
||
945 | |||
946 | Procedure TMainform.FillGrid; |
||
947 | Const |
||
948 | sorts: Array [1 .. 6] Of TSortStyle = (ssAutomatic, ssAlphabetic, ssNumeric, |
||
949 | ssDateTime, ssTime, ssCustom); |
||
950 | Var |
||
951 | i: Integer; |
||
952 | so: TSortOptions; |
||
953 | Begin |
||
954 | With StringGrid1 Do |
||
955 | Begin |
||
956 | { remove everything from grid except col titles } |
||
957 | RowCount := 2; |
||
958 | Rows[1].Clear; |
||
959 | If ZipMaster1.Count = 0 Then |
||
960 | Exit; |
||
961 | |||
962 | StringGrid1.RowCount := ZipMaster1.Count + 2; |
||
963 | TotUncomp := 0; |
||
964 | TotComp := 0; |
||
965 | For i := 1 To ZipMaster1.Count Do |
||
966 | Begin |
||
967 | With ZipMaster1.DirEntry[i - 1] Do |
||
968 | Begin |
||
969 | Cells[0, i] := ExtractFileName(FileName); |
||
970 | Cells[1, i] := IntToStr(CompressedSize); |
||
971 | Cells[2, i] := IntToStr(UncompressedSize); |
||
972 | Cells[3, i] := FormatDateTime('ddddd t', FileDateToDateTime(DateTime)); |
||
973 | If UncompressedSize <> 0 Then |
||
974 | Cells[4, i] := IntToStr |
||
975 | (Round((1 - (CompressedSize / UncompressedSize)) * 100)) + '% ' |
||
976 | Else |
||
977 | Cells[4, i] := '0% '; |
||
978 | Cells[5, i] := ExtractFilePath(FileName); |
||
979 | TotUncomp := TotUncomp + Cardinal(UncompressedSize); |
||
980 | Inc(TotComp, CompressedSize); |
||
981 | End; // end with |
||
982 | End; // end for |
||
983 | |||
984 | so.SortDirection := sdAscending; |
||
985 | so.SortStyle := { sorts[SortColumn]; // } ssAutomatic; |
||
986 | so.SortCaseSensitive := False; |
||
987 | SortByColumn(SortColumn, so); |
||
988 | Row := 1; |
||
989 | End; // end with |
||
990 | End; |
||
991 | |||
992 | Procedure TMainform.StringGrid1EndSort(Sender: TObject; Col: LongInt); |
||
993 | Begin |
||
994 | SetZipTotals; |
||
995 | End; |
||
996 | |||
997 | Procedure TMainform.StringGrid1GetCellFormat |
||
998 | (Sender: TObject; Col, Row: LongInt; State: TGridDrawState; |
||
999 | Var FormatOptions: TFormatOptions); |
||
1000 | Begin |
||
1001 | If (Row <> 0) And (Col <> 0) And (Col <> 5) Then |
||
1002 | FormatOptions.AlignmentHorz := taRightJustify; |
||
1003 | End; |
||
1004 | |||
1005 | Procedure TMainform.RenameButClick(Sender: TObject); |
||
1006 | Begin |
||
1007 | RenForm.Show(); |
||
1008 | End; |
||
1009 | |||
1010 | // 1.72 show some activity |
||
1011 | |||
1012 | procedure TMainform.ZipMaster1Tick(Sender: TObject); |
||
1013 | Begin |
||
1014 | FNewCount := succ(FNewCount); |
||
1015 | if (FNewCount and 7) = 0 then |
||
1016 | begin |
||
1017 | FNewCount := FNewCount and 127; |
||
1018 | MsgForm.StatusBar1.Panels[0].Text := IntToStr(FNewCount); |
||
1019 | end; |
||
1020 | End; |
||
1021 | |||
1022 | End. |