fixed #225 Create new project from main menu ok.

Signed-off-by: yangws <yangws@cocos2d-x.org>
This commit is contained in:
yangws 2010-11-26 17:30:34 +08:00
parent 8c079cb89f
commit 462a8baf33
2 changed files with 322 additions and 343 deletions

View File

@ -27,21 +27,6 @@ function OnFinish(selProj, selObj) {
wizard.AddSymbol("CCX_CURRENT_YEAR", nYear); wizard.AddSymbol("CCX_CURRENT_YEAR", nYear);
wizard.AddSymbol("CCX_CURRENT_DATE", d.toString()); wizard.AddSymbol("CCX_CURRENT_DATE", d.toString());
var FileSys = new ActiveXObject("Scripting.FileSystemObject");
var strUserTarget = strProjectName + ".uphone.vcproj.user";
var strUserPath = FileSys.BuildPath(strProjectPath, strUserTarget);
if (!FileSys.FolderExists(strProjectPath))
FileSys.CreateFolder(strProjectPath);
var file = FileSys.OpenTextFile(strUserPath, 2, true);
if (file == null) {
return;
}
var strUserValue = "<?xml version=\"1.0\" encoding=\"utf-8\"?><VisualStudioUserFile ProjectType=\"Visual C++\" Version=\"9.00\" ShowAllFiles=\"true\"><Configurations><Configuration Name=\"Debug|Win32\"><DebugSettings Command=\"TG3_RunDLL.exe\" CommandArguments=\"$(TargetPath)\"/></Configuration></VisualStudioUserFile>";
file.WriteLine(strUserValue);
file.Close();
selProj = CreateCustomProject(strProjectName, strProjectPath); selProj = CreateCustomProject(strProjectName, strProjectPath);
AddConfig(selProj, strProjectName); AddConfig(selProj, strProjectName);
AddFilters(selProj); AddFilters(selProj);
@ -77,6 +62,35 @@ function CreateCustomProject(strProjectName, strProjectPath) {
} }
} }
// Create vcproj.user file
var FileSys = new ActiveXObject("Scripting.FileSystemObject");
var strUserTarget = strProjectName + ".uphone.vcproj.user";
var strUserPath = FileSys.BuildPath(strProjectPath, strUserTarget);
var astrParentPath = new Array();
astrParentPath[0] = strProjectPath;
while (astrParentPath.length) {
var strPath = astrParentPath.pop();
var strParentPath = FileSys.GetParentFolderName(strPath);
if (!FileSys.FolderExists(strParentPath)) {
astrParentPath.push(strPath);
astrParentPath.push(strParentPath);
continue;
}
else {
FileSys.CreateFolder(strPath);
}
}
var file = FileSys.OpenTextFile(strUserPath, 2, true);
if (file == null) {
return;
}
var strUserValue = "<?xml version=\"1.0\" encoding=\"utf-8\"?><VisualStudioUserFile ProjectType=\"Visual C++\" Version=\"9.00\" ShowAllFiles=\"true\"><Configurations><Configuration Name=\"Debug|Win32\"><DebugSettings Command=\"TG3_RunDLL.exe\" CommandArguments=\"$(TargetPath)\"/></Configuration></VisualStudioUserFile>";
file.WriteLine(strUserValue);
file.Close();
var strProjectNameWithExt = ''; var strProjectNameWithExt = '';
strProjectNameWithExt = strProjectName + '.uphone.vcproj'; strProjectNameWithExt = strProjectName + '.uphone.vcproj';

View File

@ -1,14 +1,12 @@
function OnFinish(selProj, selObj) function OnFinish(selProj, selObj) {
{ try {
try
{
var strProjectPath = wizard.FindSymbol('PROJECT_PATH'); var strProjectPath = wizard.FindSymbol('PROJECT_PATH');
var strProjectName = wizard.FindSymbol('PROJECT_NAME'); var strProjectName = wizard.FindSymbol('PROJECT_NAME');
// var WizardVersion = wizard.FindSymbol('WIZARD_VERSION'); // var WizardVersion = wizard.FindSymbol('WIZARD_VERSION');
// if(WizardVersion >= 8.0) // if(WizardVersion >= 8.0)
// { // {
// } // }
// Create symbols based on the project name // Create symbols based on the project name
var strSafeProjectName = CreateSafeName(strProjectName); var strSafeProjectName = CreateSafeName(strProjectName);
@ -20,24 +18,8 @@ function OnFinish(selProj, selObj)
var d = new Date(); var d = new Date();
var nYear = 0; var nYear = 0;
nYear = d.getFullYear(); nYear = d.getFullYear();
if(nYear >= 2003) if (nYear >= 2003)
wizard.AddSymbol("CCX_CURRENT_YEAR", nYear); wizard.AddSymbol("CCX_CURRENT_YEAR", nYear);
var FileSys = new ActiveXObject("Scripting.FileSystemObject");
var strUserTarget = strProjectName + ".win32.vcproj.user";
var strUserPath = FileSys.BuildPath(strProjectPath, strUserTarget);
if (!FileSys.FolderExists(strProjectPath))
FileSys.CreateFolder(strProjectPath);
var file = FileSys.OpenTextFile(strUserPath, 2, true);
if (file == null)
{
return;
}
var strUserValue = "<?xml version=\"1.0\" encoding=\"utf-8\"?><VisualStudioUserFile ProjectType=\"Visual C++\" Version=\"9.00\" ShowAllFiles=\"true\"></VisualStudioUserFile>";
file.WriteLine(strUserValue);
file.Close();
// Create project and configurations // Create project and configurations
selProj = CreateCustomProject(strProjectName, strProjectPath); selProj = CreateCustomProject(strProjectName, strProjectPath);
AddConfigurations(selProj, strProjectName); AddConfigurations(selProj, strProjectName);
@ -51,35 +33,56 @@ function OnFinish(selProj, selObj)
selProj.Object.Save(); selProj.Object.Save();
} }
catch(e) catch (e) {
{
if (e.description.length != 0) if (e.description.length != 0)
SetErrorInfo(e); SetErrorInfo(e);
return e.number; return e.number;
} }
} }
function CreateCustomProject(strProjectName, strProjectPath) function CreateCustomProject(strProjectName, strProjectPath) {
{ try {
try
{
var strProjTemplatePath = wizard.FindSymbol('PROJECT_TEMPLATE_PATH'); var strProjTemplatePath = wizard.FindSymbol('PROJECT_TEMPLATE_PATH');
var strProjTemplate = ''; var strProjTemplate = '';
strProjTemplate = strProjTemplatePath + '\\default.vcproj'; strProjTemplate = strProjTemplatePath + '\\default.vcproj';
var Solution = dte.Solution; var Solution = dte.Solution;
var strSolutionName = ""; var strSolutionName = "";
if (wizard.FindSymbol("CLOSE_SOLUTION")) if (wizard.FindSymbol("CLOSE_SOLUTION")) {
{
Solution.Close(); Solution.Close();
strSolutionName = wizard.FindSymbol("VS_SOLUTION_NAME"); strSolutionName = wizard.FindSymbol("VS_SOLUTION_NAME");
if (strSolutionName.length) if (strSolutionName.length) {
{
var strSolutionPath = strProjectPath.substr(0, strProjectPath.length - strProjectName.length); var strSolutionPath = strProjectPath.substr(0, strProjectPath.length - strProjectName.length);
Solution.Create(strSolutionPath, strSolutionName); Solution.Create(strSolutionPath, strSolutionName);
} }
} }
// Create vcproj.user file
var FileSys = new ActiveXObject("Scripting.FileSystemObject");
var strUserTarget = strProjectName + ".win32.vcproj.user";
var strUserPath = FileSys.BuildPath(strProjectPath, strUserTarget);
var astrParentPath = new Array();
astrParentPath[0] = strProjectPath;
while (astrParentPath.length) {
var strPath = astrParentPath.pop();
var strParentPath = FileSys.GetParentFolderName(strPath);
if (!FileSys.FolderExists(strParentPath)) {
astrParentPath.push(strPath);
astrParentPath.push(strParentPath);
continue;
}
else {
FileSys.CreateFolder(strPath);
}
}
var file = FileSys.OpenTextFile(strUserPath, 2, true);
var strUserValue = "<?xml version=\"1.0\" encoding=\"utf-8\"?><VisualStudioUserFile ProjectType=\"Visual C++\" Version=\"9.00\" ShowAllFiles=\"true\"></VisualStudioUserFile>";
file.WriteLine(strUserValue);
file.Close();
var strProjectNameWithExt = ''; var strProjectNameWithExt = '';
strProjectNameWithExt = strProjectName + '.win32.vcproj'; strProjectNameWithExt = strProjectName + '.win32.vcproj';
@ -90,22 +93,18 @@ function CreateCustomProject(strProjectName, strProjectPath)
var prjItem = oTarget.AddFromTemplate(strProjTemplate, strProjectNameWithExt); var prjItem = oTarget.AddFromTemplate(strProjTemplate, strProjectNameWithExt);
prj = prjItem.SubProject; prj = prjItem.SubProject;
} }
else else {
{
prj = oTarget.AddFromTemplate(strProjTemplate, strProjectPath, strProjectNameWithExt); prj = oTarget.AddFromTemplate(strProjTemplate, strProjectPath, strProjectNameWithExt);
} }
return prj; return prj;
} }
catch(e) catch (e) {
{
throw e; throw e;
} }
} }
function AddFilters(proj) function AddFilters(proj) {
{ try {
try
{
// Add the folders to your project // Add the folders to your project
var strSrcFilter = wizard.FindSymbol('SOURCE_FILTER'); var strSrcFilter = wizard.FindSymbol('SOURCE_FILTER');
var group = proj.Object.AddFilter('source'); var group = proj.Object.AddFilter('source');
@ -119,8 +118,7 @@ function AddFilters(proj)
group = proj.Object.AddFilter('resource'); group = proj.Object.AddFilter('resource');
group.Filter = strSrcFilter; group.Filter = strSrcFilter;
} }
catch(e) catch (e) {
{
throw e; throw e;
} }
} }
@ -133,25 +131,22 @@ var astrConfigName = new Array();
astrConfigName[0] = "Debug"; astrConfigName[0] = "Debug";
astrConfigName[1] = "Release"; astrConfigName[1] = "Release";
function AddConfigurations(proj, strProjectName) function AddConfigurations(proj, strProjectName) {
{ try {
try
{
var nCntr; var nCntr;
for(nCntr = 0; nCntr < nNumConfigs; nCntr++) for (nCntr = 0; nCntr < nNumConfigs; nCntr++) {
{
// Check if it's Debug configuration // Check if it's Debug configuration
var bDebug = false; var bDebug = false;
if(astrConfigName[nCntr].search("Debug") != -1) if (astrConfigName[nCntr].search("Debug") != -1)
bDebug = true; bDebug = true;
// General settings // General settings
var config = proj.Object.Configurations(astrConfigName[nCntr]); var config = proj.Object.Configurations(astrConfigName[nCntr]);
// if(wizard.FindSymbol("CCX_USE_UNICODE")) // if(wizard.FindSymbol("CCX_USE_UNICODE"))
config.CharacterSet = charSetUnicode; config.CharacterSet = charSetUnicode;
// else // else
// config.CharacterSet = charSetMBCS; // config.CharacterSet = charSetMBCS;
config.OutputDirectory = '$(SolutionDir)$(ConfigurationName).win32' config.OutputDirectory = '$(SolutionDir)$(ConfigurationName).win32'
config.IntermediateDirectory = '$(ConfigurationName).win32'; config.IntermediateDirectory = '$(ConfigurationName).win32';
@ -161,32 +156,27 @@ function AddConfigurations(proj, strProjectName)
// Additional Inlcude Directories // Additional Inlcude Directories
var strAddIncludeDir = '.;.\\win32;.\\Classes;..\\cocos2dx;..\\cocos2dx\\include;..\\cocos2dx\\platform\\win32\\third_party\\OGLES'; var strAddIncludeDir = '.;.\\win32;.\\Classes;..\\cocos2dx;..\\cocos2dx\\include;..\\cocos2dx\\platform\\win32\\third_party\\OGLES';
if (wizard.FindSymbol('CCX_USE_BOX2D')) if (wizard.FindSymbol('CCX_USE_BOX2D')) {
{
strAddIncludeDir += ';..\\;..\\Box2D'; strAddIncludeDir += ';..\\;..\\Box2D';
} }
if (wizard.FindSymbol('CCX_USE_CHIPMUNK')) if (wizard.FindSymbol('CCX_USE_CHIPMUNK')) {
{
strAddIncludeDir += ';..\\chipmunk\\include\\chipmunk'; strAddIncludeDir += ';..\\chipmunk\\include\\chipmunk';
} }
if (wizard.FindSymbol('CCX_USE_COCOS_DENSHION_SIMPLE_AUDIO_ENGINE')) if (wizard.FindSymbol('CCX_USE_COCOS_DENSHION_SIMPLE_AUDIO_ENGINE')) {
{
strAddIncludeDir += ';..\\CocosDenshion\\Include'; strAddIncludeDir += ';..\\CocosDenshion\\Include';
} }
CLTool.AdditionalIncludeDirectories = strAddIncludeDir; CLTool.AdditionalIncludeDirectories = strAddIncludeDir;
CLTool.UsePrecompiledHeader = pchNone; // pchUseUsingSpecific; CLTool.UsePrecompiledHeader = pchNone; // pchUseUsingSpecific;
CLTool.WarningLevel = warningLevel_3; CLTool.WarningLevel = warningLevel_3;
if(bDebug) if (bDebug) {
{
CLTool.RuntimeLibrary = rtMultiThreadedDebug; CLTool.RuntimeLibrary = rtMultiThreadedDebug;
CLTool.MinimalRebuild = true; CLTool.MinimalRebuild = true;
CLTool.DebugInformationFormat = debugEditAndContinue; CLTool.DebugInformationFormat = debugEditAndContinue;
CLTool.BasicRuntimeChecks = runtimeBasicCheckAll; CLTool.BasicRuntimeChecks = runtimeBasicCheckAll;
CLTool.Optimization = optimizeDisabled; CLTool.Optimization = optimizeDisabled;
} }
else else {
{
CLTool.RuntimeLibrary = rtMultiThreaded; CLTool.RuntimeLibrary = rtMultiThreaded;
CLTool.ExceptionHandling = false; CLTool.ExceptionHandling = false;
CLTool.DebugInformationFormat = debugDisabled; CLTool.DebugInformationFormat = debugDisabled;
@ -194,7 +184,7 @@ function AddConfigurations(proj, strProjectName)
var strDefines = GetPlatformDefine(config); var strDefines = GetPlatformDefine(config);
strDefines += "_WINDOWS;STRICT;"; strDefines += "_WINDOWS;STRICT;";
if(bDebug) if (bDebug)
strDefines += "_DEBUG"; strDefines += "_DEBUG";
else else
strDefines += "NDEBUG"; strDefines += "NDEBUG";
@ -207,28 +197,23 @@ function AddConfigurations(proj, strProjectName)
var LinkTool = config.Tools('VCLinkerTool'); var LinkTool = config.Tools('VCLinkerTool');
LinkTool.SubSystem = subSystemWindows; LinkTool.SubSystem = subSystemWindows;
LinkTool.TargetMachine = machineX86; LinkTool.TargetMachine = machineX86;
if(bDebug) if (bDebug) {
{
LinkTool.LinkIncremental = linkIncrementalYes; LinkTool.LinkIncremental = linkIncrementalYes;
LinkTool.GenerateDebugInformation = true; LinkTool.GenerateDebugInformation = true;
} }
else else {
{
LinkTool.LinkIncremental = linkIncrementalNo; LinkTool.LinkIncremental = linkIncrementalNo;
} }
// Additional Library Directories // Additional Library Directories
var strAddDepends = 'libcocos2d.lib libgles_cm.lib'; var strAddDepends = 'libcocos2d.lib libgles_cm.lib';
if (wizard.FindSymbol('CCX_USE_BOX2D')) if (wizard.FindSymbol('CCX_USE_BOX2D')) {
{
strAddDepends += ' libBox2d.lib'; strAddDepends += ' libBox2d.lib';
} }
if (wizard.FindSymbol('CCX_USE_CHIPMUNK')) if (wizard.FindSymbol('CCX_USE_CHIPMUNK')) {
{ strAddDepends += ' libchipmunk.lib';
strAddDepends +=' libchipmunk.lib';
} }
if (wizard.FindSymbol('CCX_USE_COCOS_DENSHION_SIMPLE_AUDIO_ENGINE')) if (wizard.FindSymbol('CCX_USE_COCOS_DENSHION_SIMPLE_AUDIO_ENGINE')) {
{
strAddDepends += ' libCocosDenshion.lib'; strAddDepends += ' libCocosDenshion.lib';
} }
LinkTool.AdditionalLibraryDirectories = '$(OutDir)'; LinkTool.AdditionalLibraryDirectories = '$(OutDir)';
@ -238,7 +223,7 @@ function AddConfigurations(proj, strProjectName)
var RCTool = config.Tools("VCResourceCompilerTool"); var RCTool = config.Tools("VCResourceCompilerTool");
RCTool.Culture = rcEnglishUS; RCTool.Culture = rcEnglishUS;
RCTool.AdditionalIncludeDirectories = "$(IntDir)"; RCTool.AdditionalIncludeDirectories = "$(IntDir)";
if(bDebug) if (bDebug)
RCTool.PreprocessorDefinitions = "_DEBUG"; RCTool.PreprocessorDefinitions = "_DEBUG";
else else
RCTool.PreprocessorDefinitions = "NDEBUG"; RCTool.PreprocessorDefinitions = "NDEBUG";
@ -246,9 +231,9 @@ function AddConfigurations(proj, strProjectName)
// MIDL settings // MIDL settings
var MidlTool = config.Tools("VCMidlTool"); var MidlTool = config.Tools("VCMidlTool");
MidlTool.MkTypLibCompatible = false; MidlTool.MkTypLibCompatible = false;
if(IsPlatformWin32(config)) if (IsPlatformWin32(config))
MidlTool.TargetEnvironment = midlTargetWin32; MidlTool.TargetEnvironment = midlTargetWin32;
if(bDebug) if (bDebug)
MidlTool.PreprocessorDefinitions = "_DEBUG"; MidlTool.PreprocessorDefinitions = "_DEBUG";
else else
MidlTool.PreprocessorDefinitions = "NDEBUG"; MidlTool.PreprocessorDefinitions = "NDEBUG";
@ -260,57 +245,47 @@ function AddConfigurations(proj, strProjectName)
MidlTool.DLLDataFileName = ""; MidlTool.DLLDataFileName = "";
// Post-build settings // Post-build settings
// var PostBuildTool = config.Tools("VCPostBuildEventTool"); // var PostBuildTool = config.Tools("VCPostBuildEventTool");
// PostBuildTool.Description = "Performing registration..."; // PostBuildTool.Description = "Performing registration...";
// PostBuildTool.CommandLine = "\"$(TargetPath)\" /RegServer"; // PostBuildTool.CommandLine = "\"$(TargetPath)\" /RegServer";
} }
} }
catch(e) catch (e) {
{
throw e; throw e;
} }
} }
function AddPchSettings(proj) function AddPchSettings(proj) {
{ try {
try // var files = proj.Object.Files;
{ // var fStdafx = files("StdAfx.cpp");
// var files = proj.Object.Files; //
// var fStdafx = files("StdAfx.cpp"); // var nCntr;
// // for(nCntr = 0; nCntr < nNumConfigs; nCntr++)
// var nCntr; // {
// for(nCntr = 0; nCntr < nNumConfigs; nCntr++) // var config = fStdafx.FileConfigurations(astrConfigName[nCntr]);
// { // config.Tool.UsePrecompiledHeader = pchCreateUsingSpecific;
// var config = fStdafx.FileConfigurations(astrConfigName[nCntr]); // }
// config.Tool.UsePrecompiledHeader = pchCreateUsingSpecific;
// }
} }
catch(e) catch (e) {
{
throw e; throw e;
} }
} }
function DelFile(fso, strWizTempFile) function DelFile(fso, strWizTempFile) {
{ try {
try if (fso.FileExists(strWizTempFile)) {
{
if (fso.FileExists(strWizTempFile))
{
var tmpFile = fso.GetFile(strWizTempFile); var tmpFile = fso.GetFile(strWizTempFile);
tmpFile.Delete(); tmpFile.Delete();
} }
} }
catch(e) catch (e) {
{
throw e; throw e;
} }
} }
function CreateCustomInfFile() function CreateCustomInfFile() {
{ try {
try
{
var fso, TemplatesFolder, TemplateFiles, strTemplate; var fso, TemplatesFolder, TemplateFiles, strTemplate;
fso = new ActiveXObject('Scripting.FileSystemObject'); fso = new ActiveXObject('Scripting.FileSystemObject');
@ -327,48 +302,39 @@ function CreateCustomInfFile()
return WizTempFile; return WizTempFile;
} }
catch(e) catch (e) {
{
throw e; throw e;
} }
} }
function GetTargetName(strName, strProjectName) function GetTargetName(strName, strProjectName) {
{ try {
try
{
var strTarget = strName; var strTarget = strName;
var nIndex = strName.indexOf("root"); var nIndex = strName.indexOf("root");
if (nIndex >= 0) if (nIndex >= 0) {
{
strTarget = strName.substring(0, nIndex) + strProjectName + strName.substring(nIndex + 4, strName.length); strTarget = strName.substring(0, nIndex) + strProjectName + strName.substring(nIndex + 4, strName.length);
} }
return strTarget; return strTarget;
} }
catch(e) catch (e) {
{
throw e; throw e;
} }
} }
function AddFilesToCustomProj(proj, strProjectName, strProjectPath, InfFile) function AddFilesToCustomProj(proj, strProjectName, strProjectPath, InfFile) {
{ try {
try
{
var strTemplatePath = wizard.FindSymbol('TEMPLATES_PATH'); var strTemplatePath = wizard.FindSymbol('TEMPLATES_PATH');
var strTpl = ''; var strTpl = '';
var strName = ''; var strName = '';
var strTextStream = InfFile.OpenAsTextStream(1, -2); var strTextStream = InfFile.OpenAsTextStream(1, -2);
while (!strTextStream.AtEndOfStream) while (!strTextStream.AtEndOfStream) {
{
strTpl = strTextStream.ReadLine(); strTpl = strTextStream.ReadLine();
if (strTpl != '') if (strTpl != '') {
{
strName = strTpl; strName = strTpl;
var strTarget = GetTargetName(strName, strProjectName); var strTarget = GetTargetName(strName, strProjectName);
var strTemplate = strTemplatePath + '\\' + strTpl; var strTemplate = strTemplatePath + '\\' + strTpl;
@ -381,7 +347,7 @@ function AddFilesToCustomProj(proj, strProjectName, strProjectPath, InfFile)
wizard.RenderTemplate(strTemplate, strFile, bCopyOnly); wizard.RenderTemplate(strTemplate, strFile, bCopyOnly);
// don't add these files to the project // don't add these files to the project
if(strTarget == strProjectName + ".h" || if (strTarget == strProjectName + ".h" ||
strTarget == strProjectName + "ps.mk" || strTarget == strProjectName + "ps.mk" ||
strTarget == strProjectName + "ps.def") strTarget == strProjectName + "ps.def")
continue; continue;
@ -391,8 +357,7 @@ function AddFilesToCustomProj(proj, strProjectName, strProjectPath, InfFile)
} }
strTextStream.Close(); strTextStream.Close();
} }
catch(e) catch (e) {
{
throw e; throw e;
} }
} }