1
1
import { WinPackager } from "../winPackager"
2
- import { Arch , NsisOptions } from "../metadata"
2
+ import { Arch , NsisOptions , FileAssociation } from "../metadata"
3
3
import { exec , debug , doSpawn , handleProcess , use } from "../util/util"
4
4
import * as path from "path"
5
5
import { Promise as BluebirdPromise } from "bluebird"
@@ -30,10 +30,17 @@ export default class NsisTarget extends Target {
30
30
31
31
private readonly nsisTemplatesDir = path . join ( __dirname , ".." , ".." , "templates" , "nsis" )
32
32
33
+ private readonly fileAssociations : Array < FileAssociation >
34
+
33
35
constructor ( private packager : WinPackager , private outDir : string ) {
34
36
super ( "nsis" )
35
37
36
38
this . options = packager . info . devMetadata . build . nsis || Object . create ( null )
39
+
40
+ // CFBundleTypeName
41
+ // https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/20001431-101685
42
+ // CFBundleTypeExtensions
43
+ this . fileAssociations = asArray ( packager . devMetadata . build . fileAssociations ) . concat ( asArray ( packager . platformSpecificBuildOptions . fileAssociations ) )
37
44
}
38
45
39
46
async build ( arch : Arch , appOutDir : string ) {
@@ -221,24 +228,26 @@ export default class NsisTarget extends Target {
221
228
const binDir = process . platform === "darwin" ? "mac" : ( process . platform === "win32" ? "Bin" : "linux" )
222
229
const nsisPath = await nsisPathPromise
223
230
224
- const packager = this . packager
225
- // CFBundleTypeName
226
- // https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/20001431-101685
227
- // CFBundleTypeExtensions
228
- const fileAssociations = asArray ( packager . devMetadata . build . fileAssociations ) . concat ( asArray ( packager . platformSpecificBuildOptions . fileAssociations ) )
229
-
230
231
let script = originalScript
231
232
const customInclude = await this . getResource ( this . options . include , "installer.nsh" )
232
233
if ( customInclude != null ) {
233
234
script = `!include "${ customInclude } "\n!addincludedir "${ this . packager . buildResourcesDir } "\n${ script } `
234
235
}
235
236
236
- if ( fileAssociations . length !== 0 ) {
237
+ if ( this . fileAssociations . length !== 0 ) {
237
238
script = "!include FileAssociation.nsh\n" + script
238
239
if ( isInstaller ) {
239
240
let registerFileAssociationsScript = ""
240
- for ( let item of fileAssociations ) {
241
- const icon = '"$INSTDIR\\${APP_EXECUTABLE_FILENAME},0"'
241
+ for ( let item of this . fileAssociations ) {
242
+ const customIcon = await this . getResource ( item . icon , `${ normalizeExt ( item . ext ) } .ico` )
243
+ let installedIconPath = "${APP_EXECUTABLE_FILENAME},0"
244
+ if ( customIcon != null ) {
245
+ installedIconPath = `resources\\${ path . basename ( customIcon ) } `
246
+ //noinspection SpellCheckingInspection
247
+ registerFileAssociationsScript += ` File "/oname=${ installedIconPath } " "${ customIcon } "\n`
248
+ }
249
+
250
+ const icon = `"$INSTDIR\\${ installedIconPath } "`
242
251
const commandText = `"Open with ${ this . packager . appInfo . productName } "`
243
252
const command = '"$INSTDIR\\${APP_EXECUTABLE_FILENAME} $\\"%1$\\""'
244
253
registerFileAssociationsScript += ` !insertmacro APP_ASSOCIATE "${ normalizeExt ( item . ext ) } " "${ item . name } " "${ item . description || "" } " ${ icon } ${ commandText } ${ command } \n`
@@ -247,7 +256,7 @@ export default class NsisTarget extends Target {
247
256
}
248
257
else {
249
258
let unregisterFileAssociationsScript = ""
250
- for ( let item of fileAssociations ) {
259
+ for ( let item of this . fileAssociations ) {
251
260
unregisterFileAssociationsScript += ` !insertmacro APP_UNASSOCIATE "${ normalizeExt ( item . ext ) } " "${ item . name } "\n`
252
261
}
253
262
script = `!macro unregisterFileAssociations\n${ unregisterFileAssociationsScript } !macroend\n${ script } `
0 commit comments