コード例 #1
0
ファイル: KG_Public.cpp プロジェクト: viticm/pap2
int KG_SetRuntimeEnvironment(const char cszAppFullPathName[MAX_PATH])
{
    int nResult  = false;
    int nRetCode = false;
    char szProgramPath[MAX_PATH];

    KGLOG_PROCESS_ERROR(cszAppFullPathName);

    // Set the locale to the default, which is the user-default ANSI code page obtained from 
    // the operating system.
    setlocale(LC_ALL, "");

    // Set working path to application path.
    g_ExtractFilePath(szProgramPath, const_cast<char *>(cszAppFullPathName));
    szProgramPath[sizeof(szProgramPath) - 1] = '\0';

    if (szProgramPath[0])
    {
        nRetCode = chdir(szProgramPath);
        KG_PROCESS_ERROR(nRetCode == 0);

        // Set root path for config file.
        g_SetRootPath(szProgramPath); 
    }
    else
    {
        g_SetRootPath(NULL);
    }

    nResult = true;
Exit0:
    return nResult;
}
コード例 #2
0
ファイル: AloneFile.cpp プロジェクト: github188/yol
//---------------------------------------------------------------------------
// 功能:	创建一个文件,准备写入。
// 参数:	FileName	文件名
// 返回:	成功返回TRUE,失败返回FALSE。
//---------------------------------------------------------------------------
QAloneFile*	QAloneFile::Create(const char*  FileName)
{
	FILE* pFile = NULL;

	char FullPathName[MAX_PATH] = "";
	g_GetFullPath(FullPathName, FileName);
#ifdef unix
	{
		char *ptr = FullPathName;
		while(*ptr)
		{
			if (*ptr == '\\')
				*ptr = '/';
			ptr++;
		}
	}
#endif	// #ifdef unix
	char PathName[MAX_PATH] = "";
	g_ExtractFilePath(PathName, FullPathName);
	g_CreatePath(PathName);
	pFile = fopen(FullPathName, "wb+");
#ifdef unix
	{
		if (pFile == NULL)
		{
			QStrLower(FullPathName);
			pFile = fopen(FullPathName, "wb+");
		}
	}
#endif	// #ifdef unix

	return pFile ? new QAloneFile(pFile) : NULL;
}
コード例 #3
0
int KGTestMapDisuseResource::FindResInMDL(const char cszResourceName[], set<string>& setResList)
{
	//参照KG3DModelST::LoadMDLContent
	int nResult = false;
	char szFilePath[MAX_PATH] = {0};
	IFile* pFile = NULL;
	unsigned long uSize = 0;
	unsigned long uFileSize = 0;
	char* pBuffer = NULL;
	std::stringstream ss;
	std::string strBuffer;
	std::string strFilePath;
	MDLFileContent Content;

	KG_ASSERT_EXIT(cszResourceName);
	KGLOG_PROCESS_ERROR(cszResourceName[0] != '\0');

	Content.dwNumModels = 0;
	pFile = g_OpenFile(cszResourceName);
	KG_PROCESS_ERROR(pFile);

	uFileSize = pFile->Size();

	pBuffer = (char*)malloc(uFileSize + 1);
	KG_PROCESS_ERROR(pBuffer);

	uSize = pFile->Read(pBuffer, uFileSize);
	KG_PROCESS_ERROR(uSize == uFileSize);

	pBuffer[uSize] = '\0'; // TODO : text 文件没有使用'\0'作结束,不能作为字符串处理,特别麻烦,建议使用binary

	ss << pBuffer;

	std::getline(ss, strBuffer);
	strBuffer.erase(strBuffer.find_last_not_of("\n\r") + 1);
	KG_PROCESS_ERROR(!strBuffer.empty());

	g_ExtractFilePath(szFilePath, cszResourceName);

	strFilePath = szFilePath;
	strFilePath += "\\";

	if (strBuffer[0] == '\\')
	{
		Content.strBipFile = strBuffer;
	}
	else
	{
		Content.strBipFile = std::string(strFilePath + strBuffer);
	}
	FindResource(Content.strBipFile.c_str(), setResList);

	while (std::getline(ss, strBuffer))
	{
		strBuffer.erase(strBuffer.find_last_not_of("\n\r") + 1);
		if (strBuffer.empty())
			break;

		std::stringstream ssLine(strBuffer);
		std::string strMesh, strMtl;
		ssLine >> strMesh >> strMtl;

		if (strMtl.size())
		{
			Content.strMaterialFile[Content.dwNumModels] = strMtl;
		}
		FindResource(Content.strMaterialFile[Content.dwNumModels].c_str(), setResList);

		if (strMesh.size())
		{
			if (strMesh[0] == '\\')
			{
				Content.strMeshFile[Content.dwNumModels] = strMesh;
			}
			else
			{
				Content.strMeshFile[Content.dwNumModels] = strFilePath + strMesh;
			}
			FindResource(Content.strMeshFile[Content.dwNumModels].c_str(), setResList);
			Content.dwNumModels++;
		}
	}
	nResult = true;
Exit0:
	SAFE_FREE(pBuffer);
	KG_COM_RELEASE(pFile);

	if (!nResult && cszResourceName)
	{
		KGLogPrintf(KGLOG_ERR, "Find Res In MDL %s failed.\n", cszResourceName);
	}
	return nResult;
}