From 481f42163c994f9d8582274dbc342e7ea41364f1 Mon Sep 17 00:00:00 2001 From: Vincent Weevers Date: Sat, 5 Aug 2023 01:20:32 +0200 Subject: [PATCH] feat: support setting resource strings (#92) rcedit supports `--set-resource-string ` but this was not yet exposed here. Co-authored-by: David Sanders --- 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 225866c..481e6c9 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,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 4f0295b..67f215b 100644 --- a/test/rcedit-test.js +++ b/test/rcedit-test.js @@ -131,6 +131,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)',