VS2008 사용자 정의 마법사의 default.js 설정(DLL 파일)

18711 단어 vs2008
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);

        PchSettings(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 = '';

        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);

        }

        var fxtarget = wizard.FindSymbol("TARGET_FRAMEWORK_VERSION");

        if (fxtarget != null && fxtarget != "")

        {

            fxtarget = fxtarget.split('.', 2);

            if (fxtarget.length == 2)

            prj.Object.TargetFrameworkVersion = parseInt(fxtarget[0]) * 0x10000 + parseInt(fxtarget[1])

        }

        return prj;

    }

    catch(e)

    {

        throw e;

    }

}



function AddFilters(proj)

{

    try

    {

        //  

//        var strSrcFilter = wizard.FindSymbol('SOURCE_FILTER');

//        var group = proj.Object.AddFilter(' ');

//        group.Filter = strSrcFilter;

        proj.Object.AddFilter(' ').Filter = 'cpp;c;def';

        proj.Object.AddFilter(' ').Filter = 'hpp;h';

        proj.Object.AddFilter(' ').Filter = 'ico;rc;bin';

     }

    catch(e)

    {

        throw e;

    }

}



function AddConfig(proj, strProjectName)

{

    try

    {

        var config = proj.Object.Configurations('Debug');

        config.CharacterSet = charSetUNICODE;

        config.ConfigurationType = typeDynamicLibrary;

        config.IntermediateDirectory = '$(ConfigurationName)';

        config.OutputDirectory = '$(ConfigurationName)';



        var CLTool = config.Tools('VCCLCompilerTool');

        // TODO:  

        CLTool.RuntimeLibrary = rtMultiThreadedDebugDLL;

        

        var strDefines = CLTool.PreprocessorDefinitions;

        if (strDefines != "") strDefines += ";";

        strDefines += GetPlatformDefine(config);

        strDefines += "_DEBUG";        

        strDefines += ";_WINDOWS;_USRDLL;";

        var strExports = strProjectName.toString().toUpperCase() + "_EXPORTS";

        strDefines += strExports;

        CLTool.PreprocessorDefinitions = strDefines;

        CLTool.DebugInformationFormat = debugEditAndContinue;

        

        var LinkTool = config.Tools('VCLinkerTool');

        // TODO:  

        LinkTool.ModuleDefinitionFile = strProjectName+".def";

        LinkTool.GenerateDebugInformation = true;

        LinkTool.SubSystem = subSystemWindows;

        

        config = proj.Object.Configurations('Release');

        config.IntermediateDirectory = '$(ConfigurationName)';

        config.OutputDirectory = '$(ConfigurationName)';

        config.CharacterSet = charSetUNICODE;

        config.ConfigurationType = typeDynamicLibrary;



        var CLTool = config.Tools('VCCLCompilerTool');

        // TODO:  

        CLTool.RuntimeLibrary = rtMultiThreadedDLL;

        

        var strDefines = CLTool.PreprocessorDefinitions;

        if (strDefines != "") strDefines += ";";

        strDefines += GetPlatformDefine(config);

        strDefines += "NDEBUG"

        strDefines += ";_WINDOWS;_USRDLL;";

        var strExports = strProjectName.toString().toUpperCase() + "_EXPORTS";

        strDefines += strExports;

        CLTool.PreprocessorDefinitions = strDefines;

        CLTool.DebugInformationFormat = debugEnabled;



        var LinkTool = config.Tools('VCLinkerTool');

        // TODO:  

        LinkTool.ModuleDefinitionFile = strProjectName+".def";

        LinkTool.GenerateDebugInformation = true;

        LinkTool.SubSystem = subSystemWindows;

    }

    catch(e)

    {

        throw e;

    }

}



function PchSettings(proj)

{

    // TODO:   pch  

}



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

    {

        // TODO:  

        var strTarget = strName;



        if (strName == 'readme.txt')

            strTarget = 'ReadMe.txt';



        if (strName == 'MoonDriver.cpp')

            strTarget =strProjectName+ '.cpp';

        if (strName == 'MoonDriver.def')

            strTarget =strProjectName+ '.def';

        if (strName == 'MoonDriver.h')

            strTarget =strProjectName+ '.h';



        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;



                var bCopyOnly = false;  //“true”  strTemplate   strTarget, / 

                var strExt = strName.substr(strName.lastIndexOf("."));

                if(strExt==".bmp" || strExt==".ico" || strExt==".gif" || strExt==".rtf" || strExt==".css"|| strExt==".lib")

                    bCopyOnly = true;

                wizard.RenderTemplate(strTemplate, strFile, bCopyOnly);

                proj.Object.AddFile(strFile);

            }

        }

        strTextStream.Close();

    }

    catch(e)

    {

        throw e;

    }

}

좋은 웹페이지 즐겨찾기