Procházet zdrojové kódy

feat(nsis-gen): custom default installation directory

evshiron před 8 roky
rodič
revize
5fa80429d2

+ 1 - 0
assets/project/package.json

@@ -33,6 +33,7 @@
       "icon": "./assets/pd.icns"
     },
     "nsis": {
+      "installDirectory": "$PROGRAMFILES\\${_COMPANYNAME}\\${_APPNAME}",
       "diffUpdaters": true
     }
   },

+ 1 - 0
docs/Options.md

@@ -49,5 +49,6 @@ Name | Type | Description
 icon | string | .ico icon file for NSIS installers relative to the project root. Defaults to `undefined`.
 unIcon | string | .ico icon file for NSIS uninstallers relative to the project root. Defaults to `undefined`.
 languages | string[] | Languages for NSIS installers. Multiple languages will result in a language selection dialog on startup. See [/assets/nsis/Contrib/Language files/](../assets/nsis/Contrib/Language%20files/) for available values. Defaults to `[ 'English' ]`.
+installDirectory | string | Default installation directory. Allow using NSIS variables. See [/src/lib/nsis-gen/NsisComposer.ts](../src/lib/nsis-gen/NsisComposer.ts) for a list of self-defined constants. Defaults to `$LOCALAPPDATA\\${_APPNAME}`.
 diffUpdaters | boolean | Whether to build diff updaters. Defaults to `false`.
 hashCalculation | boolean | Whether to calculate hashes for installers and updaters. Defaults to `true`.

+ 3 - 0
src/lib/Builder.ts

@@ -429,6 +429,7 @@ export class Builder {
             solid: true,
 
             languages: config.nsis.languages,
+            installDirectory: config.nsis.installDirectory,
 
             // Output.
             output: diffNsis,
@@ -556,6 +557,7 @@ export class Builder {
             solid: true,
 
             languages: config.nsis.languages,
+            installDirectory: config.nsis.installDirectory,
 
             // Output.
             output: targetNsis,
@@ -620,6 +622,7 @@ export class Builder {
             solid: true,
 
             languages: config.nsis.languages,
+            installDirectory: config.nsis.installDirectory,
 
             // Output.
             output: targetNsis,

+ 2 - 0
src/lib/config/NsisConfig.ts

@@ -6,6 +6,8 @@ export class NsisConfig {
 
     public languages: string[] = [ 'English' ];
 
+    public installDirectory: string = '$LOCALAPPDATA\\${_APPNAME}';
+
     public diffUpdaters: boolean = false;
     public hashCalculation: boolean = true;
 

+ 59 - 53
src/lib/nsis-gen/NsisComposer.ts

@@ -23,6 +23,8 @@ export interface INsisComposerOptions {
 
     languages: string[];
 
+    installDirectory: string;
+
     // Output.
     output: string;
 
@@ -66,31 +68,54 @@ export class NsisComposer {
 
     public async make(): Promise<string> {
 
-        return `
-${ NsisComposer.DIVIDER }
+        return `${ NsisComposer.DIVIDER }
 #
 # Generated by nsis-gen.
 #
 ${ NsisComposer.DIVIDER }
 
-${ await this.makeGeneralSection() }
+${ await this.makeStrings() }
 
-${ await this.makeStringsSection() }
+${ await this.makeGeneral() }
 
-${ await this.makeModernUISection() }
+${ await this.makeModernUI() }
 
-${ await this.makeVersionSection() }
+${ await this.makeVersioning() }
 
-${ await this.makeHookSection() }
+${ await this.makeHooks() }
 
 ${ await this.makeInstallSection() }
 
-${ await this.makeUninstallSection() }
-`;
+${ await this.makeUninstallSection() }`;
+
+    }
+
+    protected async makeStrings(): Promise<string> {
+        return `${ NsisComposer.DIVIDER }
+#
+# Strings
+#
+${ NsisComposer.DIVIDER }
+
+!define _APPNAME "${ this.options.appName }"
+!define _COMPANYNAME "${ this.options.companyName }"
+!define _DESCRIPTION "${ this.options.description }"
+!define _VERSION "${ this.fixedVersion }"
+!define _COPYRIGHT "${ this.options.copyright }"
+!define _OUTPUT "${ win32.normalize(resolve(this.options.output)) }"
+
+# FIXME: More translations.
+
+LangString CREATE_DESKTOP_SHORTCUT 1033 "Create Desktop Shortcut"
+LangString CREATE_DESKTOP_SHORTCUT 2052 "创建桌面快捷方式"
+LangString CREATE_DESKTOP_SHORTCUT 1028 "建立桌面捷徑"
 
+LangString INSTALLING 1033 "Installing"
+LangString INSTALLING 2052 "正在安装"
+LangString INSTALLING 1028 "安裝中"`;
     }
 
-    protected async makeGeneralSection(): Promise<string> {
+    protected async makeGeneral(): Promise<string> {
         return `${ NsisComposer.DIVIDER }
 #
 # General
@@ -99,9 +124,9 @@ ${ NsisComposer.DIVIDER }
 
 Unicode true
 
-Name "${ this.options.appName }"
-Caption "${ this.options.appName }"
-BrandingText "${ this.options.appName } ${ this.fixedVersion }"
+Name "\${_APPNAME}"
+Caption "\${_APPNAME}"
+BrandingText "\${_APPNAME} \${_VERSION}"
 ${
     this.options.icon
     ? `Icon "${ win32.normalize(resolve(this.options.icon)) }"`
@@ -114,35 +139,16 @@ ${
 }
 
 SetCompressor ${ this.options.solid ? '/SOLID' : '' } ${ this.options.compression }
-OutFile "${ win32.normalize(resolve(this.options.output)) }"
+OutFile "\${_OUTPUT}"
 
-InstallDir "$LOCALAPPDATA\\${ this.options.appName }"
-InstallDirRegKey HKCU "Software\\${ this.options.appName }" "InstallDir"
+InstallDir "${ this.options.installDirectory }"
+InstallDirRegKey HKCU "Software\\\${_APPNAME}" "InstallDir"
 
 RequestExecutionLevel user
 XPStyle on`;
     }
 
-    protected async makeStringsSection(): Promise<string> {
-        return `${ NsisComposer.DIVIDER }
-#
-# Strings
-#
-${ NsisComposer.DIVIDER }
-
-# FIXME: More translations.
-
-LangString CREATE_DESKTOP_SHORTCUT 1033 "Create Desktop Shortcut"
-LangString CREATE_DESKTOP_SHORTCUT 2052 "创建桌面快捷方式"
-LangString CREATE_DESKTOP_SHORTCUT 1028 "建立桌面捷徑"
-
-LangString INSTALLING 1033 "Installing"
-LangString INSTALLING 2052 "正在安装"
-LangString INSTALLING 1028 "安裝中"
-`;
-    }
-
-    protected async makeModernUISection(): Promise<string> {
+    protected async makeModernUI(): Promise<string> {
         return `${ NsisComposer.DIVIDER }
 #
 # Modern UI
@@ -152,11 +158,11 @@ ${ NsisComposer.DIVIDER }
 !include "MUI2.nsh"
 
 Function CreateDesktopShortcut
-    CreateShortcut "$DESKTOP\\${ this.options.appName }.lnk" "$INSTDIR\\${ this.options.appName }.exe"
+    CreateShortcut "$DESKTOP\\\${_APPNAME}.lnk" "$INSTDIR\\\${_APPNAME}.exe"
 FunctionEnd
 
 !define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKCU"
-!define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\\${ this.options.appName }"
+!define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\\\${_APPNAME}"
 !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "StartMenuFolder"
 
 !define MUI_FINISHPAGE_SHOWREADME ""
@@ -165,7 +171,7 @@ FunctionEnd
 
 Var StartMenuFolder
 
-!define MUI_FINISHPAGE_RUN "$INSTDIR\\${ this.options.appName }.exe"
+!define MUI_FINISHPAGE_RUN "$INSTDIR\\\${_APPNAME}.exe"
 
 !insertmacro MUI_PAGE_WELCOME
 !insertmacro MUI_PAGE_DIRECTORY
@@ -191,22 +197,22 @@ ${
 }`;
     }
 
-    protected async makeVersionSection(): Promise<string> {
+    protected async makeVersioning(): Promise<string> {
         return `${ NsisComposer.DIVIDER }
 #
-# Versions
+# Versioning
 #
 ${ NsisComposer.DIVIDER }
 
-VIProductVersion "${ this.fixedVersion }"
-VIAddVersionKey /LANG=0 "ProductName" "${ this.options.appName }"
-VIAddVersionKey /LANG=0 "CompanyName" "${ this.options.companyName }"
-VIAddVersionKey /LANG=0 "FileDescription" "${ this.options.description }"
-VIAddVersionKey /LANG=0 "FileVersion" "${ this.fixedVersion }"
-VIAddVersionKey /LANG=0 "LegalCopyright" "${ this.options.copyright }"`;
+VIProductVersion "\${_VERSION}"
+VIAddVersionKey /LANG=0 "ProductName" "\${_APPNAME}"
+VIAddVersionKey /LANG=0 "CompanyName" "\${_COMPANYNAME}"
+VIAddVersionKey /LANG=0 "FileDescription" "$\{_DESCRIPTION}"
+VIAddVersionKey /LANG=0 "FileVersion" "\${_VERSION}"
+VIAddVersionKey /LANG=0 "LegalCopyright" "\${_COPYRIGHT}"`;
     }
 
-    protected async makeHookSection(): Promise<string> {
+    protected async makeHooks(): Promise<string> {
         return `${ NsisComposer.DIVIDER }
 #
 # Hooks
@@ -236,14 +242,14 @@ Section -Install
 SetShellVarContext current
 SetOverwrite ifnewer
 
-WriteRegStr HKCU "Software\\${ this.options.appName }" "InstallDir" "$INSTDIR"
+WriteRegStr HKCU "Software\\\${_APPNAME}" "InstallDir" "$INSTDIR"
 
 ${ await this.makeInstallerFiles() }
 
 !insertmacro MUI_STARTMENU_WRITE_BEGIN "Application"
 
     CreateDirectory "$SMPROGRAMS\\$StartMenuFolder"
-    CreateShortcut "$SMPROGRAMS\\$StartMenuFolder\\${ this.options.appName }.lnk" "$INSTDIR\\${ this.options.appName }.exe"
+    CreateShortcut "$SMPROGRAMS\\$StartMenuFolder\\\${_APPNAME}.lnk" "$INSTDIR\\\${_APPNAME}.exe"
     CreateShortcut "$SMPROGRAMS\\$StartMenuFolder\\Uninstall.lnk" "$INSTDIR\\Uninstall.exe"
 
 !insertmacro MUI_STARTMENU_WRITE_END
@@ -267,13 +273,13 @@ RMDir /r "$INSTDIR"
 
 !insertmacro MUI_STARTMENU_GETFOLDER "Application" $StartMenuFolder
 
-Delete "$SMPROGRAMS\\$StartMenuFolder\\${ this.options.appName }.lnk"
+Delete "$SMPROGRAMS\\$StartMenuFolder\\\${_APPNAME}.lnk"
 Delete "$SMPROGRAMS\\$StartMenuFolder\\Uninstall.lnk"
 RMDir "$SMPROGRAMS\\$StartMenuFolder"
 
-Delete "$DESKTOP\\${ this.options.appName }.lnk"
+Delete "$DESKTOP\\\${_APPNAME}.lnk"
 
-DeleteRegKey HKCU "Software\\${ this.options.appName }"
+DeleteRegKey HKCU "Software\\\${_APPNAME}"
 
 SectionEnd`;
     }