예제 #1
0
파일: tinyxml.cpp 프로젝트: github188/yol
bool TiXmlDocument::LoadFile( const char* filename, TiXmlEncoding encoding )
{
	// There was a really terrifying little bug here. The code:
	//		value = filename
	// in the STL case, cause the assignment method of the std::string to
	// be called. What is strange, is that the std::string had the same
	// address as it's c_str() method, and so bad things happen. Looks
	// like a bug in the Microsoft STL implementation.
	// See STL_STRING_BUG above.
	// Fixed with the StringToBuffer class.
	value = filename;

	// reading in binary mode so that tinyxml can normalize the EOL
	IFile* file = g_OpenFile( value.c_str () );

	if ( file )
	{
		bool result = LoadBuffer( (LPCSTR)file->GetBuffer(), file->Size(), encoding );
		file->Release();
		return result;
	}
	else
	{
		SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN );
		return false;
	}
}
예제 #2
0
파일: IniFile.cpp 프로젝트: github188/yol
IIniFile*
g_OpenIniFile(const char* FileName, int ForceUnpakFile/* = false*/, int ForWrite/* = false*/)
{
	QIniFileImpl*	pIni = NULL;
	IFile*		pFile = g_OpenFile(FileName, ForceUnpakFile, ForWrite);

	if (pFile)
	{
		pIni = QIniFileImpl::New();
		if (pIni)
		{
			if (!pIni->LoadData(pFile))
			{
				pIni->Release();
				pIni = NULL;
			}
		}
		pFile->Release();
		pFile = NULL;
	}

	if (pIni == NULL && ForWrite)
		pIni = QIniFileImpl::New();
	return pIni;
}
예제 #3
0
bool KLuaWrap::DoScriptFile(const char *ScriptFile, const char *EnvName /*= NULL*/)
{
	bool ret = false;
	assert(m_L);
	if (!(ScriptFile && ScriptFile[0]))
		return false;

	IFile*	pFile = NULL;
	char*	pBuffer = NULL;
	unsigned int	size;

	if ((pFile = g_OpenFile(ScriptFile)) == NULL)
	{
		printf("%s is not exist!\n", ScriptFile);
		KGLogPrintf(KGLOG_WARNING, "[Lua] %s is not exist!\n", ScriptFile);
		return false;
	}

	size = pFile->Size();
	pBuffer = (char*)malloc(size + 1024);
	if (pBuffer)
	{
		char tmp[128];
		int pos = 0;
		int tmpLen = sprintf(tmp, "package.path = \"%s?.lua\"", m_ScriptPackagePath);
#ifdef WIN32
		for (int i = 0; i < tmpLen; ++i)
		{
			pBuffer[pos++] = tmp[i];
			if (tmp[i] == '\\')
			{
				pBuffer[pos++] = '\\';
			}
		}
#endif
		if (EnvName && EnvName[0])
			pos += sprintf(pBuffer + pos, "%s={} setmetatable(%s,{__index=_G,__newindex=function(t,i,v)for _,r in pairs(_RESERVE_G_VAR_)do if i==r then _G[i] = v return end end rawset(t,i,v)end}) setfenv(1,%s)", EnvName, EnvName, EnvName);

		if (pFile->Read(pBuffer + pos, size) == size)
		{
			ret = lua_tinker::dobuffer(m_L, pBuffer, size + pos, ScriptFile);
			if (ret && EnvName && EnvName[0])
			{
				lua_getglobal(m_L, EnvName);
				lua_pushstring(m_L, "CURRENT_SCRIPT_FILE");
				lua_pushstring(m_L, ScriptFile);
				lua_settable(m_L, -3);
				lua_pop(m_L, 1);
			}
		}
		free(pBuffer);
		pBuffer = NULL;
	}

	pFile->Release();
	pFile = NULL;
	return ret;
}
예제 #4
0
// Close the File.
VFS_BOOL VFS_File_Close( VFS_Handle hFile )
{
	// Not initialized yet?
	if( !IsInit() )
	{
		SetLastError( VFS_ERROR_NOT_INITIALIZED_YET );
		return VFS_FALSE;
	}

	// Invalid Handle Value?
	if( hFile == VFS_INVALID_HANDLE_VALUE )
	{
		SetLastError( VFS_ERROR_INVALID_PARAMETER );
		return VFS_FALSE;
	}

	// Get the File Pointer.
	IFile* pFile = ( IFile* )( VFS_DWORD )hFile;

    // Invalid Handle Value?
	VFS_BOOL bFound = VFS_FALSE;
	for( FileMap::iterator iter = GetOpenFiles().begin(); iter != GetOpenFiles().end(); iter++ )
	{
		// Found?
		if( ( *iter ).second == pFile )
		{
			bFound = VFS_TRUE;
			break;
		}
	}
	if( !bFound )
	{
		SetLastError( VFS_ERROR_INVALID_PARAMETER );
		return VFS_FALSE;
	}

	// If the File will be deleted afterwards, remove the File from the
	// Open Files Map.
	if( pFile->GetRefCount() == 1 )
	{
		FileMap::iterator iter = GetOpenFiles().find( pFile->GetFileName() );
		if( iter == GetOpenFiles().end() )
		{
			SetLastError( VFS_ERROR_GENERIC );
			return VFS_FALSE;
		}
		GetOpenFiles().erase( iter );
	}

	// Release the File.
	pFile->Release();

	return VFS_TRUE;
}
예제 #5
0
void KLuaWrap::LoadJitOpt()
{
	IFile*	pFile = NULL;

	if ((pFile = g_OpenFile("\\script\\lib\\jit\\opt.lua")) == NULL)
	{
		lua_tinker::print_error(m_L, "\\script\\lib\\jit\\opt.lua is not exist!\n");
		return;
	}
	if (luaL_loadbuffer(m_L, (const char*)pFile->GetBuffer(), pFile->Size(), "load jit opt"))
	{
		lua_tinker::print_error(m_L, "%s", lua_tostring(m_L, -1));
		lua_pop(m_L, 1);
		return;
	}
	pFile->Release();

	if ((pFile = g_OpenFile("\\script\\lib\\jit\\opt_inline.lua")) == NULL)
	{
		lua_tinker::print_error(m_L, "\\script\\lib\\jit\\opt_inline.lua is not exist!\n");
		return;
	}
	if (luaL_loadbuffer(m_L, (const char*)pFile->GetBuffer(), pFile->Size(), "load jit opt_inline"))
	{
		lua_tinker::print_error(m_L, "%s", lua_tostring(m_L, -1));
		lua_pop(m_L, 1);
		return;
	}
	pFile->Release();

	lua_getglobal(m_L, "package");
	lua_getfield(m_L, -1, "preload");
	lua_insert(m_L, 1);
	lua_pop(m_L, 1);

	lua_setfield(m_L, 1, "jit.opt_inline");
	lua_setfield(m_L, 1, "jit.opt");

	lua_pop(m_L, 1);
}
예제 #6
0
    void testIO(unsigned nr, SocketEndpoint *ep)
    {
        IFile *ifile;
        IFileIO *ifileio;
        unsigned fsize = (unsigned)(((double)nr * (double)rs) / (1024.0 * 1024.0));

        fflush(NULL);
        fprintf(stdout,"\n");
        fflush(NULL);

        for(int j=0; j<2; j++)
        {
            if (j==0)
                fprintf(stdout, "File size: %d (MB) Cache, ", fsize);
            else
                fprintf(stdout, "\nFile size: %d (MB) Nocache, ", fsize);

            if (ep != NULL)
            {
                ifile = createRemoteFile(*ep, tmpfile);
                fprintf(stdout, "Remote: (%s)\n", server.toCharArray());
            }
            else
            {
                ifile = createIFile(tmpfile);
                fprintf(stdout, "Local:\n");
            }

            ifile->remove();

            unsigned st = msTick();

            IFEflags extraFlags = IFEcache;
            if (j==1)
                extraFlags = IFEnocache;
            ifileio = ifile->open(IFOcreate, extraFlags);

            unsigned iter = nr / 40;

            __int64 pos = 0;
            for (int i=0;i<nr;i++)
            {
                ifileio->write(pos, rs, record);
                pos += rs;
                if ((i % iter) == 0)
                {
                    fprintf(stdout,".");
                    fflush(NULL);
                }
            }

            ifileio->close();

            double rsec = (double)(msTick() - st)/1000.0;
            unsigned iorate = (unsigned)((double)fsize / rsec);

            fprintf(stdout, "\nwrite - elapsed time = %6.2f (s) iorate = %4d (MB/s)\n", rsec, iorate);

            st = msTick();

            extraFlags = IFEcache;
            if (j==1)
                extraFlags = IFEnocache;
            ifileio = ifile->open(IFOread, extraFlags);

            pos = 0;
            for (int i=0;i<nr;i++)
            {
                ifileio->read(pos, rs, record);
                pos += rs;
                if ((i % iter) == 0)
                {
                    fprintf(stdout,".");
                    fflush(NULL);
                }
            }

            ifileio->close();

            rsec = (double)(msTick() - st)/1000.0;
            iorate = (unsigned)((double)fsize / rsec);

            fprintf(stdout, "\nread -- elapsed time = %6.2f (s) iorate = %4d (MB/s)\n", rsec, iorate);

            ifileio->Release();
            ifile->remove();
            ifile->Release();
        }
    }