// default.js
//
// Script to set up an NNA plug-in project for Visual Studio .NET.
// This is for NNA developers only.
//
// (c) 2005 Nemetschek North America


var	g_strTargetDirName					= "VWPluginWiz";
var	g_bAutomaticMacResourceGeneration	= true;

var g_bAddVWUISupport					= true;
var g_bAddVWFCSupport                   = false;
var	g_bAddMFCSupport					= false;
var g_bAddSampleCode					= true;
var	g_bAddMacPrefix						= true;
var g_strUserPrefixFile					= "Prefix";
var g_strUserSDKPath					= "..\\..\\..\\SDKLib";
var g_strUserDebugOutputPath			= ".\\Debug";
var g_strUserReleaseOutputPath			= ".\\Release";
var g_strUserBuildPath					= ".\\Build Data";
var g_strUserRezExePath					= "Rez.exe";
var g_strUserQuickTimeSDKRIncludePath	= "RIncludes";
var g_strUserVWSDKResourcesPath			= "";

//	if ( g_pluginType == 0 ) {	// object
//	if ( g_pluginType == 1 ) {	// menu command
//	if ( g_pluginType == 2 ) {	// tool
//	if ( g_pluginType == 3 ) {	// object + tool
var g_pluginType						= 0;

function OnFinish(selProj, selObj)
{
//wizard.OkCancelAlert( 'point' );
/*	try
	{*/
		var strProjectPath = wizard.FindSymbol("PROJECT_PATH");
		var strProjectName = wizard.FindSymbol("PROJECT_NAME");
		
		var strProjTemplatePath = wizard.FindSymbol("PROJECT_TEMPLATE_PATH");
		var strFileTemplatePath = strProjTemplatePath + "\\" + g_strTargetDirName + "\\Templates\\1033";

		g_bAddVWUISupport					= true;
		g_bAddVWFCSupport				    = true;
		g_bAddMFCSupport				    = wizard.FindSymbol('ADD_MFC_SUPPORT');
		g_bAddSampleCode				    = wizard.FindSymbol('ADD_SAMPLE_CODE');
		g_bAddMacPrefix					    = true;
		g_strUserPrefixFile				    = wizard.FindSymbol('PRECOMPILED_HEADER');
		g_strUserSDKPath				    = wizard.FindSymbol('SDK_PATH');
		g_strUserDebugOutputPath		    = wizard.FindSymbol('DEBUG_OUTPUT_PATH');
		g_strUserReleaseOutputPath		    = wizard.FindSymbol('RELEASE_OUTPUT_PATH');
		g_strUserBuildPath				    = wizard.FindSymbol('BUILD_PATH');
		g_strUserRezExePath				    = wizard.FindSymbol('REZ_EXE_PATH');
		g_strUserQuickTimeSDKRIncludePath	= wizard.FindSymbol('QUICKTIME_SDK_RINCLUDE_PATH');
		g_strUserVWSDKResourcesPath		    = g_strUserSDKPath + "/Include/Kernel";
		g_pluginType						= wizard.FindSymbol('PLUGINTYPE_LISTBOX');

		// for VWFC support we mush have the prefix file StdAfx.h
		if ( g_bAddVWFCSupport ) {
		    g_strUserPrefixFile = "StdAfx"
		}

		// Options
		var pluginType = wizard.FindSymbol('PLUGINTYPE_LISTBOX');
		//var automaticMacResourceGeneration = wizard.FindSymbol('AUTOMACRESOURCE_CHECKBOX');

		//wizard.YesNoAlert("Project Path: " + strProjectPath);

		if ( ! CanUseDrive( strProjectPath ) )
			return VS_E_WIZARDBACKBUTTONPRESS;

		// create module
		var moduleProj = CreateModuleProject(strProjectName, strProjectPath, strProjTemplatePath, strFileTemplatePath);
		moduleProj.Object.Save();
/*	}

	catch(e)
	{
	    wizard.OkCancelAlert( 'Error has occured during running wizard script:\n' + e.description );
    	return e.number;
	}*/
}

/******************************************************************************
    Description: Creates a C++ SDK plug-in project
 strProjectName: Project Name
 strProjectPath: The path that the project will be created in
******************************************************************************/
function CreateBasePluginProject(strProjectName, strProjectPath, strProjTemplatePath, strFileTemplatePath)
{
	try
	{
		var strProjTemplate = strProjTemplatePath + "\\default.vcproj"; 

		var Solution = dte.Solution;
		var strSolutionName = "";


		// Create new solution, if user chose this option
		strSolutionName = wizard.FindSymbol("VS_SOLUTION_NAME");
		if (strSolutionName.length)
		{
			var strSolutionPath = strProjectPath.substr(0, strProjectPath.length - strProjectName.length);
			Solution.Create(strSolutionPath, strSolutionName);
		}


		// Add project file
		var oProj;
		oProj = Solution.AddFromTemplate(strProjTemplate, strProjectPath, strProjectName, false);


		// Add Source, Headers, and Resource folders
		//SetupFilters(oProj);
		var groupSources	= oProj.Object.AddFilter("Source Files");
		groupSources.Filter	= 'c;cpp;cp;h;hpp';
		var	groupPrefix		= groupSources.AddFilter("Prefix");
		groupPrefix.Filter	= 'c;cpp;cp;h;hpp';
		if ( g_bAddMFCSupport ) {
			var mfcResFiles		= oProj.Object.AddFilter('Resource Files');
			mfcResFiles.Filter	= "rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx";
		}

		if ( g_bAutomaticMacResourceGeneration ) {
			// Add a "Resources" folder
			oProj.Object.AddFilter("Resources");
		}

		// Set project configuration
		AddCommonConfig(oProj, strProjectName);		// Add Debug and Release configs
		SetPluginBaseSpecificSettings(oProj, strProjectName);

		return oProj;
	}

	catch(e)
	{   
		throw e;
	}
}



// ******************************************************
// Adds specific Nemetschek project settings that are
// common to all plug-in projects.
// ******************************************************
function SetPluginBaseSpecificSettings(oProj, projName)
{
	try
	{
		// *********** DEBUG **************

		// Compiler options
		var config = oProj.Object.Configurations("Debug");
		config.OutputDirectory					= g_strUserDebugOutputPath;
		config.IntermediateDirectory			= g_strUserBuildPath + '\\Debug';
		config.ConfigurationType				= typeDynamicLibrary;
		//config.DeleteExtensionsOnClean			+= ";*.qtr";

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

		if ( g_bAddVWFCSupport ) {
    		CLTool.AdditionalIncludeDirectories		+= g_strUserSDKPath;
    		CLTool.AdditionalIncludeDirectories		+= ",";
		}
		if ( g_bAddVWFCSupport ) {
    		CLTool.AdditionalIncludeDirectories		+= g_strUserSDKPath + "\\Include";
    		CLTool.AdditionalIncludeDirectories		+= ",";
		}
		CLTool.AdditionalIncludeDirectories		+= g_strUserSDKPath + "\\Include\\Kernel";
   		CLTool.AdditionalIncludeDirectories		+= ",";
		CLTool.AdditionalIncludeDirectories		+= g_strUserSDKPath + "\\Include\\GCL";
   		CLTool.AdditionalIncludeDirectories		+= ",";
		CLTool.AdditionalIncludeDirectories		+= g_strUserSDKPath + "\\Include\\OnlyWin";
   		CLTool.AdditionalIncludeDirectories		+= ",";
		CLTool.AdditionalIncludeDirectories		+= g_strUserSDKPath + "\\Include\\Interfaces";
		if ( g_bAddVWUISupport ) {
    		CLTool.AdditionalIncludeDirectories		+= ",";
    		CLTool.AdditionalIncludeDirectories		+= g_strUserSDKPath + "\\Include\\VWUI";
		}
   		CLTool.AdditionalIncludeDirectories		+= ",";
		CLTool.AdditionalIncludeDirectories		+= ".\\Source\\Prefix";
   		CLTool.AdditionalIncludeDirectories		+= ",";
		CLTool.AdditionalIncludeDirectories		+= ".\\Resources";

		CLTool.PreprocessorDefinitions			= "_DEBUG;WIN32;_WINDOWS;_USRDLL;_WIN_EXTERNAL_;DEV_BLD,_WINDLL";	// No altura
		CLTool.TreatWChar_tAsBuiltInType		= true;
		CLTool.Optimization						= optimizeDisabled;
		CLTool.DebugInformationFormat			= debugEditAndContinue;
		CLTool.BasicRuntimeChecks				= runtimeBasicCheckAll;
		CLTool.RuntimeLibrary					= rtMultiThreadedDebug;
		CLTool.StructMemberAlignment			= alignTwoBytes;
		CLTool.SmallerTypeCheck					= true;
		CLTool.BufferSecurityCheck				= true;
		CLTool.RuntimeTypeInfo					= true;
		CLTool.UsePrecompiledHeader				= pchUseUsingSpecific;
		CLTool.PrecompiledHeaderFile			= '$(IntDir)\\' + g_strUserPrefixFile + '.h';
		CLTool.PrecompiledHeaderThrough			= g_strUserPrefixFile + '.h';
		CLTool.MinimalRebuild					= true;
		CLTool.AssemblerListingLocation			= '$(IntDir)\\';
		CLTool.ObjectFile						= '$(IntDir)\\';
		CLTool.ProgramDataBaseFileName			= '$(IntDir)\\';
		CLTool.BrowseInformation				= brAllInfo;
		CLTool.BrowseInformationFile			= '$(IntDir)\\';
		//CLTool.CompileAs						= "0";
		//CLTool.OptimizeForProcessor				= "1";
		CLTool.Detect64BitPortabilityProblems	= false;

		// Linker options
		var LinkTool			= config.Tools("VCLinkerTool");
		LinkTool.AdditionalDependencies			= "GSESDK.lib RecordHandler.lib";
		LinkTool.AdditionalDependencies			+= " USP10.lib";
		if ( g_bAddVWUISupport ) {
			LinkTool.AdditionalDependencies			+= " VWUI.lib"
		}
		if ( g_bAddVWFCSupport ) {
			LinkTool.AdditionalDependencies			+= " VWFC.lib"
		    LinkTool.AdditionalDependencies			+= " Rpcrt4.lib"
		}
		LinkTool.AdditionalLibraryDirectories	= g_strUserSDKPath + "\\LibWin\\Debug";
		LinkTool.ProgramDatabaseFile			= "$(IntDir)\\$(TargetName).pdb"
		LinkTool.ImportLibrary					= "$(IntDir)\\$(TargetName).lib";
		LinkTool.SuppressStartupBanner			= "TRUE";
		LinkTool.LinkIncremental				= linkIncrementalYes;
		LinkTool.SubSystem						= subSystemWindows

		// MIDL options
		var MIDLTool			= config.Tools("VCMIDLTool");
		MIDLTool.TypeLibraryName				= "$(IntDir)\\$(TargetName).tlb";

		var BSCTool				= config.Tools("VCBscMakeTool");
		BSCTool.OutputFile						= "$(IntDir)\\$(TargetName).bsc"

		// *********** RELEASE **************

		// Compiler options
		config = oProj.Object.Configurations("Release");
		config.OutputDirectory					= g_strUserReleaseOutputPath;
		config.IntermediateDirectory			= g_strUserBuildPath + '\\Release';
		config.ConfigurationType				= typeDynamicLibrary;
		config.DeleteExtensionsOnClean			+= ";*.qtr";

		CLTool				= config.Tools("VCCLCompilerTool");

		if ( g_bAddVWFCSupport ) {
    		CLTool.AdditionalIncludeDirectories		+= g_strUserSDKPath;
    		CLTool.AdditionalIncludeDirectories		+= ",";
		}
		if ( g_bAddVWFCSupport ) {
    		CLTool.AdditionalIncludeDirectories		+= g_strUserSDKPath + "\\Include";
    		CLTool.AdditionalIncludeDirectories		+= ",";
		}
		CLTool.AdditionalIncludeDirectories		+= g_strUserSDKPath + "\\Include\\Kernel";
   		CLTool.AdditionalIncludeDirectories		+= ",";
		CLTool.AdditionalIncludeDirectories		+= g_strUserSDKPath + "\\Include\\GCL";
   		CLTool.AdditionalIncludeDirectories		+= ",";
		CLTool.AdditionalIncludeDirectories		+= g_strUserSDKPath + "\\Include\\OnlyWin";
   		CLTool.AdditionalIncludeDirectories		+= ",";
		CLTool.AdditionalIncludeDirectories		+= g_strUserSDKPath + "\\Include\\Interfaces";
		if ( g_bAddVWUISupport ) {
    		CLTool.AdditionalIncludeDirectories		+= ",";
    		CLTool.AdditionalIncludeDirectories		+= g_strUserSDKPath + "\\Include\\VWUI";
		}
   		CLTool.AdditionalIncludeDirectories		+= ",";
		CLTool.AdditionalIncludeDirectories		+= ".\\Source\\Prefix";
   		CLTool.AdditionalIncludeDirectories		+= ",";
		CLTool.AdditionalIncludeDirectories		+= ".\\Resources";
		
		CLTool.PreprocessorDefinitions			= "NDEBUG;WIN32;_WINDOWS;_USRDLL;_WIN_EXTERNAL_;RELEASE_BLD,_WINDLL";	// No altura
		CLTool.TreatWChar_tAsBuiltInType		= true;
		CLTool.Optimization						= optimizeMaxSpeed;
		CLTool.DebugInformationFormat			= debugEnabled;
		CLTool.BasicRuntimeChecks				= runtimeBasicCheckNone;
		CLTool.RuntimeLibrary					= rtMultiThreaded;
		CLTool.StructMemberAlignment			= alignTwoBytes;
		CLTool.SmallerTypeCheck					= false;
		CLTool.BufferSecurityCheck				= false;
		CLTool.RuntimeTypeInfo					= true;
		CLTool.UsePrecompiledHeader				= pchUseUsingSpecific;
		CLTool.PrecompiledHeaderFile			= '$(IntDir)\\' + g_strUserPrefixFile + '.h';
		CLTool.PrecompiledHeaderThrough			= g_strUserPrefixFile + '.h';
		CLTool.MinimalRebuild					= false;
		CLTool.AssemblerListingLocation			= '$(IntDir)\\';
		CLTool.ObjectFile						= '$(IntDir)\\';
		CLTool.ProgramDataBaseFileName			= '$(IntDir)\\';
		CLTool.BrowseInformation				= brAllInfo;
		CLTool.BrowseInformationFile			= '$(IntDir)\\';
		CLTool.Detect64BitPortabilityProblems	= false;

		// Linker options
		LinkTool			= config.Tools("VCLinkerTool");
		LinkTool.AdditionalDependencies			= "GSESDK.lib RecordHandler.lib";
		LinkTool.AdditionalDependencies			+= " USP10.lib";
		if ( g_bAddVWUISupport ) {
			LinkTool.AdditionalDependencies			+= " VWUI.lib"
		}
		if ( g_bAddVWFCSupport ) {
			LinkTool.AdditionalDependencies			+= " VWFC.lib"
		    LinkTool.AdditionalDependencies			+= " Rpcrt4.lib"
		}
		LinkTool.AdditionalLibraryDirectories	= g_strUserSDKPath + "\\LibWin\\Release";
		LinkTool.ProgramDatabaseFile			= "$(IntDir)\\$(TargetName).pdb"
		LinkTool.ImportLibrary					= "$(IntDir)\\$(TargetName).lib";
		LinkTool.SuppressStartupBanner			= true;
		LinkTool.LinkIncremental				= linkIncrementalNo;
		LinkTool.SubSystem						= subSystemWindows;
		LinkTool.GenerateDebugInformation		= false;
		LinkTool.EnableCOMDATFolding			= "0";
		LinkTool.OptimizeReferences				= "0";

		// MIDL options
		var MIDLTool		= config.Tools("VCMIDLTool");
		MIDLTool.TypeLibraryName				="$(IntDir)\\$(TargetName).tlb";

		var BSCTool				= config.Tools("VCBscMakeTool");
		BSCTool.OutputFile						= "$(IntDir)\\$(TargetName).bsc"
	}
	catch(e)
	{   
		throw e;
	}
}


// ****************************************************************
// Replaces a string within a file.
// ****************************************************************

function ReplaceStringInFile(strFileDirectory, strFileName, strOldString, strNewString)
{
	try {
		// Since a file can't be opened and written to without destroying the file,
		// the file will be renamed, and then read from, and the output will be
		// written to the destination file.

		var  strFilePath = strFileDirectory + "\\" + strFileName;
		var  strTempFilePath = strFileDirectory + "\\" + "!!temp.txt";
		var  fSrcObj, fDestObj;

		// First rename the file to "!!temp.txt"
		var oFSO = new ActiveXObject("Scripting.FileSystemObject");

		if (oFSO.FileExists(strFilePath)) {
			if (oFSO.FileExists(strTempFilePath)) {
				oFSO.DeleteFile(strTempFilePath);
			}
			else {
				// Attempt to delay the system.  It seems the JScript file commands can easily
				// lead to race conditions, which causes file errors.  This is an attempt to
				// slow things down to prevent this.
				for (i = 0; i < 25; i++) {
					oFSO.CreateTextFile(strTempFilePath);
					oFSO.DeleteFile(strTempFilePath);
				}
			}

			oFSO.CopyFile(strFilePath, strTempFilePath);
			oFSO.DeleteFile(strFilePath);

			fSrcObj = oFSO.GetFile(strTempFilePath);		// Get file object

			oFSO.CreateTextFile(strFilePath);
			fDestObj = oFSO.GetFile(strFilePath);

			var srcStream = fSrcObj.OpenAsTextStream(1);	// Open for reading
			var destStream = fDestObj.OpenAsTextStream(2);	// Open for writing

			while (!srcStream.AtEndOfStream) {
				var strLine = srcStream.ReadLine();

				// Search for name to replace
				var strNewLine = strLine.replace(strOldString, strNewString);
				destStream.WriteLine(strNewLine);
			}

			srcStream.Close();
			destStream.Close();

			oFSO.DeleteFile(strTempFilePath);
		}
		else {
			wizard.YesNoAlert("Error: " + strFilePath + " does not exist.");
		}
	}

	catch (e) {
		throw e;
	}
}

// ****************************************************************
// Add a file from template to the project
// ****************************************************************
function RenderFileForProject(curProj, strTemplatePath, strTpl, strProjectPath, strTarget)
{
	var strName		= strTpl;
	var strTemplate	= strTemplatePath + '\\' + strTpl;
	var strFile		= strProjectPath + '\\' + strTarget;

	var bCopyOnly	= false;  //"true" will only copy the file from strTemplate to strTarget without rendering/adding to the project
	var strExt		= strName.substr(strName.lastIndexOf("."));
	if (	strExt == ".bmp" ||
			strExt == ".ico" ||
			strExt == ".gif" ||
			strExt == ".rtf" ||
			strExt == ".css" ||
//			strExt == ".pch++" ||
			strExt == ".plist" ||
			strExt == ".pbxproj" ||
			strTarget == "DevPrefix.h" ||
			strTarget == "ReleasePrefix.h" )
	{
		// only copy this file without adding it to the Win project
		bCopyOnly = true;
	}
	wizard.RenderTemplate(strTemplate, strFile, false, bCopyOnly);

	// Make file read/write
	var oFSO = new ActiveXObject("Scripting.FileSystemObject");
	var f = oFSO.GetFile(strFile);

	if (f.attributes & 1) {
		f.attributes = f.attributes - 1;
	}

	if ( ! bCopyOnly ) {
		return curProj.Object.AddFile(strFile);
	}
	
	return null;
}

// ****************************************************************
// Add prefix files to the project
// ****************************************************************
function CreatePrefixFiles(curProj, strFileTemplatePath, strSourceFilesPath)
{
	var projItems = curProj.ProjectItems;

	var AfxFileH						= RenderFileForProject( curProj, strFileTemplatePath, "Prefix\\StdAfx.h", strSourceFilesPath + "\\Prefix", g_strUserPrefixFile + ".h" );
	AfxFileH.Move( projItems.Item("Source Files").ProjectItems.Item("Prefix").Object );

	var VCFile							= RenderFileForProject( curProj, strFileTemplatePath, "Prefix\\StdAfx.cpp", strSourceFilesPath + "\\Prefix", g_strUserPrefixFile + ".cpp" );
	var config							= VCFile.FileConfigurations( 'Debug' );
	config.Tool.UsePrecompiledHeader	= pchCreateUsingSpecific;
	config								= VCFile.FileConfigurations( 'Release' );
	config.Tool.UsePrecompiledHeader	= pchCreateUsingSpecific;
	VCFile.Move( projItems.Item("Source Files").ProjectItems.Item("Prefix").Object );
	
	if ( g_bAddMacPrefix ) {
		var commonFile = RenderFileForProject( curProj, strFileTemplatePath, "Prefix\\CommonPrefix.h", strSourceFilesPath + "\\Prefix", "CommonPrefix.h" );
		commonFile.Move( projItems.Item("Source Files").ProjectItems.Item("Prefix").Object );
		
		// this is obsolete CodeWarrior prefix -- should be removed
//		RenderFileForProject( curProj, strFileTemplatePath, "Prefix\\DebugPrefix.pch++", strSourceFilesPath + "\\Prefix", "Debug" + g_strUserPrefixFile + ".pch++" );
//		RenderFileForProject( curProj, strFileTemplatePath, "Prefix\\FinalPrefix.pch++", strSourceFilesPath + "\\Prefix", "Final" + g_strUserPrefixFile + ".pch++" );
		
		// XCode prefix
		RenderFileForProject( curProj, strFileTemplatePath, "Prefix\\DevPrefix.h", strSourceFilesPath + "\\Prefix", "DevPrefix.h" );
		RenderFileForProject( curProj, strFileTemplatePath, "Prefix\\ReleasePrefix.h", strSourceFilesPath + "\\Prefix", "ReleasePrefix.h" );
	}
} 

// puts files for MFC support
function CreateMFCFiles(curProj, projItems, strFileTemplatePath, strSourceFilesPath, strProjectName)
{
	var VCFile = RenderFileForProject( curProj, strFileTemplatePath, "resource.h", strSourceFilesPath + "\\res", "resource.h" );
	// Move resource.h file to "Resource Files" folder
	VCFile.Move( projItems.Item("Resource Files").Object );
	
	RenderFileForProject( curProj, strFileTemplatePath, "MFCApp.h", strSourceFilesPath, strProjectName + "MFCApp.h" );
	RenderFileForProject( curProj, strFileTemplatePath, "MFCApp.cpp", strSourceFilesPath, strProjectName + "MFCApp.cpp" );
	RenderFileForProject( curProj, strFileTemplatePath, "MFCTestDialog.h", strSourceFilesPath, "MFCTestDialog.h" );
	RenderFileForProject( curProj, strFileTemplatePath, "MFCTestDialog.cpp", strSourceFilesPath, "MFCTestDialog.cpp" );
	RenderFileForProject( curProj, strFileTemplatePath + "\\res", "MFCLibrary.rc", strSourceFilesPath + "\\res", strProjectName + "Library.rc" );
	RenderFileForProject( curProj, strFileTemplatePath + "\\res", "MFCLibrary.rc2", strSourceFilesPath + "\\res", strProjectName + "Library.rc2" );
}

// puts mac resource files
function CreateMacResourceFile(curProj, projItems, strFileTemplatePath, strProjectPath, strSourceResFile)
{
	var VCFile = RenderFileForProject( curProj, strFileTemplatePath, strSourceResFile, strProjectPath + "\\Resources", "PluginResource.r" );

	// Move .r file to "Resources" folder
	VCFile.Move( projItems.Item("Resources").Object );

	// Custom Build options
	var configDebug					= VCFile.FileConfigurations( 'Debug' );
	configDebug.Tool.CommandLine	= '"' + g_strUserRezExePath + '" -define _WINDOWS=1 -i "' + g_strUserQuickTimeSDKRIncludePath + '" -i "' + g_strUserVWSDKResourcesPath + '" -s ".\\Resources" -o "$(OutDir)\\$(TargetName).qtr" "$(InputPath)"';
	configDebug.Tool.Description	= "Running 'Rez.exe' on $(InputPath)";
	configDebug.Tool.Outputs		= "$(OutDir)\\$(TargetName).qtr";
	
	var configRelease				= VCFile.FileConfigurations( 'Release' );
	configRelease.Tool.CommandLine	= '"' + g_strUserRezExePath + '" -define _WINDOWS=1 -i "' + g_strUserQuickTimeSDKRIncludePath + '" -i "' + g_strUserVWSDKResourcesPath + '" -s ".\\Resources" -o "$(OutDir)\\$(TargetName).qtr" "$(InputPath)"';
	configRelease.Tool.Description	= "Running 'Rez.exe' on $(InputPath)";
	configRelease.Tool.Outputs		= "$(OutDir)\\$(TargetName).qtr";
	
	var HResFile = 
	RenderFileForProject( curProj, strFileTemplatePath, "PluginResource.h", strProjectPath + "\\Resources", "PluginResource.h" );
	
	// Move .h file to "Resources" folder
	HResFile.Move( projItems.Item("Resources").Object );

	// XCode specific resources
	RenderFileForProject( curProj, strFileTemplatePath, "Module-Info.plist", strProjectPath + "\\Resources", "Module-Info.plist" );
}

// *************************** Plug-in Library ***************************



// ****************************************************************
// Creates a Plug-in Library project.
// ****************************************************************
function CreateModuleProject(strProjectName, strProjectPath, strProjTemplatePath, strFileTemplatePath)
{
	try
	{
		var oProj = CreateBasePluginProject(strProjectName, strProjectPath, strProjTemplatePath, strFileTemplatePath);
		SetPluginLibrarySpecificSettings(oProj, strProjectName);

		// Add library files
		AddLibrarySourceFilesToProject(oProj, strFileTemplatePath, strProjectName, strProjectPath);

		// Add XCode project
		RenderFileForProject(	oProj,
								strFileTemplatePath, "module_project.pbxproj",
								strProjectPath + "\\" + strProjectName + ".xcodeproj", "project.pbxproj" );

		return oProj;
	}

	catch(e)
	{
		throw e;
	}
}


// ************************************
// Adds library files to project.
// ************************************
function AddLibrarySourceFilesToProject(curProj, strFileTemplatePath, strProjectName, strProjectPath)
{
	// Might want to just open the Templates.inf file and loop through that file, checking
	// the extension for .cpp or .h, and adding to the project.

	var projItems = curProj.ProjectItems;

	var	strSourceFilesPath	= strProjectPath + "\\Source";
	
	RenderFileForProject( curProj, strFileTemplatePath, "ModuleMain.cpp", strSourceFilesPath, strProjectName + "Module.cpp" );

	// make prefix files and it's settnigs
	CreatePrefixFiles(curProj, strFileTemplatePath, strSourceFilesPath);

	if ( g_bAutomaticMacResourceGeneration ) {
		CreateMacResourceFile( curProj, projItems, strFileTemplatePath, strProjectPath, "Module.r" );
	}
	
	if ( g_bAddMFCSupport ) {
		CreateMFCFiles( curProj, projItems, strFileTemplatePath, strSourceFilesPath, strProjectName );
	}
}


// ******************************************************
// Adds specific Nemetschek plug-in library settings to project.
// ******************************************************
function SetPluginLibrarySpecificSettings(oProj, projName)
{
	try
	{
		// *********** DEBUG **************

		// Compiler options
		var config = oProj.Object.Configurations("Debug");

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

		// Linker options
		var LinkTool = config.Tools("VCLinkerTool");
		LinkTool.OutputFile					= '$(OutDir)\\$(ProjectName).vlb';
		LinkTool.IgnoreDefaultLibraryNames	= "libc";

		// MIDL options
		var MIDLTool = config.Tools("VCMIDLTool");



		// *********** RELEASE **************

		// Compiler options
		config = oProj.Object.Configurations("Release");

		CLTool = config.Tools("VCCLCompilerTool");

		// Linker options
		LinkTool = config.Tools("VCLinkerTool");
		LinkTool.OutputFile					= '$(OutDir)\\$(ProjectName).vlb';

		// MIDL options
		var MIDLTool = config.Tools("VCMIDLTool");
	}

	catch(e)
	{   
		throw e;
	}
}


