コード例 #1
0
ファイル: gameconfigfile.cpp プロジェクト: coelckers/gzdoom
void FGameConfigFile::AddAutoexec (FArgs *list, const char *game)
{
	char section[64];
	const char *key;
	const char *value;

	mysnprintf (section, countof(section), "%s.AutoExec", game);

	// If <game>.AutoExec section does not exist, create it
	// with a default autoexec.cfg file present.
	CreateStandardAutoExec(section, false);
	// Run any files listed in the <game>.AutoExec section
	if (!SectionIsEmpty())
	{
		while (NextInSection (key, value))
		{
			if (stricmp (key, "Path") == 0 && *value != '\0')
			{
				FString expanded_path = ExpandEnvVars(value);
				if (FileExists(expanded_path))
				{
					list->AppendArg (ExpandEnvVars(value));
				}
			}
		}
	}
}
コード例 #2
0
void FGameConfigFile::AddAutoexec (DArgs *list, const char *game)
{
	char section[64];
	const char *key;
	const char *value;

	mysnprintf (section, countof(section), "%s.AutoExec", game);

	if (bMigrating)
	{
		FBaseCVar *autoexec = FindCVar ("autoexec", NULL);

		if (autoexec != NULL)
		{
			UCVarValue val;
			char *path;

			val = autoexec->GetGenericRep (CVAR_String);
			path = copystring (val.String);
			delete autoexec;
			SetSection (section, true);
			SetValueForKey ("Path", path);
			list->AppendArg (path);
			delete[] path;
		}
	}
	else
	{
		// If <game>.AutoExec section does not exist, create it
		// with a default autoexec.cfg file present.
		CreateStandardAutoExec(section, false);
		// Run any files listed in the <game>.AutoExec section
		if (!SectionIsEmpty())
		{
			while (NextInSection (key, value))
			{
				if (stricmp (key, "Path") == 0 && *value != '\0')
				{
					FString expanded_path = ExpandEnvVars(value);
					if (FileExists(expanded_path))
					{
						list->AppendArg (ExpandEnvVars(value));
					}
				}
			}
		}
	}
}
コード例 #3
0
ファイル: cmdlib.cpp プロジェクト: Marqt/ViZDoom
FString NicePath(const char *path)
{
#ifdef _WIN32
	return ExpandEnvVars(path);
#else
	if (path == NULL || *path == '\0')
	{
		return FString("");
	}
	if (*path != '~')
	{
		return ExpandEnvVars(path);
	}

	const char *slash;
	FString where;

	if (path[1] == '/' || path[1] == '\0')
	{ // Get my home directory from environment var
		where = getenv("HOME");
		slash = path + 1;
	}
	else
	{ // Get somebody else's home directory, from getpwnam
		slash = strchr(path, '/');
		if (slash == NULL)
		{
			slash = path + strlen(path);
		}
		FString who(path, slash - path);
		passwd *pwstruct = getpwnam(who);

		if (pwstruct == NULL)
		{
			return ExpandEnvVars(path);
		}
		where = pwstruct->pw_dir;
	}
	if (*slash != '\0')
	{
		where += ExpandEnvVars(slash);
	}
	return where;
#endif
}
コード例 #4
0
FString NicePath(const char *path)
{
#ifdef _WIN32
	return ExpandEnvVars(path);
#else
	if (path == NULL || *path == '\0')
	{
		return FString("");
	}
	if (*path != '~')
	{
		return ExpandEnvVars(path);
	}

	passwd *pwstruct;
	const char *slash;

	if (path[1] == '/' || path[1] == '\0')
	{ // Get my home directory
		pwstruct = getpwuid(getuid());
		slash = path + 1;
	}
	else
	{ // Get somebody else's home directory
		slash = strchr(path, '/');
		if (slash == NULL)
		{
			slash = path + strlen(path);
		}
		FString who(path, slash - path);
		pwstruct = getpwnam(who);
	}
	if (pwstruct == NULL)
	{
		return ExpandEnvVars(path);
	}
	FString where(pwstruct->pw_dir);
	if (*slash != '\0')
	{
		where += ExpandEnvVars(slash);
	}
	return where;
#endif
}
コード例 #5
0
bool wxFileConfig::Read(const wxString& key,
                        wxString* pStr, const wxString& defVal) const
{
  wxConfigPathChanger path(this, key);

  ConfigEntry *pEntry = m_pCurrentGroup->FindEntry(path.Name());
  bool ok;
  if (pEntry == NULL) {
    if( IsRecordingDefaults() )
      ((wxFileConfig *)this)->Write(key,defVal);
    *pStr = ExpandEnvVars(defVal);
    ok = FALSE;
  }
  else {
    *pStr = ExpandEnvVars(pEntry->Value());
    ok = TRUE;
  }

  return ok;
}
コード例 #6
0
bool wxFileConfig::Read(const wxString& key,
                        wxString* pStr) const
{
  wxConfigPathChanger path(this, key);

  ConfigEntry *pEntry = m_pCurrentGroup->FindEntry(path.Name());
  if (pEntry == NULL) {
    return FALSE;
  }

  *pStr = ExpandEnvVars(pEntry->Value());
  return TRUE;
}
コード例 #7
0
ファイル: CmdLineParser.cpp プロジェクト: dreamsxin/PcManager
BOOL CCmdLineParser::_DoParser(LPCTSTR lpCmdLine,
							  LPCTSTR lpCurDir, 
							  LPCTSTR lpEnvVars, 
							  LPCTSTR lpExtNames,
							  LPCTSTR lpParentPath
							  )
{
	BOOL	bResult = FALSE;
	LPCTSTR	lpCmdBegin = NULL;
	BOOL	bQuotation = FALSE;
	
	m_szCmd[0] = 0;

    if (m_lpParam != NULL)
    {
        delete[] m_lpParam;
        m_lpParam = NULL;
    }

	if ( is_empty_str(lpCmdLine) ) return FALSE;
	if ( is_empty_str(lpParentPath) ) lpParentPath = NULL;
	if ( is_empty_str(lpCurDir) ) lpCurDir = NULL;
	if ( is_empty_str(lpEnvVars) ) lpEnvVars = NULL;
	if ( is_empty_str(lpExtNames) ) lpExtNames = NULL;

	/*
	1、The directory from which the application loaded. 
	2、The current directory for the parent process. 
	3、The 32-bit Windows system directory. Use the GetSystemDirectory function to get the path of this directory.
	Windows Me/98/95:  The Windows system directory. Use the GetSystemDirectory function to get the path of this directory.
	4、The 16-bit Windows system directory. There is no function that obtains the path of this directory, but it is searched. The name of this directory is System. 
	5、The Windows directory. Use the GetWindowsDirectory function to get the path of this directory. 
	6、The directories that are listed in the PATH environment variable. Note that this function does not search the per-application path specified by the App Paths registry key. To include this per-application path in the search sequence, use the ShellExecute function. 
	*/
	lpCmdBegin = lpCmdLine;
	if ( *lpCmdBegin == _T('\"') )
	{
		lpCmdBegin = skip_quotation(lpCmdBegin);
		bQuotation = TRUE;
	}

	if ( (m_dwFlag & DEF_EXT_NAME) && lpExtNames == NULL )
	{
		// 默认扩展名
		lpExtNames = _T("bat;cmd;exe;pif");
	}

	if ( _tcsnicmp(lpCmdBegin, _T("\\??\\"), 4) == 0 )
	{
		lpCmdBegin += 4;
	}

	if ( _tcsnicmp(lpCmdBegin, _T("file://"), 7) == 0 )
	{
		if ( lpCmdBegin[8] == _T(':') )
		{
			lpCmdBegin += 7;
		}
	}

	/*
		宏展开
	*/
	if ( *lpCmdBegin == _T('%') )
	{
		LPTSTR lpCmdBuff = ExpandMacro(lpCmdBegin);
		if ( lpCmdBuff != NULL )
		{
			bResult = ExpandAbsolute(lpCmdBuff, lpExtNames, bQuotation);

			delete lpCmdBuff;
			lpCmdBuff = NULL;
		}
		
		goto _Exit;
	}
	
	/*
		绝对路径展开
	*/
	if ( is_absolute_path(lpCmdBegin) )
	{
		bResult = ExpandAbsolute(lpCmdBegin, lpExtNames, bQuotation);
		goto _Exit;
	}

	/*
		相对路径转换
	*/
	if ( (lpCurDir != NULL) || (m_dwFlag & DEF_CUR_DIR) )
	{
		LPTSTR lpCmdBuff = ExpandRelative(lpCmdBegin, lpCurDir, bQuotation);
		if ( lpCmdBuff != NULL )
		{
			bResult = ExpandAbsolute(lpCmdBuff, lpExtNames, bQuotation);

			delete lpCmdBuff;
			lpCmdBuff = NULL;

			if ( bResult )
			{
				goto _Exit;
			}
		}
	}
	
	/*
		二次宏展开
	*/
	if ( m_dwFlag & DEF_ENV_VAR )
	{
		LPTSTR lpCmdBuff = ExpandMacro2(lpCmdBegin);
		if ( lpCmdBuff != NULL )
		{
			bResult = ExpandAbsolute(lpCmdBuff, lpExtNames, bQuotation);
			
			delete lpCmdBuff;
			lpCmdBuff = NULL;

			if ( bResult )
			{
				goto _Exit;
			}
		}
	}

	/*
		在父程序目录下查找
	*/
	if ( lpParentPath != NULL )
	{
		if ( MyGetLongPathName(lpParentPath, m_szCmd, MAX_PATH) != 0 )
		{
			LPTSTR lpFileName = (LPTSTR)get_file_name(m_szCmd);
			*lpFileName = 0;
			DWORD dwLen2 = (DWORD)_tcslen(m_szCmd);

			LPTSTR lpCmdBuff = new TCHAR[dwLen2 + _tcslen(lpCmdBegin) + 2];
			if ( lpCmdBuff != NULL )
			{
				_tcscpy(lpCmdBuff, m_szCmd);
				if ( lpCmdBuff[dwLen2 - 1] != _T('\\') )
				{
					lpCmdBuff[dwLen2++] = _T('\\');
				}
				_tcscpy(lpCmdBuff + dwLen2, lpCmdBegin);
				//MessageBox(0, lpCmdBuff, NULL, 0);

				bResult = ExpandAbsolute(lpCmdBuff, lpExtNames, bQuotation);
				
				delete lpCmdBuff;
				lpCmdBuff = NULL;

				if ( bResult )
				{
					goto _Exit;
				}
			}
		}
	}

	/*
	环境变量中查找
	*/
	if ( lpEnvVars != NULL || (m_dwFlag & DEF_ENV_VAR) )
	{
		LPCTSTR lpCmdEnd = NULL;

		if ( bQuotation )
		{
			lpCmdEnd = _tcschr(lpCmdBegin, _T('\"'));
			if ( lpCmdEnd == NULL )
			{
				goto _Exit;
			}
		}
		else
		{
			lpCmdEnd = skip_no_blank(lpCmdBegin);
		}

		if ( !fix_path_separator(m_szCmd, MAX_PATH, lpCmdBegin, lpCmdEnd - lpCmdBegin) )
		{
			goto _Exit;
		}

		if ( !is_relative_path(m_szCmd) )
		{
			bResult = ExpandEnvVars(m_szCmd, lpEnvVars, lpExtNames);
			if ( bResult )
			{
				ExpandParam(lpCmdEnd);
			}
		}
	}

_Exit:
	if ( !bResult )
	{
		m_szCmd[0] = 0;
	}

	return bResult;
}