-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
bgloader.js
49 lines (44 loc) · 1.11 KB
/
bgloader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
if (!Array.prototype.map) {
Array.prototype.map = function(fn) {
var rv = [];
for (var i = 0; i < this.length; i++)
rv.push(fn(this[i]));
return rv;
};
}
function main() {
var args = [];
var argl = WScript.arguments.length;
for (var i = 0; i < argl; i++) {
args.push(WScript.arguments(i));
}
var objShell = WScript.CreateObject("WScript.Shell");
objShell.Run(build(args), 0, true);
}
function build(cmd) {
if (typeof(cmd) === "string") {
return cmd;
} else if (typeof(cmd) === "object") {
return cmd.map(function(s) {
var regex = /[ "]/g;
if (!regex.test(s)) {
return s;
} else {
return "\"" + addslashes(s) + "\"";
}
}).join(' ');
} else {
return "";
}
}
function addslashes(s) {
return s.toString().replace(/\\/g, '\\\\').
replace(/\u0008/g, '\\b').
replace(/\t/g, '\\t').
replace(/\n/g, '\\n').
replace(/\f/g, '\\f').
replace(/\r/g, '\\r').
replace(/'/g, '\\\'').
replace(/"/g, '\\"');
};
main();