Esempio n. 1
0
BOOL read_appkey(LPCWSTR lpappname,              /* 区段名 */
                 LPCWSTR lpkey,					 /* 键名  */
                 LPWSTR  prefstring,			 /* 保存值缓冲区 */
                 DWORD   bufsize				 /* 缓冲区大小 */
                )
{
    DWORD  res = 0;
    LPWSTR lpstring;
    if ( profile_path[1] != L':' )
    {
        if (!ini_ready(profile_path,MAX_PATH))
        {
            return res;
        }
    }
    lpstring = (LPWSTR)SYS_MALLOC(bufsize);
    res = GetPrivateProfileStringW(lpappname, lpkey ,L"", lpstring, bufsize, profile_path);
    if (res == 0 && GetLastError() != 0x0)
    {
        SYS_FREE(lpstring);
        return FALSE;
    }
    wcsncpy(prefstring,lpstring,bufsize/sizeof(WCHAR)-1);
    prefstring[res] = '\0';
    SYS_FREE(lpstring);
    return ( res>0 );
}
Esempio n. 2
0
int read_appint(LPCWSTR cat,LPCWSTR name)
{
    int res = -1;
    if ( profile_path[1] != L':' )
    {
        if (!ini_ready(profile_path,MAX_PATH))
        {
            return res;
        }
    }
    res = GetPrivateProfileIntW(cat, name, -1, profile_path);
    return res;
}
Esempio n. 3
0
BOOL foreach_section(LPCWSTR cat,						/* ini 区段 */
                     WCHAR (*lpdata)[VALUE_LEN+1],	    /* 二维数组首地址,保存多个段值 */
                     int line							/* 二维数组行数 */
                    )
{
    DWORD	res = 0;
    LPWSTR	lpstring;
    LPWSTR	strKey;
    int		i = 0;
    const	WCHAR delim[] = L"=";
    DWORD	num = VALUE_LEN*sizeof(WCHAR)*line;
    if ( profile_path[1] != L':' )
    {
        if (!ini_ready(profile_path,MAX_PATH))
        {
            return res;
        }
    }
    if ( (lpstring = (LPWSTR)SYS_MALLOC(num)) != NULL )
    {
        if ( (res = GetPrivateProfileSectionW(cat, lpstring, num, profile_path)) > 0 )
        {
            fzero(*lpdata,num);
            strKey = lpstring;
            while(*strKey != L'\0'&& i < line)
            {
                LPWSTR strtmp;
                WCHAR t_str[VALUE_LEN] = {0};
                wcsncpy(t_str,strKey,VALUE_LEN-1);
                strtmp = StrStrW(t_str, delim);
                if (strtmp)
                {
                    wcsncpy(lpdata[i],&strtmp[1],VALUE_LEN-1);
                }
                strKey += wcslen(strKey)+1;
                ++i;
            }
        }
        SYS_FREE(lpstring);
    }
    return (BOOL)res;
}
Esempio n. 4
0
/* 必须使用进程依赖crt的wputenv函数追加环境变量 */
unsigned WINAPI SetPluginPath(void * pParam)
{
    typedef			int (__cdecl *_pwrite_env)(LPCWSTR envstring);
    int				ret = 0;
    HMODULE			hCrt =NULL;
    _pwrite_env		write_env = NULL;
    char			msvc_crt[CRT_LEN+1] = {0};
    LPWSTR			lpstring;
    if ( !find_msvcrt(msvc_crt,CRT_LEN) )
    {
        return (0);
    }
    if ( (hCrt = GetModuleHandleA(msvc_crt)) == NULL )
    {
        return (0);
    }
    if ( profile_path[1] != L':' )
    {
        if (!ini_ready(profile_path,MAX_PATH))
        {
            return (0);
        }
    }
    write_env = (_pwrite_env)GetProcAddress(hCrt,"_wputenv");
    if ( write_env == NULL )
    {
        return (0);
    }
    if ( (lpstring = (LPWSTR)SYS_MALLOC(MAX_ENV_SIZE)) == NULL )
    {
        return (0);
    }
    if ( (ret = GetPrivateProfileSectionW(L"Env", lpstring, MAX_ENV_SIZE-1, profile_path)) > 0 )
    {
        LPWSTR	strKey = lpstring;
        while(*strKey != L'\0')
        {
            if ( stristrW(strKey, L"NpluginPath") )
            {
                WCHAR lpfile[VALUE_LEN+1];
                if ( read_appkey(L"Env",L"NpluginPath",lpfile,sizeof(lpfile)) )
                {
                    WCHAR env_string[VALUE_LEN+1] = {0};
                    PathToCombineW(lpfile, VALUE_LEN);
                    if ( _snwprintf(env_string,VALUE_LEN,L"%ls%ls",L"MOZ_PLUGIN_PATH=",lpfile) > 0)
                    {
                        ret = write_env( (LPCWSTR)env_string );
                    }
                }
            }
            else if ( stristrW(strKey, L"VimpPentaHome") )
            {
                WCHAR lpfile[VALUE_LEN+1];
                if ( read_appkey(L"Env",L"VimpPentaHome",lpfile,sizeof(lpfile)) )
                {
                    WCHAR env_string[VALUE_LEN+1] = {0};
                    if (lpfile[1] != L':')
                    {
                        WCHAR vimp_path[VALUE_LEN+1] = {0};
                        charTochar(lpfile);
                        if ( PathCombineW(vimp_path,portable_data_path,lpfile) )
                        {
                            int n = _snwprintf(lpfile,VALUE_LEN,L"%ls",vimp_path);
                            lpfile[n] = L'\0';
                        }
                    }
                    if ( _snwprintf(env_string,VALUE_LEN,L"%ls%ls",L"HOME=",lpfile) > 0)
                    {
                        ret = write_env( (LPCWSTR)env_string );
                    }
                }
            }
            else if	(stristrW(strKey, L"MOZ_GMP_PATH"))
            {
                WCHAR lpfile[VALUE_LEN+1];
                if ( read_appkey(L"Env",L"MOZ_GMP_PATH",lpfile,sizeof(lpfile)) )
                {
                    WCHAR env_string[VALUE_LEN+1] = {0};
                    PathToCombineW(lpfile, VALUE_LEN);
                    if ( _snwprintf(env_string,VALUE_LEN,L"%ls%ls",L"MOZ_GMP_PATH=",lpfile) > 0)
                    {
                        ret = write_env( (LPCWSTR)env_string );
                    }
                }
            }
            else if	(stristrW(strKey, L"TmpDataPath"))
            {
                /* the PATH environment variable does not exist */
            }
            else
            {
                ret = write_env( (LPCWSTR)strKey );
            }
            strKey += wcslen(strKey)+1;
        }
    }
    SYS_FREE(lpstring);
    return (1);
}
Esempio n. 5
0
/* 必须使用进程依赖crt的wputenv函数追加环境变量 */
unsigned WINAPI SetPluginPath(void * pParam)
{
	typedef			int (__cdecl *_pwrite_env)(LPCWSTR envstring);
	int				ret = 0;
	HMODULE			hCrt =NULL;
	_pwrite_env		write_env = NULL;
	char			msvc_crt[CRT_LEN+1] = {0};
	LPWSTR			lpstring;
	if ( !find_msvcrt(msvc_crt,CRT_LEN) )
	{
		return ((unsigned)ret);
	}
	if ( (hCrt = GetModuleHandleA(msvc_crt)) == NULL )
	{
		return ((unsigned)ret);
	}
	if ( profile_path[1] != L':' )
	{
		if (!ini_ready(profile_path,MAX_PATH))
		{
			return ((unsigned)ret);
		}
	}
	write_env = (_pwrite_env)GetProcAddress(hCrt,"_wputenv");
	if ( write_env )
	{
		if ( (lpstring = (LPWSTR)SYS_MALLOC(MAX_ENV_SIZE)) != NULL )
		{
			if ( (ret = GetPrivateProfileSectionW(L"Env", lpstring, MAX_ENV_SIZE-1, profile_path)) > 0 )
			{
				LPWSTR	strKey = lpstring;
				while(*strKey != L'\0') 
				{
					if ( stristrW(strKey, L"NpluginPath") )
					{
						WCHAR lpfile[VALUE_LEN+1];
						if ( read_appkey(L"Env",L"NpluginPath",lpfile,sizeof(lpfile)) )
						{
							WCHAR env_string[VALUE_LEN+1] = {0};
							PathToCombineW(lpfile, VALUE_LEN);
							if ( _snwprintf(env_string,VALUE_LEN,L"%ls%ls",L"MOZ_PLUGIN_PATH=",lpfile) > 0)
							{
								ret = write_env( (LPCWSTR)env_string );
							}
						}
					}
					else if	(stristrW(strKey, L"TmpDataPath"))
					{
						;
					}
					else
					{
						ret = write_env( (LPCWSTR)strKey );
					}
					strKey += wcslen(strKey)+1;
				}
			}
			SYS_FREE(lpstring);
		}
	}
	return ( (unsigned)ret );
}