From 0561c3e51a0fc0ea27ee44af1ff5df670a798bdf Mon Sep 17 00:00:00 2001 From: Vincent Weevers Date: Thu, 12 May 2022 17:35:23 +0200 Subject: [PATCH] feat: support setting resource strings rcedit supports `--set-resource-string ` but this was not yet exposed here. --- README.md | 2 ++ lib/index.d.ts | 11 +++++++++++ lib/rcedit.js | 2 +- test/rcedit-test.js | 12 ++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index eee2ce7..f658139 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,8 @@ const rcedit = require('rcedit') * `application-manifest` - String path to a local manifest file to use. See [here](https://msdn.microsoft.com/en-us/library/windows/desktop/aa374191.aspx) for more details. +* `resource-string` - An object in the form of `{ [id]: value }` to add to the + [string table](https://docs.microsoft.com/en-us/windows/win32/menurc/stringtable-resource). Returns a `Promise` with no value. diff --git a/lib/index.d.ts b/lib/index.d.ts index 24c931a..bc657ad 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -36,6 +36,13 @@ declare namespace rcedit { /** Name of the product with which the file is distributed. */ ProductName?: string } + /** + * Resource strings. See [string table](https://docs.microsoft.com/en-us/windows/win32/menurc/stringtable-resource) + * for details. + */ + interface ResourceStrings { + [n: number]: string + } /** * EXE metadata that can be changed. */ @@ -62,6 +69,10 @@ declare namespace rcedit { * XML that is to be embedded in the EXE. */ 'application-manifest'?: string + /** + * Set resource strings. + */ + 'resource-string'?: ResourceStrings } } diff --git a/lib/rcedit.js b/lib/rcedit.js index b6bd5ce..a7b0a72 100644 --- a/lib/rcedit.js +++ b/lib/rcedit.js @@ -1,7 +1,7 @@ const { canRunWindowsExeNatively, is64BitArch, spawnExe } = require('cross-spawn-windows-exe') const path = require('path') -const pairSettings = ['version-string'] +const pairSettings = ['version-string', 'resource-string'] const singleSettings = ['file-version', 'product-version', 'icon', 'requested-execution-level'] const noPrefixSettings = ['application-manifest'] diff --git a/test/rcedit-test.js b/test/rcedit-test.js index 1ee2efc..163843e 100644 --- a/test/rcedit-test.js +++ b/test/rcedit-test.js @@ -105,6 +105,18 @@ describe('async rcedit(exePath, options)', function () { assert.ok(exeData.includes('requireAdministrator')) }) + it('supports setting resource strings', async () => { + let exeData = await readFile(exePath, 'utf16le') + assert.ok(!exeData.includes('bonfire')) + assert.ok(!exeData.includes('mumbai')) + + await rcedit(exePath, { 'resource-string': { 1: 'bonfire', 2: 'mumbai' } }) + + exeData = await readFile(exePath, 'utf16le') + assert.ok(exeData.includes('bonfire')) + assert.ok(exeData.includes('mumbai')) + }) + it('reports an error when the .exe path does not exist', async () => { await assertRceditError(path.join(tempPath, 'does-not-exist.exe'), { 'file-version': '3.4.5.6' }, [ 'Command failed with a non-zero return code (1)',