Subversion Repositories autosfx

Compare Revisions

Ignore whitespace Rev 1 → Rev HEAD

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