forked from Memnarch/Delphinus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DN.Zip.pas
61 lines (51 loc) · 1.76 KB
/
DN.Zip.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{
#########################################################
# Copyright by Alexander Benikowski #
# This unit is part of the Delphinus project hosted on #
# https://github.com/Memnarch/Delphinus #
#########################################################
}
unit DN.Zip;
interface
//code taken from
//http://www.tmssoftware.com/site/blog.asp?post=146
//and FIXED with the help of Delphi-Praxis
//http://www.delphipraxis.net/988492-post9.html
//apparently you can't use a string as namespace directly but have to convert it to OLEVariant
function ShellUnzip(AZipFile, ATargetFolder: string; AFilter: string = ''): boolean;
//procedure DecompressFiles(const Filename, DestDirectory : String);
implementation
uses
ZLib,
Classes,
SysUtils,
Comobj,
Windows,
Tlhelp32;
const
SHCONTCH_NOPROGRESSBOX = 4;
SHCONTCH_AUTORENAME = 8;
SHCONTCH_RESPONDYESTOALL = 16;
SHCONTF_INCLUDEHIDDEN = 128;
SHCONTF_FOLDERS = 32;
SHCONTF_NONFOLDERS = 64;
function ShellUnzip(AZipFile, ATargetFolder: string; AFilter: string = ''): boolean;
var
LShellObject: Variant;
LSourceFolder, LTargetFolder: Variant;
LShellFolderItems: Variant;
begin
try
LShellObject := CreateOleObject('Shell.Application');
LSourceFolder := LShellObject.NameSpace(OLEVariant(AZipFile));
LTargetFolder := LShellObject.NameSpace(OLEVariant(ATargetFolder));
LShellFolderItems := LSourceFolder.Items;
if (AFilter <> '') then
LShellFolderItems.Filter(SHCONTF_INCLUDEHIDDEN or SHCONTF_NONFOLDERS or SHCONTF_FOLDERS, AFilter);
LTargetFolder.CopyHere(LShellFolderItems, SHCONTCH_NOPROGRESSBOX or SHCONTCH_RESPONDYESTOALL);
Result := True;
except
Result := False;
end;
end;
end.