var iconv = require('iconv-lite')
var child_process = require('child_process')

function getVisualStudioPath() {
  var options = { encoding: 'ASCII' }
  var key = 'HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\VisualStudio\\SxS\\VS7'
  var result = child_process.execSync('reg query ' + key, options)
  var lines = result.split('\n')

  for (var i = 0; i < lines.length; ++i) {
    var values = lines[i].trim().split('    ')
    if (values.length > 2) {
      if (values[0] === '15.0') {
        return values[2]
      }
    }
  }
  return null
}

function getVSDevCmdPath() {
  var path = getVisualStudioPath()
  if (!path) {
    return null
  }
  return path + 'Common7\\Tools\\VsDevCmd.bat'
}

module.exports = {
  exec: function (filename) {
    var path = getVSDevCmdPath()
  	if (!path) {
  		return false
  	}

	  var encoding = 'cp936'
  	var binaryEncoding = 'binary'
	  var options = { encoding: binaryEncoding }
  	var cmd = 'cmd /c ' + filename + ' "' + path + '"'
	  child_process.exec(cmd, options, function (err, stdout, stderr) {
	    console.log(iconv.decode(new Buffer(stdout, binaryEncoding), encoding))
  	  console.log(iconv.decode(new Buffer(stderr, binaryEncoding), encoding))
	  })
  },
  exists: function () {
    return process.platform == 'win32' && !!getVSDevCmdPath()
  }
}


@@ -1,55 +1,33 @@
-var iconv = require('iconv-lite')%0Avar child_process
+const %7B execSync, spawnSync %7D
  = r
@@ -86,19 +86,21 @@
 h() %7B%0A  
-var
+const
  options
@@ -126,19 +126,21 @@
 II' %7D%0A  
-var
+const
  key = '
@@ -223,35 +223,22 @@
 '%0A  
-var result = child_process.
+const lines = 
 exec
@@ -274,29 +274,8 @@
 ons)
-%0A  var lines = result
 .spl
@@ -291,19 +291,19 @@
 %0A  for (
-var
+let
  i = 0; 
@@ -331,19 +331,19 @@
 ) %7B%0A    
-var
+let
  values 
@@ -528,19 +528,21 @@
 h() %7B%0A  
-var
+const
  path = 
@@ -567,15 +567,15 @@
 h()%0A
+%0A
   if (
-!
 path
@@ -593,63 +593,69 @@
 urn 
-null%0A  %7D%0A  return path + 'Common7%5C%5CTools%5C%5CVsDevCmd.bat'
+%60$%7Bpath%7DVC%5C%5CAuxiliary%5C%5CBuild%5C%5Cvcvars64.bat%60%0A  %7D%0A  return null
 %0A%7D%0A%0A
@@ -679,27 +679,16 @@
 %7B%0A  exec
-: function 
 (filenam
@@ -688,24 +688,33 @@
 filename
+, options
 ) %7B%0A    
 var path
@@ -705,19 +705,21 @@
 ) %7B%0A    
-var
+const
  path = 
@@ -736,19 +736,21 @@
 dPath()%0A
+%0A
   
-%09
+  
 if (!pat
@@ -760,413 +760,112 @@
 %7B%0A  
-%09%09
+    
 return 
-false%0A  %09%7D%0A%0A%09  var encoding = 'cp936'%0A  %09var binaryEncoding = 'binary'%0A%09  var options = %7B encoding: binaryEncoding %7D%0A  %09var cmd = 'cmd /c ' + filename + ' %22' + path + '%22'%0A%09  child_process.exec(cmd, options, function (err, stdout, stderr) %7B%0A%09    console.log(iconv.decode(new Buffer(stdout, binaryEncoding), encoding))%0A  %09  console.log(iconv.decode(new Buffer(stderr, binaryEncoding), encoding))%0A%09 
+null%0A    %7D%0A    return spawnSync('cmd', %5B'/c', filename, path%5D, %7B stdio: 'inherit', ...options
  %7D)%0A
@@ -881,19 +881,8 @@
 ists
-: function 
 () %7B
@@ -950,9 +950,8 @@
 )%0A  %7D%0A%7D%0A
-%0A

update msbuild.js