-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
Copy pathInstallWizardForVC2010Express.js
230 lines (198 loc) · 8.14 KB
/
InstallWizardForVC2010Express.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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
// Setup program for the Cocos2d-win32 App Wizard for VC++ 10.0 (VC2010)
main();
function EchoError(bQuiet, strMsg) {
strMsg = "Error: " + strMsg;
if (! bQuiet) {
WScript.Echo(strMsg);
}
else {
var FileSys = new ActiveXObject("Scripting.FileSystemObject");
var strLogPath = "InstallWizardLog.txt"
var file = FileSys.OpenTextFile(strLogPath, 8, true);
file.WriteLine(strMsg);
file.Close();
}
}
function main() {
// Decode command line arguments
var bDebug = false;
var bQuiet = false;
var bElevated = false;
var Args = WScript.Arguments;
for (var i = 0; i < Args.length; i++) {
if (Args(i) == "/debug")
bDebug = true;
else if (Args(i) == "/elevated")
bElevated = true;
else if (Args(i) == "/quiet")
bQuiet = true;
}
// See if UAC is enabled
var Shell = WScript.CreateObject("Shell.Application");
if (!bElevated && Shell.IsRestricted("System", "EnableLUA")) {
// Check that the script is being run interactively.
if (!WScript.Interactive) {
EchoError(bQuiet, "(Windows LUA) Elevation required.");
return;
}
// Now relaunch the script, using the "RunAs" verb to elevate
var strParams = "\"" + WScript.ScriptFullName + "\"";
if (bDebug)
strParams += " /debug";
strParams += " /elevated";
Shell.ShellExecute(WScript.FullName, strParams, null, "RunAs");
return;
}
// Create shell object
var WSShell = WScript.CreateObject("WScript.Shell");
// Create file system object
var FileSys = WScript.CreateObject("Scripting.FileSystemObject");
// Get the folder containing the script file
var strScriptPath = FileSys.GetParentFolderName(WScript.ScriptFullName);
if (strScriptPath == null || strScriptPath == "")
strScriptPath = ".";
// Get the folder script files copy to
var strValue = "";
try {
var strVCKey = "HKLM\\Software\\Microsoft\\VCExpress\\10.0\\Setup\\VC\\ProductDir";
strValue = WSShell.RegRead(strVCKey);
}
catch (e) {
try {
var strVCKey_x64 = "HKLM\\Software\\Wow6432Node\\Microsoft\\VCExpress\\10.0\\Setup\\VC\\ProductDir";
strValue = WSShell.RegRead(strVCKey_x64);
}
catch (e) {
EchoError(bQuiet, "Cannot find where Visual C++ 2010 Express is installed.");
return;
}
}
var strDestFolder = FileSys.BuildPath(strValue, "Express\\vcprojects");
if (bDebug)
WScript.Echo("Destination: " + strDestFolder);
if (!FileSys.FolderExists(strDestFolder)) {
EchoError(bQuiet, "Cannot find destination folder (should be: " + strDestFolder + ")");
return;
}
// Wizard Info
var nNumWizards = 2;
var astrWizardName = new Array();
astrWizardName[0] = "CCAppWiz.win32";
astrWizardName[1] = "CCAppWiz.wophone";
var nCntr;
for (nCntr = 0; nCntr < nNumWizards; nCntr++) {
var strSourceFolder = FileSys.BuildPath(strScriptPath, astrWizardName[nCntr]);
if (bDebug)
WScript.Echo("Source: " + strSourceFolder);
if (!FileSys.FolderExists(strSourceFolder)) {
EchoError(bQuiet, "Cannot find Wizard folder (should be: " + strSourceFolder + ")");
return;
}
// Copy files
try {
var strSrc = FileSys.BuildPath(strSourceFolder, astrWizardName[nCntr] + ".ico");
var strDest = FileSys.BuildPath(strDestFolder, astrWizardName[nCntr] + ".ico");
FileSys.CopyFile(strSrc, strDest);
strSrc = FileSys.BuildPath(strSourceFolder, astrWizardName[nCntr] + ".vsdir");
strDest = FileSys.BuildPath(strDestFolder, astrWizardName[nCntr] + ".vsdir");
FileSys.CopyFile(strSrc, strDest);
}
catch (e) {
var strError = "no info";
if (e.description.length != 0)
strError = e.description;
EchoError(bQuiet, "Cannot copy file (" + strError + ")");
return;
}
// Read and write CCAppWiz.vsz, add engine version and replace path when found
try {
var strSrc = FileSys.BuildPath(strSourceFolder, astrWizardName[nCntr] + ".vsz");
var strDest = FileSys.BuildPath(strDestFolder, astrWizardName[nCntr] + ".vsz");
var ForReading = 1;
var fileSrc = FileSys.OpenTextFile(strSrc, ForReading);
if (fileSrc == null) {
EchoError(bQuiet, "Cannot open source file: " + strSrc);
return;
}
var ForWriting = 2;
var fileDest = FileSys.OpenTextFile(strDest, ForWriting, true);
if (fileDest == null) {
EchoError(bQuiet, " Cannot open destination file: " + strDest);
return;
}
while (!fileSrc.AtEndOfStream) {
var strLine = fileSrc.ReadLine();
if (strLine.indexOf("Wizard=VsWizard.VsWizardEngine") != -1)
strLine += ".10.0";
else if (strLine.indexOf("WIZARD_VERSION") != -1)
strLine = "Param=\"WIZARD_VERSION = 10.0\"";
else if (strLine.indexOf("ABSOLUTE_PATH") != -1)
strLine = "Param=\"ABSOLUTE_PATH = " + strSourceFolder + "\"";
fileDest.WriteLine(strLine);
}
fileDest.WriteLine("Param=\"VC_EXPRESS = 1\"");
fileSrc.Close();
fileDest.Close();
}
catch (e) {
var strError = "no info";
if (e.description.length != 0)
strError = e.description;
EchoError(bQuiet, "Cannot read and write CCAppWiz.vsz (" + strError + ")");
return;
}
}
// Create Cocos2d-x folder
var strDestCCFolder = "";
try {
strDestCCFolder = FileSys.BuildPath(strDestFolder, "Cocos2d-x");
if (!FileSys.FolderExists(strDestCCFolder))
FileSys.CreateFolder(strDestCCFolder);
if (bDebug)
WScript.Echo("Cocos2d-x Folder: " + strDestCCFolder);
}
catch (e) {
var strError = "no info";
if (e.description.length != 0)
strError = e.description;
EchoError(bQuiet, "Cannot create Cocos2d-x folder (" + strError + ")");
return;
}
// Read and write additional CCAppWiz.vsdir and CCAppWiz.uphone.vsdir, add path to the wizard location
try {
var strDest = FileSys.BuildPath(strDestCCFolder, "Cocos2d-x.vsdir");
var ForWriting = 2;
var fileDest = FileSys.OpenTextFile(strDest, ForWriting, true);
if (fileDest == null) {
EchoError(bQuiet, "Cannot open destination file: " + strDest);
return;
}
var nCntr;
for (nCntr = 0; nCntr < nNumWizards; nCntr++) {
var strSourceFolder = FileSys.BuildPath(strScriptPath, astrWizardName[nCntr]);
var strSrc = FileSys.BuildPath(strSourceFolder, astrWizardName[nCntr] + ".vsdir");
var ForReading = 1;
var fileSrc = FileSys.OpenTextFile(strSrc, ForReading);
if (fileSrc == null) {
EchoError(bQuiet, "Cannot open source file: " + strSrc);
return;
}
while (!fileSrc.AtEndOfStream) {
var strLine = fileSrc.ReadLine();
if (strLine.indexOf(astrWizardName[nCntr] + ".vsz|") != -1)
strLine = "..\\" + strLine;
fileDest.WriteLine(strLine);
}
fileSrc.Close();
}
fileDest.Close();
}
catch (e) {
var strError = "no info";
if (e.description.length != 0)
strError = e.description;
EchoError(bQuiet, "Cannot read and write Cocos2d-x\\CCAppWiz.vsdir (" + strError + ")");
return;
}
EchoError(bQuiet, "App Wizard successfully installed for VC2010 Express!");
}