Esempio n. 1
0
/**
 * 读入数据
 * @param buf 存放数据的缓冲
 * @param cnt 读放数据大小
 * @return
 */
int File::read(void* buf, int cnt)
{
    if (!good())
        return -1;

    return IFILE_Read(_File, buf, cnt);
}
Esempio n. 2
0
PassRefPtr<SharedBuffer> SharedBuffer::createWithContentsOfFile(const String& filePath)
{
    if (filePath.isEmpty())
        return 0;

    long long fileSize;
    if (!fileExists(filePath) || !getFileSize(filePath, fileSize))
        return 0;

    RefPtr<SharedBuffer> result = create();
    result->m_buffer.grow(fileSize);

    OwnPtr<IFileMgr> fileMgr = createInstance<IFileMgr>(AEECLSID_FILEMGR);

    CString filename = fileSystemRepresentation(filePath);
    OwnPtr<IFile> file(IFILEMGR_OpenFile(fileMgr.get(), filename.data(), _OFM_READ));

    if (!file) {
        LOG_ERROR("Failed to open file %s to create shared buffer, errno(%i)", filePath.ascii().data(), IFILEMGR_GetLastError(fileMgr.get()));
        return 0;
    }

    size_t totalBytesRead = 0;
    int32 bytesRead;
    while ((bytesRead = IFILE_Read(file.get(), result->m_buffer.data() + totalBytesRead, fileSize - totalBytesRead)) > 0)
        totalBytesRead += bytesRead;
    result->m_size = totalBytesRead;

    if (totalBytesRead != fileSize) {
        LOG_ERROR("Failed to fully read contents of file %s - errno(%i)", filePath.ascii().data(), IFILEMGR_GetLastError(fileMgr.get()));
        return 0;
    }

    return result.release();
}
Esempio n. 3
0
size_t sk_fread(void* buffer, size_t byteCount, SkFILE* f)
{
    SkASSERT(f);
    if (buffer == NULL)
    {
        int err = IFILE_Seek((IFile*)f, _SEEK_CURRENT, (int)byteCount);
        if (err == EFAILED) {
            SkDEBUGF(("sk_fread: IFILE_Seek(%d) failed returned:%d\n", byteCount, err));
            return 0;
        }
        return byteCount;
    }
    else
        return IFILE_Read((IFile*)f, buffer, byteCount);
}
Esempio n. 4
0
/*======================================================================= 
Function: Loc_ReadGPSSettings()

Description: 
   Reads the GPS configuration settings from the configuration file.
=======================================================================*/
static uint32 Loc_ReadGPSSettings(IFile * pIFile, AEEGPSConfig *gpsConfig)
{
   char    *pszBuf = NULL;
   char    *pszTok = NULL;
   char    *pszSvr = NULL;
   char    *pszDelimiter = ";";
   int32   nResult = 0;
   FileInfo fiInfo;

   if (pIFile == NULL || gpsConfig == NULL)
      return EFAILED;

   if ( SUCCESS != IFILE_GetInfo( pIFile, &fiInfo ) ) {
      return EFAILED;
   }

   if ( fiInfo.dwSize == 0 ) {
      return EFAILED;
   }

   // Allocate enough memory to read the full text into memory
   pszBuf = MALLOC( fiInfo.dwSize );

   nResult = IFILE_Read( pIFile, pszBuf, fiInfo.dwSize );
   if ( (uint32)nResult < fiInfo.dwSize ) {
      FREE( pszBuf );
      return EFAILED;
   }

   // Check for an optimization mode setting in the file:
   pszTok = STRSTR( pszBuf, LOC_CONFIG_OPT_STRING );
   if ( pszTok ) {
      pszTok = pszTok + STRLEN( LOC_CONFIG_OPT_STRING );
      gpsConfig->optim = (AEEGPSOpt)STRTOUL( pszTok, &pszDelimiter, 10 );
   }

   // Check for a QoS setting in the file:
   pszTok = STRSTR( pszBuf, LOC_CONFIG_QOS_STRING );
   if ( pszTok ) {
      pszTok = pszTok + STRLEN( LOC_CONFIG_QOS_STRING );
      gpsConfig->qos = (AEEGPSQos)STRTOUL( pszTok, &pszDelimiter, 10 );
   }

   // Check for a server type setting in the file:
   pszTok = STRSTR( pszBuf, LOC_CONFIG_SVR_TYPE_STRING );
   if ( pszTok ) {
      pszTok = pszTok + STRLEN( LOC_CONFIG_SVR_TYPE_STRING );
      gpsConfig->server.svrType = STRTOUL( pszTok, &pszDelimiter, 10 );

      // If the server type is IP, we need to find the ip address and the port number
      if ( AEEGPS_SERVER_IP == gpsConfig->server.svrType ) {
         pszTok = STRSTR( pszBuf, LOC_CONFIG_SVR_IP_STRING );
         if ( pszTok ) {
            pszTok = pszTok + STRLEN( LOC_CONFIG_SVR_IP_STRING );
            nResult = DistToSemi( pszTok );
            pszSvr = MALLOC( nResult+1 );
            STRNCPY( pszSvr, pszTok, nResult );
            *(pszSvr+nResult) = 0;  // Need to manually NULL-terminate the string
            if ( !INET_ATON( pszSvr, &gpsConfig->server.svr.ipsvr.addr ) ) {
               FREE( pszBuf );
               FREE( pszSvr );
               return EFAILED;
            }
            FREE( pszSvr );
         }
         pszTok = STRSTR( pszBuf, LOC_CONFIG_SVR_PORT_STRING );
         if ( pszTok ) {
            pszTok = pszTok + STRLEN( LOC_CONFIG_SVR_PORT_STRING );
            gpsConfig->server.svr.ipsvr.port = AEE_htons((INPort)STRTOUL( pszTok, &pszDelimiter, 10 ));
         }
      }
   }

   FREE( pszBuf );
   
   return SUCCESS;
}
Esempio n. 5
0
int AEEStaticMod_New(int16 nSize, IShell *pIShell, void *ph, IModule **ppMod,PFNMODCREATEINST pfnMC,PFNFREEMODDATA pfnMF)
{
	IFileMgr      *pFileMgr      = NULL;
	IFile         *pFile         = NULL;
	byte          *pData         = NULL;
	FileInfo      fileinfo             ;
	RunLoadMod    pFun           = NULL;
	int           nResult        = 0;
	char          name[128];
	char          path[128];
	DBGPRINTF( "+++++++++++++++++++++++++++++++++++++++++");
	MEMSET(name,0,128*sizeof(char));
	MEMSET(path,0,128*sizeof(char));
	if(!(SUCCESS == ISHELL_CreateInstance( pIShell , AEECLSID_FILEMGR, (void **) &pFileMgr)) )
		goto TagFailModLoader;

	/*
	pFile = IFILEMGR_OpenFile( pFileMgr , AEEFS_SHARED_DIR"run.app" ,_OFM_READWRITE);
		if ( NULL == pFile ){
			DBGPRINTF( "Open run.app EFAILED");
			IFILEMGR_Release( pFileMgr );
			goto TagFailModLoader;}
		else{
			DBGPRINTF( "Open run.app OK");
		}
		IFILE_Read(pFile, name, 128);
		IFILE_Release(pFile);
		STRCPY(path,AEEFS_SHARED_DIR);
		STRCAT(path,name);
	
		DBGPRINTF("Load Mod Path:%s",path);
		DBGPRINTF("Load Mod Name:%s",name);*/
	
	//pFile = IFILEMGR_OpenFile( pFileMgr , "helloworld.bin" ,_OFM_READWRITE);//打开读 和写。
	pFile = IFILEMGR_OpenFile( pFileMgr , "flyvideo.mod" ,_OFM_READWRITE);//打开读 和写。
	if ( NULL == pFile ){
		DBGPRINTF( "Open Mod File EFAILED");
		IFILEMGR_Release( pFileMgr );
		goto TagFailModLoader;}
	else{
		DBGPRINTF( "Open Mod File OK");
	}
	IFILE_GetInfo(pFile, &fileinfo);
	pData = (byte *)MALLOC( 4 * fileinfo.dwSize + 5);//pData不用释放,由AEE环境释放
	MEMSET( pData , 0x00 ,  4 * fileinfo.dwSize + 5);
	MEMCPY( pData , &ph , 4 );
	DBGPRINTF( "Open File OK:%d" , fileinfo.dwSize );
	IFILE_Read( pFile , pData + 4 , fileinfo.dwSize );
	DBGPRINTF( "Read File OK" );

	IFILE_Release( pFile );
	IFILEMGR_Release( pFileMgr );

	DBGPRINTF("Before RunLoadMod");
	pFun = (RunLoadMod)(pData + 4);
	nResult =  pFun(pIShell,ph,ppMod);
	(*ppMod)->pvt->FreeResources = AEEMod_FreeResources;
	DBGPRINTF("After RunLoadMod");
	DBGPRINTF( "+++++++++++++++++++++++++++++++++++++++++");
	return nResult;
TagFailModLoader:
	DBGPRINTF("AEEMod_Load EFAILED");
	DBGPRINTF( "+++++++++++++++++++++++++++++++++++++++++");
	return EFAILED;
}