📄 pvr_apphint.c
字号:
/*!
******************************************************************************
@file : pvr_apphint.c
@brief
@Author Vlad Stamate
@date 10/12/2003
<b>Copyright 2003 by Imagination Technologies Limited.</b>\n
All rights reserved. No part of this software, either
material or conceptual may be copied or distributed,
transmitted, transcribed, stored in a retrieval system
or translated into any human or computer language in any
form by any means, electronic, mechanical, manual or
other-wise, or disclosed to third parties without the
express written permission of Imagination Technologies
Limited, Unit 8, HomePark Industrial Estate,
King's Langley, Hertfordshire, WD4 8LZ, U.K.
<b>Description:</b>\n
Provides support for reading application specific hints in WinCE.
<b>Platform:</b>\n
WinCE
@Version
???
******************************************************************************/
#include <windows.h>
#include <winbase.h>
#include <stdlib.h>
#include <stdio.h>
#include "img_defs.h"
#include "services.h"
#define pszCommonFile "\\windows\\powervr.ini"
#define pwszOpenGLESRegistryLocation TEXT("Drivers\\Display\\PowerVR\\MBX1\\Game Settings\\OpenGLES\\")
#define pwszD3DMRegistryLocation TEXT("Drivers\\Display\\PowerVR\\MBX1\\Game Settings\\D3DM\\")
IMG_BOOL HostReadRegistryString( IMG_UINT32 ui32DevCookie, IMG_CHAR *pszKey, IMG_CHAR *pszValue, IMG_CHAR *pszOutBuf, IMG_UINT32 ui32OutBufSize );
/* the registry location that we will be looking into
depends on which module is calling us */
static WCHAR pwszRegistryLocation[255];
/*
In WinCE the order in which we are looking for the apphints is
- registry common area
- registry apps area
- environment variables
- file located in \windows
- file located in the same folder as the application using our library
*/
/*----------------------------------------------------------------------------
<function>
FUNCTION : PVRReadRegistryString
PURPOSE : Read a key string from the registry
PARAMETERS : PREGISTRY_INFO psRegInfo
RETURNS : Error status
</function>
------------------------------------------------------------------------------*/
PVRSRV_ERROR IMG_CALLCONV PVRReadRegistryString (PPVRSRV_REGISTRY_INFO psRegInfo)
{
/* Read registry */
if (HostReadRegistryString (psRegInfo->ui32DevCookie,
psRegInfo->pszKey,
psRegInfo->pszValue,
psRegInfo->pszBuf,
psRegInfo->ui32BufSize) != FALSE)
{
return (PVRSRV_OK);
}
else
{
return (PVRSRV_ERROR_GENERIC);
}
}
void GetApplicationName(WCHAR *pszAppName, IMG_UINT32 ui32Size)
{
WCHAR *pszExe = 0, *pszTemp;
WCHAR pszLocalAppName[255]={0};
IMG_UINT32 ui32LocalSize;
ui32LocalSize = GetModuleFileName(0, pszLocalAppName, 255);
if(ui32LocalSize)
{
pszTemp = pszLocalAppName;
do
{
pszTemp = wcschr(pszTemp, (WCHAR)'\\');
if(pszTemp)
{
pszTemp++;
pszExe = pszTemp;
}
}while(pszTemp);
if(!pszExe)
{
pszExe = pszLocalAppName;
}
wcscpy(pszAppName, pszExe);
}
}
IMG_VOID ConvertReturn(IMG_VOID *pReturn, IMG_CHAR *szBuf, IMG_DATA_TYPE eDataType)
{
switch(eDataType)
{
case IMG_STRING_TYPE:
strcpy((IMG_CHAR*)pReturn, szBuf);
break;
case IMG_FLOAT_TYPE:
*(IMG_FLOAT*)pReturn = (IMG_FLOAT) atof(szBuf);
break;
case IMG_UINT_TYPE:
case IMG_FLAG_TYPE:
*(IMG_UINT32*)pReturn = (IMG_UINT32) atoi(szBuf);
break;
case IMG_INT_TYPE:
*(IMG_INT32*)pReturn = (IMG_INT32) atoi(szBuf);
break;
}
}
IMG_BOOL FindCommonHintInRegistry(WCHAR *pwszHintName, IMG_VOID *pReturn, IMG_DATA_TYPE eDataType)
{
PVRSRV_REGISTRY_INFO sRegInfo;
WCHAR wszLocalString[255] = {0};
IMG_CHAR szBuf[255] = {0};
PVRSRV_ERROR Error;
sRegInfo.ui32DevCookie = 0; /* not used */
/* the key is the application name plus the hint name */
sRegInfo.pszKey = (IMG_CHAR*)malloc(512 * sizeof(IMG_CHAR));
wcscpy(wszLocalString, pwszRegistryLocation);
wcscat(wszLocalString, TEXT("Common"));
wcstombs(sRegInfo.pszKey, wszLocalString, 255);
/* fill in the remaining members of the sRegInfo structure */
sRegInfo.pszValue = (IMG_CHAR*)malloc(512 * sizeof(IMG_CHAR));
wcstombs(sRegInfo.pszValue, pwszHintName, 255);
sRegInfo.pszBuf = szBuf;
sRegInfo.ui32BufSize = sizeof(szBuf);
Error = PVRReadRegistryString(&sRegInfo);
free(sRegInfo.pszKey);
free(sRegInfo.pszValue);
if(Error == PVRSRV_OK)
{
ConvertReturn(pReturn, sRegInfo.pszBuf, eDataType);
return TRUE;
}
return IMG_FALSE;
}
IMG_BOOL FindAppHintInRegistry(IMG_CHAR *pszAppName, WCHAR *pwszHintName, IMG_VOID *pReturn, IMG_DATA_TYPE eDataType)
{
PVRSRV_REGISTRY_INFO sRegInfo;
WCHAR szAppName[255] = {0};
WCHAR wszLocalString[255] = {0};
IMG_CHAR szBuf[255] = {0};
PVRSRV_ERROR Error;
/* getting the application name and path */
GetApplicationName(szAppName, 255);
sRegInfo.ui32DevCookie = 0; /* not used */
/* the key is the application name plus the hint name */
sRegInfo.pszKey = (IMG_CHAR*)malloc(512 * sizeof(IMG_CHAR));
wcscpy(wszLocalString, pwszRegistryLocation);
wcscat(wszLocalString, szAppName);
wcstombs(sRegInfo.pszKey, wszLocalString, 255);
/* fill in the remaining members of the sRegInfo structure */
sRegInfo.pszValue = (IMG_CHAR*)malloc(512 * sizeof(IMG_CHAR));
wcstombs(sRegInfo.pszValue, pwszHintName, 255);
sRegInfo.pszBuf = szBuf;
sRegInfo.ui32BufSize = sizeof(szBuf);
Error = PVRReadRegistryString(&sRegInfo);
free(sRegInfo.pszKey);
free(sRegInfo.pszValue);
if(Error == PVRSRV_OK)
{
ConvertReturn(pReturn, sRegInfo.pszBuf, eDataType);
return TRUE;
}
return IMG_FALSE;
}
IMG_BOOL FindAppHintInFile(IMG_CHAR *pszFileName, IMG_CHAR *pszAppName, WCHAR *pwszHintName, IMG_VOID *pReturn, IMG_DATA_TYPE eDataType)
{
return IMG_FALSE;
}
IMG_BOOL FindAppHint(IMG_MODULE_ID eModuleID, IMG_CHAR *pszAppName, IMG_CHAR *pszHintName, IMG_VOID *pReturn, IMG_DATA_TYPE eDataType)
{
WCHAR *pwszHintName;
IMG_UINT32 length;
IMG_BOOL bFound = IMG_FALSE;
pwszHintName = (WCHAR*)malloc(512 * sizeof(WCHAR));
length = mbstowcs( pwszHintName, pszHintName, 256 );
/* depending on which module is calling us, we look in different parts of the registry */
switch(eModuleID)
{
case IMG_OPENGLES:
wcscpy(pwszRegistryLocation, pwszOpenGLESRegistryLocation);
break;
case IMG_D3DM:
wcscpy(pwszRegistryLocation, pwszD3DMRegistryLocation);
break;
}
/* first look in the common are of registry */
if(FindCommonHintInRegistry(pwszHintName, pReturn, eDataType))
{
bFound = IMG_TRUE;
}
/* second look in the apps are of the registry */
if(FindAppHintInRegistry(pszAppName, pwszHintName, pReturn, eDataType))
{
bFound = IMG_TRUE;
}
/* if not found look at the common apphit file in the windows folder */
if(FindAppHintInFile(pszCommonFile, pszAppName, pwszHintName, pReturn, eDataType))
{
bFound = IMG_TRUE;
}
free(pwszHintName);
return bFound;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -