<commit_before>var os = require('os')
var path = require('path')

var mkdirp = require('mkdirp')
var rimraf = require('rimraf')
var ncp = require('ncp').ncp
var mv = require('mv')
var rcedit = require('rcedit')
var common = require('./common')

module.exports = {
  createApp: function createApp (opts, electronApp, cb) {
    var tmpDir = path.join(os.tmpdir(), 'electron-packager-windows')

    var newApp = path.join(tmpDir, opts.name + '-win32')
    // reset build folders + copy template app
    rimraf(tmpDir, function rmrfd () {
      // ignore errors
      mkdirp(newApp, function mkdirpd () {
        // ignore errors
        // copy app folder and use as template (this is exactly what Atom editor does)
        ncp(electronApp, newApp, function copied (err) {
          if (err) return cb(err)
          // rename electron.exe
          mv(path.join(newApp, 'electron.exe'), path.join(newApp, opts.name + '.exe'), function (err) {
            if (err) return cb(err)

            buildWinApp(opts, cb, newApp)
          })
        })
      })
    })
  }
}

function copy (from, to, cb) {
  rimraf(to, function () {
    mkdirp(to, function () {
      ncp(from, to, function (err) {
        if (err) { return cb(err) }
        cb()
      })
    })
  })
}

function buildWinApp (opts, cb, newApp) {
  var paths = {
    app: path.join(newApp, 'resources', 'app')
  }

  // copy users app into destination path
  ncp(opts.dir, paths.app, {filter: common.userIgnoreFilter(opts, true), dereference: true}, function copied (err) {
    if (err) return cb(err)

    function moveApp () {
      // finally, move app into cwd
      var finalPath = path.join(opts.out || process.cwd(), opts.name + '-win32')
      copy(newApp, finalPath, function moved (err) {
        if (err) return cb(err)
        if (opts.asar) {
          var finalPath = path.join(opts.out || process.cwd(), opts.name + '-win32', 'resources')
          common.asarApp(finalPath, function (err) {
            if (err) return cb(err)
            updateResourceData()
          })
        } else {
          updateResourceData()
        }
      })
    }

    function updateResourceData () {
      var finalPath = path.join(opts.out || process.cwd(), opts.name + '-win32')

      if (!opts.icon) {
        return cb(null, finalPath)
      }

      var exePath = path.join(opts.out || process.cwd(), opts.name + '-win32', opts.name + '.exe')
      var rcOptions = {<commit_msg>skipping the rcedit when both icon & version-string hash is not available<commit_after>var os = require('os')
var path = require('path')

var mkdirp = require('mkdirp')
var rimraf = require('rimraf')
var ncp = require('ncp').ncp
var mv = require('mv')
var rcedit = require('rcedit')
var common = require('./common')

module.exports = {
  createApp: function createApp (opts, electronApp, cb) {
    var tmpDir = path.join(os.tmpdir(), 'electron-packager-windows')

    var newApp = path.join(tmpDir, opts.name + '-win32')
    // reset build folders + copy template app
    rimraf(tmpDir, function rmrfd () {
      // ignore errors
      mkdirp(newApp, function mkdirpd () {
        // ignore errors
        // copy app folder and use as template (this is exactly what Atom editor does)
        ncp(electronApp, newApp, function copied (err) {
          if (err) return cb(err)
          // rename electron.exe
          mv(path.join(newApp, 'electron.exe'), path.join(newApp, opts.name + '.exe'), function (err) {
            if (err) return cb(err)

            buildWinApp(opts, cb, newApp)
          })
        })
      })
    })
  }
}

function copy (from, to, cb) {
  rimraf(to, function () {
    mkdirp(to, function () {
      ncp(from, to, function (err) {
        if (err) { return cb(err) }
        cb()
      })
    })
  })
}

function buildWinApp (opts, cb, newApp) {
  var paths = {
    app: path.join(newApp, 'resources', 'app')
  }

  // copy users app into destination path
  ncp(opts.dir, paths.app, {filter: common.userIgnoreFilter(opts, true), dereference: true}, function copied (err) {
    if (err) return cb(err)

    function moveApp () {
      // finally, move app into cwd
      var finalPath = path.join(opts.out || process.cwd(), opts.name + '-win32')
      copy(newApp, finalPath, function moved (err) {
        if (err) return cb(err)
        if (opts.asar) {
          var finalPath = path.join(opts.out || process.cwd(), opts.name + '-win32', 'resources')
          common.asarApp(finalPath, function (err) {
            if (err) return cb(err)
            updateResourceData()
          })
        } else {
          updateResourceData()
        }
      })
    }

    function updateResourceData () {
      var finalPath = path.join(opts.out || process.cwd(), opts.name + '-win32')

      if (!opts.icon && !opts['version-string']) {
        return cb(null, finalPath)
      }

      var exePath = path.join(opts.out || process.cwd(), opts.name + '-win32', opts.name + '.exe')
      var rcOptions = {
{'fraction_non_alphanumeric': 0.1459883370199075, 'fraction_numerical': 0.004021717273275689, 'mean_word_length': 2.3975409836065573, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6016501', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1565, 'n_words': 427}