feature(console) change volume in windows

This commit is contained in:
coderaiser 2014-07-08 10:10:39 -04:00
parent 2775d4cfc6
commit 7ebfd53ec3

View file

@ -97,6 +97,8 @@
var funcExec, firstChar,
connName, ret, isContain,
isVolume = isChangeWinVolume(command),
symbolsExec = ['*', '&', '{', '}', '|', '\'', '"'],
CWD = process.cwd(),
dir = ClientDirs[connNum],
@ -112,7 +114,7 @@
if (equalPart(command, CLOUDCMD))
ret = onCloudCmd(command, callback);
else if (equalPart(command, 'cd ')) {
else if (equalPart(command, 'cd ') || isVolume) {
ret = true;
onCD(command, dir, function(error, json) {
@ -262,30 +264,55 @@
return is;
}
function onCD(command, currDir, callback) {
var dir,
getDir = WIN32 ? 'chdir' : 'pwd',
paramDir = Util.rmStr(command, 'cd ');
function onCD(command, currDir, callback) {
var isChangeVolume = isChangeWinVolume(command),
isVolume = isWinVolume(command),
paramDir = Util.rmStr(command, 'cd '),
isRootOrHome = equalPart(paramDir, ['/', '~']),
getDir = WIN32 ? 'chdir' : 'pwd';
if (equalPart(paramDir, ['/', '~']))
dir = paramDir;
else
dir = path.join(currDir, paramDir);
if (!isRootOrHome && !isChangeVolume || isVolume)
command = 'cd ' + path.join(currDir, paramDir);
exec('cd ' + dir + ' && ' + getDir, function (error, stdout, stderr) {
exec(command + ' && ' + getDir, {cwd : currDir}, function (error, stdout, stderr) {
var errorStr = '',
errorData = error || stderr;
errorData = stderr || error,
isStr = Util.isString(errorData);
if (errorData)
if (errorData && !isStr)
errorStr = Util.stringifyJSON(errorData);
else
errorStr = errorData;
callback(errorData, {
Util.exec(callback, {
stderr : errorStr,
path : CloudFunc.rmNewLine(stdout)
});
});
}
function isWinVolume(command) {
var is, winVolume;
if (WIN32) {
winVolume = new RegExp('^[a-z]{1}:\\\\.*', 'i');
is = command.match(winVolume);
}
return is;
}
function isChangeWinVolume(command) {
var is, winVolume;
if (WIN32) {
winVolume = new RegExp('^[a-z]{1}:$', 'i');
is = command.match(winVolume);
}
return is;
}
function log(connNum, str, typeParam) {
var ret,