Rev 1 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1 | Rev 4 | ||
---|---|---|---|
Line 8... | Line 8... | ||
8 | uses |
8 | uses |
9 | SysUtils, |
9 | SysUtils, |
10 | Windows, |
10 | Windows, |
11 | Classes, |
11 | Classes, |
12 | ZipMstr19, |
12 | ZipMstr19, |
- | 13 | Dialogs, |
|
13 | Functions in 'Functions.pas', |
14 | Functions in 'Functions.pas', |
14 | SFXBehavior in 'SFXBehavior.pas'; |
15 | SFXBehavior in 'SFXBehavior.pas'; |
15 | 16 | ||
16 | const |
17 | const |
17 | Extractor_EXE = 'Extractor.exe'; |
18 | Extractor_EXE = 'Extractor.exe'; |
18 | SIGN_BAT = 'Tools\VTSSign.bat'; |
19 | SIGN_BAT = 'Tools\VTSSign.bat'; |
19 | ZIP_EXE = 'Tools\zip.exe'; |
20 | ZIP_EXE = 'Tools\zip.exe'; |
20 | RemoveSignature_EXE = 'Tools\RemoveSignature.exe'; |
21 | RemoveSignature_EXE = 'Tools\RemoveSignature.exe'; |
21 | 22 | ||
- | 23 | procedure DoMakeSFX(AFilename: string); |
|
22 | var |
24 | var |
23 | Src, Dst: string; |
25 | Dst: string; |
24 | i: integer; |
- | |
25 | s1, s2: TFileStream; |
26 | s1, s2: TFileStream; |
26 | x: TZipMaster19; |
27 | x: TZipMaster19; |
27 | - | ||
28 | resourcestring |
28 | resourcestring |
29 | ImportantFileNotFound = 'Error: Important file "%s" not found!'; |
- | |
30 | LngErrorWhileCopy = 'Error: Could not copy "%s" to "%s".'; |
29 | LngErrorWhileCopy = 'Error: Could not copy "%s" to "%s".'; |
31 | LngErrorWhileExecuting = 'Error while executing "%s".'; |
30 | LngErrorWhileExecuting = 'Error while executing "%s".'; |
32 | SourceFileNotFound = 'Source file "%s" not found.'; |
31 | SourceFileNotFound = 'Source file "%s" not found.'; |
33 | Lng_In = 'Input:'; |
32 | Lng_In = 'Input:'; |
34 | Lng_Out = 'Output:'; |
33 | Lng_Out = 'Output:'; |
Line 36... | Line 35... | ||
36 | Lng_Append = 'Append ZIP to Extractor template...'; |
35 | Lng_Append = 'Append ZIP to Extractor template...'; |
37 | Lng_Adjust = 'Adjust the ZIP offset of the SFX...'; |
36 | Lng_Adjust = 'Adjust the ZIP offset of the SFX...'; |
38 | Lng_ModifyZIPComment = 'Modify ZIP Comment...'; |
37 | Lng_ModifyZIPComment = 'Modify ZIP Comment...'; |
39 | Lng_SignSfx = 'Sign the SFX...'; |
38 | Lng_SignSfx = 'Sign the SFX...'; |
40 | Lng_Finished = 'Finished! :-)'; |
39 | Lng_Finished = 'Finished! :-)'; |
- | 40 | begin |
|
41 | Lng_Title = 'ViaThinkSoft AutoSFX'; |
41 | if not FileExists(AFilename) then |
42 | Lng_Usage1 = 'Usage:'; |
42 | begin |
43 | Lng_Usage2 = 'MakeSFX [File1.zip [File2.zip...]]'; |
43 | WriteLn(Format(SourceFileNotFound, [AFilename])); |
- | 44 | {$IFDEF DELAY_ON_ERROR} |
|
- | 45 | Sleep(2000); |
|
- | 46 | {$ENDIF} |
|
- | 47 | ExitCode := 1; |
|
- | 48 | Exit; |
|
- | 49 | end; |
|
44 | 50 | ||
45 | {$R *.res} |
51 | Dst := ChangeFileExt(AFilename, '.exe'); |
46 | 52 | ||
47 | begin |
- | |
48 | WriteLn(Lng_Title); |
- | |
49 | WriteLn(''); |
- | |
50 | WriteLn(Lng_Usage1); |
53 | WriteLn(Format(Lng_In+#9+'%s', [AFilename])); |
51 | WriteLn(Lng_Usage2); |
54 | WriteLn(Format(Lng_Out+#9+'%s', [Dst])); |
52 | WriteLn(''); |
55 | WriteLn(''); |
53 | 56 | ||
54 | if not FileExists(ExtractFilePath(ParamStr(0)) + Extractor_EXE) then |
57 | if not RawFileCopy(ExtractFilePath(ParamStr(0)) + Extractor_EXE, Dst) then |
55 | begin |
58 | begin |
56 | WriteLn(Format(ImportantFileNotFound, [Extractor_EXE])); |
59 | WriteLn(Format(LngErrorWhileCopy, [Extractor_EXE, Dst])); |
57 | {$IFDEF DELAY_ON_ERROR} |
60 | {$IFDEF DELAY_ON_ERROR} |
58 | Sleep(2000); |
61 | Sleep(2000); |
59 | {$ENDIF} |
62 | {$ENDIF} |
60 | ExitCode := 2; |
63 | ExitCode := 1; |
61 | Exit; |
64 | Exit; |
62 | end; |
65 | end; |
63 | 66 | ||
64 | for i := 1 to ParamCount do |
67 | // Remove the signature of Extractor first (otherwise signing will fail later) |
65 | begin |
- | |
66 | Src := ParamStr(i); |
- | |
67 | 68 | ||
68 | if not FileExists(Src) then |
69 | WriteLn(#9 + Lng_RemoveSig); |
- | 70 | ||
- | 71 | if not ShellExecuteAndWait(ExtractFilePath(ParamStr(0)) + RemoveSignature_EXE, PChar('"' + ExpandUNCFileName(Dst) + '"')) then |
|
69 | begin |
72 | begin |
70 | WriteLn(Format(SourceFileNotFound, [Src])); |
73 | WriteLn(Format(LngErrorWhileExecuting, [RemoveSignature_EXE])); |
- | 74 | {$IFDEF BREAK_ON_CERT_FAILURE} |
|
- | 75 | DeleteFile(PChar(Dst)); |
|
71 | {$IFDEF DELAY_ON_ERROR} |
76 | {$IFDEF DELAY_ON_ERROR} |
72 | Sleep(2000); |
77 | Sleep(2000); |
73 | {$ENDIF} |
78 | {$ENDIF} |
74 | ExitCode := 1; |
79 | ExitCode := 1; |
75 | Continue; |
80 | Exit; |
- | 81 | {$ENDIF} |
|
76 | end; |
82 | end; |
77 | 83 | ||
78 | Dst := ChangeFileExt(Src, '.exe'); |
84 | WriteLn(#9 + Lng_Append); |
79 | 85 | ||
80 | WriteLn(Format(Lng_In+#9+'%s', [Src])); |
86 | s1 := TFileStream.Create(Dst, fmOpenWrite); |
81 | WriteLn(Format(Lng_Out+#9+'%s', [Dst])); |
87 | try |
82 | WriteLn(''); |
88 | s1.Seek(0, soEnd); |
83 | 89 | ||
84 | if not RawFileCopy(ExtractFilePath(ParamStr(0)) + Extractor_EXE, Dst) then |
90 | s2 := TFileStream.Create(AFilename, fmOpenRead or fmShareDenyWrite); |
85 | begin |
91 | try |
86 | WriteLn(Format(LngErrorWhileCopy, [Extractor_EXE, Dst])); |
- | |
87 | {$IFDEF DELAY_ON_ERROR} |
92 | s1.CopyFrom(s2, s2.Size); |
88 | Sleep(2000); |
- | |
89 | {$ENDIF} |
93 | finally |
90 | ExitCode := 1; |
- | |
91 | Continue; |
94 | s2.Free; |
92 | end; |
95 | end; |
- | 96 | finally |
|
- | 97 | s1.Free; |
|
- | 98 | end; |
|
93 | 99 | ||
94 | // Remove the signature of Extractor first (otherwise signing will fail later) |
100 | WriteLn(#9 + Lng_Adjust); |
95 | 101 | ||
- | 102 | if not ShellExecuteAndWait(ExtractFilePath(ParamStr(0)) + ZIP_EXE, PChar('-A "' + ExpandUNCFileName(Dst) + '"')) then |
|
- | 103 | begin |
|
- | 104 | DeleteFile(PChar(Dst)); |
|
96 | WriteLn(#9 + Lng_RemoveSig); |
105 | WriteLn(Format(LngErrorWhileExecuting, [ZIP_EXE])); |
- | 106 | {$IFDEF DELAY_ON_ERROR} |
|
- | 107 | Sleep(2000); |
|
- | 108 | {$ENDIF} |
|
- | 109 | ExitCode := 1; |
|
- | 110 | Exit; |
|
- | 111 | end; |
|
97 | 112 | ||
98 | if not ShellExecuteAndWait(ExtractFilePath(ParamStr(0)) + RemoveSignature_EXE, PChar('"' + ExpandUNCFileName(Dst) + '"')) then |
- | |
99 | begin |
- | |
100 | WriteLn(Format(LngErrorWhileExecuting, [RemoveSignature_EXE])); |
- | |
101 | {$IFDEF BREAK_ON_CERT_FAILURE} |
- | |
102 | DeleteFile(PChar(Dst)); |
113 | WriteLn(#9 + Lng_ModifyZIPComment); |
103 | {$IFDEF DELAY_ON_ERROR} |
- | |
104 | Sleep(2000); |
- | |
105 | {$ENDIF} |
- | |
106 | ExitCode := 1; |
- | |
107 | Continue; |
- | |
108 | {$ENDIF} |
- | |
109 | end; |
- | |
110 | 114 | ||
111 | WriteLn(#9 + Lng_Append); |
115 | x := TZipMaster19.Create(nil); |
- | 116 | try |
|
- | 117 | x.ZipFileName := Dst; |
|
112 | 118 | ||
113 | s1 := TFileStream.Create(Dst, fmOpenWrite); |
- | |
114 | try |
- | |
115 | s1.Seek(0, soEnd); |
119 | // Correct CRLFs |
116 | 120 | ||
117 | s2 := TFileStream.Create(Src, fmOpenRead or fmShareDenyWrite); |
121 | x.ZipComment := NormalizeLineBreaks(x.ZipComment, lbWindows); |
118 | try |
- | |
119 | s1.CopyFrom(s2, s2.Size); |
- | |
120 | finally |
- | |
121 | s2.Free; |
- | |
122 | end; |
- | |
123 | finally |
- | |
124 | s1.Free; |
- | |
125 | end; |
- | |
126 | 122 | ||
127 | WriteLn(#9 + Lng_Adjust); |
123 | // Ensure we have 2 CRLF before old comment |
128 | 124 | ||
129 | if not ShellExecuteAndWait(ExtractFilePath(ParamStr(0)) + ZIP_EXE, PChar('-A "' + ExpandUNCFileName(Dst) + '"')) then |
125 | x.ZipComment := TrimRight(x.ZipComment); |
- | 126 | if x.ZipComment <> '' then |
|
130 | begin |
127 | begin |
131 | DeleteFile(PChar(Dst)); |
- | |
132 | WriteLn(Format(LngErrorWhileExecuting, [ZIP_EXE])); |
128 | x.ZipComment := x.ZipComment + #13#10 + #13#10; |
133 | {$IFDEF DELAY_ON_ERROR} |
- | |
134 | Sleep(2000); |
- | |
135 | {$ENDIF} |
- | |
136 | ExitCode := 1; |
- | |
137 | Continue; |
- | |
138 | end; |
129 | end; |
139 | 130 | ||
140 | WriteLn(#9 + Lng_ModifyZIPComment); |
- | |
141 | - | ||
142 | x := TZipMaster19.Create(nil); |
131 | // Read, strip and re-add behavior (inclusive signature) |
143 | try |
- | |
144 | x.ZipFileName := Dst; |
- | |
145 | 132 | ||
- | 133 | x.ZipComment := RelocateBehaviorStringsToEnd(x.ZipComment); |
|
- | 134 | finally |
|
146 | // Correct CRLFs |
135 | x.Free; |
- | 136 | end; |
|
147 | 137 | ||
- | 138 | // Read filesize + zip-comment length |
|
- | 139 | // (So we can later extend the zip-comment to include the certificate |
|
148 | x.ZipComment := NormalizeLineBreaks(x.ZipComment, lbWindows); |
140 | // => The archive is then not corrupt because of 'garbage' at the end) |
149 | 141 | ||
150 | // Ensure we have 2 CRLF before old comment |
142 | WriteLn(#9 + Lng_SignSfx); |
151 | 143 | ||
- | 144 | if not ShellExecuteAndWait(ExtractFilePath(ParamStr(0)) + SIGN_BAT, PChar('"' + ExpandUNCFileName(Dst) + '"')) then |
|
- | 145 | begin |
|
152 | x.ZipComment := TrimRight(x.ZipComment); |
146 | WriteLn(Format(LngErrorWhileExecuting, [SIGN_BAT])); |
- | 147 | {$IFDEF BREAK_ON_CERT_FAILURE} |
|
153 | if x.ZipComment <> '' then |
148 | DeleteFile(PChar(Dst)); |
- | 149 | {$IFDEF DELAY_ON_ERROR} |
|
- | 150 | Sleep(2000); |
|
154 | begin |
151 | {$ENDIF} |
155 | x.ZipComment := x.ZipComment + #13#10 + #13#10; |
152 | ExitCode := 1; |
- | 153 | Exit; |
|
- | 154 | {$ENDIF} |
|
156 | end; |
155 | end; |
157 | 156 | ||
158 | // Read, strip and re-add behavior (inclusive signature) |
157 | WriteLn(#9 + Lng_Finished); |
- | 158 | WriteLn(''); |
|
- | 159 | end; |
|
159 | 160 | ||
160 | x.ZipComment := RelocateBehaviorStringsToEnd(x.ZipComment); |
- | |
161 | finally |
- | |
162 | x.Free; |
161 | {$R *.res} |
163 | end; |
- | |
164 | 162 | ||
- | 163 | var |
|
- | 164 | i: integer; |
|
- | 165 | od: TOpenDialog; |
|
- | 166 | resourcestring |
|
165 | // Read filesize + zip-comment length |
167 | Lng_Title = 'ViaThinkSoft AutoSFX'; |
- | 168 | Lng_Usage1 = 'Usage:'; |
|
166 | // (So we can later extend the zip-comment to include the certificate |
169 | Lng_Usage2 = 'MakeSFX [File1.zip [File2.zip...]]'; |
167 | // => The archive is then not corrupt because of 'garbage' at the end) |
170 | ImportantFileNotFound = 'Error: Important file "%s" not found!'; |
- | 171 | begin |
|
- | 172 | WriteLn(Lng_Title); |
|
- | 173 | WriteLn(''); |
|
- | 174 | WriteLn(Lng_Usage1); |
|
- | 175 | WriteLn(Lng_Usage2); |
|
- | 176 | WriteLn(''); |
|
168 | 177 | ||
- | 178 | if not FileExists(ExtractFilePath(ParamStr(0)) + Extractor_EXE) then |
|
- | 179 | begin |
|
- | 180 | WriteLn(Format(ImportantFileNotFound, [Extractor_EXE])); |
|
169 | WriteLn(#9 + Lng_SignSfx); |
181 | {$IFDEF DELAY_ON_ERROR} |
- | 182 | Sleep(2000); |
|
- | 183 | {$ENDIF} |
|
- | 184 | ExitCode := 2; |
|
- | 185 | Exit; |
|
- | 186 | end; |
|
170 | 187 | ||
- | 188 | if ParamCount = 0 then |
|
- | 189 | begin |
|
- | 190 | od := TOpenDialog.Create(nil); |
|
- | 191 | try |
|
- | 192 | od.DefaultExt := '.zip'; |
|
171 | if not ShellExecuteAndWait(ExtractFilePath(ParamStr(0)) + SIGN_BAT, PChar('"' + ExpandUNCFileName(Dst) + '"')) then |
193 | od.Filter := 'ZIP-Archiv (*.zip)|*.zip|Alle Dateien (*.*)|*.*'; |
- | 194 | od.Options := [ofAllowMultiSelect, ofFileMustExist, ofHideReadOnly, |
|
- | 195 | ofPathMustExist, ofEnableSizing]; |
|
- | 196 | if od.Execute then |
|
- | 197 | begin |
|
- | 198 | for i := 0 to od.Files.Count - 1 do |
|
- | 199 | begin |
|
- | 200 | DoMakeSFX(od.Files.Strings[i]); |
|
- | 201 | end; |
|
- | 202 | end; |
|
- | 203 | finally |
|
- | 204 | od.Free; |
|
- | 205 | end; |
|
- | 206 | end |
|
- | 207 | else |
|
- | 208 | begin |
|
- | 209 | for i := 1 to ParamCount do |
|
172 | begin |
210 | begin |
173 | WriteLn(Format(LngErrorWhileExecuting, [SIGN_BAT])); |
- | |
174 | {$IFDEF BREAK_ON_CERT_FAILURE} |
- | |
175 | DeleteFile(PChar(Dst)); |
211 | DoMakeSFX(ParamStr(i)); |
176 | {$IFDEF DELAY_ON_ERROR} |
- | |
177 | Sleep(2000); |
- | |
178 | {$ENDIF} |
- | |
179 | ExitCode := 1; |
- | |
180 | Continue; |
- | |
181 | {$ENDIF} |
- | |
182 | end; |
212 | end; |
183 | - | ||
184 | WriteLn(#9 + Lng_Finished); |
- | |
185 | WriteLn(''); |
- | |
186 | end; |
213 | end; |
187 | 214 | ||
188 | // TODO: Es gibt bei Win2000 außerhalb des debuggers eine AV... |
215 | // TODO: Es gibt bei Win2000 außerhalb des debuggers eine AV... |
189 | end. |
216 | end. |