10,7 → 10,6 |
Windows, |
Classes, |
ZipMstr19, |
Dialogs, |
Functions in 'Functions.pas', |
SFXBehavior in 'SFXBehavior.pas'; |
|
20,12 → 19,14 |
ZIP_EXE = 'Tools\zip.exe'; |
RemoveSignature_EXE = 'Tools\RemoveSignature.exe'; |
|
procedure DoMakeSFX(AFilename: string); |
var |
Dst: string; |
Src, Dst: string; |
i: integer; |
s1, s2: TFileStream; |
x: TZipMaster19; |
|
resourcestring |
ImportantFileNotFound = 'Error: Important file "%s" not found!'; |
LngErrorWhileCopy = 'Error: Could not copy "%s" to "%s".'; |
LngErrorWhileExecuting = 'Error while executing "%s".'; |
SourceFileNotFound = 'Source file "%s" not found.'; |
37,179 → 38,151 |
Lng_ModifyZIPComment = 'Modify ZIP Comment...'; |
Lng_SignSfx = 'Sign the SFX...'; |
Lng_Finished = 'Finished! :-)'; |
begin |
if not FileExists(AFilename) then |
begin |
WriteLn(Format(SourceFileNotFound, [AFilename])); |
{$IFDEF DELAY_ON_ERROR} |
Sleep(2000); |
{$ENDIF} |
ExitCode := 1; |
Exit; |
end; |
Lng_Title = 'ViaThinkSoft AutoSFX'; |
Lng_Usage1 = 'Usage:'; |
Lng_Usage2 = 'MakeSFX [File1.zip [File2.zip...]]'; |
|
Dst := ChangeFileExt(AFilename, '.exe'); |
{$R *.res} |
|
WriteLn(Format(Lng_In+#9+'%s', [AFilename])); |
WriteLn(Format(Lng_Out+#9+'%s', [Dst])); |
begin |
WriteLn(Lng_Title); |
WriteLn(''); |
WriteLn(Lng_Usage1); |
WriteLn(Lng_Usage2); |
WriteLn(''); |
|
if not RawFileCopy(ExtractFilePath(ParamStr(0)) + Extractor_EXE, Dst) then |
if not FileExists(ExtractFilePath(ParamStr(0)) + Extractor_EXE) then |
begin |
WriteLn(Format(LngErrorWhileCopy, [Extractor_EXE, Dst])); |
WriteLn(Format(ImportantFileNotFound, [Extractor_EXE])); |
{$IFDEF DELAY_ON_ERROR} |
Sleep(2000); |
{$ENDIF} |
ExitCode := 1; |
ExitCode := 2; |
Exit; |
end; |
|
// Remove the signature of Extractor first (otherwise signing will fail later) |
for i := 1 to ParamCount do |
begin |
Src := ParamStr(i); |
|
WriteLn(#9 + Lng_RemoveSig); |
if not FileExists(Src) then |
begin |
WriteLn(Format(SourceFileNotFound, [Src])); |
{$IFDEF DELAY_ON_ERROR} |
Sleep(2000); |
{$ENDIF} |
ExitCode := 1; |
Continue; |
end; |
|
if not ShellExecuteAndWait(ExtractFilePath(ParamStr(0)) + RemoveSignature_EXE, PChar('"' + ExpandUNCFileName(Dst) + '"')) then |
begin |
WriteLn(Format(LngErrorWhileExecuting, [RemoveSignature_EXE])); |
{$IFDEF BREAK_ON_CERT_FAILURE} |
DeleteFile(PChar(Dst)); |
{$IFDEF DELAY_ON_ERROR} |
Sleep(2000); |
{$ENDIF} |
ExitCode := 1; |
Exit; |
{$ENDIF} |
end; |
Dst := ChangeFileExt(Src, '.exe'); |
|
WriteLn(#9 + Lng_Append); |
WriteLn(Format(Lng_In+#9+'%s', [Src])); |
WriteLn(Format(Lng_Out+#9+'%s', [Dst])); |
WriteLn(''); |
|
s1 := TFileStream.Create(Dst, fmOpenWrite); |
try |
s1.Seek(0, soEnd); |
|
s2 := TFileStream.Create(AFilename, fmOpenRead or fmShareDenyWrite); |
try |
s1.CopyFrom(s2, s2.Size); |
finally |
s2.Free; |
if not RawFileCopy(ExtractFilePath(ParamStr(0)) + Extractor_EXE, Dst) then |
begin |
WriteLn(Format(LngErrorWhileCopy, [Extractor_EXE, Dst])); |
{$IFDEF DELAY_ON_ERROR} |
Sleep(2000); |
{$ENDIF} |
ExitCode := 1; |
Continue; |
end; |
finally |
s1.Free; |
end; |
|
WriteLn(#9 + Lng_Adjust); |
// Remove the signature of Extractor first (otherwise signing will fail later) |
|
if not ShellExecuteAndWait(ExtractFilePath(ParamStr(0)) + ZIP_EXE, PChar('-A "' + ExpandUNCFileName(Dst) + '"')) then |
begin |
DeleteFile(PChar(Dst)); |
WriteLn(Format(LngErrorWhileExecuting, [ZIP_EXE])); |
{$IFDEF DELAY_ON_ERROR} |
Sleep(2000); |
{$ENDIF} |
ExitCode := 1; |
Exit; |
end; |
WriteLn(#9 + Lng_RemoveSig); |
|
WriteLn(#9 + Lng_ModifyZIPComment); |
if not ShellExecuteAndWait(ExtractFilePath(ParamStr(0)) + RemoveSignature_EXE, PChar('"' + ExpandUNCFileName(Dst) + '"')) then |
begin |
WriteLn(Format(LngErrorWhileExecuting, [RemoveSignature_EXE])); |
{$IFDEF BREAK_ON_CERT_FAILURE} |
DeleteFile(PChar(Dst)); |
{$IFDEF DELAY_ON_ERROR} |
Sleep(2000); |
{$ENDIF} |
ExitCode := 1; |
Continue; |
{$ENDIF} |
end; |
|
x := TZipMaster19.Create(nil); |
try |
x.ZipFileName := Dst; |
WriteLn(#9 + Lng_Append); |
|
// Correct CRLFs |
s1 := TFileStream.Create(Dst, fmOpenWrite); |
try |
s1.Seek(0, soEnd); |
|
x.ZipComment := NormalizeLineBreaks(x.ZipComment, lbWindows); |
s2 := TFileStream.Create(Src, fmOpenRead or fmShareDenyWrite); |
try |
s1.CopyFrom(s2, s2.Size); |
finally |
s2.Free; |
end; |
finally |
s1.Free; |
end; |
|
// Ensure we have 2 CRLF before old comment |
WriteLn(#9 + Lng_Adjust); |
|
x.ZipComment := TrimRight(x.ZipComment); |
if x.ZipComment <> '' then |
if not ShellExecuteAndWait(ExtractFilePath(ParamStr(0)) + ZIP_EXE, PChar('-A "' + ExpandUNCFileName(Dst) + '"')) then |
begin |
x.ZipComment := x.ZipComment + #13#10 + #13#10; |
DeleteFile(PChar(Dst)); |
WriteLn(Format(LngErrorWhileExecuting, [ZIP_EXE])); |
{$IFDEF DELAY_ON_ERROR} |
Sleep(2000); |
{$ENDIF} |
ExitCode := 1; |
Continue; |
end; |
|
// Read, strip and re-add behavior (inclusive signature) |
WriteLn(#9 + Lng_ModifyZIPComment); |
|
x.ZipComment := RelocateBehaviorStringsToEnd(x.ZipComment); |
finally |
x.Free; |
end; |
x := TZipMaster19.Create(nil); |
try |
x.ZipFileName := Dst; |
|
// Read filesize + zip-comment length |
// (So we can later extend the zip-comment to include the certificate |
// => The archive is then not corrupt because of 'garbage' at the end) |
// Correct CRLFs |
|
WriteLn(#9 + Lng_SignSfx); |
x.ZipComment := NormalizeLineBreaks(x.ZipComment, lbWindows); |
|
if not ShellExecuteAndWait(ExtractFilePath(ParamStr(0)) + SIGN_BAT, PChar('"' + ExpandUNCFileName(Dst) + '"')) then |
begin |
WriteLn(Format(LngErrorWhileExecuting, [SIGN_BAT])); |
{$IFDEF BREAK_ON_CERT_FAILURE} |
DeleteFile(PChar(Dst)); |
{$IFDEF DELAY_ON_ERROR} |
Sleep(2000); |
{$ENDIF} |
ExitCode := 1; |
Exit; |
{$ENDIF} |
end; |
// Ensure we have 2 CRLF before old comment |
|
WriteLn(#9 + Lng_Finished); |
WriteLn(''); |
end; |
x.ZipComment := TrimRight(x.ZipComment); |
if x.ZipComment <> '' then |
begin |
x.ZipComment := x.ZipComment + #13#10 + #13#10; |
end; |
|
{$R *.res} |
// Read, strip and re-add behavior (inclusive signature) |
|
var |
i: integer; |
od: TOpenDialog; |
resourcestring |
Lng_Title = 'ViaThinkSoft AutoSFX'; |
Lng_Usage1 = 'Usage:'; |
Lng_Usage2 = 'MakeSFX [File1.zip [File2.zip...]]'; |
ImportantFileNotFound = 'Error: Important file "%s" not found!'; |
begin |
WriteLn(Lng_Title); |
WriteLn(''); |
WriteLn(Lng_Usage1); |
WriteLn(Lng_Usage2); |
WriteLn(''); |
x.ZipComment := RelocateBehaviorStringsToEnd(x.ZipComment); |
finally |
x.Free; |
end; |
|
if not FileExists(ExtractFilePath(ParamStr(0)) + Extractor_EXE) then |
begin |
WriteLn(Format(ImportantFileNotFound, [Extractor_EXE])); |
{$IFDEF DELAY_ON_ERROR} |
Sleep(2000); |
{$ENDIF} |
ExitCode := 2; |
Exit; |
end; |
// Read filesize + zip-comment length |
// (So we can later extend the zip-comment to include the certificate |
// => The archive is then not corrupt because of 'garbage' at the end) |
|
if ParamCount = 0 then |
begin |
od := TOpenDialog.Create(nil); |
try |
od.DefaultExt := '.zip'; |
od.Filter := 'ZIP-Archiv (*.zip)|*.zip|Alle Dateien (*.*)|*.*'; |
od.Options := [ofAllowMultiSelect, ofFileMustExist, ofHideReadOnly, |
ofPathMustExist, ofEnableSizing]; |
if od.Execute then |
begin |
for i := 0 to od.Files.Count - 1 do |
begin |
DoMakeSFX(od.Files.Strings[i]); |
end; |
end; |
finally |
od.Free; |
end; |
end |
else |
begin |
for i := 1 to ParamCount do |
WriteLn(#9 + Lng_SignSfx); |
|
if not ShellExecuteAndWait(ExtractFilePath(ParamStr(0)) + SIGN_BAT, PChar('"' + ExpandUNCFileName(Dst) + '"')) then |
begin |
DoMakeSFX(ParamStr(i)); |
WriteLn(Format(LngErrorWhileExecuting, [SIGN_BAT])); |
{$IFDEF BREAK_ON_CERT_FAILURE} |
DeleteFile(PChar(Dst)); |
{$IFDEF DELAY_ON_ERROR} |
Sleep(2000); |
{$ENDIF} |
ExitCode := 1; |
Continue; |
{$ENDIF} |
end; |
|
WriteLn(#9 + Lng_Finished); |
WriteLn(''); |
end; |
|
// TODO: Es gibt bei Win2000 außerhalb des debuggers eine AV... |