@@ -73,33 +73,64 @@ public class InnoSetupInstaller : IInstaller
73
73
fileContents = fileContents . Replace ( "[VERSION_DISPLAY]" , BuildContext . General . Version . FullSemVer ) ;
74
74
fileContents = fileContents . Replace ( "[WIZARDIMAGEFILE]" , string . Format ( "logo_large{0}" , setupSuffix ) ) ;
75
75
76
- var signTool = string . Empty ;
77
- if ( ! string . IsNullOrWhiteSpace ( BuildContext . General . CodeSign . CertificateSubjectName ) )
76
+ var signToolIndex = GetRandomSignToolIndex ( ) ;
77
+
78
+ try
78
79
{
79
- signTool = string . Format ( "SignTool={0}" , BuildContext . General . CodeSign . CertificateSubjectName ) ;
80
- }
80
+ var codeSignContext = BuildContext . General . CodeSign ;
81
+ var azureCodeSignContext = BuildContext . General . AzureCodeSign ;
82
+
83
+ var signTool = string . Empty ;
81
84
82
- fileContents = fileContents . Replace ( "[SIGNTOOL]" , signTool ) ;
83
- System . IO . File . WriteAllText ( innoSetupScriptFileName , fileContents ) ;
85
+ var signToolFileName = GetSignToolFileName ( BuildContext ) ;
86
+ if ( ! string . IsNullOrWhiteSpace ( signToolFileName ) )
87
+ {
88
+ var signToolName = DateTime . Now . ToString ( "yyyyMMddHHmmss" ) ;
89
+ var signToolCommandLine = GetSignToolCommandLine ( BuildContext ) ;
84
90
85
- BuildContext . CakeContext . Information ( "Generating Inno Setup packages, this can take a while, especially when signing is enabled... " ) ;
91
+ BuildContext . CakeContext . Information ( "Adding random sign tool config for Inno Setup " ) ;
86
92
87
- BuildContext . CakeContext . InnoSetup ( innoSetupScriptFileName , new InnoSetupSettings
88
- {
89
- OutputDirectory = innoSetupReleasesRoot
90
- } ) ;
93
+ using ( var registryKey = Microsoft . Win32 . Registry . CurrentUser . OpenSubKey ( GetRegistryKey ( ) , true ) )
94
+ {
95
+ var registryValueName = GetSignToolIndexName ( signToolIndex ) ;
91
96
92
- if ( BuildContext . Wpf . UpdateDeploymentsShare )
93
- {
94
- BuildContext . CakeContext . Information ( "Copying Inno Setup files to deployments share at '{0}'" , installersOnDeploymentsShare ) ;
97
+ // Important: must end with "$f"
98
+ var signToolRegistryValue = $ "{ signToolName } =\" { signToolFileName } \" { signToolCommandLine } \" $f\" ";
95
99
96
- // Copy the following files:
97
- // - Setup.exe => [projectName]-[version].exe
98
- // - Setup.exe => [projectName]-[channel].exe
100
+ registryKey . SetValue ( registryValueName , signToolRegistryValue ) ;
101
+ }
102
+
103
+ signTool = string . Format ( "SignTool={0}" , signToolName ) ;
104
+ }
105
+
106
+ fileContents = fileContents . Replace ( "[SIGNTOOL]" , signTool ) ;
107
+ System . IO . File . WriteAllText ( innoSetupScriptFileName , fileContents ) ;
108
+
109
+ BuildContext . CakeContext . Information ( "Generating Inno Setup packages, this can take a while, especially when signing is enabled..." ) ;
110
+
111
+ BuildContext . CakeContext . InnoSetup ( innoSetupScriptFileName , new InnoSetupSettings
112
+ {
113
+ OutputDirectory = innoSetupReleasesRoot
114
+ } ) ;
99
115
100
- var installerSourceFile = System . IO . Path . Combine ( innoSetupReleasesRoot , $ "{ projectName } _{ BuildContext . General . Version . FullSemVer } .exe") ;
101
- BuildContext . CakeContext . CopyFile ( installerSourceFile , System . IO . Path . Combine ( installersOnDeploymentsShare , $ "{ projectName } _{ BuildContext . General . Version . FullSemVer } .exe") ) ;
102
- BuildContext . CakeContext . CopyFile ( installerSourceFile , System . IO . Path . Combine ( installersOnDeploymentsShare , $ "{ projectName } { setupSuffix } .exe") ) ;
116
+ if ( BuildContext . Wpf . UpdateDeploymentsShare )
117
+ {
118
+ BuildContext . CakeContext . Information ( "Copying Inno Setup files to deployments share at '{0}'" , installersOnDeploymentsShare ) ;
119
+
120
+ // Copy the following files:
121
+ // - Setup.exe => [projectName]-[version].exe
122
+ // - Setup.exe => [projectName]-[channel].exe
123
+
124
+ var installerSourceFile = System . IO . Path . Combine ( innoSetupReleasesRoot , $ "{ projectName } _{ BuildContext . General . Version . FullSemVer } .exe") ;
125
+ BuildContext . CakeContext . CopyFile ( installerSourceFile , System . IO . Path . Combine ( installersOnDeploymentsShare , $ "{ projectName } _{ BuildContext . General . Version . FullSemVer } .exe") ) ;
126
+ BuildContext . CakeContext . CopyFile ( installerSourceFile , System . IO . Path . Combine ( installersOnDeploymentsShare , $ "{ projectName } { setupSuffix } .exe") ) ;
127
+ }
128
+ }
129
+ finally
130
+ {
131
+ BuildContext . CakeContext . Information ( "Removing random sign tool config for Inno Setup" ) ;
132
+
133
+ RemoveSignToolFromRegistry ( signToolIndex ) ;
103
134
}
104
135
}
105
136
@@ -222,4 +253,53 @@ public class InnoSetupInstaller : IInstaller
222
253
223
254
return installersOnDeploymentsShare ;
224
255
}
256
+
257
+ //-------------------------------------------------------------
258
+
259
+ private string GetRegistryKey ( )
260
+ {
261
+ return "Software\\ Jordan Russell\\ Inno Setup\\ SignTools" ;
262
+ }
263
+
264
+ //-------------------------------------------------------------
265
+
266
+ private int GetRandomSignToolIndex ( )
267
+ {
268
+ using ( var registryKey = Microsoft . Win32 . Registry . CurrentUser . CreateSubKey ( GetRegistryKey ( ) ) )
269
+ {
270
+ for ( int i = 0 ; i < 100 ; i ++ )
271
+ {
272
+ var valueName = GetSignToolIndexName ( i ) ;
273
+
274
+ if ( registryKey . GetValue ( valueName ) is null )
275
+ {
276
+ // Immediately lock it
277
+ registryKey . SetValue ( valueName , "reserved" ) ;
278
+
279
+ return i ;
280
+ }
281
+ }
282
+ }
283
+
284
+ throw new Exception ( "Could not find any empty slots for the sign tool, please clean up the sign tool registry for Inno Setup" ) ;
285
+ }
286
+
287
+ //-------------------------------------------------------------
288
+
289
+ private string GetSignToolIndexName ( int index )
290
+ {
291
+ return $ "SignTool{ index } ";
292
+ }
293
+
294
+ //-------------------------------------------------------------
295
+
296
+ private void RemoveSignToolFromRegistry ( int index )
297
+ {
298
+ using ( var registryKey = Microsoft . Win32 . Registry . CurrentUser . CreateSubKey ( GetRegistryKey ( ) ) )
299
+ {
300
+ var valueName = GetSignToolIndexName ( index ) ;
301
+
302
+ registryKey . DeleteValue ( valueName , false ) ;
303
+ }
304
+ }
225
305
}
0 commit comments