minor changes

This commit is contained in:
coderaiser 2012-12-14 05:49:54 -05:00
parent 506fedcd1b
commit 033e0314a6

View file

@ -16,60 +16,71 @@
'# http://coderaiser.github.com/cloudcmd' + '\n');
var main = global.cloudcmd.main,
Charset ={
UNICODE : 65001,
WIN32 : 866
},
SRVDIR = main.SRVDIR,
BATDIR = SRVDIR + 'win\\',
GETVOLUMES = BATDIR + 'getvolumes',
BAT = GETVOLUMES + '.bat',
SCENARIO = GETVOLUMES + '.txt',
StdOut,
exec = main.child_process.exec,
Util = main.util;
/**
* get position of current name of volume
* @param pNumber = number of volume
*/
function getPosition(pNumber){
var lRet,
lstrPattern = 'Том ';
exports.GetVolumes = function(pCallBack){
var SRVDIR = '.\\',
BATDIR = SRVDIR + 'win\\',
SCENARIO = BATDIR + 'getvolumes.txt',
lCHCP = 'chcp ' + Charset.Unicode,
lDiskPart = 'diskpart -s' + SCENARIO;
lRet = StdOut.indexOf(lstrPattern + pNumber);
return lRet;
}
exec(lCHCP + ' && ' + lDiskPart, retProcessOuput(pCallBack));
};
/**
* get name of volume
* @param pPosition - current char position
*/
function getVolumeName(pPosition){
var lRet,
lCharPosition = 10;
function retProcessOuput(pCallBack){
return function(pError, pStdout, pStderr){
/**
* get position of current name of volume
* @param pNumber = number of volume
*/
var getPosition = function(pNumber){
var lRet,
lstrPattern = 'Том ';
lRet = pStdout.indexOf(lstrPattern + pNumber);
return lRet;
};
lRet = StdOut[pPosition + lCharPosition];
return lRet;
}
exec(BAT + ' -s ' + SCENARIO, processOuput);
function processOuput(pError, pStdout, pStderr){
StdOut = pStdout;
if(!pError){
var lVolumes = [],
i = 0,
lNum = getPosition(i);
/**
* get name of volume
* @param pPosition - current char position
*/
var getVolumeName = function (pPosition){
var lRet,
lCharPosition = 10;
lRet = pStdout[pPosition + lCharPosition];
return lRet;
};
do{
lVolumes[i] = getVolumeName(lNum);
lNum = getPosition(++i);
}while(lNum > 0);
}
else
Util.log(pError);
var lVolumes = [];
exec('chcp ' + Charset.WIN32);
if(!pError){
var i = 0,
lNum = getPosition(i);
do{
lVolumes[i] = getVolumeName(lNum);
lNum = getPosition(++i);
}while(lNum > 0);
}
else
Util.log(pError);
Util.exec(pCallBack, lVolumes);
};
}
})();