Ejemplo n.º 1
0
__inline
errno_t __cdecl DuplicateEnvString(TCHAR **ppszBuffer, size_t *pnBufferSizeInTChars, const TCHAR *pszVarName)
{	    
    /* validation section */
	if (ppszBuffer == NULL) { return  EINVAL; }
    *ppszBuffer = NULL;
    if (pnBufferSizeInTChars != NULL)
    {
        *pnBufferSizeInTChars = 0;
    }
    /* varname is already validated in getenv */
	TCHAR szDummyBuff[1] = {0};
	size_t nSizeNeeded = 0;
    errno_t ret=_tgetenv_s(&nSizeNeeded,szDummyBuff,1,pszVarName);
	if (nSizeNeeded > 0)
	{	    		
		*ppszBuffer = new TCHAR[nSizeNeeded];
		if (*ppszBuffer != NULL)
		{
			size_t nSizeNeeded2 = 0;
			ret=_tgetenv_s(&nSizeNeeded2,*ppszBuffer,nSizeNeeded,pszVarName);
			if (nSizeNeeded2!=nSizeNeeded)
			{
				ret=ERANGE;
			} else if (pnBufferSizeInTChars != NULL)
			{
				*pnBufferSizeInTChars = nSizeNeeded;
			}				
		} else
		{
			ret=ENOMEM;
		}	    		
	}
    return ret;
}
Ejemplo n.º 2
0
void dxLogger::getSystemInfo () {

	size_t retVal;

	_tgetenv_s (&retVal, osName, MAX_PATH, _T("OS"));
	_tgetenv_s (&retVal, compName, MAX_PATH, _T("COMPUTERNAME"));
	_tgetenv_s (&retVal, userName, MAX_PATH, _T("USERNAME"));
	_tgetenv_s (&retVal, appDataPath, MAX_PATH, _T("APPDATA"));
}
Ejemplo n.º 3
0
static BOOL FindGitPath()
{
	size_t size;
	_tgetenv_s(&size, NULL, 0, _T("PATH"));

	if (!size)
	{
		return FALSE;
	}

	TCHAR *env = (TCHAR*)alloca(size * sizeof(TCHAR));
	_tgetenv_s(&size, env, size, _T("PATH"));

	TCHAR buf[_MAX_PATH];

	// search in all paths defined in PATH
	while ((env = nextpath(env, buf, _MAX_PATH-1)) && *buf)
	{
		TCHAR *pfin = buf + _tcslen(buf)-1;

		// ensure trailing slash
		if (*pfin != _T('/') && *pfin != _T('\\'))
			_tcscpy(++pfin, _T("\\"));

		const int len = _tcslen(buf);

		if ((len + 7) < _MAX_PATH)
			_tcscpy(pfin+1, _T("git.exe"));
		else
			break;

		if ( FileExists(buf) )
		{
			// dir found
			pfin[1] = 0;
			CGit::ms_LastMsysGitDir = buf;
			return TRUE;
		}
	}

	return FALSE;
}
Ejemplo n.º 4
0
TCHAR * UTBStr::tgetenv(const TCHAR *varname) 
{
#if _MSC_VER >= 1400
	TCHAR* retval;
	size_t requiredSize;
	// Get required length
	_tgetenv_s( &requiredSize, NULL, 0, varname);
	retval = new TCHAR[requiredSize];
	if (!_tgetenv_s( &requiredSize, retval, requiredSize, varname ))
		return retval;
	else
	{
		delete [] retval;
		return NULL;
	}
	
#else
	return _tgetenv(varname);
#endif
}
Ejemplo n.º 5
0
BOOL CGit::CheckMsysGitDir()
{
	static BOOL bInitialized = FALSE;

	if (bInitialized)
	{
		return TRUE;
	}

	TCHAR *oldpath,*home;
	size_t size;

	// set HOME if not set already
	_tgetenv_s(&size, NULL, 0, _T("HOME"));
	if (!size)
	{
		_tdupenv_s(&home,&size,_T("USERPROFILE")); 
		_tputenv_s(_T("HOME"),home);
		free(home);
	}

	//setup ssh client
	CRegString sshclient=CRegString(_T("Software\\TortoiseGit\\SSH"));
	CString ssh=sshclient;

	if(!ssh.IsEmpty())
	{
		_tputenv_s(_T("GIT_SSH"),ssh);
	}else
	{
		_tputenv_s(_T("GIT_SSH"),_T(""));
	}

	// search PATH if git/bin directory is alredy present
	if ( FindGitPath() )
	{
		bInitialized = TRUE;
		return TRUE;
	}

	// add git/bin path to PATH

	CRegString msysdir=CRegString(REG_MSYSGIT_PATH,_T(""),FALSE,HKEY_LOCAL_MACHINE);
	CString str=msysdir;
	if(str.IsEmpty())
	{
		CRegString msysinstalldir=CRegString(REG_MSYSGIT_INSTALL,_T(""),FALSE,HKEY_LOCAL_MACHINE);
		str=msysinstalldir;
		if ( !str.IsEmpty() )
		{
			str += (str[str.GetLength()-1] != '\\') ? "\\bin" : "bin";
			msysdir=str;
			msysdir.write();
		}
		else
		{
			return false;
		}
	}
	//CGit::m_MsysGitPath=str;

	//set path

	_tdupenv_s(&oldpath,&size,_T("PATH")); 

	CString path;
	path.Format(_T("%s;%s"),oldpath,str);

	_tputenv_s(_T("PATH"),path);

	CString sOldPath = oldpath;
	free(oldpath);


    if( !FindGitPath() )
	{
		return false;
	}
	else
	{
#ifdef _TORTOISESHELL
		l_processEnv = GetEnvironmentStrings();
		// updated environment is now duplicated for use in CreateProcess, restore original PATH for current process
		_tputenv_s(_T("PATH"),sOldPath);
#endif

		bInitialized = TRUE;
		return true;
	}
}