⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plugintool.cpp

📁 cy7c68013目前最流行的几种gps芯片的控制定制程序的源代码
💻 CPP
字号:
////////////////////////////////////////////////////////////////////////////////
// plugintool.cpp : implementation of the CPlugInTool class
// Author:	Saji Varkey (SCV)
// $Header: /USB/Util/EzMr/plugintool.cpp 3     8/08/00 2:26p Tpm $
// Copyright (c) 2000 Cypress Semiconductor. May not be reproduced without permission.
// See the EzUsb Developer's Kit license agreement for more details.
////////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "plugintool.h"
#include <direct.h> // TPM for _getcwd
#include <stdio.h>
#include <stdlib.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

static CMapStringToString m_varMap;		// Store variables and their values

static const CString PROJ_NAME			= "PROJ_NAME";
static const CString TOP_FILE			= "TOP_FILE";
static const CString TOP_FILE_WO_EXT	= "TOP_FILE_WO_EXT";
static const CString JED				= "JED";
static const CString TOP_DESIGN			= "TOP_DESIGN";
static const CString PROJ_DIR			= "PROJ_DIR";
static const CString DEVICE				= "DEVICE";
static const CString PACKAGE			= "PACKAGE";


//.........................................................................................
//
// DESCRIPTION:
//			Constructor
//
//.........................................................................................
CPlugInTool::CPlugInTool( CString name, CString path, CString initDir, CString args )
{
	m_menuName = name;
	m_exePath = path;
	m_initDir = initDir;
	m_defArgs = args;
	m_varMap.RemoveAll();

}

//.........................................................................................
//
// DESCRIPTION:
//			This function gets all the variable info. from the project manager and
//			store it in m_varMap.
//
// RETURN:
//			void
//.........................................................................................
void CPlugInTool::GetVariables() const
{
}


//.........................................................................................
//
// DESCRIPTION:
//			This function changes the current directory to the initial directory.
//
// RETURN:
//			void
//.........................................................................................
void CPlugInTool::ChangeToInitDir() const
{
	CString dir = SubstituteVariables( m_initDir );	// expand the reg string
	if ( dir.IsEmpty() )
	{
		CString tmpStr;
		if ( !m_varMap.Lookup( PROJ_DIR, tmpStr ) ) // get proj. dir
		{
			tmpStr.Empty();							// this should never happen
		}
		if ( !tmpStr.IsEmpty() )
		{
			dir = tmpStr;
		}
		else {										// get the current working dir.
			char buffer[_MAX_PATH];
			if( _getcwd( buffer, _MAX_PATH ) != NULL )
			{
				dir = buffer;
			}
			else {
				return;		// cannot get any information to change dir.
			}
		}
	}
	_chdir( (LPCTSTR) dir );	// change the current working directory
}



//.........................................................................................
//
// DESCRIPTION:
//			Launch the tool with appropriate arguments in the initial directory.
//
// RETURN:
//			BOOL - TRUE if successful; otherwise FALSE
//
//.........................................................................................
BOOL CPlugInTool::Run() const
{
	char currWorkdir[_MAX_PATH];
	BOOL bHaveCurrDir = FALSE;
	GetVariables();
	if ( _getcwd( currWorkdir, _MAX_PATH ) != NULL )	// get the current working dir.
	{
		bHaveCurrDir = TRUE;
	}
	ChangeToInitDir();
	CString args = SubstituteVariables( m_defArgs );

	CString sep = "\\";
	CString CommandLine;
	STARTUPINFO si = {0};
	PROCESS_INFORMATION pi = {0};
	
	si.cb = sizeof(STARTUPINFO);
	si.lpReserved = NULL;
	si.lpReserved2 = NULL;
	si.cbReserved2 = 0;
	si.lpDesktop = NULL;
	si.dwFlags = 0;

	CommandLine = m_exePath + " " + args;
	if (!CreateProcess( NULL, (LPSTR)(LPCTSTR)CommandLine, NULL,	// launch 
						NULL, FALSE, NORMAL_PRIORITY_CLASS,
						NULL, NULL, &si, &pi ) ) 
	{
		// Create failed. Show error message.
		//
		CString msg = "Can't launch tool - " + GetMenuName() + ".\nCommand Line: " + CommandLine + "\n\n";
		LPVOID lpMsgBuf;
		CString err;
 		FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
					   NULL,
					   GetLastError(),
					   MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language 
					   (LPTSTR) &lpMsgBuf,
					   0,
					   NULL );
		err = (LPSTR)lpMsgBuf;
		msg += err;
		AfxMessageBox( msg, MB_ICONSTOP );
		if ( bHaveCurrDir )		// restore the working directory
		{
			_chdir( currWorkdir );
		}
		return FALSE;
	}
	if ( bHaveCurrDir )			// restore the working directory
	{
		_chdir( currWorkdir );
	}
	return TRUE;
}



//.........................................................................................
//
// DESCRIPTION:
//			This function gets the value for galaxy defined varables.
//
// RETURN:
//			BOOL - TRUE if variable found, otherwise FALSE
//
//.........................................................................................
BOOL CPlugInTool::GetValue( CString inStr, CString & outStr ) const
{
	CString tmpStr;
	BOOL bRet = FALSE;

	if ( m_varMap.Lookup( inStr, tmpStr ) )
	{
		outStr = tmpStr;
		bRet = TRUE;
	}
	return bRet;
}




//.........................................................................................
//
// DESCRIPTION:
//			This function parses a string substitutes the value of the varables
//			in the string.
//
// RETURN:
//			CString - the string after substitutation. If any of the variables
//			values are empty this string will be empty.
//
//.........................................................................................
CString CPlugInTool::SubstituteVariables( CString inStr ) const
{
	CString str = inStr;
	CString tmp = str;

    //char sep[] = " \t \n \\ / .";
    char* cpString;
	char* curStr;

	BOOL bFlag = FALSE;
    cpString = new char[ tmp.GetLength() + 1 ];
	LPCTSTR tmpPtr = tmp.GetBuffer( tmp.GetLength() + 1 );
    strcpy( cpString, tmpPtr );
	tmp.ReleaseBuffer();
    curStr = cpString;

	CString strSub;
	CString strMain;

    while( *curStr )
    {
		char c = *curStr;
		switch ( c )
		{
			case '$':
			{
				bFlag = TRUE;
				break;
			}
			case '\t':
			case '\n':
			case ' ':
			case '\\':
			case '/':
			case '.':
			{
				bFlag = FALSE;
				if ( !strSub.IsEmpty() )
				{
					CString newStr;
					if ( GetValue( strSub.Mid(1), newStr ) )
					{
						if ( newStr.IsEmpty() )
						{
							return "";	// don't pass any args
						}
						strMain += newStr;
					}
					else {
						strMain += strSub;
					}
					strSub.Empty();
				}
				break;
			}
		}
		if ( bFlag )
		{
			strSub += c;
		}
		else {
			strMain += c;
		}
		curStr++;
    }

	if ( !strSub.IsEmpty() )
	{
		CString newStr;
		if ( GetValue( strSub.Mid(1), newStr ) )
		{
			if ( newStr.IsEmpty() )
			{
				return "";	// don't pass any args
			}
			strMain += newStr;
		}
		else {
			strMain += strSub;
		}
		strSub.Empty();
	}
	delete [] cpString;
	return strMain;
}



//.........................................................................................
//
// DESCRIPTION:
//			Sets the menu name.
//
// RETURN:
//			void
//.........................................................................................
void CPlugInTool::SetMenuName( CString name )
{
	m_menuName = name;
}


//.........................................................................................
//
// DESCRIPTION:
//			Sets the executable path.
//
// RETURN:
//			void
//.........................................................................................
void CPlugInTool::SetPath( CString path )
{
	m_exePath = path;
}


//.........................................................................................
//
// DESCRIPTION:
//			Sets the initial directory.
//
// RETURN:
//			void
//.........................................................................................
void CPlugInTool::SetInitDir( CString initDir )
{
	m_initDir = initDir;
}



//.........................................................................................
//
// DESCRIPTION:
//			Sets the Default Arguments.
//
// RETURN:
//			void
//.........................................................................................
void CPlugInTool::SetDefArgs( CString args )
{
	m_defArgs = args;
}




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -