Skip to content

Commit

Permalink
fix(nsis): if unicode disabled, add only english custom translations
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jul 12, 2017
1 parent 203c8c4 commit 88e36db
Show file tree
Hide file tree
Showing 32 changed files with 953 additions and 143 deletions.
6 changes: 3 additions & 3 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
[
"transform-inline-imports-commonjs",
{
excludeModules: ["path"]
excludeModules: ["path", "debug"]
}
],
"./packages/babel-plugin-version-transform.js",
"./scripts/babel-plugin-version-transform.js",
],
},
test: {
Expand All @@ -35,7 +35,7 @@
[
"transform-inline-imports-commonjs",
{
excludeModules: ["path"]
excludeModules: ["path", "debug"]
}
],
]
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ dist/
/packages/electron-builder/README.md
/packages/electron-builder/scheme.json

/jsdoc/out/
/scripts/jsdoc/out/

electron-builder-*.d.ts
1 change: 1 addition & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workspaces-experimental true
10 changes: 5 additions & 5 deletions docs/encapsulated manual update via menu.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* updater.js
*
*
* Please use manual update only when it is really required, otherwise please use recommended non-intrusive auto update.
*
*
* Import steps:
* 1. create `updater.js` for the code snippet
* 2. require `updater.js` for menu implementation, and set `checkForUpdates` callback from `updater` for the click property of `Check Updates...` MenuItem.
Expand All @@ -26,7 +26,7 @@ autoUpdater.on('update-available', () => {
}, (buttonIndex) => {
if (buttonIndex === 0) {
autoUpdater.downloadUpdate()
}
}
else {
updater.enabled = true
updater = null
Expand All @@ -36,7 +36,7 @@ autoUpdater.on('update-available', () => {

autoUpdater.on('update-not-available', () => {
dialog.showMessageBox({
title: 'No Updates',
title: 'No Updates',
message: 'Current version is up-to-date.'
})
updater.enabled = true
Expand All @@ -48,7 +48,7 @@ autoUpdater.on('update-downloaded', () => {
title: 'Install Updates',
message: 'Updates downloaded, application will be quit for update...'
}, () => {
autoUpdater.quitAndInstall()
setImmediate(() => autoUpdater.quitAndInstall())
})
})

Expand Down
17 changes: 12 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
"update-wiki": "(git branch -D wiki || true) && git subtree split -b wiki --prefix docs/ && git push -f wiki wiki:master",
"whitespace": "whitespace 'src/**/*.ts'",
"docker-images": "docker/build.sh",
"update-deps": "node ./packages/update-deps.js",
"update-deps": "node ./scripts/update-deps.js",
"set-versions": "node test/out/helpers/setVersions.js",
"npm-publish": "yarn set-versions && yarn compile && ./packages/npm-publish.sh && conventional-changelog -p angular -i CHANGELOG.md -s",
"npm-publish": "yarn set-versions && yarn compile && ./scripts/npm-publish.sh && conventional-changelog -p angular -i CHANGELOG.md -s",
"schema": "typescript-json-schema packages/electron-builder/tsconfig.json Config --out packages/electron-builder/scheme.json --noExtraProps --useTypeOfKeyword --strictNullChecks --titles --required",
"jsdoc": "ts2jsdoc packages/electron-builder-http packages/electron-updater packages/electron-builder packages/electron-publish",
"jsdoc2md": "node packages/jsdoc2md.js",
"api": "yarn jsdoc && yarn jsdoc2md"
"jsdoc2md": "node scripts/jsdoc2md.js",
"api": "yarn jsdoc && yarn jsdoc2md",
"dist": "webpack --env.production --progress --bail --config scripts/webpack.config.js"
},
"//": "repository must be specified otherwise conventional-changelog will use forked repo (currently cloned)",
"repository": "electron-userland/electron-builder",
Expand Down Expand Up @@ -89,10 +90,13 @@
"jest-junit": "^1.5.1",
"jsdoc-to-markdown": "^3.0.0",
"path-sort": "^0.1.0",
"shebang-loader": "^0.0.1",
"ts-babel": "^3.1.2",
"ts-loader": "^2.2.2",
"tslint": "^5.5.0",
"typescript": "^2.4.1",
"v8-compile-cache": "^1.1.0",
"webpack": "^3.2.0",
"whitespace": "^2.1.0",
"worker-farm": "^1.4.1",
"xml2js": "^0.4.17"
Expand All @@ -116,5 +120,8 @@
"<rootDir>/packages"
],
"setupTestFrameworkScriptFile": "<rootDir>/test/jestSetup.js"
}
},
"workspaces": [
"packages/*"
]
}
4 changes: 2 additions & 2 deletions packages/electron-builder-http/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
},
"declaration": true,
"jsdoc": {
"out": "../../jsdoc/out/http",
"examples": "../../jsdoc/examples",
"out": "../../scripts/jsdoc/out/http",
"examples": "../../scripts/jsdoc/examples",
"access": "public"
},
"include": [
Expand Down
98 changes: 10 additions & 88 deletions packages/electron-builder/src/targets/nsis.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { path7za } from "7zip-bin"
import BluebirdPromise from "bluebird-lst"
import _debug from "debug"
import { asArray, debug7zArgs, doSpawn, getPlatformIconFileName, handleProcess, isEmptyOrSpaces, log, spawn, subTask, use, warn } from "electron-builder-util"
import { asArray, debug7zArgs, doSpawn, getPlatformIconFileName, handleProcess, isEmptyOrSpaces, log, spawn, use, warn } from "electron-builder-util"
import { getBinFromGithub } from "electron-builder-util/out/binDownload"
import { copyFile } from "electron-builder-util/out/fs"
import { outputFile, readFile, unlink, writeFile } from "fs-extra-p"
import { safeLoad } from "js-yaml"
import { readFile, writeFile } from "fs-extra-p"
import * as path from "path"
import sanitizeFileName from "sanitize-filename"
import { v5 as uuid5 } from "uuid-1345"
Expand All @@ -18,7 +17,8 @@ import { execWine } from "../util/wine"
import { WinPackager } from "../winPackager"
import { addZipArgs, archive, ArchiveOptions } from "./archive"
import { computeBlockMap } from "./blockMap"
import { bundledLanguages, getLicenseFiles, lcid, toLangWithRegion } from "./license"
import { bundledLanguages, getLicenseFiles, lcid } from "./license"
import { addCustomMessageFileInclude, AppPackageHelper, nsisTemplatesDir } from "./nsis/nsisUtil"

const debug = _debug("electron-builder:nsis")

Expand All @@ -32,59 +32,12 @@ const nsisResourcePathPromise = getBinFromGithub("nsis-resources", "3.0.0", "cde

const USE_NSIS_BUILT_IN_COMPRESSOR = false

interface PackageFileInfo {
file: string
}

export class AppPackageHelper {
private readonly archToFileInfo = new Map<Arch, Promise<PackageFileInfo>>()
private readonly infoToIsDelete = new Map<PackageFileInfo, boolean>()

/** @private */
refCount = 0

async packArch(arch: Arch, target: NsisTarget) {
let infoPromise = this.archToFileInfo.get(arch)
if (infoPromise == null) {
infoPromise = subTask(`Packaging NSIS installer for arch ${Arch[arch]}`, target.buildAppPackage(target.archs.get(arch)!, arch))
.then(it => ({file: it}))
this.archToFileInfo.set(arch, infoPromise)
}

const info = await infoPromise
if (target.isWebInstaller) {
this.infoToIsDelete.set(info, false)
}
else if (!this.infoToIsDelete.has(info)) {
this.infoToIsDelete.set(info, true)
}
return info.file
}

async finishBuild(): Promise<any> {
if (--this.refCount > 0) {
return
}

const filesToDelete: Array<string> = []
for (const [info, isDelete] of this.infoToIsDelete.entries()) {
if (isDelete) {
filesToDelete.push(info.file)
}
}

await BluebirdPromise.map(filesToDelete, it => unlink(it))
}
}

export class NsisTarget extends Target {
readonly options: NsisOptions

/** @private */
readonly archs: Map<Arch, string> = new Map()

private readonly nsisTemplatesDir = path.join(__dirname, "..", "..", "templates", "nsis")

constructor(protected readonly packager: WinPackager, readonly outDir: string, targetName: string, protected readonly packageHelper: AppPackageHelper) {
super(targetName)

Expand Down Expand Up @@ -267,7 +220,7 @@ export class NsisTarget extends Target {
return
}

const script = isPortable ? await readFile(path.join(this.nsisTemplatesDir, "portable.nsi"), "utf8") : await this.computeScriptAndSignUninstaller(defines, commands, installerPath)
const script = isPortable ? await readFile(path.join(nsisTemplatesDir, "portable.nsi"), "utf8") : await this.computeScriptAndSignUninstaller(defines, commands, installerPath)
await this.executeMakensis(defines, commands, await this.computeFinalScript(script, true))
await packager.sign(installerPath)

Expand All @@ -291,7 +244,7 @@ export class NsisTarget extends Target {
private async computeScriptAndSignUninstaller(defines: any, commands: any, installerPath: string) {
const packager = this.packager
const customScriptPath = await packager.getResource(this.options.script, "installer.nsi")
const script = await readFile(customScriptPath || path.join(this.nsisTemplatesDir, "installer.nsi"), "utf8")
const script = await readFile(customScriptPath || path.join(nsisTemplatesDir, "installer.nsi"), "utf8")

if (customScriptPath != null) {
log("Custom NSIS script is used - uninstaller is not signed by electron-builder")
Expand Down Expand Up @@ -466,7 +419,7 @@ export class NsisTarget extends Target {
// we use NSIS_CONFIG_CONST_DATA_PATH=no to build makensis on Linux, but in any case it doesn't use stubs as MacOS/Windows version, so, we explicitly set NSISDIR
// set LC_CTYPE to avoid crash https://github.com/electron-userland/electron-builder/issues/503 Even "en_DE.UTF-8" leads to error.
env: {...process.env, NSISDIR: nsisPath, LC_CTYPE: "en_US.UTF-8"},
cwd: this.nsisTemplatesDir,
cwd: nsisTemplatesDir,
}, {isPipeInput: true, isDebugEnabled: debug.enabled})

const timeout = setTimeout(() => childProcess.kill(), 4 * 60 * 1000)
Expand All @@ -491,22 +444,10 @@ export class NsisTarget extends Target {
})
}

private async writeCustomLangFile(data: string) {
const file = await this.packager.getTempFile("messages.nsh")
await outputFile(file, data)
return file
}

private async computeFinalScript(originalScript: string, isInstaller: boolean) {
const packager = this.packager
let scriptHeader = `!addincludedir "${path.join(__dirname, "..", "..", "templates", "nsis", "include")}"\n`

const addCustomMessageFileInclude = async (input: string) => {
const data = computeCustomMessageTranslations(safeLoad(await readFile(path.join(this.nsisTemplatesDir, input), "utf-8"))).join("\n")
debug(data)
return '!include "' + await this.writeCustomLangFile(data) + '"\n'
}

const taskManager = new AsyncTaskManager(packager.info.cancellationToken)

taskManager.add(async () => {
Expand All @@ -522,11 +463,11 @@ export class NsisTarget extends Target {
return licensePage == null ? "" : createMacro("licensePage", licensePage)
})

taskManager.addTask(addCustomMessageFileInclude("messages.yml"))
taskManager.addTask(addCustomMessageFileInclude("messages.yml", packager, this.isUnicodeEnabled))

if (!this.isPortable) {
if (this.options.oneClick === false) {
taskManager.addTask(addCustomMessageFileInclude("boringMessages.yml"))
if (this.isUnicodeEnabled && this.options.oneClick === false) {
taskManager.addTask(addCustomMessageFileInclude("boringMessages.yml", packager, this.isUnicodeEnabled))
}

taskManager.add(async () => {
Expand Down Expand Up @@ -625,25 +566,6 @@ export class NsisTarget extends Target {
}
}

function computeCustomMessageTranslations(messages: any): Array<string> {
const result: Array<string> = []
for (const messageId of Object.keys(messages)) {
const langToTranslations = messages[messageId]
const unspecifiedLangs = new Set(bundledLanguages)
for (const lang of Object.keys(langToTranslations)) {
const langWithRegion = toLangWithRegion(lang)
result.push(`LangString ${messageId} ${lcid[langWithRegion]} "${langToTranslations[lang].replace(/\n/g, "$\\r$\\n")}"`)
unspecifiedLangs.delete(langWithRegion)
}

const defaultTranslation = langToTranslations.en.replace(/\n/g, "$\\r$\\n")
for (const langWithRegion of unspecifiedLangs) {
result.push(`LangString ${messageId} ${lcid[langWithRegion]} "${defaultTranslation}"`)
}
}
return result
}

function createMacro(name: string, lines: Array<string>) {
return `\n!macro ${name}\n ${lines.join("\n ")}\n!macroend\n`
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { NsisWebOptions } from "../options/winOptions"
import { computeDownloadUrl, getPublishConfigs, getPublishConfigsForUpdateInfo } from "../publish/PublishManager"
import { WinPackager } from "../winPackager"
import { AppPackageHelper, NsisTarget } from "./nsis"
import { NsisWebOptions } from "../../options/winOptions"
import { computeDownloadUrl, getPublishConfigs, getPublishConfigsForUpdateInfo } from "../../publish/PublishManager"
import { WinPackager } from "../../winPackager"
import { NsisTarget } from "../nsis"
import { AppPackageHelper } from "./nsisUtil"

/** @private */
export class WebInstallerTarget extends NsisTarget {
Expand Down
Loading

0 comments on commit 88e36db

Please sign in to comment.