Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support setting resource strings #92

Merged
merged 2 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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