-
Notifications
You must be signed in to change notification settings - Fork 4
/
eaglemode.wsf
107 lines (94 loc) · 3.13 KB
/
eaglemode.wsf
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<job><script language="JScript">
//------------------------------------------------------------------------------
// eaglemode.wsf
//
// Copyright (C) 2006-2010 Oliver Hamann.
//
// Homepage: http://eaglemode.sourceforge.net/
//
// This program is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License version 3 as published by the
// Free Software Foundation.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License version 3 for
// more details.
//
// You should have received a copy of the GNU General Public License version 3
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//------------------------------------------------------------------------------
// Have some objects.
var FileSys=WScript.CreateObject("Scripting.FileSystemObject");
var WshShell=WScript.CreateObject("WScript.Shell");
var ProcEnv=WshShell.Environment("PROCESS");
// Function for creating a command line from arguments.
function CommandFromArgs(argsArray)
{
var i,j,k,c,cmd,arg;
cmd="";
for (i=0; i<argsArray.length; i++) {
if (i>0) cmd+=" ";
arg=argsArray[i];
for (j=arg.length-1; j>=0; j--) {
c=arg.charAt(j);
if ((c<'0' || c>'9') && (c<'A' || c>'Z') && (c<'a' || c>'z') &&
c!='\\' && c!='/' && c!='.' && c!=':' && c!='-' && c!='+') break;
}
if (j<0 && arg.length>0) {
cmd+=arg;
}
else {
cmd+='"';
k=0;
for (j=0; j<arg.length; j++) {
c=arg.charAt(j);
if (c=='"') {
while (k>0) { cmd+='\\'; k--; }
cmd+='\\';
}
else if (c=='\\') k++;
else k=0;
cmd+=c;
}
while (k>0) { cmd+='\\'; k--; }
cmd+='"';
}
}
return (cmd);
}
// Helper for extending the PATH environment variable.
function PrependPath(path, list)
{
var i,j,k;
var newList=path;
for (i=0; i<list.length; i=j+1) {
j=list.indexOf(";",i);
if (j<0) j=list.length;
k=list.substr(i,j-i);
if (k.length>0 && k!=path) newList=newList+";"+k;
}
return newList;
}
// Determine the directory where this script file is in.
var emDir=FileSys.GetParentFolderName(WScript.ScriptFullName);
// Set the EM_DIR environment variable.
ProcEnv("EM_DIR")=emDir;
// Set the EM_ORIG_PATH environment variable.
ProcEnv("EM_ORIG_PATH")=ProcEnv("PATH");
// Prepend third-party bin directory to PATH, if it exists.
var thirdpartyBin=emDir+"\\thirdparty\\bin";
if (FileSys.FolderExists(thirdpartyBin)) {
ProcEnv("PATH")=PrependPath(thirdpartyBin,ProcEnv("PATH"));
}
// Prepend our own lib directory to PATH.
ProcEnv("PATH")=PrependPath(emDir+"\\lib",ProcEnv("PATH"));
// Prepare an array of arguments for starting the executable.
Args=new Array;
Args[0]=emDir+"\\bin\\eaglemode.exe";
for (i=0; i<WScript.Arguments.length; i++) Args[i+1]=WScript.Arguments(i);
// Convert the array of arguments to a command string.
Cmd=CommandFromArgs(Args);
// Run the command (without waiting for termination).
WshShell.Run(Cmd);
</script></job>