Skip to content

Commit

Permalink
feat: support setting resource strings (#92)
Browse files Browse the repository at this point in the history
rcedit supports `--set-resource-string <id> <value>` but this was
not yet exposed here.

Co-authored-by: David Sanders <[email protected]>
  • Loading branch information
vweevers and dsanders11 authored Aug 4, 2023
1 parent b696ed2 commit 481f421
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
11 changes: 11 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/rcedit.js
Original file line number Diff line number Diff line change
@@ -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']

Expand Down
12 changes: 12 additions & 0 deletions test/rcedit-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
Expand Down

0 comments on commit 481f421

Please sign in to comment.