Debian Codegraph @

plugins/wcx/zip/src/fparchive/abselfex.pas

raw
1 (* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Original Code is TurboPower Abbrevia
15 *
16 * The Initial Developer of the Original Code is
17 * TurboPower Software
18 *
19 * Portions created by the Initial Developer are Copyright (C) 1997-2002
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * ***** END LICENSE BLOCK ***** *)
25
26 {*********************************************************}
27 {* ABBREVIA: AbSelfEx.pas *}
28 {*********************************************************}
29 {* ABBREVIA: Component for building self-extracting zips *}
30 {*********************************************************}
31
32 unit AbSelfEx;
33
34 {$I AbDefine.inc}
35
36 interface
37
38 uses
39 Classes,
40 AbBase;
41
42 type
43 TAbGetFileEvent = procedure(Sender : TObject; var aFilename : string;
44 var Abort : Boolean) of object;
45
46 type
47 TAbMakeSelfExe = class(TAbBaseComponent)
48 protected {private}
49 FStubExe : string;
50 FZipFile : string;
51 FSelfExe : string;
52 FStubStream : TStream;
53 FZipStream : TStream;
54 FSelfStream : TStream;
55 FOnGetStubExe : TAbGetFileEvent;
56 FOnGetZipFile : TAbGetFileEvent;
57
58 procedure DoGetStubExe(var Abort : Boolean);
59 procedure DoGetZipFile(var Abort : Boolean);
60
61 public
62 function Execute : Boolean;
63
64 published
65 property SelfExe : string
66 read FSelfExe
67 write FSelfExe;
68 property StubExe : string
69 read FStubExe
70 write FStubExe;
71 property ZipFile : string
72 read FZipFile
73 write FZipFile;
74 property OnGetStubExe : TAbGetFileEvent
75 read FOnGetStubExe
76 write FOnGetStubExe;
77 property OnGetZipFile : TAbGetFileEvent
78 read FOnGetZipFile
79 write FOnGetZipFile;
80 property Version;
81 end;
82
83
84 implementation
85
86 uses
87 SysUtils,
88 {$IFDEF LibcAPI}
89 Libc,
90 {$ENDIF}
91 AbExcept, AbZipTyp, DCOSUtils, DCClassesUtf8;
92
93 { -------------------------------------------------------------------------- }
94 function TAbMakeSelfExe.Execute : Boolean;
95 var
96 Abort : Boolean;
97 begin
98 Abort := False;
99 if (FStubExe = '') then
100 DoGetStubExe(Abort);
101 if Abort then
102 raise EAbUserAbort.Create;
103 if not mbFileExists(FStubExe) then
104 raise EAbFileNotFound.Create;
105 if (FZipFile = '') then
106 DoGetZipFile(Abort);
107 if Abort then
108 raise EAbUserAbort.Create;
109 if not mbFileExists(FZipFile) then
110 raise EAbFileNotFound.Create;
111
112 FStubStream := TFileStreamEx.Create(FStubExe, fmOpenRead or fmShareDenyWrite);
113 FZipStream := TFileStreamEx.Create(FZipFile, fmOpenRead or fmShareDenyWrite);
114 if (FSelfExe = '') then
115 FSelfExe := ChangeFileExt(FZipFile, '.exe');
116 FSelfStream := TFileStreamEx.Create(FSelfExe, fmCreate or fmShareExclusive);
117 try
118 MakeSelfExtracting(FStubStream, FZipStream, FSelfStream);
119 Result := True;
120 finally
121 FStubStream.Free;
122 FZipStream.Free;
123 FSelfStream.Free;
124 end;
125 end;
126 { -------------------------------------------------------------------------- }
127 procedure TAbMakeSelfExe.DoGetStubExe(var Abort: Boolean);
128 begin
129 if Assigned(FOnGetStubExe) then
130 FOnGetStubExe(Self, FStubExe, Abort);
131 end;
132 { -------------------------------------------------------------------------- }
133 procedure TAbMakeSelfExe.DoGetZipFile(var Abort : Boolean);
134 begin
135 if Assigned(FOnGetZipFile) then
136 FOnGetZipFile(Self, FZipFile, Abort);
137 end;
138 { -------------------------------------------------------------------------- }
139
140 end.