From 1e5a8ae82b68e407e804fdd79307f1791a1d0cb6 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 23 Apr 2014 08:46:06 -0400 Subject: [PATCH] refactor(win) processOutput --- lib/server/win.js | 53 +++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/lib/server/win.js b/lib/server/win.js index 32264aa9..5e802849 100644 --- a/lib/server/win.js +++ b/lib/server/win.js @@ -4,9 +4,9 @@ */ (function(){ - "use strict"; + 'use strict'; - if(!global.cloudcmd) + if (!global.cloudcmd) return console.log( '# win.js' + '\n' + '# -----------' + '\n' + @@ -24,34 +24,33 @@ exec = main.child_process.exec, Util = main.util; + exports.getVolumes = function(callback) { + var chcp = 'chcp ' + Charset.UNICODE, + getVolumes = 'wmic logicaldisk get name'; - exports.getVolumes = function(pCallBack){ - var lCHCP = 'chcp ' + Charset.UNICODE, - lGetVolumes = 'wmic logicaldisk get name'; - - exec(lCHCP + ' && ' + lGetVolumes, retProcessOuput(pCallBack)); + exec(chcp + ' && ' + getVolumes, Util.bind(processOuput, callback)); }; - - function retProcessOuput(pCallBack){ - return function(pError, pStdout, pStderr){ - var lRemoveStr = [ - '\r', '\n', - 'Name', - 'Active code page: 65001 ' - ], - lVolumes = [], - lError = pError || pStderr; - exec('chcp ' + Charset.WIN32); - - if(!lError) { - lVolumes = Util.removeStr(pStdout, lRemoveStr) - .split(' '); - - lVolumes.pop(); - } + function processOuput(callback, error, stdout, stderr) { + var volumes = [], + removeStr = [ + '\r', '\n', + 'Name', + 'Active code page: 65001 ' + ]; + + if (!error) + error = stderr; + + exec('chcp ' + Charset.WIN32); + + if(!error) { + volumes = Util.removeStr(stdout, removeStr) + .split(' '); - Util.exec(pCallBack, lError || lVolumes); - }; + volumes.pop(); + } + + Util.exec(callback, error || volumes); } })();