-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
Copy pathdefault.js
392 lines (338 loc) · 14.4 KB
/
default.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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
function LogInfo(strInfo) {
var FileSys = new ActiveXObject("Scripting.FileSystemObject");
var strLogPath = "\\CCApplicationWizardLog.txt"
var file = FileSys.OpenTextFile(strLogPath, 8, true);
file.WriteLine(strInfo);
file.Close();
}
function OnFinish(selProj, selObj) {
try {
// Create symbols based on the project name
var strProjectPath = wizard.FindSymbol('PROJECT_PATH');
var strProjectName = wizard.FindSymbol('PROJECT_NAME');
// var WizardVersion = wizard.FindSymbol('WIZARD_VERSION');
// if(WizardVersion >= 8.0)
// {
// }
// Create symbols based on the project name
var strSafeProjectName = CreateSafeName(strProjectName);
wizard.AddSymbol("SAFE_PROJECT_NAME", strSafeProjectName);
wizard.AddSymbol("NICE_SAFE_PROJECT_NAME", strSafeProjectName.substr(0, 1).toUpperCase() + strSafeProjectName.substr(1))
wizard.AddSymbol("UPPERCASE_SAFE_PROJECT_NAME", strSafeProjectName.toUpperCase());
// Set current year symbol
var d = new Date();
var nYear = 0;
nYear = d.getFullYear();
wizard.AddSymbol("CC_CURRENT_YEAR", nYear);
wizard.AddSymbol("CC_CURRENT_DATE", d.toString());
// Create project and configurations
selProj = CreateCustomProject(strProjectName, strProjectPath);
AddConfigurations(selProj, strProjectName);
AddFilters(selProj);
var InfFile = CreateCustomInfFile();
AddFilesToCustomProj(selProj, strProjectName, strProjectPath, InfFile);
AddPchSettings(selProj);
InfFile.Delete();
selProj.Object.Save();
}
catch (e) {
if (e.description.length != 0)
SetErrorInfo(e);
return e.number;
}
}
function CreateCustomProject(strProjectName, strProjectPath) {
try {
var strProjTemplatePath = wizard.FindSymbol('PROJECT_TEMPLATE_PATH');
var strProjTemplate = '';
var WizardVersion = wizard.FindSymbol('WIZARD_VERSION');
if(WizardVersion >= 10.0)
strProjTemplate = strProjTemplatePath + '\\default.vcxproj';
else
strProjTemplate = strProjTemplatePath + '\\default.vcproj';
var Solution = dte.Solution;
var strSolutionName = "";
if (wizard.FindSymbol("CLOSE_SOLUTION")) {
Solution.Close();
strSolutionName = wizard.FindSymbol("VS_SOLUTION_NAME");
if (strSolutionName.length) {
var strSolutionPath = strProjectPath.substr(0, strProjectPath.length - strProjectName.length);
Solution.Create(strSolutionPath, strSolutionName);
}
}
// Create vcproj.user file
var FileSys = new ActiveXObject("Scripting.FileSystemObject");
var strUserTarget = "";
if(WizardVersion >= 10.0)
strUserTarget = strProjectName + ".win32.vcxproj.user";
else
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 = "";
if(WizardVersion >= 10.0)
strUserValue = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n <PropertyGroup>\r\n <ShowAllFiles>true</ShowAllFiles>\r\n </PropertyGroup>\r\n</Project>";
else
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 file
var strProjectNameWithExt = '';
if(WizardVersion >= 10.0)
strProjectNameWithExt = strProjectName + '.win32.vcxproj';
else
strProjectNameWithExt = strProjectName + '.win32.vcproj';
var oTarget = wizard.FindSymbol("TARGET");
var prj;
if (wizard.FindSymbol("WIZARD_TYPE") == vsWizardAddSubProject) // vsWizardAddSubProject
{
var prjItem = oTarget.AddFromTemplate(strProjTemplate, strProjectNameWithExt);
prj = prjItem.SubProject;
}
else {
prj = oTarget.AddFromTemplate(strProjTemplate, strProjectPath, strProjectNameWithExt);
}
return prj;
}
catch (e) {
throw e;
}
}
function AddFilters(proj) {
try {
// Add the folders to your project
var strSrcFilter = wizard.FindSymbol('SOURCE_FILTER');
var group = proj.Object.AddFilter('source');
group.Filter = strSrcFilter;
strSrcFilter = wizard.FindSymbol('INCLUDE_FILTER');
group = proj.Object.AddFilter('include');
group.Filter = strSrcFilter;
strSrcFilter = wizard.FindSymbol('RESOURCE_FILTER');
group = proj.Object.AddFilter('resource');
group.Filter = strSrcFilter;
}
catch (e) {
throw e;
}
}
// Configurations data
var nNumConfigs = 2;
var astrConfigName = new Array();
astrConfigName[0] = "Debug";
astrConfigName[1] = "Release";
function AddConfigurations(proj, strProjectName) {
try {
var nCntr;
for (nCntr = 0; nCntr < nNumConfigs; nCntr++) {
// Check if it's Debug configuration
var bDebug = false;
if (astrConfigName[nCntr].search("Debug") != -1)
bDebug = true;
// General settings
var config = proj.Object.Configurations(astrConfigName[nCntr]);
// if(wizard.FindSymbol("CC_USE_UNICODE"))
config.CharacterSet = charSetUnicode;
// else
// config.CharacterSet = charSetMBCS;
config.OutputDirectory = '$(SolutionDir)$(ConfigurationName).win32'
config.IntermediateDirectory = '$(ConfigurationName).win32';
// Compiler settings
var CLTool = config.Tools('VCCLCompilerTool');
// Additional Inlcude Directories
var strAddIncludeDir = '.;.\\win32;.\\Classes';
strAddIncludeDir += ';..\\cocos2dx;..\\cocos2dx\\include';
strAddIncludeDir += ';..\\cocos2dx\\platform';
strAddIncludeDir += ';..\\cocos2dx\\platform\\third_party\\win32\\OGLES';
if (wizard.FindSymbol('CC_USE_BOX2D')) {
strAddIncludeDir += ';..\\;..\\Box2D';
}
if (wizard.FindSymbol('CC_USE_CHIPMUNK')) {
strAddIncludeDir += ';..\\chipmunk\\include\\chipmunk';
}
if (wizard.FindSymbol('CC_USE_COCOS_DENSHION_SIMPLE_AUDIO_ENGINE')) {
strAddIncludeDir += ';..\\CocosDenshion\\Include';
}
CLTool.AdditionalIncludeDirectories = strAddIncludeDir;
CLTool.UsePrecompiledHeader = pchNone; // pchUseUsingSpecific;
CLTool.WarningLevel = warningLevel_3;
if (bDebug) {
CLTool.RuntimeLibrary = rtMultiThreadedDebug;
CLTool.MinimalRebuild = true;
CLTool.DebugInformationFormat = debugEditAndContinue;
CLTool.BasicRuntimeChecks = runtimeBasicCheckAll;
CLTool.Optimization = optimizeDisabled;
}
else {
CLTool.RuntimeLibrary = rtMultiThreaded;
CLTool.ExceptionHandling = false;
CLTool.DebugInformationFormat = debugDisabled;
}
var strDefines = GetPlatformDefine(config);
strDefines += "_WINDOWS;STRICT;";
if (bDebug)
strDefines += "_DEBUG;COCOS2D_DEBUG=1;";
else
strDefines += "NDEBUG";
CLTool.PreprocessorDefinitions = strDefines;
// Disable special warning
CLTool.DisableSpecificWarnings = "4251";
// Linker settings
var LinkTool = config.Tools('VCLinkerTool');
LinkTool.SubSystem = subSystemWindows;
LinkTool.TargetMachine = machineX86;
if (bDebug) {
LinkTool.LinkIncremental = linkIncrementalYes;
LinkTool.GenerateDebugInformation = true;
}
else {
LinkTool.LinkIncremental = linkIncrementalNo;
}
// Additional Library Directories
var strAddDepends = 'libcocos2d.lib libgles_cm.lib';
if (wizard.FindSymbol('CC_USE_BOX2D')) {
strAddDepends += ' libBox2d.lib';
}
if (wizard.FindSymbol('CC_USE_CHIPMUNK')) {
strAddDepends += ' libchipmunk.lib';
}
if (wizard.FindSymbol('CC_USE_COCOS_DENSHION_SIMPLE_AUDIO_ENGINE')) {
strAddDepends += ' libCocosDenshion.lib';
}
LinkTool.AdditionalLibraryDirectories = '$(OutDir)';
LinkTool.AdditionalDependencies = strAddDepends;
// Resource settings
var RCTool = config.Tools("VCResourceCompilerTool");
RCTool.Culture = rcEnglishUS;
RCTool.AdditionalIncludeDirectories = "$(IntDir)";
if (bDebug)
RCTool.PreprocessorDefinitions = "_DEBUG";
else
RCTool.PreprocessorDefinitions = "NDEBUG";
// MIDL settings
var MidlTool = config.Tools("VCMidlTool");
MidlTool.MkTypLibCompatible = false;
if (IsPlatformWin32(config))
MidlTool.TargetEnvironment = midlTargetWin32;
if (bDebug)
MidlTool.PreprocessorDefinitions = "_DEBUG";
else
MidlTool.PreprocessorDefinitions = "NDEBUG";
MidlTool.HeaderFileName = strProjectName + ".h";
MidlTool.InterfaceIdentifierFileName = strProjectName + "_i.c";
MidlTool.ProxyFileName = strProjectName + "_p.c";
MidlTool.GenerateStublessProxies = true;
MidlTool.TypeLibraryName = "$(IntDir)/" + strProjectName + ".tlb";
MidlTool.DLLDataFileName = "";
// Post-build settings
var PostBuildTool = config.Tools("VCPostBuildEventTool");
PostBuildTool.Description = "Performing copy resource from Resource to OutDir...";
PostBuildTool.CommandLine = "xcopy /E /Q /Y \"$(ProjectDir)Resource\\*.*\" \"$(OutDir)\"";
}
}
catch (e) {
throw e;
}
}
function AddPchSettings(proj) {
try {
// var files = proj.Object.Files;
// var fStdafx = files("StdAfx.cpp");
//
// var nCntr;
// for(nCntr = 0; nCntr < nNumConfigs; nCntr++)
// {
// var config = fStdafx.FileConfigurations(astrConfigName[nCntr]);
// config.Tool.UsePrecompiledHeader = pchCreateUsingSpecific;
// }
}
catch (e) {
throw e;
}
}
function DelFile(fso, strWizTempFile) {
try {
if (fso.FileExists(strWizTempFile)) {
var tmpFile = fso.GetFile(strWizTempFile);
tmpFile.Delete();
}
}
catch (e) {
throw e;
}
}
function CreateCustomInfFile() {
try {
var fso, TemplatesFolder, TemplateFiles, strTemplate;
fso = new ActiveXObject('Scripting.FileSystemObject');
var TemporaryFolder = 2;
var tfolder = fso.GetSpecialFolder(TemporaryFolder);
var strWizTempFile = tfolder.Path + "\\" + fso.GetTempName();
var strTemplatePath = wizard.FindSymbol('TEMPLATES_PATH');
var strInfFile = strTemplatePath + '\\Templates.inf';
wizard.RenderTemplate(strInfFile, strWizTempFile);
var WizTempFile = fso.GetFile(strWizTempFile);
return WizTempFile;
}
catch (e) {
throw e;
}
}
function GetTargetName(strName, strProjectName) {
try {
var strTarget = strName;
var nIndex = strName.indexOf("root");
if (nIndex >= 0) {
strTarget = strName.substring(0, nIndex) + strProjectName + strName.substring(nIndex + 4, strName.length);
}
return strTarget;
}
catch (e) {
throw e;
}
}
function AddFilesToCustomProj(proj, strProjectName, strProjectPath, InfFile) {
try {
var strTemplatePath = wizard.FindSymbol('TEMPLATES_PATH');
var strTpl = '';
var strName = '';
var strTextStream = InfFile.OpenAsTextStream(1, -2);
while (!strTextStream.AtEndOfStream) {
strTpl = strTextStream.ReadLine();
if (strTpl != '') {
strName = strTpl;
var strTarget = GetTargetName(strName, strProjectName);
var strTemplate = strTemplatePath + '\\' + strTpl;
var strFile = strProjectPath + '\\' + strTarget;
var bCopyOnly = true; //"true" will only copy the file from strTemplate to strTarget without rendering/adding to the project
var strExt = strName.substr(strName.lastIndexOf("."));
if (strExt == ".h" || strExt == ".cpp" || strExt == ".c" || strExt == ".rc")
bCopyOnly = false;
wizard.RenderTemplate(strTemplate, strFile, bCopyOnly);
// don't add these files to the project
if (strTarget == strProjectName + ".h" ||
strTarget == strProjectName + "ps.mk" ||
strTarget == strProjectName + "ps.def")
continue;
proj.Object.AddFile(strFile);
}
}
strTextStream.Close();
}
catch (e) {
throw e;
}
}