2011-03-09 15:35:06 +08:00
|
|
|
// Setup program for the Cocos2d-win32 App Wizard for VC++ 10.0 (VC2010)
|
2010-11-16 11:25:33 +08:00
|
|
|
|
|
|
|
main();
|
|
|
|
|
2011-05-03 14:28:31 +08:00
|
|
|
function EchoInfo(bQuiet, 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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-09 15:35:06 +08:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-19 15:56:32 +08:00
|
|
|
function main() {
|
|
|
|
// Decode command line arguments
|
|
|
|
var bDebug = false;
|
2011-03-09 15:35:06 +08:00
|
|
|
var bQuiet = false;
|
2010-11-19 15:56:32 +08:00
|
|
|
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;
|
2011-03-09 15:35:06 +08:00
|
|
|
else if (Args(i) == "/quiet")
|
|
|
|
bQuiet = true;
|
2010-11-19 15:56:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
2011-03-09 15:35:06 +08:00
|
|
|
EchoError(bQuiet, "(Windows LUA) Elevation required.");
|
2010-11-19 15:56:32 +08:00
|
|
|
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 {
|
2011-03-09 15:35:06 +08:00
|
|
|
var strVCKey = "HKLM\\Software\\Microsoft\\VisualStudio\\10.0\\Setup\\VC\\ProductDir";
|
|
|
|
strValue = WSShell.RegRead(strVCKey);
|
2010-11-19 15:56:32 +08:00
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
try {
|
2011-03-09 15:35:06 +08:00
|
|
|
var strVCKey_x64 = "HKLM\\Software\\Wow6432Node\\Microsoft\\VisualStudio\\10.0\\Setup\\VC\\ProductDir";
|
|
|
|
strValue = WSShell.RegRead(strVCKey_x64);
|
2010-11-19 15:56:32 +08:00
|
|
|
}
|
|
|
|
catch (e) {
|
2011-03-09 15:35:06 +08:00
|
|
|
EchoError(bQuiet, "Cannot find where Visual Studio 2010 is installed.");
|
2010-11-19 15:56:32 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var strDestFolder = FileSys.BuildPath(strValue, "vcprojects");
|
|
|
|
if (bDebug)
|
|
|
|
WScript.Echo("Destination: " + strDestFolder);
|
2011-03-09 15:35:06 +08:00
|
|
|
|
2010-11-19 15:56:32 +08:00
|
|
|
if (!FileSys.FolderExists(strDestFolder)) {
|
2011-03-09 15:35:06 +08:00
|
|
|
EchoError(bQuiet, "Cannot find destination folder (should be: " + strDestFolder + ")");
|
2010-11-19 15:56:32 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wizard Info
|
|
|
|
var nNumWizards = 2;
|
|
|
|
|
|
|
|
var astrWizardName = new Array();
|
2011-03-09 15:35:06 +08:00
|
|
|
astrWizardName[0] = "CCAppWiz.win32";
|
|
|
|
astrWizardName[1] = "CCAppWiz.wophone";
|
2010-11-19 15:56:32 +08:00
|
|
|
|
|
|
|
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)) {
|
2011-03-09 15:35:06 +08:00
|
|
|
EchoError(bQuiet, "Cannot find Wizard folder (should be: " + strSourceFolder + ")");
|
2010-11-19 15:56:32 +08:00
|
|
|
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;
|
2011-03-09 15:35:06 +08:00
|
|
|
EchoError(bQuiet, "Cannot copy file (" + strError + ")");
|
2010-11-19 15:56:32 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-09 15:35:06 +08:00
|
|
|
// Read and write CCAppWiz.vsz, add engine version and replace path when found
|
2010-11-19 15:56:32 +08:00
|
|
|
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) {
|
2011-03-09 15:35:06 +08:00
|
|
|
EchoError(bQuiet, "Cannot open source file: " + strSrc);
|
2010-11-19 15:56:32 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var ForWriting = 2;
|
|
|
|
var fileDest = FileSys.OpenTextFile(strDest, ForWriting, true);
|
|
|
|
if (fileDest == null) {
|
2011-03-09 15:35:06 +08:00
|
|
|
EchoError(bQuiet, " Cannot open destination file: " + strDest);
|
2010-11-19 15:56:32 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!fileSrc.AtEndOfStream) {
|
|
|
|
var strLine = fileSrc.ReadLine();
|
|
|
|
if (strLine.indexOf("Wizard=VsWizard.VsWizardEngine") != -1)
|
2011-03-09 15:35:06 +08:00
|
|
|
strLine += ".10.0";
|
2010-11-19 15:56:32 +08:00
|
|
|
else if (strLine.indexOf("WIZARD_VERSION") != -1)
|
2011-03-09 15:35:06 +08:00
|
|
|
strLine = "Param=\"WIZARD_VERSION = 10.0\"";
|
2010-11-19 15:56:32 +08:00
|
|
|
else if (strLine.indexOf("ABSOLUTE_PATH") != -1)
|
|
|
|
strLine = "Param=\"ABSOLUTE_PATH = " + strSourceFolder + "\"";
|
|
|
|
fileDest.WriteLine(strLine);
|
|
|
|
}
|
|
|
|
|
|
|
|
fileSrc.Close();
|
|
|
|
fileDest.Close();
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
var strError = "no info";
|
|
|
|
if (e.description.length != 0)
|
|
|
|
strError = e.description;
|
2011-03-09 15:35:06 +08:00
|
|
|
EchoError(bQuiet, "Cannot read and write CCAppWiz.vsz (" + strError + ")");
|
2010-11-19 15:56:32 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create Cocos2d-x folder
|
2011-03-09 15:35:06 +08:00
|
|
|
var strDestCCFolder = "";
|
2010-11-19 15:56:32 +08:00
|
|
|
try {
|
2011-03-09 15:35:06 +08:00
|
|
|
strDestCCFolder = FileSys.BuildPath(strDestFolder, "Cocos2d-x");
|
|
|
|
if (!FileSys.FolderExists(strDestCCFolder))
|
|
|
|
FileSys.CreateFolder(strDestCCFolder);
|
2010-11-19 15:56:32 +08:00
|
|
|
if (bDebug)
|
2011-03-09 15:35:06 +08:00
|
|
|
WScript.Echo("Cocos2d-x Folder: " + strDestCCFolder);
|
2010-11-19 15:56:32 +08:00
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
var strError = "no info";
|
|
|
|
if (e.description.length != 0)
|
|
|
|
strError = e.description;
|
2011-03-09 15:35:06 +08:00
|
|
|
EchoError(bQuiet, "Cannot create Cocos2d-x folder (" + strError + ")");
|
2010-11-19 15:56:32 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-09 15:35:06 +08:00
|
|
|
// Read and write additional CCAppWiz.vsdir and CCAppWiz.uphone.vsdir, add path to the wizard location
|
2010-11-19 15:56:32 +08:00
|
|
|
try {
|
2011-03-09 15:35:06 +08:00
|
|
|
var strDest = FileSys.BuildPath(strDestCCFolder, "Cocos2d-x.vsdir");
|
2010-11-19 15:56:32 +08:00
|
|
|
|
|
|
|
var ForWriting = 2;
|
|
|
|
|
|
|
|
var fileDest = FileSys.OpenTextFile(strDest, ForWriting, true);
|
|
|
|
if (fileDest == null) {
|
2011-03-09 15:35:06 +08:00
|
|
|
EchoError(bQuiet, "Cannot open destination file: " + strDest);
|
2010-11-19 15:56:32 +08:00
|
|
|
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) {
|
2011-03-09 15:35:06 +08:00
|
|
|
EchoError(bQuiet, "Cannot open source file: " + strSrc);
|
2010-11-19 15:56:32 +08:00
|
|
|
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;
|
2011-03-09 15:35:06 +08:00
|
|
|
EchoError(bQuiet, "Cannot read and write Cocos2d-x\\CCAppWiz.vsdir (" + strError + ")");
|
2010-11-19 15:56:32 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-03 14:28:31 +08:00
|
|
|
EchoInfo(bQuiet, "App Wizard successfully installed for VS2010!");
|
2010-11-16 11:25:33 +08:00
|
|
|
}
|