示例#1
0
void CPigEngine::LoadScriptFile(CPigBehaviorScriptType* pScript,
  const WIN32_FIND_DATA* pffd, tstring strFileName)
{
  // Initialize the specified object
  HRESULT hr = pScript->Load(pffd, strFileName);
  if (SUCCEEDED(hr) && SUCCEEDED(hr = AddInvokeCommands(pScript)))
    return;

  // Display the error information
  IErrorInfo* pei;
  HRESULT hrEI = GetErrorInfo(0, &pei);
  _com_error err(hr, pei);
  _bstr_t bstrDesc(err.Description());
  _TRACE2("CPigEngine::LoadScriptFile(%s): %s\n", strFileName.c_str(),
    (bstrDesc.length()) ? LPCTSTR(bstrDesc) : err.ErrorMessage());
}
示例#2
0
HRESULT 
AsdkSheetSet::create(char* name,		
					 char* path,		
					 char* description,
					 char* templPath,
					 char* defSheetLoc)
{
	BOOL  bAlwaysCreate = TRUE;
	CComBSTR bstrSSName(name);	 // Sheet set name
	HRESULT hr;
	
	// If sheet set manager doesnt exist, create one
	if(!m_pSSetMgr.p)
	{
		if (FAILED(m_pSSetMgr.CoCreateInstance(CLSID_AcSmSheetSetMgr)))
		{
			acutPrintf("\n Error Cannot get sheet set manager!!");	
			return E_FAIL;
		}
	}
	 
	char fullPath[255];
	strcpy(fullPath, path);

	// If no trailing backslash entered, add it
	if (strcmp("\\" , &fullPath[strlen(fullPath)-1]) != 0)
		strcat(fullPath, "\\");

	// check if folder exists
	if(_access(fullPath,0))
	{
		acutPrintf("\n Error: Folder does not exist. Specify another folder!!!");
		return E_FAIL;
	}

	if(!strstr(name,".dst"))
		strcat(name, ".dst");	

	strcat(fullPath, name);
	
	CComBSTR bstrPath(fullPath);
	AcSmLockStatus lockStatus;
	
	// check if file exists 
	// If so, ask the user whether to overwrite or open existing
	if(!_access(fullPath,0))
	{
	   if(!getYorN("\n File exists!! Overwrite existing?"))
	   {
	    	// Don't overwrite existing
			// Just open the file
			// 2nd parameter = FALSE means don't fail if already open
			if(FAILED(m_pSSetMgr->OpenDatabase(bstrPath, FALSE, &m_pDb)))
			{
				acutPrintf("\n Error: Cannot open database!!");
				return E_FAIL;
			}
			
			// get the sheet set from the database.
			if (FAILED(m_pDb->GetSheetSet(&m_pSheetSet)))
			{  
				acutPrintf("\n Error: Cannot get sheet set");
				return E_FAIL;
			}
			
			return E_ABORT;
		}
	}  
	
	// create the database for the sheet set
	// bAlwaysCreate lets you override the existing file if it's set to true
	if (FAILED(hr = m_pSSetMgr->CreateDatabase(bstrPath, NULL, bAlwaysCreate, &m_pDb)))
	{
		acutPrintf("\nError: Cannot create database!");
		if (E_INVALIDARG == hr)
			acutPrintf("\n File name invalid!");		
		return E_FAIL;
	}

	
	 // lock the the database first before doing any operation on it
    if (FAILED(LockDatabase()))
	{
		acutPrintf("\n Error: Database lock failed!");
        return E_FAIL;
	}

	CComBSTR bstrDesc(description);
	
	// set the sheet set db name, description = sheet set name, description
	 if (FAILED(m_pDb->SetName(bstrSSName)))
	 {
		acutPrintf("\n Error: Cannot set database name");
		return E_FAIL;
	 }
	 
	 if (FAILED(m_pDb->SetDesc(bstrDesc)))
	 {
		acutPrintf("\nError: Cannot set database description!");
		return E_FAIL;
	 }
	
	    // get the sheet set from the database.
    if (FAILED(m_pDb->GetSheetSet(&m_pSheetSet)))
	{  
		acutPrintf("\n Error: Cannot get sheet set");
        return E_FAIL;
	}

	// set the name and description to the sheet set
	if (FAILED(m_pSheetSet->SetName(bstrSSName)))
	{
		acutPrintf("\nError: Cannot set name!");
        return E_FAIL;
	}


    if (FAILED(m_pSheetSet->SetDesc(bstrDesc)))
	{
		acutPrintf("\nError: Cannot set description!");
        return E_FAIL;
	}

	if(isValid(templPath))
	{
		// set default template for layout at sheet set level
		overrideDefaultDWTLayout(templPath, m_pSheetSet);
	}

	if(isValid(defSheetLoc))
	{
		// set default sheet location
		setNewSheetLocation(defSheetLoc, m_pSheetSet);
	}

	if (FAILED(UnlockDatabase())) 
	{
		acutPrintf("\n Cannot unlock database");
        return E_FAIL;
	}
    else
		acutPrintf("\n Sheet set %s created", fullPath);
	
	return S_OK;

}