From 28ebbe234d446163473dbc51a1e3f0c0c9b7a172 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Mon, 22 Jul 2013 14:23:38 +0000 Subject: [PATCH] feature(win) diskpart -> wmic --- ChangeLog | 2 + lib/server/win.js | 70 +++++++++-------------------------- lib/server/win/getvolumes.bat | 1 - lib/server/win/getvolumes.txt | 1 - 4 files changed, 19 insertions(+), 55 deletions(-) delete mode 100644 lib/server/win/getvolumes.bat delete mode 100644 lib/server/win/getvolumes.txt diff --git a/ChangeLog b/ChangeLog index a6e71d8d..c6af7437 100644 --- a/ChangeLog +++ b/ChangeLog @@ -124,6 +124,8 @@ getJSONfromFileTable. * feature(main) add to exports checkCallBackParams +* feature(win) diskpart -> wmic + 2012.04.22, v0.2.0 * Added alerting about errors. diff --git a/lib/server/win.js b/lib/server/win.js index 4dde5190..b98368dc 100644 --- a/lib/server/win.js +++ b/lib/server/win.js @@ -15,7 +15,6 @@ '# functions like work with drives(etc c).' + '\n' + '# http://coderaiser.github.com/cloudcmd' + '\n'); - var main = global.cloudcmd.main, Charset ={ UNICODE : 65001, @@ -27,67 +26,32 @@ exports.getVolumes = function(pCallBack){ - var SRVDIR = main.SRVDIR, - BATDIR = SRVDIR + 'win\\', - SCENARIO = BATDIR + 'getvolumes.txt', - lCHCP = 'chcp ' + Charset.UNICODE, - lDiskPart = 'diskpart -s "' + SCENARIO + '"'; + var lCHCP = 'chcp ' + Charset.UNICODE, + lGetVolumes = 'wmic logicaldisk get name' - exec(lCHCP + ' && ' + lDiskPart, retProcessOuput(pCallBack)); + exec(lCHCP + ' && ' + lGetVolumes, retProcessOuput(pCallBack)); }; function retProcessOuput(pCallBack){ return function(pError, pStdout, pStderr){ - var lstrPattern = 'Том ', - lCharPosition = 10; - - /** - * get position of current name of volume - * @param pNumber = number of volume - */ - var getPosition = function(pNumber){ - var lRet = pStdout.indexOf(lstrPattern + pNumber); - - return lRet; - }; - - /** - * get name of volume - * @param pPosition - current char position - */ - var getVolumeName = function (pPosition){ - var lRet = pStdout[pPosition + lCharPosition]; - - return lRet; - }; - - var lVolumes = []; - + var lRemoveStr = [ + '\r', '\n', + 'Name', + 'Active code page: 65001 ' + ], + lVolumes = [], + lError = pError || pStderr; exec('chcp ' + Charset.WIN32); - - if(!pError){ - var i = 0, - lNum = getPosition(i); - - /* if russian name not found - * try to search english name - */ - if(lNum < 0){ - lstrPattern = 'Volume ', - lCharPosition = 10 + 3; - lNum = getPosition(i); - } - - do{ - lVolumes[i] = getVolumeName(lNum); - lNum = getPosition(++i); - }while(lNum > 0); + + if(!lError) { + lVolumes = Util.removeStr(pStdout, lRemoveStr) + .split(' ') + + lVolumes.pop(); } - else - Util.log(pError); - Util.exec(pCallBack, lVolumes); + Util.exec(pCallBack, lError || lVolumes); }; } })(); diff --git a/lib/server/win/getvolumes.bat b/lib/server/win/getvolumes.bat deleted file mode 100644 index 15dc3828..00000000 --- a/lib/server/win/getvolumes.bat +++ /dev/null @@ -1 +0,0 @@ -diskpart /s getvolumes.txt diff --git a/lib/server/win/getvolumes.txt b/lib/server/win/getvolumes.txt deleted file mode 100644 index 7736c7fd..00000000 --- a/lib/server/win/getvolumes.txt +++ /dev/null @@ -1 +0,0 @@ -list volume