Subversion Repositories autosfx

Rev

Rev 1 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1 Rev 4
1
program MakeSFX;
1
program MakeSFX;
2
 
2
 
3
{$APPTYPE CONSOLE}
3
{$APPTYPE CONSOLE}
4
 
4
 
5
{.$DEFINE BREAK_ON_CERT_FAILURE}
5
{.$DEFINE BREAK_ON_CERT_FAILURE}
6
{$DEFINE DELAY_ON_ERROR}
6
{$DEFINE DELAY_ON_ERROR}
7
 
7
 
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:';
35
  Lng_RemoveSig = 'Remove signature of Extractor template...';
34
  Lng_RemoveSig = 'Remove signature of Extractor template...';
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! :-)';
41
  Lng_Title = 'ViaThinkSoft AutoSFX';
-
 
42
  Lng_Usage1 = 'Usage:';
-
 
43
  Lng_Usage2 = 'MakeSFX [File1.zip [File2.zip...]]';
-
 
44
 
-
 
45
{$R *.res}
-
 
46
 
-
 
47
begin
40
begin
48
  WriteLn(Lng_Title);
-
 
49
  WriteLn('');
-
 
50
  WriteLn(Lng_Usage1);
-
 
51
  WriteLn(Lng_Usage2);
-
 
52
  WriteLn('');
-
 
53
 
-
 
54
  if not FileExists(ExtractFilePath(ParamStr(0)) + Extractor_EXE) then
41
  if not FileExists(AFilename) then
55
  begin
42
  begin
56
    WriteLn(Format(ImportantFileNotFound, [Extractor_EXE]));
-
 
57
    {$IFDEF DELAY_ON_ERROR}
-
 
58
    Sleep(2000);
-
 
59
    {$ENDIF}
-
 
60
    ExitCode := 2;
-
 
61
    Exit;
-
 
62
  end;
-
 
63
 
-
 
64
  for i := 1 to ParamCount do
-
 
65
  begin
-
 
66
    Src := ParamStr(i);
-
 
67
 
-
 
68
    if not FileExists(Src) then
-
 
69
    begin
-
 
70
      WriteLn(Format(SourceFileNotFound, [Src]));
43
    WriteLn(Format(SourceFileNotFound, [AFilename]));
71
      {$IFDEF DELAY_ON_ERROR}
44
    {$IFDEF DELAY_ON_ERROR}
72
      Sleep(2000);
45
    Sleep(2000);
73
      {$ENDIF}
46
    {$ENDIF}
74
      ExitCode := 1;
47
    ExitCode := 1;
75
      Continue;
48
    Exit;
76
    end;
49
  end;
77
 
50
 
78
    Dst := ChangeFileExt(Src, '.exe');
51
  Dst := ChangeFileExt(AFilename, '.exe');
79
 
52
 
80
    WriteLn(Format(Lng_In+#9+'%s', [Src]));
53
  WriteLn(Format(Lng_In+#9+'%s', [AFilename]));
81
    WriteLn(Format(Lng_Out+#9+'%s', [Dst]));
54
  WriteLn(Format(Lng_Out+#9+'%s', [Dst]));
82
    WriteLn('');
55
  WriteLn('');
83
 
56
 
84
    if not RawFileCopy(ExtractFilePath(ParamStr(0)) + Extractor_EXE, Dst) then
57
  if not RawFileCopy(ExtractFilePath(ParamStr(0)) + Extractor_EXE, Dst) then
85
    begin
58
  begin
86
      WriteLn(Format(LngErrorWhileCopy, [Extractor_EXE, Dst]));
59
    WriteLn(Format(LngErrorWhileCopy, [Extractor_EXE, Dst]));
87
      {$IFDEF DELAY_ON_ERROR}
60
    {$IFDEF DELAY_ON_ERROR}
88
      Sleep(2000);
61
    Sleep(2000);
89
      {$ENDIF}
62
    {$ENDIF}
90
      ExitCode := 1;
63
    ExitCode := 1;
91
      Continue;
64
    Exit;
92
    end;
65
  end;
93
 
66
 
94
   // Remove the signature of Extractor first (otherwise signing will fail later)
67
 // Remove the signature of Extractor first (otherwise signing will fail later)
95
 
68
 
96
    WriteLn(#9 + Lng_RemoveSig);
69
  WriteLn(#9 + Lng_RemoveSig);
97
 
70
 
98
    if not ShellExecuteAndWait(ExtractFilePath(ParamStr(0)) + RemoveSignature_EXE, PChar('"' + ExpandUNCFileName(Dst) + '"')) then
71
  if not ShellExecuteAndWait(ExtractFilePath(ParamStr(0)) + RemoveSignature_EXE, PChar('"' + ExpandUNCFileName(Dst) + '"')) then
99
    begin
72
  begin
100
      WriteLn(Format(LngErrorWhileExecuting, [RemoveSignature_EXE]));
73
    WriteLn(Format(LngErrorWhileExecuting, [RemoveSignature_EXE]));
101
      {$IFDEF BREAK_ON_CERT_FAILURE}
74
    {$IFDEF BREAK_ON_CERT_FAILURE}
102
      DeleteFile(PChar(Dst));
75
    DeleteFile(PChar(Dst));
103
      {$IFDEF DELAY_ON_ERROR}
76
    {$IFDEF DELAY_ON_ERROR}
104
      Sleep(2000);
77
    Sleep(2000);
105
      {$ENDIF}
78
    {$ENDIF}
106
      ExitCode := 1;
79
    ExitCode := 1;
107
      Continue;
80
    Exit;
108
      {$ENDIF}
81
    {$ENDIF}
109
    end;
82
  end;
110
 
83
 
111
    WriteLn(#9 + Lng_Append);
84
  WriteLn(#9 + Lng_Append);
112
 
85
 
113
    s1 := TFileStream.Create(Dst, fmOpenWrite);
86
  s1 := TFileStream.Create(Dst, fmOpenWrite);
114
    try
87
  try
115
      s1.Seek(0, soEnd);
88
    s1.Seek(0, soEnd);
116
 
89
 
117
      s2 := TFileStream.Create(Src, fmOpenRead or fmShareDenyWrite);
90
    s2 := TFileStream.Create(AFilename, fmOpenRead or fmShareDenyWrite);
118
      try
91
    try
119
        s1.CopyFrom(s2, s2.Size);
92
      s1.CopyFrom(s2, s2.Size);
120
      finally
93
    finally
121
        s2.Free;
94
      s2.Free;
122
      end;
95
    end;
123
    finally
96
  finally
124
      s1.Free;
97
    s1.Free;
125
    end;
98
  end;
126
 
99
 
127
    WriteLn(#9 + Lng_Adjust);
100
  WriteLn(#9 + Lng_Adjust);
128
 
101
 
129
    if not ShellExecuteAndWait(ExtractFilePath(ParamStr(0)) + ZIP_EXE, PChar('-A "' + ExpandUNCFileName(Dst) + '"')) then
102
  if not ShellExecuteAndWait(ExtractFilePath(ParamStr(0)) + ZIP_EXE, PChar('-A "' + ExpandUNCFileName(Dst) + '"')) then
130
    begin
103
  begin
131
      DeleteFile(PChar(Dst));
104
    DeleteFile(PChar(Dst));
132
      WriteLn(Format(LngErrorWhileExecuting, [ZIP_EXE]));
105
    WriteLn(Format(LngErrorWhileExecuting, [ZIP_EXE]));
133
      {$IFDEF DELAY_ON_ERROR}
106
    {$IFDEF DELAY_ON_ERROR}
134
      Sleep(2000);
107
    Sleep(2000);
135
      {$ENDIF}
108
    {$ENDIF}
136
      ExitCode := 1;
109
    ExitCode := 1;
137
      Continue;
110
    Exit;
138
    end;
111
  end;
139
 
112
 
140
    WriteLn(#9 + Lng_ModifyZIPComment);
113
  WriteLn(#9 + Lng_ModifyZIPComment);
141
 
114
 
142
    x := TZipMaster19.Create(nil);
115
  x := TZipMaster19.Create(nil);
143
    try
116
  try
144
      x.ZipFileName := Dst;
117
    x.ZipFileName := Dst;
145
 
118
 
146
      // Correct CRLFs
119
    // Correct CRLFs
147
 
120
 
148
      x.ZipComment := NormalizeLineBreaks(x.ZipComment, lbWindows);
121
    x.ZipComment := NormalizeLineBreaks(x.ZipComment, lbWindows);
149
 
122
 
150
      // Ensure we have 2 CRLF before old comment
123
    // Ensure we have 2 CRLF before old comment
151
 
124
 
152
      x.ZipComment := TrimRight(x.ZipComment);
125
    x.ZipComment := TrimRight(x.ZipComment);
153
      if x.ZipComment <> '' then
126
    if x.ZipComment <> '' then
154
      begin
127
    begin
155
        x.ZipComment := x.ZipComment + #13#10 + #13#10;
128
      x.ZipComment := x.ZipComment + #13#10 + #13#10;
156
      end;
129
    end;
157
 
130
 
158
      // Read, strip and re-add behavior (inclusive signature)
131
    // Read, strip and re-add behavior (inclusive signature)
159
 
132
 
160
      x.ZipComment := RelocateBehaviorStringsToEnd(x.ZipComment);
133
    x.ZipComment := RelocateBehaviorStringsToEnd(x.ZipComment);
161
    finally
134
  finally
162
      x.Free;
135
    x.Free;
163
    end;
136
  end;
164
 
137
 
165
    // Read filesize + zip-comment length
138
  // Read filesize + zip-comment length
166
    // (So we can later extend the zip-comment to include the certificate
139
  // (So we can later extend the zip-comment to include the certificate
167
    // => The archive is then not corrupt because of 'garbage' at the end)
140
  // => The archive is then not corrupt because of 'garbage' at the end)
168
 
141
 
169
    WriteLn(#9 + Lng_SignSfx);
142
  WriteLn(#9 + Lng_SignSfx);
170
 
143
 
171
    if not ShellExecuteAndWait(ExtractFilePath(ParamStr(0)) + SIGN_BAT, PChar('"' + ExpandUNCFileName(Dst) + '"')) then
144
  if not ShellExecuteAndWait(ExtractFilePath(ParamStr(0)) + SIGN_BAT, PChar('"' + ExpandUNCFileName(Dst) + '"')) then
172
    begin
145
  begin
173
      WriteLn(Format(LngErrorWhileExecuting, [SIGN_BAT]));
146
    WriteLn(Format(LngErrorWhileExecuting, [SIGN_BAT]));
174
      {$IFDEF BREAK_ON_CERT_FAILURE}
147
    {$IFDEF BREAK_ON_CERT_FAILURE}
175
      DeleteFile(PChar(Dst));
148
    DeleteFile(PChar(Dst));
176
      {$IFDEF DELAY_ON_ERROR}
149
    {$IFDEF DELAY_ON_ERROR}
177
      Sleep(2000);
150
    Sleep(2000);
178
      {$ENDIF}
151
    {$ENDIF}
179
      ExitCode := 1;
152
    ExitCode := 1;
180
      Continue;
153
    Exit;
181
      {$ENDIF}
154
    {$ENDIF}
182
    end;
155
  end;
183
 
156
 
184
    WriteLn(#9 + Lng_Finished);
157
  WriteLn(#9 + Lng_Finished);
185
    WriteLn('');
158
  WriteLn('');
186
  end;
159
end;
-
 
160
 
-
 
161
{$R *.res}
-
 
162
 
-
 
163
var
-
 
164
  i: integer;
-
 
165
  od: TOpenDialog;
-
 
166
resourcestring
-
 
167
  Lng_Title = 'ViaThinkSoft AutoSFX';
-
 
168
  Lng_Usage1 = 'Usage:';
-
 
169
  Lng_Usage2 = 'MakeSFX [File1.zip [File2.zip...]]';
-
 
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('');
-
 
177
 
-
 
178
  if not FileExists(ExtractFilePath(ParamStr(0)) + Extractor_EXE) then
-
 
179
  begin
-
 
180
    WriteLn(Format(ImportantFileNotFound, [Extractor_EXE]));
-
 
181
    {$IFDEF DELAY_ON_ERROR}
-
 
182
    Sleep(2000);
-
 
183
    {$ENDIF}
-
 
184
    ExitCode := 2;
-
 
185
    Exit;
-
 
186
  end;
-
 
187
 
-
 
188
  if ParamCount = 0 then
-
 
189
  begin
-
 
190
    od := TOpenDialog.Create(nil);
-
 
191
    try
-
 
192
      od.DefaultExt := '.zip';
-
 
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
-
 
210
    begin
-
 
211
      DoMakeSFX(ParamStr(i));
-
 
212
    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.
190
 
217