예제 #1
0
CString openTemporaryFile(const char* prefix, PlatformFileHandle& handle)
{
    // BREW does not have a system-wide temporary directory,
    // use "fs:/~/tmp" as our temporary directory.
    String tempPath("fs:/~/tmp");

    PlatformRefPtr<IFileMgr> fileMgr = createRefPtrInstance<IFileMgr>(AEECLSID_FILEMGR);

    // Create the temporary directory if it does not exist.
    IFILEMGR_MkDir(fileMgr.get(), tempPath.utf8().data());

    // Loop until we find a temporary filename that does not exist.
    int number = static_cast<int>(randomNumber() * 10000);
    CString filename;
    do {
        StringBuilder builder;
        builder.append(tempPath);
        builder.append('/');
        builder.append(prefix);
        builder.append(String::number(number));
        filename = builder.toString().utf8();
        number++;
    } while (IFILEMGR_Test(fileMgr.get(), filename.data()) == SUCCESS);

    IFile* tempFile = IFILEMGR_OpenFile(fileMgr.get(), filename.data(), _OFM_CREATE);
    if (tempFile) {
        handle = tempFile;
        return filename;
    }

    return CString();
}
예제 #2
0
파일: File.cpp 프로젝트: bonly/Template
/**
 * 打开文件
 * @param file 打开文件名
 * @param flag 打开方式
 * @return 0:成功 -1:失败
 enum {
 _OFM_READ      = 0x0001,
 _OFM_READWRITE = 0x0002,
 _OFM_CREATE    = 0x0004,
 _OFM_APPEND    = 0x0008
 };
 */
int File::open(const char* file,
            int flag)
{
    if (_FileMgr == 0)
        return -1;

    _flag = flag;
	  if (SUCCESS != IFILEMGR_Test(_FileMgr, file))
	  {
      _flag |= _OFM_CREATE;
	  }
	  else
	  {
      _flag |= _OFM_APPEND;
	  }
    _File = IFILEMGR_OpenFile(_FileMgr, file, _flag);

    if (!_File)
    {
        _FileMgr = 0;
        return -1;
    }
    if (_flag|_OFM_APPEND)
    {
        IFILE_Seek(_File,_SEEK_END,0);
    }

    return 0;
}
예제 #3
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();
}
예제 #4
0
파일: Location.c 프로젝트: TopSoup/BasicLoc
/*======================================================================= 
Function: Loc_InitGPSSettings()

Description: 
   Initializes the GPS configuration to the default values.
=======================================================================*/
uint32 Loc_InitGPSSettings(IShell *pIShell, AEEGPSConfig *gpsConfig)
{
   IFileMgr   *pIFileMgr = NULL;
   IFile      *pIConfigFile = NULL;
   uint32      nResult = 0;
   
   if (pIShell == NULL || gpsConfig == NULL)
      return EFAILED;

   // Create the instance of IFileMgr
   nResult = ISHELL_CreateInstance( pIShell, AEECLSID_FILEMGR, (void**)&pIFileMgr );
   if ( SUCCESS != nResult ) {
      return nResult;
   }

   // If the config file exists, open it and read the settings.  Otherwise, we need to
   // create a new config file.
   nResult = IFILEMGR_Test( pIFileMgr, LOC_CONFIG_FILE );
   if ( SUCCESS == nResult ) {
      pIConfigFile = IFILEMGR_OpenFile( pIFileMgr, LOC_CONFIG_FILE, _OFM_READ );
      if ( !pIConfigFile ) {
         nResult = EFAILED;
      }
      else {
         nResult = Loc_ReadGPSSettings( pIConfigFile, gpsConfig );
      }
   }
   else {
      pIConfigFile = IFILEMGR_OpenFile( pIFileMgr, LOC_CONFIG_FILE, _OFM_CREATE );
      if ( !pIConfigFile ) {
         nResult = EFAILED;
      }
      else {
         // Setup the default GPS settings
         gpsConfig->optim  = AEEGPS_OPT_DEFAULT;
         gpsConfig->qos    = LOC_QOS_DEFAULT;
         gpsConfig->server.svrType = AEEGPS_SERVER_DEFAULT;
         nResult = Loc_WriteGPSSettings( pIConfigFile , gpsConfig);
      }
   }

   // Free the IFileMgr and IFile instances
   IFILE_Release( pIConfigFile );
   IFILEMGR_Release( pIFileMgr );

   return nResult;
}
예제 #5
0
/*======================================================================= 
Function: SamplePosDet_InitGPSSettings()

Description: 
   Initializes the GPS configuration to the default values.

Prototype:

   uint32 SamplePosDet_InitGPSSettings( CSamplePosDet *pMe );

Parameters:
   pMe: [in]. CSamplePosDet instance.

Return Value:

   SUCCESS - If the settings were initialized successfully.
   Returns error code otherwise.
 
Comments:  
   None

Side Effects: 
   None

See Also:
   None
=======================================================================*/
uint32 SamplePosDet_InitGPSSettings(CSamplePosDet *pMe)
{
   IFileMgr   *pIFileMgr = NULL;
   IFile      *pIConfigFile = NULL;
   uint32      nResult = 0;

   // Create the instance of IFileMgr
   nResult = ISHELL_CreateInstance( pMe->theApp.m_pIShell, AEECLSID_FILEMGR, (void**)&pIFileMgr );
   if ( SUCCESS != nResult ) {
      return nResult;
   }

   // If the config file exists, open it and read the settings.  Otherwise, we need to
   // create a new config file.
   nResult = IFILEMGR_Test( pIFileMgr, SPD_CONFIG_FILE );
   if ( SUCCESS == nResult ) {
      pIConfigFile = IFILEMGR_OpenFile( pIFileMgr, SPD_CONFIG_FILE, _OFM_READ );
      if ( !pIConfigFile ) {
         nResult = EFAILED;
      }
      else {
         nResult = SamplePosDet_ReadGPSSettings( pMe, pIConfigFile );
      }
   }
   else {
      pIConfigFile = IFILEMGR_OpenFile( pIFileMgr, SPD_CONFIG_FILE, _OFM_CREATE );
      if ( !pIConfigFile ) {
         nResult = EFAILED;
      }
      else {
         // Setup the default GPS settings
         pMe->gpsSettings.optim  = AEEGPS_OPT_DEFAULT;
         pMe->gpsSettings.qos    = SPD_QOS_DEFAULT;
         pMe->gpsSettings.server.svrType = AEEGPS_SERVER_DEFAULT;
         nResult = SamplePosDet_WriteGPSSettings( pMe, pIConfigFile );
      }
   }

   // Free the IFileMgr and IFile instances
   IFILE_Release( pIConfigFile );
   IFILEMGR_Release( pIFileMgr );

   return nResult;
}
예제 #6
0
/*======================================================================= 
Function: SamplePosDet_SaveGPSSettings()

Description: 
   Opens the configuration file and saves the settings.

Prototype:

   uint32 SamplePosDet_SaveGPSSettings(CSamplePosDet *pMe);

Parameters:
   pMe: [in]. CSamplePosDet instance.

Return Value:

  SUCCESS - If the settings were written successfully.
  Error code otherwise.
 
Comments:  
   None

Side Effects: 
   None

See Also:
   None
=======================================================================*/
uint32 SamplePosDet_SaveGPSSettings( CSamplePosDet *pMe )
{
   IFileMgr   *pIFileMgr = NULL;
   IFile      *pIConfigFile = NULL;
   uint32      nResult = 0;

   // Create the instance of IFileMgr
   nResult = ISHELL_CreateInstance( pMe->theApp.m_pIShell, AEECLSID_FILEMGR, (void**)&pIFileMgr );
   if ( SUCCESS != nResult ) {
      return nResult;
   }

   // If the config file exists, open it and read the settings.  Otherwise, we need to
   // create a new config file.
   nResult = IFILEMGR_Test( pIFileMgr, SPD_CONFIG_FILE );
   if ( SUCCESS == nResult ) {
      pIConfigFile = IFILEMGR_OpenFile( pIFileMgr, SPD_CONFIG_FILE, _OFM_READWRITE );
      if ( !pIConfigFile ) {
         nResult = EFAILED;
      }
      else {
         nResult = SamplePosDet_WriteGPSSettings( pMe, pIConfigFile );
      }
   }
   else {
      pIConfigFile = IFILEMGR_OpenFile( pIFileMgr, SPD_CONFIG_FILE, _OFM_CREATE );
      if ( !pIConfigFile ) {
         nResult = EFAILED;
      }
      else {
         nResult = SamplePosDet_WriteGPSSettings( pMe, pIConfigFile );
      }
   }

   // Free the IFileMgr and IFile instances
   IFILE_Release( pIConfigFile );
   IFILEMGR_Release( pIFileMgr );

   return nResult;
}
예제 #7
0
SkFILE* sk_fopen(const char path[], SkFILE_Flags flags)
{
    int err;
    OpenFileMode mode;
    IFileMgr* fileMgr;
    IFile* file;
    IShell* shell;

    shell = reinterpret_cast<AEEApplet*>(GETAPPINSTANCE())->m_pIShell;
    err = ISHELL_CreateInstance(shell, AEECLSID_FILEMGR, (void**)&fileMgr);
    if (err!= SUCCESS)
        return NULL;

    if (flags & kWrite_SkFILE_Flag)
        mode = _OFM_READWRITE;
    else /* kRead_SkFILE_Flag */
        mode = _OFM_READ;

    file = IFILEMGR_OpenFile(fileMgr, path, mode);
    IFILEMGR_Release(fileMgr);

    return (SkFILE*)file;
}
예제 #8
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;
}