📄 default.js
字号:
function OnFinish(selProj, selObj)
{
try
{
var strProjectPath = wizard.FindSymbol('PROJECT_PATH');
var strProjectName = wizard.FindSymbol('PROJECT_NAME');
selProj = CreateCustomProject(strProjectName, strProjectPath);
AddConfig(selProj, strProjectName);
AddFilters(selProj);
var InfFile = CreateCustomInfFile();
AddFilesToCustomProj(selProj, strProjectName, strProjectPath, InfFile);
InfFile.Delete();
selProj.Object.Save();
//*******************************************************************************//
// The following patch has been added for VS .NET 2003 where the AEEAppGen.c and
// AEEModGen.c files get added to the project as ".\$(BREWDIR)\src\AEEAppGen.c" and
// ".\$(BREWDIR)\src\AEEModGen.c". This patch prompts the users to reload the project
// as soon as it is created, but this is a known issue with VS .NET 2003 and should
// not occur on VS .NET 2002
// variable that tells whether there have been any changes to the vcproj file
var bChanged = false;
var fso = new ActiveXObject("Scripting.FileSystemObject");
// Open the vcproj file
var projFile = fso.OpenTextFile(strProjectPath + '\\' + strProjectName + ".vcproj", 1);
// create a temporary file
var tname = fso.GetTempName();
var tfile = fso.CreateTextFile(strProjectPath + '\\' + tname, true);
// read the project file
while(!projFile.AtEndOfStream)
{
var strLine = projFile.ReadLine();
// Regular expression to match the string ".\(brewdir)"
var re = /\.\\\$\(brewdir\)/i;
// If the regular expression matches, then the vcproj file needs to be replaced
if (strLine.match(re) != null)
bChanged = true;
// replace ".\$(brewdir)" with "$(BREWDIR)"
strLine = strLine.replace(re, "$(BREWDIR)");
tfile.WriteLine(strLine);
}
tfile.Close();
projFile.Close();
// delete the project file and rename the temp file to the project file
// this causes Visual Studio to prompt the users to reload the project
// Do this ONLY if the bChanged variable is set to true
if (bChanged)
{
fso.DeleteFile(strProjectPath + '\\' + strProjectName + ".vcproj");
fso.MoveFile(strProjectPath + '\\' + tname, strProjectPath + '\\' + strProjectName + ".vcproj");
}
else
{
// if we didn't rename the temp file to the vcproj file, then delete the tempfile
fso.DeleteFile(strProjectPath + '\\' + tname);
}
//***********************************************************************************//
}
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 = '';
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);
}
}
var strProjectNameWithExt = '';
strProjectNameWithExt = strProjectName + '.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 Files');
group.Filter = strSrcFilter;
}
catch(e)
{
throw e;
}
}
function AddConfig(proj, strProjectName)
{
try
{
// Start - DEBUG mode settings ###################################
var config = proj.Object.Configurations('Debug');
config.IntermediateDirectory = 'Debug';
config.OutputDirectory = 'Debug';
config.ConfigurationType = typeDynamicLibrary;
// Add compiler settings ---------------------------------
var CLTool = config.Tools('VCCLCompilerTool');
// Include directories
CLTool.AdditionalIncludeDirectories += "$(BREWDIR)\\inc;";
// Do not use precompiled header
CLTool.UsePrecompiledHeader = pchNone;
// Use multithreaded debug library
CLTool.RuntimeLibrary = rtMultiThreadedDebug;
// Preprocessor definitions
var strDefines = GetPlatformDefine(config);
strDefines += "_DEBUG;_WINDOWS;_USRDLL;AEE_SIMULATOR;";
CLTool.PreprocessorDefinitions = strDefines;
// Enable debug information in debug mode
CLTool.DebugInformationFormat = debugEnabled;
// Disable optimization in debug mode
CLTool.Optimization = optimizeDisabled;
// Done adding compiler settings ---------------------------
// Add linker settings -------------------------------------
var LinkTool = config.Tools('VCLinkerTool');
// subsystem, output path and filename
LinkTool.SubSystem = subSystemWindows;
LinkTool.ImportLibrary = "$(OutDir)/" + strProjectName + ".lib";
LinkTool.OutputFile = "./" + strProjectName + ".dll";
// Done adding linker settings -----------------------------
// End - DEBUG mode settings ###################################
// Start - RELEASE mode settings ###############################
config = proj.Object.Configurations('Release');
config.IntermediateDirectory = 'Release';
config.OutputDirectory = 'Release';
config.ConfigurationType = typeDynamicLibrary;
// Add compiler settings ---------------------------------
var CLTool = config.Tools('VCCLCompilerTool');
// Include directories
CLTool.AdditionalIncludeDirectories += "$(BREWDIR)\\inc;";
// Do not use precompiled header
CLTool.UsePrecompiledHeader = pchNone;
// Use multithreaded library
CLTool.RuntimeLibrary = rtMultiThreaded;
// Preprocessor definitions
var strDefines = GetPlatformDefine(config);
strDefines += "_DEBUG;_WINDOWS;_USRDLL;AEE_SIMULATOR;";
CLTool.PreprocessorDefinitions = strDefines;
// Disable debug information in release mode
CLTool.DebugInformationFormat = debugDisabled;
// Optimize for speed in release mode
CLTool.Optimization = optimizeMaxSpeed;
// Done adding compiler settings ---------------------------
// Add linker settings -------------------------------------
var LinkTool = config.Tools('VCLinkerTool');
// subsystem, output path and filename
LinkTool.SubSystem = subSystemWindows;
LinkTool.ImportLibrary = "$(OutDir)/" + strProjectName + ".lib";
LinkTool.OutputFile = "./" + strProjectName + ".dll";
// Done adding linker settings -----------------------------
// End - RELEASE mode settings #################################
}
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 strTempFolder = tfolder.Drive + '\\' + tfolder.Name;
var strWizTempFile = strTempFolder + "\\" + 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
{
// Set the name of the rendered file based on the template filename
var strTarget = strName;
var strProjectName = wizard.FindSymbol('PROJECT_NAME');
if (strName == 'root.c')
{
// When the template file is root.c, we should rename it to
// the PROJECT_NAME ...
strTarget = strProjectName;
strTarget += ".c";
}
return strTarget;
}
catch(e)
{
throw e;
}
}
function AddFilesToCustomProj(proj, strProjectName, strProjectPath, InfFile)
{
try
{
var projItems = proj.ProjectItems;
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;
wizard.RenderTemplate(strTemplate, strFile, false);
proj.Object.AddFile(strFile);
}
}
strTextStream.Close();
// Add AEEAppGen.c and AEEModGen.c relative to the
// 'src' folder of BREWDIR environment variable (path)
proj.Object.AddFile("$(BREWDIR)\\src\\AEEAppGen.c");
proj.Object.AddFile("$(BREWDIR)\\src\\AEEModGen.c");
}
catch(e)
{
throw e;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -