Skip to content

Commit

Permalink
Uppercase environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed May 5, 2015
1 parent 9c90f2f commit a2395b8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
22 changes: 14 additions & 8 deletions lib/env.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
var debug = require('debug')('win-detect-browsers')

// Clone env, dont mutate
var env = module.exports = require('xtend')(process.env)
, debug = require('debug')('win-detect-browsers')
var env = module.exports = {}

// Normalize to uppercase
Object.keys(process.env).forEach(function(name){
env[name.toUpperCase()] = process.env[name]
})

env.ProgramFiles_x86 = env['ProgramFiles(x86)'] || env['ProgramFiles']
env.ProgramFiles_x64 = env.ProgramW6432 // "C:\Program Files" on x64
env.PROGRAMFILES_X86 = env['PROGRAMFILES(X86)'] || env['PROGRAMFILES']
env.PROGRAMFILES_X64 = env.PROGRAMW6432 // "C:\Program Files" on x64

if (!env.USERPROFILE)
env.USERPROFILE = env.HOMEDRIVE + env.HOMEPATH
Expand All @@ -13,12 +19,12 @@ if (!env.USERPROFILE)
if (!env.LOCALAPPDATA)
env.LOCALAPPDATA = env.USERPROFILE + '\\Local Settings\\Application Data'

env.x64 =
env.X64 =
process.arch == 'x64' ||
'ProgramFiles(x86)' in env ||
'PROGRAMFILES(X86)' in env ||
'PROCESSOR_ARCHITEW6432' in env // in 32-bit process

debug('32-bit Program Files: %s', env.ProgramFiles_x86 || '-')
if (env.x64) debug('64-bit Program Files: %s', env.ProgramFiles_x64 || '-')
debug('32-bit Program Files: %s', env.PROGRAMFILES_X86 || '-')
if (env.X64) debug('64-bit Program Files: %s', env.PROGRAMFILES_X64 || '-')
debug('USERPROFILE: %s', env.USERPROFILE || '-')
debug('LOCALAPPDATA: %s', env.LOCALAPPDATA || '-')
8 changes: 4 additions & 4 deletions lib/finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ Finder.prototype.dir = function(envVar, path) {

// Find 32-bit or 64-bit version
Finder.prototype.programFiles = function(path) {
this.dir('ProgramFiles_x86', path)
if (env.x64) this.dir('ProgramFiles_x64', path)
this.dir('PROGRAMFILES_X86', path)
if (env.X64) this.dir('PROGRAMFILES_X64', path)
}

// Find in PATH environment variable
Expand All @@ -74,7 +74,7 @@ Finder.prototype.inPath = function() {
// Find in registry
Finder.prototype.registry = function(key, valueName, isParent, _useWoW) {
// Also check 32-bit registry (only works if 64-bit `cscript` is used?)
if (env.x64 && _useWoW!==false) {
if (env.X64 && _useWoW!==false) {
this.registry('Wow6432Node\\'+key, valueName, isParent, false)
}

Expand All @@ -88,7 +88,7 @@ Finder.prototype.registry = function(key, valueName, isParent, _useWoW) {
// Find in registry with version number
// First query for version, then for path
Finder.prototype.versionRegistry = function (vKey, vValue, pathKey, pathValue, _useWoW) {
if (env.x64 && _useWoW!==false) {
if (env.X64 && _useWoW!==false) {
// Also check 32-bit registry
this.versionRegistry(
'Wow6432Node\\'+vKey, vValue,
Expand Down

0 comments on commit a2395b8

Please sign in to comment.