-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPV_Packer.pas
93 lines (70 loc) · 2.06 KB
/
PV_Packer.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
unit PV_Packer;
{$mode objfpc}{$H+}
//PV Pack
//https://github.com/PascalVault
//Licence: MIT
//Last update: 2023-10-06
interface
uses
Classes, SysUtils, Dialogs, PV_Pack;
type
{ TPacker }
TPacker = class
private
FObj: TPack;
FFile: TFileStream;
public
constructor Create(Str: TStream; Format: String = ''); overload;
constructor Create(Filename: String; Format: String = ''); overload;
destructor Destroy; override;
function AddFile(Str: TStream; Name: String): Boolean; overload;
function AddFile(Filename: String; Name: String = ''): Boolean; overload;
procedure SetComment(Comment: String);
end;
implementation
uses PV_Zip, PV_BH, PV_Bga, PV_Tar, PV_Lzh, PV_Arj, PV_Rar, PV_Zoo, PV_Gzip, PV_Arc, PV_Ace;
{ TPacker }
constructor TPacker.Create(Str: TStream; Format: String = '');
begin
Format := LowerCase(Format);
case Format of
'zip': FObj := TZip.Create(Str);
'bh' : FObj := TBH.Create(Str);
'bga': FObj := TBga.Create(Str);
'lzh': FObj := TLzh.Create(Str);
'arj': FObj := TArj.Create(Str);
'tar': FObj := TTar.Create(Str);
'rar': FObj := TRar.Create(Str);
'zoo': FObj := TZoo.Create(Str);
'arc': FObj := TArc.Create(Str);
'ace': FObj := TAce.Create(Str);
'gz': FObj := TGzip.Create(Str);
end;
end;
constructor TPacker.Create(Filename: String; Format: String);
begin
FFile := TFileStream.Create(Filename, fmCreate or fmShareDenyWrite);
Create(FFile, Format);
end;
destructor TPacker.Destroy;
begin
FObj.Destroy;
if FFile <> nil then FFile.Free;
end;
function TPacker.AddFile(Str: TStream; Name: String): Boolean;
begin
FObj.AddFile(Str, Name);
end;
function TPacker.AddFile(Filename: String; Name: String): Boolean;
var F: TFileStream;
begin
if Name = '' then Name := ExtractFileName(Filename);
F := TFileStream.Create(Filename, fmOpenRead or fmShareDenyNone);
FObj.AddFile(F, Name);
F.Free;
end;
procedure TPacker.SetComment(Comment: String);
begin
FOBj.SetComment(Comment);
end;
end.