-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathunit1.pas
113 lines (84 loc) · 2.12 KB
/
unit1.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, sevenzip7;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button4: TButton;
Memo1: TMemo;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var i: Integer;
begin
with CreateOutArchive(CLSID_CFormat7z) do
begin
AddFile('7z.dll', 'Name In Archive.dll');
SaveToFile('archive.7z');
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var i: Integer;
Guid: TGuid;
Filename: String;
begin
if not OpenDialog1.Execute then Exit;
Filename := OpenDialog1.Filename;
Guid := DetectFormat(Filename);
if IsEqualGUID(Guid, CLSID_CFormat_Unsupported) then begin
ShowMessage('Unsupported');
Exit;
end;
with CreateInArchive(Guid) do begin
OpenFile(Filename);
for i := 0 to NumberOfItems - 1 do
if not ItemIsFolder[i] then
Memo1.Lines.Add(
ItemPath[i] + ' == ' + GetItemCRC(i) +
ItemComment[i] +IntToStr(GetItemPackSize(i)) + ' ' +
FormatDateTime('YYYY-MM-DD', GetItemModDate(i))
);
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
var Guid: TGuid;
i: Integer;
str: TStringStream;
S: String;
begin
if not OpenDialog1.Execute then Exit;
Guid := DetectFormat(OpenDialog1.Filename);
if IsEqualGUID(Guid, CLSID_CFormat_Unsupported) then begin
ShowMessage('Unsupported');
Exit;
end;
S := '';
Str := TStringStream.Create(S);
with CreateInArchive(Guid) do
begin
OpenFile(OpenDialog1.Filename);
for i := 0 to NumberOfItems - 1 do
if not ItemIsFolder[i] then begin
ExtractItem(i, str, false);
break;
end;
end;
S := Str.DataString;
str.free;
Memo1.Lines.Text := S;
end;
end.