rcedit.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. var path = require('path')
  2. var spawn = require('child_process').spawn
  3. var pairSettings = ['version-string']
  4. var singleSettings = ['file-version', 'product-version', 'icon', 'requested-execution-level']
  5. var noPrefixSettings = ['application-manifest']
  6. module.exports = function (exe, options, callback) {
  7. var rcedit = path.resolve(__dirname, '..', 'bin', 'rcedit.exe')
  8. var args = [exe]
  9. pairSettings.forEach(function (name) {
  10. if (options[name] != null) {
  11. for (var key in options[name]) {
  12. var value = options[name][key]
  13. args.push('--set-' + name)
  14. args.push(key)
  15. args.push(value)
  16. }
  17. }
  18. })
  19. singleSettings.forEach(function (name) {
  20. if (options[name] != null) {
  21. args.push('--set-' + name)
  22. args.push(options[name])
  23. }
  24. })
  25. noPrefixSettings.forEach(function (name) {
  26. if (options[name] != null) {
  27. args.push('--' + name)
  28. args.push(options[name])
  29. }
  30. })
  31. var spawnOptions = {}
  32. spawnOptions.env = Object.create(process.env)
  33. if (process.platform !== 'win32') {
  34. args.unshift(rcedit)
  35. rcedit = 'wine'
  36. // Supress fixme: stderr log messages
  37. spawnOptions.env.WINEDEBUG = '-all'
  38. }
  39. var child = spawn(rcedit, args, spawnOptions)
  40. var stderr = ''
  41. var error = null
  42. child.on('error', function (err) {
  43. if (error == null) error = err
  44. })
  45. child.stderr.on('data', function (data) {
  46. stderr += data
  47. })
  48. child.on('close', function (code) {
  49. if (error != null) {
  50. callback(error)
  51. } else if (code === 0) {
  52. callback()
  53. } else {
  54. var message = 'rcedit.exe failed with exit code ' + code
  55. stderr = stderr.trim()
  56. if (stderr) message += '. ' + stderr
  57. callback(new Error(message))
  58. }
  59. })
  60. }